I need to write a C++ code coverage program that takes in another C++ program (given in a file) and enhances or adds below to each of its statement a call to a function that increases a counter. But, I need to use a different counter for each type of expression (i.e. I need to figure how many expressions there are of each type). For this I need to figure the type of each C++ expression. IMO I need to use a parser API to parse each line to get its type.
Do you see a better solution?
Otherwise, where can I find parsing API?
Thanks
A “parser” API won’t give you type information. It will at best give you access to ASTs.
You need a full C++ front end, that can parse C++ code, do name and type resolution, and can compute the type, literally, of each expression. On top of that, you need to insert the instrumentation that you want, and then spit out compilable source code.
Our DMS Software Reengineering Toolkit with its C++ Front End has all the capabilities necessary to do this.
DMS has been used to build test coverage and profiler tools for C++ (and many other languages); you can even download and try one to see what they are like. You may find this paper on building test coverage tools with DMS interesting as a baseline for what you want to do. Your variant needs the type inference but otherwise it isn’t a lot different.