Exemple #1
0
bool EvaluatePOET::match_lookahead(POETCode* r1, POETCode* cur_filter)
{
#ifdef DEBUG_LOOKAHEAD
std::cerr << "trying to match " << r1->toString() << " with lookahead:" << cur_filter->toString() << "\n";
#endif

    POETCode* r1_first = get_head(r1);
    switch (cur_filter->get_enum()) {
     case SRC_STRING: 
     case SRC_ICONST: return (cur_filter == r1_first);
     case SRC_CVAR: /* a code template token */
          return (r1_first->get_enum() == SRC_CVAR &&
              static_cast<CodeVar*>(r1_first)->get_entry() == 
              static_cast<CodeVar*>(cur_filter)->get_entry());
     case SRC_TYPE:
          return (match_Type(r1_first, static_cast<POETType*>(cur_filter), 
                               MATCH_AST_PATTERN)); 
     case SRC_TUPLE: /*QY: multiple lookahead tokens*/
        {
         POETTuple* tuple = static_cast<POETTuple*>(cur_filter);
         for (unsigned i = 0; i < tuple->size(); ++i) {
              if (!match_lookahead(r1_first, tuple->get_entry(i))) return false;
              r1_first = NextToken(r1);
         }
         return true; 
        }  
     case SRC_OP: {
        POETParseList* parse = dynamic_cast<POETParseList*>(cur_filter);
        if (parse != 0) return parse->match_lookahead(this,r1);
     }
     default: std::cerr << "Unexpected: " << cur_filter->toString() << "\n"; assert(0);
    }
    return false;
  }
Exemple #2
0
void set_code_xform_parameters( Entry e, POETCode* par) 
{
   POETCode* p = e.get_param();
   if (p == 0) 
      e.set_param(par); 
   else {
     if (p != par && !match_AST(p, par, MATCH_AST_EQ))  {
       std::cerr << "par=" << par << "; p = " << p << "\n";
        SYM_DIFF_DEFINED(par->get_className() + ":" + par->toString(OUTPUT_VAR_VAL), p->get_className() + ":" + p->toString(OUTPUT_VAR_VAL)); 
     }
     return;
   }
   switch (par->get_enum()) {
   case SRC_LVAR:  
      static_cast<LocalVar*>(par)->get_entry().set_code(ASTFactory::inst()->new_iconst(0));
      break;
   case SRC_TUPLE: {
      POETTuple* vec = static_cast<POETTuple*>(par);
      for (unsigned i = 0; i < vec->size(); ++i)
       {
         LocalVar* cur_par = dynamic_cast<LocalVar*>(vec->get_entry(i));
         assert (cur_par != 0);
         cur_par->get_entry().set_code(ASTFactory::inst()->new_iconst(i) );
       }
      break;
   }
   default:
      assert(false);
   }
}
Exemple #3
0
 bool ExamineParseFunctionResult()
   {
    if (res != 0 && res != EMPTY) {
       POETTuple* vec = dynamic_cast<POETTuple*>(res);
       if (vec == 0 || vec->size() != 2) 
          EXIT("ERROR: Parsing function must return a (code, rest-of-input) pair : " + res->toString() + "\n"); 
       POETCode*res1 = vec->get_entry(1);
       POETCode*res0 = vec->get_entry(0);
       if (res1 != 0 && res1 != EMPTY && fullmatch == 0) 
         { return false; }
       r1 = res1; res = res0;
       return true;
    }
    return false;
   }
Exemple #4
0
 POETCode_ext_delegate(POETCode_ext* e, std::ostream& _out) : out(_out) 
 {
   SgNode* input = (SgNode*)e->get_content();
   POETCode* children = e->get_children();
   POETTuple* t = dynamic_cast<POETTuple*>(children);
   AstInterface::AstList c = AstInterface::GetChildrenList(input);
   if (t == 0) {
      assert(c.size() == 1); 
      SgNode* cur = (SgNode*)(c[0]);
      if (POETAstInterface::find_Ast2POET(cur) != children)
          repl[cur] = children;
   }
   else {
      int i=0;
      for (AstInterface::AstList::const_iterator p = c.begin(); p != c.end(); ++p,++i) {
         SgNode* cur = (SgNode*)(*p);
         POETCode *cur2 = t->get_entry(i);
         if (POETAstInterface::find_Ast2POET(cur) != cur2) repl[cur] = cur2; 
      }
   }
 }
