Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit952f4c5

Browse files
committed
Remove parseHistory, improve class ending
- Support anonymous structs/classes in addition to unions
1 parent2b4c628 commit952f4c5

File tree

1 file changed

+51
-70
lines changed

1 file changed

+51
-70
lines changed

‎CppHeaderParser/CppHeaderParser.py‎

Lines changed: 51 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ def trace_print(*args):
142142
ignoreSymbols= ["Q_OBJECT"]
143143

144144

145-
# Track what was added in what order and at what depth
146-
parseHistory= []
147-
148-
149145
defis_namespace(nameStack):
150146
"""Determines if a namespace is being specified"""
151147
iflen(nameStack)==0:
@@ -2379,14 +2375,6 @@ def _evaluate_method_stack(self):
23792375
)
23802376
newMethod["parent"]=None
23812377
self.functions.append(newMethod)
2382-
globalparseHistory
2383-
parseHistory.append(
2384-
{
2385-
"braceDepth":self.braceDepth,
2386-
"item_type":"method",
2387-
"item":newMethod,
2388-
}
2389-
)
23902378
else:
23912379
trace_print("free function?",self.nameStack)
23922380

@@ -2443,21 +2431,20 @@ def _evaluate_typedef(self):
24432431
ifnamenotinself.typedefs_order:
24442432
self.typedefs_order.append(name)
24452433

2446-
def_finish_struct_typedef(self):
2434+
def_finish_struct_typedef(self,toks):
24472435
# Look for the name of a typedef struct: struct typedef {...] StructName; or unions to get renamed
24482436
debug_print("finish struct typedef")
24492437
self.typedef_encountered=False
24502438

2451-
toks=self._consume_up_to([],";")
2452-
2453-
# grab the first name token, TODO: typedef struct{} X, *PX;
2439+
# grab the first name token
24542440
fortokintoks:
24552441
iftok.type=="NAME":
24562442
new_name=tok.value
24572443
break
24582444
else:
24592445
return
24602446

2447+
# TODO: typedef struct{} X, *PX;
24612448
type_name_to_rename=self.curClass["name"]
24622449
type_to_rename=self.classes[type_name_to_rename]
24632450
type_to_rename["name"]=new_name
@@ -2466,10 +2453,52 @@ def _finish_struct_typedef(self):
24662453
ifnew_name!=type_name_to_rename:
24672454
delself.classes[type_name_to_rename]
24682455

