예제 #1
0
POETCode* POETProgram::make_tuple3(POETCode* r1, POETCode* r2, POETCode* r3)
{
  ASTFactory* fac = ASTFactory::inst();
  POETCode* res = fac->new_pair(r1,r2);
  res = fac->append_tuple(res, r3);
  return res;
}
예제 #2
0
파일: driver.cpp 프로젝트: LoggerMN/rose
extern "C" POETCode* make_varRef(POETCode* name, int config) 
{
  try {
  ASTFactory* fac = ASTFactory::inst();
  if (name == fac->make_any()) return name;
  switch (config) {
  case CODE_VAR: return curfile->make_codeRef(name, 0);
  case XFORM_VAR: return curfile->make_xformVar(name);
  case CODE_OR_XFORM_VAR: {
     POETCode* res = find_code_or_xform_var(name);
     if (res != 0) return res; 
     CODE_OR_XFORM_UNDEFINED(name->toString()); 
  }
  case GLOBAL_SCOPE: {
     POETCode* res = find_code_or_xform_var(name);
     if (res != 0) return res; 
     res = find_global_var(name);
     if (res != 0) return res;
     SYM_UNDEFINED(name->toString());
   }
  case GLOBAL_VAR: {
     POETCode* res = find_code_or_xform_var(name);
     if (res != 0) return res; 
     res = find_global_var(name);
     if (res != 0) return res;
     return curfile->make_evalVar(name);
  }
  case ID_DEFAULT: {
     LvarSymbolTable* local = top_scope(); 
     POETCode* res = find_code_or_xform_var(name);
     if (res != 0) return res; 
     if (local == 0) {
        res = find_global_var(name);
        if (res != 0) return res;
        return curfile->make_evalVar(name);
     }
     return POETProgram::make_localVar(local, name, LVAR_REG);
  }
  case ASSIGN_VAR: {
     LvarSymbolTable* local = top_scope(); 
     POETCode* res = find_code_or_xform_var(name);
     if (res != 0) VAR_ASSIGN_ERROR(name->toString());
     if (local == 0) {
        res = find_global_var(name);
        if (res != 0) return res;
        return curfile->make_evalVar(name);
     }
     return POETProgram::make_localVar(local, name, LVAR_REG);
  }
  default:
     std::cerr << "something is wrong with variable creation config: " << name->toString() << " config = " << config << "\n";
     std::cerr << "At line " << yylineno << " of file " << curfile->get_filename() << "\n";
     assert(0);
   }
  }
  catch (Error err) { std::cerr << "At line " << yylineno << " of file " << curfile->get_filename() << "\n"; exit(1); }
}
예제 #3
0
파일: driver.cpp 프로젝트: LoggerMN/rose
inline POETCode* find_code_or_xform_var(POETCode* name)
{
     POETCode* res = curfile->find_macroVar(name);
     if (res != 0) return res;
     ASTFactory* fac = ASTFactory::inst();
     CvarSymbolTable::Entry ge;
     if (fac->find_codeDef(name, ge))
         return fac->new_codeRef(ge, 0); 
     res= fac->find_xformDef(name, false);
     if (res != 0) return res; 
     return 0;
}
예제 #4
0
파일: driver.cpp 프로젝트: LoggerMN/rose
POETCode* make_sourceIntegers( char* text, int len)
{
  char* p = text, *p1 = p; 
  POETCode* r = 0;
  ASTFactory* fac = ASTFactory::inst();
  for (int i = 0; i < len; ++p, ++i) {
     if ((*p) == ',') {
        if (r == 0) r = make_Iconst(p1,p-p1);
        else r = fac->append_tuple(r, make_Iconst(p1, p-p1)); 
        p1 = p+1;
     }
  }
  if (p1 < p) {
     if (r == 0) r = make_Iconst(p1,p-p1);
     else r = fac->append_tuple(r, make_Iconst(p1, p-p1)); 
  }
  return r;
}
예제 #5
0
 void output(POETString* s) {  
       ASTFactory* fac = ASTFactory::inst();
       std::string r = s->get_content();
       if (r == "\n") {
           for (int i = 0; i < align; ++i) r = r + " ";
           s = fac->new_string(r);
       }
       if (output_xform == 0) 
            output_content(r,r); 
       else {
          POETCode* args = fac->new_pair(s, fac->new_iconst(cur_pos));
          if (!match_parameters(output_xform->get_entry().get_param(), args,
                        MATCH_PAR_MOD_CODE))
               INCORRECT_XFORM_DEF("output(string,cur_pos)", output_xform->toString()); 
          XformVarInvoke invoke(output_xform->get_entry(), output_xform->get_config(), args);
          POETCode* res = invoke.eval(0);
          output_content(res->toString(OUTPUT_NO_DEBUG),r);
       }
    }
