# HG changeset patch # User Jaroslav Hajek # Date 1264855671 -3600 # Node ID 01df458291fbf29b538dd8702e2ec9c399b44066 # Parent d3fc22c3071cb0cd7a94a2a585c45a671772c48f disallow computed multiple assignment diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -0,0 +1,11 @@ +2010-01-30 Jaroslav Hajek + + * pt-assign.h (tree_multi_assignment::etype): Remove. + (tree_multi_assignment::tree_multi_assignment): Update. + (tree_multi_assignment::op_type): Update. + * pt-assign.cc (tree_multi_assignment::tree_multi_assignment): Update. + (tree_multi_assignment::rvalue): Update. + (tree_multi_assignment::dup): Update. + * oct=parse.yy (make_assign_op): Don't allow computed multiple + assignments. + diff --git a/src/oct-parse.yy b/src/oct-parse.yy --- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -2737,8 +2737,10 @@ delete lhs; } - else - return new tree_multi_assignment (lhs, rhs, false, l, c, t); + else if (t == octave_value::op_asn_eq) + return new tree_multi_assignment (lhs, rhs, false, l, c); + else + yyerror ("computed multiple assignment not allowed"); return retval; } diff --git a/src/pt-assign.cc b/src/pt-assign.cc --- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -300,8 +300,8 @@ tree_multi_assignment::tree_multi_assignment (tree_argument_list *lst, tree_expression *r, - bool plhs, int l, int c, octave_value::assign_op t) - : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), etype (t), + bool plhs, int l, int c) + : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), first_execution (true) { } tree_multi_assignment::~tree_multi_assignment (void) @@ -393,25 +393,16 @@ { if (k + nel <= n) { - if (etype == octave_value::op_asn_eq) + // This won't do a copy. + octave_value_list ovl = rhs_val.slice (k, nel); + + ult.assign (octave_value::op_asn_eq, octave_value (ovl, true)); + + if (! error_state) { - // This won't do a copy. - octave_value_list ovl = rhs_val.slice (k, nel); + retval_list.push_back (ovl); - ult.assign (etype, octave_value (ovl, true)); - - if (! error_state) - { - retval_list.push_back (ovl); - - k += nel; - } - } - else - { - std::string op = octave_value::assign_op_as_string (etype); - error ("operator %s unsupported for comma-separated list assignment", - op.c_str ()); + k += nel; } } else @@ -421,7 +412,7 @@ { if (k < n) { - ult.assign (etype, rhs_val(k)); + ult.assign (octave_value::op_asn_eq, rhs_val(k)); if (ult.is_black_hole ()) { @@ -430,10 +421,7 @@ } else if (! error_state) { - if (etype == octave_value::op_asn_eq) - retval_list.push_back (rhs_val(k)); - else - retval_list.push_back (ult.value ()); + retval_list.push_back (rhs_val(k)); k++; } @@ -478,7 +466,7 @@ std::string tree_multi_assignment::oper (void) const { - return octave_value::assign_op_as_string (etype); + return octave_value::assign_op_as_string (op_type ()); } tree_expression * @@ -488,7 +476,7 @@ tree_multi_assignment *new_ma = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0, rhs ? rhs->dup (scope, context) : 0, - preserve, etype); + preserve); new_ma->copy_base (*this); diff --git a/src/pt-assign.h b/src/pt-assign.h --- a/src/pt-assign.h +++ b/src/pt-assign.h @@ -118,14 +118,12 @@ { public: - tree_multi_assignment (bool plhs = false, int l = -1, int c = -1, - octave_value::assign_op t = octave_value::op_asn_eq) - : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype(t), + tree_multi_assignment (bool plhs = false, int l = -1, int c = -1) + : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), first_execution (true) { } tree_multi_assignment (tree_argument_list *lst, tree_expression *r, - bool plhs = false, int l = -1, int c = -1, - octave_value::assign_op t = octave_value::op_asn_eq); + bool plhs = false, int l = -1, int c = -1); ~tree_multi_assignment (void); @@ -150,7 +148,7 @@ void accept (tree_walker& tw); - octave_value::assign_op op_type (void) const { return etype; } + octave_value::assign_op op_type (void) const { return octave_value::op_asn_eq; } private: @@ -163,9 +161,6 @@ // True if we should not delete the lhs. bool preserve; - // The type of the expression. - octave_value::assign_op etype; - // true only on first rvalue() call. bool first_execution;