@@ -193,7 +193,9 @@ def is_method_namestack(stack):
193
193
elif "{" in stack and stack .index ("{" ) < stack .index ("(" ):
194
194
r = False # struct that looks like a method/class
195
195
elif "(" in stack and ")" in stack :
196
- if "{" in stack and "}" in stack :
196
+ if stack [- 1 ] == ":" :
197
+ r = True
198
+ elif "{" in stack and "}" in stack :
197
199
r = True
198
200
elif stack [- 1 ] == ";" :
199
201
if is_function_pointer_stack (stack ):
@@ -255,11 +257,13 @@ def _split_namespace(namestack):
255
257
256
258
:rtype: Tuple[str, list]
257
259
"""
260
+ # TODO: this should be using tokens instead of nhack
261
+
258
262
last_colon = None
259
263
for i , n in enumerate (namestack ):
260
- if n == ":" :
264
+ if n == ":: " :
261
265
last_colon = i
262
- if i and n != ":" and not _nhack .match (n ):
266
+ if i and n != ":: " and not _nhack .match (n ):
263
267
break
264
268
265
269
if last_colon :
@@ -472,12 +476,8 @@ def _parse_cppclass_name(c, stack):
472
476
if t == ":" :
473
477
if i >= sl :
474
478
raise CppParseError ("class decl ended with ':'" )
475
- t = stack [i ]
476
- if t != ":" :
477
- # reached the base declaration
478
- break
479
-
480
- i += 1
479
+ break
480
+ elif t == "::" :
481
481
name += "::"
482
482
continue
483
483
elif t == "final" :
@@ -954,7 +954,7 @@ def __init__(self, nameStack, curClass, methinfo, curTemplate, doxygen, location
954
954
if len (self ["rtnType" ]) == 0 or self ["name" ] == curClass :
955
955
self ["rtnType" ] = "void"
956
956
957
- self ["rtnType" ] = self ["rtnType" ].replace (" : : " , "::" )
957
+ self ["rtnType" ] = self ["rtnType" ].replace (" :: " , "::" )
958
958
self ["rtnType" ] = self ["rtnType" ].replace (" < " , "<" )
959
959
self ["rtnType" ] = self ["rtnType" ].replace (" > " , "> " ).replace (">>" , "> >" )
960
960
self ["rtnType" ] = self ["rtnType" ].replace (" ," , "," )
@@ -996,22 +996,6 @@ def __init__(self, nameStack, curClass, methinfo, curTemplate, doxygen, location
996
996
self .update (methinfo )
997
997
set_location_info (self , location )
998
998
999
- # Filter out initializer lists used in constructors
1000
- try :
1001
- paren_depth_counter = 0
1002
- for i in range (0 , len (nameStack )):
1003
- elm = nameStack [i ]
1004
- if elm == "(" :
1005
- paren_depth_counter += 1
1006
- if elm == ")" :
1007
- paren_depth_counter -= 1
1008
- if paren_depth_counter == 0 and nameStack [i + 1 ] == ":" :
1009
- debug_print ("Stripping out initializer list" )
1010
- nameStack = nameStack [: i + 1 ]
1011
- break
1012
- except :
1013
- pass
1014
-
1015
999
paramsStack = self ._params_helper1 (nameStack )
1016
1000
1017
1001
debug_print ("curTemplate: %s" , curTemplate )
@@ -1959,8 +1943,8 @@ def finalize(self):
1959
1943
)
1960
1944
meth ["returns_unknown" ] = True
1961
1945
1962
- if meth ["returns" ].startswith (": : " ):
1963
- meth ["returns" ] = meth ["returns" ].replace (": : " , "::" )
1946
+ if meth ["returns" ].startswith (":: " ):
1947
+ meth ["returns" ] = meth ["returns" ].replace (":: " , "::" )
1964
1948
1965
1949
for cls in list (self .classes .values ()):
1966
1950
methnames = cls .get_all_method_names ()
@@ -1992,11 +1976,9 @@ def finalize(self):
1992
1976
1993
1977
def parse_method_type (self , stack ):
1994
1978
trace_print ("meth type info" , stack )
1995
- if stack [0 ] in ":;" and stack [1 ] != ":" :
1996
- stack = stack [1 :]
1997
1979
info = {
1998
1980
"debug" : " " .join (stack )
1999
- .replace (" : : " , "::" )
1981
+ .replace (" :: " , "::" )
2000
1982
.replace (" < " , "<" )
2001
1983
.replace (" > " , "> " )
2002
1984
.replace (" >" , ">" )
@@ -2010,7 +1992,7 @@ def parse_method_type(self, stack):
2010
1992
2011
1993
header = stack [: stack .index ("(" )]
2012
1994
header = " " .join (header )
2013
- header = header .replace (" : : " , "::" )
1995
+ header = header .replace (" :: " , "::" )
2014
1996
header = header .replace (" < " , "<" )
2015
1997
header = header .replace (" > " , "> " )
2016
1998
header = header .replace ("default " , "default" )
@@ -2022,6 +2004,10 @@ def parse_method_type(self, stack):
2022
2004
self .braceHandled = True
2023
2005
elif stack [- 1 ] == ";" :
2024
2006
info ["defined" ] = False
2007
+ elif stack [- 1 ] == ":" :
2008
+ info ["defined" ] = True
2009
+ self ._discard_ctor_initializer ()
2010
+ self .braceHandled = True
2025
2011
else :
2026
2012
assert 0
2027
2013
@@ -2452,6 +2438,7 @@ def evalute_forward_decl(self):
2452
2438
"+" ,
2453
2439
"STRING_LITERAL" ,
2454
2440
"ELLIPSIS" ,
2441
+ "DBL_COLON" ,
2455
2442
"SHIFT_LEFT" ,
2456
2443
}
2457
2444
@@ -2651,6 +2638,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2651
2638
#
2652
2639
2653
2640
self ._doxygen_cache = None
2641
+ self .braceHandled = False
2654
2642
tok = None
2655
2643
self .stmtTokens = []
2656
2644
@@ -2809,6 +2797,12 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2809
2797
self .nameStack = []
2810
2798
self .stack = []
2811
2799
self .stmtTokens = []
2800
+ elif is_method_namestack (self .stack ):
2801
+ debug_print ("trace" )
2802
+ self ._evaluate_method_stack ()
2803
+ self .nameStack = []
2804
+ self .stack = []
2805
+ self .stmtTokens = []
2812
2806
else :
2813
2807
self .nameStack .append (tok .value )
2814
2808
@@ -2874,6 +2868,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2874
2868
for key in [
2875
2869
"_precomp_macro_buf" ,
2876
2870
"_doxygen_cache" ,
2871
+ "braceHandled" ,
2877
2872
"lex" ,
2878
2873
"nameStack" ,
2879
2874
"nameSpaces" ,
@@ -2926,7 +2921,7 @@ def _parse_error(self, tokens, expected):
2926
2921
def _next_token_must_be (self , * tokenTypes ):
2927
2922
tok = self .lex .token ()
2928
2923
if tok .type not in tokenTypes :
2929
- raise self ._parse_error ((tok ,), " or " .join (tokenTypes ))
2924
+ raise self ._parse_error ((tok ,), "' or ' " .join (tokenTypes ))
2930
2925
return tok
2931
2926
2932
2927
_end_balanced_tokens = {">" , "}" , "]" , ")" , "DBL_RBRACKET" }
@@ -2986,6 +2981,59 @@ def _discard_contents(self, start_type, end_type):
2986
2981
if level == 0 :
2987
2982
break
2988
2983
2984
+ def _discard_ctor_initializer (self ):
2985
+ """
2986
+ ctor_initializer: ":" mem_initializer_list
2987
+
2988
+ mem_initializer_list: mem_initializer ["..."]
2989
+ | mem_initializer "," mem_initializer_list ["..."]
2990
+
2991
+ mem_initializer: mem_initializer_id "(" [expression_list] ")"
2992
+ | mem_initializer_id braced_init_list
2993
+
2994
+ mem_initializer_id: class_or_decltype
2995
+ | IDENTIFIER
2996
+ """
2997
+ debug_print ("discarding ctor intializer" )
2998
+ # all of this is discarded.. the challenge is to determine
2999
+ # when the initializer ends and the function starts
3000
+ while True :
3001
+ tok = self .lex .token ()
3002
+ if tok .type == "DBL_COLON" :
3003
+ tok = self .lex .token ()
3004
+
3005
+ if tok .type == "decltype" :
3006
+ tok = self ._next_token_must_be ("(" )
3007
+ self ._consume_balanced_tokens (tok )
3008
+ tok = self .lex .token ()
3009
+
3010
+ # each initializer is either foo() or foo{}, so look for that
3011
+ while True :
3012
+ if tok .type not in ("{" , "(" ):
3013
+ tok = self .lex .token ()
3014
+ continue
3015
+
3016
+ if tok .type == "{" :
3017
+ self ._discard_contents ("{" , "}" )
3018
+ elif tok .type == "(" :
3019
+ self ._discard_contents ("(" , ")" )
3020
+
3021
+ tok = self .lex .token ()
3022
+ break
3023
+
3024
+ # at the end
3025
+ if tok .type == "ELLIPSIS" :
3026
+ tok = self .lex .token ()
3027
+
3028
+ if tok .type == "," :
3029
+ continue
3030
+ elif tok .type == "{" :
3031
+ # reached the function
3032
+ self ._discard_contents ("{" , "}" )
3033
+ return
3034
+ else :
3035
+ raise self ._parse_error ((tok ,), ",' or '{" )
3036
+
2989
3037
def _evaluate_stack (self , token = None ):
2990
3038
"""Evaluates the current name stack"""
2991
3039
@@ -3076,24 +3124,10 @@ def _evaluate_stack(self, token=None):
3076
3124
self .using [alias ] = atype
3077
3125
elif is_method_namestack (self .stack ) and "(" in self .nameStack :
3078
3126
debug_print ("trace" )
3079
- if self .braceDepth > 0 :
3080
- if (
3081
- "{" in self .stack
3082
- and self .stack [0 ] != "{"
3083
- and self .stack [- 1 ] == ";"
3084
- and self .braceDepth == 1
3085
- ):
3086
- # Special case of a method defined outside a class that has a body
3087
- pass
3088
- else :
3089
- self ._evaluate_method_stack ()
3090
- else :
3091
- # Free function
3092
- self ._evaluate_method_stack ()
3127
+ self ._evaluate_method_stack ()
3093
3128
elif is_enum_namestack (self .nameStack ):
3094
3129
debug_print ("trace" )
3095
3130
self ._parse_enum ()
3096
- self .nameStack = []
3097
3131
self .stack = []
3098
3132
self .stmtTokens = []
3099
3133
elif (
@@ -3137,25 +3171,22 @@ def _evaluate_stack(self, token=None):
3137
3171
3138
3172
elif not self .curClass :
3139
3173
debug_print ("trace" )
3140
- self .nameStack = []
3141
3174
elif self .braceDepth < 1 :
3142
3175
debug_print ("trace" )
3143
3176
# Ignore global stuff for now
3144
3177
debug_print ("Global stuff: %s" % self .nameStack )
3145
- self .nameStack = []
3146
3178
elif self .braceDepth > len (self .nameSpaces ) + 1 :
3147
3179
debug_print ("trace" )
3148
- self .nameStack = []
3149
3180
else :
3150
3181
debug_print ("Discarded statement %s" % (self .nameStack ,))
3151
3182
3152
3183
try :
3153
3184
self .nameStackHistory [self .braceDepth ] = (nameStackCopy , self .curClass )
3154
3185
except :
3155
3186
self .nameStackHistory .append ((nameStackCopy , self .curClass ))
3156
- self . nameStack = (
3157
- []
3158
- ) # its a little confusing to have some if/else above return and others not, and then clearning the nameStack down here
3187
+
3188
+ # its a little confusing to have some if/else above return and others not, and then clearning the nameStack down here
3189
+ self . nameStack = []
3159
3190
self .lex .doxygenCommentCache = ""
3160
3191
self .curTemplate = None
3161
3192
@@ -3164,7 +3195,7 @@ def _parse_template(self):
3164
3195
consumed = self ._consume_balanced_tokens (tok )
3165
3196
tmpl = " " .join (tok .value for tok in consumed )
3166
3197
tmpl = (
3167
- tmpl .replace (" : : " , "::" )
3198
+ tmpl .replace (" :: " , "::" )
3168
3199
.replace (" <" , "<" )
3169
3200
.replace ("< " , "<" )
3170
3201
.replace (" >" , ">" )
@@ -3364,10 +3395,10 @@ def _parse_enumerator_list(self, values):
3364
3395
while True :
3365
3396
tok = self .lex .token ()
3366
3397
if tok .type == "}" :
3367
- value ["value" ] = ( " " .join (v )). replace ( ": :" , "::" )
3398
+ value ["value" ] = " " .join (v )
3368
3399
return
3369
3400
elif tok .type == "," :
3370
- value ["value" ] = ( " " .join (v )). replace ( ": :" , "::" )
3401
+ value ["value" ] = " " .join (v )
3371
3402
break
3372
3403
elif tok .type in self ._balanced_token_map :
3373
3404
v .extend (t .value for t in self ._consume_balanced_tokens (tok ))
0 commit comments