Skip to content

Commit 443f5e3

Browse files
committed
Get rid of _classes_brace_level, change curClass to the class object instead of a string
1 parent 694536e commit 443f5e3

File tree

1 file changed

+37
-51
lines changed

1 file changed

+37
-51
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,6 @@ def initextra(self):
15101510
self.stack = (
15111511
[]
15121512
) # full name stack, good idea to keep both stacks? (simple stack and full stack)
1513-
self._classes_brace_level = {} # class name : level
15141513
self._forward_decls = []
15151514
self._template_typenames = [] # template<typename XXX>
15161515

@@ -2278,7 +2277,7 @@ def parse_method_type(self, stack):
22782277
if name.startswith("~"):
22792278
info["destructor"] = True
22802279
name = name[1:]
2281-
elif not a or (name == self.curClass and len(self.curClass)):
2280+
elif not a or (self.curClass and name == self.curClass["name"]):
22822281
info["constructor"] = True
22832282

22842283
info["name"] = name
@@ -2353,15 +2352,15 @@ def _evaluate_method_stack(self):
23532352
newMethod["path"] = klass["name"]
23542353

23552354
elif self.curClass: # normal case
2355+
klass = self.curClass
23562356
newMethod = CppMethod(
23572357
self.nameStack,
2358-
self.curClass,
2358+
klass["name"],
23592359
info,
23602360
self.curTemplate,
23612361
self._get_stmt_doxygen(),
23622362
self._get_location(self.nameStack),
23632363
)
2364-
klass = self.classes[self.curClass]
23652364
klass["methods"][self.curAccessSpecifier].append(newMethod)
23662365
newMethod["parent"] = klass
23672366
if klass["namespace"]:
@@ -2453,11 +2452,10 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
24532452
if self.curClass:
24542453
typedef = self._parse_typedef(self.stack)
24552454
name = typedef["name"]
2456-
klass = self.classes[self.curClass]
2457-
klass["typedefs"][self.curAccessSpecifier].append(name)
2455+
self.curClass["typedefs"][self.curAccessSpecifier].append(name)
24582456
if self.curAccessSpecifier == "public":
2459-
klass._public_typedefs[name] = typedef["type"]
2460-
Resolver.SubTypedefs[name] = self.curClass
2457+
self.curClass._public_typedefs[name] = typedef["type"]
2458+
Resolver.SubTypedefs[name] = self.curClass["name"]
24612459
else:
24622460
assert 0
24632461
elif self.curClass:
@@ -2510,7 +2508,7 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
25102508
)
25112509
newVar["namespace"] = self.current_namespace()
25122510
if self.curClass:
2513-
klass = self.classes[self.curClass]
2511+
klass = self.curClass
25142512
klass["properties"][self.curAccessSpecifier].append(newVar)
25152513
newVar["property_of_class"] = klass["name"]
25162514
newVar["parent"] = klass
@@ -2589,27 +2587,26 @@ def _evaluate_class_stack(self):
25892587
classKey = newClass["name"]
25902588

25912589
if parent:
2592-
newClass["namespace"] = self.classes[parent]["namespace"] + "::" + parent
2593-
newClass["parent"] = self.classes[parent]
2590+
newClass["namespace"] = parent["namespace"] + "::" + parent["name"]
2591+
newClass["parent"] = parent
25942592
newClass["access_in_parent"] = self.accessSpecifierStack[-1]
2595-
self.classes[parent]["nested_classes"].append(newClass)
2593+
parent["nested_classes"].append(newClass)
25962594
## supports nested classes with the same name ##
2597-
self.curClass = key = parent + "::" + classKey
2598-
self._classes_brace_level[key] = self.braceDepth
2595+
key = parent["name"] + "::" + classKey
25992596

26002597
elif newClass["parent"]: # nested class defined outside of parent. A::B {...}
26012598
pcls = newClass["parent"]
2602-
parent = pcls["name"]
2603-
newClass["namespace"] = pcls["namespace"] + "::" + parent
2599+
parentName = pcls["name"]
2600+
newClass["namespace"] = pcls["namespace"] + "::" + parentName
26042601
pcls["nested_classes"].append(newClass)
26052602
## supports nested classes with the same name ##
2606-
self.curClass = key = parent + "::" + classKey
2607-
self._classes_brace_level[key] = self.braceDepth
2603+
key = parentName + "::" + classKey
26082604

26092605
else:
26102606
newClass["namespace"] = self.cur_namespace()
2611-
self.curClass = key = classKey
2612-
self._classes_brace_level[classKey] = self.braceDepth
2607+
key = classKey
2608+
2609+
self.curClass = newClass
26132610

26142611
if not key.endswith("::") and not key.endswith(" ") and len(key) != 0:
26152612
if key in self.classes:
@@ -2628,10 +2625,9 @@ def evalute_forward_decl(self):
26282625
assert self.nameStack[0] in ("class", "struct")
26292626
name = self.nameStack[-1]
26302627
if self.curClass:
2631-
klass = self.classes[self.curClass]
2632-
klass["forward_declares"][self.curAccessSpecifier].append(name)
2628+
self.curClass["forward_declares"][self.curAccessSpecifier].append(name)
26332629
if self.curAccessSpecifier == "public":
2634-
klass._public_forward_declares.append(name)
2630+
self.curClass._public_forward_declares.append(name)
26352631
else:
26362632
self._forward_decls.append(name)
26372633

