diff --git a/configure.ac b/configure.ac index a1aa904eec2e6e1a72ffced7a0e0940892b7ec4c..c19e7abd34629b8756a7ba4690be5a1b6ed7a07e 100644 --- a/configure.ac +++ b/configure.ac @@ -43,7 +43,7 @@ esac # Use C++ for testing headers AC_LANG([C++]) -AM_CXXFLAGS="-std=gnu++20 -Wall -Wno-dangling-else -Wextra -Wold-style-cast" +AM_CXXFLAGS="-std=gnu++20 -Wall -Wextra -Wold-style-cast" AC_SUBST([AM_CXXFLAGS]) # If default 'ar' is not available, try to find one with a host prefix (see ticket #145) diff --git a/src/ConfigFile.cc b/src/ConfigFile.cc index e6b0abbff29ccfa8e25f6b06a86a9fcb9da86b6b..ebf8d3cfcc44c944eb9d1be6f8f6f23e595d73bf 100644 --- a/src/ConfigFile.cc +++ b/src/ConfigFile.cc @@ -148,13 +148,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file) #endif configFile.open(defaultConfigFile, fstream::in); if (!configFile.is_open()) - if (parallel || parallel_test) - { - cerr << "ERROR: Could not open the default config file (" << defaultConfigFile.string() << ")" << endl; - exit(EXIT_FAILURE); - } - else - return; + { + if (parallel || parallel_test) + { + cerr << "ERROR: Could not open the default config file (" << defaultConfigFile.string() << ")" << endl; + exit(EXIT_FAILURE); + } + else + return; + } } else { @@ -396,13 +398,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file) if (!begin_weight) { if (!node_name.empty()) - if (member_nodes.contains(node_name)) - { - cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl; - exit(EXIT_FAILURE); - } - else - member_nodes[node_name] = 1.0; + { + if (member_nodes.contains(node_name)) + { + cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl; + exit(EXIT_FAILURE); + } + else + member_nodes[node_name] = 1.0; + } node_name = token; } else @@ -423,13 +427,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file) } } if (!node_name.empty()) - if (!member_nodes.contains(node_name)) - member_nodes[node_name] = 1.0; - else - { - cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl; - exit(EXIT_FAILURE); - } + { + if (!member_nodes.contains(node_name)) + member_nodes[node_name] = 1.0; + else + { + cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl; + exit(EXIT_FAILURE); + } + } } else { @@ -505,16 +511,16 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member operatingSystem); //! ADD CLUSTER else if (inCluster) - if (minCpuNbr > 0 || maxCpuNbr > 0 || !userName.empty() - || !password.empty() || !remoteDrive.empty() || !remoteDirectory.empty() - || !programPath.empty() || !programConfig.empty() - || !matlabOctavePath.empty() || !operatingSystem.empty()) - { - cerr << "Invalid option passed to [cluster]." << endl; - exit(EXIT_FAILURE); - } - else - if (name.empty() || clusters.contains(name)) + { + if (minCpuNbr > 0 || maxCpuNbr > 0 || !userName.empty() + || !password.empty() || !remoteDrive.empty() || !remoteDirectory.empty() + || !programPath.empty() || !programConfig.empty() + || !matlabOctavePath.empty() || !operatingSystem.empty()) + { + cerr << "Invalid option passed to [cluster]." << endl; + exit(EXIT_FAILURE); + } + else if (name.empty() || clusters.contains(name)) { cerr << "ERROR: The cluster must be assigned a unique name." << endl; exit(EXIT_FAILURE); @@ -525,6 +531,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member firstClusterName = name; clusters.emplace(name, member_nodes); } + } } void diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 4480b4f503d9f15bead6d052e354562ba9e00d29..04292b003b8ea07b8f2bae92561065de1d60f6ae 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -514,16 +514,17 @@ DynamicModel::parseIncludeExcludeEquations(const string &inc_exc_option_value, b { removeLeadingTrailingWhitespace(line); if (!line.empty()) - if (tags.empty() && line.find("=") != string::npos) - { - tagname_on_first_line = true; - tags += line + "("; - } - else - if (line.find("'") != string::npos) + { + if (tags.empty() && line.find("=") != string::npos) + { + tagname_on_first_line = true; + tags += line + "("; + } + else if (line.find("'") != string::npos) tags += line + ","; else tags += "'" + line + "',"; + } } if (!tags.empty()) @@ -634,21 +635,23 @@ DynamicModel::removeEquationsHelper(set<pair<string, string>> &listed_eqs_by_tag if (eqs_to_delete_by_number.contains(i)) { if (excluded_vars_change_type) - if (auto tmp = all_equation_tags.getTagValueByEqnAndKey(i, "endogenous"); tmp) - excluded_vars.push_back(symbol_table.getID(*tmp)); - else - { - set<int> result; - all_equations[i]->arg1->collectVariables(SymbolType::endogenous, result); - if (result.size() == 1) - excluded_vars.push_back(*result.begin()); - else - { - cerr << "ERROR: Equation " << i+1 - << " has been excluded but it does not have a single variable on its left-hand side or an `endogenous` tag" << endl; - exit(EXIT_FAILURE); - } - } + { + if (auto tmp = all_equation_tags.getTagValueByEqnAndKey(i, "endogenous"); tmp) + excluded_vars.push_back(symbol_table.getID(*tmp)); + else + { + set<int> result; + all_equations[i]->arg1->collectVariables(SymbolType::endogenous, result); + if (result.size() == 1) + excluded_vars.push_back(*result.begin()); + else + { + cerr << "ERROR: Equation " << i+1 + << " has been excluded but it does not have a single variable on its left-hand side or an `endogenous` tag" << endl; + exit(EXIT_FAILURE); + } + } + } } else { @@ -2616,17 +2619,19 @@ DynamicModel::expandEqTags() set<int> existing_tags = equation_tags.getEqnsByKey("name"); for (int eq = 0; eq < static_cast<int>(equations.size()); eq++) if (!existing_tags.contains(eq)) - if (auto lhs_expr = dynamic_cast<VariableNode *>(equations[eq]->arg1); - lhs_expr - && !equation_tags.exists("name", symbol_table.getName(lhs_expr->symb_id))) - equation_tags.add(eq, "name", symbol_table.getName(lhs_expr->symb_id)); - else if (!equation_tags.exists("name", to_string(eq+1))) - equation_tags.add(eq, "name", to_string(eq+1)); - else - { - cerr << "Error creating default equation tag: cannot assign default tag to equation number " << eq+1 << " because it is already in use" << endl; - exit(EXIT_FAILURE); - } + { + if (auto lhs_expr = dynamic_cast<VariableNode *>(equations[eq]->arg1); + lhs_expr + && !equation_tags.exists("name", symbol_table.getName(lhs_expr->symb_id))) + equation_tags.add(eq, "name", symbol_table.getName(lhs_expr->symb_id)); + else if (!equation_tags.exists("name", to_string(eq+1))) + equation_tags.add(eq, "name", to_string(eq+1)); + else + { + cerr << "Error creating default equation tag: cannot assign default tag to equation number " << eq+1 << " because it is already in use" << endl; + exit(EXIT_FAILURE); + } + } } set<int> diff --git a/src/ExprNode.cc b/src/ExprNode.cc index e69a177bc8126d180851181608d08d36a2bdb654..7b1a86d728ef4f181112cef1d8fe5f20379cade6 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -5664,10 +5664,12 @@ BinaryOpNode::getPacNonOptimizingPart(int optim_share_symb_id) const expr_t non_optim_part = datatree.One; for (auto [factor, exponent] : factors) if (factor != one_minus_optim_share) - if (exponent == 1) - non_optim_part = datatree.AddTimes(non_optim_part, factor); - else - non_optim_part = datatree.AddDivide(non_optim_part, factor); + { + if (exponent == 1) + non_optim_part = datatree.AddTimes(non_optim_part, factor); + else + non_optim_part = datatree.AddDivide(non_optim_part, factor); + } return non_optim_part; } diff --git a/src/ModFile.cc b/src/ModFile.cc index da331f8e8b80cbf43e843e91e4d78aa49d8a1a7b..34ea448622a80777d555d1cda1b397c8172a4130 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -245,18 +245,20 @@ ModFile::checkPass(bool nostrict, bool stochastic) } if (mod_file_struct.dsge_prior_weight_in_estimated_params) - if (!mod_file_struct.dsge_var_estimated && !mod_file_struct.dsge_var_calibrated.empty()) - { - cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, the prior weight cannot be calibrated " - << "via the dsge_var option in the estimation statement." << endl; - exit(EXIT_FAILURE); - } - else if (!mod_file_struct.dsge_var_estimated && !symbol_table.exists("dsge_prior_weight")) - { - cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, it must either be declared as a parameter " + { + if (!mod_file_struct.dsge_var_estimated && !mod_file_struct.dsge_var_calibrated.empty()) + { + cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, the prior weight cannot be calibrated " + << "via the dsge_var option in the estimation statement." << endl; + exit(EXIT_FAILURE); + } + else if (!mod_file_struct.dsge_var_estimated && !symbol_table.exists("dsge_prior_weight")) + { + cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, it must either be declared as a parameter " << "(deprecated) or the dsge_var option must be passed to the estimation statement (preferred)." << endl; - exit(EXIT_FAILURE); - } + exit(EXIT_FAILURE); + } + } if (dynamic_model.staticOnlyEquationsNbr() != dynamic_model.dynamicOnlyEquationsNbr()) { @@ -477,13 +479,15 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool PlannerObjectiveStatement *pos = nullptr; for (auto &statement : statements) if (auto pos2 = dynamic_cast<PlannerObjectiveStatement *>(statement.get()); pos2) - if (pos) - { - cerr << "ERROR: there can only be one planner_objective statement" << endl; - exit(EXIT_FAILURE); - } - else - pos = pos2; + { + if (pos) + { + cerr << "ERROR: there can only be one planner_objective statement" << endl; + exit(EXIT_FAILURE); + } + else + pos = pos2; + } assert(pos); const PlannerObjective &planner_objective = pos->getPlannerObjective(); @@ -621,22 +625,23 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool } if (symbol_table.exists("dsge_prior_weight")) - if (mod_file_struct.bayesian_irf_present) - { - if (symbol_table.exo_nbr() != symbol_table.observedVariablesNbr()) - { - cerr << "ERROR: When estimating a DSGE-Var and the bayesian_irf option is passed to the estimation " - << "statement, the number of shocks must equal the number of observed variables." << endl; - exit(EXIT_FAILURE); - } - } - else - if (symbol_table.exo_nbr() < symbol_table.observedVariablesNbr()) + { + if (mod_file_struct.bayesian_irf_present) + { + if (symbol_table.exo_nbr() != symbol_table.observedVariablesNbr()) + { + cerr << "ERROR: When estimating a DSGE-Var and the bayesian_irf option is passed to the estimation " + << "statement, the number of shocks must equal the number of observed variables." << endl; + exit(EXIT_FAILURE); + } + } + else if (symbol_table.exo_nbr() < symbol_table.observedVariablesNbr()) { cerr << "ERROR: When estimating a DSGE-Var, the number of shocks must be " << "greater than or equal to the number of observed variables." << endl; exit(EXIT_FAILURE); } + } } void @@ -728,10 +733,12 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll); if (linear) - if (mod_file_struct.ramsey_model_present) - orig_ramsey_dynamic_model.checkIsLinear(); - else - dynamic_model.checkIsLinear(); + { + if (mod_file_struct.ramsey_model_present) + orig_ramsey_dynamic_model.checkIsLinear(); + else + dynamic_model.checkIsLinear(); + } } // Those matrices can only be filled here, because we use derivatives diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 8510952002efd709af9d73aa9755225e1acbe6d9..1eef9a4d51b55d1a3dd4e45013cee629748aabe6 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -845,13 +845,15 @@ ParsingDriver::end_model() if (undeclared_model_variable_errors.size() > 0) for (auto &it : undeclared_model_variable_errors) - if (nostrict) - warning(it.second); - else - { - exit_after_write = true; - cerr << it.second << endl; - } + { + if (nostrict) + warning(it.second); + else + { + exit_after_write = true; + cerr << it.second << endl; + } + } undeclared_model_variable_errors.clear(); if (exit_after_write) @@ -2154,13 +2156,15 @@ ParsingDriver::end_planner_objective(expr_t expr) bool exit_after_write = false; if (undeclared_model_variable_errors.size() > 0) for (auto &it : undeclared_model_variable_errors) - if (nostrict) - warning(it.second); - else - { - exit_after_write = true; - cerr << it.second << endl; - } + { + if (nostrict) + warning(it.second); + else + { + exit_after_write = true; + cerr << it.second << endl; + } + } undeclared_model_variable_errors.clear(); if (exit_after_write) exit(EXIT_FAILURE); @@ -3149,12 +3153,14 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b error("Using a derivative of an external function (" + function_name + ") in the model block is currently not allowed."); if (in_model_block || parsing_epilogue) - if (mod_file->external_functions_table.getNargs(symb_id) == ExternalFunctionsTable::IDNotSet) - error("Before using " + function_name - +"() in the model block, you must first declare it via the external_function() statement"); - else if (static_cast<int>(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id)) - error("The number of arguments passed to " + function_name - +"() does not match those of a previous call or declaration of this function."); + { + if (mod_file->external_functions_table.getNargs(symb_id) == ExternalFunctionsTable::IDNotSet) + error("Before using " + function_name + +"() in the model block, you must first declare it via the external_function() statement"); + else if (static_cast<int>(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id)) + error("The number of arguments passed to " + function_name + +"() does not match those of a previous call or declaration of this function."); + } } else { //First time encountering this external function i.e., not previously declared or encountered diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index d7cee2bf79c1ad4410d9dbd04af02c4ad84779d2..435ce5c521a2a039d75d11ec6389328e82276f32 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -686,10 +686,12 @@ SymbolTable::getOrigSymbIdForAuxVar(int aux_var_symb_id_arg) const noexcept(fals || aux_var.type == AuxVarType::diffForward || aux_var.type == AuxVarType::unaryOp) && aux_var.symb_id == aux_var_symb_id_arg) - if (optional<int> r = aux_var.orig_symb_id; r) - return *r; - else - throw UnknownSymbolIDException(aux_var_symb_id_arg); // Some diff and unaryOp auxvars have orig_symb_id unset + { + if (optional<int> r = aux_var.orig_symb_id; r) + return *r; + else + throw UnknownSymbolIDException(aux_var_symb_id_arg); // Some diff and unaryOp auxvars have orig_symb_id unset + } throw UnknownSymbolIDException(aux_var_symb_id_arg); } diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index c34e850052e170bade9f27f9725488a022288685..54f747008cfc8e1c791c546276036cd6c3ff7bee 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -1029,10 +1029,12 @@ Comprehension::eval(Environment &env) const throw; } if ((bp && *bp) || (dp && *dp)) - if (c_expr) - values.emplace_back(c_expr->eval(env)); - else - values.emplace_back(btp); + { + if (c_expr) + values.emplace_back(c_expr->eval(env)); + else + values.emplace_back(btp); + } } } return make_shared<Array>(values);