changeset 2963:c0c280cda856

[project @ 1997-05-12 03:25:07 by jwe]
author jwe
date Mon, 12 May 1997 03:29:38 +0000
parents 5e0fe4c5d52f
children 0a2551ec7004
files src/ChangeLog src/data.cc src/oct-var-ref.cc src/oct-var-ref.h src/ov.cc src/ov.h src/pt-indir.cc src/pt-indir.h src/pt-plot.cc src/variables.cc
diffstat 10 files changed, 115 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,65 @@
+Sun May 11 17:51:22 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* help.cc (Ftype): Make it work again for functions.
+
+	* pt-pr-code.cc (tree_print_code::print_parens): New function.
+	Use it in other tree_print_code functions to handle printing all
+	the parens that we found when parsing the expression, not just one
+	pair.
+	* pt-exp-base.h (tree_expression::paren_count): Rename from
+	is_in_parens.
+	* parse.y (maybe_warn_assign_as_truth_value): Use new name.
+
+	* parse.y (constant): New non-terminal.
+	(simple_expr1): Use it.
+
+	* parse.y (make_unary_op): Delete.
+	(simple_expr1): Where appropriate, use make_prefix_op and
+	make_postfix_op instead of make_unary_op.  Allow increment and
+	decrement ops to work on expressions, not just identifiers.
+	(make_prefix_op, make_postfix_op): Arg is expression, not identifier.
+	Handle old unary_op cases too.
+	(fold (tree_unary_expression *)): Delete.
+	* pt-exp.h, pt-exp.cc (tree_prefix_expression::eval): Handle unary
+	minus and not here.
+	(tree_postfix_expression::eval): Likewise, for transpose and hermitian.
+	(class tree_prefix_expression, class tree_postfix_expression):
+	Derive from tree_unary_expression.  Delete identifier member.
+	Delete ident member function.
+	(tree_unary_expression): Don't handle evaluation here.
+	* pt-exp-base.h (mark_in_parens): No longer virtual. Return this.
+	(reference): New virtual function.
+	(class tree_expression): Don't handle expression type here.
+	* pt-mvr-base.h (tree_multi_val_ret::tree_multi_val_ret): Likewise.
+	* pt-mvr.h, pt-mvr.cc (tree_multi_assignment_expression): Likewise.
+	* pt-walk.h (visit_unary_expression): Delete declaration.
+	* pt-pr-code.h, pt-pr-code.cc (visit_unary_expression): Delete.
+	(visit_prefix_expression): Use operand(), not ident().
+	new, visit_postfix_expression):
+	* pt-id.h, pt-id.cc (increment, decrement): Delete.
+
+	* pt-misc.cc (tree_parameter_list::define_from_arg_vector): Get a
+	reference to each element and use the assignment operator instead
+	of tree_identifier::define.
+	* pt-id.h, pt-id.cc (tree_identifier::define): Delete versions
+	that take octave_value and octave_symbol args.
+
+Sat May 10 23:32:13 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* pt-indir.h, pt-indir.cc (tree_indirect_reference::value): Delete.
+
+	* oct-var-ref.cc (octave_variable_ref::assign): Clear idx after
+	assignment.
+
+	* ov.h, ov.cc (assign): Return void, not reference to octave_value.
+	(do_index_op): Rename, from index.
+	(do_struct_elt_index_op): Rename, from struct_elt_val.
+	Add version that accepts index arg.
+	Change all uses and derived classes to match.
+	* pt-const.h (index): Delete.
+	* oct-var-ref.h, oct-var-ref.cc (value): Handle indexed structure
+	ops here too.
+
 Fri May  9 07:40:59 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* pt-exp.cc (print_rhs_assign_val, symbols_of_pt_exp): New functions.
--- a/src/data.cc
+++ b/src/data.cc
@@ -786,10 +786,13 @@
     {
       retval = 0.0;
 
+      // XXX FIXME XXX -- should this work for all types that can do
+      // structure reference operations?
+
       if (args(0).is_map () && args(1).is_string ())
 	{
 	  string s = args(1).string_value ();
-	  octave_value tmp = args(0).struct_elt_val (s, true);
+	  octave_value tmp = args(0).do_struct_elt_index_op (s, true);
 	  retval = static_cast<double> (tmp.is_defined ());
 	}
       else
--- a/src/oct-var-ref.cc
+++ b/src/oct-var-ref.cc
@@ -54,6 +54,11 @@
 
   if (chg_fcn && chg_fcn () < 0)
     *val = saved_val;
+
+  // Clear index so subsequent value() operations will not perform an
+  // indexing operation.
+
+  idx = octave_value_list ();
 }
 
 /*
--- a/src/oct-var-ref.h
+++ b/src/oct-var-ref.h
@@ -81,7 +81,12 @@
   octave_value value (void)
     {
       return struct_elt_name.empty ()
-	? *val : val->struct_elt_val (struct_elt_name);
+	? (idx.empty ()
+	   ? *val
+	   : val->do_index_op (idx))
+	: (idx.empty ()
+	   ? val->do_struct_elt_index_op (struct_elt_name)
+	   : val->do_struct_elt_index_op (struct_elt_name, idx));
     }
 
 private:
--- a/src/ov.cc
+++ b/src/ov.cc
@@ -486,15 +486,15 @@
 	 tn2.c_str (), tn1.c_str ());
 }
 
-octave_value&
+void
 octave_value::assign (assign_op, const octave_value& rhs)
 {
   // XXX FIXME XXX -- make this work for ops other than `='.
 
-  return operator = (rhs);
+  operator = (rhs);
 }
 
-octave_value&
+void
 octave_value::assign (octave_value::assign_op op,
 		      const octave_value_list& idx,
 		      const octave_value& rhs)
@@ -521,8 +521,6 @@
       error ("indexed assignment to previously undefined variables");
       error ("is only possible when resize_on_range_error is true");
     }
-
-  return *this;
 }
 
 void
@@ -562,7 +560,7 @@
 octave_value_list
 octave_value::eval (int, const octave_value_list& idx)
 {
-  return (idx.length () > 0) ? index (idx) : *this;
+  return (idx.length () > 0) ? do_index_op (idx) : *this;
 }
 
 Octave_map
--- a/src/ov.h
+++ b/src/ov.h
@@ -213,13 +213,13 @@
   virtual octave_value *try_narrowing_conversion (void)
     { return rep->try_narrowing_conversion (); }
 
-  virtual octave_value index (const octave_value_list& idx) const
-    { return rep->index (idx); }
+  virtual octave_value do_index_op (const octave_value_list& idx) const
+    { return rep->do_index_op (idx); }
 
-  octave_value& assign (assign_op, const octave_value& rhs);
+  void assign (assign_op, const octave_value& rhs);
 
-  octave_value& assign (assign_op, const octave_value_list& idx,
-			const octave_value& rhs);
+  void assign (assign_op, const octave_value_list& idx,
+	       const octave_value& rhs);
 
   virtual void
   assign_struct_elt (assign_op, const string& elt_nm,
@@ -233,8 +233,13 @@
     { return rep->index_vector (); }
 
   virtual octave_value
-  struct_elt_val (const string& nm, bool silent = false) const
-    { return rep->struct_elt_val (nm, silent); }
+  do_struct_elt_index_op (const string& nm, bool silent = false)
+    { return rep->do_struct_elt_index_op (nm, silent); }
+
+  virtual octave_value
+  do_struct_elt_index_op (const string& nm, const octave_value_list& idx,
+			  bool silent = false)
+    { return rep->do_struct_elt_index_op (nm, idx, silent); }
 
   octave_variable_reference struct_elt_ref (const string& nm);
 
--- a/src/pt-indir.cc
+++ b/src/pt-indir.cc
@@ -95,14 +95,14 @@
     retval = id->eval (print);
   else
     {
-      retval = value ();
+      octave_variable_reference tmp = reference ();
 
-      if (! error_state && retval.is_defined ())
+      if (! (error_state || tmp.is_undefined ()))
 	{
-	  if (maybe_do_ans_assign)
+	  retval = tmp.value ();
+
+	  if (! error_state && maybe_do_ans_assign && retval.is_defined ())
 	    bind_ans (retval, print);
-	  else if (print)
-	    retval.print_with_name (octave_stdout, name ());
 	}
     }
 
@@ -119,17 +119,18 @@
     retval = id->eval (print, nargout, args);
   else
     {
-      octave_value tmp = value ();
+      octave_variable_reference tmp = reference ();
 
-      if (! error_state && tmp.is_defined ())
+      if (! (error_state || tmp.is_undefined ()))
 	{
-	  retval = tmp.index (args);
+	  tmp.index (args);
 
-	  if (! error_state)
+	  retval = tmp.value ();
+
+	  if (! error_state && maybe_do_ans_assign && nargout == 1
+	      && retval.length () > 0 && retval(0).is_defined ())
 	    {
-	      if (maybe_do_ans_assign && nargout == 1
-		  && retval.length () > 0 && retval(0).is_defined ())
-		bind_ans (retval(0), print);
+	      bind_ans (retval(0), print);
 	    }
 	}
     }
@@ -143,29 +144,6 @@
   tw.visit_indirect_ref (*this);
 }
 
-octave_value
-tree_indirect_ref::value (void) const
-{
-  octave_value retval;
-
-  if (is_identifier_only ())
-    retval = id->value ();
-  else
-    {
-      if (id)
-	retval = id->value ();
-      else if (indir)
-	retval = indir->value ();
-      else
-	panic_impossible ();
-
-      if (! error_state)
-	retval = retval.struct_elt_val (nm);
-    }
-
-  return retval;
-}
-
 octave_variable_reference
 tree_indirect_ref::reference (void)
 {
--- a/src/pt-indir.h
+++ b/src/pt-indir.h
@@ -90,8 +90,6 @@
   octave_value_list
   eval (bool print, int nargout, const octave_value_list& args);
 
-  octave_value value (void) const;
-
   octave_variable_reference reference (void);
 
   string elt_name (void)
--- a/src/pt-plot.cc
+++ b/src/pt-plot.cc
@@ -660,10 +660,11 @@
       ColumnVector val = sp_using_clause->values (ndim);
 
       octave_value_list args;
+
       args(1) = val;
       args(0) = octave_value::magic_colon_t;
 
-      retval = data.index (args);
+      retval = data.do_index_op (args);
 
       if (error_state)
 	return octave_value ();
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -339,11 +339,13 @@
       if (tmp->is_constant ())
 	vtmp = tmp->eval ();
 
+      // XXX FIXME XXX -- make this work for all types that can do
+      // structure reference operations.
       if (vtmp.is_map ())
 	{
 	  for (int i = 1; i < elts.length (); i++)
 	    {
-	      vtmp = vtmp.struct_elt_val (elts[i], true);
+	      vtmp = vtmp.do_struct_elt_index_op (elts[i], true);
 
 	      if (! vtmp.is_map ())
 		break;
@@ -384,11 +386,14 @@
       if (tmp->is_constant ())
 	vtmp = tmp->eval ();
 
+      // XXX FIXME XXX -- should this work for all types that can do
+      // structure reference operations?
+
       if (vtmp.is_map ())
 	{
 	  for (int i = 1; i < elts.length (); i++)
 	    {
-	      vtmp = vtmp.struct_elt_val (elts[i], true);
+	      vtmp = vtmp.do_struct_elt_index_op (elts[i], true);
 
 	      if (! vtmp.is_map ())
 		{