Skip to content

Commit d2dd075

Browse files
committed
Simplify access specifier parsing
1 parent d909209 commit d2dd075

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
25232523
self.curAccessSpecifier = "private" # private is default
25242524
self.curTemplate = None
25252525
self.accessSpecifierStack = []
2526-
self.accessSpecifierScratch = []
25272526
debug_print(
25282527
"curAccessSpecifier changed/defaulted to %s", self.curAccessSpecifier
25292528
)
@@ -2747,7 +2746,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
27472746
self.curClass = ""
27482747
self.stack = []
27492748

2750-
if tok.type in _namestack_append_tokens:
2749+
elif tok.type in _namestack_append_tokens:
27512750
self.nameStack.append(tok.value)
27522751
elif tok.type in _namestack_pass_tokens:
27532752
pass
@@ -2756,47 +2755,24 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
27562755
debug_print("Ignore symbol %s", tok.value)
27572756
elif tok.value == "class":
27582757
self.nameStack.append(tok.value)
2759-
elif tok.value in supportedAccessSpecifier:
2760-
if len(self.nameStack) and self.nameStack[0] in (
2761-
"class",
2762-
"struct",
2763-
"union",
2764-
):
2765-
self.nameStack.append(tok.value)
2766-
elif self.braceDepth == len(
2767-
self.nameSpaces
2768-
) + 1 or self.braceDepth == (
2769-
len(self.nameSpaces) + len(self.curClass.split("::"))
2770-
):
2771-
self.curAccessSpecifier = tok.value
2772-
self.accessSpecifierScratch.append(tok.value)
2773-
debug_print(
2774-
"curAccessSpecifier updated to %s",
2775-
self.curAccessSpecifier,
2776-
)
2777-
self.stack = []
27782758
else:
27792759
self.nameStack.append(tok.value)
27802760
if self.anon_union_counter[0] == self.braceDepth:
27812761
self.anon_union_counter = [-1, 0]
27822762
elif tok.type == ":":
2783-
# Dont want colon to be first in stack
2784-
if len(self.nameStack) == 0:
2785-
self.accessSpecifierScratch = []
2786-
continue
2787-
2788-
# Handle situation where access specifiers can be multi words such as "public slots"
2789-
jns = " ".join(self.accessSpecifierScratch + self.nameStack)
2790-
if jns in supportedAccessSpecifier:
2791-
self.curAccessSpecifier = jns
2763+
if self.nameStack and self.nameStack[0] in supportedAccessSpecifier:
2764+
specifier = " ".join(self.nameStack)
2765+
if specifier in supportedAccessSpecifier:
2766+
self.curAccessSpecifier = specifier
2767+
else:
2768+
self.curAccessSpecifier = self.nameStack[0]
27922769
debug_print(
2793-
"curAccessSpecifier updated to %s" % self.curAccessSpecifier
2770+
"curAccessSpecifier updated to %s", self.curAccessSpecifier
27942771
)
2795-
self.stack = []
27962772
self.nameStack = []
2773+
self.stack = []
27972774
else:
27982775
self.nameStack.append(tok.value)
2799-
self.accessSpecifierScratch = []
28002776

28012777
elif tok.type == ";":
28022778
if (
@@ -2858,7 +2834,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
28582834
"nameSpaces",
28592835
"curAccessSpecifier",
28602836
"accessSpecifierStack",
2861-
"accessSpecifierScratch",
28622837
"nameStackHistory",
28632838
"anon_struct_counter",
28642839
"anon_union_counter",

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