diff --git a/DynareBison.yy b/DynareBison.yy index f3149766701aad08d020563030b03e1aaf8e82c6..a8d04a8a8eb783c25a1208dba6f609385ffc9441 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -636,7 +636,11 @@ initval_list : initval_list initval_elem initval_elem : symbol EQUAL expression ';' { driver.init_val($1, $3); }; -histval : HISTVAL ';' histval_list END ';' { driver.end_histval(); }; +histval : HISTVAL ';' histval_list END ';' + { driver.end_histval(false); }; + | HISTVAL '(' ALL_VALUES_REQUIRED ')' ';' histval_list END ';' + { driver.end_histval(true); } + ; histval_list : histval_list histval_elem | histval_elem diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 07e0d5814eb1894399d4805f65c3ef02f9af61cf..3bbd803eba40724ca34dfa064b30a5aa9ba0a89e 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2016 Dynare Team * * This file is part of Dynare. * @@ -268,9 +268,11 @@ EndValStatement::writeOutput(ostream &output, const string &basename, bool minim } HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, - const SymbolTable &symbol_table_arg) : + const SymbolTable &symbol_table_arg, + const bool &all_values_required_arg) : hist_values(hist_values_arg), - symbol_table(symbol_table_arg) + symbol_table(symbol_table_arg), + all_values_required(all_values_required_arg) { } @@ -278,6 +280,44 @@ void HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { mod_file_struct.histval_present = true; + + if (all_values_required) + { + set<int> unused_endo = symbol_table.getEndogenous(); + set<int> unused_exo = symbol_table.getExogenous(); + + set<int>::iterator sit; + for (hist_values_t::const_iterator it = hist_values.begin(); + it != hist_values.end(); it++) + { + sit = unused_endo.find(it->first.first); + if (sit != unused_endo.end()) + unused_endo.erase(sit); + + sit = unused_exo.find(it->first.first); + if (sit != unused_exo.end()) + unused_exo.erase(sit); + } + + if (unused_endo.size() > 0) + { + cerr << "ERROR: You have not set the following endogenous variables in histval:"; + for (set<int>::const_iterator it = unused_endo.begin(); it != unused_endo.end(); it++) + cerr << " " << symbol_table.getName(*it); + cerr << endl; + } + + if (unused_exo.size() > 0) + { + cerr << "ERROR: You have not set the following exogenous variables in endval:"; + for (set<int>::const_iterator it = unused_exo.begin(); it != unused_exo.end(); it++) + cerr << " " << symbol_table.getName(*it); + cerr << endl; + } + + if (unused_endo.size() > 0 || unused_exo.size() > 0) + exit(EXIT_FAILURE); + } } void diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index ccc67794471f86429fd144157554471e63211808..2e34677b816155039e4dce226f387938a9b84d0b 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2016 Dynare Team * * This file is part of Dynare. * @@ -106,9 +106,11 @@ public: private: const hist_values_t hist_values; const SymbolTable &symbol_table; + const bool all_values_required; public: HistValStatement(const hist_values_t &hist_values_arg, - const SymbolTable &symbol_table_arg); + const SymbolTable &symbol_table_arg, + const bool &all_values_required_arg); //! Workaround for trac ticket #157 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; diff --git a/ParsingDriver.cc b/ParsingDriver.cc index b1425c87b8b9f414aa2406922f496e0e4b2bd330..6456f5222de382aca618c83fb5626ef1c704710f 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -614,9 +614,9 @@ ParsingDriver::end_endval(bool all_values_required) } void -ParsingDriver::end_histval() +ParsingDriver::end_histval(bool all_values_required) { - mod_file->addStatement(new HistValStatement(hist_values, mod_file->symbol_table)); + mod_file->addStatement(new HistValStatement(hist_values, mod_file->symbol_table, all_values_required)); hist_values.clear(); } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index a05fdfef1ebf4c046c5f7c1a3e88a55d5131614e..398c2a2253dbbb58fb37ff8d5c2b0cf5cef5d3d8 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -335,7 +335,7 @@ public: //! Writes end of an endval block void end_endval(bool all_values_required); //! Writes end of an histval block - void end_histval(); + void end_histval(bool all_values_required); //! Writes end of an homotopy_setup block void end_homotopy(); //! Begin a model block