Mercurial > hg > octave-nkf
changeset 5161:3cdcddfab90b
[project @ 2005-02-23 16:44:59 by jwe]
author | jwe |
---|---|
date | Wed, 23 Feb 2005 16:44:59 +0000 |
parents | 6b9c4cf05a6a |
children | b087938bf4ba |
files | src/ChangeLog src/parse.y |
diffstat | 2 files changed, 64 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2005-02-23 John W. Eaton <jwe@octave.org> + + * parse.y (fold (tree_binary_expression*)): Skip constant folding + for some expressions to preserve warnings. + (Vwarn_associativity_change): New static variable. + (warn_associativity_change): New function. + (symbols_of_parse): DEFVAR warn_associativity_change. + (maybe_warn_associativity_change): New function. + (make_binary_op): Use it. + 2005-02-22 John W. Eaton <jwe@octave.org> * parse.y (POW, EPOW): Use %left associativity for compatibility.
--- a/src/parse.y +++ b/src/parse.y @@ -80,8 +80,10 @@ // static bool Vwarn_assign_as_truth_value; -// If TRUE, generate a warning for variable swich labels. -static bool Vwarn_variable_switch_label; +// If TRUE, generate warning about the meaning of code changing due to +// changes in associativity for various ops (typically for Matlab +// compatibility). +static bool Vwarn_associativity_change; // If TRUE, generate warning if declared function name disagrees with // the name of the file in which it is defined. @@ -100,6 +102,9 @@ // compatibility). static bool Vwarn_precedence_change; +// If TRUE, generate a warning for variable switch labels. +static bool Vwarn_variable_switch_label; + // Temporary symbol table pointer used to cope with bogus function syntax. symbol_table *tmp_local_sym_tab = 0; @@ -1580,7 +1585,13 @@ tree_expression *op1 = e->lhs (); tree_expression *op2 = e->rhs (); - if (op1->is_constant () && op2->is_constant ()) + octave_value::binary_op op_type = e->op_type (); + + if (op1->is_constant () && op2->is_constant () + && (! ((Vwarn_associativity_change + && (op_type == POW || op_type == EPOW)) + || (Vwarn_precedence_change + && (op_type == EXPR_OR || op_type == EXPR_OR_OR))))) { octave_value tmp = e->rvalue (); @@ -1840,6 +1851,27 @@ return retval; } +static void +maybe_warn_associativity_change (tree_expression *op) +{ + if (Vwarn_associativity_change + && op->paren_count () == 0 && op->is_binary_expression ()) + { + tree_binary_expression *e + = dynamic_cast<tree_binary_expression *> (op); + + octave_value::binary_op op_type = e->op_type (); + + if (op_type == octave_value::op_pow + || op_type == octave_value::op_el_pow) + { + std::string op_str = octave_value::binary_op_as_string (op_type); + + warning ("meaning may have changed due to change in associativity for %s operator", op_str.c_str ()); + } + } +} + // Build a binary expression. static tree_expression * @@ -1852,10 +1884,12 @@ { case POW: t = octave_value::op_pow; + maybe_warn_associativity_change (op1); break; case EPOW: t = octave_value::op_el_pow; + maybe_warn_associativity_change (op1); break; case '+': @@ -3848,6 +3882,14 @@ } static int +warn_associativity_change (void) +{ + Vwarn_associativity_change = check_preference ("warn_associativity_change"); + + return 0; +} + +static int warn_function_name_clash (void) { Vwarn_function_name_clash = check_preference ("warn_function_name_clash"); @@ -3955,6 +3997,15 @@ The default value of @code{warn_assign_as_truth_value} is 1.\n\ @end defvr"); + DEFVAR (warn_associativity_change, true, warn_associativity_change, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_associativity_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\ +associativity for some operators. Associativity changes have typically\n\ +been made for Matlab compatibility. The default value is 1.\n\ +@end defvr"); + DEFVAR (warn_function_name_clash, true, warn_function_name_clash, "-*- texinfo -*-\n\ @defvr {Built-in Variable} warn_function_name_clash\n\