Compare commits

...

10 Commits

Author SHA1 Message Date
Sébastien Villemot 378d00fc3a Merge branch 'globals' into 'master'
Remove globals from dynare_sensitivity and dynare_identification

See merge request Dynare/preprocessor!95
2023-12-07 11:03:06 +00:00
Sébastien Villemot 045fbaec0e
Remove empty line
[skip ci]
2023-12-04 17:36:20 +01:00
Sébastien Villemot bffd68e0bf
Add a clang-tidy configuration file
Also add some annotations to remove some false positives.

There remain some boost-related false positives, it’s unclear how to suppress
them.
2023-12-04 16:37:00 +01:00
Johannes Pfeifer 6d9fc367d0 Remove globals from dynare_sensitivity and dynare_identification 2023-12-04 12:01:19 +01:00
Sébastien Villemot b2e9ec205e
No longer use reserved identifiers for include guards
Automatically detected using clang-tidy with bugprone-reserved-identifier
check.

By the way, homogeneize the define identifiers in relation to camel case
convention.
2023-12-01 15:39:01 +01:00
Sébastien Villemot 5af38c8ced
ModelTree.hh: fix misplaced #endif for include guard 2023-12-01 15:35:40 +01:00
Sébastien Villemot c2d6ab8ee0
Simplify a few loops using std::ranges::reverse_view
Automatically detected using clang-tidy with modernize-loop-convert check.
2023-12-01 15:06:40 +01:00
Sébastien Villemot c5cc61b110
PlannerObjectiveStatement: turn model_tree into a std::unique_ptr
Avoids an unnecessary copy.
2023-12-01 14:59:20 +01:00
Sébastien Villemot 5e89921ea1
Use emplace() and emplace_back() at several places
Automatically detected using clang-tidy with modernize-use-emplace check.
2023-12-01 14:30:03 +01:00
Sébastien Villemot b8c521be31
Mark SymbolTable::maxID() as const and nodiscard 2023-12-01 14:17:12 +01:00
41 changed files with 160 additions and 134 deletions

9
.clang-tidy Normal file
View File

@ -0,0 +1,9 @@
# TODO: add the following check families:
# - performance-*
# - bugprone-*
# - cppcoreguidelines-
# NB: as of clang-tidy 16, we get several false positives inside boost, notably this one:
# https://github.com/llvm/llvm-project/issues/40486
Checks: 'modernize-*,-modernize-use-trailing-return-type,-clang-diagnostic-unqualified-std-cast-call'

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _BYTECODE_HH #ifndef BYTECODE_HH
#define _BYTECODE_HH #define BYTECODE_HH
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@ -1151,4 +1151,4 @@ BytecodeWriter& operator<<(BytecodeWriter& code_file, const FCALL_& instr);
template<> template<>
BytecodeWriter& operator<<(BytecodeWriter& code_file, const FBEGINBLOCK_& instr); BytecodeWriter& operator<<(BytecodeWriter& code_file, const FBEGINBLOCK_& instr);
#endif // _BYTECODE_HH #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2007-2022 Dynare Team * Copyright © 2007-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _COMMON_ENUMS_HH #ifndef COMMON_ENUMS_HH
#define _COMMON_ENUMS_HH #define COMMON_ENUMS_HH
//! Enumeration of possible symbol types //! Enumeration of possible symbol types
/*! Warning: do not to change existing values for 0 to 4: the values matter for homotopy_setup /*! Warning: do not to change existing values for 0 to 4: the values matter for homotopy_setup
@ -151,4 +151,4 @@ enum class PacTargetKind
dd dd
}; };
#endif // _COMMON_ENUMS_HH #endif

View File

@ -1106,7 +1106,7 @@ DynareSensitivityStatement::writeOutput(ostream& output, [[maybe_unused]] const
if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("graph_format")) if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("graph_format"))
opt->writeOutput("options_.graph_format", output); opt->writeOutput("options_.graph_format", output);
output << "dynare_sensitivity(options_gsa);" << endl; output << "dynare_sensitivity(M_,oo_,options_,bayestopt_,estim_params_,options_gsa);" << endl;
} }
void void
@ -2400,8 +2400,8 @@ ModelComparisonStatement::writeJsonOutput(ostream& output) const
output << "}"; output << "}";
} }
PlannerObjectiveStatement::PlannerObjectiveStatement(const PlannerObjective& model_tree_arg) : PlannerObjectiveStatement::PlannerObjectiveStatement(unique_ptr<PlannerObjective> model_tree_arg) :
model_tree {model_tree_arg} model_tree {move(model_tree_arg)}
{ {
} }
@ -2409,8 +2409,8 @@ void
PlannerObjectiveStatement::checkPass(ModFileStructure& mod_file_struct, PlannerObjectiveStatement::checkPass(ModFileStructure& mod_file_struct,
[[maybe_unused]] WarningConsolidation& warnings) [[maybe_unused]] WarningConsolidation& warnings)
{ {
assert(model_tree.equation_number() == 1); assert(model_tree->equation_number() == 1);
if (model_tree.exoPresentInEqs()) if (model_tree->exoPresentInEqs())
{ {
cerr << "ERROR: You cannot include exogenous variables (or variables of undeclared type) in " cerr << "ERROR: You cannot include exogenous variables (or variables of undeclared type) in "
"the planner objective. Please " "the planner objective. Please "
@ -2424,13 +2424,13 @@ PlannerObjectiveStatement::checkPass(ModFileStructure& mod_file_struct,
const PlannerObjective& const PlannerObjective&
PlannerObjectiveStatement::getPlannerObjective() const PlannerObjectiveStatement::getPlannerObjective() const
{ {
return model_tree; return *model_tree;
} }
void void
PlannerObjectiveStatement::computingPass(const ModFileStructure& mod_file_struct) PlannerObjectiveStatement::computingPass(const ModFileStructure& mod_file_struct)
{ {
model_tree.computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false); model_tree->computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false);
computing_pass_called = true; computing_pass_called = true;
} }
@ -2439,14 +2439,14 @@ PlannerObjectiveStatement::writeOutput(ostream& output, const string& basename,
[[maybe_unused]] bool minimal_workspace) const [[maybe_unused]] bool minimal_workspace) const
{ {
output << "M_.NNZDerivatives_objective = ["; output << "M_.NNZDerivatives_objective = [";
for (int i = 1; i < static_cast<int>(model_tree.getNNZDerivatives().size()); i++) for (int i = 1; i < static_cast<int>(model_tree->getNNZDerivatives().size()); i++)
output << (i > model_tree.getComputedDerivsOrder() ? -1 : model_tree.getNNZDerivatives()[i]) output << (i > model_tree->getComputedDerivsOrder() ? -1 : model_tree->getNNZDerivatives()[i])
<< ";"; << ";";
output << "];" << endl << "M_.objective_tmp_nbr = ["; output << "];" << endl << "M_.objective_tmp_nbr = [";
for (const auto& temporary_terms_derivative : model_tree.getTemporaryTermsDerivatives()) for (const auto& temporary_terms_derivative : model_tree->getTemporaryTermsDerivatives())
output << temporary_terms_derivative.size() << "; "; output << temporary_terms_derivative.size() << "; ";
output << "];" << endl; output << "];" << endl;
model_tree.writeStaticFile(basename + ".objective", false, "", {}, false); model_tree->writeStaticFile(basename + ".objective", false, "", {}, false);
} }
void void
@ -2455,9 +2455,9 @@ PlannerObjectiveStatement::writeJsonOutput(ostream& output) const
output << R"({"statementName": "planner_objective")" output << R"({"statementName": "planner_objective")"
<< ", "; << ", ";
if (computing_pass_called) if (computing_pass_called)
model_tree.writeJsonComputingPassOutput(output, false); model_tree->writeJsonComputingPassOutput(output, false);
else else
model_tree.writeJsonOutput(output); model_tree->writeJsonOutput(output);
output << "}"; output << "}";
} }
@ -2941,7 +2941,8 @@ IdentificationStatement::writeOutput(ostream& output, [[maybe_unused]] const str
if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("graph_format")) if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("graph_format"))
opt->writeOutput("options_.graph_format", output); opt->writeOutput("options_.graph_format", output);
output << "dynare_identification(options_ident);" << endl; output << "dynare_identification(M_,oo_,options_,bayestopt_,estim_params_,"
<< "options_ident);" << endl;
} }
void void

View File

@ -17,9 +17,10 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _COMPUTINGTASKS_HH #ifndef COMPUTING_TASKS_HH
#define _COMPUTINGTASKS_HH #define COMPUTING_TASKS_HH
#include <memory>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
@ -618,11 +619,11 @@ public:
class PlannerObjectiveStatement : public Statement class PlannerObjectiveStatement : public Statement
{ {
private: private:
PlannerObjective model_tree; unique_ptr<PlannerObjective> model_tree;
bool computing_pass_called {false}; bool computing_pass_called {false};
public: public:
explicit PlannerObjectiveStatement(const PlannerObjective& model_tree_arg); explicit PlannerObjectiveStatement(unique_ptr<PlannerObjective> model_tree_arg);
/*! \todo check there are only endogenous variables at the current period in the objective /*! \todo check there are only endogenous variables at the current period in the objective
(no exogenous, no lead/lag) */ (no exogenous, no lead/lag) */
void checkPass(ModFileStructure& mod_file_struct, WarningConsolidation& warnings) override; void checkPass(ModFileStructure& mod_file_struct, WarningConsolidation& warnings) override;
@ -631,7 +632,7 @@ public:
void writeOutput(ostream& output, const string& basename, bool minimal_workspace) const override; void writeOutput(ostream& output, const string& basename, bool minimal_workspace) const override;
void writeJsonOutput(ostream& output) const override; void writeJsonOutput(ostream& output) const override;
//! Return a reference the Planner Objective model tree //! Return a reference the Planner Objective model tree
const PlannerObjective& getPlannerObjective() const; [[nodiscard]] const PlannerObjective& getPlannerObjective() const;
}; };
class BVARDensityStatement : public Statement class BVARDensityStatement : public Statement