예제 #6
0
POETCode* POETProgram::append_tuple(POETCode* r1, POETCode* r2)
{
  ASTFactory* fac = ASTFactory::inst();
  POETCode* res = fac->append_tuple(r1, r2);
  return res;
}
예제 #7
0
/*QY: return the min length of tokens placed in the filter res*/
unsigned EvaluatePOET::
compute_lookaheadInfo(POETCode* cur, std::vector<POETCode*>& res, unsigned need)
{
 try {
    assert(cur != 0);
    switch (cur->get_enum()) {
     case SRC_TYPE: 
         if (cur != ANY) { res.push_back(cur); return 1; }
         return 0;
     case SRC_STRING: 
         if (cur != EMPTY) { res.push_back(cur); return 1; }
         return 0;
     case SRC_ICONST:  
         res.push_back(cur); res.push_back(AST2String(cur)); 
         return 1;
     case SRC_CVAR:  {
         CodeVar* cvar = static_cast<CodeVar*>(cur);
         POETCode* parse=cvar->get_parseInfo();
         unsigned lookahead = cvar->get_entry().get_lookahead();
         if (need < lookahead) need = lookahead;
         if (parse != EMPTY) {
            unsigned len = compute_lookaheadInfo(parse, res, need);
            if (lookahead > 1 && len < lookahead) 
               { LOOKAHEAD_AMBIGUOUS(cvar); return 0; }
            return len;
         }
         res.push_back(cvar);  /*QY: the code var is a token */
         return 1;
        }
     case SRC_LVAR: {
          LocalVar* lvar = static_cast<LocalVar*>(cur);
          POETCode* restr = 0;
          switch (lvar->get_entry().get_entry_type())
          {
            case LVAR_CODEPAR: case LVAR_ATTR:
                 restr = lvar->get_entry().get_restr(); break;
            default: restr = lvar->get_entry().get_code(); 
                 break;
          }
          if (restr == 0) { LOOKAHEAD_AMBIGUOUS(cur); return 0; }
          else return compute_lookaheadInfo(restr,res,need); 
        }
     case SRC_LIST: {
         POETList* curlist = static_cast<POETList*>(cur);
         int curstart = res.size();
         unsigned len = compute_lookaheadInfo(curlist->get_first(),res,need);
         cur = curlist->get_rest();
         if (cur == 0) return len;
         int cursize = res.size();
         if (need == 1) {
            if (len == 0) return compute_lookaheadInfo(cur, res, need);
            return len;
         }
         if (len < need ) {
            std::vector<POETCode*> tailres;
            unsigned len2 = compute_lookaheadInfo(cur, tailres, need-len);
            ASTFactory* fac = ASTFactory::inst();
            for (int i = curstart; i < cursize; ++i) {
               POETCode* first = res[i]; 
               res[i] = fac->append_tuple(first,tailres[0]);
               for (unsigned j = 1; j < tailres.size(); ++j) 
                   res.push_back(fac->append_tuple(first,tailres[j]));
            }
            return len+len2;
         }
         return len;
        }
     case SRC_OP : {
        POETOperator* op = static_cast<POETOperator*>(cur);
        switch(op->get_op()) {
        case TYPE_TOR: {
            POETTypeTor* tor = static_cast<POETTypeTor*>(cur);
            return tor->compute_lookaheadInfo(this, res, need);
           }
        case POET_OP_LIST1: 
        case TYPE_LIST1: 
            return compute_lookaheadInfo(op->get_arg(0),res,need);
        case POET_OP_LIST: 
        case TYPE_LIST: 
            compute_lookaheadInfo(op->get_arg(0),res); return 0;
        case POET_OP_EXP:
            return compute_exp_lookahead(res);
        default:
           LOOKAHEAD_AMBIGUOUS(cur); return 0;
        }
       }
     default:
        LOOKAHEAD_AMBIGUOUS(cur); return 0;
     }
   }
   catch (Error err) { std::cerr << " From computing filter information for " << cur->toString() << "\n"; throw err; }
}