Add [[nodiscard]] attribute to various functions

Automatically detected using clang-tidy with modernize-use-nodiscard check.
master
Sébastien Villemot 2023-12-01 14:02:38 +01:00
parent 5332c12ab7
commit 7e6abc97c4
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
18 changed files with 482 additions and 442 deletions

View File

@ -528,7 +528,7 @@ protected:
const SymbolTable& symbol_table;
AbstractEstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable& symbol_table_arg);
virtual string blockName() const = 0;
[[nodiscard]] virtual string blockName() const = 0;
// Part of the check pass that is common to the three estimated_params{,_init,bounds} blocks
void commonCheckPass() const;
};
@ -541,7 +541,7 @@ private:
public:
EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable& symbol_table_arg, bool overwrite_arg);
string
[[nodiscard]] string
blockName() const override
{
return "estimated_params";
@ -559,7 +559,7 @@ private:
public:
EstimatedParamsInitStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable& symbol_table_arg, const bool use_calibration_arg);
string
[[nodiscard]] string
blockName() const override
{
return "estimated_params_init";
@ -574,7 +574,7 @@ class EstimatedParamsBoundsStatement : public AbstractEstimatedParamsStatement
public:
EstimatedParamsBoundsStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable& symbol_table_arg);
string
[[nodiscard]] string
blockName() const override
{
return "estimated_params_bounds";
@ -981,7 +981,7 @@ private:
const svar_identification_restrictions_t restrictions;
const bool upper_cholesky_present, lower_cholesky_present, constants_exclusion_present;
const SymbolTable& symbol_table;
int getMaxLag() const;
[[nodiscard]] int getMaxLag() const;
public:
SvarIdentificationStatement(svar_identification_restrictions_t restrictions_arg,
@ -1111,7 +1111,7 @@ protected:
void writeCommonOutput(ostream& output, const string& lhs_field) const;
void writeCommonOutputHelper(ostream& output, const string& field, const string& lhs_field) const;
void writePriorOutput(ostream& output, string& lhs_field, const string& name2) const;
bool is_structural_innovation(const SymbolType symb_type) const;
[[nodiscard]] bool is_structural_innovation(const SymbolType symb_type) const;
void writePriorIndex(ostream& output, const string& lhs_field) const;
void writeVarianceOption(ostream& output, const string& lhs_field) const;
void writeOutputHelper(ostream& output, const string& field, const string& lhs_field) const;
@ -1185,7 +1185,7 @@ protected:
void writeOptionsOutput(ostream& output, string& lhs_field, const string& name2) const;
void writeCommonOutput(ostream& output, const string& lhs_field) const;
void writeCommonOutputHelper(ostream& output, const string& field, const string& lhs_field) const;
bool is_structural_innovation(const SymbolType symb_type) const;
[[nodiscard]] bool is_structural_innovation(const SymbolType symb_type) const;
void writeOptionsIndex(ostream& output, const string& lhs_field) const;
void writeOutputHelper(ostream& output, const string& field, const string& lhs_field) const;
void writeJsonOptionsOutput(ostream& output) const;

View File

@ -39,7 +39,7 @@ private:
map<string, string> hooks;
public:
map<string, string>
[[nodiscard]] map<string, string>
get_hooks() const
{
return hooks;
@ -55,7 +55,7 @@ private:
map<string, vector<string>> paths;
public:
map<string, vector<string>>
[[nodiscard]] map<string, vector<string>>
get_paths() const
{
return paths;
@ -136,7 +136,7 @@ public:
//! Check Pass
void transformPass();
//! Get Path Info
vector<filesystem::path> getIncludePaths() const;
[[nodiscard]] vector<filesystem::path> getIncludePaths() const;
//! Write any hooks
void writeHooks(ostream& output) const;
//! Create options_.parallel structure, write options

View File

@ -111,7 +111,7 @@ protected:
vector<int> local_variables_vector;
//! Internal implementation of ParamUsedWithLeadLag()
bool ParamUsedWithLeadLagInternal() const;
[[nodiscard]] bool ParamUsedWithLeadLagInternal() const;
/* Writes the contents of “new_contents” to the file “filename”. However, if
the file already exists and would not be modified by this operation, then do
@ -166,7 +166,7 @@ public:
//! Gets a variable
/*! Same as AddVariable, except that it fails if the variable node has not
already been created */
VariableNode* getVariable(int symb_id, int lag = 0) const;
[[nodiscard]] VariableNode* getVariable(int symb_id, int lag = 0) const;
//! Adds "arg1+arg2" to model tree
expr_t AddPlus(expr_t iArg1, expr_t iArg2);
//! Adds "arg1-arg2" to model tree
@ -274,19 +274,19 @@ public:
expr_t AddSecondDerivExternalFunction(int top_level_symb_id, const vector<expr_t>& arguments,
int input_index1, int input_index2);
//! Checks if a given symbol is used somewhere in the data tree
bool isSymbolUsed(int symb_id) const;
[[nodiscard]] bool isSymbolUsed(int symb_id) const;
//! Checks if a given unary op is used somewhere in the data tree
bool isUnaryOpUsed(UnaryOpcode opcode) const;
[[nodiscard]] bool isUnaryOpUsed(UnaryOpcode opcode) const;
//! Checks if a given unary op is used somewhere in the data tree on an endogenous variable
bool isUnaryOpUsedOnType(SymbolType type, UnaryOpcode opcode) const;
[[nodiscard]] bool isUnaryOpUsedOnType(SymbolType type, UnaryOpcode opcode) const;
//! Checks if a given binary op is used somewhere in the data tree
bool isBinaryOpUsed(BinaryOpcode opcode) const;
[[nodiscard]] bool isBinaryOpUsed(BinaryOpcode opcode) const;
//! Checks if a given binary op is used somewhere in the data tree on an endogenous variable
bool isBinaryOpUsedOnType(SymbolType type, BinaryOpcode opcode) const;
[[nodiscard]] bool isBinaryOpUsedOnType(SymbolType type, BinaryOpcode opcode) const;
//! Returns the minimum lag (as a negative number) of the given symbol in the whole data tree (and
//! not only in the equations !!)
/*! Returns 0 if the symbol is not used */
int minLagForSymbol(int symb_id) const;
[[nodiscard]] int minLagForSymbol(int symb_id) const;
/* Writes definitions of C function helpers (getPowerDeriv(), sign()) as
inline functions */
void writeCHelpersDefinition(ostream& output) const;
@ -308,17 +308,17 @@ public:
};
// Returns the derivation ID, or throws an exception if the derivation ID does not exist
virtual int getDerivID(int symb_id, int lag) const noexcept(false);
[[nodiscard]] virtual int getDerivID(int symb_id, int lag) const noexcept(false);
// Get the type corresponding to a derivation ID
virtual SymbolType getTypeByDerivID(int deriv_id) const noexcept(false);
[[nodiscard]] virtual SymbolType getTypeByDerivID(int deriv_id) const noexcept(false);
// Get the lag corresponding to a derivation ID
virtual int getLagByDerivID(int deriv_id) const noexcept(false);
[[nodiscard]] virtual int getLagByDerivID(int deriv_id) const noexcept(false);
// Get the symbol ID corresponding to a derivation ID
virtual int getSymbIDByDerivID(int deriv_id) const noexcept(false);
[[nodiscard]] virtual int getSymbIDByDerivID(int deriv_id) const noexcept(false);
// Get the type-specific ID corresponding to a derivation ID
virtual int getTypeSpecificIDByDerivID(int deriv_id) const;
[[nodiscard]] virtual int getTypeSpecificIDByDerivID(int deriv_id) const;
// Get the symbol name corresponding to a derivation ID
string
[[nodiscard]] string
getNameByDerivID(int deriv_id) const
{
return symbol_table.getName(getSymbIDByDerivID(deriv_id));
@ -327,7 +327,7 @@ public:
/* Returns the column of the Jacobian associated to a derivation ID.
The sparse argument selects between the legacy representation and the
sparse representation. */
virtual int
[[nodiscard]] virtual int
getJacobianCol([[maybe_unused]] int deriv_id, [[maybe_unused]] bool sparse) const
{
throw UnknownDerivIDException();
@ -336,7 +336,7 @@ public:
/* Returns the number of columns of the Jacobian
The sparse argument selects between the legacy representation and the
sparse representation. */
virtual int
[[nodiscard]] virtual int
getJacobianColsNbr([[maybe_unused]] bool sparse) const
{
throw UnknownDerivIDException();
@ -347,7 +347,7 @@ public:
//! Returns bool indicating whether DataTree represents a Dynamic Model (returns true in
//! DynamicModel.hh)
virtual bool
[[nodiscard]] virtual bool
isDynamic() const
{
return false;
@ -359,7 +359,7 @@ public:
int id;
};
expr_t
[[nodiscard]] expr_t
getLocalVariable(int symb_id) const
{
auto it = local_variables_table.find(symb_id);

View File

@ -63,7 +63,7 @@ public:
//! Various functions to get info from equation tags
//! Get equation tags for a given equation
map<string, string>
[[nodiscard]] map<string, string>
getTagsByEqn(int eqn) const
{
if (auto it = eqn_tags.find(eqn); it != eqn_tags.end())
@ -72,19 +72,19 @@ public:
}
//! Get equations that have the given key
set<int> getEqnsByKey(const string& key) const;
[[nodiscard]] set<int> getEqnsByKey(const string& key) const;
//! Get equations that have the given key and value
set<int> getEqnsByTag(const string& key, const string& value) const;
[[nodiscard]] set<int> getEqnsByTag(const string& key, const string& value) const;
//! Get the first equation that has the given key and value
optional<int> getEqnByTag(const string& key, const string& value) const;
[[nodiscard]] optional<int> getEqnByTag(const string& key, const string& value) const;
// Get equations that have all the given keys and values (seen as a conjunction)
set<int> getEqnsByTags(const map<string, string>& tags_selected) const;
[[nodiscard]] set<int> getEqnsByTags(const map<string, string>& tags_selected) const;
//! Get the tag value given the equation number and key
optional<string>
[[nodiscard]] optional<string>
getTagValueByEqnAndKey(int eqn, const string& key) const
{
if (auto it = eqn_tags.find(eqn); it != eqn_tags.end())
@ -94,21 +94,21 @@ public:
}
//! Get the equations marked dynamic
set<int>
[[nodiscard]] set<int>
getDynamicEqns() const
{
return getEqnsByTag("dynamic", "");
}
//! Returns true if equation tag with key and value exists
bool
[[nodiscard]] bool
exists(const string& key, const string& value) const
{
return getEqnByTag(key, value).has_value();
}
//! Returns true if equation tag with key exists for a given equation
bool
[[nodiscard]] bool
exists(int eqn, const string& key) const
{
auto it = eqn_tags.find(eqn);

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2010-2022 Dynare Team
* Copyright © 2010-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -66,13 +66,13 @@ public:
const external_function_options& external_function_options_arg,
bool track_nargs);
//! See if the function exists in the External Functions Table
inline bool exists(int symb_id) const;
[[nodiscard]] inline bool exists(int symb_id) const;
//! Get the number of arguments for a given external function
inline int getNargs(int symb_id) const noexcept(false);
[[nodiscard]] inline int getNargs(int symb_id) const noexcept(false);
//! Get the symbol_id of the first derivative function
inline int getFirstDerivSymbID(int symb_id) const noexcept(false);
[[nodiscard]] inline int getFirstDerivSymbID(int symb_id) const noexcept(false);
//! Get the symbol_id of the second derivative function
inline int getSecondDerivSymbID(int symb_id) const noexcept(false);
[[nodiscard]] inline int getSecondDerivSymbID(int symb_id) const noexcept(false);
};
inline bool

View File

@ -204,7 +204,7 @@ protected:
max_endo_lead {
0}; // Maximum lag/lead on endos that appear in and *that belong to* the block
int
[[nodiscard]] int
getRecursiveSize() const
{
return size - mfs_size;

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2003-2022 Dynare Team
* Copyright © 2003-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -41,9 +41,9 @@ public:
//! Adds a non-negative constant (possibly Inf or NaN) and returns its ID
int AddNonNegativeConstant(const string& iConst);
//! Get a constant in string form
string get(int ID) const;
[[nodiscard]] string get(int ID) const;
//! Get a constant in double form
double getDouble(int ID) const;
[[nodiscard]] double getDouble(int ID) const;
};
#endif

View File

@ -856,7 +856,7 @@ public:
//! Adds an external function argument
void add_external_function_arg(expr_t arg);
//! Test to see if model/external function has exactly one integer argument
optional<int> is_there_one_integer_argument() const;
[[nodiscard]] optional<int> is_there_one_integer_argument() const;
//! Adds an external function call node
expr_t add_model_var_or_external_function(const string& function_name, bool in_model_block);
//! Adds a native statement

View File

@ -72,7 +72,7 @@ private:
void writeCovarOrCorrShock(ostream& output, const pair<pair<int, int>, expr_t>& it,
bool corr) const;
void writeCovarAndCorrShocks(ostream& output) const;
bool has_calibrated_measurement_errors() const;
[[nodiscard]] bool has_calibrated_measurement_errors() const;
public:
ShocksStatement(bool overwrite_arg, det_shocks_t det_shocks_arg,

View File

@ -254,10 +254,10 @@ public:
{
};
bool empty() const;
[[nodiscard]] bool empty() const;
void clear();
// Whether there is an option with that name that has been given a value
bool contains(const string& name) const;
[[nodiscard]] bool contains(const string& name) const;
// Erase the option with that name
void erase(const string& name);

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2018-2022 Dynare Team
* Copyright © 2018-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -64,25 +64,25 @@ public:
void addTrendComponentModel(string name_arg, vector<string> eqtags_arg,
vector<string> target_eqtags_arg);
inline bool isExistingTrendComponentModelName(const string& name_arg) const;
inline bool empty() const;
[[nodiscard]] inline bool isExistingTrendComponentModelName(const string& name_arg) const;
[[nodiscard]] inline bool empty() const;
const map<string, vector<string>>& getEqTags() const;
const vector<string>& getEqTags(const string& name_arg) const;
const map<string, vector<string>>& getTargetEqTags() const;
const map<string, vector<int>>& getEqNums() const;
const map<string, vector<int>>& getTargetEqNums() const;
const vector<int>& getTargetEqNums(const string& name_arg) const;
const vector<int>& getEqNums(const string& name_arg) const;
const vector<int>& getMaxLags(const string& name_arg) const;
int getMaxLag(const string& name_arg) const;
const vector<int>& getLhs(const string& name_arg) const;
const vector<expr_t>& getLhsExprT(const string& name_arg) const;
const vector<bool>& getDiff(const string& name_arg) const;
const map<string, vector<int>>& getNonTargetEqNums() const;
const vector<int>& getNonTargetEqNums(const string& name_arg) const;
const vector<int>& getNonTargetLhs(const string& name_arg) const;
const vector<int>& getTargetLhs(const string& name_arg) const;
[[nodiscard]] const map<string, vector<string>>& getEqTags() const;
[[nodiscard]] const vector<string>& getEqTags(const string& name_arg) const;
[[nodiscard]] const map<string, vector<string>>& getTargetEqTags() const;
[[nodiscard]] const map<string, vector<int>>& getEqNums() const;
[[nodiscard]] const map<string, vector<int>>& getTargetEqNums() const;
[[nodiscard]] const vector<int>& getTargetEqNums(const string& name_arg) const;
[[nodiscard]] const vector<int>& getEqNums(const string& name_arg) const;
[[nodiscard]] const vector<int>& getMaxLags(const string& name_arg) const;
[[nodiscard]] int getMaxLag(const string& name_arg) const;
[[nodiscard]] const vector<int>& getLhs(const string& name_arg) const;
[[nodiscard]] const vector<expr_t>& getLhsExprT(const string& name_arg) const;
[[nodiscard]] const vector<bool>& getDiff(const string& name_arg) const;
[[nodiscard]] const map<string, vector<int>>& getNonTargetEqNums() const;
[[nodiscard]] const vector<int>& getNonTargetEqNums(const string& name_arg) const;
[[nodiscard]] const vector<int>& getNonTargetLhs(const string& name_arg) const;
[[nodiscard]] const vector<int>& getTargetLhs(const string& name_arg) const;
void setVals(map<string, vector<int>> eqnums_arg, map<string, vector<int>> target_eqnums_arg,
map<string, vector<int>> lhs_arg, map<string, vector<expr_t>> lhs_expr_t_arg);
@ -145,21 +145,21 @@ public:
//! Add a VAR model
void addVarModel(string name, bool structural_arg, vector<string> eqtags);
inline bool isExistingVarModelName(const string& name_arg) const;
inline bool empty() const;
[[nodiscard]] inline bool isExistingVarModelName(const string& name_arg) const;
[[nodiscard]] inline bool empty() const;
const map<string, bool>& getStructural() const;
const map<string, vector<string>>& getEqTags() const;
const vector<string>& getEqTags(const string& name_arg) const;
const map<string, vector<int>>& getEqNums() const;
const vector<bool>& getDiff(const string& name_arg) const;
const vector<int>& getEqNums(const string& name_arg) const;
const vector<int>& getMaxLags(const string& name_arg) const;
int getMaxLag(const string& name_arg) const;
const vector<int>& getLhs(const string& name_arg) const;
const vector<int>& getLhsOrigIds(const string& name_arg) const;
const vector<set<pair<int, int>>>& getRhs(const string& name_arg) const;
const vector<expr_t>& getLhsExprT(const string& name_arg) const;
[[nodiscard]] const map<string, bool>& getStructural() const;
[[nodiscard]] const map<string, vector<string>>& getEqTags() const;
[[nodiscard]] const vector<string>& getEqTags(const string& name_arg) const;
[[nodiscard]] const map<string, vector<int>>& getEqNums() const;
[[nodiscard]] const vector<bool>& getDiff(const string& name_arg) const;
[[nodiscard]] const vector<int>& getEqNums(const string& name_arg) const;
[[nodiscard]] const vector<int>& getMaxLags(const string& name_arg) const;
[[nodiscard]] int getMaxLag(const string& name_arg) const;
[[nodiscard]] const vector<int>& getLhs(const string& name_arg) const;
[[nodiscard]] const vector<int>& getLhsOrigIds(const string& name_arg) const;
[[nodiscard]] const vector<set<pair<int, int>>>& getRhs(const string& name_arg) const;
[[nodiscard]] const vector<expr_t>& getLhsExprT(const string& name_arg) const;
void setEqNums(map<string, vector<int>> eqnums_arg);
void setLhs(map<string, vector<int>> lhs_arg);
@ -213,8 +213,8 @@ public:
explicit VarExpectationModelTable(SymbolTable& symbol_table_arg);
void addVarExpectationModel(string name_arg, expr_t expression_arg, string aux_model_name_arg,
string horizon_arg, expr_t discount_arg, int time_shift_arg);
bool isExistingVarExpectationModelName(const string& name_arg) const;
bool empty() const;
[[nodiscard]] bool isExistingVarExpectationModelName(const string& name_arg) const;
[[nodiscard]] bool empty() const;
void substituteUnaryOpsInExpression(const lag_equivalence_table_t& nodes,
ExprNode::subst_table_t& subst_table,
vector<BinaryOpNode*>& neweqs);
@ -313,7 +313,7 @@ private:
// pac_model_name → (target variable/expr, auxname_target_nonstationary, target components)
map<string, tuple<expr_t, string, vector<target_component_t>>> target_info;
int pacEquationMaxLag(const string& name_arg) const;
[[nodiscard]] int pacEquationMaxLag(const string& name_arg) const;
// Return a text representation of a kind (but fails on “unspecified” kind value)
static string kindToString(PacTargetKind kind);
@ -322,8 +322,8 @@ public:
explicit PacModelTable(SymbolTable& symbol_table_arg);
void addPacModel(string name_arg, string aux_model_name_arg, string discount_arg,
expr_t growth_arg, string auxname_arg, PacTargetKind kind_arg);
bool isExistingPacModelName(const string& name_arg) const;
bool empty() const;
[[nodiscard]] bool isExistingPacModelName(const string& name_arg) const;
[[nodiscard]] bool empty() const;
void checkPass(ModFileStructure& mod_file_struct);
// Called by DynamicModel::substituteUnaryOps()
void substituteUnaryOpsInGrowth(const lag_equivalence_table_t& nodes,

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2003-2022 Dynare Team
* Copyright © 2003-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -59,13 +59,13 @@ public:
//! Write JSON output
void writeJsonOutput(ostream& output) const;
//! Is Empty
bool
[[nodiscard]] bool
empty() const
{
return symbols.empty();
};
//! Return the list of symbols
vector<string> getSymbols() const;
[[nodiscard]] vector<string> getSymbols() const;
};
#endif

View File

@ -84,7 +84,7 @@ struct AuxVarInfo
const expr_t expr_node; // Auxiliary variable definition
const string unary_op; // Used with AuxUnaryOp
int
[[nodiscard]] int
get_type_id() const
{
return static_cast<int>(type);
@ -278,14 +278,14 @@ public:
\return the symbol ID of the auxiliary variable
Throws an exception if match not found.
*/
int searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const noexcept(false);
[[nodiscard]] int searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const noexcept(false);
/* Searches aux_vars for the aux var represented by aux_var_symb_id and
returns its associated orig_symb_id.
Throws an UnknownSymbolIDException if there is no orig_symb_id associated to
this auxvar (either because its of the wrong type, or because there is
no such orig var for this specific auxvar, in case of complex expressions
in diff or unaryOp). */
int getOrigSymbIdForAuxVar(int aux_var_symb_id_arg) const noexcept(false);
[[nodiscard]] int getOrigSymbIdForAuxVar(int aux_var_symb_id_arg) const noexcept(false);
/* Unrolls a chain of diffLag or diffLead aux vars until it founds a (regular) diff aux
var. In other words:
- if the arg is a (regu) diff aux var, returns the arg
@ -297,7 +297,7 @@ public:
output argument is equal to the 2nd input argument, shifted by as many
lead/lags were encountered in the chain (a diffLag decreases it, a
diffLead increases it). */
pair<int, int> unrollDiffLeadLagChain(int symb_id, int lag) const noexcept(false);
[[nodiscard]] pair<int, int> unrollDiffLeadLagChain(int symb_id, int lag) const noexcept(false);
//! Adds an auxiliary variable when the diff operator is encountered
int addDiffAuxiliaryVar(int index, expr_t expr_arg, optional<int> orig_symb_id = nullopt,
optional<int> orig_lag = nullopt) noexcept(false);
@ -316,32 +316,33 @@ public:
//! An auxiliary variable for a pac_target_nonstationary operator
int addPacTargetNonstationaryAuxiliaryVar(const string& name, expr_t expr_arg);
//! Returns the number of auxiliary variables
int
[[nodiscard]] int
AuxVarsSize() const
{
return aux_vars.size();
};
//! Tests if symbol already exists
inline bool exists(const string& name) const;
[[nodiscard]] inline bool exists(const string& name) const;
//! Get symbol name (by ID)
inline string getName(int id) const noexcept(false);
[[nodiscard]] inline string getName(int id) const noexcept(false);
//! Get TeX name
inline string getTeXName(int id) const noexcept(false);
[[nodiscard]] inline string getTeXName(int id) const noexcept(false);
//! Get long name
inline string getLongName(int id) const noexcept(false);
[[nodiscard]] inline string getLongName(int id) const noexcept(false);
//! Returns true if the partition name is the first encountered for the type of variable
//! represented by id
bool isFirstOfPartitionForType(int id) const noexcept(false);
[[nodiscard]] bool isFirstOfPartitionForType(int id) const noexcept(false);
//! Returns a list of partitions and symbols that belong to that partition
map<string, map<int, string>> getPartitionsForType(SymbolType st) const noexcept(false);
[[nodiscard]] map<string, map<int, string>> getPartitionsForType(SymbolType st) const
noexcept(false);
//! Get type (by ID)
inline SymbolType getType(int id) const noexcept(false);
[[nodiscard]] inline SymbolType getType(int id) const noexcept(false);
//! Get type (by name)
inline SymbolType getType(const string& name) const noexcept(false);
[[nodiscard]] inline SymbolType getType(const string& name) const noexcept(false);
//! Get ID (by name)
inline int getID(const string& name) const noexcept(false);
[[nodiscard]] inline int getID(const string& name) const noexcept(false);
//! Get ID (by type specific ID)
int getID(SymbolType type, int tsid) const noexcept(false);
[[nodiscard]] int getID(SymbolType type, int tsid) const noexcept(false);
//! Freeze symbol table
void freeze() noexcept(false);
//! unreeze symbol table
@ -350,21 +351,21 @@ public:
//! Change the type of a symbol
void changeType(int id, SymbolType newtype) noexcept(false);
//! Get type specific ID (by symbol ID)
inline int getTypeSpecificID(int id) const noexcept(false);
[[nodiscard]] inline int getTypeSpecificID(int id) const noexcept(false);
//! Get type specific ID (by symbol name)
inline int getTypeSpecificID(const string& name) const noexcept(false);
[[nodiscard]] inline int getTypeSpecificID(const string& name) const noexcept(false);
//! Get number of endogenous variables
inline int endo_nbr() const noexcept(false);
[[nodiscard]] inline int endo_nbr() const noexcept(false);
//! Get number of exogenous variables
inline int exo_nbr() const noexcept(false);
[[nodiscard]] inline int exo_nbr() const noexcept(false);
//! Get number of exogenous deterministic variables
inline int exo_det_nbr() const noexcept(false);
[[nodiscard]] inline int exo_det_nbr() const noexcept(false);
//! Get number of parameters
inline int param_nbr() const noexcept(false);
[[nodiscard]] inline int param_nbr() const noexcept(false);
//! Returns the greatest symbol ID (the smallest is zero)
inline int maxID();
//! Get number of user-declared endogenous variables (without the auxiliary variables)
inline int orig_endo_nbr() const noexcept(false);
[[nodiscard]] inline int orig_endo_nbr() const noexcept(false);
//! Write output of this class
void writeOutput(ostream& output) const noexcept(false);
//! Write JSON Output
@ -374,56 +375,56 @@ public:
//! Mark an endogenous as having been declared with “var(log)”
void markWithLogTransform(int symb_id) noexcept(false);
//! Test if a given symbol is a predetermined variable
bool isPredetermined(int symb_id) const noexcept(false);
[[nodiscard]] bool isPredetermined(int symb_id) const noexcept(false);
//! Return the number of predetermined variables
int predeterminedNbr() const;
[[nodiscard]] int predeterminedNbr() const;
//! Add an observed variable
void addObservedVariable(int symb_id) noexcept(false);
//! Return the number of observed variables
int observedVariablesNbr() const;
[[nodiscard]] int observedVariablesNbr() const;
//! Is a given symbol in the set of observed variables
bool isObservedVariable(int symb_id) const;
[[nodiscard]] bool isObservedVariable(int symb_id) const;
//! Return the index of a given observed variable in the vector of all observed variables
int getObservedVariableIndex(int symb_id) const;
[[nodiscard]] int getObservedVariableIndex(int symb_id) const;
//! Add an observed exogenous variable
void addObservedExogenousVariable(int symb_id) noexcept(false);
//! Return the number of observed exogenous variables
int observedExogenousVariablesNbr() const;
[[nodiscard]] int observedExogenousVariablesNbr() const;
//! Is a given symbol in the set of observed exogenous variables
bool isObservedExogenousVariable(int symb_id) const;
[[nodiscard]] bool isObservedExogenousVariable(int symb_id) const;
//! Return the index of a given observed exogenous variable in the vector of all observed
//! variables
int getObservedExogenousVariableIndex(int symb_id) const;
vector<int> getTrendVarIds() const;
[[nodiscard]] int getObservedExogenousVariableIndex(int symb_id) const;
[[nodiscard]] vector<int> getTrendVarIds() const;
//! Get list of exogenous variables
set<int> getExogenous() const;
[[nodiscard]] set<int> getExogenous() const;
//! Get list of exogenous variables
set<int> getObservedExogenous() const;
[[nodiscard]] set<int> getObservedExogenous() const;
//! Get list of endogenous variables
set<int> getEndogenous() const;
[[nodiscard]] set<int> getEndogenous() const;
//! Is a given symbol an auxiliary variable
bool isAuxiliaryVariable(int symb_id) const;
[[nodiscard]] bool isAuxiliaryVariable(int symb_id) const;
//! Is a given symbol a diff, diff lead, or diff lag auxiliary variable
bool isDiffAuxiliaryVariable(int symb_id) const;
[[nodiscard]] bool isDiffAuxiliaryVariable(int symb_id) const;
//! Get list of endogenous variables without aux vars
set<int> getOrigEndogenous() const;
[[nodiscard]] set<int> getOrigEndogenous() const;
//! Returns the original symbol corresponding to this variable
/* If symb_id has no original variable, returns symb_id. Otherwise,
repeatedly call getOrigSymbIDForAuxVar() until an original variable is
found. Note that the result may be an auxiliary variable if the latter has
no original variable (e.g. aux var for lead, Lagrange Multiplier or diff
associated to a complex expression). */
int getUltimateOrigSymbID(int symb_id) const;
[[nodiscard]] int getUltimateOrigSymbID(int symb_id) const;
//! If this is a Lagrange multiplier, return its associated equation number; otherwise return
//! nullopt
optional<int> getEquationNumberForMultiplier(int symb_id) const;
[[nodiscard]] optional<int> getEquationNumberForMultiplier(int symb_id) const;
/* Return all the information about a given auxiliary variable. Throws
UnknownSymbolIDException if it is not an aux var */
const AuxVarInfo& getAuxVarInfo(int symb_id) const;
[[nodiscard]] const AuxVarInfo& getAuxVarInfo(int symb_id) const;
// Returns the set of all endogenous declared with “var(log)”
const set<int>& getVariablesWithLogTransform() const;
[[nodiscard]] const set<int>& getVariablesWithLogTransform() const;
// Returns all Lagrange multipliers
set<int> getLagrangeMultipliers() const;
[[nodiscard]] set<int> getLagrangeMultipliers() const;
};
inline void

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2009-2020 Dynare Team
* Copyright © 2009-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -59,18 +59,18 @@ public:
The property vertex_index1 of the subgraph contains indices of the original
graph.
*/
VariableDependencyGraph extractSubgraph(const vector<int>& select_index) const;
[[nodiscard]] VariableDependencyGraph extractSubgraph(const vector<int>& select_index) const;
//! Return the feedback set
set<int> minimalSetOfFeedbackVertices() const;
[[nodiscard]] set<int> minimalSetOfFeedbackVertices() const;
//! Reorder the recursive variables
/*! They appear first in a quasi triangular form and they are followed by the feedback variables
*/
vector<int> reorderRecursiveVariables(const set<int>& feedback_vertices) const;
[[nodiscard]] vector<int> reorderRecursiveVariables(const set<int>& feedback_vertices) const;
/* Computes the strongly connected components (SCCs) of the graph, and sort them
topologically.
Returns the number of SCCs, and a mapping of vertex indices to sorted SCC
indices. */
pair<int, vector<int>> sortedStronglyConnectedComponents() const;
[[nodiscard]] pair<int, vector<int>> sortedStronglyConnectedComponents() const;
// Print on stdout a description of the graph
void print() const;
@ -86,7 +86,7 @@ private:
// Internal helper for hasCycle()
bool hasCycleDFS(vertex_descriptor u, color_t& color, vector<int>& circuit_stack) const;
// Determine whether the graph has a cycle
bool hasCycle() const;
[[nodiscard]] bool hasCycle() const;
bool vertexBelongsToAClique(vertex_descriptor vertex) const;
bool eliminationOfVerticesWithOneOrLessIndegreeOrOutdegree();
bool eliminationOfVerticesBelongingToAClique();

View File

@ -92,7 +92,7 @@ public:
//! Error handler
void error(const Tokenizer::parser::location_type& location, const string& message) const;
bool
[[nodiscard]] bool
inContext() const
{
return !directive_stack.empty();

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2019-2022 Dynare Team
* Copyright © 2019-2023 Dynare Team
*
* This file is part of Dynare.
*
@ -42,12 +42,15 @@ public:
}
void define(VariablePtr var, ExpressionPtr value);
void define(FunctionPtr func, ExpressionPtr value);
ExpressionPtr getVariable(const string& name) const;
tuple<FunctionPtr, ExpressionPtr> getFunction(const string& name) const;
codes::BaseType getType(const string& name) const;
bool isVariableDefined(const string& name) const noexcept;
bool isFunctionDefined(const string& name) const noexcept;
bool
/* The following two functions are not marked [[nodiscard]], because they are used without output
to check whether they return an exception or not. */
ExpressionPtr getVariable(const string& name) const; // NOLINT(modernize-use-nodiscard)
tuple<FunctionPtr, ExpressionPtr> // NOLINT(modernize-use-nodiscard)
getFunction(const string& name) const;
[[nodiscard]] codes::BaseType getType(const string& name) const;
[[nodiscard]] bool isVariableDefined(const string& name) const noexcept;
[[nodiscard]] bool isFunctionDefined(const string& name) const noexcept;
[[nodiscard]] bool
isSymbolDefined(const string& name) const noexcept
{
return isVariableDefined(name) || isFunctionDefined(name);
@ -58,12 +61,12 @@ public:
bool save) const;
void printFunction(ostream& output, const tuple<FunctionPtr, ExpressionPtr>& function,
const optional<int>& line, bool save) const;
size_t
[[nodiscard]] size_t
size() const noexcept
{
return variables.size() + functions.size();
}
const Environment*
[[nodiscard]] const Environment*
getGlobalEnv() const noexcept
{
return parent == nullptr ? this : parent->getGlobalEnv();

View File

@ -72,7 +72,7 @@ public:
ss << "-" << end_col;
message.emplace_back(ss.str());
}
string
[[nodiscard]] string
trace() const
{
stringstream ss;
@ -94,7 +94,7 @@ public:
virtual ~Node() = default;
public:
Tokenizer::location
[[nodiscard]] Tokenizer::location
getLocation() const noexcept
{
return location;
@ -131,7 +131,7 @@ public:
explicit Expression(Tokenizer::location location_arg) : Node(move(location_arg))
{
}
virtual string to_string() const noexcept = 0;
[[nodiscard]] virtual string to_string() const noexcept = 0;
virtual void print(ostream& output, bool matlab_output = false) const noexcept = 0;
virtual BaseTypePtr eval(Environment& env) const = 0;
};
@ -1063,7 +1063,7 @@ public:
Expression(move(location_arg)), name {move(name_arg)}, indices {move(indices_arg)}
{
}
string
[[nodiscard]] string
to_string() const noexcept override
{
return name;
@ -1076,12 +1076,12 @@ public:
BaseTypePtr eval(Environment& env) const override;
public:
const string&
[[nodiscard]] const string&
getName() const noexcept
{
return name;
}
codes::BaseType
[[nodiscard]] codes::BaseType
getType(const Environment& env) const
{
return env.getType(name);
@ -1099,7 +1099,7 @@ public:
Expression(move(location_arg)), name {move(name_arg)}, args {move(args_arg)}
{
}
string to_string() const noexcept override;
[[nodiscard]] string to_string() const noexcept override;
void
print(ostream& output, [[maybe_unused]] bool matlab_output = false) const noexcept override
{
@ -1115,12 +1115,12 @@ public:
output << name;
}
void printArgs(ostream& output) const noexcept;
const string&
[[nodiscard]] const string&
getName() const
{
return name;
}
const vector<ExpressionPtr>&
[[nodiscard]] const vector<ExpressionPtr>&
getArgs() const
{
return args;
@ -1138,7 +1138,7 @@ public:
Expression(move(location_arg)), op_code {move(op_code_arg)}, arg {move(arg_arg)}
{
}
string to_string() const noexcept override;
[[nodiscard]] string to_string() const noexcept override;
void print(ostream& output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment& env) const override;
};
@ -1160,7 +1160,7 @@ public:
}
public:
string to_string() const noexcept override;
[[nodiscard]] string to_string() const noexcept override;
void print(ostream& output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment& env) const override;
};
@ -1181,7 +1181,7 @@ public:
arg3 {move(arg3_arg)}
{
}
string to_string() const noexcept override;
[[nodiscard]] string to_string() const noexcept override;
void print(ostream& output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment& env) const override;
};
@ -1223,7 +1223,7 @@ public:
c_when {move(c_when_arg)}
{
}
string to_string() const noexcept override;
[[nodiscard]] string to_string() const noexcept override;
void print(ostream& output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment& env) const override;
};