fp_t ast_fun_call_expr::eval(symbol_table& sym) { list<fp_t> args; for (auto _ex : *_exs) args.push_back(_ex->eval(sym)); sym.open_scope(); ptr<ast_fun_def> _fd = sym.get_fun_def(_id); auto arg_it = args.begin(); for (auto _param_id : *(_fd->_ids)) sym.set_var(_param_id, *arg_it++); maybe_fp_t ret = _fd->_bl->exec(sym); sym.close_scope(); if (not ret.is_valid) { // runtime error cerr << MYLANGA_RUNTIME_ERROR << " | " << \ "La función \'" << *_id << "\' se ejecutó sin retornar un valor." << endl; MYLANGA_END_ABRUPTLY(); } return ret.value; }
symbol* find_typeTable (const string* key) { auto found = typeTable.find(key); if (found == typeTable.end()){ return NULL; } else { return found->second; } }
symbol* grabStructSymbol (const string* ident) { auto table_check = typeTable.find(ident); if(table_check != typeTable.end()) { return table_check->second; } fprintf(stderr, "oc: %s struct does not exist\n", ident->c_str()); return NULL; }
/** Traverse block and find name of symbol */ static string traverse_block_two(symbol_table mymap,string tname){ // find in map symbol_table::iterator got = mymap.find (&tname); // if symbool found, return symbol if ( got != mymap.end() ) { string type = *(got->first); return type; } // otherwise, keep traversing return traverse_block_two(*got->second->fields,tname); }
bool ast_fun_call_expr::is_valid(symbol_table& sym) { bool res = true; do { ptr<ast_fun_def> _fd = sym.get_fun_def(_id); if (_fd == nullptr) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "La función \'" << *_id << "\' no se encuentra definida." << endl; res = false; break; } if (_fd->_ids->size() != _exs->size()) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "La función " << (*(_fd->_id)) << " recibe " << to_string(_fd->_ids->size()) << \ " parámetro(s), pero es invocada con " << to_string(_exs->size()) << \ " argumento(s)." << endl; res = false; break; } } while (false); for (auto _ex : *_exs) res = _ex->is_valid(sym) and res; return res; }
cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node ¶mnode) : m_value(0) { // read the core attributes m_minval = number_and_format(xml_get_attribute_int(¶mnode, "min", 0), xml_get_attribute_int_format(¶mnode, "min")); m_maxval = number_and_format(xml_get_attribute_int(¶mnode, "max", 0), xml_get_attribute_int_format(¶mnode, "max")); m_stepval = number_and_format(xml_get_attribute_int(¶mnode, "step", 1), xml_get_attribute_int_format(¶mnode, "step")); // iterate over items for (xml_data_node *itemnode = xml_get_sibling(paramnode.child, "item"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "item")) { // check for NULL text if (itemnode->value == NULL || itemnode->value[0] == 0) throw emu_fatalerror("%s.xml(%d): item is missing text\n", filename, itemnode->line); // check for non-existant value if (xml_get_attribute(itemnode, "value") == NULL) throw emu_fatalerror("%s.xml(%d): item is value\n", filename, itemnode->line); // extract the parameters UINT64 value = xml_get_attribute_int(itemnode, "value", 0); int format = xml_get_attribute_int_format(itemnode, "value"); // allocate and append a new item item &curitem = m_itemlist.append(*global_alloc(item(itemnode->value, value, format))); // ensure the maximum expands to suit m_maxval = MAX(m_maxval, curitem.value()); } // add a variable to the symbol table for our value symbols.add("param", symbol_table::READ_ONLY, &m_value); }
cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const ¶mnode) : m_value(0) { // read the core attributes m_minval = number_and_format(paramnode.get_attribute_int("min", 0), paramnode.get_attribute_int_format("min")); m_maxval = number_and_format(paramnode.get_attribute_int("max", 0), paramnode.get_attribute_int_format("max")); m_stepval = number_and_format(paramnode.get_attribute_int("step", 1), paramnode.get_attribute_int_format("step")); // iterate over items for (xml_data_node const *itemnode = paramnode.get_child("item"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("item")) { // check for nullptr text if (itemnode->get_value() == nullptr || itemnode->get_value()[0] == 0) throw emu_fatalerror("%s.xml(%d): item is missing text\n", filename, itemnode->line); // check for non-existant value if (!itemnode->has_attribute("value")) throw emu_fatalerror("%s.xml(%d): item is value\n", filename, itemnode->line); // extract the parameters uint64_t const value = itemnode->get_attribute_int("value", 0); xml_data_node::int_format const format = itemnode->get_attribute_int_format("value"); // allocate and append a new item auto curitem = std::make_unique<item>(itemnode->get_value(), value, format); // ensure the maximum expands to suit m_maxval = std::max(m_maxval, curitem->value()); m_itemlist.push_back(std::move(curitem)); } // add a variable to the symbol table for our value symbols.add("param", symbol_table::READ_ONLY, &m_value); }
tree::node::ptr parse_state(std::string expr, std::string const& context, symbol_table symbol_table, const parser::parse_policy& ppol) { if (expr == "") { tree::node::ptr p = tree::node::ptr(tree::node::null_node()); return p; } else { symbol_table.set_context(context); state_grammar g; state_ast my_ast; std::string::const_iterator iter = expr.begin(); std::string::const_iterator end = expr.end(); bool r = boost::spirit::qi::phrase_parse(iter, end, g, boost::spirit::ascii::space, my_ast); if (r && iter == end) { return make_state_tree(my_ast, symbol_table,ppol); } else { /** * error handle : precise as to when the parser fails * (part of the predicate fails) */ throw basic_exception("Could not parse predicate:\n" + expr + "\n" + std::string(iter-expr.begin(),' ') + "^"+ std::string(iter, end)); } } }
bool ast_var_assign_stmt::is_valid(symbol_table& sym) { bool res = true; res = _ex->is_valid(sym) and res; sym.declare_var(_id); return res; }
bool ast_plot_cmd::is_valid(symbol_table& sym) { bool res = true; sym.open_scope(); do { res = _ex1->is_valid(sym) and res; res = _ex2->is_valid(sym) and res; res = _ex3->is_valid(sym) and res; if (not res) break; fp_t range_from = _ex1->eval(sym), range_step = _ex2->eval(sym), range_to = _ex3->eval(sym); if (not (range_from <= range_to and 0 < range_step)) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "En la instrucción de plot, el rango de evaluación es inválido; un rango válido a..d..b debe cumplir a <= b y 0 < d." << endl; res = false; } if (not (_ex_x->is_plottable() and _ex_y->is_plottable())) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "En la instrucción de plot, las expresiones a evaluar deben ser de tipo llamado a función." << endl; res = false; } sym.declare_var(_id); res = _ex_x->is_valid(sym) and res; res = _ex_y->is_valid(sym) and res; } while (false); sym.close_scope(); return res; }
tree::node_ptr operator()(state_loc const& pred) const { std::string autom(pred.aut); std::string context=my_symbol_table.get_context(); if (autom == "") { autom = context; context = ""; } return tree::node_ptr(hybrid_automata::location_node_creator::create( autom, context, pred.loc, pred.eq)); }
void affineStatement::reset_patterns( const symbol_table& new_table ) { Datum * parent; AccessPattern * new_pat; symbol_table::const_iterator it; for ( int i = 0 ; i < Reads.size() ; i++ ) { parent = Reads[i]->get_parent(); it = new_table.find(parent->get_name()); new_pat = it->second.get_pattern(Reads[i]->get_id()); Reads[i] = new_pat; } for ( int i = 0 ; i < Writes.size() ; i++ ) { parent = Writes[i]->get_parent(); it = new_table.find(parent->get_name()); new_pat = it->second.get_pattern(Writes[i]->get_id()); Writes[i] = new_pat; } }
void ast_plot_cmd::plot(symbol_table& sym) { sym.open_scope(); fp_t range_from = _ex1->eval(sym), range_step = _ex2->eval(sym), range_to = _ex3->eval(sym); for (fp_t x = range_from; x <= range_to; x += range_step) { sym.set_var(_id, x); fp_t x_value = _ex_x->eval(sym), y_value = _ex_y->eval(sym); cout << x_value << " " << y_value << endl; } sym.close_scope(); }
bool ast_id_expr::is_valid(symbol_table& sym) { bool res = true; if (not sym.var_is_declared(_id)) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "La variable \'" << *_id << "\' no se encuentra previamente declarada." << endl; res = false; } return res; }
// print out the items stored in the two tables void table_dump () { printf("Identifiers:\n"); int ident_scp = 0; for (auto v: idents) { printf("%d\n", ident_scp); for (auto i = v->cbegin(); i != v->cend(); i++) { printf("\t %s %s\n", i->first->c_str(), get_attributes(i->second->attributes)); } ident_scp++; } printf("Types:\n"); for (auto i = types.cbegin(); i != types.cend(); i++) { printf("%s\n", i->first->c_str()); for (auto j = i->second->fields->cbegin(); j != i->second->fields->cend(); j++) { printf("\t%s %s\n", j->first->c_str(), get_attributes(j->second->attributes)); } } }
bool ast_fun_def::is_valid(symbol_table& sym) { bool res = true; if (sym.get_fun_def(_id) != nullptr) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "La función \'" << *_id << "\' ya está definida." << endl; res = false; } if (has_repeated_elements(_ids)) { cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \ "La función \'" << *_id << "\' contiene parámetros repetidos en su definición." << endl; res = false; } // para soportar recursión sym.define_fun(shared_from_this()); sym.open_scope(); for (auto _id : *_ids) sym.declare_var(_id); res = _bl->is_valid(sym) and res; sym.close_scope(); sym.undefine_fun(shared_from_this()); return res; }
symbol* intern_typeTable (astree* tree) { symbol* temp = (symbol*)malloc(sizeof(struct symbol)); temp->fields = NULL; temp->parameters = NULL; temp->attributes = ATTR_struct; temp->blocknr = 0; temp->filenr = tree->filenr; temp->linenr = tree->linenr; temp->offset = tree->offset; temp->initialized = 0; typeTable.insert ({tree->children.at(0)->lexinfo, temp}); return temp; }
fp_t ast_id_expr::eval(symbol_table& sym) { maybe_fp_t var = sym.get_var(_id); if (not var.is_valid) { // runtime error cerr << MYLANGA_RUNTIME_ERROR << " | " << \ "Lectura de la variable \'" << *_id << "\' sin haberle asignado previamente un valor." << endl; MYLANGA_END_ABRUPTLY(); } return var.value; }
void Statement::set_patterns( symbol_table& data ) { SgExpression * exp = myStatement->get_expression(); IO lhsIO; vector<AccessPattern*> patList; if ( !isSgBinaryOp(exp) ) { if ( isSgUnaryOp(exp) ) search_for_access_patterns( isSgUnaryOp(exp)->get_operand(), patList, INOUT ); else report_error("Unrecognized expression statement",exp); } else { lhsIO = ( isSgAssignOp(exp) ) ? OUT : INOUT; /* Left hand side */ search_for_access_patterns( isSgBinaryOp(exp)->get_lhs_operand(), patList, lhsIO ); /* Right hand side */ search_for_access_patterns( isSgBinaryOp(exp)->get_rhs_operand(), patList, IN ); } for ( int i = 0 ; i < patList.size() ; i++ ) { int dim = patList[i]->get_dim(); SgExpression * exp = patList[i]->get_refExp(); for ( int j = 0 ; j < dim ; j++ ) exp = isSgPntrArrRefExp(exp)->get_lhs_operand(); string ap_name = isSgVarRefExp(exp)->get_symbol()->get_name().getString(); symbol_table::iterator it = data.find(ap_name); it->second.add_pattern(patList[i]); add_pattern(patList[i]); } }
symbol_data lookup_string(const char * str, std::size_t length) { static symbol_table table; return table.find(str, length); }
void myFunctionToDoThatThing (astree* tree) { typeTable.erase(tree->children.at(0)->lexinfo); }
maybe_fp_t ast_var_assign_stmt::exec(symbol_table& sym) { sym.set_var(_id, _ex->eval(sym)); return maybe_fp_t(); }