Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Introspection: Enumerate available classes and methods in a C++ codebase

I'm working on some custom C++ static code analysis for my PHD thesis. As part of an extension to the C++ type system, I want to take a C++ code base and enumerate its available functions, methods, and classes, along with their type signatures, with minimal effort (it's just a prototype). What's the best approach to doing something like this quickly and easily? Should I be hacking on Clang to spit out the information I need? Should I look at parsing header files with something like SWIG? Or is there an even easier thing I could be doing?

like image 289
Derek Thurn Avatar asked Feb 22 '23 13:02

Derek Thurn


2 Answers

GCCXML, based on GCC, might be the ticket. As I understand it, it collects and dumps all definitions but not the content of functions/methods.

Others will likely mention CLANG, which certainly parses code and must have access to the definitions of the symbols in a compilation unit. (I have no experience here).

For completeness, you should know about our DMS Software Reengineering Toolkit with its C++ Front End. (The CLANG answers seem to say "walk the AST"). The DMS solution provides an enumerable symbol table containing all the type information. You can walk the AST, too, if you want.

Often a static analysis leads to a diagnosis, and a desire to change the source code. DMS can apply source-to-source program transformations to carry out such changes conditioned by the analysis.

like image 177
Ira Baxter Avatar answered May 10 '23 19:05

Ira Baxter


I heartily recommend LLVM for statical analysis (see also Clang Static Analyzer)

like image 26
sehe Avatar answered May 10 '23 21:05

sehe