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

Douglas Gregor dgregor at apple.com
Fri May 13 09:07:30 PDT 2011


On May 13, 2011, at 8:45 AM, devel hevel 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]).

I'm fairly certain that GCC-XML handles namespaces; it doesn't keep as much source information as Clang does, but it handles all of C++.

> 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.

You can write an ASTConsumer that prints all of the functions; see, e.g., the PrintFunctionNames example.

Alternatively, you can use the C interface to Clang's ASTs, libclang: http://clang.llvm.org/doxygen/group__CINDEX.html

	- Doug



More information about the cfe-dev mailing list