From c1debb1afe4fda2346e77ca62e7df2c6255a02c0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 30 Aug 2017 15:46:17 +0200 Subject: [PATCH] =?UTF-8?q?preprocessor:=20don=E2=80=99t=20allow=20write?= =?UTF-8?q?=5Flatex=5Fsteady=5Fstate=5Fmodel=20without=20steady=5Fstate=5F?= =?UTF-8?q?model=20block.=20#1496?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComputingTasks.cc | 6 ++++++ ComputingTasks.hh | 1 + ModFile.cc | 9 ++++++++- Statement.cc | 4 +++- Statement.hh | 5 ++++- SteadyStateModel.cc | 5 +++-- SteadyStateModel.hh | 3 ++- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index c3390c27..1926b67a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2382,6 +2382,12 @@ WriteLatexSteadyStateModelStatement::WriteLatexSteadyStateModelStatement(const S { } +void +WriteLatexSteadyStateModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +{ + mod_file_struct.write_latex_steady_state_model_present = true; +} + void WriteLatexSteadyStateModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index e371284f..18ec20d1 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -632,6 +632,7 @@ private: const SteadyStateModel &steady_state_model; public: WriteLatexSteadyStateModelStatement(const SteadyStateModel &steady_state_model_arg); + virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeJsonOutput(ostream &output) const; }; diff --git a/ModFile.cc b/ModFile.cc index 39f9b5b1..6fea425e 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -114,7 +114,14 @@ ModFile::checkPass(bool nostrict) (*it)->checkPass(mod_file_struct, warnings); // Check the steady state block - steady_state_model.checkPass(mod_file_struct.ramsey_model_present, warnings); + steady_state_model.checkPass(mod_file_struct, warnings); + + if (mod_file_struct.write_latex_steady_state_model_present && + !mod_file_struct.steady_state_model_present) + { + cerr << "ERROR: You cannot have a write_latex_steady_state_model statement without a steady_state_model block." << endl; + exit(EXIT_FAILURE); + } // If order option has not been set, default to 2 if (!mod_file_struct.order_option) diff --git a/Statement.cc b/Statement.cc index 14bffcc3..8a86f75a 100644 --- a/Statement.cc +++ b/Statement.cc @@ -59,7 +59,9 @@ ModFileStructure::ModFileStructure() : ms_dsge_present(false), occbin_option(false), orig_eq_nbr(0), - ramsey_eq_nbr(0) + ramsey_eq_nbr(0), + steady_state_model_present(false), + write_latex_steady_state_model_present(false) { } diff --git a/Statement.hh b/Statement.hh index 7c80f5d5..db7d5606 100644 --- a/Statement.hh +++ b/Statement.hh @@ -119,7 +119,10 @@ public: int orig_eq_nbr; //! Stores the number of equations added to the Ramsey model int ramsey_eq_nbr; - + //! Whether there was a steady_state_model block + bool steady_state_model_present; + //! Whether there is a write_latex_steady_state_model statement present + bool write_latex_steady_state_model_present; }; class Statement diff --git a/SteadyStateModel.cc b/SteadyStateModel.cc index 22792983..a68b2b1c 100644 --- a/SteadyStateModel.cc +++ b/SteadyStateModel.cc @@ -56,11 +56,12 @@ SteadyStateModel::addMultipleDefinitions(const vector &symb_ids, expr_t exp } void -SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) const +SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) const { if (def_table.size() == 0) return; + mod_file_struct.steady_state_model_present = true; vector so_far_defined; for (size_t i = 0; i < def_table.size(); i++) @@ -74,7 +75,7 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(symb_ids[j]) << "' is declared twice" << endl; // Check that expression has no undefined symbol - if (!ramsey_model) + if (!mod_file_struct.ramsey_model_present) { set used_symbols; const expr_t &expr = def_table[i].second; diff --git a/SteadyStateModel.hh b/SteadyStateModel.hh index f0782bc1..a4b879dc 100644 --- a/SteadyStateModel.hh +++ b/SteadyStateModel.hh @@ -21,6 +21,7 @@ #define _STEADY_STATE_MODEL_HH #include "DataTree.hh" +#include "Statement.hh" #include "StaticModel.hh" #include "WarningConsolidation.hh" @@ -43,7 +44,7 @@ public: /*! \param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then disable the check on the recursivity of the declarations */ - void checkPass(bool ramsey_model, WarningConsolidation &warnings) const; + void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) const; //! Write the steady state file /*! \param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values