2 * smatch/check_db_info.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
15 static struct range_list
*return_ranges
;
16 static struct ptr_list
*backup
;
18 static void add_return_range(struct range_list
*rl
)
20 rl
= cast_rl(cur_func_return_type(), rl
);
25 return_ranges
= rl_union(return_ranges
, rl
);
28 static void match_return(struct expression
*ret_value
)
30 struct range_list
*rl
;
32 ret_value
= strip_expr(ret_value
);
36 if (get_implied_rl(ret_value
, &rl
)) {
39 struct symbol
*data_type
= get_type(ret_value
);
40 struct symbol
*func_type
= cur_func_return_type();
42 add_return_range(cast_rl(func_type
, alloc_whole_rl(data_type
)));
46 static void match_end_func(struct symbol
*sym
)
50 sql_insert_return_values(show_rl(return_ranges
));
54 static void match_save_states(struct expression
*expr
)
56 __add_ptr_list(&backup
, return_ranges
, 0);
60 static void match_restore_states(struct expression
*expr
)
62 return_ranges
= last_ptr_list(backup
);
63 delete_ptr_list_last(&backup
);
66 void check_db_info(int id
)
69 add_hook(&match_return
, RETURN_HOOK
);
70 add_hook(&match_end_func
, END_FUNC_HOOK
);
71 add_hook(&match_save_states
, INLINE_FN_START
);
72 add_hook(&match_restore_states
, INLINE_FN_END
);