mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-20 17:31:08 +00:00
produce a warning for the likes of "x - x & y"
This commit is contained in:
parent
128faf773a
commit
ccb8faf6ef
2 changed files with 30 additions and 9 deletions
|
@ -180,6 +180,7 @@ expr_t *new_short_expr (short short_val);
|
|||
|
||||
int is_constant (expr_t *e);
|
||||
int is_compare (int op);
|
||||
int is_math (int op);
|
||||
int is_logic (int op);
|
||||
expr_t *constant_expr (expr_t *var);
|
||||
|
||||
|
|
|
@ -1382,6 +1382,14 @@ is_compare (int op)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
is_math (int op)
|
||||
{
|
||||
if (op == '*' || op == '/' || op == '+' || op == '-')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
is_logic (int op)
|
||||
{
|
||||
|
@ -1411,9 +1419,7 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
|
|||
if (options.traditional) {
|
||||
if (e2->type == ex_expr && !e2->paren) {
|
||||
if (((op == '&' || op == '|')
|
||||
&& (e2->e.expr.op == '*' || e2->e.expr.op == '/'
|
||||
|| e2->e.expr.op == '+' || e2->e.expr.op == '-'
|
||||
|| is_compare (e2->e.expr.op)))
|
||||
&& (is_math (e2->e.expr.op) || is_compare (e2->e.expr.op)))
|
||||
|| (op == '='
|
||||
&& (e2->e.expr.op == OR || e2->e.expr.op == AND))) {
|
||||
notice (e1, "precedence of `%s' and `%s' inverted for "
|
||||
|
@ -1435,9 +1441,7 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
|
|||
}
|
||||
} else if (e1->type == ex_expr && !e1->paren) {
|
||||
if (((op == '&' || op == '|')
|
||||
&& (e1->e.expr.op == '*' || e1->e.expr.op == '/'
|
||||
|| e1->e.expr.op == '+' || e1->e.expr.op == '-'
|
||||
|| is_compare (e1->e.expr.op)))
|
||||
&& (is_math (e1->e.expr.op) || is_compare (e1->e.expr.op)))
|
||||
|| (op == '='
|
||||
&& (e1->e.expr.op == OR || e1->e.expr.op == AND))) {
|
||||
notice (e1, "precedence of `%s' and `%s' inverted for "
|
||||
|
@ -1451,10 +1455,26 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
|
|||
} else {
|
||||
if (e2->type == ex_expr && !e2->paren) {
|
||||
if ((op == '&' || op == '|' || op == '^')
|
||||
&& is_compare (e2->e.expr.op)) {
|
||||
&& (is_math (e2->e.expr.op) || is_compare (e2->e.expr.op))) {
|
||||
if (options.warnings.precedence)
|
||||
warning (e2, "suggest parentheses around comparison in "
|
||||
"operand of %c", op);
|
||||
warning (e2, "suggest parentheses around %s in "
|
||||
"operand of %c",
|
||||
is_compare (e2->e.expr.op)
|
||||
? "comparison"
|
||||
: get_op_string (e2->e.expr.op),
|
||||
op);
|
||||
}
|
||||
}
|
||||
if (e1->type == ex_expr && !e1->paren) {
|
||||
if ((op == '&' || op == '|' || op == '^')
|
||||
&& (is_math (e1->e.expr.op) || is_compare (e1->e.expr.op))) {
|
||||
if (options.warnings.precedence)
|
||||
warning (e1, "suggest parentheses around %s in "
|
||||
"operand of %c",
|
||||
is_compare (e1->e.expr.op)
|
||||
? "comparison"
|
||||
: get_op_string (e1->e.expr.op),
|
||||
op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue