Skip to content

Commit 08950fc

Browse files
committed
Prevent enums from being parsed as a class
1 parent 5623e93 commit 08950fc

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,10 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
27112711
if "class" in self.nameStack and self.nameStack[0] != "class":
27122712
classLocationNS = self.nameStack.index("class")
27132713
classLocationS = self.stack.index("class")
2714-
if "(" not in self.nameStack[classLocationNS:]:
2714+
if (
2715+
"(" not in self.nameStack[classLocationNS:]
2716+
and self.nameStack[classLocationNS - 1] != "enum"
2717+
):
27152718
debug_print(
27162719
"keyword 'class' found in unexpected location in nameStack, must be following #define magic. Process that before moving on"
27172720
)

test/test_CppHeaderParser.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,5 +3420,28 @@ def test_future(self):
34203420
self.assertEqual(c["methods"]["public"][0]["name"], "future")
34213421

34223422

3423+
class EnumClass_TestCase(unittest.TestCase):
3424+
def setUp(self):
3425+
self.cppHeader = CppHeaderParser.CppHeader(
3426+
"""
3427+
enum class MyEnum {
3428+
V = 1
3429+
};
3430+
3431+
""",
3432+
"string",
3433+
)
3434+
3435+
def test_enum(self):
3436+
self.assertEqual(self.cppHeader.classes, {})
3437+
self.assertEqual(len(self.cppHeader.enums), 1)
3438+
e = self.cppHeader.enums[0]
3439+
3440+
self.assertEqual(e["name"], "MyEnum")
3441+
self.assertEqual(
3442+
e["values"], [{"name": "V", "value": 1}],
3443+
)
3444+
3445+
34233446
if __name__ == "__main__":
34243447
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