[aspectc-user] Modifying C++ code?

Matthias Urban matthias.urban at pure-systems.com
Thu Oct 23 10:52:25 CEST 2008


Hi Gordon,

> 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)

Please use the following code to identify the node type:

   if (node->NodeName() == Puma::CT_IfThenExpr::NodeId())

>    {
>       Puma::ManipCommander manip;
>       Puma::CUnit funcCall(m_Err);
> 
>       // expression is "test ? trueExpr : falseExpr"
>       funcCall << "__ternaryOp(";
>       node->Son(0)->Value()->print(funcCall);   // "test"

Value() is intended to return constant expression values, i.e. 
expressions that can be calculated at compile time. That is not what you 
want. The easiest way to copy the whole expression is as follows:

void serialize(Puma::CTree* tree, std::ostream& os) {
   Puma::Token* token = tree->token();
   Puma::Token* end = tree->end_token();
   while (token) {
     os << token->text();
     if (token == end) {
       break;
     }
     token = token->unit()->next(token);
   }
}

OK, your code should then look like this:

   ...
   Puma::CT_IfThenExpr* ifthen = (Puma::CT_IfThenExpr*)node;
   funcCall << "__ternaryOp(";
   serialize(ifthen->Condition(), funcCall);     // "test"
   funcCall << ","
   serialize(ifthen->LeftOperand(), funcCall);   // "trueExpr"
   funcCall << ","
   serialize(ifthen->RightOperand(), funcCall);  // "falseExpr"
   funcCall << ")" << Puma::endu;
   ...

Best regards,
Matthias




More information about the aspectc-user mailing list