View File

@ -166,7 +166,6 @@ ConfigFile::getConfigFileInfo(const filesystem::path& config_file)
if (!configFile.is_open()) if (!configFile.is_open())
{ {
cerr << "ERROR: Couldn't open file " << config_file.string() << endl; cerr << "ERROR: Couldn't open file " << config_file.string() << endl;
;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _CONFIG_FILE_HH #ifndef CONFIG_FILE_HH
#define _CONFIG_FILE_HH #define CONFIG_FILE_HH
#include <filesystem> #include <filesystem>
#include <map> #include <map>
@ -145,4 +145,4 @@ public:
void writeEndParallel(ostream& output) const; void writeEndParallel(ostream& output) const;
}; };
#endif // ! CONFIG_FILE_HH #endif

View File

@ -205,7 +205,7 @@ DataTree::AddPlus(expr_t iArg1, expr_t iArg2)
// To treat commutativity of "+" // To treat commutativity of "+"
// Nodes iArg1 and iArg2 are sorted by index // Nodes iArg1 and iArg2 are sorted by index
if (iArg1->idx > iArg2->idx && !no_commutativity) if (iArg1->idx > iArg2->idx && !no_commutativity) // NOLINT(clang-analyzer-core.NullDereference)
swap(iArg1, iArg2); swap(iArg1, iArg2);
return AddBinaryOp(iArg1, BinaryOpcode::plus, iArg2); return AddBinaryOp(iArg1, BinaryOpcode::plus, iArg2);
} }
@ -283,7 +283,7 @@ DataTree::AddTimes(expr_t iArg1, expr_t iArg2)
// To treat commutativity of "*" // To treat commutativity of "*"
// Nodes iArg1 and iArg2 are sorted by index // Nodes iArg1 and iArg2 are sorted by index
if (iArg1->idx > iArg2->idx && !no_commutativity) if (iArg1->idx > iArg2->idx && !no_commutativity) // NOLINT(clang-analyzer-core.NullDereference)
swap(iArg1, iArg2); swap(iArg1, iArg2);
return AddBinaryOp(iArg1, BinaryOpcode::times, iArg2); return AddBinaryOp(iArg1, BinaryOpcode::times, iArg2);
} }

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _DATATREE_HH #ifndef DATA_TREE_HH
#define _DATATREE_HH #define DATA_TREE_HH
#include <cmath> #include <cmath>
#include <filesystem> #include <filesystem>
@ -431,7 +431,7 @@ DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, int
{ {
try try
{ {
double argval = arg->eval({}); double argval = arg->eval({}); // NOLINT(clang-analyzer-core.CallAndMessage)
double val = UnaryOpNode::eval_opcode(op_code, argval); double val = UnaryOpNode::eval_opcode(op_code, argval);
return AddPossiblyNegativeConstant(val); return AddPossiblyNegativeConstant(val);
} }
@ -460,8 +460,8 @@ DataTree::AddBinaryOp(expr_t arg1, BinaryOpcode op_code, expr_t arg2, int powerD
// Try to reduce to a constant // Try to reduce to a constant
try try
{ {
double argval1 = arg1->eval({}); double argval1 = arg1->eval({}); // NOLINT(clang-analyzer-core.CallAndMessage)
double argval2 = arg2->eval({}); double argval2 = arg2->eval({}); // NOLINT(clang-analyzer-core.CallAndMessage)
double val = BinaryOpNode::eval_opcode(argval1, op_code, argval2, powerDerivOrder); double val = BinaryOpNode::eval_opcode(argval1, op_code, argval2, powerDerivOrder);
return AddPossiblyNegativeConstant(val); return AddPossiblyNegativeConstant(val);
} }

View File

@ -23,6 +23,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <numeric> #include <numeric>
#include <ranges>
#include <regex> #include <regex>
#include <sstream> #include <sstream>
#include <string_view> #include <string_view>
@ -1355,10 +1356,10 @@ DynamicModel::fillVarModelTableFromOrigModel() const
<< eqn << endl; << eqn << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
orig_diff_var_vec.push_back(diff_set.begin()->first); orig_diff_var_vec.emplace_back(diff_set.begin()->first);
} }
else else
orig_diff_var_vec.push_back(nullopt); orig_diff_var_vec.emplace_back(nullopt);
} }
if (eqns.size() != lhs.size()) if (eqns.size() != lhs.size())
@ -1702,10 +1703,10 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel() const
<< eqn << endl; << eqn << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
orig_diff_var_vec.push_back(diff_set.begin()->first); orig_diff_var_vec.emplace_back(diff_set.begin()->first);
} }
else else
orig_diff_var_vec.push_back(nullopt); orig_diff_var_vec.emplace_back(nullopt);
} }
if (eqns.size() != lhs.size()) if (eqns.size() != lhs.size())
@ -2730,7 +2731,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel& static_model)
else else
{ {
orig_endo_nbr++; orig_endo_nbr++;
neweqs_lineno.push_back(nullopt); neweqs_lineno.emplace_back(nullopt);
} }
} }
} }
@ -3485,18 +3486,18 @@ void
DynamicModel::detrendEquations() DynamicModel::detrendEquations()
{ {
// We go backwards in the list of trend_vars, to deal correctly with I(2) processes // We go backwards in the list of trend_vars, to deal correctly with I(2) processes
for (auto it = nonstationary_symbols_map.crbegin(); it != nonstationary_symbols_map.crend(); ++it) for (const auto& it : std::ranges::reverse_view(nonstationary_symbols_map))
{ {
for (auto& equation : equations) for (auto& equation : equations)
{ {
equation = dynamic_cast<BinaryOpNode*>( equation = dynamic_cast<BinaryOpNode*>(
equation->detrend(it->first, it->second.first, it->second.second)); equation->detrend(it.first, it.second.first, it.second.second));
assert(equation); assert(equation);
} }
for (auto& equation : static_only_equations) for (auto& equation : static_only_equations)
{ {
equation = dynamic_cast<BinaryOpNode*>( equation = dynamic_cast<BinaryOpNode*>(
equation->detrend(it->first, it->second.first, it->second.second)); equation->detrend(it.first, it.second.first, it.second.second));
assert(equation); assert(equation);
} }
} }

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _DYNAMICMODEL_HH #ifndef DYNAMIC_MODEL_HH
#define _DYNAMICMODEL_HH #define DYNAMIC_MODEL_HH
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _EQUATION_TAGS_HH #ifndef EQUATION_TAGS_HH
#define _EQUATION_TAGS_HH #define EQUATION_TAGS_HH
#include <map> #include <map>
#include <optional> #include <optional>

View File

@ -3727,7 +3727,7 @@ UnaryOpNode::substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t&
if (vn) if (vn)
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, rit->second, symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, rit->second,
vn->symb_id, vn->lag); vn->symb_id, vn->lag);
else else // NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, rit->second); symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, rit->second);
// make originating aux var & equation // make originating aux var & equation
@ -3745,8 +3745,10 @@ UnaryOpNode::substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t&
for (int i = last_index; i > rit->first; i--) for (int i = last_index; i > rit->first; i--)
{ {
if (i == last_index) if (i == last_index)
// NOLINTBEGIN(clang-analyzer-core.NullDereference)
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(argsubst->idx, rit->second, symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(argsubst->idx, rit->second,
last_aux_var->symb_id, -1); last_aux_var->symb_id, -1);
// NOLINTEND(clang-analyzer-core.NullDereference)
else else
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar( symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(
new_aux_var->idx, rit->second, last_aux_var->symb_id, -1); new_aux_var->idx, rit->second, last_aux_var->symb_id, -1);
@ -3884,6 +3886,7 @@ UnaryOpNode::substituteUnaryOpNodes(const lag_equivalence_table_t& nodes,
} }
else else
subst_table[rit->second] subst_table[rit->second]
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
= dynamic_cast<VariableNode*>(aux_var->decreaseLeadsLags(base_index - rit->first)); = dynamic_cast<VariableNode*>(aux_var->decreaseLeadsLags(base_index - rit->first));
assert(subst_table.contains(this)); assert(subst_table.contains(this));
@ -5692,6 +5695,7 @@ BinaryOpNode::getPacAREC(
vector<tuple<int, int, optional<int>, double>> linear_combination; vector<tuple<int, int, optional<int>, double>> linear_combination;
try try
{ {
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
auto [vid, lag, pid, constant] = term->matchVariableTimesConstantTimesParam(true); auto [vid, lag, pid, constant] = term->matchVariableTimesConstantTimesParam(true);
linear_combination.emplace_back(vid.value(), lag, move(pid), constant); linear_combination.emplace_back(vid.value(), lag, move(pid), constant);
} }
@ -5773,6 +5777,7 @@ BinaryOpNode::isParamTimesEndogExpr() const
} }
else else
{ {
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
arg1->collectDynamicVariables(SymbolType::endogenous, endogs); arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
arg1->collectDynamicVariables(SymbolType::exogenous, exogs); arg1->collectDynamicVariables(SymbolType::exogenous, exogs);
arg1->collectVariables(SymbolType::parameter, params); arg1->collectVariables(SymbolType::parameter, params);
@ -9311,6 +9316,7 @@ BinaryOpNode::matchEndogenousTimesConstant() const
varg1 && varg1->get_type() == SymbolType::endogenous && arg2->isConstant()) varg1 && varg1->get_type() == SymbolType::endogenous && arg2->isConstant())
return {varg1->symb_id, arg2}; return {varg1->symb_id, arg2};
if (auto varg2 = dynamic_cast<VariableNode*>(arg2); if (auto varg2 = dynamic_cast<VariableNode*>(arg2);
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
varg2 && varg2->get_type() == SymbolType::endogenous && arg1->isConstant()) varg2 && varg2->get_type() == SymbolType::endogenous && arg1->isConstant())
return {varg2->symb_id, arg1}; return {varg2->symb_id, arg1};
} }

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _EXPR_NODE_HH #ifndef EXPR_NODE_HH
#define _EXPR_NODE_HH #define EXPR_NODE_HH
#include <functional> #include <functional>
#include <map> #include <map>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2014-2021 Dynare Team * Copyright © 2014-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _EXTENDED_PREPROCESSOR_TYPES_HH #ifndef EXTENDED_PREPROCESSOR_TYPES_HH
#define _EXTENDED_PREPROCESSOR_TYPES_HH #define EXTENDED_PREPROCESSOR_TYPES_HH
// Values for the “output” option // Values for the “output” option
enum class OutputType enum class OutputType

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _EXTERNALFUNCTIONSTABLE_HH #ifndef EXTERNAL_FUNCTIONS_TABLE_HH
#define _EXTERNALFUNCTIONSTABLE_HH #define EXTERNAL_FUNCTIONS_TABLE_HH
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _MOD_FILE_HH #ifndef MOD_FILE_HH
#define _MOD_FILE_HH #define MOD_FILE_HH
#include <ctime> #include <ctime>
#include <filesystem> #include <filesystem>
@ -194,4 +194,4 @@ public:
bool jsonderivsimple = false); bool jsonderivsimple = false);
}; };
#endif // ! MOD_FILE_HH #endif

