开发者

C++ code parser/processor library

开发者 https://www.devze.com 2023-01-01 19:56 出处:网络
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 (

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
                                    ^
                                    |
      开发者_Python百科                        [i need this]

`


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.


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


  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.


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号