Skip to content

Commit 43c65dc

Browse files
committed
Properly handle 'extern "C"' namespaces
1 parent 207bb7e commit 43c65dc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,6 +3170,10 @@ def _evaluate_stack(self, token=None):
31703170
elif self.nameStack[0] == "namespace":
31713171
# Taken care of outside of here
31723172
pass
3173+
elif len(self.nameStack) == 2 and self.nameStack[0] == "extern":
3174+
debug_print("trace extern")
3175+
self.stack = []
3176+
self.stmtTokens = []
31733177
elif (
31743178
len(self.nameStack) == 2 and self.nameStack[0] == "friend"
31753179
): # friend class declaration

test/test_CppHeaderParser.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,5 +3545,39 @@ def test_nothing(self):
35453545
pass
35463546

35473547

3548+
class ExternInline_TestCase(unittest.TestCase):
3549+
def setUp(self):
3550+
self.cppHeader = CppHeaderParser.CppHeader(
3551+
"""
3552+
extern "C++" {
3553+
inline HAL_Value HAL_GetSimValue(HAL_SimValueHandle handle) {
3554+
HAL_Value v;
3555+
return v;
3556+
}
3557+
} // extern "C++"
3558+
3559+
""",
3560+
"string",
3561+
)
3562+
3563+
def test_fn(self):
3564+
self.assertEqual(self.cppHeader.variables, [])
3565+
self.assertEqual(len(self.cppHeader.functions), 1)
3566+
fn = self.cppHeader.functions[0]
3567+
self.assertEqual(fn["name"], "HAL_GetSimValue")
3568+
self.assertEqual(
3569+
filter_pameters(fn["parameters"], ["namespace", "raw_type"]),
3570+
[
3571+
{
3572+
"type": "HAL_SimValueHandle",
3573+
"name": "handle",
3574+
"desc": None,
3575+
"namespace": "",
3576+
"raw_type": "HAL_SimValueHandle",
3577+
},
3578+
],
3579+
)
3580+
3581+
35483582
if __name__ == "__main__":
35493583
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy