changeset 3930:61d4427c016e

[project @ 2002-05-07 00:47:31 by jwe]
author jwe
date Tue, 07 May 2002 00:47:31 +0000
parents cc8ae49d6e79
children 311981a9726d
files src/ChangeLog src/Makefile.in src/ov.h src/parse.y src/pt-all.h src/pt-bp.cc src/pt-bp.h src/pt-check.cc src/pt-check.h src/pt-idx.cc src/pt-idx.h src/pt-indir.cc src/pt-indir.h src/pt-pr-code.cc src/pt-pr-code.h src/pt-walk.h src/variables.h
diffstat 17 files changed, 190 insertions(+), 340 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat May 04 02:47:14 2002 +0000
+++ b/src/ChangeLog	Tue May 07 00:47:31 2002 +0000
@@ -1,3 +1,42 @@
+2002-05-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* pt-indir.h, pt-indir.cc: Delete.
+
+	* pt-all.h: Don't include pt-indir.h.
+
+	* Makefile.in (PT_SRC): Delete pt-indir.cc from the list.
+	(PT_INCLUDES): Delete pt-indir.h from the list.
+
+	* pt-walk.h (tree_walker::visit_indirect_ref): Delete.
+	* pt-pr-code.h, pt-pr-code.cc (tree_print_code::visit_indirect_ref):
+	Likewise.
+	* pt-check.h, pt-check.cc (tree_checker::visit_indirect_ref): Likewise.
+	* pt-bp.h, pt-bp.cc (tree_breakpoint::visit_indirect_ref): Likewise.
+
+	* pt-walk.h: Delete forward decl for tree_indirect_ref.
+	* variables.h: Likewise.
+
+	* parse.y (make_indirect_ref): Return tree_index_expression, not
+	tree_indirect_ref.
+
+	* pt-idx.h (tree_index_expression::struct_elt_name): New function.
+
+	* pt-idx.cc (tree_index_expression::lvalue): Handle dot case too.
+	(tree_index_expression::name): Likewise.
+	(tree_index_expression rvalue (int)): Likewise.
+	(tree_index_expression::eval_error): Likewise.
+	* pt-pr-code.cc (visit_index_expression): Likewise.
+	* pt-bp.cc (tree_breakpoint::visit_index_expression): Likewise.
+
+	* pt-idx.h (tree_index_expression::dot): New type enum element.
+	(tree_index_expression::expr_type): New function.
+	(tree_index_expression::tree_index_expression (tree_expression*,
+	const std::string&, int, int)): New constructor.
+	(tree_index_expression::is_index_expression): Return value is now
+	conditional on itype.
+	(tree_index_expression::is_indirect_ref): New function.
+	(tree_index_expression::lvalue_ok): Also return true if itype is dot.
+
 2002-05-03  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* parse.y (ABORT_PARSE): Maybe restore symbol table context too.
--- a/src/Makefile.in	Sat May 04 02:47:14 2002 +0000
+++ b/src/Makefile.in	Tue May 07 00:47:31 2002 +0000
@@ -73,7 +73,7 @@
 
 PT_INCLUDES := pt.h pt-all.h pt-arg-list.h pt-assign.h pt-binop.h \
         pt-bp.h	pt-cell.h pt-check.h pt-cmd.h pt-colon.h pt-const.h \
-	pt-decl.h pt-except.h pt-exp.h pt-id.h pt-idx.h pt-indir.h \
+	pt-decl.h pt-except.h pt-exp.h pt-id.h pt-idx.h \
 	pt-jump.h pt-loop.h pt-mat.h pt-misc.h pt-plot.h \
 	pt-pr-code.h pt-select.h pt-stmt.h pt-unop.h pt-walk.h \
 
@@ -117,7 +117,7 @@
 
 PT_SRC := pt.cc pt-arg-list.cc pt-assign.cc pt-bp.cc pt-binop.cc pt-cell.cc \
 	pt-check.cc pt-cmd.cc pt-colon.cc pt-const.cc pt-decl.cc \
-	pt-except.cc pt-exp.cc pt-id.cc pt-idx.cc pt-indir.cc pt-jump.cc \
+	pt-except.cc pt-exp.cc pt-id.cc pt-idx.cc pt-jump.cc \
 	pt-loop.cc pt-mat.cc pt-misc.cc pt-plot.cc pt-pr-code.cc \
 	pt-select.cc pt-stmt.cc pt-unop.cc
 
--- a/src/ov.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/ov.h	Tue May 07 00:47:31 2002 +0000
@@ -250,7 +250,8 @@
 
   virtual void
   assign_struct_elt (assign_op, const std::string& elt_nm,
-		     const octave_value_list& idx, const octave_value& rhs);
+		     const octave_value_list& idx,
+		     const octave_value& rhs);
 
   virtual idx_vector index_vector (void) const
     { return rep->index_vector (); }
@@ -260,7 +261,8 @@
     { return rep->do_struct_elt_index_op (nm, silent); }
 
   virtual octave_value
-  do_struct_elt_index_op (const std::string& nm, const octave_value_list& idx,
+  do_struct_elt_index_op (const std::string& nm,
+			  const octave_value_list& idx,
 			  bool silent = false)
     { return rep->do_struct_elt_index_op (nm, idx, silent); }
 
--- a/src/parse.y	Sat May 04 02:47:14 2002 +0000
+++ b/src/parse.y	Tue May 07 00:47:31 2002 +0000
@@ -284,7 +284,7 @@
 		       tree_index_expression::type);
 
 // Make an indirect reference expression.
-static tree_indirect_ref *
+static tree_index_expression *
 make_indirect_ref (tree_expression *expr, const std::string&);
 
 // Make a declaration command.
@@ -2607,15 +2607,15 @@
 
 // Make an indirect reference expression.
 
-static tree_indirect_ref *
+static tree_index_expression *
 make_indirect_ref (tree_expression *expr, const std::string& elt)
 {
-  tree_indirect_ref *retval = 0;
+  tree_index_expression *retval = 0;
 
   int l = expr->line ();
   int c = expr->column ();
 
-  retval = new tree_indirect_ref (expr, elt, l, c);
+  retval = new tree_index_expression (expr, elt, l, c);
 
   lexer_flags.looking_at_indirect_ref = false;
 
--- a/src/pt-all.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-all.h	Tue May 07 00:47:31 2002 +0000
@@ -37,7 +37,6 @@
 #include "pt-exp.h"
 #include "pt-id.h"
 #include "pt-idx.h"
-#include "pt-indir.h"
 #include "pt-jump.h"
 #include "pt-loop.h"
 #include "pt-mat.h"
--- a/src/pt-bp.cc	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-bp.cc	Tue May 07 00:47:31 2002 +0000
@@ -345,26 +345,23 @@
   if (found)
     return;
 
-  tree_expression *expr = cmd.expression ();
-
-  if (expr)
-    if (expr->line () >= line)
-      take_action (*expr);
-
-  tree_argument_list *lst = cmd.arg_list ();
+  if (cmd.expr_type () == tree_index_expression::dot)
+    {
+      if (cmd.line () >= line)
+	take_action (cmd);
+    }
+  else
+    {
+      tree_expression *expr = cmd.expression ();
 
-  if (lst)
-    lst->accept (*this);
-}
+      if (expr && expr->line () >= line)
+	take_action (*expr);
 
-void 
-tree_breakpoint::visit_indirect_ref (tree_indirect_ref& cmd)
-{
-  if (found)
-    return;
+      tree_argument_list *lst = cmd.arg_list ();
 
-  if (cmd.line () >= line)
-    take_action (cmd);  
+      if (lst)
+	lst->accept (*this);
+    }
 }
 
 void 
--- a/src/pt-bp.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-bp.h	Tue May 07 00:47:31 2002 +0000
@@ -89,8 +89,6 @@
 
   void visit_index_expression (tree_index_expression&);
 
-  void visit_indirect_ref (tree_indirect_ref&);
-
   void visit_matrix (tree_matrix&);
 
   void visit_cell (tree_cell&);
--- a/src/pt-check.cc	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-check.cc	Tue May 07 00:47:31 2002 +0000
@@ -255,15 +255,6 @@
 }
 
 void
-tree_checker::visit_indirect_ref (tree_indirect_ref& expr)
-{
-  tree_expression *e = expr.expression ();
-
-  if (e)
-    e->accept (*this);
-}
-
-void
 tree_checker::visit_matrix (tree_matrix& lst)
 {
   Pix p = lst.first ();
--- a/src/pt-check.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-check.h	Tue May 07 00:47:31 2002 +0000
@@ -73,8 +73,6 @@
 
   void visit_index_expression (tree_index_expression&);
 
-  void visit_indirect_ref (tree_indirect_ref&);
-
   void visit_matrix (tree_matrix&);
 
   void visit_multi_assignment (tree_multi_assignment&);
--- a/src/pt-idx.cc	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-idx.cc	Tue May 07 00:47:31 2002 +0000
@@ -29,12 +29,17 @@
 #endif
 
 #include "error.h"
+#include "oct-map.h"
 #include "oct-obj.h"
 #include "oct-lvalue.h"
 #include "ov.h"
+#include "pager.h"
 #include "pt-arg-list.h"
+#include "pt-bp.h"
 #include "pt-idx.h"
 #include "pt-walk.h"
+#include "utils.h"
+#include "variables.h"
 
 // Index expressions.
 
@@ -44,6 +49,12 @@
   : tree_expression (l, c), expr (e), list (lst),
     itype (t), arg_nm (lst ? lst->get_arg_names () : string_vector ()) { }
 
+tree_index_expression::tree_index_expression (tree_expression *e,
+					      const std::string& n,
+					      int l = -1, int c = -1)
+  : tree_expression (l, c), expr (e), list (0), itype (dot),
+    arg_nm (n) { }
+
 tree_index_expression::~tree_index_expression (void)
 {
   delete expr;
@@ -56,7 +67,10 @@
 std::string
 tree_index_expression::name (void) const
 {
-  return expr->name ();
+  // ??? FIXME ???
+  std::string xname = expr->name ();
+
+  return (! dot || xname == "<unknown>") ? xname : xname + "." + arg_nm(0);
 }
 
 octave_value_list
@@ -71,24 +85,63 @@
 
   if (! error_state)
     {
-      octave_value_list args;
-
-      if (list)
-	args = list->convert_to_const_vector ();
-
-      if (! error_state)
+      if (itype == dot)
 	{
-	  if (! args.empty ())
-	    args.stash_name_tags (arg_nm);
+	  MAYBE_DO_BREAKPOINT;
+
+	  if (nargout > 1)
+	    error ("invalid number of output arguments for structure reference");
+	  else
+	    {
+	      octave_value_list tmp = expr->rvalue (nargout);
+
+	      if (tmp.empty ())
+		eval_error ();
+	      else
+		{
+		  octave_value val = tmp(0).do_struct_elt_index_op (arg_nm(0));
+
+		  if (print_result () && nargout == 0 && val.is_defined ())
+		    {
+		      // ??? FIXME ???
+
+		      std::string xname = name ();
+
+		      if (xname == "<unknown>")
+			bind_ans (val, true);
+		      else
+			val.print_with_name (octave_stdout, xname);
+		    }
 
-	  // XXX FIXME XXX -- is this the right thing to do?
-	  if (tmp.is_constant ())
-	    retval = tmp.do_index_op (args);
+		  retval = val;
+		}
+	    }
+	}
+      else if (itype == paren || itype == brace)
+	{
+	  octave_value_list args;
+
+	  if (list)
+	    args = list->convert_to_const_vector ();
+
+	  if (! error_state)
+	    {
+	      if (! args.empty ())
+		args.stash_name_tags (arg_nm);
+
+	      // XXX FIXME XXX -- is this the right thing to do?
+	      if (tmp.is_constant ())
+		retval = tmp.do_index_op (args);
+	      else
+		retval = tmp.do_multi_index_op (nargout, args);
+	    }
 	  else
-	    retval = tmp.do_multi_index_op (nargout, args);
+	    eval_error ();
 	}
+#if 0
       else
-	eval_error ();
+	panic_impossible ();
+#endif
     }
   else
     eval_error ();
@@ -116,16 +169,32 @@
 
   if (! error_state)
     {
-      retval = expr->lvalue ();
+      if (itype == dot)
+	{
+	  octave_lvalue tmp = expr->lvalue ();
 
-      if (! error_state)
+	  if (tmp.is_undefined () || ! tmp.is_map ())
+	    tmp.define (Octave_map ());
+
+	  retval = tmp.struct_elt_ref (arg_nm(0));
+	}
+      else if (itype == paren || itype == brace)
 	{
-	  octave_value_list args;
+	  retval = expr->lvalue ();
+
+	  if (! error_state)
+	    {
+	      octave_value_list args;
 	  
-	  if (list)
-	    args = list->convert_to_const_vector ();
+	      if (list)
+		args = list->convert_to_const_vector ();
 
-	  retval.set_index (args);
+	      retval.set_index (args);
+	    }
+#if 0
+	  else
+	    panic_impossible ();
+#endif
 	}
     }
 
@@ -140,21 +209,19 @@
       int l = line ();
       int c = column ();
 
+      const char *type_str;
+
+      if (itype == dot)
+	type_str = "structure reference operator";
+      else if (list)
+	type_str = "index expression";
+      else
+	type_str = "expression";
+
       if (l != -1 && c != -1)
-	{
-	  if (list)
-	    ::error ("evaluating index expression near line %d, column %d",
-		     l, c);
-	  else
-	    ::error ("evaluating expression near line %d, column %d", l, c);
-	}
+	::error ("evaluating %s near line %d, column %d", type_str, l, c);
       else
-	{
-	  if (list)
-	    ::error ("evaluating index expression");
-	  else
-	    ::error ("evaluating expression");
-	}
+	::error ("evaluating %s", type_str);
     }
 }
 
