changeset 3110:fe2d1ae8926b

[project @ 1997-11-21 02:11:19 by jwe]
author jwe
date Fri, 21 Nov 1997 02:11:20 +0000
parents fcb2f5063e7f
children fe6f9bd9d0e6
files src/ChangeLog src/octave.cc src/ov-ch-mat.h src/parse.y src/pt-mat.cc
diffstat 5 files changed, 114 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,26 @@
+Thu Nov 20 15:16:22 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* octave.cc (maximum_braindamage): Bind implicit_num_to_str_ok to 1.
+	* pt-mat.cc (Vimplicit_num_to_str_ok): New static variable.
+	(implicit_num_to_str_ok): New function.
+	(symbols_of_pt_mat): DEFVAR implicit_num_to_str_ok.
+	(tm_row_const::some_str): New data member.
+	(tm_row_const::some_strings_p): New function.
+	(tm_row_const::init): Set some_str.
+	(tm_const::some_str): New data member.
+	(tm_const::some_strings_p): New function.
+	(tm_const::init): Set some_str.
+	(tree_matrix::eval): If Vimplicit_num_to_str_ok is true and some
+	of the elements are strings, force a string conversion before
+	returning.
+
+	* parse.y (fold, finish_colon_expression, finish_matrix):
+	If an error occurs, return the original expression.
+	Use unwind_protect to restore error_state.
+
+	* ov-ch-mat.h (octave_char_matrix::convert_to_str): Result is
+	char_matrix_str, not just char_matrix.
+
 Wed Nov 19 02:05:40 1997  Mumit Khan <khan@dhaka.xraylith.wisc.edu>
 
 	* DLD-FUNCTIONS/filter.cc: Don't include extern template decls if
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -332,6 +332,7 @@
   bind_builtin_variable ("do_fortran_indexing", 1.0);
   bind_builtin_variable ("empty_list_elements_ok", 1.0);
   bind_builtin_variable ("fixed_point_format", 1.0);
+  bind_builtin_variable ("implicit_num_to_str_ok", 1.0);
   bind_builtin_variable ("implicit_str_to_num_ok", 1.0);
   bind_builtin_variable ("ok_to_lose_imaginary_part", 1.0);
   bind_builtin_variable ("page_screen_output", 0.0);
--- a/src/ov-ch-mat.h
+++ b/src/ov-ch-mat.h
@@ -118,7 +118,7 @@
   charMatrix char_matrix_value (bool = false) const { return matrix; }
 
   octave_value convert_to_str (void) const
-    { return octave_value (matrix); }
+    { return octave_value (matrix, true); }
 
   octave_value transpose (void) const
     { return octave_value (matrix.transpose ()); }
--- a/src/parse.y
+++ b/src/parse.y
@@ -1489,7 +1489,16 @@
 static tree_expression *
 fold (tree_binary_expression *e)
 {
-  tree_expression *retval = 0;
+  tree_expression *retval = e;
+
+  unwind_protect::begin_frame ("fold");
+
+  unwind_protect_int (error_state);
+
+  unwind_protect_bool (buffer_error_messages);
+  buffer_error_messages = true;
+
+  unwind_protect::add (clear_global_error_variable, 0);
 
   tree_expression *op1 = e->lhs ();
   tree_expression *op2 = e->rhs ();
@@ -1520,11 +1529,9 @@
 
 	  retval = tc_retval;
 	}
-      else
-	delete e;
     }
-  else
-    retval = e;
+
+  unwind_protect::run_frame ("fold");
 
   return retval;
 }
@@ -1534,7 +1541,16 @@
 static tree_expression *
 finish_colon_expression (tree_colon_expression *e)
 {
-  tree_expression *retval = 0;
+  tree_expression *retval = e;
+
+  unwind_protect::begin_frame ("finish_colon_expression");
+
+  unwind_protect_int (error_state);
+
+  unwind_protect_bool (buffer_error_messages);
+  buffer_error_messages = true;
+
+  unwind_protect::add (clear_global_error_variable, 0);
 
   tree_expression *base = e->base ();
   tree_expression *limit = e->limit ();
@@ -1571,11 +1587,7 @@
 
 		  retval = tc_retval;
 		}
-	      else
-		delete e;
 	    }
-	  else
-	    retval = e;
 	}
       else
 	{
@@ -1588,6 +1600,8 @@
 	}
     }
 
+  unwind_protect::run_frame ("finish_colon_expression");
+
   return retval;
 }
 
@@ -1803,6 +1817,8 @@
   int l = tok_val->line ();
   int c = tok_val->column ();
 
+  // XXX FIXME XXX -- what about constant folding here?
+
   return new tree_prefix_expression (t, op1, l, c);
 }
 
@@ -1839,6 +1855,8 @@
   int l = tok_val->line ();
   int c = tok_val->column ();
 
+  // XXX FIXME XXX -- what about constant folding here?
+
   return new tree_postfix_expression (t, op1, l, c);
 }
 
@@ -2320,7 +2338,16 @@
 static tree_expression *
 finish_matrix (tree_matrix *m)
 {
-  tree_expression *retval = 0;
+  tree_expression *retval = m;
+
+  unwind_protect::begin_frame ("finish_matrix");
+
+  unwind_protect_int (error_state);
+
+  unwind_protect_bool (buffer_error_messages);
+  buffer_error_messages = true;
+
+  unwind_protect::add (clear_global_error_variable, 0);
 
   if (m->all_elements_are_constant ())
     {
@@ -2348,11 +2375,9 @@
 
 	  retval = tc_retval;
 	}
-      else
-	delete m;
     }
-  else
-    retval = m;
+
+  unwind_protect::run_frame ("finish_matrix");
 
   return retval;
 }
