changeset 18126:d76f790b4eec gui-release

enable do_braindead_shortcircuit_evaluation by default and deprecate * octave.cc (maximum_braindamage): Don't call Fdo_brainded_shortcircuit_evaluation. * pt-exp.h (tree_expression::mark_braindead_shortcircuit): Eliminate file name argument. * pt-binop.h, pt-binop.cc (tree_binary_expression::mark_braindead_shortcircuit): Likewise. * oct-parse.in.yy (if_cmd_list1, elseif_clause, loop_command): Eliminate argument from call to mark_braindead_shortcircuit. * pt-binop.h, pt-binop.cc (Vdo_braindead_shortcircuit_evaluation): Initialize to true. (tree_binary_expression::matlab_style_short_circuit_warning): New function. (tree_binary_expression::rvalue1): Call matlab_style_short_circuit_warning if short circuit evaluation occurs. (Fdo_braindead_shortcircuit_evaluation): Display deprecated warning. Delete tests for do_braindead_shortcircuit_evaluation. (tree_binary_expression::braindead_shortcircuit_warning_issued): New member variable. * NEWS: Mention change in default value and deprecated function.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Dec 2013 20:51:22 -0500
parents 834549618a52
children d96747f74b1e
files NEWS libinterp/octave.cc libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/pt-binop.cc libinterp/parse-tree/pt-binop.h libinterp/parse-tree/pt-exp.h
diffstat 6 files changed, 48 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Dec 05 11:48:58 2013 -0800
+++ b/NEWS	Wed Dec 11 20:51:22 2013 -0500
@@ -1,6 +1,12 @@
 Summary of important user-visible changes for version 4.0:
 ---------------------------------------------------------
 
+ ** The preference
+
+      do_braindead_shortcircuit_evaluation
+
+    is now enabled by default.
+
  ** Other new functions added in 4.0.0:
 
     validateattributes
@@ -20,7 +26,7 @@
     be removed from Octave 4.4 (or whatever version is the second major
     release after 4.0):
 
-    *none*
+      do_braindead_shortcircuit_evaluation
 
 ---------------------------------------------------------
 
--- a/libinterp/octave.cc	Thu Dec 05 11:48:58 2013 -0800
+++ b/libinterp/octave.cc	Wed Dec 11 20:51:22 2013 -0500
@@ -487,7 +487,6 @@
   Fconfirm_recursive_rmdir (octave_value (false));
   Fcrash_dumps_octave_core (octave_value (false));
   Fsave_default_options (octave_value ("-mat-binary"));
-  Fdo_braindead_shortcircuit_evaluation (octave_value (true));
   Ffixed_point_format (octave_value (true));
   Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%"));
   Fpage_screen_output (octave_value (false));
--- a/libinterp/parse-tree/oct-parse.in.yy	Thu Dec 05 11:48:58 2013 -0800
+++ b/libinterp/parse-tree/oct-parse.in.yy	Wed Dec 11 20:51:22 2013 -0500
@@ -943,7 +943,7 @@
 
 if_cmd_list1    : expression stmt_begin opt_sep opt_list
                   {
-                    $1->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
+                    $1->mark_braindead_shortcircuit ();
 
                     $$ = parser.start_if_command ($1, $4);
                   }
@@ -956,7 +956,7 @@
 
 elseif_clause   : ELSEIF stash_comment opt_sep expression stmt_begin opt_sep opt_list
                   {
-                    $4->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
+                    $4->mark_braindead_shortcircuit ();
 
                     $$ = parser.make_elseif_clause ($1, $4, $7, $2);
                   }