--- a/src/pt-idx.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-idx.h	Tue May 07 00:47:31 2002 +0000
@@ -50,19 +50,31 @@
     {
       unknown,
       paren,
-      brace
+      brace,
+      dot
     };
 
   tree_index_expression (tree_expression *e = 0, tree_argument_list *lst = 0,
 			 int l = -1, int c = -1, type t = paren);
 
+  tree_index_expression (tree_expression *e, const std::string& n,
+			 int l = -1, int c = -1);
+
   ~tree_index_expression (void);
 
   bool is_index_expression (void) const
-    { return true; }
+    { return (itype == paren || itype == brace); }
+
+  bool is_indirect_ref (void) const
+    { return (itype == dot); }
 
   std::string name (void) const;
 
+  std::string struct_elt_name (void) const
+    { return itype == dot ? arg_nm(0) : "<unknown>"; }
+
+  type expr_type (void) { return itype; }
+
   tree_expression *expression (void)
     { return expr; }
 
@@ -70,7 +82,7 @@
     { return list; }
 
   bool lvalue_ok (void) const
-    { return expr->lvalue_ok (); }
+    { return (itype == dot || expr->lvalue_ok ()); }
 
   bool rvalue_ok (void) const
     { return true; }
@@ -87,12 +99,16 @@
 
 private:
 
+  // The LHS of this index expression.
   tree_expression *expr;
 
+  // The indices (only valid if itype == paren || itype == brace).
   tree_argument_list *list;
 
+  // The type of this index expression.
   type itype;
 
+  // The names of the arguments.
   string_vector arg_nm;
 
   // No copying!
