Dumping AST information to other formats

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 28 02:31:04 PST 2018


On 27/11/2018 09:49, Stephen Kelly via cfe-commits wrote:
> On 26/11/2018 19:20, Aaron Ballman via cfe-commits wrote:
>> Once upon a time, there was -ast-print-xml. This -cc1 option was
>> dropped because it was frequently out of sync with the AST data. It is
>> right to ask: why would JSON, etc be any different? This is still an
>> open question, but a goal of this implementation will be to ensure
>> it's easier to maintain as the AST evolves. However, this feature is
>> intended to output a safe subset of AST information, so I don't think
>> this feature will require any more burden to support than -ast-dump
>> already requires (which is extremely limited). 
> 
>> I wanted to see if there were concerns or implementation ideas the
>> community wanted to share before beginning the implementation phase of
>> this feature.
> 
> Hi Aaron,
> 
> As you know, I've already done some work in this area.
> 
> I split the ASTDumper.cpp into multiple classes so that the traversal of 
> the AST is separate to the printing of it to the output stream. You can 
> see the proof of concept here:
> 
>   https://github.com/steveire/clang/commits/extract-AST-dumping


For those following along at home, I implemented a Proof of Concept JSON 
dumper on that github branch in order to show the benefit of splitting 
the traversal logic which is central to my design.

You can play with it here:

  http://ec2-52-14-16-249.us-east-2.compute.amazonaws.com:10240/z/JGBcRH

  http://ec2-52-14-16-249.us-east-2.compute.amazonaws.com:10240/z/fIJjV1

This shows how simple it would be to maintain alternative output formats 
such as JSON and CBOR, which may interest clangd folks and others who 
want a binary AST dump.

Thanks,

Steve.



More information about the cfe-commits mailing list