2 * sparse/check_precedence.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
14 static int is_bool(struct expression
*expr
)
18 type
= get_type(expr
);
21 if (type
->bit_size
== 1 && type
->ctype
.modifiers
& MOD_UNSIGNED
)
26 static void match_condition(struct expression
*expr
)
30 if (expr
->type
== EXPR_COMPARE
) {
31 if (expr
->left
->type
== EXPR_COMPARE
|| expr
->right
->type
== EXPR_COMPARE
)
33 if (expr
->left
->op
== '!') {
34 if (expr
->left
->type
== EXPR_PREOP
&& expr
->left
->unop
->op
== '!')
36 if (expr
->right
->op
== '!')
38 if (is_bool(expr
->right
))
44 if (expr
->type
== EXPR_BINOP
) {
45 if (expr
->left
->type
== EXPR_COMPARE
|| expr
->right
->type
== EXPR_COMPARE
)
50 sm_msg("warn: add some parenthesis here?");
53 static void match_binop(struct expression
*expr
)
57 if (expr
->left
->op
== '!')
58 sm_msg("warn: add some parenthesis here?");
61 void check_precedence(int id
)
65 add_hook(&match_condition
, CONDITION_HOOK
);
66 add_hook(&match_binop
, BINOP_HOOK
);