[cfe-dev] AST XML dump

Douglas Gregor dgregor at apple.com
Thu May 21 13:57:24 PDT 2009


Hi Olaf,

On May 20, 2009, at 6:01 AM, Olaf Krzikalla wrote:
> Thanks for your comments. By now I understand why Sebastian objected  
> at first of all. I initially used the organization that was used for  
> AST dumping.
> But I've changed that and thus became really minimal intrusive.

Great!

> Find attached another patch which respected some comments and should  
> now compile out of the box (tested with VC and cygwin) with the  
> current revision. I also added the output for ast-printing.c as  
> found in the test suit. As you can see the _Complex type is one of  
> the features not implemented yet.

Okay, looks good. I've committed your patch, after making two small  
adjustments:

   - Removed order_QualType; we already had a similar QualTypeOrdering  
in clang/AST/TypeOrdering.h
   - Moved the XML-dumping functionality into Frontend, as Sebastian  
suggested.

> Douglas Gregor schrieb:
>> 1) Why do we need to build an in-memory representation of the XML  
>> document just to print it? The in-memory representation itself  
>> isn't likely to be useful for much, since we're not providing any  
>> way of directly manipulating the in-memory representation. Would it  
>> be possible, instead, to stream the XML representation to disk  
>> directly, rather than building it all in memory? Doing so would  
>> save a lot of memory and should improve performance, since we won't  
>> be doing so much string copying and manipulation. Also in the same  
>> vein: there are quite a few std::map's to strings. These should  
>> probably be llvm::DenseMaps, and is it possible to map to something  
>> more efficient than a std::string?

This is still an interesting question for me, but it's not critical.

>> 2) I see that you've added a dumpXML routine into Stmt. Is there  
>> some benefit to having this as a method on Stmt, or can we just  
>> separate the XML-dumping functionality completely, putting it all  
>> into an AST consumer?
> Most of these things are done by now.

Looks good.

>> 3) I feel that it is very important that we have a proper XML  
>> schema before we claim to generate good XML. It's also important  
>> for testing: we'd like to be able to, e.g., generate XML from some  
>> translation unit and then verify that the XML meets the known schema.
>>
> Documentation is indeed the most important TODO. However I'm not  
> completely convinced by the current format yet.  I had some hope  
> that there is already an existing inter-language de-facto standard  
> for ASTs but beside GENERIC I didn't found anything. And at a first  
> glance GENERIC seems to be too low level at least for my purposes.

It doesn't look like there is such a standard, unfortunately.

>> It might be better to use the macro invocations in include/clang/ 
>> AST/TypeNodes.def to enumerate and switch on the various kinds of  
>> type nodes. It's generally cleaner, and protects this code better  
>> against changes in the type hierarchy.
> Thats another TODO. In fact I don't like all the dyn_cast chains  
> either.

Okay.

	- Doug



More information about the cfe-dev mailing list