2 * Copyright (C) 2010 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * People should just return the error codes they received
20 * instead of making up there own dumb error codes all the time.
27 static struct expression
*last_return
;
28 static struct expression
*last_func
;
30 static char *get_fn_name(struct expression
*expr
)
32 if (expr
->type
!= EXPR_CALL
)
34 if (expr
->fn
->type
!= EXPR_SYMBOL
)
36 return expr_to_var(expr
->fn
);
39 static void match_call_assignment(struct expression
*expr
)
41 if (get_macro_name(expr
->left
->pos
))
43 last_return
= expr
->left
;
44 last_func
= expr
->right
;
47 static void match_unset(struct expression
*expr
)
52 static void match_return(struct expression
*ret_value
)
58 if (!get_value(ret_value
, &rval
) || rval
.value
>= 0)
60 if (get_implied_value(last_return
, &lret
))
62 if (!get_implied_max(last_return
, &lret
) || lret
.value
>= 0)
64 if (get_implied_min(last_return
, &lret
) && !sval_is_min(lret
))
66 name
= expr_to_var(last_return
);
67 sm_msg("info: why not propagate '%s' from %s() instead of %s?",
68 name
, get_fn_name(last_func
), sval_to_str(rval
));
72 void check_propagate(int id
)
74 if (option_project
!= PROJ_KERNEL
)
78 add_hook(&match_unset
, ASSIGNMENT_HOOK
);
79 add_hook(&match_call_assignment
, CALL_ASSIGNMENT_HOOK
);
80 add_hook(&match_return
, RETURN_HOOK
);