5

i have a big workspace containing a lot of source-files (*.cpp, *.c, *.h, *.hpp etc.) and want to do some automated analysis to it.

I already have a coverage-analysis using the cobertura-format which tells me the lines of code which has been executed during a test but now i want to do an Analysis at function-level so i have to map the executed lines-of-code to it's functions.

I tried to implement the listing of functions by myself but it's extremely complicated to find all the different types of functions (inlines, virtuals, de- / constructors, constructors of structs etc)

So does anybody know a tool who could be used to create a list of functions contained in a given source-file so that i can map the line-of-code analysis to it?

Many thanks

  • Alternatively you could get a coverage tool that provided you that mapping directly. – Ira Baxter Dec 13 '15 at 22:51
1

Our DMS Software Reengineering Toolkit with its C++14 front end can be used to do this.

DMS is a general purpose program analysis and transformation tool based on compiler technology. It parses source code based on the front end it is using, to compiler data structures such as ASTs stampled with source location information, symbol tables and control flow graphs. It provides a variety of libraries and DSLs for specifying actions over those compiler data structures, including walking ASTs, pattern matching over ASTs using surface syntax patterns, modifying the ASTs, and finally prettyprinting any modified code back to compilable source form with comments.

To handle OP's task, one would configure DMS to "just" parse the source code (you can skip name resolution and flow analysis for this task) to build ASTs for the files of interest. Then using the line numbers, one could walk the AST looking for nodes that match the line numbers, pick out the function subtree corresponding to the node, and prettyprint just those subtrees to see the entire function definition, or prettyprint just the function signature. Voila.

An alternative approach would parse the files and then do name resolution. Traversing the symbol table is easy and provides access to the function signature, and location by virtue of references to the function's AST.

In either case, rather than just printing function names/signatures/bodies, one could use DMS to implement the static analyses of choice.

DMS has been in use analyzing and transforming large C++ code bases for over a decade.

I'm the author, so don't consider this as a recommendation. I'm documenting its existence as a solution.

1

The first option might be to use a code documentation generator tool such as doxygen. If you tell it to include undocumented functions then it can give you such gems as which functions are in which files and also call and caller maps.

Doxygen Features:

  • Free
  • Cross Platform OS-X, Linux & Windows
  • Lots of diagramming options
  • Can process C++, C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, VHDL, Tcl, and to some extent D
  • Can also document your code from the comments producing documentation in HTML, Latex, RTF, PostScrript, PDF, Compressed HTML or man.

I also use SourceMonitor which can monitor your code for complexity and gives a list of which functions are in which files.

SourceMonitor features:

  • Free
  • Windows only - XP..
  • Collects metrics in a fast, single pass through source files.
  • Measures metrics for source code written in C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML.
  • Includes method and function level metrics for C++, C, C#, VB.NET, Java, and Delphi.
  • Export as XML or CSV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.