extra: Fix segmentation fault in match_assign
[smatch.git] / smatch_extra.h
blob9719b154ecbcffb2390b3b95f9fdb7ce6ef90ba4
1 /*
2 * sparse/smatch_extra.h
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 DECLARE_PTR_LIST(range_list, struct data_range);
11 DECLARE_PTR_LIST(range_list_stack, struct range_list);
13 struct relation {
14 char *name;
15 struct symbol *sym;
18 DECLARE_PTR_LIST(related_list, struct relation);
20 struct data_info {
21 struct related_list *related;
22 struct range_list *value_ranges;
23 unsigned int hard_max:1;
25 DECLARE_ALLOCATOR(data_info);
27 extern struct string_list *__ignored_macros;
29 /* these are implemented in smatch_ranges.c */
30 char *show_rl(struct range_list *list);
31 void str_to_rl(struct symbol *type, char *value, struct range_list **rl);
33 struct data_range *alloc_range(sval_t min, sval_t max);
34 struct data_range *alloc_range_perm(sval_t min, sval_t max);
36 struct range_list *alloc_rl(sval_t min, sval_t max);
37 struct range_list *clone_rl(struct range_list *list);
38 struct range_list *clone_rl_permanent(struct range_list *list);
39 struct range_list *alloc_whole_rl(struct symbol *type);
41 void add_range(struct range_list **list, sval_t min, sval_t max);
42 struct range_list *remove_range(struct range_list *list, sval_t min, sval_t max);
43 void tack_on(struct range_list **list, struct data_range *drange);
45 int true_comparison_range(struct data_range *left, int comparison, struct data_range *right);
46 int true_comparison_range_LR(int comparison, struct data_range *var, struct data_range *val, int left);
47 int false_comparison_range_LR(int comparison, struct data_range *var, struct data_range *val, int left);
49 int possibly_true(struct expression *left, int comparison, struct expression *right);
50 int possibly_true_rl(struct range_list *left_ranges, int comparison, struct range_list *right_ranges);
51 int possibly_true_rl_LR(int comparison, struct range_list *a, struct range_list *b, int left);
53 int possibly_false(struct expression *left, int comparison, struct expression *right);
54 int possibly_false_rl(struct range_list *left_ranges, int comparison, struct range_list *right_ranges);
55 int possibly_false_rl_LR(int comparison, struct range_list *a, struct range_list *b, int left);
57 int ranges_equiv(struct data_range *one, struct data_range *two);
59 int rl_equiv(struct range_list *one, struct range_list *two);
60 int is_whole_rl(struct range_list *rl);
62 sval_t rl_min(struct range_list *rl);
63 sval_t rl_max(struct range_list *rl);
64 struct symbol *rl_type(struct range_list *rl);
66 struct range_list *rl_invert(struct range_list *orig);
67 struct range_list *rl_filter(struct range_list *rl, struct range_list *filter);
68 struct range_list *rl_intersection(struct range_list *one, struct range_list *two);
69 struct range_list *rl_union(struct range_list *one, struct range_list *two);
71 void push_rl(struct range_list_stack **rl_stack, struct range_list *rl);
72 struct range_list *pop_rl(struct range_list_stack **rl_stack);
73 struct range_list *top_rl(struct range_list_stack *rl_stack);
74 void filter_top_rl(struct range_list_stack **rl_stack, sval_t sval);
76 struct range_list *rl_truncate_cast(struct symbol *type, struct range_list *rl);
77 struct range_list *cast_rl(struct symbol *type, struct range_list *rl);
78 int get_implied_rl(struct expression *expr, struct range_list **rl);
80 void free_rl(struct range_list **rlist);
81 void free_data_info_allocs(void);
83 /* smatch_estate.c */
85 struct smatch_state *alloc_estate_empty(void);
86 struct smatch_state *alloc_estate_sval(sval_t sval);
87 struct smatch_state *alloc_estate_range(sval_t min, sval_t max);
88 struct smatch_state *alloc_estate_rl(struct range_list *rl);
89 struct smatch_state *alloc_estate_whole(struct symbol *type);
90 struct smatch_state *clone_estate(struct smatch_state *state);
92 struct smatch_state *merge_estates(struct smatch_state *s1, struct smatch_state *s2);
94 int estates_equiv(struct smatch_state *one, struct smatch_state *two);
95 int estate_is_whole(struct smatch_state *state);
97 struct range_list *estate_rl(struct smatch_state *state);
98 struct related_list *estate_related(struct smatch_state *state);
100 sval_t estate_min(struct smatch_state *state);
101 sval_t estate_max(struct smatch_state *state);
102 struct symbol *estate_type(struct smatch_state *state);
104 int estate_has_hard_max(struct smatch_state *state);
105 void estate_set_hard_max(struct smatch_state *state);
106 void estate_clear_hard_max(struct smatch_state *state);
107 int estate_get_hard_max(struct smatch_state *state, sval_t *sval);
109 int estate_get_single_value(struct smatch_state *state, sval_t *sval);
110 struct smatch_state *get_implied_estate(struct expression *expr);
112 struct smatch_state *estate_filter_sval(struct smatch_state *orig, sval_t filter);
113 struct smatch_state *estate_filter_range(struct smatch_state *orig, sval_t filter_min, sval_t filter_max);
115 /* smatch_extra.c */
116 void call_extra_mod_hooks(const char *name, struct symbol *sym, struct smatch_state *state);
117 struct sm_state *set_extra_mod(const char *name, struct symbol *sym, struct smatch_state *state);
118 struct sm_state *set_extra_expr_mod(struct expression *expr, struct smatch_state *state);
119 void set_extra_expr_nomod(struct expression *expr, struct smatch_state *state);
121 struct data_info *get_dinfo(struct smatch_state *state);
123 void add_extra_mod_hook(void (*fn)(const char *name, struct symbol *sym, struct smatch_state *state));
124 int implied_not_equal(struct expression *expr, long long val);
126 struct sm_state *__extra_handle_canonical_loops(struct statement *loop, struct state_list **slist);
127 int __iterator_unchanged(struct sm_state *sm);
128 void __extra_pre_loop_hook_after(struct sm_state *sm,
129 struct statement *iterator,
130 struct expression *condition);
132 /* smatch_equiv.c */
133 void set_equiv(struct expression *left, struct expression *right);
134 void set_related(struct smatch_state *estate, struct related_list *rlist);
135 struct related_list *get_shared_relations(struct related_list *one,
136 struct related_list *two);
137 struct related_list *clone_related_list(struct related_list *related);
138 void remove_from_equiv(const char *name, struct symbol *sym);
139 void remove_from_equiv_expr(struct expression *expr);
140 void set_equiv_state_expr(int id, struct expression *expr, struct smatch_state *state);
142 /* smatch_function_hooks.c */
143 void function_comparison(int comparison, struct expression *expr, sval_t sval, int left);
145 /* smatch_expressions.c */
146 struct expression *zero_expr();
147 struct expression *value_expr(long long val);
148 struct expression *member_expression(struct expression *deref, int op, struct ident *member);
149 struct expression *deref_expression(struct expression *expr);
150 struct expression *assign_expression(struct expression *left, struct expression *right);
151 struct expression *binop_expression(struct expression *left, int op, struct expression *right);
152 struct expression *symbol_expression(struct symbol *sym);