--- a/src/pt-indir.cc	Sat May 04 02:47:14 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
-
-Copyright (C) 1996, 1997 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-#if defined (__GNUG__)
-#pragma implementation
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "error.h"
-#include "oct-map.h"
-#include "oct-obj.h"
-#include "oct-lvalue.h"
-#include "ov.h"
-#include "pager.h"
-#include "pt-bp.h"
-#include "pt-indir.h"
-#include "pt-walk.h"
-#include "utils.h"
-#include "variables.h"
-
-// Indirect references to values (structure elements).
-
-tree_indirect_ref::~tree_indirect_ref (void)
-{
-  delete expr;
-}
-
-std::string
-tree_indirect_ref::name (void) const
-{
-  // ??? FIXME ???
-  std::string xname = expr->name ();
-
-  return (xname == "<unknown>") ? xname : xname + "." + nm;
-}
-
-octave_value_list
-tree_indirect_ref::rvalue (int nargout)
-{
-  octave_value_list retval;
-
-  MAYBE_DO_BREAKPOINT;
-
-  if (nargout > 1)
-    error ("invalid number of output arguments for structure reference");
-  else
-    {
-      octave_value_list tmp = expr->rvalue (nargout);
-
-      if (tmp.empty ())
-	eval_error ();
-      else
-	{
-	  octave_value val = tmp(0).do_struct_elt_index_op (nm);
-
-	  if (print_result () && nargout == 0 && val.is_defined ())
-	    {
-	      // ??? FIXME ???
-
-	      std::string xname = name ();
-
-	      if (xname == "<unknown>")
-		bind_ans (val, true);
-	      else
-		val.print_with_name (octave_stdout, xname);
-	    }
-
-	  retval = val;
-	}
-    }
-
-  return retval;
-}
-
-octave_value
-tree_indirect_ref::rvalue (void)
-{
-  octave_value retval;
-
-  octave_value_list tmp = rvalue (1);
-
-  if (! tmp.empty ())
-    retval = tmp(0);
-
-  return retval;
-}
-
-octave_lvalue
-tree_indirect_ref::lvalue (void)
-{
-  octave_lvalue tmp = expr->lvalue ();
-
-  if (tmp.is_undefined () || ! tmp.is_map ())
-    tmp.define (Octave_map ());
-
-  return tmp.struct_elt_ref (nm);
-}
-
-void
-tree_indirect_ref::accept (tree_walker& tw)
-{
-  tw.visit_indirect_ref (*this);
-}
-
-void
-tree_indirect_ref::eval_error (void) const
-{
-  if (error_state > 0)
-    ::error ("evaluating structure reference operator near line %d, column %d",
-	     line (), column ());
-}
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/src/pt-indir.h	Sat May 04 02:47:14 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
-
-Copyright (C) 1996, 1997 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-#if !defined (octave_tree_indirect_ref_h)
-#define octave_tree_indirect_ref_h 1
-
-#if defined (__GNUG__)
-#pragma interface
-#endif
-
-#include <iostream>
-#include <string>
-
-class octave_value;
-class octave_value_list;
-class tree_walker;
-
-#include "pt-exp.h"
-
-// Indirect references to values (structure references).
-
-class
-tree_indirect_ref : public tree_expression
-{
-public:
-
-  tree_indirect_ref (int l = -1, int c = -1)
-    : tree_expression (l, c), expr (0), nm () { }
-
-  tree_indirect_ref (tree_expression *e, const std::string& n,
-		     int l = -1, int c = -1)
-    : tree_expression (l, c), expr (e), nm (n) { }
-
-  ~tree_indirect_ref (void);
-
-  bool is_indirect_ref (void) const
-    { return true; }
-
-  std::string name (void) const;
-
-  bool lvalue_ok (void) const
-    { return true; }
-
-  octave_value rvalue (void);
-
-  octave_value_list rvalue (int nargout);
-
-  octave_lvalue lvalue (void);
-
-  tree_expression *expression (void)
-    { return expr; }
-
-  std::string elt_name (void)
-    { return nm; }
-
-  void accept (tree_walker& tw);
-
-private:
-
-  // The LHS of this structure reference.
-  tree_expression *expr;
-
-  // The sub-element name.
-  std::string nm;
-
-  void eval_error (void) const;
-
-  // No copying!
-
-  tree_indirect_ref (const tree_indirect_ref&);
-
-  tree_indirect_ref& operator = (const tree_indirect_ref&);
-};
-
-#endif
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/src/pt-pr-code.cc	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-pr-code.cc	Tue May 07 00:47:31 2002 +0000
@@ -486,31 +486,20 @@
 
   tree_argument_list *list = expr.arg_list ();
 
-  if (list)
+  if (expr.expr_type () == tree_index_expression::dot)
+    {
+      os << "." << expr.struct_elt_name ();
+    }
+  else if (list)
     {
       os << " (";
       list->accept (*this);
       os << ")";
     }
   else if (expr_has_parens)
-    os << " ()";
-
-  print_parens (expr, ")");
-}
-
-void
-tree_print_code::visit_indirect_ref (tree_indirect_ref& expr)
-{
-  indent ();
-
-  print_parens (expr, "(");
-
-  tree_expression *e = expr.expression ();
-
-  if (e)
-    e->accept (*this);
-
-  os << "." << expr.elt_name ();
+    {
+      os << " ()";
+    }
 
   print_parens (expr, ")");
 }
--- a/src/pt-pr-code.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-pr-code.h	Tue May 07 00:47:31 2002 +0000
@@ -85,8 +85,6 @@
 
   void visit_index_expression (tree_index_expression&);
 
-  void visit_indirect_ref (tree_indirect_ref&);
-
   void visit_matrix (tree_matrix&);
 
   void visit_cell (tree_cell&);
--- a/src/pt-walk.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/pt-walk.h	Tue May 07 00:47:31 2002 +0000
@@ -42,7 +42,6 @@
 class tree_switch_case_list;
 class tree_switch_command;
 class tree_index_expression;
-class tree_indirect_ref;
 class tree_matrix;
 class tree_cell;
 class tree_multi_assignment;
@@ -132,9 +131,6 @@
   visit_index_expression (tree_index_expression&) = 0;
 
   virtual void
-  visit_indirect_ref (tree_indirect_ref&) = 0;
-
-  virtual void
   visit_matrix (tree_matrix&) = 0;
 
   virtual void
--- a/src/variables.h	Sat May 04 02:47:14 2002 +0000
+++ b/src/variables.h	Tue May 07 00:47:31 2002 +0000
@@ -28,7 +28,6 @@
 class symbol_table;
 
 class tree_identifier;
-class tree_indirect_ref;
 class octave_value;
 class octave_value_list;
 class octave_builtin;