From c4f331c74c9493c91f5eabb46204a63bab70aa09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Wed, 14 Aug 2019 17:14:42 +0200 Subject: [PATCH] Macro processor: make more node classes immutable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the node classes are stored and copied as std::shared_ptr, a given class instance can actually be shared by two different expressions. Hence, in order to prevent weird bugs, it’s necessary to make these classes immutable. This commit deals with the easy cases. The remaining (and more complex) ones are: — Variable — Array — Include — IncludePath --- src/macro/Directives.hh | 8 ++++---- src/macro/Expressions.hh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/macro/Directives.hh b/src/macro/Directives.hh index 67912c77..a6b99038 100644 --- a/src/macro/Directives.hh +++ b/src/macro/Directives.hh @@ -134,7 +134,7 @@ namespace macro class EchoMacroVars : public Directive { private: - bool save; + const bool save; public: EchoMacroVars(bool save_arg, Environment &env_arg, Tokenizer::location location_arg) : @@ -148,7 +148,7 @@ namespace macro private: const vector<VariablePtr> index_vec; const ExpressionPtr index_vals; - vector<DirectivePtr> statements; + const vector<DirectivePtr> statements; public: For(vector<VariablePtr> index_vec_arg, ExpressionPtr index_vals_arg, @@ -164,8 +164,8 @@ namespace macro { protected: const ExpressionPtr condition; - vector<DirectivePtr> if_statements; - vector<DirectivePtr> else_statements; + const vector<DirectivePtr> if_statements; + const vector<DirectivePtr> else_statements; public: If(ExpressionPtr condition_arg, vector<DirectivePtr> if_statements_arg, diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index d67daabf..7ae6b837 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -197,7 +197,7 @@ namespace macro class Bool final : public BaseType { private: - bool value; + const bool value; public: Bool(bool value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : @@ -231,7 +231,7 @@ namespace macro class Real final : public BaseType { private: - double value; + const double value; public: // Use strtod to handle extreme cases (e.g. 1e500, 1e-500), nan, inf // See Note in NumericalConstants::AddNonNegativeConstant @@ -326,7 +326,7 @@ namespace macro class String final : public BaseType { private: - string value; + const string value; public: String(string value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : @@ -364,7 +364,7 @@ namespace macro class Tuple final : public BaseType { private: - vector<ExpressionPtr> tup; + const vector<ExpressionPtr> tup; public: Tuple(vector<ExpressionPtr> tup_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : -- GitLab