# HG changeset patch # User jwe # Date 1028703281 0 # Node ID ef3caf27cb9ceee58d756fb385732d0aaf9ea547 # Parent 789c4112a37dbebe259d9bcadfb5bb29bf982b2a [project @ 2002-08-07 06:54:41 by jwe] diff -r 789c4112a37d -r ef3caf27cb9c src/ChangeLog --- a/src/ChangeLog Tue Aug 06 03:42:41 2002 +0000 +++ b/src/ChangeLog Wed Aug 07 06:54:41 2002 +0000 @@ -1,3 +1,19 @@ +2002-08-07 John W. Eaton + + * pt-binop.h (tree_binary_expression::is_binary_expression): + New function, return true. + (tree_boolean_expression::is_boolean_expression): New function, + return true. + * pt-exp.h (tree_expression::is_binary_expression): New function. + (tree_expression::is_boolean_expression): Likewise. + * parse.y (EXPR_OR_OR): Now lower precedence than EXPR_AND_AND. + (EXPR_OR): Now lower precedence than EXPR_AND. + (make_boolean_op): Maybe warn about change in precedence. + (make_binary_op): Likewise. + (Vwarn_precedence_change): New static variable. + (warn_precedence_change): New function. + (Vwarn_precedence_change): New DEFVAR. + 2002-08-05 John W. Eaton * data.cc (ANY_ALL): Improve arg checks. diff -r 789c4112a37d -r ef3caf27cb9c src/parse.y --- a/src/parse.y Tue Aug 06 03:42:41 2002 +0000 +++ b/src/parse.y Wed Aug 07 06:54:41 2002 +0000 @@ -94,6 +94,11 @@ // should only produce output using explicit printing statements. static bool Vwarn_missing_semicolon; +// If TRUE, generate warning about the meaning of code changing due to +// changes in precedence levels for various ops (typically for Matlab +// compatibility). +static bool Vwarn_precedence_change; + // Temporary symbol table pointer used to cope with bogus function syntax. symbol_table *tmp_local_sym_tab = 0; @@ -445,8 +450,10 @@ // Precedence and associativity. %left ';' ',' '\n' %right '=' ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ OR_EQ AND_EQ LSHIFT_EQ RSHIFT_EQ -%left EXPR_AND_AND EXPR_OR_OR -%left EXPR_AND EXPR_OR +%left EXPR_OR_OR +%left EXPR_AND_AND +%left EXPR_OR +%left EXPR_AND %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT %left LSHIFT RSHIFT %left ':' @@ -1963,6 +1970,15 @@ case EXPR_OR: t = octave_value::op_el_or; + if (Vwarn_precedence_change + && op1->paren_count () == 0 && op2->is_binary_expression ()) + { + tree_binary_expression *e + = dynamic_cast (op2); + + if (e->op_type () == octave_value::op_el_and) + warning ("meaning may have changed due to change in precedence for & and | operators"); + } break; default: @@ -1995,6 +2011,15 @@ case EXPR_OR_OR: t = tree_boolean_expression::bool_or; + if (Vwarn_precedence_change + && op1->paren_count () == 0 && op2->is_boolean_expression ()) + { + tree_boolean_expression *e + = dynamic_cast (op2); + + if (e->op_type () == tree_boolean_expression::bool_and) + warning ("meaning may have changed due to change in precedence for && and || operators"); + } break; default: @@ -3671,6 +3696,14 @@ } static int +warn_precedence_change (void) +{ + Vwarn_precedence_change = check_preference ("warn_precedence_change"); + + return 0; +} + +static int warn_variable_switch_label (void) { Vwarn_variable_switch_label @@ -3779,6 +3812,15 @@ value is 0.\n\ @end defvr"); + DEFVAR (warn_precedence_change, 1.0, warn_precedence_change, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_precedence_change\n\ +If the value of this variable is nonzero, Octave will warn about\n\ +possible changes in the meaning of some code due to changes in\n\ +precedence for some operators. Precedence changes have typically\n\ +been made for Matlab compatibility. The default value is 1.\n\ +@end defvr"); + DEFVAR (warn_variable_switch_label, 0.0, warn_variable_switch_label, "-*- texinfo -*-\n\ @defvr {Built-in Variable} warn_variable_switch_label\n\ diff -r 789c4112a37d -r ef3caf27cb9c src/pt-binop.h --- a/src/pt-binop.h Tue Aug 06 03:42:41 2002 +0000 +++ b/src/pt-binop.h Wed Aug 07 06:54:41 2002 +0000 @@ -62,6 +62,8 @@ delete op_rhs; } + bool is_binary_expression (void) const { return true; } + bool rvalue_ok (void) const { return true; } octave_value rvalue (void); @@ -72,6 +74,8 @@ std::string oper (void) const; + octave_value::binary_op op_type (void) const { return etype; } + tree_expression *lhs (void) { return op_lhs; } tree_expression *rhs (void) { return op_rhs; } @@ -118,6 +122,8 @@ ~tree_boolean_expression (void) { } + bool is_boolean_expression (void) const { return true; } + bool rvalue_ok (void) const { return true; } octave_value rvalue (void); @@ -126,6 +132,8 @@ std::string oper (void) const; + type op_type (void) const { return etype; } + private: // The type of the expression. diff -r 789c4112a37d -r ef3caf27cb9c src/pt-exp.h --- a/src/pt-exp.h Tue Aug 06 03:42:41 2002 +0000 +++ b/src/pt-exp.h Wed Aug 07 06:54:41 2002 +0000 @@ -59,6 +59,10 @@ virtual bool is_prefix_expression (void) const { return false; } + virtual bool is_binary_expression (void) const { return false; } + + virtual bool is_boolean_expression (void) const { return false; } + virtual bool is_logically_true (const char *); virtual bool lvalue_ok (void) const { return false; }