Пример #1
0
    POETCode* eval_cvar_attr(CodeVar* cv, LocalVar* lv)
    {
      CvarSymbolTable::Entry cv_e = cv->get_entry();
      LvarSymbolTable* symTable = cv_e.get_symTable();
      LvarSymbolTable::Entry e = lv->get_entry();
      if (symTable->find(e.get_name()) != lv) return 0;

      POETCode* res = 0;
      switch (e.get_entry_type()) {
       case LVAR_CODEPAR:
           res = eval_tuple_access(cv->get_args(), e.get_code()); 
           break;
       case LVAR_ATTR:
          for (int i = 0; i < cv_e.attr_size(); ++i) {
             if (cv_e.get_attr(i) == lv) { 
                POETCode* tuple = cv->get_attr();
                if (tuple == 0) res = e.get_code();
                else res = eval_tuple_access(tuple,i);
                break;
             }
          }
          break;
       default: /*QY: access is a local variable. treat this as tuple access*/
           res = eval_tuple_access(cv, lv);
      }
      return res;
   }
Пример #2
0
 virtual void visitLocalVar(LocalVar* var) 
   {
      LvarSymbolTable::Entry e = var->get_entry();
      POETCode *restr = e.get_restr();
      if (restr == 0) {
         CollectInfoVisitor::visitLocalVar(var);
         return;
      }
      if (restr->get_enum() == SRC_CVAR) {
         CodeVar* cvar = static_cast<CodeVar*>(restr);
         POETCode* code = e.get_code();
         if (code!=0 && !match_AST(code, cvar,MATCH_AST_EQ)) {
            CodeVar* tmp = ASTFactory::inst()->new_codeRef(cvar->get_entry(), code); 
            tmp->visit(this); 
            return; 
         }
      }
      else if (restr->get_enum() == SRC_OP) {
          POETOperator* op = static_cast<POETOperator*>(restr);
          if (op->get_op() == POET_OP_LIST || op->get_op()==POET_OP_LIST1)  {
              POETCode* _listsep = listsep;
              CodeVar* _listelem = listelem;
              int save = align;
              align = start_pos;
              listsep = op->get_arg(1);
              listelem=dynamic_cast<CodeVar*>(op->get_arg(0));
              CollectInfoVisitor::visitLocalVar(var);
              align = save; listsep = _listsep; listelem = _listelem;
              return;
           }
      }
      CollectInfoVisitor::visitLocalVar(var);
   }
Пример #3
0
 virtual void visitLocalVar(LocalVar* v)
 {
    LvarSymbolTable::Entry e =v->get_entry();
    POETCode* code = e.get_code();
    if (code != v && code != 0)  code->visit(this); 
    else {
       POETCode* restr =  e.get_restr();
       if (restr != 0) restr->visit(this);
       else SYM_UNDEFINED(v->toString());
       e.set_code(res);
    }
 }
Пример #4
0
std:: string ParameterDecl:: toString(ASTOutputEnum config) 
{ 
      LvarSymbolTable::Entry e = var->get_entry();
      std::string res =  "<parameter " + e.get_name()->toString(OUTPUT_NO_DEBUG); 
      if (parse != 0) 
         res = res + " parse=" +  parse->toString(ASTOutputEnum(config | DEBUG_NO_VAR));
      if (e.get_restr() != 0) 
         res = res + " type=" + e.get_restr()->toString(ASTOutputEnum(config | DEBUG_NO_VAR));
      if (init != 0)  
         res = res + " default=" + init->toString(ASTOutputEnum(config | DEBUG_NO_VAR));
      if (msg != 0) 
         res = res + " message=" + msg->toString(ASTOutputEnum(config | DEBUG_NO_VAR));
      res = res + "/>";
      return res; 
   }
Пример #5
0
 virtual void visitTupleAccess(TupleAccess* fc) 
    { 
     try {
      POETCode* tuple = apply(fc->get_tuple());
      POETCode* tuple1 = EvalTrace(tuple);
      if (tuple1 == 0) SYM_UNDEFINED(tuple->toString())
      else tuple = tuple1;
      POETCode* access= EvalTrace(fc->get_access()); 
      switch (tuple->get_enum()) {
        case SRC_TUPLE: {
           access= apply(access);
           if (access->get_enum() == SRC_LVAR) {
             LvarSymbolTable::Entry e = static_cast<LocalVar*>(access)->get_entry();
             if (e.get_entry_type() == LVAR_OUTPUT) access = e.get_code(); 
             else TUPLE_ACC_MISMATCH(fc, tuple,access);
           }
           res = eval_tuple_access(tuple,access);
           if (res == 0) { TUPLE_ACC_MISMATCH(fc, tuple,access); }
           return;
         }
        case SRC_MAP: {
           POETMap* m = static_cast<POETMap*>(tuple);
           access= apply(access);
           res = m->find(access);
           if (res == 0) 
               res = EMPTY;
           return;
        }
        case SRC_CVAR: {
           CodeVar* cv = static_cast<CodeVar*>(tuple);
           CvarSymbolTable::Entry cv_e = cv->get_entry();
           LvarSymbolTable* symTable = cv_e.get_symTable();
           res = eval_cvar_access(cv, access);
           return;
        }
        default: { 
           res = eval_tuple_access(tuple,access);
           if (res == 0)
            TUPLE_ACC_MISMATCH( fc, tuple, access); 
          }
       }
     }
     catch (Error err) { std::cerr << "From invoking " << SHORT(fc->toString(),500) << "\n"; throw err; }
    } 
