[cfe-dev] Howto extract C++ functions with Clang?

Eli Friedman eli.friedman at gmail.com
Fri May 13 09:09:37 PDT 2011


On Fri, May 13, 2011 at 8:45 AM, devel hevel <devel.hevel at gmx.de> wrote:
> Hi guys,
>
> I want to use Clang to extract all C++ function signatures, from a C++ header file and transfer it to a easy to parse/work format (the best would be XML or something [I knew about GCCXML but it does not help me because it could not manage namespaces]).
>
> E.g. I have a function in my header file like:
> int makeSometing(int a, int b);
>
> now I want to run Clang and get a output file which I can simply parse to extract all function signatures.

There really isn't anything quite like that at the moment, but it
shouldn't be too hard to write... it should be a very straightforward
RecursiveASTVisitor (there's an example of a very simple one in
lib/Frontend/BoostConAction.cpp.)  See examples/PrintFunctionNames for
how to write your own little AST consuming utility.  I'd say the hard
part is actually figuring out what exactly the output should look
like.

Please feel free to ask any questions if you need help, either here or
on the IRC channel (#llvm on irc.oftc.net).  And I think other people
would be interested in this work, so if you get something usable,
please send it here.

-Eli



More information about the cfe-dev mailing list