From 96a5949d9edebadc0c6fac5a7066cd4927dd3eff Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 6 Mar 2015 15:58:11 +0100 Subject: [PATCH 01/54] preprocessor: remove extraneous varexo, update model and statements, #841 --- DataTree.hh | 3 +- DynamicModel.cc | 16 +++++++ DynamicModel.hh | 3 ++ ExprNode.cc | 71 ++++++++++++++++++++++++++++ ExprNode.hh | 14 +++++- ModFile.cc | 13 ++++++ NumericalInitialization.cc | 94 +++++++++++++++++++++++++++++++++++++- NumericalInitialization.hh | 10 +++- Statement.cc | 8 +++- Statement.hh | 9 +++- SymbolTable.cc | 37 ++++++++++++++- SymbolTable.hh | 4 +- 12 files changed, 272 insertions(+), 10 deletions(-) diff --git a/DataTree.hh b/DataTree.hh index d7c53645..f81f19e6 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -233,6 +233,7 @@ public: //! Returns the minimum lag (as a negative number) of the given symbol in the whole data tree (and not only in the equations !!) /*! Returns 0 if the symbol is not used */ int minLagForSymbol(int symb_id) const; + inline SymbolTable *getSymbolTable() const { return &symbol_table; }; //! Write the Header for getPowerDeriv when use_dll is used void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv diff --git a/DynamicModel.cc b/DynamicModel.cc index 645fa646..a4997e02 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3425,6 +3425,22 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } +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 8efbc5d3..b13d23e1 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,6 +235,9 @@ 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); + //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model diff --git a/ExprNode.cc b/ExprNode.cc index d61ebb56..66cd230e 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -354,6 +354,12 @@ NumConstNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); } +expr_t +NumConstNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); +} + int NumConstNode::maxEndoLead() const { @@ -988,6 +994,12 @@ VariableNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddVariable(symb_id, lag); } +expr_t +VariableNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + return dynamic_datatree.AddVariable(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), lag); +} + int VariableNode::maxEndoLead() const { @@ -2234,6 +2246,13 @@ UnaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarUnaryOpNode(substarg, dynamic_datatree); } +expr_t +UnaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg = arg->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarUnaryOpNode(substarg, dynamic_datatree); +} + int UnaryOpNode::maxEndoLead() const { @@ -3452,6 +3471,14 @@ BinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); } +expr_t +BinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); +} + int BinaryOpNode::maxEndoLead() const { @@ -4120,6 +4147,15 @@ TrinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); } +expr_t +TrinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg3 = arg3->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); +} + int TrinaryOpNode::maxEndoLead() const { @@ -4689,6 +4725,17 @@ ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); } +expr_t +ExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments); +} + int AbstractExternalFunctionNode::maxEndoLead() const { @@ -5182,6 +5229,18 @@ FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex); } +expr_t +FirstDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddFirstDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments, + inputIndex); +} + expr_t FirstDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { @@ -5417,6 +5476,18 @@ SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex1, inputIndex2); } +expr_t +SecondDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddSecondDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments, + inputIndex1, inputIndex2); +} + expr_t SecondDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { diff --git a/ExprNode.hh b/ExprNode.hh index b008333c..b6c7b9b9 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2014 Dynare Team + * Copyright (C) 2007-2015 Dynare Team * * This file is part of Dynare. * @@ -407,6 +407,9 @@ public: //! Add ExprNodes to the provided datatree virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; + //! Add ExprNodes to the provided datatree, changing the symbol id from those provided in orig_symbol_table + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; + //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor virtual expr_t removeTrendLeadLag(map trend_symbols_map) const = 0; @@ -467,6 +470,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -529,6 +533,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -606,6 +611,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -696,6 +702,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; //! Function to write out the oPowerNode in expr_t terms as opposed to writing out the function itself expr_t unpackPowerDeriv() const; @@ -766,6 +773,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -841,6 +849,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -871,6 +880,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class FirstDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -905,6 +915,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class SecondDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -941,6 +952,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; #endif diff --git a/ModFile.cc b/ModFile.cc index 847fc7e3..1d1df2a5 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -307,6 +307,19 @@ ModFile::checkPass() void ModFile::transformPass(bool nostrict) { + // Remove unused exogenous from symbol table and update dynamic_model + set unusedExo = dynamic_model.findUnusedExogenous(); + if (unusedExo.size() > 0) + { + SymbolTable orig_symbol_table = symbol_table; + symbol_table.rmExo(unusedExo); + dynamic_model.reindexEquations(dynamic_model, orig_symbol_table); + vector orig_statements = statements; + statements.clear(); + for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) + addStatement((*it)->cloneAndReindexSymbIds(dynamic_model, orig_symbol_table)); + } + // Save the original model (must be done before any model transformations by preprocessor) dynamic_model.cloneDynamic(original_model); diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 3df225fc..4937308c 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -73,6 +73,24 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const } } +Statement * +InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + cout << orig_symbol_table.getName(symb_id) << " " << symb_id << "->" << new_symbol_table->getID(orig_symbol_table.getName(symb_id)) << endl; + return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), + param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), + *new_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; + exit(EXIT_FAILURE); + } +} + InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -208,6 +226,27 @@ InitValStatement::writeOutputPostInit(ostream &output) const <<"end;" << endl; } +Statement * +InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + init_values_t new_init_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the initval statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new InitValStatement(new_init_values, *new_symbol_table, all_values_required); +} + EndValStatement::EndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -254,6 +293,27 @@ EndValStatement::writeOutput(ostream &output, const string &basename) const writeInitValues(output); } +Statement * +EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + init_values_t new_init_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the endval statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new EndValStatement(new_init_values, *new_symbol_table, all_values_required); +} + HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, const SymbolTable &symbol_table_arg) : hist_values(hist_values_arg), @@ -320,6 +380,28 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const } } +Statement * +HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + hist_values_t new_hist_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (hist_values_t::const_iterator it=hist_values.begin(); + it != hist_values.end(); it++) + new_hist_values[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + it->first.second)] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the hist_val statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new HistValStatement(new_hist_values, *new_symbol_table); +} + InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : filename(filename_arg) { @@ -393,9 +475,10 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba output << "save_params_and_steady_state('" << filename << "');" << endl; } -LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename, +LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename_arg, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings) : + filename(filename_arg), symbol_table(symbol_table_arg) { cout << "Reading " << filename << "." << endl; @@ -465,3 +548,10 @@ LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) it != content.end(); it++) eval_context[it->first] = atof(it->second.c_str()); } + +Statement * +LoadParamsAndSteadyStateStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + WarningConsolidation warnings(false); + return new LoadParamsAndSteadyStateStatement(filename, *(dynamic_datatree.getSymbolTable()), warnings); +} diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index c61d41e1..913e2730 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -44,6 +44,7 @@ public: virtual void writeCOutput(ostream &output, const string &basename); //! Fill eval context with parameter value void fillEvalContext(eval_context_t &eval_context) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class InitOrEndValStatement : public Statement @@ -80,6 +81,7 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Writes initializations for oo_.exo_simul and oo_.exo_det_simul void writeOutputPostInit(ostream &output) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EndValStatement : public InitOrEndValStatement @@ -91,6 +93,7 @@ public: //! Workaround for trac ticket #35 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class HistValStatement : public Statement @@ -111,6 +114,7 @@ public: //! Workaround for trac ticket #157 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class InitvalFileStatement : public Statement @@ -158,17 +162,19 @@ public: class LoadParamsAndSteadyStateStatement : public Statement { private: + const string filename; const SymbolTable &symbol_table; //! Content of the file /*! Maps symbol ID to numeric value (stored as string) */ map content; public: - LoadParamsAndSteadyStateStatement(const string &filename, + LoadParamsAndSteadyStateStatement(const string &filename_arg, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; //! Fill eval context with parameters/variables values void fillEvalContext(eval_context_t &eval_context) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif diff --git a/Statement.cc b/Statement.cc index d4d522e7..2b3cd8c6 100644 --- a/Statement.cc +++ b/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -73,6 +73,12 @@ Statement::computingPass() { } +Statement * +Statement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + return this; +} + NativeStatement::NativeStatement(const string &native_statement_arg) : native_statement(native_statement_arg) { diff --git a/Statement.hh b/Statement.hh index 5bdade39..30643596 100644 --- a/Statement.hh +++ b/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -27,6 +27,8 @@ #include "SymbolList.hh" #include "WarningConsolidation.hh" +#include "SymbolTable.hh" +#include "DataTree.hh" class ModFileStructure { @@ -136,6 +138,11 @@ public: */ virtual void writeOutput(ostream &output, const string &basename) const = 0; virtual void writeCOutput(ostream &output, const string &basename); + //! clone a statement while updating all symbol ids that are contained within it. + /* Symbol id's are updated from the symbol table contained in dynamic_datatree + The original symbol table is contained in orig_symbol_table + */ + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class NativeStatement : public Statement diff --git a/SymbolTable.cc b/SymbolTable.cc index 9d43b791..490dbb31 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -21,6 +21,7 @@ #include #include #include +#include #include "SymbolTable.hh" @@ -473,6 +474,40 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce return symb_id; } +void +SymbolTable::rmExo(set &unused) throw (FrozenException) +{ + if (frozen) + throw FrozenException(); + + list idxs; + for (set::const_iterator it = unused.begin(); it != unused.end(); it++) + { + string name = getName(*it); + idxs.push_back(symbol_table[name]); + symbol_table.erase(name); + size--; + } + + idxs.sort(); + idxs.reverse(); + for (list::const_iterator it = idxs.begin(); it != idxs.end(); it++) + { + type_table.erase(type_table.begin() + *it); + name_table.erase(name_table.begin() + *it); + tex_name_table.erase(tex_name_table.begin() + *it); + long_name_table.erase(long_name_table.begin() + *it); + } + + symbol_table.clear(); + int i = 0; + for (vector::const_iterator it=name_table.begin(); + it != name_table.end(); it++) + symbol_table[*it] = i++; + + assert(size == symbol_table.size()); +} + int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index 3e4c47e1..85267fe6 100644 --- a/SymbolTable.hh +++ b/SymbolTable.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,8 @@ public: bool isAuxiliaryVariable(int symb_id) const; //! Get list of endogenous variables without aux vars set getOrigEndogenous() const; + //! Remove exogenous variables contained in the set + void rmExo(set &unused) throw (FrozenException); }; inline bool From 5cc4ad033f1c8850450de0fdf733052c6c5f1d2e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 10 Mar 2015 11:24:20 +0100 Subject: [PATCH 02/54] preprocessor: remove spurious print statement --- NumericalInitialization.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 4937308c..943bbb93 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -79,7 +79,6 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { - cout << orig_symbol_table.getName(symb_id) << " " << symb_id << "->" << new_symbol_table->getID(orig_symbol_table.getName(symb_id)) << endl; return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), *new_symbol_table); From 81a2a2ee0d01e277efb57c6f561dcf46f5f9f0e4 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 10 Mar 2015 14:10:10 +0100 Subject: [PATCH 03/54] =?UTF-8?q?remove=20extra=20exo=E2=80=99s=20for=20sh?= =?UTF-8?q?ocks=20statement,=20nonstationary,=20and=20trend=20vars;=20fix?= =?UTF-8?q?=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DynamicModel.cc | 54 ++++++++++++++++++++++++++++ DynamicModel.hh | 11 +++++- ModFile.cc | 1 + Shocks.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ Shocks.hh | 4 ++- 5 files changed, 164 insertions(+), 2 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index a4997e02..493bbff4 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3425,6 +3425,60 @@ 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() +{ + num_const_node_map.clear(); + 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(); +} + void DynamicModel::reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) { diff --git a/DynamicModel.hh b/DynamicModel.hh index b13d23e1..79f085de 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -238,6 +238,15 @@ public: //! 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(); + //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model @@ -248,7 +257,7 @@ public: //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; - + //! Returns number of dynamic only equations size_t dynamicOnlyEquationsNbr() const; diff --git a/ModFile.cc b/ModFile.cc index 1d1df2a5..f21f8f62 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -313,6 +313,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); vector orig_statements = statements; statements.clear(); diff --git a/Shocks.cc b/Shocks.cc index d0aecd96..46632b3d 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -67,6 +67,31 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const output << "M_.exo_det_length = " << exo_det_length << ";\n"; } +AbstractShocksStatement::det_shocks_t +AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + det_shocks_t new_det_shocks; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + for (det_shocks_t::const_iterator it=det_shocks.begin(); it!=det_shocks.end(); it++) + try + { + vector det_shock_vec; + for (int i=0; isecond.size(); i++) + { + DetShockElement dse; + dse.period1 = it->second[1].period1; + dse.period2 = it->second[1].period2; + dse.value = it->second[i].value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + det_shock_vec.push_back(dse); + } + new_det_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = det_shock_vec; + } + catch (...) + { + } + return new_det_shocks; +} + ShocksStatement::ShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const var_and_std_shocks_t &var_shocks_arg, @@ -332,6 +357,69 @@ ShocksStatement::has_calibrated_measurement_errors() const return false; } +Statement * +ShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + var_and_std_shocks_t new_var_shocks, new_std_shocks; + covar_and_corr_shocks_t new_covar_shocks, new_corr_shocks; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + + for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); + it != var_shocks.end(); it++) + try + { + new_var_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); + it != std_shocks.end(); it++) + try + { + new_std_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); + it != covar_shocks.end(); it++) + try + { + new_covar_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); + it != corr_shocks.end(); it++) + try + { + new_corr_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + return new ShocksStatement(overwrite, + reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), + new_var_shocks, + new_std_shocks, + new_covar_shocks, + new_corr_shocks, + *(dynamic_datatree.getSymbolTable())); +} + + MShocksStatement::MShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg) : @@ -352,6 +440,14 @@ MShocksStatement::writeOutput(ostream &output, const string &basename) const writeDetShocks(output); } +Statement * +MShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + return new MShocksStatement(overwrite, + reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), + *(dynamic_datatree.getSymbolTable())); +} + ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const AbstractShocksStatement::det_shocks_t &paths_arg) : paths(paths_arg), path_length(-1) diff --git a/Shocks.hh b/Shocks.hh index 6ab43a64..2072e02f 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -50,7 +50,7 @@ protected: const det_shocks_t det_shocks; const SymbolTable &symbol_table; void writeDetShocks(ostream &output) const; - + det_shocks_t reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); AbstractShocksStatement(bool mshocks_arg, bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); @@ -79,6 +79,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class MShocksStatement : public AbstractShocksStatement @@ -88,6 +89,7 @@ public: const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastPathsStatement : public Statement From 52e3bc993c917231833a52fd0ad8d4e2f41f79ca Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 12:23:36 +0200 Subject: [PATCH 04/54] fix copyright dates --- Shocks.cc | 2 +- Shocks.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Shocks.cc b/Shocks.cc index 46632b3d..0ea7fd53 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * diff --git a/Shocks.hh b/Shocks.hh index 2072e02f..7ea320db 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * From e2c0f5698f5851135715b409021418d3a8b5c559 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 12:45:31 +0200 Subject: [PATCH 05/54] preprocessor: fix bug in shocks statement for removal of exos --- Shocks.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shocks.cc b/Shocks.cc index 0ea7fd53..1c70cee0 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -79,8 +79,8 @@ AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, Sym for (int i=0; isecond.size(); i++) { DetShockElement dse; - dse.period1 = it->second[1].period1; - dse.period2 = it->second[1].period2; + dse.period1 = it->second[i].period1; + dse.period2 = it->second[i].period2; dse.value = it->second[i].value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); det_shock_vec.push_back(dse); } From 8a92da9c5adafce49b5a076b74e690db3dcf2364 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 16:59:47 +0200 Subject: [PATCH 06/54] preprocessor: take care of extra exos in stoch_simul --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 2d7b1ffc..18d54db9 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -165,6 +165,42 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } +Statement * +StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the stoch_simul statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new StochSimulStatement(new_symbol_list, new_options_list); +} + void StochSimulStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d19f3e4c..d84ef1af 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -97,6 +97,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ForecastStatement : public Statement From 71f76cdaa6688ff1595e2f8d6c2bc21e428c164f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 17:41:41 +0200 Subject: [PATCH 07/54] preprocessor: take care of extra exos in forecast statement --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 18d54db9..7fc5d59e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -223,6 +223,29 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, { } +Statement * +ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the forecast statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new ForecastStatement(new_symbol_list, options_list); +} + void ForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d84ef1af..bc7dbcb1 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -109,6 +109,7 @@ public: ForecastStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyModelStatement : public Statement From e82958222e22bc03719684fa0bae7454bd648865 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 17:50:16 +0200 Subject: [PATCH 08/54] preprocessor: take care of extra exos in ramsey_model statement --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7fc5d59e..a17099ea 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -293,6 +293,29 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol mod_file_struct.k_order_solver = true; } +Statement * +RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ramsey_model statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new RamseyModelStatement(new_symbol_list, options_list); +} + void RamseyModelStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index bc7dbcb1..b5da1f9d 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -122,6 +122,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyPolicyStatement : public Statement From 33420148dd1525fa54d249e7dc8f7768284a985f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:19:51 +0200 Subject: [PATCH 09/54] preprocessor: take care of extra exos in ramsey_policy --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index a17099ea..9fdd0430 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -377,6 +377,42 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.k_order_solver = true; } +Statement * +RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ramsey_policy statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new RamseyPolicyStatement(new_symbol_list, new_options_list); +} + void RamseyPolicyStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b5da1f9d..02e83750 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -135,6 +135,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DiscretionaryPolicyStatement : public Statement From 5163f2887118dcd15ac779b317bed88e0d94a75d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:26:07 +0200 Subject: [PATCH 10/54] preprocessor: take care of extra exos in discretionary_policy --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9fdd0430..b7b40e51 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -473,6 +473,29 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.k_order_solver = true; } +Statement * +DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the discretionary_policy statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new DiscretionaryPolicyStatement(new_symbol_list, options_list); +} + void DiscretionaryPolicyStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 02e83750..fbb94dff 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -148,6 +148,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RplotStatement : public Statement From 18624e0f8ffaaaa2fa97f6dcb2608f83e9dca3c7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:36:56 +0200 Subject: [PATCH 11/54] preprocessor: take care of extra exos in estimation --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b7b40e51..b90b65db 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -602,6 +602,42 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimation statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new EstimationStatement(new_symbol_list, new_options_list); +} + void EstimationStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index fbb94dff..0dacf107 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -198,6 +198,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynareSensitivityStatement : public Statement From c5b58ee1d93330af21aadcf8706d06ed17641873 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 15:06:04 +0200 Subject: [PATCH 12/54] preprocessor: take care of extra exos in dynare_sensitivity --- ComputingTasks.cc | 35 +++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 36 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b90b65db..373b73fa 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -673,6 +673,41 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning mod_file_struct.identification_present = true; } +Statement * +DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + { + new_symbol_table->getID(*it2); + new_options_symbol_list.addSymbol(*it2); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynare_sensitivity statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new DynareSensitivityStatement(new_options_list); +} + void DynareSensitivityStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 0dacf107..786cf947 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -209,6 +209,7 @@ public: DynareSensitivityStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ObservationTrendsStatement : public Statement From e4b10c4ec6e1f6893b8336e057671c09c4fa1f6e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 15:48:07 +0200 Subject: [PATCH 13/54] preprocessor: take care of extra exos in rplot --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1b14ebc6..7882a61f 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -735,6 +735,29 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : { } +Statement * +RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the rplot statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new RplotStatement(new_symbol_list); +} + void RplotStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index e1c659c1..a3dc37ca 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -158,6 +158,7 @@ private: public: RplotStatement(const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class UnitRootVarsStatement : public Statement From 27a69b8cec49525cd491e096cae2bcf46f9ba295 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 17:42:01 +0200 Subject: [PATCH 14/54] take care of extra exos in estimated_params --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7882a61f..b060df70 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -874,6 +874,32 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name)); } +Statement * +EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new EstimatedParamsStatement(estim_params_list, *new_symbol_table); +} + void EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index a3dc37ca..690315c7 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -318,6 +318,7 @@ public: const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EstimatedParamsInitStatement : public Statement From 5a60f2d9d7f1baf3807e95e63ecf9095c30fa07d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 17:57:12 +0200 Subject: [PATCH 15/54] take care of extra exos in estimated_params_init --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b060df70..c617fbf4 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -975,6 +975,32 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.estim_params_use_calib = true; } +Statement * +EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params_init statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new EstimatedParamsInitStatement(estim_params_list, *new_symbol_table, use_calibration); +} + void EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 690315c7..d1b08beb 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -333,6 +333,7 @@ public: const bool use_calibration_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EstimatedParamsBoundsStatement : public Statement From fd5b9279da0b583a6649ba09826230c4936893e0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 18:03:16 +0200 Subject: [PATCH 16/54] take care of extra exos in estimated_params_bounds --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index c617fbf4..4b7b7c7e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1067,6 +1067,32 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params_bounds statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new EstimatedParamsBoundsStatement(estim_params_list, *new_symbol_table); +} + void EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d1b08beb..968fd5d9 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -345,6 +345,7 @@ public: EstimatedParamsBoundsStatement(const vector &estim_params_list_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptimWeightsStatement : public Statement From e7218bd26a2fe05c44cb444e0df1a4ba1d90853c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:20:11 +0200 Subject: [PATCH 17/54] preprocessor: take care of extra exos in observation_trends --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 4b7b7c7e..9acdc06a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1181,6 +1181,29 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t { } +Statement * +ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + map new_trend_elements; + try + { + for (map::const_iterator it = trend_elements.begin(); + it != trend_elements.end(); it++) + { + new_symbol_table->getID(it->first); + new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + } + catch (...) + { + cerr << "ERROR: A variable in the observation_trends statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new ObservationTrendsStatement(new_trend_elements, *new_symbol_table); +} + void ObservationTrendsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 968fd5d9..3a4df94b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -222,6 +222,7 @@ public: ObservationTrendsStatement(const trend_elements_t &trend_elements_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OsrParamsStatement : public Statement From f852c834c2c32b986c3a405ff2de73fe3034ebba Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:21:54 +0200 Subject: [PATCH 18/54] preprocessor: update warning message for missing varexos --- ModFile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModFile.cc b/ModFile.cc index f21f8f62..570ad72a 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -300,7 +300,7 @@ ModFile::checkPass() if (++it != unusedExo.end()) warnings << ", "; } - warnings << ") are declared but not used in the model. This may lead to crashes or unexpected behaviour." << endl; + warnings << ") are declared but not used in the model. We have removed them and will attempt to continue..." << endl; } } From 6a634ba1043e15b3d76dc03992d8406712762563 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:30:55 +0200 Subject: [PATCH 19/54] preprocessor: take care of extra exos in osr_params --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9acdc06a..1274858b 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1237,6 +1237,29 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid mod_file_struct.osr_params_present = true; } +Statement * +OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the osr_params statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OsrParamsStatement(new_symbol_list); +} + void OsrParamsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3a4df94b..88d51c2c 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -233,6 +233,7 @@ public: OsrParamsStatement(const SymbolList &symbol_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OsrStatement : public Statement From 9dda8c40585b528f7e9664e9fcede9d7bf104f0f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:46:44 +0200 Subject: [PATCH 20/54] preprocessor: take care of extra exos in osr --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1274858b..1a9e4601 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1295,6 +1295,29 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation mod_file_struct.k_order_solver = true; } +Statement * +OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the osr statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OsrStatement(new_symbol_list, options_list); +} + void OsrStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 88d51c2c..3736d0de 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -246,6 +246,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynaTypeStatement : public Statement From de1af956047da881d79cceb48d35d1666785d6de Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:58:13 +0200 Subject: [PATCH 21/54] preprocessor: take care of extra exos in optim_weights --- ComputingTasks.cc | 33 +++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 34 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1a9e4601..7f1e8f04 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1348,6 +1348,39 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.optim_weights_present = true; } +Statement * +OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + var_weights_t new_var_weights; + covar_weights_t new_covar_weights; + try + { + for (var_weights_t::const_iterator it = var_weights.begin(); + it != var_weights.end(); it++) + { + new_symbol_table->getID(it->first); + new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + + for (covar_weights_t::const_iterator it = covar_weights.begin(); + it != covar_weights.end(); it++) + { + new_symbol_table->getID(it->first.first); + new_symbol_table->getID(it->first.second); + new_covar_weights[make_pair(it->first.first, it->first.second)] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + } + catch (...) + { + cerr << "ERROR: A variable in the optim_weights statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OptimWeightsStatement(new_var_weights, new_covar_weights, *new_symbol_table); +} + void OptimWeightsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3736d0de..01f3cd2e 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -366,6 +366,7 @@ public: const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; /*! \todo Make model_tree a member instead of a pointer */ From 0c6f84bdcf8248a025abc7cb5958978333e5ea88 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 17:11:28 +0200 Subject: [PATCH 22/54] preprocessor: take care of extra exos in dynasave --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7f1e8f04..d32157f3 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1424,6 +1424,29 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, { } +Statement * +DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynasave statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new DynaSaveStatement(new_symbol_list, filename); +} + void DynaSaveStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 01f3cd2e..dc9a873b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -269,6 +269,7 @@ public: DynaSaveStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelComparisonStatement : public Statement From 47d0516d4fb76767b61711d940c2249e23687677 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 17:15:01 +0200 Subject: [PATCH 23/54] preprocessor: take care of extra exos in dynatype --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d32157f3..1d86564e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1462,6 +1462,29 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, { } +Statement * +DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynatype statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new DynaTypeStatement(new_symbol_list, filename); +} + void DynaTypeStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index dc9a873b..4eedddb4 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -258,6 +258,7 @@ public: DynaTypeStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynaSaveStatement : public Statement From ef640070c27305584eef65fdbc5de7168f706e82 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 7 Apr 2015 15:11:39 +0200 Subject: [PATCH 24/54] preprocessor: move reindexing functions from DynamicModel to ModelTree --- DynamicModel.cc | 57 ------------------------------------------- DynamicModel.hh | 9 ------- ModFile.cc | 2 +- ModelTree.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ ModelTree.hh | 9 ++++++- 5 files changed, 73 insertions(+), 68 deletions(-) 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 From 5fb6667f869698b5e8b6341bbb5d6c7120a347ac Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 14:04:05 +0200 Subject: [PATCH 25/54] preprocessor: take care of extra exos in external functions --- DataTree.cc | 8 ++++++- DataTree.hh | 2 ++ ExternalFunctionsTable.cc | 44 +++++++++++++++++++++++++++++++++++++-- ExternalFunctionsTable.hh | 6 +++++- ModelTree.cc | 1 + 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index 3f90a44f..7135c9c6 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -50,6 +50,12 @@ DataTree::~DataTree() delete *it; } +void +DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) +{ + external_functions_table.reindex(symbol_table, orig_symbol_table); +} + expr_t DataTree::AddNonNegativeConstant(const string &value) { diff --git a/DataTree.hh b/DataTree.hh index f81f19e6..87f61726 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -238,6 +238,8 @@ public: void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv void writePowerDeriv(ostream &output, bool use_dll) const; + //! reindex external functions + void reindexExternalFunctions(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id class UnknownDerivIDException { diff --git a/ExternalFunctionsTable.cc b/ExternalFunctionsTable.cc index 8554d830..2fa1523d 100644 --- a/ExternalFunctionsTable.cc +++ b/ExternalFunctionsTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -24,7 +24,6 @@ #include #include "ExternalFunctionsTable.hh" -#include "SymbolTable.hh" ExternalFunctionsTable::ExternalFunctionsTable() { @@ -115,3 +114,44 @@ ExternalFunctionsTable::addExternalFunction(int symb_id, const external_function externalFunctionTable[symb_id] = external_function_options_chng; } + +void +ExternalFunctionsTable::reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table) +{ + external_function_table_type orig_externalFunctionTable = externalFunctionTable; + externalFunctionTable.clear(); + for (external_function_table_type::const_iterator it = orig_externalFunctionTable.begin(); + it != orig_externalFunctionTable.end(); it++) + try + { + external_function_options new_external_function_options; + if (it->second.firstDerivSymbID == eExtFunNotSet || + it->second.firstDerivSymbID == eExtFunSetButNoNameProvided) + new_external_function_options.firstDerivSymbID = it->second.firstDerivSymbID; + else + new_external_function_options.firstDerivSymbID = + new_symbol_table.getID(orig_symbol_table.getName(it->second.firstDerivSymbID)); + + if (it->second.secondDerivSymbID == eExtFunNotSet || + it->second.secondDerivSymbID == eExtFunSetButNoNameProvided) + new_external_function_options.secondDerivSymbID = it->second.secondDerivSymbID; + else + new_external_function_options.secondDerivSymbID = + new_symbol_table.getID(orig_symbol_table.getName(it->second.secondDerivSymbID)); + new_external_function_options.nargs = it->second.nargs; + bool new_track_nargs = true; + if (it->second.nargs == eExtFunNotSet) + { + new_track_nargs = false; + new_external_function_options.nargs = eExtFunSetDefaultNargs; + } + addExternalFunction(new_symbol_table.getID(orig_symbol_table.getName(it->first)), + new_external_function_options, + new_track_nargs); + } + catch (...) + { + cerr << "Error: problem encountered when reindexing external functions table." << endl; + exit(EXIT_FAILURE); + } +} diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index aa4b02cd..b5218bea 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -27,6 +27,8 @@ using namespace std; #include #include +#include "SymbolTable.hh" + enum ExternalFunctionSetOrNot { eExtFunSetButNoNameProvided = -2, //! Signifies that the derivative is obtained from the top-level function @@ -76,6 +78,8 @@ public: inline int getSecondDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Returns the total number of unique external functions declared or used in the .mod file inline int get_total_number_of_unique_model_block_external_functions() const; + //! Reindex external function table (after removal of extra exo) + void reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table); }; inline bool diff --git a/ModelTree.cc b/ModelTree.cc index b95a508e..b252d96d 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1419,6 +1419,7 @@ ModelTree::reindex(SymbolTable &orig_symbol_table) reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); + reindexExternalFunctions(orig_symbol_table); } void From c22d5f6b2be6470c0d160bf233d2cf412e09be7b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 16:35:09 +0200 Subject: [PATCH 26/54] preprocessor: take care of extra exos in planner_objective --- ComputingTasks.cc | 16 ++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 17 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1d86564e..7700ebc2 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1534,6 +1534,22 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC mod_file_struct.planner_objective_present = true; } +Statement * +PlannerObjectiveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + model_tree->reindex(orig_symbol_table); + } + catch (...) + { + cerr << "ERROR: A variable in the planner_objective statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new PlannerObjectiveStatement(model_tree); +} + StaticModel * PlannerObjectiveStatement::getPlannerObjective() const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 4eedddb4..fdb894ee 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -390,6 +390,7 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Return the Planner Objective StaticModel *getPlannerObjective() const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class BVARDensityStatement : public Statement From 5b029637e7ecc81e0978d281a57efdb5da0ded02 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 17:30:45 +0200 Subject: [PATCH 27/54] preprocessor: take care of extra exos in ms_sbvar_irf --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7700ebc2..caad9f15 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1765,6 +1765,29 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ms_sbvar_irf statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new MSSBVARIrfStatement(new_symbol_list, options_list); +} + void MSSBVARIrfStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index fdb894ee..7d8a7a3b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -475,6 +475,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class MSSBVARForecastStatement : public Statement From 1b81049cb04229d6fa3fb10787a494777aa365af Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:04:36 +0200 Subject: [PATCH 28/54] preprocessor: take care of extra exos in shock_decomposition --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index caad9f15..c4dc0778 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1946,6 +1946,29 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo { } +Statement * +ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the shock_decomposition statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new ShockDecompositionStatement(new_symbol_list, options_list); +} + void ShockDecompositionStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 7d8a7a3b..03b1f4ce 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -544,6 +544,7 @@ public: ShockDecompositionStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastStatement : public Statement From 6b79c05e451fdf10ab374fa182e3ec46c697f0f6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:12:09 +0200 Subject: [PATCH 29/54] preprocessor: take care of extra exos in conditional_forecast --- ComputingTasks.cc | 30 ++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 31 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index c4dc0778..ebfdb366 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1982,6 +1982,36 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op { } +Statement * +ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + OptionsList new_options_list = options_list; + try + { + OptionsList::symbol_list_options_t::const_iterator it = + options_list.symbol_list_options.find("controlled_varexo"); + if (it != options_list.symbol_list_options.end()) + { + SymbolList new_options_symbol_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the conditional_forecast statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new ConditionalForecastStatement(new_options_list); +} + void ConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 03b1f4ce..72c3649f 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -554,6 +554,7 @@ private: public: ConditionalForecastStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PlotConditionalForecastStatement : public Statement From f329a2686e13c16c09da778b3bf2e8d8f3532f68 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:16:52 +0200 Subject: [PATCH 30/54] preprocessor: take care of extra exos in plot_conditional_forecast --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index ebfdb366..82327b03 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2025,6 +2025,29 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a { } +Statement * +PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the plot_conditional_forecast statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new PlotConditionalForecastStatement(periods, new_symbol_list); +} + void PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 72c3649f..4c761a08 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -566,6 +566,7 @@ private: public: PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CalibSmootherStatement : public Statement From cb086756966db160f407b67b00a927cd8aa5df5d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 15:18:12 +0200 Subject: [PATCH 31/54] preprocessor: pointer to symbol_table unnecessary --- ComputingTasks.cc | 14 ++++++-------- NumericalInitialization.cc | 20 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 82327b03..02adf8d7 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1184,14 +1184,13 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t Statement * ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); map new_trend_elements; try { for (map::const_iterator it = trend_elements.begin(); it != trend_elements.end(); it++) { - new_symbol_table->getID(it->first); + symbol_table.getID(it->first); new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } } @@ -1201,7 +1200,7 @@ ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, S << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new ObservationTrendsStatement(new_trend_elements, *new_symbol_table); + return new ObservationTrendsStatement(new_trend_elements, symbol_table); } void @@ -1351,7 +1350,6 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); var_weights_t new_var_weights; covar_weights_t new_covar_weights; try @@ -1359,15 +1357,15 @@ OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol for (var_weights_t::const_iterator it = var_weights.begin(); it != var_weights.end(); it++) { - new_symbol_table->getID(it->first); + symbol_table.getID(it->first); new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } for (covar_weights_t::const_iterator it = covar_weights.begin(); it != covar_weights.end(); it++) { - new_symbol_table->getID(it->first.first); - new_symbol_table->getID(it->first.second); + symbol_table.getID(it->first.first); + symbol_table.getID(it->first.second); new_covar_weights[make_pair(it->first.first, it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } @@ -1378,7 +1376,7 @@ OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new OptimWeightsStatement(new_var_weights, new_covar_weights, *new_symbol_table); + return new OptimWeightsStatement(new_var_weights, new_covar_weights, symbol_table); } void diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 943bbb93..de910dc0 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -76,12 +76,11 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const Statement * InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { - return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), + return new InitParamStatement(symbol_table.getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), - *new_symbol_table); + symbol_table); } catch (SymbolTable::UnknownSymbolIDException &e) { @@ -229,12 +228,11 @@ Statement * InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { init_values_t new_init_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (init_values_t::const_iterator it=init_values.begin(); it != init_values.end(); it++) - new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } catch (SymbolTable::UnknownSymbolIDException &e) @@ -243,7 +241,7 @@ InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new InitValStatement(new_init_values, *new_symbol_table, all_values_required); + return new InitValStatement(new_init_values, symbol_table, all_values_required); } EndValStatement::EndValStatement(const init_values_t &init_values_arg, @@ -296,12 +294,11 @@ Statement * EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { init_values_t new_init_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (init_values_t::const_iterator it=init_values.begin(); it != init_values.end(); it++) - new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } catch (SymbolTable::UnknownSymbolIDException &e) @@ -310,7 +307,7 @@ EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new EndValStatement(new_init_values, *new_symbol_table, all_values_required); + return new EndValStatement(new_init_values, symbol_table, all_values_required); } HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, @@ -383,12 +380,11 @@ Statement * HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { hist_values_t new_hist_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (hist_values_t::const_iterator it=hist_values.begin(); it != hist_values.end(); it++) - new_hist_values[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_hist_values[make_pair(symbol_table.getID(orig_symbol_table.getName(it->first.first)), it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } @@ -398,7 +394,7 @@ HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new HistValStatement(new_hist_values, *new_symbol_table); + return new HistValStatement(new_hist_values, symbol_table); } InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : From 3deea8367db37425888cbe8bf114d733575b7308 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:14:25 +0200 Subject: [PATCH 32/54] preprocessor: remove unnecessary cloneAndReindexSymbIds method --- NumericalInitialization.cc | 7 ------- NumericalInitialization.hh | 1 - 2 files changed, 8 deletions(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index de910dc0..e588bc0d 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -543,10 +543,3 @@ LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) it != content.end(); it++) eval_context[it->first] = atof(it->second.c_str()); } - -Statement * -LoadParamsAndSteadyStateStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - WarningConsolidation warnings(false); - return new LoadParamsAndSteadyStateStatement(filename, *(dynamic_datatree.getSymbolTable()), warnings); -} diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index 913e2730..84f04770 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -174,7 +174,6 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Fill eval context with parameters/variables values void fillEvalContext(eval_context_t &eval_context) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif From bddcc87c6e114932cbd894fc2426f3201812f2c9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:17:22 +0200 Subject: [PATCH 33/54] preprocessor: replace catch all exceptions in catch statements for clone/reindex methods --- ComputingTasks.cc | 38 +++++++++++++++++++------------------- NumericalInitialization.cc | 8 ++++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 02adf8d7..abf45b23 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -192,7 +192,7 @@ StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the stoch_simul statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -237,7 +237,7 @@ ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the forecast statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -307,7 +307,7 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ramsey_model statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -404,7 +404,7 @@ RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ramsey_policy statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -487,7 +487,7 @@ DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the discretionary_policy statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -629,7 +629,7 @@ EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimation statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -699,7 +699,7 @@ DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, S } } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynare_sensitivity statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -749,7 +749,7 @@ RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable & new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the rplot statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -891,7 +891,7 @@ EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Sym else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -992,7 +992,7 @@ EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params_init statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1084,7 +1084,7 @@ EstimatedParamsBoundsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatre else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params_bounds statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1250,7 +1250,7 @@ OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the osr_params statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1308,7 +1308,7 @@ OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &or new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the osr statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1436,7 +1436,7 @@ DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynasave statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1474,7 +1474,7 @@ DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynatype statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1777,7 +1777,7 @@ MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ms_sbvar_irf statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -1958,7 +1958,7 @@ ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the shock_decomposition statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -2001,7 +2001,7 @@ ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the conditional_forecast statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -2037,7 +2037,7 @@ PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datat new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the plot_conditional_forecast statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index e588bc0d..08a172f8 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -82,7 +82,7 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), symbol_table); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; exit(EXIT_FAILURE); @@ -235,7 +235,7 @@ InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the initval statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -301,7 +301,7 @@ EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the endval statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; @@ -388,7 +388,7 @@ HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the hist_val statement was not found in the symbol table" << endl << " This likely means that you have declared a varexo that is not used in the model" << endl; From 6df3bb785e616791ce290071bc9861bdabf00d39 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:17:47 +0200 Subject: [PATCH 34/54] preprocessor: fix error message for InitParamStatement clone/reindex method --- NumericalInitialization.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 08a172f8..501f202b 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -84,7 +84,8 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab } catch (...) { - cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; + cerr << "ERROR: A variable in the init_param statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } } From 8719bbff32387cdad098fba0e127aa727c83deaa Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:29:52 +0200 Subject: [PATCH 35/54] preprocessor: take care of extra exos in ramsey_model instruments option --- ComputingTasks.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index abf45b23..01a7205f 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -296,7 +296,8 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolList new_symbol_list; + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; try { SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); @@ -306,6 +307,19 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_table->getID(*it); new_symbol_list.addSymbol(*it); } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } catch (...) { From 7cc464b5ea9cbe633df27bad6c648da83d8b595b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 12:06:53 +0200 Subject: [PATCH 36/54] preprocessor: take care of exos in prior statements --- ComputingTasks.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 4 +++ 2 files changed, 87 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index bc004ae0..9d1a93b7 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2974,6 +2974,23 @@ PriorStatement::PriorStatement(const string &name_arg, { } +Statement * +PriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the prior statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new PriorStatement(name, subsample_name, prior_shape, variance, options_list); +} + void PriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3011,6 +3028,23 @@ StdPriorStatement::StdPriorStatement(const string &name_arg, { } +Statement * +StdPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the std_prior statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new StdPriorStatement(name, subsample_name, prior_shape, variance, options_list, *new_symbol_table); +} + void StdPriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3074,6 +3108,24 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } } +Statement * +CorrPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + new_symbol_table->getID(name1); + } + catch (...) + { + cerr << "ERROR: A variable in the corr_prior statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new CorrPriorStatement(name, name1, subsample_name, prior_shape, variance, options_list, *new_symbol_table); +} + void CorrPriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3153,6 +3205,37 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +PriorEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(to_name1); + if (!to_name2.empty()) + new_symbol_table->getID(to_name2); + + new_symbol_table->getID(from_name1); + if (!from_name2.empty()) + new_symbol_table->getID(from_name2); + } + catch (...) + { + cerr << "ERROR: A variable in the prior equal statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new PriorEqualStatement(to_declaration_type, + to_name1, + to_name2, + to_subsample_name, + from_declaration_type, + from_name1, + from_name2, + from_subsample_name, + *new_symbol_table); +} + void PriorEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 4c761a08..b6625e81 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -756,6 +756,7 @@ public: const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdPriorStatement : public BasicPriorStatement @@ -771,6 +772,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrPriorStatement : public BasicPriorStatement @@ -789,6 +791,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PriorEqualStatement : public Statement @@ -816,6 +819,7 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class BasicOptionsStatement : public Statement From 1165c2608bab8ab94c5027e7143372ac55456df1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 12:49:15 +0200 Subject: [PATCH 37/54] preprocessor: take care of exos in options statements --- ComputingTasks.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 4 +++ 2 files changed, 87 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9d1a93b7..4955fa1c 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3391,6 +3391,23 @@ OptionsStatement::OptionsStatement(const string &name_arg, { } +Statement * +OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the options statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OptionsStatement(name, subsample_name, options_list); +} + void OptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3419,6 +3436,23 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg, { } +Statement * +StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the std_options statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); +} + void StdOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3474,6 +3508,24 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } } +Statement * +CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + new_symbol_table->getID(name1); + } + catch (...) + { + cerr << "ERROR: A variable in the corr_options statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); +} + void CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3521,6 +3573,37 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } } +Statement * +OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(to_name1); + if (!to_name2.empty()) + new_symbol_table->getID(to_name2); + + new_symbol_table->getID(from_name1); + if (!from_name2.empty()) + new_symbol_table->getID(from_name2); + } + catch (...) + { + cerr << "ERROR: A variable in the options equal statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OptionsEqualStatement(to_declaration_type, + to_name1, + to_name2, + to_subsample_name, + from_declaration_type, + from_name1, + from_name2, + from_subsample_name, + *new_symbol_table); +} + void OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b6625e81..3d3f07f5 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -850,6 +850,7 @@ public: OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdOptionsStatement : public BasicOptionsStatement @@ -863,6 +864,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrOptionsStatement : public BasicOptionsStatement @@ -878,6 +880,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptionsEqualStatement : public Statement @@ -905,6 +908,7 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelDiagnosticsStatement : public Statement From e4f3d31757c6efe002df0c5eafd062b5bb21c2ea Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 14:42:17 +0200 Subject: [PATCH 38/54] preprocessor: take care of exos in calib_smoother statements --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 4955fa1c..1f10ea5a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3687,6 +3687,29 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons mod_file_struct.calib_smoother_present = true; } +Statement * +CalibSmootherStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (...) + { + cerr << "ERROR: A variable in the calib_smoother statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new CalibSmootherStatement(new_symbol_list, options_list); +} + void CalibSmootherStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3d3f07f5..7f17a30a 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -579,6 +579,7 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ExtendedPathStatement : public Statement From f76a6cb58b3f485d2a987f8082e2e7a81da17348 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 15:04:46 +0200 Subject: [PATCH 39/54] preprocessor: take care of exos in smoother2histval statement --- ComputingTasks.cc | 35 +++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 36 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 5fafda9e..7c290d29 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3794,6 +3794,41 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ { } +Statement * +Smoother2histvalStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"invars", "outvars"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + { + new_symbol_table->getID(*it2); + new_options_symbol_list.addSymbol(*it2); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + } + catch (...) + { + cerr << "ERROR: A variable in the smoother2histval statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new Smoother2histvalStatement(new_options_list); +} + void Smoother2histvalStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 7f17a30a..a59ad9ad 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -926,6 +926,7 @@ private: public: Smoother2histvalStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif From 0a7172cb50d98aa87cd756514e9b1a8ae8f1a489 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 18:13:28 +0200 Subject: [PATCH 40/54] preprocessor: little fixes for removing unused exos from symbol_table --- SymbolTable.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index 490dbb31..ffaa7bb8 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -482,12 +482,7 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) list idxs; for (set::const_iterator it = unused.begin(); it != unused.end(); it++) - { - string name = getName(*it); - idxs.push_back(symbol_table[name]); - symbol_table.erase(name); - size--; - } + idxs.push_back(getID(getName(*it))); idxs.sort(); idxs.reverse(); @@ -500,10 +495,10 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) } symbol_table.clear(); - int i = 0; + size = 0; for (vector::const_iterator it=name_table.begin(); it != name_table.end(); it++) - symbol_table[*it] = i++; + symbol_table[*it] = size++; assert(size == symbol_table.size()); } From cb1fb288f4887701f7353695e39240161145d4ac Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 14:21:05 +0200 Subject: [PATCH 41/54] preprocessor: remove clearing of num_const_node_map --- DynamicModel.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index e881b302..c6c308e1 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3432,7 +3432,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode void DynamicModel::resetDataTree() { - num_const_node_map.clear(); variable_node_map.clear(); unary_op_node_map.clear(); binary_op_node_map.clear(); From e045d42c12da1bea7d00432cbead9fab1d76717d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 16:16:26 +0200 Subject: [PATCH 42/54] preprocessor: remove resetDataTree method --- DynamicModel.cc | 12 ------------ DynamicModel.hh | 3 --- ModFile.cc | 1 - ModelTree.cc | 8 ++++++++ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index c6c308e1..1de6bc8c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3429,18 +3429,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } -void -DynamicModel::resetDataTree() -{ - 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(); -} - void DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index e6a56675..7c4b5e0e 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,9 +235,6 @@ public: /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; - //! reset DataTree vars - void resetDataTree(); - //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model diff --git a/ModFile.cc b/ModFile.cc index d9f36dbb..c1c345ff 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -313,7 +313,6 @@ ModFile::transformPass(bool nostrict) { SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); - dynamic_model.resetDataTree(); dynamic_model.reindex(orig_symbol_table); vector orig_statements = statements; statements.clear(); diff --git a/ModelTree.cc b/ModelTree.cc index b252d96d..6f3a10e5 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1416,6 +1416,14 @@ 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(); + reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); From b27a60d06ce2a3262548889d70de43b1c7fe0e1a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 17:00:17 +0200 Subject: [PATCH 43/54] preprocessor: reindex equations marked as [static] --- DynamicModel.cc | 9 +++++++++ DynamicModel.hh | 3 +++ ModFile.cc | 1 + 3 files changed, 13 insertions(+) diff --git a/DynamicModel.cc b/DynamicModel.cc index 1de6bc8c..8805ceb1 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4294,6 +4294,15 @@ DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) static_only_equations_lineno.push_back(lineno); } +void +DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) +{ + vectoreqbak = static_only_equations; + static_only_equations.clear(); + for (size_t i = 0; i < eqbak.size(); i++) + addStaticOnlyEquation(eqbak[i]->cloneDynamic(*this), static_only_equations_lineno[i]); +} + size_t DynamicModel::staticOnlyEquationsNbr() const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 7c4b5e0e..d87093e7 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -243,6 +243,9 @@ public: //! Adds an equation marked as [static] void addStaticOnlyEquation(expr_t eq, int lineno); + //! reindex equations marked as [static] + void reindexStaticOnlyEquations(SymbolTable &orig_symbol_table); + //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; diff --git a/ModFile.cc b/ModFile.cc index c1c345ff..b4767def 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,6 +314,7 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); + dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); vector orig_statements = statements; statements.clear(); for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) From a39448b63fd0331ace54c6320982756396389a5e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 16:45:17 +0200 Subject: [PATCH 44/54] fix typo --- ComputingTasks.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7c290d29..d7d11787 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -317,7 +317,7 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_table->getID(*it1); new_options_symbol_list.addSymbol(*it1); } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } } From 781039752aa8852d59ee043e2aa68fd7564dcf03 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 17:13:19 +0200 Subject: [PATCH 45/54] preprocessor: take care of instruments option in discretionary_policy squash --- ComputingTasks.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d7d11787..5070ae5a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -490,7 +490,8 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolList new_symbol_list; + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; try { SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); @@ -500,6 +501,18 @@ DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_table->getID(*it); new_symbol_list.addSymbol(*it); } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } } catch (...) { From 6905456cb36dda3ceb837f0932c21e581c6fa375 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 15:41:07 +0200 Subject: [PATCH 46/54] preprocessor: provide more info in error message --- ComputingTasks.cc | 1187 +++++++++++++++++++++++------------- NumericalInitialization.cc | 93 ++- 2 files changed, 840 insertions(+), 440 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 5070ae5a..db890793 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -168,34 +168,55 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the stoch_simul statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the stoch_simul statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new StochSimulStatement(new_symbol_list, new_options_list); @@ -226,23 +247,31 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, Statement * ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the forecast statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new ForecastStatement(new_symbol_list, options_list); } @@ -296,35 +325,55 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } - catch (...) + + if (!errors.empty()) { - cerr << "ERROR: A variable in the ramsey_model statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the ramsey_model statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new RamseyModelStatement(new_symbol_list, options_list); @@ -394,37 +443,58 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the ramsey_policy statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } - return new RamseyPolicyStatement(new_symbol_list, new_options_list); + return new RamseyPolicyStatement(new_symbol_list, options_list); } void @@ -490,34 +560,55 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the discretionary_policy statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the discretionary_policy statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DiscretionaryPolicyStatement(new_symbol_list, options_list); @@ -632,34 +723,55 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the estimation statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the estimation statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimationStatement(new_symbol_list, new_options_list); @@ -703,33 +815,53 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning Statement * DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + try { new_symbol_table->getID(*it2); new_options_symbol_list.addSymbol(*it2); } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the dynare_sensitivity statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the dynare_sensitivity statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynareSensitivityStatement(new_options_list); @@ -765,21 +897,28 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : Statement * RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the rplot statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the rplot statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new RplotStatement(new_symbol_list); @@ -904,12 +1043,14 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo Statement * EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -917,11 +1058,19 @@ EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Sym } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the estimated_params statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsStatement(estim_params_list, *new_symbol_table); @@ -1005,12 +1154,13 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -1018,11 +1168,19 @@ EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params_init statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the estimated_params_init statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsInitStatement(estim_params_list, *new_symbol_table, use_calibration); @@ -1097,12 +1255,13 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -1110,11 +1269,19 @@ EstimatedParamsBoundsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatre } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params_bounds statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the estimated_params_bounds statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsBoundsStatement(estim_params_list, *new_symbol_table); @@ -1211,20 +1378,31 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t Statement * ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; map new_trend_elements; - try + for (map::const_iterator it = trend_elements.begin(); + it != trend_elements.end(); it++) + try + { + symbol_table.getID(it->first); + new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - for (map::const_iterator it = trend_elements.begin(); - it != trend_elements.end(); it++) - { - symbol_table.getID(it->first); - new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - } - catch (...) - { - cerr << "ERROR: A variable in the observation_trends statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the observation_trends statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ObservationTrendsStatement(new_trend_elements, symbol_table); @@ -1266,21 +1444,28 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid Statement * OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the osr_params statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the osr_params statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OsrParamsStatement(new_symbol_list); @@ -1324,21 +1509,28 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation Statement * OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the osr statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the osr statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OsrStatement(new_symbol_list, options_list); @@ -1377,30 +1569,51 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; var_weights_t new_var_weights; covar_weights_t new_covar_weights; - try - { - for (var_weights_t::const_iterator it = var_weights.begin(); - it != var_weights.end(); it++) - { - symbol_table.getID(it->first); - new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - for (covar_weights_t::const_iterator it = covar_weights.begin(); - it != covar_weights.end(); it++) - { - symbol_table.getID(it->first.first); - symbol_table.getID(it->first.second); - new_covar_weights[make_pair(it->first.first, it->first.second)] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - } - catch (...) + for (var_weights_t::const_iterator it = var_weights.begin(); + it != var_weights.end(); it++) + try + { + symbol_table.getID(it->first); + new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + for (covar_weights_t::const_iterator it = covar_weights.begin(); + it != covar_weights.end(); it++) + try + { + symbol_table.getID(it->first.first); + symbol_table.getID(it->first.second); + new_covar_weights[make_pair(it->first.first, it->first.second)] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the optim_weights statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the optim_weights statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OptimWeightsStatement(new_var_weights, new_covar_weights, symbol_table); @@ -1452,21 +1665,28 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, Statement * DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the dynasave statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the dynasave statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynaSaveStatement(new_symbol_list, filename); @@ -1490,21 +1710,28 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, Statement * DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the dynatype statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the dynatype statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynaTypeStatement(new_symbol_list, filename); @@ -1562,14 +1789,26 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC Statement * PlannerObjectiveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + string error; try { model_tree->reindex(orig_symbol_table); } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) { - cerr << "ERROR: A variable in the planner_objective statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + error = orig_symbol_table.getName(e.id); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + error = e.name; + } + + if (!error.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the planner_objective statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << error << endl; exit(EXIT_FAILURE); } return new PlannerObjectiveStatement(model_tree); @@ -1793,21 +2032,28 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the ms_sbvar_irf statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the ms_sbvar_irf statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new MSSBVARIrfStatement(new_symbol_list, options_list); @@ -1974,21 +2220,28 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo Statement * ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the shock_decomposition statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the shock_decomposition statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ShockDecompositionStatement(new_symbol_list, options_list); @@ -2010,28 +2263,39 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op Statement * ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; OptionsList new_options_list = options_list; - try + OptionsList::symbol_list_options_t::const_iterator it = + options_list.symbol_list_options.find("controlled_varexo"); + if (it != options_list.symbol_list_options.end()) { - OptionsList::symbol_list_options_t::const_iterator it = - options_list.symbol_list_options.find("controlled_varexo"); - if (it != options_list.symbol_list_options.end()) - { - SymbolList new_options_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; - } + SymbolList new_options_symbol_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; } - catch (...) + + if (!errors.empty()) { - cerr << "ERROR: A variable in the conditional_forecast statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the conditional_forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ConditionalForecastStatement(new_options_list); @@ -2053,21 +2317,28 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a Statement * PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the plot_conditional_forecast statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the plot_conditional_forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new PlotConditionalForecastStatement(periods, new_symbol_list); @@ -2995,10 +3266,12 @@ PriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable & SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the prior statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new PriorStatement(name, subsample_name, prior_shape, variance, options_list); @@ -3049,10 +3322,12 @@ StdPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl { new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the std_prior statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new StdPriorStatement(name, subsample_name, prior_shape, variance, options_list, *new_symbol_table); @@ -3124,16 +3399,32 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid Statement * CorrPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { new_symbol_table->getID(name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + try + { new_symbol_table->getID(name1); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the corr_prior statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + errors.push_back(e.name); + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new CorrPriorStatement(name, name1, subsample_name, prior_shape, variance, options_list, *new_symbol_table); @@ -3221,21 +3512,32 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * PriorEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(to_name1); - if (!to_name2.empty()) - new_symbol_table->getID(to_name2); + vector errors; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; + vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + if (!it->empty()) + new_symbol_table->getID(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } - new_symbol_table->getID(from_name1); - if (!from_name2.empty()) - new_symbol_table->getID(from_name2); - } - catch (...) + if (!errors.empty()) { - cerr << "ERROR: A variable in the prior equal statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the prior equal statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new PriorEqualStatement(to_declaration_type, @@ -3412,10 +3714,12 @@ OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the options statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new OptionsStatement(name, subsample_name, options_list); @@ -3457,10 +3761,12 @@ StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa { new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the std_options statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the std_options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); @@ -3524,18 +3830,36 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { new_symbol_table->getID(name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + try + { new_symbol_table->getID(name1); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the corr_options statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + errors.push_back(e.name); + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the corr_options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); } @@ -3616,23 +3940,35 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(to_name1); - if (!to_name2.empty()) - new_symbol_table->getID(to_name2); + vector errors; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; + vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + if (!it->empty()) + new_symbol_table->getID(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } - new_symbol_table->getID(from_name1); - if (!from_name2.empty()) - new_symbol_table->getID(from_name2); - } - catch (...) + if (!errors.empty()) { - cerr << "ERROR: A variable in the options equal statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the options equal statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new OptionsEqualStatement(to_declaration_type, to_name1, to_name2, @@ -3730,21 +4066,28 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons Statement * CalibSmootherStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the calib_smoother statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the calib_smoother statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new CalibSmootherStatement(new_symbol_list, options_list); @@ -3810,33 +4153,53 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ Statement * Smoother2histvalStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"invars", "outvars"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"invars", "outvars"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + try { new_symbol_table->getID(*it2); new_options_symbol_list.addSymbol(*it2); } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the smoother2histval statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the smoother2histval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new Smoother2histvalStatement(new_options_list); diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 501f202b..44fa2efd 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -76,18 +76,27 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const Statement * InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + string error; try { return new InitParamStatement(symbol_table.getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), symbol_table); } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) { - cerr << "ERROR: A variable in the init_param statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; - exit(EXIT_FAILURE); + error = orig_symbol_table.getName(e.id); } + catch (SymbolTable::UnknownSymbolNameException &e) + { + error = e.name; + } + + cerr << endl + << "ERROR: The following vars were used in the init param statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << error << endl; + exit(EXIT_FAILURE); } InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_arg, @@ -228,18 +237,27 @@ InitValStatement::writeOutputPostInit(ostream &output) const Statement * InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; init_values_t new_init_values; - try - { - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + try + { new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the initval statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the initval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new InitValStatement(new_init_values, symbol_table, all_values_required); @@ -294,18 +312,28 @@ EndValStatement::writeOutput(ostream &output, const string &basename) const Statement * EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; init_values_t new_init_values; - try - { - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) + + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + try + { new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the endval statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the endval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EndValStatement(new_init_values, symbol_table, all_values_required); @@ -380,19 +408,28 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const Statement * HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; hist_values_t new_hist_values; - try - { - for (hist_values_t::const_iterator it=hist_values.begin(); - it != hist_values.end(); it++) + for (hist_values_t::const_iterator it=hist_values.begin(); + it != hist_values.end(); it++) + try + { new_hist_values[make_pair(symbol_table.getID(orig_symbol_table.getName(it->first.first)), it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the hist_val statement was not found in the symbol table" << endl - << " This likely means that you have declared a varexo that is not used in the model" << endl; + cerr << endl + << "ERROR: The following vars were used in the histval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new HistValStatement(new_hist_values, symbol_table); From 48014c37871fca11c9065debe117507511f74c7c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Apr 2015 15:06:56 +0200 Subject: [PATCH 47/54] preprocessor: take care of expressions_tree and steady_state_model --- DataTree.cc | 26 ++++++++++++++++++++++++++ DataTree.hh | 2 ++ ModFile.cc | 7 +++++++ ModelTree.cc | 17 +---------------- SymbolTable.cc | 19 +++++++++++++++++++ SymbolTable.hh | 2 ++ 6 files changed, 57 insertions(+), 16 deletions(-) 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 From 217123bb191b8a2a6e0d83c03f671f7bfe0afd4d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:31:08 +0200 Subject: [PATCH 48/54] preprocessor: reindex predetermined variables --- SymbolTable.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index 223f4a91..a9e6d1f5 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -486,6 +486,7 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) idxs.sort(); idxs.reverse(); + vector orig_name_table = name_table; for (list::const_iterator it = idxs.begin(); it != idxs.end(); it++) { type_table.erase(type_table.begin() + *it); @@ -499,8 +500,16 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) for (vector::const_iterator it=name_table.begin(); it != name_table.end(); it++) symbol_table[*it] = size++; - assert(size == symbol_table.size()); + + set orig_predetermined_variables = predetermined_variables; + predetermined_variables.clear(); + for (set::const_iterator it=orig_predetermined_variables.begin(); + it != orig_predetermined_variables.end(); it++) + if (orig_name_table[*it] != getName(*it)) + markPredetermined(getID(orig_name_table[*it])); + else + markPredetermined(*it); } void From 1817992f452a9e41eb031be98880111ec7f91d05 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:31:50 +0200 Subject: [PATCH 49/54] preprocessor: remove unnecessary reindexing --- ModFile.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 0592c620..a206a930 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -316,11 +316,6 @@ ModFile::transformPass(bool nostrict) 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(); From 549c6637cbb893ec5425afb773a3a30a4ea7b56e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:32:26 +0200 Subject: [PATCH 50/54] preprocessor: move external_functions_table reindexing to modfile::transformpass --- DataTree.cc | 7 ------- DataTree.hh | 2 -- ModFile.cc | 1 + 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index b45d4479..acbae348 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -61,7 +61,6 @@ DataTree::reindex(SymbolTable &orig_symbol_table) first_deriv_external_function_node_map.clear(); second_deriv_external_function_node_map.clear(); - reindexExternalFunctions(orig_symbol_table); reindexLocalVars(orig_symbol_table); } @@ -76,12 +75,6 @@ DataTree::reindexLocalVars(SymbolTable &orig_symbol_table) it->second->cloneDynamicReindex(*this, orig_symbol_table)); } -void -DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) -{ - external_functions_table.reindex(symbol_table, orig_symbol_table); -} - expr_t DataTree::AddNonNegativeConstant(const string &value) { diff --git a/DataTree.hh b/DataTree.hh index 9d0f746c..b7cd2565 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -238,8 +238,6 @@ public: void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv 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 diff --git a/ModFile.cc b/ModFile.cc index a206a930..bc9cea5f 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -316,6 +316,7 @@ ModFile::transformPass(bool nostrict) dynamic_model.reindex(orig_symbol_table); dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); + external_functions_table.reindex(symbol_table, orig_symbol_table); vector orig_statements = statements; statements.clear(); From 5d9aaeef75d80abdeb1a7e5445934e48f94259e7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:44:46 +0200 Subject: [PATCH 51/54] preprocessor: reindex varobs in symboltable --- SymbolTable.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SymbolTable.cc b/SymbolTable.cc index a9e6d1f5..edce61db 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -510,6 +510,14 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) markPredetermined(getID(orig_name_table[*it])); else markPredetermined(*it); + + vector orig_varobs = varobs; + varobs.clear(); + for (vector::const_iterator it=orig_varobs.begin(); it != orig_varobs.end(); it++) + if (orig_name_table[*it] != getName(*it)) + addObservedVariable(getID(orig_name_table[*it])); + else + addObservedVariable(*it); } void From 3c7f96e29d1ea0c52f3a884dad024837d31e2417 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:47:44 +0200 Subject: [PATCH 52/54] preprocessor: remove unused, overload of rmExo --- SymbolTable.cc | 19 ------------------- SymbolTable.hh | 2 -- 2 files changed, 21 deletions(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index edce61db..177ac94e 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -520,25 +520,6 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) addObservedVariable(*it); } -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 98f88ee1..85267fe6 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -305,8 +305,6 @@ 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 From a3619804370cfc7f1c6fa2ccd0f88314c844b08e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 May 2015 12:24:55 +0200 Subject: [PATCH 53/54] preprocessor: move all dynamic model reindexing to DynamicModel --- DynamicModel.cc | 7 +++++++ DynamicModel.hh | 3 +++ ModFile.cc | 2 -- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 9e767fad..c5480aaa 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4202,6 +4202,13 @@ DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) static_only_equations_lineno.push_back(lineno); } +void +DynamicModel::reindex(SymbolTable &orig_symbol_table) +{ + ModelTree::reindex(orig_symbol_table); + reindexStaticOnlyEquations(orig_symbol_table); +} + void DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) { diff --git a/DynamicModel.hh b/DynamicModel.hh index 835f09b7..7adda7fd 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -244,6 +244,9 @@ public: //! Adds an equation marked as [static] void addStaticOnlyEquation(expr_t eq, int lineno); + //! reindex Dynamic Model after removal of extra exogenous + void reindex(SymbolTable &orig_symbol_table); + //! reindex equations marked as [static] void reindexStaticOnlyEquations(SymbolTable &orig_symbol_table); diff --git a/ModFile.cc b/ModFile.cc index bc9cea5f..ceb68724 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,8 +314,6 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); - dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); - external_functions_table.reindex(symbol_table, orig_symbol_table); vector orig_statements = statements; From f6fb8bbf47162547dcd844472aa607395dfb38f8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 May 2015 12:28:42 +0200 Subject: [PATCH 54/54] preprocessor: fix function call in reindexStaticOnlyEquations --- DynamicModel.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index c5480aaa..a43a599b 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4215,7 +4215,8 @@ DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) vectoreqbak = static_only_equations; static_only_equations.clear(); for (size_t i = 0; i < eqbak.size(); i++) - addStaticOnlyEquation(eqbak[i]->cloneDynamic(*this), static_only_equations_lineno[i]); + addStaticOnlyEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), + static_only_equations_lineno[i]); } size_t