[aspectc-user] Modifying C++ code?
Gordon Schumacher
gordon at rebit.com
Thu Oct 23 01:49:38 CEST 2008
Okay, I now have nearly everything working, except for one critical piece...
I've succeeded in identifying the bit of the tree that I care about.
Now, I need to make modifications on it... I've tried a fair number of
variations of the following theme:
void TernaryTransformer::pre_visit(Puma::CTree* node)
{
if (strcmp(node->NodeName(), "IfThenExpr") == 0)
{
Puma::ManipCommander manip;
Puma::CUnit funcCall(m_Err);
// expression is "test ? trueExpr : falseExpr"
funcCall << "__ternaryOp(";
node->Son(0)->Value()->print(funcCall); // "test"
funcCall << ","
node->Son(2)->Value()->print(funcCall); // "trueExpr"
funcCall << ","
node->Son(4)->Value()->print(funcCall); // "falseExpr"
funcCall << ")" << Puma::endu;
manip.replace(node->token(), node->end_token(), (Token*)
funcCall.first(), (Token*) funcCall.last());
if (manip.valid())
manip.commit();
}
}
None of what I've done so far is achieving what I'm after, which is to
return the original string representation of the *entire* CTree I have
been passed. I know that you can return the current token with
tree->Token()->text(), but is there a way to do the same for the whole
tree, or do I need to iterate over the CTree and add whitespace and the
like back in myself?
Thanks again!
More information about the aspectc-user
mailing list