[cfe-dev] AST XML dump
Douglas Gregor
dgregor at apple.com
Wed May 13 08:28:54 PDT 2009
On May 13, 2009, at 3:43 AM, Olaf Krzikalla wrote:
> Hi @clang-community,
>
> I've recently started a C(++)-source-to-source translation project.
> The
> project is open-source and thus all the components involved needs to
> be
> open-source too.
> The goal of the project is to semi-automatically rewrite and optimize
> parts of C(++) sources (C++ instead of C is a 'very-nice-to-have
> feature').
> Currently I'm still in the evaluation phase. Obvisiously the first
> thing
> I need is a parser. Beside gcc I found clang, sparse and the Ravi C
> parser as open source projects. Are there any others out there?
If C++ is important to you, GCC and Clang are the only two that are
likely to handle the whole C++ language in the "near" future.
> From among these three projects clang seems to be the most promising
> project for my needs as it is already able to deal with some C++ (and
> according to cfe-commits the community is very active in this area).
Clang C++ is very active and support for C++ is improving rapidly.
That said, we're still not to the point where we can handle even small
applications (because we can't parse the C++ standard library headers
yet). We're working on it!
> However one thing I badly need is a better AST dump. I'm now going to
> implement my own XML dump in clang since the current AST dump is
> hard to
> parse. Any objections? (of course I can do what I want to do anyway,
> but
> in the end I naturally want to contribute my additions to the clang
> project - so I better ask).
A good XML dump for Clang's representation would be a great addition
to Clang. You might consider looking at GCC-XML's output format, since
it is a decent representation of the C++ language in XML. GCC-XML is
here:
http://www.gccxml.org/HTML/Index.html
Matching the GCC-XML format means that other tools meant to work with
GCC-XML (e.g., Pyste) could also work with Clang as a front end.
Since you mentioned source-to-source translation... Clang has a
rewriter that allows you to replace certain parts of the source code
(based on, e.g., a source range) with other code, without disturbing
comments or formatting. If you're doing small, targeted rewrites in
your source-to-source translation, it's something else to look at (and
you won't need XML output to do it). Check out the Objective-C
rewriter in the Clang source tree for an example (tools/clang-cc/
RewriterObjC.cpp).
- Doug
More information about the cfe-dev
mailing list