Exemple #5
0
void CodeVar:: set_attr()
{
  if (attr != 0) {
      POETTuple * attrTuple = dynamic_cast<POETTuple*>(attr);
      if (attrTuple == 0) 
      {
          LocalVar* var = entry.get_attr(0);
          assert (var != 0); 
          var->get_entry().set_code(attr);
      }
      else 
      {
         unsigned size = attrTuple->size();
         for (unsigned i = 0; i < size; ++i) 
         {
            LocalVar* var = entry.get_attr(i);
            assert(var != 0);
            var->get_entry().set_code(attrTuple->get_entry(i));
         }
      }
   }
}
Exemple #6
0
void POETAstInterface::unparse(POETCode_ext* n, std::ostream& out, int align)
{ 
 static SgUnparse_Info info;
 static Unparser* roseUnparser = 0;
 static POETCode* linebreak=ASTFactory::inst()->new_string("\n");
 static POETCode* comma=ASTFactory::inst()->new_string(",");
 static bool template_only=false;
 static POETCode* left_over = 0;
  SgNode * input = (SgNode*)n->get_content();
  POETCode* res = POETAstInterface::find_Ast2POET(input);
  if (res == n) {
      if (template_only && input->variantT() == V_SgFunctionDeclaration) 
         { left_over = LIST(n,left_over); }
      else {
        std::string res = input->unparseToCompleteString(); 
        out << res;
      }
  }
  else {
     if (roseUnparser == 0) {
        /* QY/2013: copied from the global unparseFile to use a different ostream and delegate*/
       bool UseAutoKeyword                = false;
       bool generateLineDirectives        = true;
       bool useOverloadedOperators        = false;
       bool num                           = false;
       bool _this                         = true;
       bool caststring                    = false;
       bool _debug                        = false;
       bool _class                        = false;
       bool _forced_transformation_format = false;
       bool _unparse_includes             = false; 
       Unparser_Opt roseOptions( UseAutoKeyword,
                                    generateLineDirectives,
                                    useOverloadedOperators,
                                    num,
                                    _this,
                                    caststring,
                                    _debug,
                                    _class,
                                    _forced_transformation_format,
                                    _unparse_includes );
       roseUnparser = new Unparser(&out, "", roseOptions);
     }
     switch (input->variantT()) {
     case V_SgSourceFile: 
      {
       SgSourceFile* f = isSgSourceFile(input);
       info.set_current_scope(f->get_globalScope());
       template_only = true;
       code_gen(out, n->get_children(), 0, 0, align); 
       template_only = false; 
       if (left_over != 0) {
           code_gen(out, left_over, 0, 0, align); 
           left_over = 0;
       }
       break;
      }
     case V_SgFunctionDeclaration:
      if (template_only) { left_over = LIST(n, left_over); break; }
     case V_SgTemplateInstantiationFunctionDecl:
      {
        SgFunctionDeclaration* d = isSgFunctionDeclaration(input);
        roseUnparser->u_exprStmt->unparseAttachedPreprocessingInfo(d,info,PreprocessingInfo::before);
        POETCode_ext_delegate repl(n, out);
        roseUnparser->repl = &repl;
        roseUnparser->u_exprStmt->unparseFuncDeclStmt(d, info);
        break;
      }
     case V_SgFunctionDefinition:
      {
        SgStatement* d = isSgStatement(input);
        POETCode_ext_delegate repl(n, out);
        roseUnparser->repl = &repl;
        roseUnparser->u_exprStmt->unparseStatement(d, info);
        assert(n->get_children() != n);
        out << "{"; code_gen(out, linebreak, 0, 0, align + 2); 
        code_gen(out, n->get_children(), 0, linebreak, align+2); 
        code_gen(out, linebreak, 0, 0, align); out << "}"; 
        break;
      }
     case V_SgPragmaDeclaration:
      {
         out << "#pragma ";
         POETTuple* c = dynamic_cast<POETTuple*>(n->get_children());
         assert(c != 0);
         code_gen(out, c->get_entry(0)); 
         roseUnparser->cur << " "; roseUnparser->cur.insert_newline(1,align);
         code_gen(out, c->get_entry(1), 0, 0, align); 
         break;
      }
     case V_SgForStatement:
      {
         out << "for (" ;
         POETTuple* c = dynamic_cast<POETTuple*>(n->get_children());
         assert(c != 0);
         code_gen(out, c->get_entry(0)); 
         code_gen(out, c->get_entry(1)); out << ";";
         code_gen(out, c->get_entry(2)); out << ")";
         break;
      }
     case V_SgExprStatement:
        code_gen(out, n->get_children(), 0, 0, align); 
        out << ";";
        break;
     case V_SgTemplateInstantiationMemberFunctionDecl:  break;
     default: 
std::cerr << "Unsupported unparsing for  : " << input->class_name() << input->unparseToString() << "\n";
//assert(0); 
     }
  }
}