changeset 10230:0a5a769b8fc0

disallow computed multiple assignment
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 30 Jan 2010 19:28:25 +0100
parents 02ae72071221
children f63ee6a20f57
files src/ChangeLog src/oct-parse.yy src/pt-assign.cc src/pt-assign.h
diffstat 4 files changed, 31 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Jan 30 20:44:17 2010 +0200
+++ b/src/ChangeLog	Sat Jan 30 19:28:25 2010 +0100
@@ -1,3 +1,14 @@
+2010-01-30  Jaroslav Hajek  <highegg@gmail.com>
+
+	* 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.
+
 2010-01-30  Shai Ayal  <shaiay@users.sourceforge.net>
 
 	* DLD-FUNCTIONS/fltk_backend.cc (__fltk_redraw__): call
--- a/src/oct-parse.yy	Sat Jan 30 20:44:17 2010 +0200
+++ b/src/oct-parse.yy	Sat Jan 30 19:28:25 2010 +0100
@@ -2737,8 +2737,10 @@
 
       delete lhs;
     }
+  else if (t == octave_value::op_asn_eq)
+    return new tree_multi_assignment (lhs, rhs, false, l, c);
   else
-    return new tree_multi_assignment (lhs, rhs, false, l, c, t);
+    yyerror ("computed multiple assignment not allowed");
 
   return retval;
 }
--- a/src/pt-assign.cc	Sat Jan 30 20:44:17 2010 +0200
+++ b/src/pt-assign.cc	Sat Jan 30 19:28:25 2010 +0100
@@ -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);
+                  // This won't do a copy.
+                  octave_value_list ovl  = rhs_val.slice (k, nel);
 
-                      ult.assign (etype, octave_value (ovl, true));
+                  ult.assign (octave_value::op_asn_eq, octave_value (ovl, true));
 
-                      if (! error_state)
-                        {
-                          retval_list.push_back (ovl);
+                  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);
 
--- a/src/pt-assign.h	Sat Jan 30 20:44:17 2010 +0200
+++ b/src/pt-assign.h	Sat Jan 30 19:28:25 2010 +0100
@@ -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;