File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -2375,13 +2375,31 @@ def _evaluate_method_stack(self):
2375
2375
self .stack = []
2376
2376
self .stmtTokens = []
2377
2377
2378
+ _function_point_typedef_format = re .compile (r".*?\(.*?\*(.*?)\).*?\(.*?\).*?" )
2379
+
2380
+ def _function_point_typedef_parse (self , stack ):
2381
+ idx = stack .index ("typedef" )
2382
+ expression = "" .join (stack [idx + 1 :])
2383
+ m = self ._function_point_typedef_format .match (expression )
2384
+ if m is None :
2385
+ return {}
2386
+
2387
+ name = m .group (1 )
2388
+ s = " " .join ([i for i in stack if i != name ])
2389
+ r = {"name" : name , "raw" : s , "type" : s }
2390
+ return r
2391
+
2378
2392
def _parse_typedef (self , stack , namespace = "" ):
2379
2393
if not stack or "typedef" not in stack :
2380
2394
return
2381
2395
stack = list (stack ) # copy just to be safe
2382
2396
if stack [- 1 ] == ";" :
2383
2397
stack .pop ()
2384
2398
2399
+ r = self ._function_point_typedef_parse (stack )
2400
+ if len (r ) == 3 :
2401
+ return r
2402
+
2385
2403
while stack and stack [- 1 ].isdigit ():
2386
2404
stack .pop () # throw away array size for now
2387
2405
Original file line number Diff line number Diff line change @@ -4038,5 +4038,23 @@ def test_fn(self):
403
8000
8
4038
self .assertEqual (m ["parameters" ][0 ]["type" ], "typename TP<D >::S" )
4039
4039
4040
4040
4041
+ class FunctionPointerParse (unittest .TestCase ):
4042
+ def setUp (self ):
4043
+ self .cppHeader = CppHeaderParser .CppHeader (
4044
+ """
4045
+ typedef int U32;
4046
+ typedef unsigned int( * p )(int, int);
4047
+ typedef int( * mmmmp )(int, int) ;
4048
+ """ ,
4049
+ "string" ,
4050
+ )
4051
+
4052
+ def test_fn (self ):
4053
+ c = self .cppHeader
4054
+ self .assertEqual (c .typedefs ["U32" ], "int" )
4055
+ self .assertEqual (c .typedefs ["p" ], "typedef unsigned int ( * ) ( int , int )" )
4056
+ self .assertEqual (c .typedefs ["mmmmp" ], "typedef int ( * ) ( int , int )" )
4057
+
4058
+
4041
4059
if __name__ == "__main__" :
4042
4060
unittest .main ()
You can’t perform that action at this time.
0 commit comments