# HG changeset patch # User jwe # Date 1057792819 0 # Node ID f3c21a1d1c621f20f4172d274128af5682b5550f # Parent ea1d3e1a4b1b687d5631ab6981e3ee2147750494 [project @ 2003-07-09 23:20:18 by jwe] diff -r ea1d3e1a4b1b -r f3c21a1d1c62 ChangeLog --- a/ChangeLog Wed Jul 09 19:09:09 2003 +0000 +++ b/ChangeLog Wed Jul 09 23:20:19 2003 +0000 @@ -2,9 +2,10 @@ * emacs/octave-mod.el (octave-variables): Include DEFAULT_EXEC_PATH, DEFAULT_LOAD_PATH, crash_dumps_octave_core, - sighup_dumps_octave_core, sigterm_dumps_octave_core, and - warn_imag_to_real in the list. - Delete ok_to_lose_imaginary_part from list. + sighup_dumps_octave_core, sigterm_dumps_octave_core, + warn_imag_to_real, warn_num_to_str, and warn_str_to_num in the list. + Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, and + implicit_str_to_num_ok from the list. 2003-07-08 John W. Eaton diff -r ea1d3e1a4b1b -r f3c21a1d1c62 PROJECTS --- a/PROJECTS Wed Jul 09 19:09:09 2003 +0000 +++ b/PROJECTS Wed Jul 09 23:20:19 2003 +0000 @@ -241,16 +241,6 @@ * Fix the parser so that - function foo () - implicit_str_to_num_ok = 1; - '#' + 0; - endfunction - - succeeds, even when implicit_str_to_num_ok is 0 at the time the - function is parsed. - - * Fix the parser so that - if (expr) 'this is a string' end is parsed as IF expr STRING END. diff -r ea1d3e1a4b1b -r f3c21a1d1c62 doc/faq/Octave-FAQ.texi --- a/doc/faq/Octave-FAQ.texi Wed Jul 09 19:09:09 2003 +0000 +++ b/doc/faq/Octave-FAQ.texi Wed Jul 09 23:20:19 2003 +0000 @@ -725,8 +725,6 @@ do_fortran_indexing = 1.0 empty_list_elements_ok = 1.0 fixed_point_format = 1.0 - implicit_num_to_str_ok = 1.0 - implicit_str_to_num_ok = 1.0 page_screen_output = 0.0 prefer_column_vectors = 0.0 prefer_zero_one_indexing = 1.0 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 doc/interpreter/basics.txi --- a/doc/interpreter/basics.txi Wed Jul 09 19:09:09 2003 +0000 +++ b/doc/interpreter/basics.txi Wed Jul 09 23:20:19 2003 +0000 @@ -163,7 +163,6 @@ do_fortran_indexing = 1 crash_dumps_octave_core = 0 empty_list_elements_ok = 1 -implicit_str_to_num_ok = 1 page_screen_output = 0 prefer_column_vectors = 0 print_empty_dimensions = 0 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 doc/interpreter/strings.txi --- a/doc/interpreter/strings.txi Wed Jul 09 19:09:09 2003 +0000 +++ b/doc/interpreter/strings.txi Wed Jul 09 23:20:19 2003 +0000 @@ -189,9 +189,9 @@ @DOCSTRING(undo_string_escapes) -@DOCSTRING(implicit_num_to_str_ok) +@DOCSTRING(warn_num_to_str) -@DOCSTRING(implicit_str_to_num_ok) +@DOCSTRING(warn_str_to_num) @DOCSTRING(warn_single_quote_string) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 doc/interpreter/var.txi --- a/doc/interpreter/var.txi Wed Jul 09 19:09:09 2003 +0000 +++ b/doc/interpreter/var.txi Wed Jul 09 23:20:19 2003 +0000 @@ -301,16 +301,6 @@ Default value: @code{"system"}. -@item implicit_num_to_str_ok -@xref{String Conversions}. - -Default value: 0. - -@item implicit_str_to_num_ok -@xref{String Conversions}. - -Default value: 0. - @item max_recursion_depth @xref{Recursion}. @@ -416,21 +406,41 @@ Default value: 1. +@item warn_function_name_clash +@xref{Function Files}. + +Default value: 1. + @item warn_imag_to_real @xref{Special Utility Matrices}. Default value: 0. -@item warn_function_name_clash -@xref{Function Files}. +@item warn_missing_semicolon +@xref{Defining Functions}. + +Default value: 0. + +@item warn_num_to_str +@xref{String Conversions}. Default value: 1. +@item warn_str_to_num +@xref{String Conversions}. + +Default value: 0. + @item warn_reload_forces_clear @xref{Dynamically Linked Functions}. Default value: 1. +@item warn_single_quote_string) +@xref{String Conversions}. + +Default value: 0. + @item warn_variable_switch_label @xref{The switch Statement}. diff -r ea1d3e1a4b1b -r f3c21a1d1c62 emacs/octave-mod.el --- a/emacs/octave-mod.el Wed Jul 09 19:09:09 2003 +0000 +++ b/emacs/octave-mod.el Wed Jul 09 23:20:19 2003 +0000 @@ -145,7 +145,7 @@ "define_all_return_values" "do_fortran_indexing" "e" "echo_executing_commands" "empty_list_elements_ok" "eps" "error_text" "gnuplot_binary" "history_file" - "history_size" "ignore_function_time_stamp" "implicit_str_to_num_ok" + "history_size" "ignore_function_time_stamp" "inf" "nan" "nargin" "output_max_field_width" "output_precision" "page_output_immediately" "page_screen_output" "pi" @@ -160,8 +160,8 @@ "suppress_verbose_help_message" "treat_neg_dim_as_zero" "warn_assign_as_truth_value" "warn_comma_in_global_decl" "warn_divide_by_zero" "warn_function_name_clash" - "warn_imag_to_real" - "warn_missing_semicolon" "whitespace_in_literal_matrix") + "warn_imag_to_real" "warn_missing_semicolon" + "warn_num_to_str" "warn_str_to_num" "whitespace_in_literal_matrix") "Builtin variables in Octave.") (defvar octave-function-header-regexp diff -r ea1d3e1a4b1b -r f3c21a1d1c62 scripts/ChangeLog --- a/scripts/ChangeLog Wed Jul 09 19:09:09 2003 +0000 +++ b/scripts/ChangeLog Wed Jul 09 23:20:19 2003 +0000 @@ -1,10 +1,15 @@ 2003-07-09 John W. Eaton + * statistics/base/moment.m: Temporarily set warn_str_to_num, not + implict_str_to_num_ok. Use unwind_protect block to do it. + * miscellaneous/dump_prefs.m: Include DEFAULT_EXEC_PATH, DEFAULT_LOAD_PATH, crash_dumps_octave_core, - sighup_dumps_octave_core, sigterm_dumps_octave_core, and - warn_imag_to_real in the list. - Delete ok_to_lose_imaginary_part from list. + sighup_dumps_octave_core, sigterm_dumps_octave_core, + warn_imag_to_real, warn_num_to_str, and warn_str_to_num in the + list. + Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, and + implicit_str_to_num_ok from list. 2003-07-02 John W. Eaton diff -r ea1d3e1a4b1b -r f3c21a1d1c62 scripts/miscellaneous/dump_prefs.m --- a/scripts/miscellaneous/dump_prefs.m Wed Jul 09 19:09:09 2003 +0000 +++ b/scripts/miscellaneous/dump_prefs.m Wed Jul 09 23:20:19 2003 +0000 @@ -74,8 +74,6 @@ "history_file"; "history_size"; "ignore_function_time_stamp"; - "implicit_num_to_str_ok"; - "implicit_str_to_num_ok"; "initialize_global_variables"; "max_recursion_depth"; "output_max_field_width"; @@ -105,6 +103,8 @@ "warn_future_time_stamp"; "warn_imag_to_real"; "warn_missing_semicolon"; + "warn_num_to_str"; + "warn_str_to_num"; "warn_variable_switch_label"; "whitespace_in_literal_matrix"]; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 scripts/statistics/base/moment.m --- a/scripts/statistics/base/moment.m Wed Jul 09 19:09:09 2003 +0000 +++ b/scripts/statistics/base/moment.m Wed Jul 09 23:20:19 2003 +0000 @@ -57,15 +57,18 @@ endif if (nargin == 3) - tmp = implicit_str_to_num_ok; - implicit_str_to_num_ok = "true"; - if any (opt == "c") - x = x - ones (nr, 1) * sum (x) / nr; - endif - if any (opt == "a") - x = abs (x); - endif - implicit_str_to_num_ok = tmp; + tmp = warn_str_to_num; + unwind_protect + warn_str_to_num = 0; + if any (opt == "c") + x = x - ones (nr, 1) * sum (x) / nr; + endif + if any (opt == "a") + x = abs (x); + endif + unwind_protect_cleanup + warn_str_to_num = tmp; + end_unwind_protect endif m = sum(x .^ p) / nr; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ChangeLog --- a/src/ChangeLog Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ChangeLog Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,54 @@ 2003-07-09 John W. Eaton + * ov.cc (octave_value::convert_to_str): Call convert_to_str_internal. + (octave_value::convert_to_str_internal): New virtual function. + Rename all derived class convert_to_str functions to match. + + * variables.cc (generate_struct_completions): Set + discard_warning_messages, not Vwarning_option. Also protect + warning_state. + + * parse.y (fold): Temporarily discard warning messages. + Also protect warning_state. + + * error.cc (discard_warning_messages): New variable. + (vwarning): Use it. + (warning): Don't print backtrace if discard_warning_messages is true. + + * ov.cc (octave_value::convert_to_str): + Handle type conversion warning here. + + * gripes.cc (gripe_implicit_conversion): + New function accepting std::string args. + + * octave.cc (maximum_braindamage): Don't set + implicit_num_to_str_ok or implicit_str_to_num_ok. + + * ov-base.cc (octave_base_value::char_matrix_value): + Vimplicit_num_to_str_ok no longer exists. + (octave_base_value::all_strings): Likewise. + (octave_base_value::string_value): Likewise. + + * ov-str-mat.cc (octave_char_matrix_str::matrix_value): Warn based + on Vwarn_str_to_num instead of Vimplicit_str_to_num_ok. + + * ov.cc (Vwarn_num_to_str, Vwarn_str_to_num): New variables. + (warn_num_to_str, warn_str_to_num): New functions. + (symbols_of_ov): Add DEFVARs for warn_num_to_str and Vwarn_str_to_num. + * ov.h (Vwarn_num_to_str, Vwarn_str_to_num): Provide decl. + + * ov.cc (Vimplicit_num_to_str_ok, Vimplicit_str_to_num_ok): + Delete unused variables. + (implicit_num_to_str_ok, implicit_str_to_num_ok): + Delete unused functions. + (symbols_of_ov): Delete DEFVARs for implicit_num_to_str_ok and + implicit_str_to_num_ok. + * ov.h (Vimplicit_num_to_str_ok, Vimplicit_str_to_num_ok): + Delete decls. + + * pt-mat.cc (tree_matrix::rvalue): Vimplicit_num_to_str_ok no + longer exists. + * ov.cc (Vwarn_imag_to_real): New variable. (warn_imag_to_real): New function. (symbols_of_ov): Add DEFVAR for warn_imag_to_real. diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/error.cc --- a/src/error.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/error.cc Wed Jul 09 23:20:19 2003 +0000 @@ -100,6 +100,9 @@ // TRUE means error messages are turned off. bool discard_error_messages = false; +// TRUE means warning messages are turned off. +bool discard_warning_messages = false; + // The message buffer. static OSSTREAM *error_message_buffer = 0; @@ -117,6 +120,9 @@ static void vwarning (const char *name, const char *fmt, va_list args) { + if (discard_warning_messages) + return; + flush_octave_stdout (); OSSTREAM output_buf; @@ -358,7 +364,8 @@ { if (curr_sym_tab != top_level_sym_tab && Vwarning_option == "backtrace" - && ! warning_state) + && ! warning_state + && ! discard_warning_messages) pr_where ("warning"); va_list args; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/error.h --- a/src/error.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/error.h Wed Jul 09 23:20:19 2003 +0000 @@ -52,6 +52,9 @@ // TRUE means error messages are turned off. extern bool discard_error_messages; +// TRUE means warning messages are turned off. +extern bool discard_warning_messages; + // The current warning state. Valid values are "on", "off", // "backtrace", or "debug". extern std::string Vwarning_option; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/gripes.cc --- a/src/gripes.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/gripes.cc Wed Jul 09 23:20:19 2003 +0000 @@ -164,6 +164,12 @@ } void +gripe_implicit_conversion (const std::string& from, const std::string& to) +{ + warning ("implicit conversion from %s to %s", from.c_str (), to.c_str ()); +} + +void gripe_divide_by_zero (void) { if (Vwarn_divide_by_zero) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/gripes.h --- a/src/gripes.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/gripes.h Wed Jul 09 23:20:19 2003 +0000 @@ -90,6 +90,9 @@ gripe_implicit_conversion (const char *from, const char *to); extern void +gripe_implicit_conversion (const std::string& from, const std::string& to); + +extern void gripe_divide_by_zero (void); #endif diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/octave.cc --- a/src/octave.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/octave.cc Wed Jul 09 23:20:19 2003 +0000 @@ -352,8 +352,6 @@ bind_builtin_variable ("define_all_return_values", true); bind_builtin_variable ("do_fortran_indexing", true); bind_builtin_variable ("fixed_point_format", true); - bind_builtin_variable ("implicit_num_to_str_ok", true); - bind_builtin_variable ("implicit_str_to_num_ok", true); bind_builtin_variable ("initialize_global_variables", true); bind_builtin_variable ("page_screen_output", false); bind_builtin_variable ("prefer_column_vectors", false); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-base.cc --- a/src/ov-base.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-base.cc Wed Jul 09 23:20:19 2003 +0000 @@ -166,9 +166,9 @@ } octave_value -octave_base_value::convert_to_str (bool) const +octave_base_value::convert_to_str_internal (bool) const { - gripe_wrong_type_arg ("octave_base_value::convert_to_str ()", + gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", type_name ()); return octave_value (); } @@ -314,16 +314,11 @@ { charMatrix retval; - if (Vimplicit_num_to_str_ok) - { - octave_value tmp = convert_to_str (); + octave_value tmp = convert_to_str (); - if (! error_state) - retval = tmp.char_matrix_value (); - } - else - gripe_wrong_type_arg ("octave_base_value::char_matrix_value()", - type_name ()); + if (! error_state) + retval = tmp.char_matrix_value (); + return retval; } @@ -332,15 +327,10 @@ { string_vector retval; - if (Vimplicit_num_to_str_ok) - { - octave_value tmp = convert_to_str (pad); + octave_value tmp = convert_to_str (pad); - if (! error_state) - retval = tmp.all_strings (); - } - else - gripe_wrong_type_arg ("octave_base_value::all_strings()", type_name ()); + if (! error_state) + retval = tmp.all_strings (); return retval; } @@ -350,15 +340,10 @@ { std::string retval; - if (Vimplicit_num_to_str_ok) - { - octave_value tmp = convert_to_str (); + octave_value tmp = convert_to_str (); - if (! error_state) - retval = tmp.string_value (); - } - else - gripe_wrong_type_arg ("octave_base_value::string_value()", type_name ()); + if (! error_state) + retval = tmp.string_value (); return retval; } diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-base.h --- a/src/ov-base.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-base.h Wed Jul 09 23:20:19 2003 +0000 @@ -219,7 +219,7 @@ boolMatrix bool_matrix_value (void) const; - octave_value convert_to_str (bool pad = false) const; + octave_value convert_to_str_internal (bool pad = false) const; void convert_to_row_or_column_vector (void); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-bool-mat.h --- a/src/ov-bool-mat.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-bool-mat.h Wed Jul 09 23:20:19 2003 +0000 @@ -98,7 +98,7 @@ boolMatrix bool_matrix_value (void) const { return matrix; } - octave_value convert_to_str (bool = false) const + octave_value convert_to_str_internal (bool = false) const { return octave_value (matrix); } protected: diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-bool.cc --- a/src/ov-bool.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-bool.cc Wed Jul 09 23:20:19 2003 +0000 @@ -103,7 +103,7 @@ } octave_value -octave_bool::convert_to_str (bool) const +octave_bool::convert_to_str_internal (bool) const { char s[2]; s[0] = static_cast (scalar); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-bool.h --- a/src/ov-bool.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-bool.h Wed Jul 09 23:20:19 2003 +0000 @@ -102,7 +102,7 @@ boolMatrix bool_matrix_value (void) const { return boolMatrix (1, 1, scalar); } - octave_value convert_to_str (bool pad = false) const; + octave_value convert_to_str_internal (bool pad = false) const; private: diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-cell.h --- a/src/ov-cell.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-cell.h Wed Jul 09 23:20:19 2003 +0000 @@ -98,7 +98,7 @@ octave_value_list list_value (void) const; - octave_value convert_to_str (bool pad = false) const + octave_value convert_to_str_internal (bool pad = false) const { return all_strings (pad); } string_vector all_strings (bool pad = false) const; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-ch-mat.h --- a/src/ov-ch-mat.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-ch-mat.h Wed Jul 09 23:20:19 2003 +0000 @@ -101,7 +101,7 @@ charMatrix char_matrix_value (bool = false) const { return matrix; } - octave_value convert_to_str (bool = false) const + octave_value convert_to_str_internal (bool = false) const { return octave_value (matrix, true); } protected: diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-mapper.cc --- a/src/ov-mapper.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-mapper.cc Wed Jul 09 23:20:19 2003 +0000 @@ -117,9 +117,8 @@ { octave_value retval; - // XXX FIXME XXX -- is_real_type can return true for strings if - // implicit_str_to_num_ok is nonzero. Should it really work that - // way? + // XXX FIXME XXX -- is_real_type can return true. Should it really + // work that way? if (arg.is_real_type () && ! (arg.is_string () && ch_map_fcn)) { diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-range.cc --- a/src/ov-range.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-range.cc Wed Jul 09 23:20:19 2003 +0000 @@ -205,7 +205,7 @@ } octave_value -octave_range::convert_to_str (bool pad) const +octave_range::convert_to_str_internal (bool pad) const { octave_value tmp (range.matrix_value ()); return tmp.convert_to_str (pad); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-range.h --- a/src/ov-range.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-range.h Wed Jul 09 23:20:19 2003 +0000 @@ -154,7 +154,7 @@ Range range_value (void) const { return range; } - octave_value convert_to_str (bool pad = false) const; + octave_value convert_to_str_internal (bool pad = false) const; void print (std::ostream& os, bool pr_as_read_syntax = false) const; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-re-mat.cc --- a/src/ov-re-mat.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-re-mat.cc Wed Jul 09 23:20:19 2003 +0000 @@ -112,7 +112,7 @@ } octave_value -octave_matrix::convert_to_str (bool) const +octave_matrix::convert_to_str_internal (bool) const { octave_value retval; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-re-mat.h --- a/src/ov-re-mat.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-re-mat.h Wed Jul 09 23:20:19 2003 +0000 @@ -102,7 +102,7 @@ void decrement (void) { matrix -= 1.0; } - octave_value convert_to_str (bool pad = false) const; + octave_value convert_to_str_internal (bool pad = false) const; private: diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-scalar.cc --- a/src/ov-scalar.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-scalar.cc Wed Jul 09 23:20:19 2003 +0000 @@ -77,7 +77,7 @@ } octave_value -octave_scalar::convert_to_str (bool) const +octave_scalar::convert_to_str_internal (bool) const { octave_value retval; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-scalar.h --- a/src/ov-scalar.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-scalar.h Wed Jul 09 23:20:19 2003 +0000 @@ -94,7 +94,7 @@ ComplexMatrix complex_matrix_value (bool = false) const { return ComplexMatrix (1, 1, Complex (scalar)); } - octave_value convert_to_str (bool pad = false) const; + octave_value convert_to_str_internal (bool pad = false) const; void increment (void) { ++scalar; } diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov-str-mat.cc --- a/src/ov-str-mat.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov-str-mat.cc Wed Jul 09 23:20:19 2003 +0000 @@ -152,18 +152,10 @@ { Matrix retval; - int flag = force_string_conv; - - if (! flag) - flag = Vimplicit_str_to_num_ok; - - if (flag < 0) + if (! force_string_conv && Vwarn_str_to_num) gripe_implicit_conversion ("string", "real matrix"); - if (flag) - retval = Matrix (matrix); - else - gripe_invalid_conversion ("string", "real matrix"); + retval = Matrix (matrix); return retval; } diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov.cc --- a/src/ov.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov.cc Wed Jul 09 23:20:19 2003 +0000 @@ -82,21 +82,19 @@ // for A already defined and a matrix type. bool Vdo_fortran_indexing; -// Should `[97, 98, 99, "123"]' be a string? -bool Vimplicit_num_to_str_ok; +// Should we warn about conversions from complex to real? +int Vwarn_imag_to_real; -// Should we allow things like: +// Should we print a warning when converting `[97, 98, 99, "123"]' +// to a character string? +bool Vwarn_num_to_str; + +// If TRUE, warn for operations like // // octave> 'abc' + 0 // 97 98 99 // -// to happen? A positive value means yes. A negative value means -// yes, but print a warning message. Zero means it should be -// considered an error. -int Vimplicit_str_to_num_ok; - -// Should we warn about conversions from complex to real? -int Vwarn_imag_to_real; +int Vwarn_str_to_num; // If TRUE, create column vectors when doing assignments like: // @@ -1128,6 +1126,17 @@ return retval; } +octave_value +octave_value::convert_to_str (bool pad) const +{ + octave_value retval = convert_to_str_internal (pad); + + if (is_numeric_type () && Vwarn_num_to_str) + gripe_implicit_conversion (type_name (), retval.type_name ()); + + return retval; +} + void octave_value::print_with_name (std::ostream& output_buf, const std::string& name, @@ -1754,25 +1763,25 @@ } static int -implicit_num_to_str_ok (void) +warn_imag_to_real (void) { - Vimplicit_num_to_str_ok = check_preference ("implicit_num_to_str_ok"); + Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); return 0; } static int -implicit_str_to_num_ok (void) +warn_num_to_str (void) { - Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); + Vwarn_num_to_str = check_preference ("warn_num_to_str"); return 0; } static int -warn_imag_to_real (void) +warn_str_to_num (void) { - Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); + Vwarn_str_to_num = check_preference ("warn_str_to_num"); return 0; } @@ -1860,33 +1869,6 @@ the matrix. The default value is 0. \n\ @end defvr"); - DEFVAR (implicit_num_to_str_ok, false, implicit_num_to_str_ok, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} implicit_num_to_str_ok\n\ -If the value of @code{implicit_num_to_str_ok} is nonzero, implicit\n\ -conversions of numbers to their ASCII character equivalents are\n\ -allowed when strings are constructed using a mixture of strings and\n\ -numbers in matrix notation. Otherwise, an error message is printed and\n\ -control is returned to the top level. The default value is 0. For\n\ -example,\n\ -\n\ -@example\n\ -@group\n\ -[ \"f\", 111, 111 ]\n\ - @result{} \"foo\"\n\ -@end group\n\ -@end example\n\ -@end defvr"); - - DEFVAR (implicit_str_to_num_ok, false, implicit_str_to_num_ok, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} implicit_str_to_num_ok\n\ -If the value of @code{implicit_str_to_num_ok} is nonzero, implicit\n\ -conversions of strings to their numeric ASCII equivalents are allowed.\n\ -Otherwise, an error message is printed and control is returned to the\n\ -top level. The default value is 0.\n\ -@end defvr"); - DEFVAR (prefer_column_vectors, true, prefer_column_vectors, "-*- texinfo -*-\n\ @defvr {Built-in Variable} prefer_column_vectors\n\ @@ -1986,6 +1968,40 @@ printed for implicit conversions of complex numbers to real numbers.\n\ The default value is 0.\n\ @end defvr"); + + DEFVAR (warn_num_to_str, true, warn_num_to_str, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_num_to_str\n\ +If the value of @code{warn_num_to_str} is nonzero, a warning is\n\ +printed for implicit conversions of numbers to their ASCII character\n\ +equivalents when strings are constructed using a mixture of strings and\n\ +numbers in matrix notation. For example,\n\ +\n\ +@example\n\ +@group\n\ +[ \"f\", 111, 111 ]\n\ + @result{} \"foo\"\n\ +@end group\n\ +@end example\n\ +elicits a warning if @code{warn_num_to_str} is nonzero. The default\n\ +value is 1.\n\ +@end defvr"); + + DEFVAR (warn_str_to_num, false, warn_str_to_num, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_str_to_num\n\ +If the value of @code{warn_str_to_num} is nonzero, a warning is printed\n\ +for implicit conversions of strings to their numeric ASCII equivalents.\n\ +For example,\n\ +@example\n\ +@group\n\ +\"abc\" + 0\n\ + @result{} 97 98 99\n\ +@end group\n\ +@end example\n\ +elicits a warning if @code{warn_str_to_num} is nonzero. The default\n\ +value is 0.\n\ +@end defvr"); } /* diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/ov.h --- a/src/ov.h Wed Jul 09 19:09:09 2003 +0000 +++ b/src/ov.h Wed Jul 09 23:20:19 2003 +0000 @@ -536,8 +536,10 @@ // class wants a certain kind of constant, he should simply ask for // it, and we should convert it if possible. - virtual octave_value convert_to_str (bool pad = false) const - { return rep->convert_to_str (pad); } + octave_value convert_to_str (bool pad = false) const; + + virtual octave_value convert_to_str_internal (bool pad = false) const + { return rep->convert_to_str_internal (pad); } virtual void convert_to_row_or_column_vector (void) { rep->convert_to_row_or_column_vector (); } @@ -723,18 +725,16 @@ // for A already defined and a matrix type. extern bool Vdo_fortran_indexing; -// Should `[97, 98, 99, "123"]' be a string? -extern bool Vimplicit_num_to_str_ok; +// Should we print a warning when converting `[97, 98, 99, "123"]' +// to a character string? +extern bool Vwarn_num_to_str; -// Should we allow things like: +// If TRUE, warn for operations like // // octave> 'abc' + 0 // 97 98 99 // -// to happen? A positive value means yes. A negative value means -// yes, but print a warning message. Zero means it should be -// considered an error. -extern int Vimplicit_str_to_num_ok; +extern int Vwarn_str_to_num; // Should we warn about conversions from complex to real? extern int Vwarn_imag_to_real; diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/parse.y --- a/src/parse.y Wed Jul 09 19:09:09 2003 +0000 +++ b/src/parse.y Wed Jul 09 23:20:19 2003 +0000 @@ -1734,9 +1734,13 @@ unwind_protect::begin_frame ("fold_binary_expression"); unwind_protect_int (error_state); + unwind_protect_int (warning_state); unwind_protect_bool (discard_error_messages); + unwind_protect_bool (discard_warning_messages); + discard_error_messages = true; + discard_warning_messages = true; tree_expression *op1 = e->lhs (); tree_expression *op2 = e->rhs (); @@ -1780,9 +1784,13 @@ unwind_protect::begin_frame ("fold_unary_expression"); unwind_protect_int (error_state); + unwind_protect_int (warning_state); unwind_protect_bool (discard_error_messages); + unwind_protect_bool (discard_warning_messages); + discard_error_messages = true; + discard_warning_messages = true; tree_expression *op = e->operand (); @@ -1827,9 +1835,13 @@ unwind_protect::begin_frame ("finish_colon_expression"); unwind_protect_int (error_state); + unwind_protect_int (warning_state); unwind_protect_bool (discard_error_messages); + unwind_protect_bool (discard_warning_messages); + discard_error_messages = true; + discard_warning_messages = true; tree_expression *base = e->base (); tree_expression *limit = e->limit (); @@ -2803,9 +2815,13 @@ unwind_protect::begin_frame ("finish_matrix"); unwind_protect_int (error_state); + unwind_protect_int (warning_state); unwind_protect_bool (discard_error_messages); + unwind_protect_bool (discard_warning_messages); + discard_error_messages = true; + discard_warning_messages = true; if (m->all_elements_are_constant ()) { diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/pt-mat.cc --- a/src/pt-mat.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/pt-mat.cc Wed Jul 09 23:20:19 2003 +0000 @@ -486,7 +486,7 @@ 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; + frc_str_conv = some_strings_p; if (all_strings_p) chm.resize (nr, nc, Vstring_fill_char); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 src/variables.cc --- a/src/variables.cc Wed Jul 09 19:09:09 2003 +0000 +++ b/src/variables.cc Wed Jul 09 23:20:19 2003 +0000 @@ -439,12 +439,14 @@ unwind_protect::begin_frame ("generate_struct_completions"); - unwind_protect_str (Vwarning_option); + unwind_protect_int (error_state); + unwind_protect_int (warning_state); + unwind_protect_bool (discard_error_messages); - unwind_protect_int (error_state); + unwind_protect_bool (discard_warning_messages); - Vwarning_option = "off"; discard_error_messages = true; + discard_warning_messages = true; octave_value tmp = eval_string (prefix, true, parse_status); diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/io/io.exp --- a/test/octave.test/io/io.exp Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/io/io.exp Wed Jul 09 23:20:19 2003 +0000 @@ -107,11 +107,11 @@ do_test tmpnam-1.m set test tmpnam-2 -set prog_output "error:.*" +set prog_output "warning:.*" do_test tmpnam-2.m set test tmpnam-3 -set prog_output "error:.*" +set prog_output "warning:.*" do_test tmpnam-3.m set test tmpnam-4 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/linalg/linalg.exp --- a/test/octave.test/linalg/linalg.exp Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/linalg/linalg.exp Wed Jul 09 23:20:19 2003 +0000 @@ -199,7 +199,7 @@ do_test schur-2.m set test schur-3 -set prog_output "error:.*" +set prog_output "warning:.*" do_test schur-3.m set test schur-4 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/linalg/schur-3.m --- a/test/octave.test/linalg/schur-3.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/linalg/schur-3.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,1 +1,2 @@ +warn_num_to_str = 1; schur ([1, 2; 3, 4], 2) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/ismatrix-5.m --- a/test/octave.test/number/ismatrix-5.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/ismatrix-5.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! ismatrix ("t"); -implicit_str_to_num_ok = 1; -t2 = ! ismatrix ("t"); -t1 && t2 +warn_str_to_num = 0; +ismatrix ("t") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/ismatrix-6.m --- a/test/octave.test/number/ismatrix-6.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/ismatrix-6.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! ismatrix ("test"); -implicit_str_to_num_ok = 1; -t2 = ! ismatrix ("test"); -t1 && t2 +warn_str_to_num = 0; +ismatrix ("test") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/ismatrix-7.m --- a/test/octave.test/number/ismatrix-7.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/ismatrix-7.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! ismatrix (["test"; "ing"]); -implicit_str_to_num_ok = 1; -t2 = ! ismatrix (["test"; "ing"]); -t1 && t2 +warn_str_to_num = 0; +ismatrix (["test"; "ing"]) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/isscalar-5.m --- a/test/octave.test/number/isscalar-5.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/isscalar-5.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! isscalar ("t"); -implicit_str_to_num_ok = 1; -t2 = ! isscalar ("t"); -t1 && t2 +warn_str_to_num = 0; +isscalar ("t") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/issquare-5.m --- a/test/octave.test/number/issquare-5.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/issquare-5.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! issquare ("t"); -implicit_str_to_num_ok = 1; -t2 = ! issquare ("t"); -t1 && t2 +warn_str_to_num = 0; +issquare ("t") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/issquare-7.m --- a/test/octave.test/number/issquare-7.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/issquare-7.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! issquare (["test"; "ing"; "1"; "2"]); -implicit_str_to_num_ok = 1; -t2 = ! issquare (["test"; "ing"; "1"; "2"]); -t1 && t2 +warn_str_to_num = 0; +issquare (["test"; "ing"; "1"; "2"]) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/issymmetric-5.m --- a/test/octave.test/number/issymmetric-5.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/issymmetric-5.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! issymmetric ("t"); -implicit_str_to_num_ok = 1; -t2 = ! issymmetric ("t"); -t1 && t2 +warn_str_to_num = 0; +issymmetric ("t") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/issymmetric-7.m --- a/test/octave.test/number/issymmetric-7.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/issymmetric-7.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! issymmetric (["te"; "et"]); -implicit_str_to_num_ok = 1; -t2 = ! issymmetric (["te"; "et"]); -t1 && t2 +warn_str_to_num = 0; +issymmetric (["te"; "et"]) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/isvector-5.m --- a/test/octave.test/number/isvector-5.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/isvector-5.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! isvector ("t"); -implicit_str_to_num_ok = 1; -t2 = ! isvector ("t"); -t1 && t2 +warn_str_to_num = 0; +isvector ("t") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/isvector-6.m --- a/test/octave.test/number/isvector-6.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/isvector-6.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,5 +1,2 @@ -implicit_str_to_num_ok = 0; -t1 = ! isvector ("test"); -implicit_str_to_num_ok = 1; -t2 = ! isvector ("test"); -t1 && t2 +warn_str_to_num = 0; +isvector ("test") diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/number/number.exp --- a/test/octave.test/number/number.exp Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/number/number.exp Wed Jul 09 23:20:19 2003 +0000 @@ -15,15 +15,15 @@ do_test ismatrix-4.m set test ismatrix-5 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test ismatrix-5.m set test ismatrix-6 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test ismatrix-6.m set test ismatrix-7 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test ismatrix-7.m set test ismatrix-8 @@ -55,11 +55,11 @@ do_test isvector-4.m set test isvector-5 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test isvector-5.m set test isvector-6 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test isvector-6.m set test isvector-7 @@ -95,7 +95,7 @@ do_test isscalar-4.m set test isscalar-5 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test isscalar-5.m set test isscalar-6 @@ -135,7 +135,7 @@ do_test issquare-4.m set test issquare-5 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test issquare-5.m set test issquare-6 @@ -143,7 +143,7 @@ do_test issquare-6.m set test issquare-7 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test issquare-7.m set test issquare-8 @@ -179,7 +179,7 @@ do_test issymmetric-4.m set test issymmetric-5 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test issymmetric-5.m set test issymmetric-6 @@ -187,7 +187,7 @@ do_test issymmetric-6.m set test issymmetric-7 -set prog_output "ans = 1" +set prog_output "ans = 0" do_test issymmetric-7.m set test issymmetric-8 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/prefer/prefer-12.m --- a/test/octave.test/prefer/prefer-12.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/prefer/prefer-12.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,2 +1,2 @@ -implicit_str_to_num_ok = 1; +warn_str_to_num = 1; "d" + 0 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/prefer/prefer-13.m --- a/test/octave.test/prefer/prefer-13.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/prefer/prefer-13.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,2 +1,2 @@ -implicit_str_to_num_ok = 0; +warn_str_to_num = 1; "d" + 0 diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/prefer/prefer.exp --- a/test/octave.test/prefer/prefer.exp Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/prefer/prefer.exp Wed Jul 09 23:20:19 2003 +0000 @@ -44,14 +44,14 @@ set prog_output "ans = 1" do_test prefer-11.m -## implicit_str_to_num_ok +## warn_str_to_num set test implicit-str-to-num-ok-1 set prog_output "ans = 100" do_test prefer-12.m set test implicit-str-to-num-ok-2 -set prog_output "error:.*" +set prog_output "warning:.*" do_test prefer-13.m ## warn_imag_to_real diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/system/getenv-4.m --- a/test/octave.test/system/getenv-4.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/system/getenv-4.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,1 +1,2 @@ +warn_num_to_str = 1; getenv (1) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/system/putenv-4.m --- a/test/octave.test/system/putenv-4.m Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/system/putenv-4.m Wed Jul 09 23:20:19 2003 +0000 @@ -1,1 +1,2 @@ +warn_num_to_str = 1; putenv (1, 2) diff -r ea1d3e1a4b1b -r f3c21a1d1c62 test/octave.test/system/system.exp --- a/test/octave.test/system/system.exp Wed Jul 09 19:09:09 2003 +0000 +++ b/test/octave.test/system/system.exp Wed Jul 09 23:20:19 2003 +0000 @@ -368,7 +368,7 @@ do_test getenv-3.m set test getenv-4 -set prog_output "error:.*" +set prog_output "warning:.*" do_test getenv-4.m set test putenv-1 @@ -384,7 +384,7 @@ do_test putenv-3.m set test putenv-4 -set prog_output "error:.*" +set prog_output "warning:.*" do_test putenv-4.m set test cd-1