File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -2375,13 +2375,30 @@ def _evaluate_method_stack(self):
2375
2375
self .stack = []
2376
2376
self .stmtTokens = []
2377
2377
2378
+ _function_point_typedef_format = re .compile (r".*?\(.*?\*(.*?)\).*?\(.*?\).*?" )
2379
+ def _function_point_typedef_parse (self , stack ):
2380
+ idx = stack .index ("typedef" )
2381
+ expression = "" .join (stack [idx + 1 :])
2382
+ m = self ._function_point_typedef_format .match (expression )
2383
+ if m is None :
2384
+ return {}
2385
+
2386
+ name = m .group (1 )
2387
+ s = " " .join ([i for i in stack if i != name ])
2388
+ r = {"name" : name , "raw" : s , "type" : s }
2389
+ return r
2390
+
2378
2391
def _parse_typedef (self , stack , namespace = "" ):
2379
2392
if not stack or "typedef" not in stack :
2380
2393
return
2381
2394
stack = list (stack ) # copy just to be safe
2382
2395
if stack [- 1 ] == ";" :
2383
2396
stack .pop ()
2384
2397
2398
+ r = self ._function_point_typedef_parse (stack )
2399
+ if len (r ) == 3 :
2400
+ return r
2401
+
2385
2402
while stack and stack [- 1 ].isdigit ():
2386
2403
stack .pop () # throw away array size for now
2387
2404
Original file line number Diff line number Diff line change @@ -4038,5 +4038,23 @@ def test_fn(self):
4038
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