Question

Please go through if anyone has knowledge about Vera++ Or Static Analyser.

How can I implement complex C++ rules verification machine as a static analyzer? I want to implement complex rules like virtual function in base classes, identification of user defined variables like classes, structures etc. Variables scope like global, local, static etc. I understood Vera++ very well, Acc to My understanding it's doing only token parsing, Context of language needs to be implemented via scripts (and implemented context can be too complicated if language is like C++); because differentiating between a *b; (which could be a pointer b of class type a) OR a *b;(could simply be a multiplication between two in variables);

I even feels that implementation of complex rules may need some compiler like State Machines so that scripts can understand the context of language.

My question is just to ask:

  1. Is my understanding correct in terms of Static Analyzer Rules implementation.

  2. Can you Please guide me little bit how can i proceed for this task accomplishment.

  3. Can these task be simplified by REGEXP of tcl.

  4. Is there any specific design approach you can suggest for good implementation of Solid C++ Code Analyzer.

Was it helpful?

Solution

I would suggest using a full-blown c++ parser instead.

Clang is a suit of libraries that fully understand C++ because the very libraries that you can use for your analysis are those used by the compiler (talk about dog fooding). You can access several "layers": Abstract Syntax Tree, Control Flow Graph. And there is already a static analyzer framework in place for which you can implement passes.

Finally, and perhaps the most interesting thing, you can interact from C++ OR C, and there are even Python bindings (though notably incomplete) on top of the C interface.

Honestly, given the god-aweful complexity of C++ grammars, it would take a masochist to use anything short of a real semantic parser nowadays.

Other parsers (courtesy of Ira Baxter) include:

  • Elsa (open source)
  • DMS (commercial)
  • EDG (commercial, C++ front-end used to implement compilers)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top