From 16080f2bb8f18558f3842b8343797d2b17917657 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 20 Aug 2019 11:16:33 +0200 Subject: [PATCH] macro processor: make Variable class immutable --- src/macro/Expressions.hh | 6 +----- src/macro/Parser.yy | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index d77599a9..a570f48d 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -450,7 +450,7 @@ namespace macro { private: const string name; - ArrayPtr indices; // for strings/arrays + const ArrayPtr indices; // for indexing strings/arrays public: Variable(string name_arg, Environment &env_arg, Tokenizer::location location_arg) : @@ -458,10 +458,6 @@ namespace macro Variable(string name_arg, ArrayPtr indices_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), name{move(name_arg)}, indices{move(indices_arg)} { } - inline void addIndexing(const vector indices_arg) - { - indices = make_shared(indices_arg, env); - } inline string to_string() const noexcept override { return name; } inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; } BaseTypePtr eval() override; diff --git a/src/macro/Parser.yy b/src/macro/Parser.yy index 13244b40..5618b658 100644 --- a/src/macro/Parser.yy +++ b/src/macro/Parser.yy @@ -300,6 +300,11 @@ primary_expr : LPAREN expr RPAREN { $$ = $2; } | symbol { $$ = $1; } // Explicit rule needed for type conversion + | NAME LBRACKET comma_expr RBRACKET + { + $$ = make_shared($1, make_shared($3, driver.env, @3), + driver.env, @$); + } | NAME LPAREN comma_expr RPAREN { $$ = make_shared($1, $3, driver.env, @$); } | TRUE @@ -312,8 +317,6 @@ primary_expr : LPAREN expr RPAREN { $$ = make_shared($1, driver.env, @$); } | LBRACKET comma_expr RBRACKET { $$ = make_shared($2, driver.env, @$); } - | symbol LBRACKET comma_expr RBRACKET - { $1->addIndexing($3); $$ = $1; } | LPAREN tuple_comma_expr RPAREN { $$ = make_shared($2, driver.env, @$); } | LBRACKET expr IN expr WHEN expr RBRACKET