View File

@ -19,6 +19,7 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <ranges>
#include <sstream> #include <sstream>
#include "ModelEquationBlock.hh" #include "ModelEquationBlock.hh"
@ -385,10 +386,10 @@ void
Epilogue::detrend(const map<int, expr_t>& trend_symbols_map, Epilogue::detrend(const map<int, expr_t>& trend_symbols_map,
const nonstationary_symbols_map_t& nonstationary_symbols_map) const nonstationary_symbols_map_t& nonstationary_symbols_map)
{ {
for (auto it = nonstationary_symbols_map.crbegin(); it != nonstationary_symbols_map.crend(); ++it) for (const auto& it : ranges::reverse_view(nonstationary_symbols_map))
for (auto& [symb_id, expr] : dynamic_def_table) for (auto& [symb_id, expr] : dynamic_def_table)
{ {
expr = expr->detrend(it->first, it->second.first, it->second.second); expr = expr->detrend(it.first, it.second.first, it.second.second);
assert(expr); assert(expr);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2010-2022 Dynare Team * Copyright © 2010-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _MODEL_EQUATION_BLOCK_HH #ifndef MODEL_EQUATION_BLOCK_HH
#define _MODEL_EQUATION_BLOCK_HH #define MODEL_EQUATION_BLOCK_HH
#include "DataTree.hh" #include "DataTree.hh"
#include "DynamicModel.hh" #include "DynamicModel.hh"

View File

@ -393,7 +393,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t& eval_context) const
double val {[&] { double val {[&] {
try try
{ {
return d1->eval(eval_context); return d1->eval(eval_context); // NOLINT(clang-analyzer-core.NullDereference)
} }
catch (ExprNode::EvalExternalFunctionException& e) catch (ExprNode::EvalExternalFunctionException& e)
{ {

View File

@ -17,26 +17,26 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _MODELTREE_HH #ifndef MODEL_TREE_HH
# define _MODELTREE_HH #define MODEL_TREE_HH
# include <array> #include <array>
# include <cassert> #include <cassert>
# include <condition_variable> #include <condition_variable>
# include <deque> #include <deque>
# include <filesystem> #include <filesystem>
# include <map> #include <map>
# include <mutex> #include <mutex>
# include <optional> #include <optional>
# include <ostream> #include <ostream>
# include <string> #include <string>
# include <thread> #include <thread>
# include <vector> #include <vector>
# include "Bytecode.hh" #include "Bytecode.hh"
# include "DataTree.hh" #include "DataTree.hh"
# include "EquationTags.hh" #include "EquationTags.hh"
# include "ExtendedPreprocessorTypes.hh" #include "ExtendedPreprocessorTypes.hh"
using namespace std; using namespace std;
@ -623,11 +623,11 @@ private:
void copyHelper(const ModelTree& m); void copyHelper(const ModelTree& m);
//! Returns the name of the MATLAB architecture given the extension used for MEX files //! Returns the name of the MATLAB architecture given the extension used for MEX files
static string matlab_arch(const string& mexext); static string matlab_arch(const string& mexext);
# ifdef __APPLE__ #ifdef __APPLE__
/* Finds a suitable compiler on macOS. /* Finds a suitable compiler on macOS.
The boolean is false if this is GCC and true if this is Clang */ The boolean is false if this is GCC and true if this is Clang */
static pair<filesystem::path, bool> findCompilerOnMacos(const string& mexext); static pair<filesystem::path, bool> findCompilerOnMacos(const string& mexext);
# endif #endif
/* Compiles a MEX file (if link=true) or an object file to be linked later /* Compiles a MEX file (if link=true) or an object file to be linked later
into a MEX file (if link=false). The compilation is done in separate into a MEX file (if link=false). The compilation is done in separate
worker threads working in parallel, so the call to this function is not worker threads working in parallel, so the call to this function is not
@ -751,6 +751,7 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t& tt, temporary_terms_t& t
if (dynamic_cast<AbstractExternalFunctionNode*>(it)) if (dynamic_cast<AbstractExternalFunctionNode*>(it))
it->writeExternalFunctionOutput(output, output_type, temp_term_union, tt_idxs, tef_terms); it->writeExternalFunctionOutput(output, output_type, temp_term_union, tt_idxs, tef_terms);
// NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
it->writeOutput(output, output_type, tt, tt_idxs, tef_terms); it->writeOutput(output, output_type, tt, tt_idxs, tef_terms);
output << " = "; output << " = ";
it->writeOutput(output, output_type, temp_term_union, tt_idxs, tef_terms); it->writeOutput(output, output_type, temp_term_union, tt_idxs, tef_terms);
@ -2500,7 +2501,6 @@ ModelTree::writeSparseModelJuliaFiles(const string& basename) const
writeToFileIfModified(output, julia_dir / (prefix + "G" + to_string(i) + "!.jl")); writeToFileIfModified(output, julia_dir / (prefix + "G" + to_string(i) + "!.jl"));
} }
} }
#endif
template<bool dynamic> template<bool dynamic>
void void
@ -3139,3 +3139,5 @@ ModelTree::writeSetAuxiliaryVariablesFile(const string& basename, bool julia) co
output_file.close(); output_file.close();
} }
} }
#endif

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _NUMERICALCONSTANTS_HH #ifndef NUMERICAL_CONSTANTS_HH
#define _NUMERICALCONSTANTS_HH #define NUMERICAL_CONSTANTS_HH
#include <map> #include <map>
#include <string> #include <string>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _NUMERICALINITIALIZATION_HH #ifndef NUMERICAL_INITIALIZATION_HH
#define _NUMERICALINITIALIZATION_HH #define NUMERICAL_INITIALIZATION_HH
#include <filesystem> #include <filesystem>
#include <map> #include <map>

View File

@ -2235,7 +2235,7 @@ ParsingDriver::end_planner_objective(expr_t expr)
expr_t eq = model_tree->AddEqual(expr, model_tree->Zero); expr_t eq = model_tree->AddEqual(expr, model_tree->Zero);
model_tree->addEquation(eq, location.begin.line); model_tree->addEquation(eq, location.begin.line);
mod_file->addStatement(make_unique<PlannerObjectiveStatement>(*planner_objective)); mod_file->addStatement(make_unique<PlannerObjectiveStatement>(move(planner_objective)));
// Handle undeclared variables (see #81) // Handle undeclared variables (see #81)
bool exit_after_write = false; bool exit_after_write = false;
@ -3181,7 +3181,7 @@ ParsingDriver::external_function()
void void
ParsingDriver::push_external_function_arg_vector_onto_stack() ParsingDriver::push_external_function_arg_vector_onto_stack()
{ {
stack_external_function_args.push({}); stack_external_function_args.emplace();
} }
void void

View File

@ -17,10 +17,10 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _PARSING_DRIVER_HH #ifndef PARSING_DRIVER_HH
#define _PARSING_DRIVER_HH #define PARSING_DRIVER_HH
#ifdef _MACRO_DRIVER_HH #ifdef MACRO_DRIVER_HH
# error Impossible to include both ParsingDriver.hh and macro/Driver.hh # error Impossible to include both ParsingDriver.hh and macro/Driver.hh
#endif #endif
@ -964,4 +964,4 @@ public:
} }
}; };
#endif // ! PARSING_DRIVER_HH #endif

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _SHOCKS_HH #ifndef SHOCKS_HH
#define _SHOCKS_HH #define SHOCKS_HH
#include <map> #include <map>
#include <string> #include <string>

View File

@ -184,6 +184,7 @@ OptionsList::writeOutput(ostream& output, const string& option_group) const
void void
OptionsList::writeOutputCommon(ostream& output, const string& option_group) const OptionsList::writeOutputCommon(ostream& output, const string& option_group) const
{ {
// NOLINTBEGIN(clang-analyzer-core.CallAndMessage)
for (const auto& [name, val] : options) for (const auto& [name, val] : options)
std::visit( std::visit(
[&]<class T>(const T& v) { [&]<class T>(const T& v) {
@ -261,6 +262,7 @@ OptionsList::writeOutputCommon(ostream& output, const string& option_group) cons
} }
}, },
val); val);
// NOLINTEND(clang-analyzer-core.CallAndMessage)
} }
void void

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _STATEMENT_HH #ifndef STATEMENT_HH
#define _STATEMENT_HH #define STATEMENT_HH
#include <map> #include <map>
#include <optional> #include <optional>
@ -335,4 +335,4 @@ private:
static constexpr bool always_false_v {false}; static constexpr bool always_false_v {false};
}; };
#endif // ! _STATEMENT_HH #endif

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _STATIC_MODEL_HH #ifndef STATIC_MODEL_HH
#define _STATIC_MODEL_HH #define STATIC_MODEL_HH
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _SUBMODEL_HH #ifndef SUB_MODEL_HH
#define _SUBMODEL_HH #define SUB_MODEL_HH
#include <iostream> #include <iostream>
#include <map> #include <map>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _SYMBOL_LIST_HH #ifndef SYMBOL_LIST_HH
#define _SYMBOL_LIST_HH #define SYMBOL_LIST_HH
#include <algorithm> #include <algorithm>
#include <ostream> #include <ostream>

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _SYMBOLTABLE_HH #ifndef SYMBOL_TABLE_HH
#define _SYMBOLTABLE_HH #define SYMBOL_TABLE_HH
#include <map> #include <map>
#include <optional> #include <optional>
@ -363,7 +363,7 @@ public:
//! Get number of parameters //! Get number of parameters
[[nodiscard]] inline int param_nbr() const noexcept(false); [[nodiscard]] inline int param_nbr() const noexcept(false);
//! Returns the greatest symbol ID (the smallest is zero) //! Returns the greatest symbol ID (the smallest is zero)
inline int maxID(); [[nodiscard]] inline int maxID() const;
//! Get number of user-declared endogenous variables (without the auxiliary variables) //! Get number of user-declared endogenous variables (without the auxiliary variables)
[[nodiscard]] inline int orig_endo_nbr() const noexcept(false); [[nodiscard]] inline int orig_endo_nbr() const noexcept(false);
//! Write output of this class //! Write output of this class
@ -540,7 +540,7 @@ SymbolTable::param_nbr() const noexcept(false)
} }
inline int inline int
SymbolTable::maxID() SymbolTable::maxID() const
{ {
return symbol_table.size() - 1; return symbol_table.size() - 1;
} }

View File

@ -29,6 +29,7 @@
#include <boost/graph/strong_components.hpp> #include <boost/graph/strong_components.hpp>
#include <boost/graph/topological_sort.hpp> #include <boost/graph/topological_sort.hpp>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include <ranges>
using namespace boost; using namespace boost;
@ -325,8 +326,8 @@ VariableDependencyGraph::reorderRecursiveVariables(const set<int>& feedback_vert
auto v_index = get(vertex_index, G); auto v_index = get(vertex_index, G);
// Suppress feedback vertices, in decreasing order // Suppress feedback vertices, in decreasing order
for (auto it = feedback_vertices.rbegin(); it != feedback_vertices.rend(); ++it) for (int feedback_vertex : ranges::reverse_view(feedback_vertices))
G.suppress(*it); G.suppress(feedback_vertex);
bool something_has_been_done = true; bool something_has_been_done = true;
while (something_has_been_done) while (something_has_been_done)

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _VARIABLEDEPENDENCYGRAPH_HH #ifndef VARIABLE_DEPENDENCY_GRAPH_HH
#define _VARIABLEDEPENDENCYGRAPH_HH #define VARIABLE_DEPENDENCY_GRAPH_HH
#include <map> #include <map>
#include <vector> #include <vector>
@ -94,4 +94,4 @@ private:
bool suppressionOfVerticesWithLoop(set<int>& feed_back_vertices); bool suppressionOfVerticesWithLoop(set<int>& feed_back_vertices);
}; };
#endif // _VARIABLEDEPENDENCYGRAPH_HH #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2012-2017 Dynare Team * Copyright © 2012-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _WARNINGCONSOLIDATION_HH #ifndef WARNING_CONSOLIDATION_HH
#define _WARNINGCONSOLIDATION_HH #define WARNING_CONSOLIDATION_HH
#include "DynareBisonLocation.hh" #include "DynareBisonLocation.hh"
#include <sstream> #include <sstream>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2019-2020 Dynare Team * Copyright © 2019-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _DIRECTIVES_HH #ifndef DIRECTIVES_HH
#define _DIRECTIVES_HH #define DIRECTIVES_HH
#include "Expressions.hh" #include "Expressions.hh"

View File

@ -17,10 +17,10 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _MACRO_DRIVER_HH #ifndef MACRO_DRIVER_HH
#define _MACRO_DRIVER_HH #define MACRO_DRIVER_HH
#ifdef _PARSING_DRIVER_HH #ifdef PARSING_DRIVER_HH
# error Impossible to include both ../ParsingDriver.hh and Driver.hh # error Impossible to include both ../ParsingDriver.hh and Driver.hh
#endif #endif
@ -101,7 +101,7 @@ public:
void void
pushContext() pushContext()
{ {
directive_stack.emplace(vector<DirectivePtr>()); directive_stack.emplace();
} }
void void

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _ENVIRONMENT_HH #ifndef ENVIRONMENT_HH
#define _ENVIRONMENT_HH #define ENVIRONMENT_HH
#include "ForwardDeclarationsAndEnums.hh" #include "ForwardDeclarationsAndEnums.hh"

View File

@ -623,12 +623,15 @@ Range::eval(Environment& env) const
"the arguments must evaluate to reals"); "the arguments must evaluate to reals");
vector<ExpressionPtr> arr; vector<ExpressionPtr> arr;
// We do want a float counter, because thats the macro-language semantics
// NOLINTBEGIN(clang-analyzer-security.FloatLoopCounter)
if (*incdbl > 0 && *startdbl <= *enddbl) if (*incdbl > 0 && *startdbl <= *enddbl)
for (double i = *startdbl; i <= *enddbl; i += *incdbl) for (double i = *startdbl; i <= *enddbl; i += *incdbl)
arr.emplace_back(make_shared<Real>(i)); arr.emplace_back(make_shared<Real>(i));
else if (*startdbl >= *enddbl && *incdbl < 0) else if (*startdbl >= *enddbl && *incdbl < 0)
for (double i = *startdbl; i >= *enddbl; i += *incdbl) for (double i = *startdbl; i >= *enddbl; i += *incdbl)
arr.emplace_back(make_shared<Real>(i)); arr.emplace_back(make_shared<Real>(i));
// NOLINTEND(clang-analyzer-security.FloatLoopCounter)
return make_shared<Array>(arr, location); return make_shared<Array>(arr, location);
} }

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _EXPRESSIONS_HH #ifndef EXPRESSIONS_HH
#define _EXPRESSIONS_HH #define EXPRESSIONS_HH
#include "Environment.hh" #include "Environment.hh"
#include "ForwardDeclarationsAndEnums.hh" #include "ForwardDeclarationsAndEnums.hh"

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2019 Dynare Team * Copyright © 2019-2023 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef _FORWARDDECLARATIONSANDENUMS_HH #ifndef FORWARD_DECLARATIONS_AND_ENUMS_HH
#define _FORWARDDECLARATIONSANDENUMS_HH #define FORWARD_DECLARATIONS_AND_ENUMS_HH
#include <memory> #include <memory>