Пример #6
0
POETCode* EraseTrace(POETCode* vars, POETCode* res)
{
  std::vector<LocalVar*> vec;
  switch (vars->get_enum()) {
  case SRC_LVAR: {
     vars = eval_AST(vars);
     if (vars->get_enum() != SRC_LVAR) break;
     LocalVar* lvar = static_cast<LocalVar*>(vars);
     if (lvar->get_entry().get_entry_type() == LVAR_TRACE)
        vec.push_back(lvar);
     break;
  }
 case SRC_LIST: {
   POETList* l = static_cast<POETList*>(vars);
   while (l != 0) {
     POETCode* cur = l->get_first();
     if (cur->get_enum() == SRC_LVAR) {
        cur = eval_AST(cur);
        if (cur->get_enum() == SRC_LVAR) {
           LocalVar* cur_lvar = static_cast<LocalVar*>(cur);
           if (cur_lvar->get_entry().get_entry_type() == LVAR_TRACE) 
                vec.push_back(cur_lvar);
        }
     }
     l = dynamic_cast<POETList*>(l->get_rest());
   }
  }
  break;
 default: return res;
 }
 int size = vec.size();
 if (size == 0) return res;
 for (int i = size-1; i >= 0; --i) {
   LvarSymbolTable::Entry e = vec[i]->get_entry();
   assert (e.get_entry_type() == LVAR_TRACE); 
   e.set_entry_type(LVAR_TRACE_OUTDATE);
 }
 res = ReplInfoVisitor().apply(res);
 for (int i = size-1; i >= 0; --i) {
   LvarSymbolTable::Entry e = vec[i]->get_entry();
   e.set_entry_type(LVAR_TRACE);
 }
 return res;
}
Пример #7
0
 virtual void visitLocalVar(LocalVar* v) { 
      if (v->get_entry().get_entry_type() == LVAR_TRACE)
        res = v;
      else {
         res = v->get_entry().get_code(); 
         if (res == 0) 
            { SYM_UNDEFINED(v->toString()); }
         if (res != v) {
            while (res->get_enum() == SRC_LVAR) {
               LvarSymbolTable::Entry e = static_cast<LocalVar*>(res)->get_entry();
               if (e.get_entry_type() == LVAR_TRACE) break;
               POETCode* code = e.get_code();
               if (code == 0) SYM_UNDEFINED(res->toString());
               if (code == res) break;
               res = code;
            }
         }
      }
 }
Пример #8
0
POETCode* TraceEval(POETCode* vars, POETCode* res)
{
  std::vector<LocalVar*> vec;
  switch (vars->get_enum()) {
  case SRC_LVAR: {
     LocalVar* lvar = static_cast<LocalVar*>(vars);
     vec.push_back(lvar);
     break;
  }
 case SRC_LIST: {
   POETList* l = static_cast<POETList*>(vars);
   while (l != 0) {
     POETCode* cur = l->get_first();
     if (cur->get_enum() != SRC_LVAR) INCORRECT_TRACE_HANDLE(cur->toString());
     vec.push_back(static_cast<LocalVar*>(cur));
     l = dynamic_cast<POETList*>(l->get_rest());
   }
  } 
   break;
 default: INCORRECT_TRACE_HANDLE(vars->toString()); 
 }
 for (int i = vec.size()-1; i >= 0; --i) {
    LocalVar* lvar = vec[i];
    LvarSymbolTable::Entry entry = lvar->get_entry();
    entry.push(true);
    entry.set_entry_type(LVAR_TRACE);
 }
 res = eval_AST(res);
 for (int i = vec.size()-1; i >= 0; --i) {
    LocalVar* lvar = dynamic_cast<LocalVar*>(vec[i]);
    assert(lvar != 0);
    LvarSymbolTable::Entry entry = lvar->get_entry();
    POETCode* val = entry.get_code();
    entry.pop();
    entry.set_code(val);
 }
 return res;
}