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]

`

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
See 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.
Note that GCC, itself, contains a "free and complete" parser by necessity. The trick is that it would need extraction from GCC into a stand-alone library. That may not be very easy, because it probably is not modularized enough to just "yank out", and likely comprises many 10s of 1000s of lines of code so that you would have a lot of work to do to get all the various annoying little bits together in one spot AND then write a neato interface on top of it.
3

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

1 Comment

More precisely, the OP wants Clang.
1

Libclang (part of LLVM family) provide good parser for C++. The library uses C but has a very good python bindng. I am currently developing a python library that wraps libclang a bit further from the compiler and closer to the end user of the data structure (by the way, patching imperfections in the LLVM parser, for example by zipping into template parameters): https://pypi.org/project/devana/

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.