From 7e6abc97c4ced786a09509531603ffdda855e8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 1 Dec 2023 14:02:38 +0100 Subject: [PATCH] Add [[nodiscard]] attribute to various functions Automatically detected using clang-tidy with modernize-use-nodiscard check. --- src/ComputingTasks.hh | 14 +- src/ConfigFile.hh | 6 +- src/DataTree.hh | 36 +- src/EquationTags.hh | 18 +- src/ExprNode.hh | 596 +++++++++++++++++---------------- src/ExternalFunctionsTable.hh | 10 +- src/ModelTree.hh | 2 +- src/NumericalConstants.hh | 6 +- src/ParsingDriver.hh | 2 +- src/Shocks.hh | 2 +- src/Statement.hh | 4 +- src/SubModel.hh | 76 ++--- src/SymbolList.hh | 6 +- src/SymbolTable.hh | 85 ++--- src/VariableDependencyGraph.hh | 12 +- src/macro/Driver.hh | 2 +- src/macro/Environment.hh | 21 +- src/macro/Expressions.hh | 26 +- 18 files changed, 482 insertions(+), 442 deletions(-) diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index acd551eb..15378110 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -528,7 +528,7 @@ protected: const SymbolTable& symbol_table; AbstractEstimatedParamsStatement(vector 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 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 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 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; diff --git a/src/ConfigFile.hh b/src/ConfigFile.hh index fe583893..0ec61cf6 100644 --- a/src/ConfigFile.hh +++ b/src/ConfigFile.hh @@ -39,7 +39,7 @@ private: map hooks; public: - map + [[nodiscard]] map get_hooks() const { return hooks; @@ -55,7 +55,7 @@ private: map> paths; public: - map> + [[nodiscard]] map> get_paths() const { return paths; @@ -136,7 +136,7 @@ public: //! Check Pass void transformPass(); //! Get Path Info - vector getIncludePaths() const; + [[nodiscard]] vector getIncludePaths() const; //! Write any hooks void writeHooks(ostream& output) const; //! Create options_.parallel structure, write options diff --git a/src/DataTree.hh b/src/DataTree.hh index 56bec998..b6cb39ff 100644 --- a/src/DataTree.hh +++ b/src/DataTree.hh @@ -111,7 +111,7 @@ protected: vector 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& 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); diff --git a/src/EquationTags.hh b/src/EquationTags.hh index 7025146c..b5c7047d 100644 --- a/src/EquationTags.hh +++ b/src/EquationTags.hh @@ -63,7 +63,7 @@ public: //! Various functions to get info from equation tags //! Get equation tags for a given equation - map + [[nodiscard]] map 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 getEqnsByKey(const string& key) const; + [[nodiscard]] set getEqnsByKey(const string& key) const; //! Get equations that have the given key and value - set getEqnsByTag(const string& key, const string& value) const; + [[nodiscard]] set getEqnsByTag(const string& key, const string& value) const; //! Get the first equation that has the given key and value - optional getEqnByTag(const string& key, const string& value) const; + [[nodiscard]] optional getEqnByTag(const string& key, const string& value) const; // Get equations that have all the given keys and values (seen as a conjunction) - set getEqnsByTags(const map& tags_selected) const; + [[nodiscard]] set getEqnsByTags(const map& tags_selected) const; //! Get the tag value given the equation number and key - optional + [[nodiscard]] optional 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 + [[nodiscard]] set 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); diff --git a/src/ExprNode.hh b/src/ExprNode.hh index b7c860ba..5a8d7516 100644 --- a/src/ExprNode.hh +++ b/src/ExprNode.hh @@ -300,11 +300,11 @@ protected: //! Cost of computing current node /*! Nodes included in temporary_terms are considered having a null cost */ - virtual int cost(int cost, bool is_matlab) const; - virtual int cost(const vector>>& blocks_temporary_terms, - bool is_matlab) const; - virtual int cost(const map, unordered_set>& temp_terms_map, - bool is_matlab) const; + [[nodiscard]] virtual int cost(int cost, bool is_matlab) const; + [[nodiscard]] virtual int + cost(const vector>>& blocks_temporary_terms, bool is_matlab) const; + [[nodiscard]] virtual int cost(const map, unordered_set>& temp_terms_map, + bool is_matlab) const; //! For creating equation cross references struct EquationInfo @@ -333,7 +333,7 @@ protected: /* Computes the representative element and the index under the lag-equivalence relationship. See the comment above lag_equivalence_table_t for an explanation of these concepts. */ - pair getLagEquivalenceClass() const; + [[nodiscard]] pair getLagEquivalenceClass() const; /* Computes the set of all sub-expressions that contain the variable (symb_id, lag). @@ -381,8 +381,8 @@ public: //! Returns precedence of node /*! Equals 100 for constants, variables, unary ops, and temporary terms */ - virtual int precedence(ExprNodeOutputType output_t, - const temporary_terms_t& temporary_terms) const; + [[nodiscard]] virtual int precedence(ExprNodeOutputType output_t, + const temporary_terms_t& temporary_terms) const; //! Compute temporary terms in this expression /*! @@ -446,7 +446,7 @@ public: = 0; //! returns true if the expr node contains an external function - virtual bool containsExternalFunction() const = 0; + [[nodiscard]] virtual bool containsExternalFunction() const = 0; //! Writes output of node (with no temporary terms and with "outside model" output type) void writeOutput(ostream& output) const; @@ -466,12 +466,12 @@ public: = 0; // Returns a string representation of the expression, used by the GDB pretty printer - string toString() const; + [[nodiscard]] string toString() const; //! Writes the Abstract Syntax Tree in JSON virtual void writeJsonAST(ostream& output) const = 0; - virtual int precedenceJson(const temporary_terms_t& temporary_terms) const; + [[nodiscard]] virtual int precedenceJson(const temporary_terms_t& temporary_terms) const; //! Writes the output for an external function, ensuring that the external function is called as //! few times as possible using temporary terms @@ -503,7 +503,7 @@ public: virtual void collectDynamicVariables(SymbolType type_arg, set>& result) const = 0; //! Find the maximum lag in a VAR: handles case where LHS is diff - virtual int VarMaxLag(const set& lhs_lag_equiv) const = 0; + [[nodiscard]] virtual int VarMaxLag(const set& lhs_lag_equiv) const = 0; //! Finds LHS variable in a VAR equation virtual void collectVARLHSVariable(set& result) const = 0; @@ -534,7 +534,7 @@ public: { }; - virtual double eval(const eval_context_t& eval_context) const noexcept(false) = 0; + [[nodiscard]] virtual double eval(const eval_context_t& eval_context) const noexcept(false) = 0; // Write output to bytecode file virtual void writeBytecodeOutput(BytecodeWriter& code_file, @@ -573,39 +573,39 @@ public: //! Returns the maximum lead of endogenous in this expression /*! Always returns a non-negative value */ - virtual int maxEndoLead() const = 0; + [[nodiscard]] virtual int maxEndoLead() const = 0; //! Returns the maximum lead of exogenous in this expression /*! Always returns a non-negative value */ - virtual int maxExoLead() const = 0; + [[nodiscard]] virtual int maxExoLead() const = 0; //! Returns the maximum lag of endogenous in this expression /*! Always returns a non-negative value */ - virtual int maxEndoLag() const = 0; + [[nodiscard]] virtual int maxEndoLag() const = 0; //! Returns the maximum lag of exogenous in this expression /*! Always returns a non-negative value */ - virtual int maxExoLag() const = 0; + [[nodiscard]] virtual int maxExoLag() const = 0; //! Returns the maximum lead of endo/exo/exodet in this expression /*! A negative value means that the expression contains only lagged variables. A value of numeric_limits::min() means that there is no variable. */ - virtual int maxLead() const = 0; + [[nodiscard]] virtual int maxLead() const = 0; //! Returns the maximum lag of endo/exo/exodet in this expression /*! A negative value means that the expression contains only leaded variables. A value of numeric_limits::min() means that there is no variable. */ - virtual int maxLag() const = 0; + [[nodiscard]] virtual int maxLag() const = 0; //! Returns the maximum lag of endo/exo/exodet, as if diffs were expanded /*! This function behaves as maxLag(), except that it treats diff() differently. For e.g., on diff(diff(x(-1))), maxLag() returns 1 while maxLagWithDiffsExpanded() returns 3. */ - virtual int maxLagWithDiffsExpanded() const = 0; + [[nodiscard]] virtual int maxLagWithDiffsExpanded() const = 0; - virtual expr_t undiff() const = 0; + [[nodiscard]] virtual expr_t undiff() const = 0; //! Returns a new expression where all the leads/lags have been shifted backwards by the same //! amount @@ -614,7 +614,7 @@ public: \param[in] n The number of lags by which to shift \return The same expression except that leads/lags have been shifted backwards */ - virtual expr_t decreaseLeadsLags(int n) const = 0; + [[nodiscard]] virtual expr_t decreaseLeadsLags(int n) const = 0; //! Type for the substitution map used in the process of creating auxiliary vars using subst_table_t = map; @@ -715,7 +715,7 @@ public: bool partial_information_model) const = 0; - virtual expr_t decreaseLeadsLagsPredeterminedVariables() const = 0; + [[nodiscard]] virtual expr_t decreaseLeadsLagsPredeterminedVariables() const = 0; //! Constructs a new expression where forward variables (supposed to be at most in t+1) have been //! replaced by themselves at t, plus a new aux var representing their (time) differentiate @@ -736,10 +736,10 @@ public: \param[in] value of the numerical constante \param[out] the boolean equal to true if NodeId is a constant equal to value */ - virtual bool isNumConstNodeEqualTo(double value) const = 0; + [[nodiscard]] virtual bool isNumConstNodeEqualTo(double value) const = 0; //! Returns the maximum number of nested diffs in the expression - virtual int countDiffs() const = 0; + [[nodiscard]] virtual int countDiffs() const = 0; //! Return true if the nodeID is a variable withe a type equal to type_arg, a specific variable id //! aqual to varfiable_id and a lag equal to lag_arg and false otherwise @@ -747,10 +747,12 @@ public: \param[in] the type (type_arg), specifique variable id (variable_id and the lag (lag_arg) \param[out] the boolean equal to true if NodeId is the variable */ - virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const = 0; + [[nodiscard]] virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const + = 0; //! Replaces the Trend var with datatree.One - virtual expr_t replaceTrendVar() const = 0; + [[nodiscard]] virtual expr_t replaceTrendVar() const = 0; //! Constructs a new expression where the variable indicated by symb_id has been detrended /*! @@ -762,13 +764,15 @@ public: virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const = 0; //! Substitute adl operator - virtual expr_t substituteAdl() const = 0; + [[nodiscard]] virtual expr_t substituteAdl() const = 0; //! Substitute out model-local variables - virtual expr_t substituteModelLocalVariables() const = 0; + [[nodiscard]] virtual expr_t substituteModelLocalVariables() const = 0; //! Substitute VarExpectation nodes - virtual expr_t substituteVarExpectation(const map& subst_table) const = 0; + [[nodiscard]] virtual expr_t + substituteVarExpectation(const map& subst_table) const + = 0; //! Mark diff nodes to be substituted /*! The various nodes that are equivalent up to a shift of leads/lags are @@ -797,17 +801,18 @@ public: //! Substitute pac_target_nonstationary operator virtual expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) = 0; - virtual optional findTargetVariable(int lhs_symb_id) const = 0; + [[nodiscard]] virtual optional findTargetVariable(int lhs_symb_id) const = 0; //! Add ExprNodes to the provided datatree virtual expr_t clone(DataTree& alt_datatree) const = 0; //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor - virtual expr_t removeTrendLeadLag(const map& trend_symbols_map) const = 0; + [[nodiscard]] virtual expr_t removeTrendLeadLag(const map& trend_symbols_map) const + = 0; //! Returns true if the expression is in static form (no lead, no lag, no expectation, no //! STEADY_STATE) - virtual bool isInStaticForm() const = 0; + [[nodiscard]] virtual bool isInStaticForm() const = 0; //! Matches a linear combination of variables (endo or exo), where scalars can be //! constant*parameter @@ -816,7 +821,8 @@ public: parameter in a term, param_id is nullopt. Can throw a MatchFailureException. */ - vector, double>> matchLinearCombinationOfVariables() const; + [[nodiscard]] vector, double>> + matchLinearCombinationOfVariables() const; /* Matches a linear combination of variables (endo or exo), where scalars can be constant*parameter. In addition, there may be one or more scalar terms @@ -827,7 +833,7 @@ public: no variable), then variable_id is nullopt. Can throw a MatchFailureException. */ - vector, int, optional, double>> + [[nodiscard]] vector, int, optional, double>> matchLinearCombinationOfVariablesPlusConstant() const; /* Matches a parameter, times a linear combination of variables (endo or @@ -835,7 +841,7 @@ public: The first output argument is the symbol ID of the parameter. The second output argument is the linear combination, in the same format as the output of matchLinearCombinationOfVariables(). */ - pair, double>>> + [[nodiscard]] pair, double>>> matchParamTimesLinearCombinationOfVariables() const; /* Matches a linear combination of endogenous, where scalars can be any @@ -845,7 +851,8 @@ public: Returns a pair composed of: – the terms of the form endogenous*scalar, as a list of (endo_id, constant expr); – the sum of all constant (intercept) terms */ - pair>, expr_t> matchLinearCombinationOfEndogenousWithConstant() const; + [[nodiscard]] pair>, expr_t> + matchLinearCombinationOfEndogenousWithConstant() const; /* Matches an expression of the form parameter*(var1-endo2). endo2 must correspond to symb_id. var1 must be an endogenous or an @@ -853,11 +860,11 @@ public: where X itself is *not* an aux var. Returns the symbol IDs of the parameter and of var1. Throws a MatchFailureException otherwise */ - pair matchParamTimesTargetMinusVariable(int symb_id) const; + [[nodiscard]] pair matchParamTimesTargetMinusVariable(int symb_id) const; //! Returns true if expression is of the form: //! param * (endog op endog op ...) + param * (endog op endog op ...) + ... - virtual bool isParamTimesEndogExpr() const = 0; + [[nodiscard]] virtual bool isParamTimesEndogExpr() const = 0; //! Fills the EC matrix structure void fillErrorCorrectionRow(int eqn, const vector& nontarget_lhs, @@ -868,10 +875,11 @@ public: virtual expr_t replaceVarsInEquation(map& table) const = 0; //! Returns true if PacExpectationNode encountered - virtual bool containsPacExpectation(const string& pac_model_name = "") const = 0; + [[nodiscard]] virtual bool containsPacExpectation(const string& pac_model_name = "") const = 0; //! Returns true if PacTargetNonstationaryNode encountered - virtual bool containsPacTargetNonstationary(const string& pac_model_name = "") const = 0; + [[nodiscard]] virtual bool containsPacTargetNonstationary(const string& pac_model_name = "") const + = 0; //! Decompose an expression into its additive terms /*! Returns a list of terms, with their sign (either 1 or -1, depending @@ -900,7 +908,7 @@ public: If the expression is not of the expected form, throws a MatchFailureException */ - tuple, int, optional, double> + [[nodiscard]] tuple, int, optional, double> matchVariableTimesConstantTimesParam(bool variable_obligatory) const; /* Matches an expression of the form endogenous*constant where constant is an @@ -908,7 +916,7 @@ public: Returns (endo_id, constant expr). Note that it will also match a simple endogenous (in which case the constant will of course be equal to one). */ - virtual pair matchEndogenousTimesConstant() const; + [[nodiscard]] virtual pair matchEndogenousTimesConstant() const; //! Exception thrown when matching fails struct MatchFailureException @@ -926,13 +934,13 @@ public: /* Returns true if the expression contains no endogenous, no exogenous and no exogenous deterministic */ - bool isConstant() const; + [[nodiscard]] bool isConstant() const; // Returns true if the expression contains an exogenous or an exogenous deterministic - bool hasExogenous() const; + [[nodiscard]] bool hasExogenous() const; // Substitutes orig_symb_id(±l) with exp(aux_symb_id(±l)) (used for “var(log)”) - virtual expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const = 0; + [[nodiscard]] virtual expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const = 0; }; //! Object used to compare two nodes (using their indexes) @@ -983,10 +991,10 @@ public: void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -994,16 +1002,16 @@ public: expr_t toStatic(DataTree& static_datatree) const override; void computeXrefs(EquationInfo& ei) const override; BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; expr_t substituteEndoLagGreaterThanTwo(subst_table_t& subst_table, @@ -1013,34 +1021,37 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - bool isInStaticForm() const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; - bool isParamTimesEndogExpr() const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; //! Symbol or variable node @@ -1080,28 +1091,28 @@ public: void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, const deriv_node_temp_terms_t& tef_terms) const override; expr_t toStatic(DataTree& static_datatree) const override; void computeXrefs(EquationInfo& ei) const override; - SymbolType get_type() const; + [[nodiscard]] SymbolType get_type() const; BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; expr_t substituteEndoLagGreaterThanTwo(subst_table_t& subst_table, @@ -1111,37 +1122,40 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - bool isInStaticForm() const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; - bool isParamTimesEndogExpr() const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; void matchMatchedMoment(vector& symb_ids, vector& lags, vector& powers) const override; - pair matchEndogenousTimesConstant() const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] pair matchEndogenousTimesConstant() const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; //! Unary operator node @@ -1182,11 +1196,11 @@ private: computeChainRuleDerivative(int deriv_id, const map& recursive_variables, unordered_map>& non_null_chain_rule_derivatives, unordered_map>& cache) override; - int cost(int cost, bool is_matlab) const override; - int cost(const vector>>& blocks_temporary_terms, - bool is_matlab) const override; - int cost(const map, unordered_set>& temp_terms_map, - bool is_matlab) const override; + [[nodiscard]] int cost(int cost, bool is_matlab) const override; + [[nodiscard]] int cost(const vector>>& blocks_temporary_terms, + bool is_matlab) const override; + [[nodiscard]] int cost(const map, unordered_set>& temp_terms_map, + bool is_matlab) const override; //! Returns the derivative of this node if darg is the derivative of the argument expr_t composeDerivatives(expr_t darg, int deriv_id); @@ -1208,7 +1222,7 @@ public: void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void writeExternalFunctionOutput(ostream& output, ExprNodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1225,7 +1239,7 @@ public: void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; static double eval_opcode(UnaryOpcode op_code, double v) noexcept(false); - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1233,16 +1247,16 @@ public: expr_t toStatic(DataTree& static_datatree) const override; void computeXrefs(EquationInfo& ei) const override; BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; //! Creates another UnaryOpNode with the same opcode, but with a possibly different datatree and @@ -1255,36 +1269,39 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; - bool createAuxVarForUnaryOpNode() const; + [[nodiscard]] bool createAuxVarForUnaryOpNode() const; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - bool isInStaticForm() const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; - bool isParamTimesEndogExpr() const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; void decomposeAdditiveTerms(vector>& terms, int current_sign) const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; //! Binary operator node @@ -1312,11 +1329,11 @@ private: computeChainRuleDerivative(int deriv_id, const map& recursive_variables, unordered_map>& non_null_chain_rule_derivatives, unordered_map>& cache) override; - int cost(int cost, bool is_matlab) const override; - int cost(const vector>>& blocks_temporary_terms, - bool is_matlab) const override; - int cost(const map, unordered_set>& temp_terms_map, - bool is_matlab) const override; + [[nodiscard]] int cost(int cost, bool is_matlab) const override; + [[nodiscard]] int cost(const vector>>& blocks_temporary_terms, + bool is_matlab) const override; + [[nodiscard]] int cost(const map, unordered_set>& temp_terms_map, + bool is_matlab) const override; //! Returns the derivative of this node if darg1 and darg2 are the derivatives of the arguments expr_t composeDerivatives(expr_t darg1, expr_t darg2); // Returns the node obtained by applying a transformation recursively on the arguments (in same @@ -1333,9 +1350,9 @@ private: public: BinaryOpNode(DataTree& datatree_arg, int idx_arg, const expr_t arg1_arg, BinaryOpcode op_code_arg, const expr_t arg2_arg, int powerDerivOrder); - int precedenceJson(const temporary_terms_t& temporary_terms) const override; - int precedence(ExprNodeOutputType output_type, - const temporary_terms_t& temporary_terms) const override; + [[nodiscard]] int precedenceJson(const temporary_terms_t& temporary_terms) const override; + [[nodiscard]] int precedence(ExprNodeOutputType output_type, + const temporary_terms_t& temporary_terms) const override; void computeTemporaryTerms(const pair& derivOrder, map, unordered_set>& temp_terms_map, unordered_map>>& reference_count, @@ -1350,7 +1367,7 @@ public: void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void writeExternalFunctionOutput(ostream& output, ExprNodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1368,7 +1385,7 @@ public: void collectDynamicVariables(SymbolType type_arg, set>& result) const override; static double eval_opcode(double v1, BinaryOpcode op_code, double v2, int derivOrder) noexcept(false); - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1379,17 +1396,17 @@ public: BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; //! Try to normalize an equation with respect to a given dynamic variable. /*! Should only be called on Equal nodes. The variable must appear in the equation. */ - BinaryOpNode* normalizeEquation(int symb_id, int lag) const; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] BinaryOpNode* normalizeEquation(int symb_id, int lag) const; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; //! Creates another BinaryOpNode with the same opcode, but with a possibly different datatree and @@ -1402,46 +1419,49 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - bool findTargetVariableHelper1(int lhs_symb_id, int rhs_symb_id) const; + [[nodiscard]] bool findTargetVariableHelper1(int lhs_symb_id, int rhs_symb_id) const; optional findTargetVariableHelper(const expr_t arg1, const expr_t arg2, int lhs_symb_id) const; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; //! Function to write out the oPowerNode in expr_t terms as opposed to writing out the function //! itself - expr_t unpackPowerDeriv() const; + [[nodiscard]] expr_t unpackPowerDeriv() const; //! Returns MULT_i*(lhs-rhs) = 0, creating multiplier MULT_i expr_t addMultipliersToConstraints(int i); //! Returns the non-zero hand-side of an equation (that must have a hand side equal to zero) - expr_t getNonZeroPartofEquation() const; - bool isInStaticForm() const override; + [[nodiscard]] expr_t getNonZeroPartofEquation() const; + [[nodiscard]] bool isInStaticForm() const override; void fillAutoregressiveRow(int eqn, const vector& lhs, map, expr_t>& AR) const; //! Finds equations where a variable is equal to a constant void findConstantEquations(map& table) const; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; /* ec_params_and_vars: - 1st element = feedback force parameter @@ -1463,18 +1483,19 @@ public: //! Finds the share of optimizing agents in the PAC equation, //! the expr node associated with it, //! and the expr node associated with the non-optimizing part - tuple, expr_t, expr_t, expr_t> + [[nodiscard]] tuple, expr_t, expr_t, expr_t> getPacOptimizingShareAndExprNodes(int lhs_orig_symb_id) const; - pair, expr_t> getPacOptimizingShareAndExprNodesHelper(int lhs_orig_symb_id) const; - expr_t getPacNonOptimizingPart(int optim_share_symb_id) const; - bool isParamTimesEndogExpr() const override; + [[nodiscard]] pair, expr_t> + getPacOptimizingShareAndExprNodesHelper(int lhs_orig_symb_id) const; + [[nodiscard]] expr_t getPacNonOptimizingPart(int optim_share_symb_id) const; + [[nodiscard]] bool isParamTimesEndogExpr() const override; void decomposeAdditiveTerms(vector>& terms, int current_sign) const override; void decomposeMultiplicativeFactors(vector>& factors, int current_exponent = 1) const override; void matchMatchedMoment(vector& symb_ids, vector& lags, vector& powers) const override; - pair matchEndogenousTimesConstant() const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] pair matchEndogenousTimesConstant() const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; //! Trinary operator node @@ -1500,11 +1521,11 @@ private: computeChainRuleDerivative(int deriv_id, const map& recursive_variables, unordered_map>& non_null_chain_rule_derivatives, unordered_map>& cache) override; - int cost(int cost, bool is_matlab) const override; - int cost(const vector>>& blocks_temporary_terms, - bool is_matlab) const override; - int cost(const map, unordered_set>& temp_terms_map, - bool is_matlab) const override; + [[nodiscard]] int cost(int cost, bool is_matlab) const override; + [[nodiscard]] int cost(const vector>>& blocks_temporary_terms, + bool is_matlab) const override; + [[nodiscard]] int cost(const map, unordered_set>& temp_terms_map, + bool is_matlab) const override; //! Returns the derivative of this node if darg1, darg2 and darg3 are the derivatives of the //! arguments expr_t composeDerivatives(expr_t darg1, expr_t darg2, expr_t darg3); @@ -1523,8 +1544,8 @@ private: public: TrinaryOpNode(DataTree& datatree_arg, int idx_arg, const expr_t arg1_arg, TrinaryOpcode op_code_arg, const expr_t arg2_arg, const expr_t arg3_arg); - int precedence(ExprNodeOutputType output_type, - const temporary_terms_t& temporary_terms) const override; + [[nodiscard]] int precedence(ExprNodeOutputType output_type, + const temporary_terms_t& temporary_terms) const override; void computeTemporaryTerms(const pair& derivOrder, map, unordered_set>& temp_terms_map, unordered_map>>& reference_count, @@ -1539,7 +1560,7 @@ public: void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void writeExternalFunctionOutput(ostream& output, ExprNodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1556,7 +1577,7 @@ public: void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) noexcept(false); - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1564,16 +1585,16 @@ public: expr_t toStatic(DataTree& static_datatree) const override; void computeXrefs(EquationInfo& ei) const override; BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; //! Creates another TrinaryOpNode with the same opcode, but with a possibly different datatree and @@ -1587,34 +1608,37 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - bool isInStaticForm() const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; - bool isParamTimesEndogExpr() const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; //! External function node @@ -1655,9 +1679,11 @@ protected: const map& recursive_variables, unordered_map>& non_null_chain_rule_derivatives) const override; //! Returns true if the given external function has been written as a temporary term - bool alreadyWrittenAsTefTerm(int the_symb_id, const deriv_node_temp_terms_t& tef_terms) const; + [[nodiscard]] bool alreadyWrittenAsTefTerm(int the_symb_id, + const deriv_node_temp_terms_t& tef_terms) const; //! Returns the index in the tef_terms map of this external function - int getIndxInTefTerms(int the_symb_id, const deriv_node_temp_terms_t& tef_terms) const + [[nodiscard]] int getIndxInTefTerms(int the_symb_id, + const deriv_node_temp_terms_t& tef_terms) const noexcept(false); //! Helper function to write output arguments of any given external function void writeExternalFunctionArguments(ostream& output, ExprNodeOutputType output_type, @@ -1676,7 +1702,7 @@ protected: /*! Returns a predicate that tests whether an other ExprNode is an external function which is computed by the same external function call (i.e. it has the same so-called "Tef" index) */ - virtual function sameTefTermPredicate() const = 0; + [[nodiscard]] virtual function sameTefTermPredicate() const = 0; void computeSubExprContainingVariable(int symb_id, int lag, set& contain_var) const override; @@ -1700,7 +1726,7 @@ public: const deriv_node_temp_terms_t& tef_terms, bool isdynamic = true) const override = 0; - bool containsExternalFunction() const override; + [[nodiscard]] bool containsExternalFunction() const override; void writeExternalFunctionOutput(ostream& output, ExprNodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1719,7 +1745,7 @@ public: = 0; void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void writeBytecodeOutput(BytecodeWriter& code_file, ExprNodeBytecodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, @@ -1728,16 +1754,16 @@ public: expr_t toStatic(DataTree& static_datatree) const override; void computeXrefs(EquationInfo& ei) const override = 0; BinaryOpNode* normalizeEquationHelper(const set& contain_var, expr_t rhs) const override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int maxLagWithDiffsExpanded() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; expr_t substituteEndoLagGreaterThanTwo(subst_table_t& subst_table, @@ -1747,12 +1773,13 @@ public: expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, @@ -1762,26 +1789,28 @@ public: virtual expr_t buildSimilarExternalFunctionNode(vector& alt_args, DataTree& alt_datatree) const = 0; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - bool isNumConstNodeEqualTo(double value) const override; - int countDiffs() const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] int countDiffs() const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; void writePrhs(ostream& output, ExprNodeOutputType output_type, const temporary_terms_t& temporary_terms, const temporary_terms_idxs_t& temporary_terms_idxs, const deriv_node_temp_terms_t& tef_terms) const; - expr_t replaceTrendVar() const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; expr_t clone(DataTree& alt_datatree) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - bool isInStaticForm() const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; - bool isParamTimesEndogExpr() const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; }; class ExternalFunctionNode : public AbstractExternalFunctionNode @@ -1793,7 +1822,7 @@ private: expr_t composeDerivatives(const vector& dargs) override; protected: - function sameTefTermPredicate() const override; + [[nodiscard]] function sameTefTermPredicate() const override; public: ExternalFunctionNode(DataTree& datatree_arg, int idx_arg, int symb_id_arg, @@ -1836,7 +1865,7 @@ private: expr_t composeDerivatives(const vector& dargs) override; protected: - function sameTefTermPredicate() const override; + [[nodiscard]] function sameTefTermPredicate() const override; public: FirstDerivExternalFunctionNode(DataTree& datatree_arg, int idx_arg, int top_level_symb_id_arg, @@ -1880,7 +1909,7 @@ private: expr_t composeDerivatives(const vector& dargs) override; protected: - function sameTefTermPredicate() const override; + [[nodiscard]] function sameTefTermPredicate() const override; public: SecondDerivExternalFunctionNode(DataTree& datatree_arg, int idx_arg, int top_level_symb_id_arg, @@ -1933,16 +1962,16 @@ public: unordered_map>& reference_count) const override; expr_t toStatic(DataTree& static_datatree) const override; expr_t computeDerivative(int deriv_id) override; - int maxEndoLead() const override; - int maxExoLead() const override; - int maxEndoLag() const override; - int maxExoLag() const override; - int maxLead() const override; - int maxLag() const override; - int VarMaxLag(const set& lhs_lag_equiv) const override; - expr_t undiff() const override; - expr_t decreaseLeadsLags(int n) const override; - int countDiffs() const override; + [[nodiscard]] int maxEndoLead() const override; + [[nodiscard]] int maxExoLead() const override; + [[nodiscard]] int maxEndoLag() const override; + [[nodiscard]] int maxExoLag() const override; + [[nodiscard]] int maxLead() const override; + [[nodiscard]] int maxLag() const override; + [[nodiscard]] int VarMaxLag(const set& lhs_lag_equiv) const override; + [[nodiscard]] expr_t undiff() const override; + [[nodiscard]] expr_t decreaseLeadsLags(int n) const override; + [[nodiscard]] int countDiffs() const override; expr_t substituteEndoLeadGreaterThanTwo(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; expr_t substituteEndoLagGreaterThanTwo(subst_table_t& subst_table, @@ -1950,16 +1979,16 @@ public: expr_t substituteExoLead(subst_table_t& subst_table, vector& neweqs, bool deterministic_model) const override; expr_t substituteExoLag(subst_table_t& subst_table, vector& neweqs) const override; - bool containsExternalFunction() const override; - double eval(const eval_context_t& eval_context) const noexcept(false) override; + [[nodiscard]] bool containsExternalFunction() const override; + [[nodiscard]] double eval(const eval_context_t& eval_context) const noexcept(false) override; void computeXrefs(EquationInfo& ei) const override; expr_t substituteExpectation(subst_table_t& subst_table, vector& neweqs, bool partial_information_model) const override; - expr_t substituteAdl() const override; - expr_t substituteModelLocalVariables() const override; + [[nodiscard]] expr_t substituteAdl() const override; + [[nodiscard]] expr_t substituteModelLocalVariables() const override; void findDiffNodes(lag_equivalence_table_t& nodes) const override; void findUnaryOpNodesForAuxVarCreation(lag_equivalence_table_t& nodes) const override; - optional findTargetVariable(int lhs_symb_id) const override; + [[nodiscard]] optional findTargetVariable(int lhs_symb_id) const override; expr_t substituteDiff(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, vector& neweqs) const override; expr_t substituteUnaryOpNodes(const lag_equivalence_table_t& nodes, subst_table_t& subst_table, @@ -1971,18 +2000,19 @@ public: const deriv_node_temp_terms_t& tef_terms) const override; void collectVARLHSVariable(set& result) const override; void collectDynamicVariables(SymbolType type_arg, set>& result) const override; - bool isNumConstNodeEqualTo(double value) const override; - bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const override; - bool isInStaticForm() const override; + [[nodiscard]] bool isNumConstNodeEqualTo(double value) const override; + [[nodiscard]] bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, + int lag_arg) const override; + [[nodiscard]] bool isInStaticForm() const override; expr_t replaceVarsInEquation(map& table) const override; - bool isParamTimesEndogExpr() const override; + [[nodiscard]] bool isParamTimesEndogExpr() const override; expr_t differentiateForwardVars(const vector& subset, subst_table_t& subst_table, vector& neweqs) const override; - expr_t decreaseLeadsLagsPredeterminedVariables() const override; - expr_t replaceTrendVar() const override; + [[nodiscard]] expr_t decreaseLeadsLagsPredeterminedVariables() const override; + [[nodiscard]] expr_t replaceTrendVar() const override; expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override; - expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; - expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; + [[nodiscard]] expr_t removeTrendLeadLag(const map& trend_symbols_map) const override; + [[nodiscard]] expr_t substituteLogTransform(int orig_symb_id, int aux_symb_id) const override; protected: void prepareForDerivation() override; @@ -2008,12 +2038,14 @@ public: const temporary_terms_idxs_t& temporary_terms_idxs, const deriv_node_temp_terms_t& tef_terms) const override; expr_t clone(DataTree& alt_datatree) const override; - int maxLagWithDiffsExpanded() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; @@ -2028,12 +2060,14 @@ public: const temporary_terms_idxs_t& temporary_terms_idxs, const deriv_node_temp_terms_t& tef_terms) const override; expr_t clone(DataTree& alt_datatree) const override; - int maxLagWithDiffsExpanded() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; @@ -2048,12 +2082,14 @@ public: const temporary_terms_idxs_t& temporary_terms_idxs, const deriv_node_temp_terms_t& tef_terms) const override; expr_t clone(DataTree& alt_datatree) const override; - int maxLagWithDiffsExpanded() const override; - expr_t substituteVarExpectation(const map& subst_table) const override; + [[nodiscard]] int maxLagWithDiffsExpanded() const override; + [[nodiscard]] expr_t + substituteVarExpectation(const map& subst_table) const override; expr_t substitutePacExpectation(const string& name, expr_t subexpr) override; expr_t substitutePacTargetNonstationary(const string& name, expr_t subexpr) override; - bool containsPacExpectation(const string& pac_model_name = "") const override; - bool containsPacTargetNonstationary(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacExpectation(const string& pac_model_name = "") const override; + [[nodiscard]] bool containsPacTargetNonstationary(const string& pac_model_name + = "") const override; void writeJsonAST(ostream& output) const override; void writeJsonOutput(ostream& output, const temporary_terms_t& temporary_terms, const deriv_node_temp_terms_t& tef_terms, bool isdynamic) const override; diff --git a/src/ExternalFunctionsTable.hh b/src/ExternalFunctionsTable.hh index d38c4dd8..23ecc8dc 100644 --- a/src/ExternalFunctionsTable.hh +++ b/src/ExternalFunctionsTable.hh @@ -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 diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 0ff060e4..34339861 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -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; diff --git a/src/NumericalConstants.hh b/src/NumericalConstants.hh index ba20587f..0182ccb1 100644 --- a/src/NumericalConstants.hh +++ b/src/NumericalConstants.hh @@ -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 diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index 3ded45b8..ece788de 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -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 is_there_one_integer_argument() const; + [[nodiscard]] optional 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 diff --git a/src/Shocks.hh b/src/Shocks.hh index 7c4e71bb..f2b24295 100644 --- a/src/Shocks.hh +++ b/src/Shocks.hh @@ -72,7 +72,7 @@ private: void writeCovarOrCorrShock(ostream& output, const pair, 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, diff --git a/src/Statement.hh b/src/Statement.hh index 2206aec4..06a3d589 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -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); diff --git a/src/SubModel.hh b/src/SubModel.hh index 7285dc18..2d482924 100644 --- a/src/SubModel.hh +++ b/src/SubModel.hh @@ -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 eqtags_arg, vector 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>& getEqTags() const; - const vector& getEqTags(const string& name_arg) const; - const map>& getTargetEqTags() const; - const map>& getEqNums() const; - const map>& getTargetEqNums() const; - const vector& getTargetEqNums(const string& name_arg) const; - const vector& getEqNums(const string& name_arg) const; - const vector& getMaxLags(const string& name_arg) const; - int getMaxLag(const string& name_arg) const; - const vector& getLhs(const string& name_arg) const; - const vector& getLhsExprT(const string& name_arg) const; - const vector& getDiff(const string& name_arg) const; - const map>& getNonTargetEqNums() const; - const vector& getNonTargetEqNums(const string& name_arg) const; - const vector& getNonTargetLhs(const string& name_arg) const; - const vector& getTargetLhs(const string& name_arg) const; + [[nodiscard]] const map>& getEqTags() const; + [[nodiscard]] const vector& getEqTags(const string& name_arg) const; + [[nodiscard]] const map>& getTargetEqTags() const; + [[nodiscard]] const map>& getEqNums() const; + [[nodiscard]] const map>& getTargetEqNums() const; + [[nodiscard]] const vector& getTargetEqNums(const string& name_arg) const; + [[nodiscard]] const vector& getEqNums(const string& name_arg) const; + [[nodiscard]] const vector& getMaxLags(const string& name_arg) const; + [[nodiscard]] int getMaxLag(const string& name_arg) const; + [[nodiscard]] const vector& getLhs(const string& name_arg) const; + [[nodiscard]] const vector& getLhsExprT(const string& name_arg) const; + [[nodiscard]] const vector& getDiff(const string& name_arg) const; + [[nodiscard]] const map>& getNonTargetEqNums() const; + [[nodiscard]] const vector& getNonTargetEqNums(const string& name_arg) const; + [[nodiscard]] const vector& getNonTargetLhs(const string& name_arg) const; + [[nodiscard]] const vector& getTargetLhs(const string& name_arg) const; void setVals(map> eqnums_arg, map> target_eqnums_arg, map> lhs_arg, map> lhs_expr_t_arg); @@ -145,21 +145,21 @@ public: //! Add a VAR model void addVarModel(string name, bool structural_arg, vector 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& getStructural() const; - const map>& getEqTags() const; - const vector& getEqTags(const string& name_arg) const; - const map>& getEqNums() const; - const vector& getDiff(const string& name_arg) const; - const vector& getEqNums(const string& name_arg) const; - const vector& getMaxLags(const string& name_arg) const; - int getMaxLag(const string& name_arg) const; - const vector& getLhs(const string& name_arg) const; - const vector& getLhsOrigIds(const string& name_arg) const; - const vector>>& getRhs(const string& name_arg) const; - const vector& getLhsExprT(const string& name_arg) const; + [[nodiscard]] const map& getStructural() const; + [[nodiscard]] const map>& getEqTags() const; + [[nodiscard]] const vector& getEqTags(const string& name_arg) const; + [[nodiscard]] const map>& getEqNums() const; + [[nodiscard]] const vector& getDiff(const string& name_arg) const; + [[nodiscard]] const vector& getEqNums(const string& name_arg) const; + [[nodiscard]] const vector& getMaxLags(const string& name_arg) const; + [[nodiscard]] int getMaxLag(const string& name_arg) const; + [[nodiscard]] const vector& getLhs(const string& name_arg) const; + [[nodiscard]] const vector& getLhsOrigIds(const string& name_arg) const; + [[nodiscard]] const vector>>& getRhs(const string& name_arg) const; + [[nodiscard]] const vector& getLhsExprT(const string& name_arg) const; void setEqNums(map> eqnums_arg); void setLhs(map> 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& neweqs); @@ -313,7 +313,7 @@ private: // pac_model_name → (target variable/expr, auxname_target_nonstationary, target components) map>> 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, diff --git a/src/SymbolList.hh b/src/SymbolList.hh index fec24a77..d93ef4cd 100644 --- a/src/SymbolList.hh +++ b/src/SymbolList.hh @@ -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 getSymbols() const; + [[nodiscard]] vector getSymbols() const; }; #endif diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index d6a9155d..dfa72905 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -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(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 it’s 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 unrollDiffLeadLagChain(int symb_id, int lag) const noexcept(false); + [[nodiscard]] pair 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 orig_symb_id = nullopt, optional 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> getPartitionsForType(SymbolType st) const noexcept(false); + [[nodiscard]] map> 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 getTrendVarIds() const; + [[nodiscard]] int getObservedExogenousVariableIndex(int symb_id) const; + [[nodiscard]] vector getTrendVarIds() const; //! Get list of exogenous variables - set getExogenous() const; + [[nodiscard]] set getExogenous() const; //! Get list of exogenous variables - set getObservedExogenous() const; + [[nodiscard]] set getObservedExogenous() const; //! Get list of endogenous variables - set getEndogenous() const; + [[nodiscard]] set 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 getOrigEndogenous() const; + [[nodiscard]] set 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 getEquationNumberForMultiplier(int symb_id) const; + [[nodiscard]] optional 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& getVariablesWithLogTransform() const; + [[nodiscard]] const set& getVariablesWithLogTransform() const; // Returns all Lagrange multipliers - set getLagrangeMultipliers() const; + [[nodiscard]] set getLagrangeMultipliers() const; }; inline void diff --git a/src/VariableDependencyGraph.hh b/src/VariableDependencyGraph.hh index b43b5ebf..83d935f2 100644 --- a/src/VariableDependencyGraph.hh +++ b/src/VariableDependencyGraph.hh @@ -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& select_index) const; + [[nodiscard]] VariableDependencyGraph extractSubgraph(const vector& select_index) const; //! Return the feedback set - set minimalSetOfFeedbackVertices() const; + [[nodiscard]] set minimalSetOfFeedbackVertices() const; //! Reorder the recursive variables /*! They appear first in a quasi triangular form and they are followed by the feedback variables */ - vector reorderRecursiveVariables(const set& feedback_vertices) const; + [[nodiscard]] vector reorderRecursiveVariables(const set& 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> sortedStronglyConnectedComponents() const; + [[nodiscard]] pair> 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& 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(); diff --git a/src/macro/Driver.hh b/src/macro/Driver.hh index a28999d9..e59a3b31 100644 --- a/src/macro/Driver.hh +++ b/src/macro/Driver.hh @@ -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(); diff --git a/src/macro/Environment.hh b/src/macro/Environment.hh index 49545ba5..f22565aa 100644 --- a/src/macro/Environment.hh +++ b/src/macro/Environment.hh @@ -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 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 // 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& function, const optional& 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(); diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index 427c442e..d213741d 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -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& + [[nodiscard]] const vector& 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; };