2 * smatch/check_macros.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
14 static void match_inside(struct expression
*expr
, struct position pos
)
19 if (positions_eq(expr
->pos
, pos
))
21 if (positions_eq(expr
->unop
->pos
, pos
))
25 name
= get_macro_name(pos
);
28 sm_msg("warn: the '%s' macro might need parens", name
);
31 static void match_one_side(struct expression
*expr
, struct position pos
, int op
)
36 if ((op
== '+' || op
== '*' || op
== '|' || op
== '&') && expr
->op
== op
)
38 if (positions_eq(expr
->right
->pos
, pos
))
40 if (positions_eq(expr
->left
->pos
, pos
))
44 name
= get_macro_name(pos
);
47 if (option_project
== PROJ_WINE
&& !strcmp("BEGIN", name
))
49 sm_msg("warn: the '%s' macro might need parens", name
);
52 static void match_join(struct expression
*expr
)
54 if (expr
->left
->type
== EXPR_PREOP
)
55 match_inside(expr
->left
, expr
->pos
);
56 if (expr
->right
->type
== EXPR_POSTOP
)
57 match_inside(expr
->right
, expr
->pos
);
59 if (expr
->left
->type
== EXPR_BINOP
)
60 match_one_side(expr
->left
, expr
->pos
, expr
->op
);
61 if (expr
->right
->type
== EXPR_BINOP
)
62 match_one_side(expr
->right
, expr
->pos
, expr
->op
);
65 void check_macros(int id
)
68 add_hook(&match_join
, BINOP_HOOK
);
69 add_hook(&match_join
, LOGIC_HOOK
);