macro processor: make Variable class immutable
parent
b3ec807b90
commit
16080f2bb8
|
@ -450,7 +450,7 @@ namespace macro
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const string name;
|
const string name;
|
||||||
ArrayPtr indices; // for strings/arrays
|
const ArrayPtr indices; // for indexing strings/arrays
|
||||||
public:
|
public:
|
||||||
Variable(string name_arg,
|
Variable(string name_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
|
@ -458,10 +458,6 @@ namespace macro
|
||||||
Variable(string name_arg, ArrayPtr indices_arg,
|
Variable(string name_arg, ArrayPtr indices_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Expression(env_arg, move(location_arg)), name{move(name_arg)}, indices{move(indices_arg)} { }
|
Expression(env_arg, move(location_arg)), name{move(name_arg)}, indices{move(indices_arg)} { }
|
||||||
inline void addIndexing(const vector<ExpressionPtr> indices_arg)
|
|
||||||
{
|
|
||||||
indices = make_shared<Array>(indices_arg, env);
|
|
||||||
}
|
|
||||||
inline string to_string() const noexcept override { return name; }
|
inline string to_string() const noexcept override { return name; }
|
||||||
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; }
|
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; }
|
||||||
BaseTypePtr eval() override;
|
BaseTypePtr eval() override;
|
||||||
|
|
|
@ -300,6 +300,11 @@ primary_expr : LPAREN expr RPAREN
|
||||||
{ $$ = $2; }
|
{ $$ = $2; }
|
||||||
| symbol
|
| symbol
|
||||||
{ $$ = $1; } // Explicit rule needed for type conversion
|
{ $$ = $1; } // Explicit rule needed for type conversion
|
||||||
|
| NAME LBRACKET comma_expr RBRACKET
|
||||||
|
{
|
||||||
|
$$ = make_shared<Variable>($1, make_shared<Array>($3, driver.env, @3),
|
||||||
|
driver.env, @$);
|
||||||
|
}
|
||||||
| NAME LPAREN comma_expr RPAREN
|
| NAME LPAREN comma_expr RPAREN
|
||||||
{ $$ = make_shared<Function>($1, $3, driver.env, @$); }
|
{ $$ = make_shared<Function>($1, $3, driver.env, @$); }
|
||||||
| TRUE
|
| TRUE
|
||||||
|
@ -312,8 +317,6 @@ primary_expr : LPAREN expr RPAREN
|
||||||
{ $$ = make_shared<String>($1, driver.env, @$); }
|
{ $$ = make_shared<String>($1, driver.env, @$); }
|
||||||
| LBRACKET comma_expr RBRACKET
|
| LBRACKET comma_expr RBRACKET
|
||||||
{ $$ = make_shared<Array>($2, driver.env, @$); }
|
{ $$ = make_shared<Array>($2, driver.env, @$); }
|
||||||
| symbol LBRACKET comma_expr RBRACKET
|
|
||||||
{ $1->addIndexing($3); $$ = $1; }
|
|
||||||
| LPAREN tuple_comma_expr RPAREN
|
| LPAREN tuple_comma_expr RPAREN
|
||||||
{ $$ = make_shared<Tuple>($2, driver.env, @$); }
|
{ $$ = make_shared<Tuple>($2, driver.env, @$); }
|
||||||
| LBRACKET expr IN expr WHEN expr RBRACKET
|
| LBRACKET expr IN expr WHEN expr RBRACKET
|
||||||
|
|
Loading…
Reference in New Issue