@@ -2705,7 +2701,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
27052701
headerFileStr = headerFileName
27062702
else:
27072703
raise Exception("Arg type must be either file or string")
2708-
self.curClass = ""
2704+
self.curClass = None
27092705

27102706
# nested classes have parent::nested, but no extra namespace,
27112707
# this keeps the API compatible, TODO proper namespace for everything.
@@ -2977,24 +2973,14 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
29772973
self._evaluate_stack()
29782974
self.braceDepth -= 1
29792975

2980-
# if self.curClass:
2981-
# debug_print(
2982-
# "CURBD %s", self._classes_brace_level[self.curClass]
2983-
# )
2984-
2985-
if (self.braceDepth == 0) or (
2986-
self.curClass
2987-
and self._classes_brace_level[self.curClass] == self.braceDepth
2988-
):
2976+
if self.braceDepth == 0 or self.curClass:
29892977
trace_print("END OF CLASS DEF")
29902978
if self.accessSpecifierStack:
29912979
self.curAccessSpecifier = self.accessSpecifierStack[-1]
29922980
self.accessSpecifierStack = self.accessSpecifierStack[:-1]
2993-
if self.curClass and self.classes[self.curClass]["parent"]:
2994-
thisClass = self.classes[self.curClass]
2995-
self.curClass = self.curClass[
2996-
: -(len(thisClass["name"]) + 2)
2997-
]
2981+
if self.curClass and self.curClass["parent"]:
2982+
thisClass = self.curClass
2983+
self.curClass = self.curClass["parent"]
29982984

29992985
# Detect anonymous union members
30002986
if (
@@ -3014,7 +3000,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
30143000
self.nameStack = []
30153001
self.stmtTokens = []
30163002
else:
3017-
self.curClass = ""
3003+
self.curClass = None
30183004
self.stack = []
30193005
self.stmtTokens = []
30203006
elif tok.type in _namestack_append_tokens:
@@ -3115,7 +3101,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
31153101
"anon_struct_counter",
31163102
"anon_union_counter",
31173103
"anon_class_counter",
3118-
"_classes_brace_level",
31193104
"_forward_decls",
31203105
"stack",
31213106
"mainClass",
@@ -3124,6 +3109,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
31243109
"stmtTokens",
31253110
"typedefs_order",
31263111
"curTemplate",
3112+
"curClass",
31273113
]:
31283114
del self.__dict__[key]
31293115

@@ -3285,10 +3271,10 @@ def _evaluate_stack(self, token=None):
32853271
debug_caller_lineno,
32863272
)
32873273

3288-
if len(self.curClass):
3289-
debug_print("%s (%s) ", self.curClass, self.curAccessSpecifier)
3290-
else:
3291-
debug_print("<anonymous> (%s) ", self.curAccessSpecifier)
3274+
# if len(self.curClass):
3275+
# debug_print("%s (%s) ", self.curClass, self.curAccessSpecifier)
3276+
# else:
3277+
# debug_print("<anonymous> (%s) ", self.curAccessSpecifier)
32923278

32933279
# Filter special case of array with casting in it
32943280
try:
@@ -3372,7 +3358,7 @@ def _evaluate_stack(self, token=None):
33723358
atype["raw_type"] = ns + atype["type"]
33733359

33743360
if self.curClass:
3375-
klass = self.classes[self.curClass]
3361+
klass = self.curClass
33763362
klass["using"][alias] = atype
33773363
else:
33783364
# lookup is done
@@ -3436,10 +3422,11 @@ def _evaluate_stack(self, token=None):
34363422
else:
34373423
debug_print("Discarded statement %s", self.nameStack)
34383424

3425+
className = self.curClass["name"] if self.curClass else ""
34393426
try:
3440-
self.nameStackHistory[self.braceDepth] = (nameStackCopy, self.curClass)
3427+
self.nameStackHistory[self.braceDepth] = (nameStackCopy, className)
34413428
except:
3442-
self.nameStackHistory.append((nameStackCopy, self.curClass))
3429+
self.nameStackHistory.append((nameStackCopy, className))
34433430

34443431
# its a little confusing to have some if/else above return and others not, and then clearning the nameStack down here
34453432
self.nameStack = []
@@ -3595,12 +3582,11 @@ def _parse_enum(self):
35953582
self._install_enum(newEnum, instancesData)
35963583

35973584
def _install_enum(self, newEnum, instancesData):
3598-
if len(self.curClass):
3585+
if self.curClass:
35993586
newEnum["namespace"] = self.cur_namespace(False)
3600-
klass = self.classes[self.curClass]
3601-
klass["enums"][self.curAccessSpecifier].append(newEnum)
3587+
self.curClass["enums"][self.curAccessSpecifier].append(newEnum)
36023588
if self.curAccessSpecifier == "public" and "name" in newEnum:
3603-
klass._public_enums[newEnum["name"]] = newEnum
3589+
self.curClass._public_enums[newEnum["name"]] = newEnum
36043590
else:
36053591
newEnum["namespace"] = self.cur_namespace(True)
36063592
self.enums.append(newEnum)

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