@@ -1018,7 +1018,7 @@
 
 loop_command    : WHILE stash_comment expression stmt_begin opt_sep opt_list END
                   {
-                    $3->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
+                    $3->mark_braindead_shortcircuit ();
 
                     if (! ($$ = parser.make_while_command ($1, $3, $6, $7, $2)))
                       {
--- a/libinterp/parse-tree/pt-binop.cc	Thu Dec 05 11:48:58 2013 -0800
+++ b/libinterp/parse-tree/pt-binop.cc	Wed Dec 11 20:51:22 2013 -0500
@@ -36,7 +36,7 @@
 
 // TRUE means we mark | and & expressions for braindead short-circuit
 // behavior.
-static bool Vdo_braindead_shortcircuit_evaluation;
+static bool Vdo_braindead_shortcircuit_evaluation = true;
 
 // Binary expressions.
 
@@ -54,6 +54,16 @@
   return retval;
 }
 
+void
+tree_binary_expression::matlab_style_short_circuit_warning (const char *op)
+{
+  warning_with_id ("Octave:possible-matlab-short-circuit-operator",
+                   "Matlab-style short-circuit operation performed for operator %s",
+                   op);
+
+  braindead_shortcircuit_warning_issued = true;
+}
+
 octave_value
 tree_binary_expression::rvalue1 (int)
 {
@@ -83,6 +93,7 @@
                         {
                           if (etype == octave_value::op_el_or)
                             {
+                              matlab_style_short_circuit_warning ("|");
                               result = true;
                               goto done;
                             }
@@ -90,7 +101,10 @@
                       else
                         {
                           if (etype == octave_value::op_el_and)
-                            goto done;
+                            {
+                              matlab_style_short_circuit_warning ("&");
+                              goto done;
+                            }
                         }
 
                       if (op_rhs)
@@ -298,18 +312,13 @@
 The original variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
+  static bool warned = false;
+  if (! warned)
+    {
+      warned = true;
+      warning_with_id ("Octave:deprecated-function",
+                       "do_braindead_shortcircuit_evaluation is obsolete and will be removed from a future version of Octave");
+    }
+
   return SET_INTERNAL_VARIABLE (do_braindead_shortcircuit_evaluation);
 }
-
-/*
-%!test
-%! x = 0;
-%! do_braindead_shortcircuit_evaluation (0);
-%! if (1 | (x = 1))
-%! endif
-%! assert (x, 1);
-%! do_braindead_shortcircuit_evaluation (1);
-%! if (1 | (x = 0))
-%! endif
-%! assert (x, 1);
-*/
--- a/libinterp/parse-tree/pt-binop.h	Thu Dec 05 11:48:58 2013 -0800
+++ b/libinterp/parse-tree/pt-binop.h	Wed Dec 11 20:51:22 2013 -0500
@@ -46,14 +46,16 @@
                           octave_value::binary_op t
                             = octave_value::unknown_binary_op)
     : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t),
-      eligible_for_braindead_shortcircuit (false) { }
+      eligible_for_braindead_shortcircuit (false),
+      braindead_shortcircuit_warning_issued (false) { }
 
   tree_binary_expression (tree_expression *a, tree_expression *b,
                           int l = -1, int c = -1,
                           octave_value::binary_op t
                             = octave_value::unknown_binary_op)
     : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
-      eligible_for_braindead_shortcircuit (false) { }
+      eligible_for_braindead_shortcircuit (false),
+      braindead_shortcircuit_warning_issued (false) { }
 
   ~tree_binary_expression (void)
   {
@@ -61,23 +63,14 @@
     delete op_rhs;
   }
 
-  void mark_braindead_shortcircuit (const std::string& file)
+  void mark_braindead_shortcircuit (void)
   {
     if (etype == octave_value::op_el_and || etype == octave_value::op_el_or)
       {
-        if (file.empty ())
-          warning_with_id ("Octave:possible-matlab-short-circuit-operator",
-                           "possible Matlab-style short-circuit operator at line %d, column %d",
-                           line (), column ());
-        else
-          warning_with_id ("Octave:possible-matlab-short-circuit-operator",
-                           "%s: possible Matlab-style short-circuit operator at line %d, column %d",
-                           file.c_str (), line (), column ());
-
         eligible_for_braindead_shortcircuit = true;
 
-        op_lhs->mark_braindead_shortcircuit (file);
-        op_rhs->mark_braindead_shortcircuit (file);
+        op_lhs->mark_braindead_shortcircuit ();
+        op_rhs->mark_braindead_shortcircuit ();
       }
   }
 
@@ -122,6 +115,12 @@
   // or WHILE statement.
   bool eligible_for_braindead_shortcircuit;
 
+  // TRUE if we have already issued a warning about short circuiting
+  // for this operator.
+  bool braindead_shortcircuit_warning_issued;
+
+  void matlab_style_short_circuit_warning (const char *op);
+
   // No copying!
 
   tree_binary_expression (const tree_binary_expression&);
--- a/libinterp/parse-tree/pt-exp.h	Thu Dec 05 11:48:58 2013 -0800
+++ b/libinterp/parse-tree/pt-exp.h	Wed Dec 11 20:51:22 2013 -0500
@@ -100,7 +100,7 @@
 
   virtual std::string original_text (void) const;
 
-  virtual void mark_braindead_shortcircuit (const std::string&) { }
+  virtual void mark_braindead_shortcircuit (void) { }
 
   tree_expression *mark_in_parens (void)
   {