1

I would like a simple windows tool for converting c++\c header and source code to xml for analysis.

For instance,

#include "something.h"
void CSomething::CheckIt(DWORD x)
{
    if (x > 1)
    { 
       // Do something
    }
}

Will be converted to

<XML>
<CodeFile>
<IncludeCommand filename="something.h"/>

<Function namespace="CSomething" name="CheckIt" returnType="void"/>
<Arguments>
<Argument name="x" type="DWORD" />
</Arguments>
<Body>
<IfCondition>
<Expression ... />
<Body>
...
</Body>
</IfCondition>
</Body>
</Function>

</CodeFile>

Commercial products are also ok, but open source (simple) solutions are best.

user3696279
  • 99
  • 1
  • 5
  • 1
    TinyXml is a nice tool. [download TinyXml](https://www.google.ro/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0ahUKEwi8hbiizcrOAhVSOMAKHc6oBk8QFggrMAM&url=https%3A%2F%2Fsourceforge.net%2Fprojects%2Ftinyxml%2F&usg=AFQjCNEdqxbDbEsPPH3ZUtdP7CHX-BjQyg) and [documentation](http://www.grinninglizard.com/tinyxmldocs/index.html) – Mara Black Aug 18 '16 at 09:02

2 Answers2

3

The words "simple", "C++" and "tool" don't belong in the same sentence.

If you want to analyze C++ code, you presumably want accurate answers, and that requires accurate parsers.

Our DMS Software Reengineering Toolkit with its C++14 front end can do this. DMS runs under windows, and its C++ front end can handle ANSI C++14, GCC/Clang or Visual Studio dialects of C++.

You can see example ASTs produced by DMS at get human readable AST from c++ code DMS has an option to export such ASTs as XML, which would satisfy OP's request as explicitly stated.

He probably doesn't really want this. For any serious-size chunk of source code, such XML files are huge. A thousand line C++ program will produce approximately 10,000 lines/500K characters of XML output. This is clumsy to produce/read/process. If you include typical header files, you can easily reach 100K lines of C++ code; if you leave them out, you can't analyze the code very well. DMS itself provide lots of machinery to navigate the ASTs it generates; it will be a lot easier to write an analyzer using the machinery provided by DMS than to re-invent all of that to work with XML.

As a practical matter, to do any serious analysis of C++ you need what amounts to symbol table information, and you will probably want control and data flow analysis information. DMS can provide these, too. See Life After Parsing.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
1

Take a look at gcc_xml and then proceed to its successor CastXML

Tom Wilson
  • 698
  • 6
  • 9