[cfe-dev] AST transformations
Olaf.Krzikalla at tu-dresden.de
Fri Mar 11 04:02:05 CST 2011
Am 10.03.2011 20:32, schrieb Vassil Vassilev:
> Here is what I did, I derive from clang::StmtVisitor and
> clang::DeclVisitor (both of them have RetTy), which I set to
> clang::Stmt* and clang::Decl* respectively. Then I traverse the
> TranslationUnit top-down and I can return whatever AST node I want. Like
> that you can replace the every specific type of AST node you want, when
> going up. Even you can send to the parent more complex structure (than
> clang::Stmt*, clang::Decl), containing complex context, which gives
> hints to the parent how to deal with the returned node.
To a certain degree I've just sketched that approach in the
"ConditionalOperator::setCond is gone" thread. However the problem with
this approach is, that you you can't use all the neat means (e.g.
rewriting, CFG creation) coming with clang anymore. How have you solved it?
> Note that it is extremely dangerous, because you can break the semantics
> of the AST. Keep in mind, that if you plan to inject new artificially
> created nodes they wouldn't have SourceLocation, etc, which causes
> problem with the accuracy of the diagnostics, for example.
Well, during and after my AST transformation phase there were no further
needs for built-in diagnostics.
> Even more, if
> you inject new node, you should make Sema think that it actually comes
> from the Parser, which is difficult because you don't have source, right?
Why should I have to deal with Sema at all? AST transformation and
rewriting don't care about Sema.
More information about the cfe-dev