diff --git a/DataTree.cc b/DataTree.cc index 7135c9c6..b45d4479 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -50,6 +50,32 @@ DataTree::~DataTree() delete *it; } +void +DataTree::reindex(SymbolTable &orig_symbol_table) +{ + variable_node_map.clear(); + unary_op_node_map.clear(); + binary_op_node_map.clear(); + trinary_op_node_map.clear(); + external_function_node_map.clear(); + first_deriv_external_function_node_map.clear(); + second_deriv_external_function_node_map.clear(); + + reindexExternalFunctions(orig_symbol_table); + reindexLocalVars(orig_symbol_table); +} + +void +DataTree::reindexLocalVars(SymbolTable &orig_symbol_table) +{ + map orig_local_variables_table = local_variables_table; + local_variables_table.clear(); + for (map::const_iterator it = orig_local_variables_table.begin(); + it != orig_local_variables_table.end(); it++) + AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(*this, orig_symbol_table)); +} + void DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) { diff --git a/DataTree.hh b/DataTree.hh index 87f61726..9d0f746c 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -240,6 +240,8 @@ public: void writePowerDeriv(ostream &output, bool use_dll) const; //! reindex external functions void reindexExternalFunctions(SymbolTable &orig_symbol_table); + void reindex(SymbolTable &orig_symbol_table); + void reindexLocalVars(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id class UnknownDerivIDException { diff --git a/ModFile.cc b/ModFile.cc index b4767def..8824d84b 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -315,6 +315,13 @@ ModFile::transformPass(bool nostrict) symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); + + SymbolTable *exp_tree_symbol_table = expressions_tree.getSymbolTable(); + exp_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); + + SymbolTable *ssm_tree_symbol_table = steady_state_model.getSymbolTable(); + ssm_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); + vector orig_statements = statements; statements.clear(); for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) diff --git a/ModelTree.cc b/ModelTree.cc index 6f3a10e5..9d187b05 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1416,30 +1416,15 @@ ModelTree::addAuxEquation(expr_t eq) void ModelTree::reindex(SymbolTable &orig_symbol_table) { - variable_node_map.clear(); - unary_op_node_map.clear(); - binary_op_node_map.clear(); - trinary_op_node_map.clear(); - external_function_node_map.clear(); - first_deriv_external_function_node_map.clear(); - second_deriv_external_function_node_map.clear(); - + DataTree::reindex(orig_symbol_table); reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); - reindexExternalFunctions(orig_symbol_table); } void ModelTree::reindexEquations(SymbolTable &orig_symbol_table) { - map orig_local_variables_table = local_variables_table; - local_variables_table.clear(); - for (map::const_iterator it = orig_local_variables_table.begin(); - it != orig_local_variables_table.end(); it++) - AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(*this, orig_symbol_table)); - vectoreqbak = equations; equations.clear(); for (size_t i = 0; i < eqbak.size(); i++) diff --git a/SymbolTable.cc b/SymbolTable.cc index ffaa7bb8..223f4a91 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -503,6 +503,25 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) assert(size == symbol_table.size()); } +void +SymbolTable::rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException) +{ + if (frozen) + throw FrozenException(); + + for (set::const_iterator it = unused.begin(); it != unused.end(); it++) + try + { + string name = orig_symbol_table.getName(*it); + int symbid = getID(name); + cerr << "ERROR: " << name << "used in expression but not found in model block" << endl; + exit(EXIT_FAILURE); + } + catch (...) + { + } +} + int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index 85267fe6..98f88ee1 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -305,6 +305,8 @@ public: set getOrigEndogenous() const; //! Remove exogenous variables contained in the set void rmExo(set &unused) throw (FrozenException); + //! Remove exogenous variables contained in the set from the orig_symbol_table. If found, quit + void rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException); }; inline bool