예제 #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;
  }
예제 #2
0
파일: driver.cpp 프로젝트: LoggerMN/rose
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);
   }
}
예제 #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;
   }
예제 #4
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));
         }
      }
   }
}