comparison src/oct-parse.yy @ 13844:e48529b3dbd4

eliminate warnings for changes in operator precedence made years ago * oct-parse.yy (fold (tree_binary_expression *)): Don't check for Octave:precedence-change or Octave:associativity change warnings. (maybe_warn_associativity_change): Delete. (make_binary_op, make_boolean_op): Delete warnings for changes in operator precedence and associativity.
author John W. Eaton <jwe@octave.org>
date Tue, 08 Nov 2011 14:39:02 -0500
parents f6bbdea030b2
children c93b953f7d54
comparison
equal deleted inserted replaced
13843:c299b26d0e6b 13844:e48529b3dbd4
1899 tree_expression *op1 = e->lhs (); 1899 tree_expression *op1 = e->lhs ();
1900 tree_expression *op2 = e->rhs (); 1900 tree_expression *op2 = e->rhs ();
1901 1901
1902 octave_value::binary_op op_type = e->op_type (); 1902 octave_value::binary_op op_type = e->op_type ();
1903 1903
1904 if (op1->is_constant () && op2->is_constant () 1904 if (op1->is_constant () && op2->is_constant ())
1905 && (! ((warning_enabled ("Octave:associativity-change")
1906 && (op_type == POW || op_type == EPOW))
1907 || (warning_enabled ("Octave:precedence-change")
1908 && (op_type == EXPR_OR || op_type == EXPR_OR_OR)))))
1909 { 1905 {
1910 octave_value tmp = e->rvalue1 (); 1906 octave_value tmp = e->rvalue1 ();
1911 1907
1912 if (! (error_state || warning_state)) 1908 if (! (error_state || warning_state))
1913 { 1909 {
2148 //retval->stash_file_name (curr_fcn_file_name); 2144 //retval->stash_file_name (curr_fcn_file_name);
2149 2145
2150 return retval; 2146 return retval;
2151 } 2147 }
2152 2148
2153 static void
2154 maybe_warn_associativity_change (tree_expression *op)
2155 {
2156 if (op->paren_count () == 0 && op->is_binary_expression ())
2157 {
2158 tree_binary_expression *e
2159 = dynamic_cast<tree_binary_expression *> (op);
2160
2161 octave_value::binary_op op_type = e->op_type ();
2162
2163 if (op_type == octave_value::op_pow
2164 || op_type == octave_value::op_el_pow)
2165 {
2166 std::string op_str = octave_value::binary_op_as_string (op_type);
2167
2168 if (curr_fcn_file_full_name.empty ())
2169 warning_with_id
2170 ("Octave:associativity-change",
2171 "meaning may have changed due to change in associativity for %s operator",
2172 op_str.c_str ());
2173 else
2174 warning_with_id
2175 ("Octave:associativity-change",
2176 "meaning may have changed due to change in associativity for %s operator near line %d, column %d in file `%s'",
2177 op_str.c_str (), op->line (), op->column (),
2178 curr_fcn_file_full_name.c_str ());
2179 }
2180 }
2181 }
2182
2183 // Build a binary expression. 2149 // Build a binary expression.
2184 2150
2185 static tree_expression * 2151 static tree_expression *
2186 make_binary_op (int op, tree_expression *op1, token *tok_val, 2152 make_binary_op (int op, tree_expression *op1, token *tok_val,
2187 tree_expression *op2) 2153 tree_expression *op2)
2190 2156
2191 switch (op) 2157 switch (op)
2192 { 2158 {
2193 case POW: 2159 case POW:
2194 t = octave_value::op_pow; 2160 t = octave_value::op_pow;
2195 maybe_warn_associativity_change (op1);
2196 break; 2161 break;
2197 2162
2198 case EPOW: 2163 case EPOW:
2199 t = octave_value::op_el_pow; 2164 t = octave_value::op_el_pow;
2200 maybe_warn_associativity_change (op1);
2201 break; 2165 break;
2202 2166
2203 case '+': 2167 case '+':
2204 t = octave_value::op_add; 2168 t = octave_value::op_add;
2205 break; 2169 break;
2268 t = octave_value::op_el_and; 2232 t = octave_value::op_el_and;
2269 break; 2233 break;
2270 2234
2271 case EXPR_OR: 2235 case EXPR_OR:
2272 t = octave_value::op_el_or; 2236 t = octave_value::op_el_or;
2273 if (op2->paren_count () == 0 && op2->is_binary_expression ())
2274 {
2275 tree_binary_expression *e
2276 = dynamic_cast<tree_binary_expression *> (op2);
2277
2278 if (e->op_type () == octave_value::op_el_and)
2279 {
2280 if (curr_fcn_file_full_name.empty ())
2281 warning_with_id
2282 ("Octave:precedence-change",
2283 "meaning may have changed due to change in precedence for & and | operators");
2284 else
2285 warning_with_id
2286 ("Octave:precedence-change",
2287 "meaning may have changed due to change in precedence for & and | operators near line %d, column %d in file `%s'",
2288 op2->line (), op2->column (),
2289 curr_fcn_file_full_name.c_str ());
2290 }
2291 }
2292 break; 2237 break;
2293 2238
2294 default: 2239 default:
2295 panic_impossible (); 2240 panic_impossible ();
2296 break; 2241 break;
2319 t = tree_boolean_expression::bool_and; 2264 t = tree_boolean_expression::bool_and;
2320 break; 2265 break;
2321 2266
2322 case EXPR_OR_OR: 2267 case EXPR_OR_OR:
2323 t = tree_boolean_expression::bool_or; 2268 t = tree_boolean_expression::bool_or;
2324 if (op2->paren_count () == 0 && op2->is_boolean_expression ())
2325 {
2326 tree_boolean_expression *e
2327 = dynamic_cast<tree_boolean_expression *> (op2);
2328
2329 if (e->op_type () == tree_boolean_expression::bool_and)
2330 warning_with_id
2331 ("Octave:precedence-change",
2332 "meaning may have changed due to change in precedence for && and || operators");
2333 }
2334 break; 2269 break;
2335 2270
2336 default: 2271 default:
2337 panic_impossible (); 2272 panic_impossible ();
2338 break; 2273 break;