changeset 2990:35bd1b05cfbe

[project @ 1997-05-16 09:19:11 by jwe]
author jwe
date Fri, 16 May 1997 09:19:12 +0000
parents 6a7b578b6fb4
children fc751d2a99fd
files src/ChangeLog src/parse.y src/pt-colon.h src/pt-mat.cc src/pt-mat.h
diffstat 5 files changed, 62 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
 Fri May 16 00:07:11 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* pt-colon.h (tree_colon_expression::save_base): New data memmber.
+	(tree_colon_expression::preserve_base): New function.
+	* parse.y (finish_colon_expression): When converting to a simple
+	expression, be sure to delete the original colon expression but
+	not the base value.
+
+	* pt-mat.cc (tree_matrix::~tree_matrix): Actually do something.
+
 	* pt-all.h: New file.
 	* parse.y, lex.l, pt-pr-code.cc: Use it.
 
--- a/src/parse.y
+++ b/src/parse.y
@@ -1556,8 +1556,8 @@
 	}
       else
 	{
-	  // XXX FIXME XXX -- need to delete this without deleting base too.
-	  // delete e;
+	  e->preserve_base ();
+	  delete e;
 
 	  // XXX FIXME XXX -- need to attempt constant folding here
 	  // too (we need a generic way to do that).
--- a/src/pt-colon.h
+++ b/src/pt-colon.h
@@ -45,18 +45,24 @@
 public:
 
   tree_colon_expression (int l = -1, int c = -1)
-    : tree_expression (l, c), op_base (0), op_limit (0), op_increment (0) { }
+    : tree_expression (l, c), op_base (0), op_limit (0),
+      op_increment (0), save_base (false) { }
 
   tree_colon_expression (tree_expression *e, int l = -1, int c = -1)
-    : tree_expression (l, c), op_base (e), op_limit (0), op_increment (0) { }
+    : tree_expression (l, c), op_base (e), op_limit (0),
+      op_increment (0), save_base (false) { }
 
   ~tree_colon_expression (void)
     {
-      delete op_base;
+      if (! save_base)
+	delete op_base;
+
       delete op_limit;
       delete op_increment;
     }
 
+  void preserve_base (void) { save_base = true; }
+
   tree_colon_expression *append (tree_expression *t);
 
   bool rvalue_ok (void) const
@@ -83,6 +89,8 @@
   tree_expression *op_limit;
   tree_expression *op_increment;
 
+  bool save_base;
+
   // No copying!
 
   tree_colon_expression (const tree_colon_expression&);
--- a/src/pt-mat.cc
+++ b/src/pt-mat.cc
@@ -104,38 +104,40 @@
 
 public:
 
-  tm_row_const (void) : rep (0) { }
+  tm_row_const (void)
+    : rep (0) { }
 
   tm_row_const (const tree_argument_list& row)
     : rep (new tm_row_const_rep (row)) { }
 
-  tm_row_const (const tm_row_const& x) : rep (x.rep)
-    {
-      if (rep)
-	rep->count++;
-    }
+  tm_row_const (const tm_row_const& x)
+    : rep (x.rep)
+  {
+    if (rep)
+      rep->count++;
+  }
 
   tm_row_const& operator = (const tm_row_const& x)
-    {
-      if (this != &x && rep != x.rep)
-	{
-	  if (rep && --rep->count == 0)
-	    delete rep;
+  {
+    if (this != &x && rep != x.rep)
+      {
+	if (rep && --rep->count == 0)
+	  delete rep;
 
-	  rep = x.rep;
+	rep = x.rep;
 
-	  if (rep)
-	    rep->count++;
-	}
+	if (rep)
+	  rep->count++;
+      }
 
-      return *this;
-    }
+    return *this;
+  }
 
   ~tm_row_const (void)
-    {
-      if (rep && --rep->count == 0)
-	delete rep;
-    }
+  {
+    if (rep && --rep->count == 0)
+      delete rep;
+  }
 
   int rows (void) { return rep->nr; }
   int cols (void) { return rep->nc; }
@@ -153,10 +155,10 @@
   void next (Pix& p) const { rep->next (p); }
   
   operator void* () const
-    {
-      return (rep && rep->ok)
-	? static_cast<void *> (-1) : static_cast<void *> (0);
-    }
+  {
+    return (rep && rep->ok)
+      ? static_cast<void *> (-1) : static_cast<void *> (0);
+  }
 
 private:
 
@@ -379,6 +381,15 @@
   ok = ! error_state;
 }
 
+tree_matrix::~tree_matrix (void)
+{
+  while (! empty ())
+    {
+      tree_argument_list *t = remove_front ();
+      delete t;
+    }
+}
+
 bool
 tree_matrix::all_elements_are_constant (void) const
 {
--- a/src/pt-mat.h
+++ b/src/pt-mat.h
@@ -49,12 +49,12 @@
 
   tree_matrix (tree_argument_list *row = 0)
     : tree_expression (), SLList<tree_argument_list *> ()
-      {
-	if (row)
-	  append (row);
-      }
+  {
+    if (row)
+      append (row);
+  }
 
-  ~tree_matrix (void) { }
+  ~tree_matrix (void);
 
   bool all_elements_are_constant (void) const;