diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 3ec9743bcd764984f363bdd173105e31b861ea0a..e994c42a64b1a6e3975588de077980969862ff06 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -3869,12 +3869,21 @@ SubsamplesStatement::writeOutput(ostream &output, const string &basename, bool m // Initialize associated subsample substructures in estimation_info const SymbolType symb_type = symbol_table.getType(name1); string lhs_field; - if (symb_type == SymbolType::parameter) - lhs_field = "parameter"; - else if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) - lhs_field = "structural_innovation"; - else - lhs_field = "measurement_error"; + switch (symb_type) + { + case SymbolType::parameter: + lhs_field = "parameter"; + break; + case SymbolType::exogenous: + lhs_field = "structural_innovation"; + break; + case SymbolType::endogenous: + lhs_field = "measurement_error"; + break; + default: + cerr << "subsamples: invalid symbol type for " << name1 << endl; + exit(EXIT_FAILURE); + } output << "eifind = get_new_or_existing_ei_index('" << lhs_field; @@ -3955,12 +3964,21 @@ SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename, b // Initialize associated subsample substructures in estimation_info const SymbolType symb_type = symbol_table.getType(to_name1); string lhs_field; - if (symb_type == SymbolType::parameter) - lhs_field = "parameter"; - else if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) - lhs_field = "structural_innovation"; - else - lhs_field = "measurement_error"; + switch (symb_type) + { + case SymbolType::parameter: + lhs_field = "parameter"; + break; + case SymbolType::exogenous: + lhs_field = "structural_innovation"; + break; + case SymbolType::endogenous: + lhs_field = "measurement_error"; + break; + default: + cerr << "subsamples: invalid symbol type for " << to_name1 << endl; + exit(EXIT_FAILURE); + } output << "eifind = get_new_or_existing_ei_index('" << lhs_field; @@ -4213,7 +4231,7 @@ BasicPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli bool BasicPriorStatement::is_structural_innovation(const SymbolType symb_type) const { - if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) + if (symb_type == SymbolType::exogenous) return true; return false; } @@ -4221,7 +4239,7 @@ BasicPriorStatement::is_structural_innovation(const SymbolType symb_type) const void BasicPriorStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { - if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) + if (symb_type == SymbolType::exogenous) lhs_field = "structural_innovation"; else lhs_field = "measurement_error"; @@ -4473,7 +4491,7 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli void PriorEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { - if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) + if (symb_type == SymbolType::exogenous) lhs_field = "structural_innovation"; else lhs_field = "measurement_error"; @@ -4572,13 +4590,13 @@ BasicOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso bool BasicOptionsStatement::is_structural_innovation(const SymbolType symb_type) const { - return symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet; + return symb_type == SymbolType::exogenous; } void BasicOptionsStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { - if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) + if (symb_type == SymbolType::exogenous) lhs_field = "structural_innovation"; else lhs_field = "measurement_error"; @@ -4780,7 +4798,7 @@ OptionsEqualStatement::writeJsonOutput(ostream &output) const void OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { - if (symb_type == SymbolType::exogenous || symb_type == SymbolType::exogenousDet) + if (symb_type == SymbolType::exogenous) lhs_field = "structural_innovation"; else lhs_field = "measurement_error"; diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 60f70d7fcbc0c7596162fae36fb13f49c8ea395c..221ab487a0e0bbf1cc1180c6ba8fca60a1d5c441 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -548,7 +548,7 @@ ParsingDriver::init_val(const string &name, expr_t rhs) return; } - check_symbol_is_endogenous_or_exogenous(name); + check_symbol_is_endogenous_or_exogenous(name, true); int symb_id = mod_file->symbol_table.getID(name); init_values.emplace_back(symb_id, rhs); } @@ -570,7 +570,7 @@ ParsingDriver::hist_val(const string &name, const string &lag, expr_t rhs) return; } - check_symbol_is_endogenous_or_exogenous(name); + check_symbol_is_endogenous_or_exogenous(name, true); int symb_id = mod_file->symbol_table.getID(name); int ilag = stoi(lag); @@ -627,7 +627,7 @@ ParsingDriver::add_generate_irfs_element(string name) void ParsingDriver::add_generate_irfs_exog_element(string exo, const string &value) { - check_symbol_is_exogenous(exo); + check_symbol_is_exogenous(exo, false); if (generate_irf_exos.find(exo) != generate_irf_exos.end()) error("You have set the exogenous variable " + exo + " twice."); @@ -885,7 +885,7 @@ ParsingDriver::add_det_shock(const string &var, const vector<pair<int, int>> &pe if (conditional_forecast) check_symbol_is_endogenous(var); else - check_symbol_is_exogenous(var); + check_symbol_is_exogenous(var, true); int symb_id = mod_file->symbol_table.getID(var); @@ -906,7 +906,7 @@ ParsingDriver::add_det_shock(const string &var, const vector<pair<int, int>> &pe void ParsingDriver::add_heteroskedastic_shock(const string &var, const vector<pair<int, int>> &periods, const vector<expr_t> &values, bool scales) { - check_symbol_is_exogenous(var); + check_symbol_is_exogenous(var, false); int symb_id = mod_file->symbol_table.getID(var); @@ -1709,18 +1709,18 @@ ParsingDriver::copy_prior(const string &to_declaration_type, const string &to_na check_symbol_is_parameter(to_name1); else { - check_symbol_is_endogenous_or_exogenous(to_name1); + check_symbol_is_endogenous_or_exogenous(to_name1, false); if (!to_name2.empty()) - check_symbol_is_endogenous_or_exogenous(to_name2); + check_symbol_is_endogenous_or_exogenous(to_name2, false); } if (from_declaration_type == "par") check_symbol_is_parameter(from_name1); else { - check_symbol_is_endogenous_or_exogenous(from_name1); + check_symbol_is_endogenous_or_exogenous(from_name1, false); if (!from_name2.empty()) - check_symbol_is_endogenous_or_exogenous(from_name2); + check_symbol_is_endogenous_or_exogenous(from_name2, false); } mod_file->addStatement(make_unique<PriorEqualStatement>(to_declaration_type, to_name1, @@ -1749,18 +1749,18 @@ ParsingDriver::copy_options(const string &to_declaration_type, const string &to_ check_symbol_is_parameter(to_name1); else { - check_symbol_is_endogenous_or_exogenous(to_name1); + check_symbol_is_endogenous_or_exogenous(to_name1, false); if (!to_name2.empty()) - check_symbol_is_endogenous_or_exogenous(to_name2); + check_symbol_is_endogenous_or_exogenous(to_name2, false); } if (from_declaration_type == "par") check_symbol_is_parameter(from_name1); else { - check_symbol_is_endogenous_or_exogenous(from_name1); + check_symbol_is_endogenous_or_exogenous(from_name1, false); if (!from_name2.empty()) - check_symbol_is_endogenous_or_exogenous(from_name2); + check_symbol_is_endogenous_or_exogenous(from_name2, false); } mod_file->addStatement(make_unique<OptionsEqualStatement>(to_declaration_type, to_name1, @@ -1771,14 +1771,17 @@ ParsingDriver::copy_options(const string &to_declaration_type, const string &to_ } void -ParsingDriver::check_symbol_is_endogenous_or_exogenous(const string &name) +ParsingDriver::check_symbol_is_endogenous_or_exogenous(const string &name, bool allow_det) { check_symbol_existence(name); switch (mod_file->symbol_table.getType(name)) { case SymbolType::endogenous: case SymbolType::exogenous: + break; case SymbolType::exogenousDet: + if (!allow_det) + error(name + " is an exogenous deterministic."); break; default: error(name + " is neither endogenous or exogenous."); @@ -1794,13 +1797,16 @@ ParsingDriver::check_symbol_is_endogenous(const string &name) } void -ParsingDriver::check_symbol_is_exogenous(const string &name) +ParsingDriver::check_symbol_is_exogenous(const string &name, bool allow_exo_det) { check_symbol_existence(name); switch (mod_file->symbol_table.getType(name)) { case SymbolType::exogenous: + break; case SymbolType::exogenousDet: + if (!allow_exo_det) + error(name + " is an exogenous deterministic."); break; default: error(name + " is not exogenous."); @@ -1810,7 +1816,7 @@ ParsingDriver::check_symbol_is_exogenous(const string &name) void ParsingDriver::set_std_prior(const string &name, const string &subsample_name) { - check_symbol_is_endogenous_or_exogenous(name); + check_symbol_is_endogenous_or_exogenous(name, false); check_subsample_declaration_exists(name, subsample_name); mod_file->addStatement(make_unique<StdPriorStatement>(name, subsample_name, prior_shape, prior_variance, options_list, mod_file->symbol_table)); @@ -1822,7 +1828,7 @@ ParsingDriver::set_std_prior(const string &name, const string &subsample_name) void ParsingDriver::set_std_options(const string &name, const string &subsample_name) { - check_symbol_is_endogenous_or_exogenous(name); + check_symbol_is_endogenous_or_exogenous(name, false); check_subsample_declaration_exists(name, subsample_name); mod_file->addStatement(make_unique<StdOptionsStatement>(name, subsample_name, options_list, mod_file->symbol_table)); options_list.clear(); @@ -1831,8 +1837,8 @@ ParsingDriver::set_std_options(const string &name, const string &subsample_name) void ParsingDriver::set_corr_prior(const string &name1, const string &name2, const string &subsample_name) { - check_symbol_is_endogenous_or_exogenous(name1); - check_symbol_is_endogenous_or_exogenous(name2); + check_symbol_is_endogenous_or_exogenous(name1, false); + check_symbol_is_endogenous_or_exogenous(name2, false); check_subsample_declaration_exists(name1, name2, subsample_name); mod_file->addStatement(make_unique<CorrPriorStatement>(name1, name2, subsample_name, prior_shape, prior_variance, options_list, mod_file->symbol_table)); @@ -1844,8 +1850,8 @@ ParsingDriver::set_corr_prior(const string &name1, const string &name2, const st void ParsingDriver::set_corr_options(const string &name1, const string &name2, const string &subsample_name) { - check_symbol_is_endogenous_or_exogenous(name1); - check_symbol_is_endogenous_or_exogenous(name2); + check_symbol_is_endogenous_or_exogenous(name1, false); + check_symbol_is_endogenous_or_exogenous(name2, false); check_subsample_declaration_exists(name1, name2, subsample_name); mod_file->addStatement(make_unique<CorrOptionsStatement>(name1, name2, subsample_name, options_list, mod_file->symbol_table)); options_list.clear(); diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index 2329a2e999a40708c271f35f55c47fa3a7010b03..8b3af55fa14ef03810869214ebc1acea6a590a5a 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -96,13 +96,13 @@ private: void check_symbol_is_statement_variable(const string &name); //! Checks that a given symbol exists and is a endogenous or exogenous, and stops with an error message if it isn't - void check_symbol_is_endogenous_or_exogenous(const string &name); + void check_symbol_is_endogenous_or_exogenous(const string &name, bool allow_exo_det); //! Checks that a given symbol exists and is a endogenous, and stops with an error message if it isn't void check_symbol_is_endogenous(const string &name); - //! Checks that a given symbol exists and is a exogenous (possibly deterministic), and stops with an error message if it isn't - void check_symbol_is_exogenous(const string &name); + //! Checks that a given symbol exists and is a exogenous, and stops with an error message if it isn't + void check_symbol_is_exogenous(const string &name, bool allow_exo_det); //! Checks for symbol existence in model block. If it doesn't exist, an error message is stored to be printed at //! the end of the model block