--- a/src/pt-mat.cc
+++ b/src/pt-mat.cc
@@ -48,6 +48,9 @@
 // Zero means it should be considered an error.
 static int Vempty_list_elements_ok;
 
+// Should `[97, 98, 99, "123"]' be a string?
+static bool Vimplicit_num_to_str_ok;
+
 // The character to fill with when creating string arrays.
 static char Vstring_fill_char;
 
@@ -69,12 +72,14 @@
 
     tm_row_const_rep (void)
       : SLList<octave_value> (), count (1), nr (0), nc (0),
-	all_str (false), is_cmplx (false), all_mt (true), ok (false) { }
+	all_str (false), some_str (false), is_cmplx (false),
+	all_mt (true), ok (false) { }
 
     tm_row_const_rep (const tree_argument_list& row)
       : SLList<octave_value> (), count (1), nr (0), nc (0),
-	all_str (false), is_cmplx (false), all_mt (true), ok (false)
-        { init (row); }
+	all_str (false), some_str (false), is_cmplx (false),
+	all_mt (true), ok (false)
+    { init (row); }
 
     ~tm_row_const_rep (void) { }
 
@@ -84,6 +89,7 @@
     int nc;
 
     bool all_str;
+    bool some_str;
     bool is_cmplx;
     bool all_mt;
 
@@ -143,6 +149,7 @@
   int cols (void) { return rep->nc; }
 
   bool all_strings_p (void) const { return rep->all_str; }
+  bool some_strings_p (void) const { return rep->some_str; }
   bool complex_p (void) const { return rep->is_cmplx; }
   bool all_empty_p (void) const { return rep->all_mt; }
 
@@ -222,6 +229,9 @@
 	  if (all_str && ! tmp.is_string ())
 	    all_str = false;
 
+	  if (! some_str && tmp.is_string ())
+	    some_str = true;
+
 	  if (! is_cmplx && tmp.is_complex_type ())
 	    is_cmplx = true;
 	}
@@ -262,8 +272,9 @@
 public:
 
   tm_const (const tree_matrix& tm)
-    : SLList<tm_row_const> (), nr (0), nc (0), all_str (false),
-      is_cmplx (false), all_mt (true), ok (false)
+    : SLList<tm_row_const> (), nr (0), nc (0),
+      all_str (false), some_str (false), is_cmplx (false),
+      all_mt (true), ok (false)
       { init (tm); }
 
   ~tm_const (void) { }
@@ -272,6 +283,7 @@
   int cols (void) const { return nc; }
 
   bool all_strings_p (void) const { return all_str; }
+  bool some_strings_p (void) const { return some_str; }
   bool complex_p (void) const { return is_cmplx; }
   bool all_empty_p (void) const { return all_mt; }
 
@@ -284,6 +296,7 @@
   int nc;
 
   bool all_str;
+  bool some_str;
   bool is_cmplx;
   bool all_mt;
 
@@ -321,6 +334,9 @@
 	  if (all_str && ! tmp.all_strings_p ())
 	    all_str = false;
 
+	  if (! some_str && tmp.some_strings_p ())
+	    some_str = true;
+
 	  if (! is_cmplx && tmp.complex_p ())
 	    is_cmplx = true;
 
@@ -429,8 +445,11 @@
   tm_const tmp (*this);
 
   bool all_strings_p = false;
+  bool some_strings_p = false;
   bool all_empty_p = false;
 
+  bool frc_str_conv = false;
+
   if (tmp)
     {
       int nr = tmp.rows ();
@@ -446,8 +465,11 @@
       bool found_complex = tmp.complex_p ();
 
       all_strings_p = tmp.all_strings_p ();
+      some_strings_p = tmp.some_strings_p ();
       all_empty_p = tmp.all_empty_p ();
 
+      frc_str_conv = Vimplicit_num_to_str_ok && some_strings_p;
+
       if (all_strings_p)
 	chm.resize (nr, nc, Vstring_fill_char);
       else if (found_complex)
@@ -500,7 +522,7 @@
 		    }
 		  else
 		    {
-		      Matrix m_elt = elt.matrix_value ();
+		      Matrix m_elt = elt.matrix_value (frc_str_conv);
 
 		      if (error_state)
 			goto done;
@@ -525,12 +547,17 @@
 
 done:
 
-  if (! error_state && retval.is_undefined () && all_empty_p)
+  if (! error_state)
     {
-      if (all_strings_p)
-	retval = "";
-      else
-	retval = Matrix ();
+      if (retval.is_undefined () && all_empty_p)
+	{
+	  if (all_strings_p)
+	    retval = "";
+	  else
+	    retval = Matrix ();
+	}
+      else if (frc_str_conv && ! retval.is_string ())
+	retval = retval.convert_to_str ();
     }
 
   return retval;
@@ -551,6 +578,14 @@
 }
 
 static int
+implicit_num_to_str_ok (void)
+{
+  Vimplicit_num_to_str_ok = check_preference ("implicit_num_to_str_ok");
+
+  return 0;
+}
+
+static int
 string_fill_char (void)
 {
   int status = 0;
@@ -582,6 +617,9 @@
   DEFVAR (empty_list_elements_ok, "warn", 0, empty_list_elements_ok,
     "ignore the empty element in expressions like `a = [[], 1]'");
 
+  DEFVAR (implicit_num_to_str_ok, 0.0, 0, implicit_num_to_str_ok,
+    "make the result of things like `[97, 98, 99, \"123\"]' be a string");
+
   DEFVAR (string_fill_char, " ", 0, string_fill_char,
     "the character to fill with when creating string arrays.");
 }