Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ code parser/processor library

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]

`

like image 315
uray Avatar asked Dec 04 '25 17:12

uray


2 Answers

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:

  • Semantic Design frontend
  • Edison Design Group frontend

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.

like image 175
Pavel Minaev Avatar answered Dec 06 '25 08:12

Pavel Minaev


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

like image 23
BenG Avatar answered Dec 06 '25 08:12

BenG