[cfe-dev] ConditionalOperator::setCond is gone

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Fri Mar 11 01:36:11 PST 2011


Am 10.03.2011 17:11, schrieb Douglas Gregor:
> Several things come to mind immediately:
>
> 	1) There's *no* checking that the types of the replacement expressions actually make sense within their node. If the type changes
> 	2) If any temporaries are contained in the new subexpression (or were in the old subexpression that was replaced), those temporaries need to be bound and noted in an outer expression
> 	3) A number of properties, including type- and value-dependent, whether there is a parameter pack in the subexpression, etc., are incrementally computed. If replacing a subexpression changes any of those, you need to propagate that change upward.
Given the ongoing discussion in "AST transformations" there is the need 
for a transformation capability. After thinking about the points made 
there, the points made here, the experience collected during 1.5 years 
transforming ASTs and also one of your points that lead to the removal 
of the AST XML printer I came to the conclusion, that the clang AST in 
its current form is not an abstract syntax tree (with emphasis on 
syntax!) anymore. Not only the nodes are augmented with semantic stuff, 
but some nodes by its own are there for semantic reasons only 
(ImplicitCastExpr springs to mind and indeed that node causes some 
trouble from time to time).
So what we would need is a pure syntax tree with the taxonomy of the 
current AST and the source locations only. Nothing more (e.g. not even 
return types for expressions). Such a tree could also be subject of XML 
streaming, which then only represents pure syntax (omitting e.g. 
references to types, which are clang-AST specific) but nothing more.
However, I don't consider the introduction of yet another layer 
containing a bunch of new classes mirroring the AST taxonomy a good 
solution.
A solution I could like:

class MutableASTNode
{
   // the clang AST node which is represented by this node:
   Stmt* origin;

   // children of this node, interpretation of the index
   // depends on the actual type of the origin
   // (which can be computed via RTTI)
   SmallVector<MutableASTNode*, 4> children;

   // this courtesy could be introduced
   MutableASTNode* parent;

public:
   // as minimal as possible:
   // node type, source range, children manipulation,
   // rewrite functionality (maybe including XML)
};

Unfortunately such a solution has its own drawbacks. E.g. it is not 
possible to use the current rewriter for MutableASTNode, as the rewriter 
traverses the original AST. Same is true for all the static analyzer 
functionality.
So maybe there is another idea?


Best Olaf



More information about the cfe-dev mailing list