views:

94

answers:

3

is there any library that parse a source code of C++ to produce lets say, call graph, class inheritance tree, flow control, class member list or anything as a ready to use graph or structure in code (not in diagram image).

to make it more clear, suppose to generate call graph image, there will be a process like this:

`

C++ source -> parser -> intermediate structure -> renderer -> call graph image
                                    ^
                                    |
                              [i need this]

`

A: 
  1. there's the insides of GCC. It's sort of structured as a library.
  2. there's the Eclipse CDE packages that parse C++ well enough for the IDE, which might or might not be well enough for you.
bmargulies
A: 

The LLVM family of libraries is probably your best bet. The support for C++ was not complete last I checked, though.

BennyG
+2  A: 

It depends on how precise you want the parsing to be. If you want it to be absolutely accurate (i.e. shouldn't miss a class because of some overcomplicated macro or template metaprogramming that it couldn't handle), then you need a proper C++ front end for this, and I'm not aware of any that are both free and easily reusable.

If you're willing to pay, then there are at least two options:

EDG is used to drive IntelliSense in VC++2010, which is pretty impressive, and seems to be very accurate - in my experience, it handled completion on polymorphic Boost.Lambda properly (not surprising, given that it also drives EDG C++ compiler, which obviously have to get correct input).

I don't know much about Semantic Design frontend or its users, but Ira Baxter from there is on StackOverflow, so I'll leave it to him to provide more extensive information about their product.

If you want free but imperfect, then perhaps GCC_XML is good enough for you.

Pavel Minaev
GCC_XML only provides declaration information. There is no information provided by it about code, so you can't use it to produce call graphs.
Ira Baxter
See http://semanticdesigns.com/Products/DMS/FlowAnalysis.html for flow analysis and call graph information available with DMS in general. We don't yet deliver that information for C++, although we do all of that for C. The C++ front end *does* parse, build ASTs, and build complete symbol tables.
Ira Baxter