OpenC Plus Plus

From ArticleWorld

OpenC++ is a software tool that parses C++ source code to provide various analysis and extension functions. The project's status considers OpenC++ to be a C++ frontend library (lexer+parser+DOM/MOP) and source-to-source translator.


OpenC++ is widely used to develop C++ language tools. It includes a parser, a lexer and a complete DOM/MOP back-end that allow one to develop extensions to the language, platform-specific compiler enhancements, custom runtime metaobject protocol support and similar functions. Several notable software platforms use OpenC++.


The core of OpenC++'s usage is the meta-level program. A meta-level program specifies how a C++ program has to be analyzed and/or translated. This is simple to do for programmers, since it OpenC++'s meta language is none other than C++ itself. The OpenC++ compiler will then compile the meta-program and use it as a compiler plug-in for the actual C compiler. The C compiler later uses the functionality added by this plug-in to translate or to analyze the source program, using the meta-program as a base.

The heart of this meta-program is the Meta-object protocol (MOP). MOP is an object-oriented abstraction over an actual C++ compiler, exposed to the programmer so that he or she can implement whatever functionality he wants.

MOP types

There are several meta-object types that OpenC++ MOP defines. These are:

  • The Ptree metaobject, which is an abstraction of a parse tree generated by the parser when analyzing the program source code. It works as a representation of the actual text.
  • The Environment metaobjects, which abstract bindings between names and types.
  • The TypeInfo metaobjects, which represent the actual types.
  • The Class metaobjects, which represents the structural aspect of the program, but also allows subclasses and functions to be defined.
  • The member metaobjects, that allow introspection and the analysis of source code to be performed.