Пример #1
0
LocalVar* POETProgram::
set_local_static(LvarSymbolTable* local, POETCode* id, 
                 LocalVarType t, POETCode* code, POETCode * restr, bool insert)
{
  assert(local != 0);
  LocalVar* lvar = local->find(id);
  POETCode* orig = 0;
  if (lvar == 0) {
     if (insert) {
       lvar = local->insert(id, t);
       lvar->get_entry().set_code(code);
       lvar->get_entry().set_restr(restr);
     }
     else SYM_UNDEFINED(id->toString()+"="+code->toString());
  }
  else if (code != 0 && (orig = lvar->get_entry().get_code()) != 0 && orig != code && !match_AST(orig, code, MATCH_AST_EQ)) {
       SYM_DIFF_DEFINED(id->toString()+"="+code->toString(), orig->toString());
   }
  else {
      if (code != 0)
         lvar->get_entry().set_code(code);
      if (restr != 0)
          lvar->get_entry().set_restr(restr);
  }
  return lvar;
}
Пример #2
0
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
 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;
            }
         }
      }
 }
Пример #4
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);
    }
 }
Пример #5
0
unsigned EvaluatePOET:: compute_exp_lookahead(std::vector<POETCode*>& res)
{
   res.push_back(fac->new_string("("));
   if (exp_item->get_entry().get_code() == 0)
      SYM_UNDEFINED("EXP_BASE");
   compute_lookaheadInfo(exp_item->get_entry().get_code(), res);
   POETCode* uop = exp_uop->get_entry().get_code();
   while (uop != 0) {
       res.push_back(get_head(uop));
       uop = get_tail(uop);
   }
   return 1;
}
Пример #6
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; }
    } 
Пример #7
0
 ParseExp() {
    backtrack=curfile->get_backtrack();
    compute_exp_lookahead(itemFilter);
    if (exp_bop->get_entry().get_code() == 0)
       SYM_UNDEFINED("EXP_BOP");
 }