From ce7a172c21811376fdf53dcd671c7ca8ba6246d8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 30 Jul 2015 14:40:03 +0200 Subject: [PATCH] preprocessor: issue warning when param used with lead/lag. closes #976 --- DataTree.cc | 12 +++++++++++- DataTree.hh | 4 +++- DynamicModel.cc | 6 ++++++ DynamicModel.hh | 3 +++ ModFile.cc | 11 +++++++++-- ModFile.hh | 3 +++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index 3f90a44f..7c718c5e 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. * @@ -72,6 +72,16 @@ DataTree::AddVariableInternal(int symb_id, int lag) return new VariableNode(*this, symb_id, lag); } +bool +DataTree::ParamUsedWithLeadLagInternal() const +{ + for (variable_node_map_t::const_iterator it = variable_node_map.begin(); + it != variable_node_map.end(); it++) + if (symbol_table.getType(it->first.first) == eParameter && it->first.second != 0) + return true; + return false; +} + VariableNode * DataTree::AddVariable(int symb_id, int lag) { diff --git a/DataTree.hh b/DataTree.hh index d7c53645..4c740113 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. * @@ -88,6 +88,8 @@ protected: //! Internal implementation of AddVariable(), without the check on the lag VariableNode *AddVariableInternal(int symb_id, int lag); + //! Internal implementation of ParamUsedWithLeadLag() + bool ParamUsedWithLeadLagInternal() const; private: typedef list<expr_t> node_list_t; //! The list of nodes diff --git a/DynamicModel.cc b/DynamicModel.cc index 70b16176..6c506c40 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3499,6 +3499,12 @@ DynamicModel::toStatic(StaticModel &static_model) const static_model.addAuxEquation((*it)->toStatic(static_model)); } +bool +DynamicModel::ParamUsedWithLeadLag() const +{ + return ParamUsedWithLeadLagInternal(); +} + set<int> DynamicModel::findUnusedEndogenous() { diff --git a/DynamicModel.hh b/DynamicModel.hh index 0bf34f47..6f1eefd7 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -469,6 +469,9 @@ public: }; bool isModelLocalVariableUsed() const; + //! Returns true if a parameter was used in the model block with a lead or lag + bool ParamUsedWithLeadLag() const; + //! Writes model initialization and lead/lag incidence matrix to C output void writeCOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present) const; //! Writes model initialization and lead/lag incidence matrix to Cpp output diff --git a/ModFile.cc b/ModFile.cc index a4693cfc..1b7f286b 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -41,7 +41,7 @@ ModFile::ModFile(WarningConsolidation &warnings_arg) linear(false), block(false), byte_code(false), use_dll(false), no_static(false), differentiate_forward_vars(false), nonstationary_variables(false), orig_eqn_nbr(0), ramsey_eqn_nbr(0), - warnings(warnings_arg) + param_used_with_lead_lag(false), warnings(warnings_arg) { } @@ -120,6 +120,10 @@ ModFile::checkPass() if (!mod_file_struct.order_option) mod_file_struct.order_option = 2; + param_used_with_lead_lag = dynamic_model.ParamUsedWithLeadLag(); + if (param_used_with_lead_lag) + warnings << "WARNING: A parameter was used with a lead or a lag in the model block" << endl; + bool stochastic_statement_present = mod_file_struct.stoch_simul_present || mod_file_struct.estimation_present || mod_file_struct.osr_present @@ -599,7 +603,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo if (nointeractive) mOutputFile << "options_.nointeractive = 1;" << endl; - + + if (param_used_with_lead_lag) + mOutputFile << "M_.parameter_used_with_lead_lag = true;" << endl; + cout << "Processing outputs ..." << endl; symbol_table.writeOutput(mOutputFile); diff --git a/ModFile.hh b/ModFile.hh index 11e3e424..23ea3371 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -107,6 +107,9 @@ public: //! Stores the number of equations added to the Ramsey model int ramsey_eqn_nbr; + //! Parameter used with lead/lag + bool param_used_with_lead_lag; + //! Stores the list of extra files to be transefered during a parallel run /*! (i.e. option parallel_local_files of model block) */ vector<string> parallel_local_files; -- GitLab