[cfe-dev] for-range; or: distinct source and semantic ASTs

Chris Lattner clattner at apple.com
Tue Dec 14 13:04:45 PST 2010


On Dec 14, 2010, at 9:15 AM, Sebastian Redl wrote:
> Once again I'm pondering the C++0x for-range loop. I'm not sure how it would best fit into Clang.

Cool

> And now I want to find all references to the begin function. Then a for-range loop over mycollection is such a use, because it calls this function.
> 
> On the other hand, clients interested in the source representation (e.g. the pretty printer) want the original code, which is not easy to regenerate from the rewritten form. (For example, the declaration of the loop variable has gained an initializer.)
> Unfortunately, I don't think our AST supports having distinct "source view" and "semantic view" tree visitation strategies, does it? How would I best implement such a case?

I think it is best to represent it as a source-level representation.  The two clients that should "lower" it are the CFG and CodeGen.  If there are non-obvious things that sema does that would be bad to reconstruct (e.g. name lookups), then those should be cached as instance variables in the AST node.

-Chris



More information about the cfe-dev mailing list