[cfe-dev] Future of AST transformation
Olaf Krzikalla
Olaf.Krzikalla at tu-dresden.de
Wed Jul 18 04:56:45 PDT 2012
Hi @clang,
I'm working at my source-to-source transformator based on clang for
quite some time now. However, my last clang update constantly causes me
some serious headaches. Mainly it is the new expr::EvaluateAsRValue
framework, which asserts like hell. Of course rightly since I cannot
preserve all - often hidden - AST invariants during transformations.
Some assertions were fixable, but for a lot of others I have no clue.
An example: transforming a+=b to a=a+b works like this in my framework:
CompoundAssignOperator* Node;
// compute binOpc
Expr* firstRhs = Clone_(Node->getLHS());
firstRhs->setValueKind(VK_RValue);
BinaryOperator* TC = Assign_(
Node->getLHS(),
BinaryOp_(firstRhs, Node->getRHS(), binOpc));
I had to figure out that I had to set the value kind. But in the end
that was still an easy fix. But recently a new problem popped up:
struct A { float x; };
A a;
a.x += y; // assertion: APValue.h:306: isStruct() && "Invalid accessor"
This comes from the fact that "a" in "a.x" itself is treated as an
lvalue. And this is only a small example of all the assertion hell I've
got with the expr::EvaluateAsRValue framework.
So my question is whether there is or there will be a AST transformation
framework capable of transforming expressions like above? Or whether
clang/AST transformation itself is a dead end in the long run?
Best regards
Olaf Krzikalla
More information about the cfe-dev
mailing list