Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CppHeaderParser/CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2375,13 +2375,31 @@ def _evaluate_method_stack(self):
self.stack = []
self.stmtTokens = []

_function_point_typedef_format = re.compile(r".*?\(.*?\*(.*?)\).*?\(.*?\).*?")

def _function_point_typedef_parse(self, stack):
idx = stack.index("typedef")
expression = "".join(stack[idx + 1 :])
m = self._function_point_typedef_format.match(expression)
if m is None:
return {}

name = m.group(1)
s = " ".join([i for i in stack if i != name])
r = {"name": name, "raw": s, "type": s}
return r

def _parse_typedef(self, stack, namespace=""):
if not stack or "typedef" not in stack:
return
stack = list(stack) # copy just to be safe
if stack[-1] == ";":
stack.pop()

r = self._function_point_typedef_parse(stack)
if len(r) == 3:
return r

while stack and stack[-1].isdigit():
stack.pop() # throw away array size for now

Expand Down
18 changes: 18 additions & 0 deletions test/test_CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4038,5 +4038,23 @@ def test_fn(self):
self.assertEqual(m["parameters"][0]["type"], "typename TP<D >::S")


class FunctionPointerParse(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""
typedef int U32;
typedef unsigned int( * p )(int, int);
typedef int( * mmmmp )(int, int) ;
""",
"string",
)

def test_fn(self):
c = self.cppHeader
self.assertEqual(c.typedefs["U32"], "int")
self.assertEqual(c.typedefs["p"], "typedef unsigned int ( * ) ( int , int )")
self.assertEqual(c.typedefs["mmmmp"], "typedef int ( * ) ( int , int )")


if __name__ == "__main__":
unittest.main()