[cfe-dev] Clarification for term "AST"

Manuel Klimek klimek at google.com
Sun Feb 24 12:16:59 PST 2013

On Sun, Feb 24, 2013 at 11:59 AM, Joshua Cranmer <pidgeot18 at gmail.com>wrote:

> On 2/24/2013 5:38 AM, Markus Elfring wrote:
>>  I can't say that I can think of a single time where I would ever want
>>> the raw parsed AST with no semantic analysis done on it.
>> Are you interested in detailed source code transformations after a
>> specific analysis on a control flow graph?
>> Do you see use cases to drill down from higher abstraction levels to the
>> abstract syntax tree to generate some adjustments?
> The short answer here is "no", because viewing refactorings as
> transformations on ASTs is wrong. Refactoring is really transforming source
> text to source text guided by high-level semantic rules; treating it as AST
> implementations will cause lots of grief when you try to reserialize that
> AST, thanks in large part to the complications of macros and templates
> (macros++).
>  How do you think about consequences and challenges like they are
>> demonstrated by the semantic patch language from the software "Coccinelle"?
>> http://coccinelle.lip6.fr/sp.**php <http://coccinelle.lip6.fr/sp.php>
> Semantic patching is very seductive, but it's a poor substitute when it
> comes to complicated refactorings. The use case I played with a few years
> ago was rewriting a C API into C++, which requires some semantic rules
> cumbersome to produce in an spatch-like format. The best example I have is
> "make the first argument to be 'derived' from MimeObject be the implicit
> this argument." Another one is "every object which is the implicit this
> argument cast to some other type is really just the implicit this argument,
> if the cast is a cast to the current class type or some superclass thereof".

And the clang AST actually works fine for building tools like that on top -
we're doing similar stuff on a daily basis based on the AST matchers and
Tooling/Refactoring libs.

If anybody really wanted to spend some time "fixing" the AST, I'd suggest
to look at how to introduce an ExpressionStatement instead of having all
Expressions be Statements :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130224/511f67c3/attachment.html>

More information about the cfe-dev mailing list