2456+
def_finish_class_def(self):
2457+
2458+
# starting at the last } of a class/struct/union
2459+
debug_print("finish_class_def")
2460+
2461+
# consume any names for parsing
2462+
toks=self._consume_up_to([],";")
2463+
2464+
is_typedef=self.typedef_encountered
2465+
ifis_typedef:
2466+
self._finish_struct_typedef(toks)
2467+
2468+
thisClass=self.curClass
2469+
self.curClass=thisClass["parent"]
2470+
2471+
ifnotis_typedef:
2472+
iflen(toks)>1:
2473+
# Deal with "struct { } x;" style of things
2474+
expected_types= {",","NAME","*",";"}
2475+
stack= [thisClass["name"]]
2476+
fortokintoks:
2477+
stack.append(tok.value)
2478+
iftok.typenotinexpected_types:
2479+
self._parse_error((tok,),",".join(expected_types))
2480+
2481+
self.nameStack=stack[:-1]
2482+
self.stack=stack
2483+
self.stmtTokens=toks
2484+
2485+
self._evaluate_property_stack(clearStack=False)
2486+
2487+
elifself.curClassandthisClass["name"].startswith("<"):
2488+
# anonymous class struct/union
2489+
stack= [thisClass["name"],"",";"]
2490+
self.nameStack=stack[:-1]
2491+
self.stack=stack
2492+
2493+
self._evaluate_property_stack(clearStack=False)
2494+
2495+
self.stack= []
2496+
self.nameStack= []
2497+
self.stmtTokens= []
2498+
24692499
def_evaluate_property_stack(self,clearStack=True,addToVar=None):
24702500
"""Create a Property out of the name stack"""
2471-
globalparseHistory
2472-
debug_print("trace")
2501+
debug_print("evaluate_property_stack")
24732502
ifself.nameStack[0]=="typedef":
24742503
assertself.stackandself.stack[-1]==";"
24752504
ifself.curClass:
@@ -2482,21 +2511,6 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
24822511
else:
24832512
assert0
24842513
elifself.curClass:
2485-
iflen(self.nameStack)==1:
2486-
# See if we can de anonymize the type
2487-
filteredParseHistory= [
2488-
hforhinparseHistoryifh["braceDepth"]==self.braceDepth
2489-
]
2490-
if (
2491-
len(filteredParseHistory)
2492-
andfilteredParseHistory[-1]["item_type"]=="class"
2493-
):
2494-
self.nameStack.insert(0,filteredParseHistory[-1]["item"]["name"])
2495-
debug_print(
2496-
"DEANONYMOIZING %s to type '%s'",
2497-
self.nameStack[1],
2498-
self.nameStack[0],
2499-
)
25002514
if","inself.nameStack:# Maybe we have a variable list
25012515
# Figure out what part is the variable separator but remember templates of function pointer
25022516
# First find left most comma outside of a > and )
@@ -2535,9 +2549,6 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
25352549
klass["properties"][self.curAccessSpecifier].append(newVar)
25362550
newVar["property_of_class"]=klass["name"]
25372551
newVar["parent"]=klass
2538-
parseHistory.append(
2539-
{"braceDepth":self.braceDepth,"item_type":"variable","item":newVar}
2540-
)
25412552
ifaddToVar:
25422553
newVar.update(addToVar)
25432554
else:
@@ -2638,10 +2649,6 @@ def _evaluate_class_stack(self):
26382649
newClass.show()
26392650
assertkeynotinself.classes# namespace collision
26402651
self.classes[key]=newClass
2641-
globalparseHistory
2642-
parseHistory.append(
2643-
{"braceDepth":self.braceDepth,"item_type":"class","item":newClass}
2644-
)
26452652

26462653
defevalute_forward_decl(self):
26472654
trace_print("FORWARD DECL",self.nameStack)
@@ -3003,34 +3010,9 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
30033010
self.curAccessSpecifier=self.accessSpecifierStack[-1]
30043011
self.accessSpecifierStack=self.accessSpecifierStack[:-1]
30053012

3006-
ifself.curClassandself.typedef_encountered:
3007-
self._finish_struct_typedef()
3013+
ifself.curClass:
3014+
self._finish_class_def()
30083015

3009-
ifself.curClassandself.curClass["parent"]:
3010-
thisClass=self.curClass
3011-
self.curClass=self.curClass["parent"]
3012-
3013-
# Detect anonymous union members
3014-
if (
3015-
self.curClass
3016-
andthisClass["declaration_method"]=="union"
3017-
andthisClass["name"].startswith("<")
3018-
andself.lex.token_if(";")
3019-
):
3020-
debug_print("Creating anonymous union")
3021-
# Force the processing of an anonymous union
3022-
self.nameStack= [""]
3023-
self.stack=self.nameStack+ [";"]
3024-
debug_print("pre eval anon stack")
3025-
self._evaluate_stack(";")
3026-
debug_print("post eval anon stack")
3027-
self.stack= []
3028-
self.nameStack= []
3029-
self.stmtTokens= []
3030-
else:
3031-
self.curClass=None
3032-
self.stack= []
3033-
self.stmtTokens= []
30343016
eliftok.typein_namestack_append_tokens:
30353017
self.nameStack.append(tok.value)
30363018
eliftok.typein_namestack_pass_tokens:
@@ -3110,8 +3092,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
31103092
)
31113093

31123094
self.finalize()
3113-
globalparseHistory
3114-
parseHistory= []
3095+
31153096
# Delete some temporary variables
31163097
forkeyin [
31173098
"_precomp_macro_buf",
@@ -3181,7 +3162,7 @@ def _consume_up_to(self, rtoks, *token_types):
31813162
rtoks.append(tok)
31823163
iftok.typeintoken_types:
31833164
break
3184-
3165+
31853166
returnrtoks
31863167

31873168
_end_balanced_tokens= {">","}","]",")","DBL_RBRACKET"}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp