This is hard to do with perl’s extended regular expressions, which are considerably more powerful than anything in C++. I suggest a different tack:
First get rid of the things that don’t look like functions such as data (look for the D designator). Stuff like virtual thunk to this
, virtual table for that
, etc., will also get in your way; get rid of them before you do you the main parsing. This filtering is something where a regexp can help. What you should have left are functions. For each function,
-
Get rid of the stuff after the final closing parenthesis. For example,
Foo::Bar(int,double) const
becomesFoo::Bar(int,double)
. -
Strip the function arguments. The problem here is that you can have parentheses inside the parentheses, e.g., functions that take function pointers as arguments, which might in turn take function pointers as arguments. Don’t use a regexp. Use the fact that parentheses match. After this step,
Foo::Bar(int,double)
becomesFoo::Bar
whilea::b::Baz<lots<of<template>, stuff>>::Baz(int, void (*)(int, void (*)(int)))
becomesa::b::Baz<lots<of<template>, stuff>>::Baz
. -
Now work on the front end. Use a similar scheme to parse through that template stuff. With this, that messy
a::b::Baz<lots<of<template>, stuff>>::Baz
becomesa::b::Baz::Baz
. -
At this stage, your functions will look like
a::b:: ... ::ClassName::function_name
. There is a slight problem here with free functions in some namespace. Destructors are a dead giveaway of a class; there’s no doubt that you have a class name if the function name starts with a tilde. Constructors are a near giveaway that you have a class at hand — so long as you don’t have a namespaceFoo
in which you have defined a functionFoo
. -
Finally, you may want to re-insert the template stuff you cut out.
5
solved Extracting class from demangled symbol