diff --git a/DynamicModel.cc b/DynamicModel.cc index f27b1ca3..e881b302 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3429,47 +3429,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } -void -DynamicModel::reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) -{ - map orig_trend_symbols_map = trend_symbols_map; - trend_symbols_map.clear(); - for (map::const_iterator it = orig_trend_symbols_map.begin(); - it != orig_trend_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addTrendVariables(symb_id, - it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in trend symbols." << endl; - exit(EXIT_FAILURE); - } -} - -void -DynamicModel::reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) -{ - nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; - nonstationary_symbols_map.clear(); - for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); - it != orig_nonstationary_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addNonstationaryVariables(symb_id, - it->second.first, - it->second.second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in nonstationary symbols." << endl; - exit(EXIT_FAILURE); - } -} - void DynamicModel::resetDataTree() { @@ -3483,22 +3442,6 @@ DynamicModel::resetDataTree() second_deriv_external_function_node_map.clear(); } -void -DynamicModel::reindexEquations(DynamicModel &dynamic_model, 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++) - dynamic_model.AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - - vectoreqbak = equations; - equations.clear(); - for (size_t i = 0; i < eqbak.size(); i++) - dynamic_model.addEquation(eqbak[i]->cloneDynamicReindex(dynamic_model, orig_symbol_table), equations_lineno[i]); -} - void DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 79f085de..e6a56675 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,15 +235,6 @@ public: /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; - //! reindex equations after change in symbol_table - void reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - - //! reindex trend_symbol_map after change in symbol_table - void reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - - //! reindex nonstationary_symbol_map after change in symbol_table - void reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - //! reset DataTree vars void resetDataTree(); diff --git a/ModFile.cc b/ModFile.cc index 570ad72a..d9f36dbb 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,7 +314,7 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.resetDataTree(); - dynamic_model.reindexEquations(dynamic_model, orig_symbol_table); + dynamic_model.reindex(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 688d4f29..b95a508e 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1413,6 +1413,70 @@ ModelTree::addAuxEquation(expr_t eq) aux_equations.push_back(beq); } +void +ModelTree::reindex(SymbolTable &orig_symbol_table) +{ + reindexEquations(orig_symbol_table); + reindexTrendSymbolsMap(orig_symbol_table); + reindexNonstationarySymbolsMap(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++) + addEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), equations_lineno[i]); +} + +void +ModelTree::reindexTrendSymbolsMap(SymbolTable &orig_symbol_table) +{ + map orig_trend_symbols_map = trend_symbols_map; + trend_symbols_map.clear(); + for (map::const_iterator it = orig_trend_symbols_map.begin(); + it != orig_trend_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addTrendVariables(symb_id, it->second->cloneDynamicReindex(*this, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in trend symbols." << endl; + exit(EXIT_FAILURE); + } +} + +void +ModelTree::reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table) +{ + nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; + nonstationary_symbols_map.clear(); + for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); + it != orig_nonstationary_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addNonstationaryVariables(symb_id, + it->second.first, + it->second.second->cloneDynamicReindex(*this, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in nonstationary symbols." << endl; + exit(EXIT_FAILURE); + } +} + void ModelTree::addTrendVariables(vector trend_vars, expr_t growth_factor) throw (TrendException) { diff --git a/ModelTree.hh b/ModelTree.hh index 4d161daf..b86376b2 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -303,6 +303,13 @@ public: void addEquation(expr_t eq, int lineno, vector > &eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations void addAuxEquation(expr_t eq); + void reindex(SymbolTable &orig_symbol_table); + //! reindex equations after change in symbol_table + void reindexEquations(SymbolTable &orig_symbol_table); + //! reindex trend_symbol_map after change in symbol_table + void reindexTrendSymbolsMap(SymbolTable &orig_symbol_table); + //! reindex nonstationary_symbol_map after change in symbol_table + void reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table); //! Returns the number of equations in the model int equation_number() const; //! Adds a trend variable with its growth factor