Mercurial > hg > octave-avbm
changeset 4023:ef3caf27cb9c
[project @ 2002-08-07 06:54:41 by jwe]
author | jwe |
---|---|
date | Wed, 07 Aug 2002 06:54:41 +0000 |
parents | 789c4112a37d |
children | 00d06e24cc89 |
files | src/ChangeLog src/parse.y src/pt-binop.h src/pt-exp.h |
diffstat | 4 files changed, 72 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2002-08-07 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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 <jwe@bevo.che.wisc.edu> * data.cc (ANY_ALL): Improve arg checks.
--- a/src/parse.y +++ b/src/parse.y @@ -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<tree_binary_expression *> (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<tree_boolean_expression *> (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\
--- a/src/pt-binop.h +++ b/src/pt-binop.h @@ -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.
--- a/src/pt-exp.h +++ b/src/pt-exp.h @@ -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; }