preprocessor: don’t allow write_latex_steady_state_model without steady_state_model block. #1496

issue#70
Houtan Bastani 2017-08-30 15:46:17 +02:00
parent d23a684bf6
commit c1debb1afe
7 changed files with 27 additions and 6 deletions

View File

@ -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
{

View File

@ -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;
};

View File

@ -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)

View File

@ -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)
{
}

View File

@ -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

View File

@ -56,11 +56,12 @@ SteadyStateModel::addMultipleDefinitions(const vector<int> &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<int> 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<int> used_symbols;
const expr_t &expr = def_table[i].second;

View File

@ -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