[GCC-XML] MetaCpp information

Stefan Strasser sstrasser at systemhaus-gruppe.de
Tue Mar 8 13:01:39 EST 2005


here's some information about a project you might be interested in:

What?
-----
MetaC++
It is a library which is able to read and write C++ source code and
makes the tree available to its clients by API and by a XML format it
can read and write.
Parsing is done by a patched GCC.
The tree is a representation of language constructs, not a syntax tree.

Why?
-----
It's primarily aimed at source-to-source code translators, but can also
be used by source code analysis tools, stub generators, source-to-UML
converters, etc.
By using GCC as parser it has good C++ language support.

Where?
-----
http://www-user.uni-bremen.de/~strasser/metacpp/


Language Support? Status?
-----
"Alpha" status.
Full C++ should work, including templates. It has been tested with C++
STL and parts of boost.
Statements, i.e. function bodies, are ignored in this version, so no
full translation yet, but it's already usable for header translation and
source code analysis which don't need bodies.
The most common expressions for initializers and template specialization
arguments are supported. Others are still ignored, and will be supported
in the next version along with function bodies.
Rewriting of boost is not yet working completely because of advanced
initializer expressions to constants which are then used as
instantiation arguments, reading works.



API Documentation?
-----
UML Diagrams:
http://www-user.uni-bremen.de/~strasser/metacpp/uml.pdf


XML Example?
-----

C++ std string header as gzipped XML:
http://www-user.uni-bremen.de/~strasser/metacpp/string.xml.gz

There are many other things included from this header, one of the last
TemplateClassDefinitions inside NamespaceDefinition "std" is
"std::basic_string". (Id 10339)

Generated output:
http://www-user.uni-bremen.de/~strasser/metacpp/string.cpp



Code Example?
-----
Virtually inherit all classes from class "base":

object<ClassDefinition> base;
//find or create "base"

object<TranslationUnit> tu;
Code::InputFile input("in.cpp");
input >> tu;

TranslationUnit::tree_iterator<ClassDefinition>
it=tu->find_recursive<ClassDefinition>();

for(;it != tu->end();++it){
     object<BaseSpecifier> baseSpec=BaseSpecifier::New();
     baseSpec->SetClass(base);
     baseSpec->SetVirtual();
     it->GetBases().push_back(baseSpec,*it);
}

Code::OutputFile output("out.cpp");
output << tu;



You never want to change all elements, including STL etc.!
-----
Yes. There will be some mechanism to mark elements with attributes when
it is source-to-source ready(see "Language Support"), something like:

persistent class MyDatabaseObject;
distribute void function();

For now you can decide this only by language constructs(its name, what
namespace it is in, etc.)


XML format?
-----
You can use the library for reading and writing. However, the xml format
is automatically derived from the object model,data field "isVirtual"
in class "BaseSpecifier" is called "BaseSpecifier.IsVirtual" in xml
files. Normal fields and pointer<>'s are attributes, element<>'s and
list<>'s are subnodes.



-- 
Stefan Strasser



More information about the gccxml mailing list