ast-print-xml for C++ and templates

Hi,

I am working on a little documentation tool for C++. For this I need
to parse C++ files to some degree. For this purpose I want to extract
from source/header files what function signature gets defined/declared
in what line.

I figured out that all I need can be done perfectly with ast-print-xml as long
as functions and classes are not templated.

So for clang-developers this question might sound stupid: Is this technically
not possible. I mean is the information I am looking for "not in the AST"? Or
does the ast-print-xml just skip certain template-nodes?

Just to make sure that I make clear what I am looking for. If I have a code like

template <typename T>
    int
    dummy(const T a);

// ....

template <typename T>
int
dummy(const T a)
{
    // ...
}

I merely would like to extract the information:

1) Funktion "template <typename T> int dummy(const T a)" declared in line ...
2) Funktion "template <typename T> int dummy(const T a)" defined in line ...

Thanks,

Michael

Are you sure you want to write a new tool for this ? Did you consider using an existing code introspection / documentation tool instead ?
Synopsis can give you the information you want, as it is highly configurable (e.g., what kind of objects are you interested in, in what scope(s), etc.)

You may just write your own little "formatter" plugin (in Python) that prints the desired information to stdout, if you don't want an actual report in HTML or some other markup language.

FWIW,
         Stefan

The AST has all of this information, but the XML printer isn’t anywhere near complete and isn’t kept up-to-date. Personally, I wouldn’t use it: I think you’re better off using libclang, writing a Clang plugin, or extending/customizing something like Synopsis.

  • Doug