changeset 4466:b18007283045

[project @ 2003-07-15 11:43:28 by jwe]
author jwe
date Tue, 15 Jul 2003 11:43:29 +0000
parents 8290e9c9d4f6
children 78046131cc16
files ChangeLog doc/faq/Octave-FAQ.texi doc/interpreter/basics.txi doc/interpreter/func.txi doc/interpreter/var.txi emacs/octave-mod.el scripts/ChangeLog scripts/miscellaneous/dump_prefs.m src/ChangeLog src/octave.cc src/ov-usr-fcn.cc src/pt-misc.cc src/pt-misc.h test/octave.test/prefer/prefer-25.m test/octave.test/prefer/prefer.exp
diffstat 15 files changed, 98 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jul 14 15:46:05 2003 +0000
+++ b/ChangeLog	Tue Jul 15 11:43:29 2003 +0000
@@ -1,3 +1,9 @@
+2003-07-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* emacs/octave-mod.el (octave-variables): Delete
+	default_return_value and define_all_return_values from the list.
+	Add warn_undefined_return_values to the list.
+
 2003-07-11  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* emacs/octave-mod.el (octave-variables):
--- a/doc/faq/Octave-FAQ.texi	Mon Jul 14 15:46:05 2003 +0000
+++ b/doc/faq/Octave-FAQ.texi	Tue Jul 15 11:43:29 2003 +0000
@@ -721,7 +721,6 @@
   beep_on_error                 = true
   crash_dumps_octave_core       = false
   default_save_format           = "mat-binary"
-  define_all_return_values      = true
   fixed_point_format            = true
   page_screen_output            = false
   print_empty_dimensions        = false
--- a/doc/interpreter/basics.txi	Mon Jul 14 15:46:05 2003 +0000
+++ b/doc/interpreter/basics.txi	Tue Jul 15 11:43:29 2003 +0000
@@ -161,7 +161,6 @@
   beep_on_error                 = true
   crash_dumps_octave_core       = false
   default_save_format           = "mat-binary"
-  define_all_return_values      = true
   fixed_point_format            = true
   page_screen_output            = false
   print_empty_dimensions        = false
--- a/doc/interpreter/func.txi	Mon Jul 14 15:46:05 2003 +0000
+++ b/doc/interpreter/func.txi	Tue Jul 15 11:43:29 2003 +0000
@@ -317,9 +317,8 @@
 @end example
 
 @noindent
-provided that the built-in variable @code{define_all_return_values} is
-nonzero and the value of @code{default_return_value} is @samp{[]}.
-@xref{Summary of Built-in Variables}.
+along with a warning if the value of the built-in variable
+@code{warn_undefined_return_values} is nonzero.
 
 @defvr {Automatic Variable} nargout
 When a function is called, this local variable is automatically
@@ -345,9 +344,7 @@
 At the top level, @code{nargout} is undefined.
 @end defvr
 
-@DOCSTRING(default_return_value)
-
-@DOCSTRING(define_all_return_values)
+@DOCSTRING(warn_undefined_return_values)
 
 @DOCSTRING(nargchk)
 
--- a/doc/interpreter/var.txi	Mon Jul 14 15:46:05 2003 +0000
+++ b/doc/interpreter/var.txi	Tue Jul 15 11:43:29 2003 +0000
@@ -237,11 +237,6 @@
 
 Default value: @code{" "}.
 
-@item default_return_value
-@xref{Multiple Return Values}.
-
-Default value: @code{[]}.
-
 @item default_save_format
 @xref{Simple File I/O}.
 
@@ -252,11 +247,6 @@
 
 Default value: 1.
 
-@item define_all_return_values
-@xref{Multiple Return Values}.
-
-Default value: 0.
-
 @item fixed_point_format
 @xref{Matrices}.
 
@@ -407,11 +397,6 @@
 
 Default value: 1.
 
-@item warn_str_to_num
-@xref{String Conversions}.
-
-Default value: 0.
-
 @item warn_reload_forces_clear
 @xref{Dynamically Linked Functions}.
 
@@ -427,6 +412,16 @@
 
 Default value: 0.
 
+@item warn_str_to_num
+@xref{String Conversions}.
+
+Default value: 0.
+
+@item warn_undefined_return_values
+@xref{Multiple Return Values}.
+
+Default value: 0.
+
 @item warn_variable_switch_label
 @xref{The switch Statement}.
 
--- a/emacs/octave-mod.el	Mon Jul 14 15:46:05 2003 +0000
+++ b/emacs/octave-mod.el	Tue Jul 15 11:43:29 2003 +0000
@@ -140,8 +140,8 @@
     "__program_invocation_name__" "__program_name__" "__realmax__"
     "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv"
     "automatic_replot" "beep_on_error" "completion_append_char"
-    "crash_dumps_octave_core" "default_return_value" "default_save_format"
-    "define_all_return_values" "e" "echo_executing_commands" "eps"
+    "crash_dumps_octave_core" "default_save_format"
+    "e" "echo_executing_commands" "eps"
     "error_text" "gnuplot_binary" "history_file"
     "history_size" "ignore_function_time_stamp"
     "inf" "nan" "nargin" "output_max_field_width" "output_precision"
@@ -160,7 +160,7 @@
     "warn_neg_dim_as_zero" "warn_num_to_str" "warn_precedence_change"
     "warn_reload_forces_clear" "warn_separator_insert"
     "warn_single_quote_string" "warn_str_to_num"
-    "warn_variable_switch_label")
+    "warn_undefined_return_values" "warn_variable_switch_label")
   "Builtin variables in Octave.")
 
 (defvar octave-function-header-regexp
--- a/scripts/ChangeLog	Mon Jul 14 15:46:05 2003 +0000
+++ b/scripts/ChangeLog	Tue Jul 15 11:43:29 2003 +0000
@@ -1,3 +1,10 @@
+2003-07-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* miscellaneous/dump_prefs.m: Delete define_all_return_values and
+	default_return_value from the list.
+	Add warn_undefined_return_values to the list.
+	
+
 2003-07-13  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* miscellaneous/dump_prefs.m: Delete default_global_variable_value
--- a/scripts/miscellaneous/dump_prefs.m	Mon Jul 14 15:46:05 2003 +0000
+++ b/scripts/miscellaneous/dump_prefs.m	Tue Jul 15 11:43:29 2003 +0000
@@ -53,9 +53,7 @@
               "beep_on_error";
               "completion_append_char";
               "crash_dumps_octave_core";
-              "default_return_value";
               "default_save_format";
-              "define_all_return_values";
               "echo_executing_commands";
               "fixed_point_format";
               "gnuplot_binary";
@@ -101,6 +99,7 @@
               "warn_num_to_str";
               "warn_resize_on_range_error";
               "warn_str_to_num";
+              "warn_undefined_return_values";
               "warn_variable_switch_label";
               "whitespace_in_literal_matrix"];
 
--- a/src/ChangeLog	Mon Jul 14 15:46:05 2003 +0000
+++ b/src/ChangeLog	Tue Jul 15 11:43:29 2003 +0000
@@ -1,3 +1,22 @@
+2003-07-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* pt-misc.cc (tree_parameter_list::initialize_undefined_elements):
+	New args, warnfor and nargout.  Change all callers.
+	(symbols_of_pt_misc): New function.
+	(warn_undefined_return_values): New function.
+
+	* octave.cc (maximum_braindamage): Don't set
+	define_all_return_values.
+
+	* ov-usr-fcn.cc (ov_user_function::do_multi_index_op): Always
+	intiialize undefined elements in ret_list to [].
+	Never return last computed value.
+	(Vreturn_last_computed_value, Vdefine_all_return_values): Delete.
+	(return_last_computed_value, define_all_return_values): Delete.
+	(symbols_of_ov_usr_fcn): Delete DEFVARs for
+	return_last_computed_value, define_all_return_values, and
+	default_return_value.
+
 2003-07-14  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* pt-misc.cc (tree_parameter_list::convert_to_const_vector):
--- a/src/octave.cc	Mon Jul 14 15:46:05 2003 +0000
+++ b/src/octave.cc	Tue Jul 15 11:43:29 2003 +0000
@@ -347,7 +347,6 @@
   bind_builtin_variable ("beep_on_error", true);
   bind_builtin_variable ("crash_dumps_octave_core", false);
   bind_builtin_variable ("default_save_format", "mat-binary");
-  bind_builtin_variable ("define_all_return_values", true);
   bind_builtin_variable ("fixed_point_format", true);
   bind_builtin_variable ("page_screen_output", false);
   bind_builtin_variable ("print_empty_dimensions", false);
--- a/src/ov-usr-fcn.cc	Mon Jul 14 15:46:05 2003 +0000
+++ b/src/ov-usr-fcn.cc	Tue Jul 15 11:43:29 2003 +0000
@@ -51,17 +51,9 @@
 #include "parse.h"
 #include "variables.h"
 
-// If TRUE, variables returned from functions have default values even
-// if they are not explicitly initialized.
-static bool Vdefine_all_return_values;
-
 // Maximum nesting level for functions called recursively.
 static int Vmax_recursion_depth;
 
-// If TRUE, the last computed value is returned from functions that
-// don't actually define any return variables.
-static bool Vreturn_last_computed_value;
-
 // User defined functions.
 
 DEFINE_OCTAVE_ALLOCATOR (octave_user_function);
@@ -492,21 +484,14 @@
 
     if (ret_list)
       {
-	if (Vdefine_all_return_values)
-	  {
-	    octave_value tmp = builtin_any_variable ("default_return_value");
-
-	    if (tmp.is_defined ())
-	      ret_list->initialize_undefined_elements (tmp);
-	  }
+	ret_list->initialize_undefined_elements (function_name (),
+						 nargout, Matrix ());
 
 	if (has_varargout ())
 	  varargout_to_vr_val ();
 
 	retval = ret_list->convert_to_const_vector (vr_list);
       }
-    else if (Vreturn_last_computed_value)
-      retval(0) = last_computed_value;
   }
 
  abort:
@@ -735,14 +720,6 @@
 }
 
 static int
-define_all_return_values (void)
-{
-  Vdefine_all_return_values = check_preference ("define_all_return_values");
-
-  return 0;
-}
-
-static int
 max_recursion_depth (void)
 {
   Vmax_recursion_depth = check_preference ("max_recursion_depth");
@@ -750,35 +727,9 @@
   return 0;
 }
 
-static int
-return_last_computed_value (void)
-{
-  Vreturn_last_computed_value
-    = check_preference ("return_last_computed_value");
-
-  return 0;
-}
-
 void
 symbols_of_ov_usr_fcn (void)
 {
-  DEFVAR (default_return_value, Matrix (), 0,
-    "-*- texinfo -*-\n\
-@defvr {Built-in Variable} default_return_value\n\
-The value given to otherwise uninitialized return values if\n\
-@code{define_all_return_values} is nonzero.  The default value is\n\
-@code{[]}.\n\
-@end defvr");
-
-  DEFVAR (define_all_return_values, false, define_all_return_values,
-    "-*- texinfo -*-\n\
-@defvr {Built-in Variable} define_all_return_values\n\
-If the value of @code{define_all_return_values} is nonzero, Octave\n\
-will substitute the value specified by @code{default_return_value} for\n\
-any return values that remain undefined when a function returns.  The\n\
-default value is 0.\n\
-@end defvr");
-
   DEFVAR (max_recursion_depth, 256.0, max_recursion_depth,
     "-*- texinfo -*-\n\
 @defvr {Built-in Variable} max_recursion_depth\n\
@@ -788,28 +739,6 @@
 \n\
 The default value is 256.\n\
 @end defvr");
-
-  DEFVAR (return_last_computed_value, false, return_last_computed_value,
-    "-*- texinfo -*-\n\
-@defvr {Built-in Variable} return_last_computed_value\n\
-If the value of @code{return_last_computed_value} is true, and a\n\
-function is defined without explicitly specifying a return value, the\n\
-function will return the value of the last expression.  Otherwise, no\n\
-value will be returned.  The default value is 0.\n\
-\n\
-For example, the function\n\
-\n\
-@example\n\
-function f ()\n\
-  2 + 2;\n\
-endfunction\n\
-@end example\n\
-\n\
-@noindent\n\
-will either return nothing, if the value of\n\
-@code{return_last_computed_value} is 0, or 4, if the value of\n\
-@code{return_last_computed_value} is nonzero.\n\
-@end defvr");
 }
 
 /*
--- a/src/pt-misc.cc	Mon Jul 14 15:46:05 2003 +0000
+++ b/src/pt-misc.cc	Tue Jul 15 11:43:29 2003 +0000
@@ -28,6 +28,7 @@
 #include <config.h>
 #endif
 
+#include "defun.h"
 #include "error.h"
 #include "ov.h"
 #include "oct-lvalue.h"
@@ -35,6 +36,11 @@
 #include "pt-idx.h"
 #include "pt-misc.h"
 #include "pt-walk.h"
+#include "utils.h"
+
+// If TRUE, print a warning if a function does not define all the
+// values in the return list which are expected.
+static bool Vwarn_undefined_return_values;
 
 // Parameter lists.
 
@@ -59,14 +65,30 @@
 }
 
 void
-tree_parameter_list::initialize_undefined_elements (const octave_value& val)
+tree_parameter_list::initialize_undefined_elements (const std::string& warnfor,
+						    int nargout,
+						    const octave_value& val)
 {
+  bool warned = false;
+
+  int count = 0;
+
   for (iterator p = begin (); p != end (); p++)
     {
+      if (++count > nargout)
+	break;
+
       tree_identifier *elt = *p;
 
       if (! elt->is_defined ())
 	{
+	  if (Vwarn_undefined_return_values && ! warned)
+	    {
+	      warned = true;
+	      warning ("%s: some elements in list of return values are undefined",
+		       warnfor.c_str ());
+	    }
+
 	  octave_lvalue tmp = elt->lvalue ();
 
 	  tmp.assign (octave_value::op_asn_eq, val);
@@ -200,6 +222,27 @@
   tw.visit_return_list (*this);
 }
 
+static int
+warn_undefined_return_values (void)
+{
+  Vwarn_undefined_return_values
+    = check_preference ("warn_undefined_return_values");
+
+  return 0;
+}
+
+void
+symbols_of_pt_misc (void)
+{
+  DEFVAR (warn_undefined_return_values, true, warn_undefined_return_values,
+    "-*- texinfo -*-\n\
+@defvr {Built-in Variable} warn_undefined_return_values\n\
+If the value of @code{warn_undefined_return_values} is nonzero,\n\
+print a warning if a function does not define all the values in\n\
+the return list which are expected.  The default value is 1.\n\
+@end defvr");
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/pt-misc.h	Mon Jul 14 15:46:05 2003 +0000
+++ b/src/pt-misc.h	Tue Jul 15 11:43:29 2003 +0000
@@ -65,7 +65,8 @@
 
   bool varargs_only (void) { return (marked_for_varargs < 0); }
 
-  void initialize_undefined_elements (const octave_value& val);
+  void initialize_undefined_elements (const std::string& warnfor,
+				      int nargout, const octave_value& val);
 
   void define_from_arg_vector (const octave_value_list& args);
 
--- a/test/octave.test/prefer/prefer-25.m	Mon Jul 14 15:46:05 2003 +0000
+++ b/test/octave.test/prefer/prefer-25.m	Tue Jul 15 11:43:29 2003 +0000
@@ -1,3 +1,2 @@
-return_last_computed_value = 1;
 function f () 1; end
 f
--- a/test/octave.test/prefer/prefer.exp	Mon Jul 14 15:46:05 2003 +0000
+++ b/test/octave.test/prefer/prefer.exp	Tue Jul 15 11:43:29 2003 +0000
@@ -109,7 +109,7 @@
 ## return_last_computed_value
 
 set test return-last-computed-value-1
-set prog_output "^ans = 1"
+set prog_output "^$"
 do_test prefer-25.m
 
 set test return-last-computed-value-2