<br><div class="gmail_quote">On Fri, Sep 21, 2012 at 2:40 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Fri, Sep 21, 2012 at 12:32 PM, Philip Craig <<a href="mailto:philipjcraig@gmail.com">philipjcraig@gmail.com</a>> wrote:<br>
> On Fri, Sep 21, 2012 at 7:49 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
>> Hi Philip,<br>
>><br>
>> we had a discussion around the strategy for handling ast dumping<br>
>> fairly recently. I think the common agreement in the end was that<br>
>> instead of having an extra tool, we want to make clang's -ast-dump<br>
>> awesome.<br>
><br>
> Was this discussion on the mailing list? Any chance you could point me to it?<br>
<br>
</div><a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120716/060831.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120716/060831.html</a><br>
<div class="im"><br>
>> I don't know what your ultimate goal is here, but from my<br>
>> side any work that goes towards making clang -ast-dump better would be<br>
>> highly appreciated :)<br>
><br>
> My motivation was having some way of getting the structure of the AST<br>
> for a given piece of source code, so that it is easier to correctly<br>
> call the AST matchers to match that code. The issue with clang<br>
> -ast-dump is that it pretty prints decls and types. So would the goal<br>
> here be to add more command line options to clang to control how<br>
> -ast-dump prints the AST?<br>
<br>
</div>No, I think the goal is to dump decls and types in a sensible way :)<br></blockquote><div><br></div><div>More specifically, I think we agreed on changing -ast-dump from pretty-printing declarations to outputting them in the same LISP-style format, which is used for statements. I was going to implement that, but never had time to do this. If you're going to continue work on your utility, it would be much more valuable, if you instead improved clang's current -ast-dump option. In that case you consider to go this way, here's where to start:</div>
</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><font face="courier new, monospace">clang/lib/Frontend/ASTConsumers.cpp:120: A</font><font face="courier new, monospace">STConsumer *clang::CreateASTDumper(StringRef FilterString)</font></div>
</div></blockquote><div class="gmail_quote"><div>is a common entry point, used by "<font face="courier new, monospace">clang -cc1 -ast-dump</font>" and by "<font face="courier new, monospace">clang-check -ast-dump</font>". An additional benefit from this would be that after "-ast-dump" starts outputting the AST for declarations in a structured form, "-ast-dump-xml" will become useless and can be removed.</div>
<div><br></div><div>-- </div><div>Regards,</div><div>Alex</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> Are there any other areas where you think -ast-dump needs to be better?<br>
<br>
</div>As you said, decls and types need to be structured nicely. Also, a<br>
while ago Richard proposed a patch to add coloring, no idea how far he<br>
got (cc'ing him)<br>
<br>
Cheers,<br>
/Manuel<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
>><br>
>> Cheers,<br>
>> /Manuel<br>
>><br>
>> On Fri, Sep 21, 2012 at 1:17 AM, Philip Craig <<a href="mailto:philipjcraig@gmail.com">philipjcraig@gmail.com</a>> wrote:<br>
>>> Hi,<br>
>>><br>
>>> I've been writing a tool to print a clang AST. You can find it at<br>
>>> <a href="https://github.com/philipc/clang-ast" target="_blank">https://github.com/philipc/clang-ast</a>. I've been mostly writing this as<br>
>>> a learning exercise, but I would like to see if there is any wider<br>
>>> interest in the tool.<br>
>>><br>
>>> I'm new to clang, and interested in working on tooling. For this task,<br>
>>> it is important to have an understanding of the AST. I've found the<br>
>>> documentation at <a href="http://clang.llvm.org/docs/InternalsManual.html" target="_blank">http://clang.llvm.org/docs/InternalsManual.html</a> and<br>
>>> <a href="http://clang.llvm.org/docs/IntroductionToTheClangAST.html" target="_blank">http://clang.llvm.org/docs/IntroductionToTheClangAST.html</a> (is there<br>
>>> any more?), but I think it would be helpful to be able to print the<br>
>>> AST for source code to see how it is used in practice. I've found two<br>
>>> ways to do this currently, which aren't quite what I wanted:<br>
>>><br>
>>> clang --ast-dump<br>
>>> - pretty prints some parts, has too much internal info, more suited<br>
>>> for debugging use by clang developers<br>
>>><br>
>>> clang --ast-dump-xml<br>
>>> - incomplete and XML is too verbose for this purpose<br>
>>><br>
>>> Since RecursiveASTVisitor seems to be the API that will be used by<br>
>>> tool developers, I've been using RAV to print the AST. I've found a<br>
>>> few minor bugs in RAV as a result of this, which I'm in the process of<br>
>>> submitting.<br>
>>><br>
>>> One limitation of RAV is that the Visit methods aren't given<br>
>>> information about their relationship with their parent, so the tool<br>
>>> can only list all the children of a node, without distinguishing<br>
>>> between the LHS and RHS of an operator, for example. Is there any<br>
>>> desire to extend RAV to be able to do this?<br>
>>><br>
>>> I've been writing small code snippets to test printing the various<br>
>>> parts of the AST. If you want to see examples of the output of the<br>
>>> tool, this is included in the test cases. As a quick example, "void<br>
>>> foo() {}" is printed as:<br>
>>><br>
>>>   FunctionDecl<br>
>>>     DeclarationName foo<br>
>>>     FunctionNoProtoType<br>
>>>       BuiltinType void<br>
>>>     CompoundStmt<br>
>>><br>
>>> Finally, I've been trying to give a textual description of the AST<br>
>>> grammar in <a href="https://github.com/philipc/clang-ast/blob/master/ast.txt" target="_blank">https://github.com/philipc/clang-ast/blob/master/ast.txt</a>.<br>
>>> This is an attempt to give something similar to<br>
>>> <a href="http://docs.python.org/py3k/library/ast.html#abstract-grammar" target="_blank">http://docs.python.org/py3k/library/ast.html#abstract-grammar</a>. I'm not<br>
>>> sure if it is turning out to be that useful though.<br>
>>><br>
>>> Any comments welcome!<br>
>>><br>
>>> Thanks,<br>
>>> Philip<br>
>>> _______________________________________________<br>
>>> cfe-dev mailing list<br>
>>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>