user_data: update to stree
[smatch.git] / smatch.h
blob642ea6fc3ba6e775e734868160ab93709a56cffe
1 /*
2 * Copyright (C) 2006 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
18 #ifndef SMATCH_H_
19 # define SMATCH_H_
21 #include <stdio.h>
22 #include <string.h>
23 #include <limits.h>
24 #include <sys/time.h>
25 #include "lib.h"
26 #include "allocate.h"
27 #include "scope.h"
28 #include "parse.h"
29 #include "expression.h"
30 #include "avl.h"
32 typedef struct {
33 struct symbol *type;
34 union {
35 long long value;
36 unsigned long long uvalue;
38 } sval_t;
40 struct smatch_state {
41 const char *name;
42 void *data;
44 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
45 extern struct smatch_state undefined;
46 extern struct smatch_state merged;
47 extern struct smatch_state true_state;
48 extern struct smatch_state false_state;
49 DECLARE_ALLOCATOR(smatch_state);
51 static inline void *INT_PTR(int i)
53 return (void *)(long)i;
56 static inline int PTR_INT(void *p)
58 return (int)(long)p;
61 struct tracker {
62 char *name;
63 struct symbol *sym;
64 unsigned short owner;
66 DECLARE_ALLOCATOR(tracker);
67 DECLARE_PTR_LIST(tracker_list, struct tracker);
69 /* The first 3 struct members must match struct tracker */
70 struct sm_state {
71 const char *name;
72 struct symbol *sym;
73 unsigned short owner;
74 unsigned short merged:1;
75 unsigned short implied:1;
76 unsigned int nr_children;
77 unsigned int line;
78 struct smatch_state *state;
79 struct state_list *pool;
80 struct sm_state *left;
81 struct sm_state *right;
82 struct state_list *possible;
85 struct var_sym {
86 char *var;
87 struct symbol *sym;
89 DECLARE_ALLOCATOR(var_sym);
90 DECLARE_PTR_LIST(var_sym_list, struct var_sym);
92 enum hook_type {
93 EXPR_HOOK,
94 STMT_HOOK,
95 STMT_HOOK_AFTER,
96 SYM_HOOK,
97 STRING_HOOK,
98 DECLARATION_HOOK,
99 ASSIGNMENT_HOOK,
100 RAW_ASSIGNMENT_HOOK,
101 GLOBAL_ASSIGNMENT_HOOK,
102 LOGIC_HOOK,
103 CONDITION_HOOK,
104 PRELOOP_HOOK,
105 SELECT_HOOK,
106 WHOLE_CONDITION_HOOK,
107 FUNCTION_CALL_HOOK,
108 CALL_HOOK_AFTER_INLINE,
109 CALL_ASSIGNMENT_HOOK,
110 MACRO_ASSIGNMENT_HOOK,
111 BINOP_HOOK,
112 OP_HOOK,
113 DEREF_HOOK,
114 CASE_HOOK,
115 ASM_HOOK,
116 CAST_HOOK,
117 SIZEOF_HOOK,
118 BASE_HOOK,
119 FUNC_DEF_HOOK,
120 AFTER_DEF_HOOK,
121 END_FUNC_HOOK,
122 AFTER_FUNC_HOOK,
123 RETURN_HOOK,
124 INLINE_FN_START,
125 INLINE_FN_END,
126 END_FILE_HOOK,
129 #define TRUE 1
130 #define FALSE 0
132 struct range_list;
134 void add_hook(void *func, enum hook_type type);
135 typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
136 typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
137 void add_merge_hook(int client_id, merge_func_t *func);
138 void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
139 typedef void (scope_hook)(void *data);
140 void add_scope_hook(scope_hook *hook, void *data);
141 typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
142 typedef void (implication_hook)(const char *fn, struct expression *call_expr,
143 struct expression *assign_expr, void *data);
144 typedef void (return_implies_hook)(struct expression *call_expr,
145 int param, char *key, char *value);
146 typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
147 void add_function_hook(const char *look_for, func_hook *call_back, void *data);
149 void add_function_assign_hook(const char *look_for, func_hook *call_back,
150 void *info);
151 void add_implied_return_hook(const char *look_for,
152 implied_return_hook *call_back,
153 void *info);
154 void add_macro_assign_hook(const char *look_for, func_hook *call_back,
155 void *info);
156 void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
157 void *info);
158 void return_implies_state(const char *look_for, long long start, long long end,
159 implication_hook *call_back, void *info);
160 void select_return_states_hook(int type, return_implies_hook *callback);
161 void select_return_states_before(void (*fn)(void));
162 void select_return_states_after(void (*fn)(void));
163 int get_implied_return(struct expression *expr, struct range_list **rl);
165 typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
166 void add_modification_hook(int owner, modification_hook *call_back);
167 void add_indirect_modification_hook(int owner, modification_hook *call_back);
169 int outside_of_function(void);
170 const char *get_filename(void);
171 const char *get_base_file(void);
172 char *get_function(void);
173 int get_lineno(void);
174 extern int final_pass;
175 extern struct symbol *cur_func_sym;
176 extern int option_debug;
177 extern int local_debug;
178 extern int option_info;
179 int is_silenced_function(void);
181 extern FILE *sm_outfd;
182 #define sm_printf(msg...) do { if (final_pass || option_debug) fprintf(sm_outfd, msg); } while (0)
184 static inline void sm_prefix(void)
186 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
189 static inline void print_implied_debug_msg();
191 #define sm_msg(msg...) \
192 do { \
193 print_implied_debug_msg(); \
194 if (!option_debug && !final_pass) \
195 break; \
196 if (!option_info && is_silenced_function()) \
197 break; \
198 sm_prefix(); \
199 sm_printf(msg); \
200 sm_printf("\n"); \
201 } while (0)
203 #define local_debug(msg...) \
204 do { \
205 if (local_debug) \
206 sm_msg(msg); \
207 } while (0)
209 extern char *implied_debug_msg;
210 static inline void print_implied_debug_msg()
212 static struct symbol *last_printed = NULL;
214 if (!implied_debug_msg)
215 return;
216 if (last_printed == cur_func_sym)
217 return;
218 last_printed = cur_func_sym;
219 sm_msg("%s", implied_debug_msg);
222 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
224 #define sm_info(msg...) do { \
225 if (option_debug || (option_info && final_pass)) { \
226 sm_prefix(); \
227 sm_printf("info: "); \
228 sm_printf(msg); \
229 sm_printf("\n"); \
231 } while(0)
233 struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
234 struct smatch_state *get_state_expr(int owner, struct expression *expr);
235 struct state_list *get_possible_states(int owner, const char *name,
236 struct symbol *sym);
237 struct state_list *get_possible_states_expr(int owner, struct expression *expr);
238 struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
239 struct smatch_state *state);
240 struct sm_state *set_state_expr(int owner, struct expression *expr,
241 struct smatch_state *state);
242 void delete_state(int owner, const char *name, struct symbol *sym);
243 void delete_state_expr(int owner, struct expression *expr);
244 void set_true_false_states(int owner, const char *name, struct symbol *sym,
245 struct smatch_state *true_state,
246 struct smatch_state *false_state);
247 void set_true_false_states_expr(int owner, struct expression *expr,
248 struct smatch_state *true_state,
249 struct smatch_state *false_state);
251 struct state_list *get_all_states_slist(int owner, struct state_list *source);
252 struct state_list *get_all_states(int id);
253 struct AVL *get_all_states_from_stree(int owner, struct AVL *source);
254 struct AVL *get_all_states_stree(int id);
255 struct AVL *__get_cur_stree(void);
256 int is_reachable(void);
258 /* smatch_helper.c */
259 char *alloc_string(const char *str);
260 void free_string(char *str);
261 void append(char *dest, const char *data, int buff_len);
262 void remove_parens(char *str);
263 struct smatch_state *alloc_state_num(int num);
264 struct expression *get_argument_from_call_expr(struct expression_list *args,
265 int num);
267 char *expr_to_var(struct expression *expr);
268 char *expr_to_str(struct expression *expr);
269 char *expr_to_str_sym(struct expression *expr,
270 struct symbol **sym_ptr);
271 char *expr_to_var_sym(struct expression *expr,
272 struct symbol **sym_ptr);
274 int sym_name_is(const char *name, struct expression *expr);
275 int get_const_value(struct expression *expr, sval_t *sval);
276 int get_value(struct expression *expr, sval_t *val);
277 int get_implied_value(struct expression *expr, sval_t *val);
278 int get_implied_min(struct expression *expr, sval_t *sval);
279 int get_implied_max(struct expression *expr, sval_t *val);
280 int get_hard_max(struct expression *expr, sval_t *sval);
281 int get_fuzzy_min(struct expression *expr, sval_t *min);
282 int get_fuzzy_max(struct expression *expr, sval_t *max);
283 int get_absolute_min(struct expression *expr, sval_t *sval);
284 int get_absolute_max(struct expression *expr, sval_t *sval);
285 int parse_call_math(struct expression *expr, char *math, sval_t *val);
286 int is_zero(struct expression *expr);
287 int known_condition_true(struct expression *expr);
288 int known_condition_false(struct expression *expr);
289 int implied_condition_true(struct expression *expr);
290 int implied_condition_false(struct expression *expr);
292 int is_array(struct expression *expr);
293 struct expression *get_array_name(struct expression *expr);
294 struct expression *get_array_offset(struct expression *expr);
295 const char *show_state(struct smatch_state *state);
296 struct statement *get_expression_statement(struct expression *expr);
297 struct expression *strip_parens(struct expression *expr);
298 struct expression *strip_expr(struct expression *expr);
299 void scoped_state(int my_id, const char *name, struct symbol *sym);
300 int is_error_return(struct expression *expr);
301 int getting_address(void);
302 char *get_member_name(struct expression *expr);
303 char *get_fnptr_name(struct expression *expr);
304 int cmp_pos(struct position pos1, struct position pos2);
305 int positions_eq(struct position pos1, struct position pos2);
306 struct statement *get_current_statement(void);
307 int get_param_num_from_sym(struct symbol *sym);
308 int get_param_num(struct expression *expr);
309 int ms_since(struct timeval *start);
311 /* smatch_type.c */
312 struct symbol *get_real_base_type(struct symbol *sym);
313 int type_bits(struct symbol *type);
314 int type_positive_bits(struct symbol *type);
315 struct symbol *get_pointer_type(struct expression *expr);
316 struct symbol *get_type(struct expression *expr);
317 int type_unsigned(struct symbol *base_type);
318 int type_signed(struct symbol *base_type);
319 int expr_unsigned(struct expression *expr);
320 int returns_unsigned(struct symbol *base_type);
321 int is_pointer(struct expression *expr);
322 int returns_pointer(struct symbol *base_type);
323 sval_t sval_type_max(struct symbol *base_type);
324 sval_t sval_type_min(struct symbol *base_type);
325 int nr_bits(struct expression *expr);
326 int is_void_pointer(struct expression *expr);
327 int is_char_pointer(struct expression *expr);
328 int is_static(struct expression *expr);
329 int types_equiv(struct symbol *one, struct symbol *two);
330 int fn_static(void);
331 const char *global_static();
332 struct symbol *cur_func_return_type(void);
333 struct symbol *get_arg_type(struct expression *fn, int arg);
334 struct symbol *get_member_type_from_key(struct expression *expr, char *key);
336 /* smatch_ignore.c */
337 void add_ignore(int owner, const char *name, struct symbol *sym);
338 int is_ignored(int owner, const char *name, struct symbol *sym);
340 /* smatch_var_sym */
341 struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
342 struct var_sym_list *expr_to_vsl(struct expression *expr);
343 void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
344 void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
345 void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
346 int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
347 struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
348 void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
349 struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
350 void free_var_sym_list(struct var_sym_list **list);
351 void free_var_syms_and_list(struct var_sym_list **list);
353 /* smatch_tracker */
354 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
355 void add_tracker(struct tracker_list **list, int owner, const char *name,
356 struct symbol *sym);
357 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
358 void del_tracker(struct tracker_list **list, int owner, const char *name,
359 struct symbol *sym);
360 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
361 struct symbol *sym);
362 void free_tracker_list(struct tracker_list **list);
363 void free_trackers_and_list(struct tracker_list **list);
365 /* smatch_conditions */
366 int in_condition(void);
368 /* smatch_flow.c */
370 extern int __in_fake_assign;
371 void smatch (int argc, char **argv);
372 int inside_loop(void);
373 int definitely_inside_loop(void);
374 struct expression *get_switch_expr(void);
375 int in_expression_statement(void);
376 void __process_post_op_stack(void);
377 void __split_expr(struct expression *expr);
378 void __split_stmt(struct statement *stmt);
379 extern int __in_function_def;
380 extern int option_assume_loops;
381 extern int option_known_conditions;
382 extern int option_two_passes;
383 extern int option_no_db;
384 extern int option_file_output;
385 extern int option_time;
386 extern struct expression_list *big_expression_stack;
387 extern struct statement_list *big_statement_stack;
388 int inlinable(struct expression *expr);
389 extern int __inline_call;
390 extern struct expression *__inline_fn;
391 extern int __in_pre_condition;
392 extern int __bail_on_rest_of_function;
394 /* smatch_struct_assignment.c */
395 enum {
396 COPY_NORMAL,
397 COPY_MEMCPY,
398 COPY_MEMSET,
400 void __struct_members_copy(int mode, struct expression *left, struct expression *right);
401 void __fake_struct_member_assignments(struct expression *expr);
403 /* smatch_project.c */
404 int is_no_inline_function(const char *function);
406 /* smatch_conditions */
407 void __split_whole_condition(struct expression *expr);
408 void __handle_logic(struct expression *expr);
409 int is_condition(struct expression *expr);
410 int __handle_condition_assigns(struct expression *expr);
411 int __handle_select_assigns(struct expression *expr);
412 int __handle_expr_statement_assigns(struct expression *expr);
414 /* smatch_implied.c */
415 extern int option_debug_implied;
416 extern int option_debug_related;
417 extern int option_no_implied;
418 struct range_list_stack;
419 struct state_list *__implied_case_slist(struct expression *switch_expr,
420 struct expression *case_expr,
421 struct range_list_stack **remaining_cases,
422 struct AVL **raw_stree);
423 struct range_list *__get_implied_values(struct expression *switch_expr);
424 void overwrite_states_using_pool(struct sm_state *sm);
426 /* smatch_extras.c */
427 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
429 struct data_range {
430 sval_t min;
431 sval_t max;
434 static const long long valid_ptr_max = LONG_MAX;
435 static const long long valid_ptr_min = 4096;
436 static const sval_t valid_ptr_max_sval = {
437 .type = &ptr_ctype,
438 {.value = LONG_MAX},
440 static const sval_t valid_ptr_min_sval = {
441 .type = &ptr_ctype,
442 {.value = 4096},
445 /* smatch_absolute.c */
446 int get_absolute_min_helper(struct expression *expr, sval_t *sval);
447 int get_absolute_max_helper(struct expression *expr, sval_t *sval);
449 /* smatch_local_values.c */
450 int get_local_rl(struct expression *expr, struct range_list **rl);
451 int get_local_max_helper(struct expression *expr, sval_t *sval);
452 int get_local_min_helper(struct expression *expr, sval_t *sval);
454 /* smatch_type_value.c */
455 int get_db_type_rl(struct expression *expr, struct range_list **rl);
457 /* smatch_states.c */
458 void __push_fake_cur_slist();
459 struct AVL *__pop_fake_cur_slist();
460 void __free_fake_cur_slist();
461 void __set_fake_cur_slist_fast(struct state_list *slist);
462 void __pop_fake_cur_slist_fast(void);
463 void __set_fake_cur_stree_fast(struct AVL *stree);
464 void __pop_fake_cur_stree_fast(void);
465 void __merge_slist_into_cur(struct state_list *slist);
467 int unreachable(void);
468 void __set_sm(struct sm_state *sm);
469 struct state_list *__get_cur_slist(void);
470 void __set_true_false_sm(struct sm_state *true_state,
471 struct sm_state *false_state);
472 void nullify_path(void);
473 void __match_nullify_path_hook(const char *fn, struct expression *expr,
474 void *unused);
475 void __unnullify_path(void);
476 int __path_is_null(void);
477 void save_all_states(void);
478 void nullify_all_states(void);
479 void restore_all_states(void);
480 void clear_all_states(void);
482 struct sm_state *get_sm_state(int owner, const char *name,
483 struct symbol *sym);
484 struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
485 void __push_true_states(void);
486 void __use_false_states(void);
487 void __discard_false_states(void);
488 void __merge_false_states(void);
489 void __merge_true_states(void);
491 void __negate_cond_stacks(void);
492 void __use_pre_cond_states(void);
493 void __use_cond_true_states(void);
494 void __use_cond_false_states(void);
495 void __push_cond_stacks(void);
496 struct AVL *__copy_cond_true_states(void);
497 struct AVL *__copy_cond_false_states(void);
498 struct AVL *__pop_cond_true_stack(void);
499 struct AVL *__pop_cond_false_stack(void);
500 void __and_cond_states(void);
501 void __or_cond_states(void);
502 void __save_pre_cond_states(void);
503 void __discard_pre_cond_states(void);
504 void __use_cond_states(void);
505 extern struct state_list *__last_base_slist;
507 void __warn_on_silly_pre_loops(void);
509 void __push_continues(void);
510 void __discard_continues(void);
511 void __process_continues(void);
512 void __merge_continues(void);
514 void __push_breaks(void);
515 void __process_breaks(void);
516 int __has_breaks(void);
517 void __merge_breaks(void);
518 void __use_breaks(void);
520 void __save_switch_states(struct expression *switch_expr);
521 void __discard_switches(void);
522 void __merge_switches(struct expression *switch_expr, struct expression *case_expr);
523 void __push_default(void);
524 void __set_default(void);
525 int __pop_default(void);
527 void __push_conditions(void);
528 void __discard_conditions(void);
530 void __save_gotos(const char *name);
531 void __merge_gotos(const char *name);
533 void __print_cur_slist(void);
535 /* smatch_hooks.c */
536 void __pass_to_client(void *data, enum hook_type type);
537 void __pass_to_client_no_data(enum hook_type type);
538 void __pass_case_to_client(struct expression *switch_expr,
539 struct expression *case_expr);
540 int __has_merge_function(int client_id);
541 struct smatch_state *__client_merge_function(int owner,
542 struct smatch_state *s1,
543 struct smatch_state *s2);
544 struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
545 void __push_scope_hooks(void);
546 void __call_scope_hooks(void);
548 /* smatch_function_hooks.c */
549 void create_function_hook_hash(void);
550 void __match_initializer_call(struct symbol *sym);
552 /* smatch_db.c */
553 enum info_type {
554 INTERNAL = 0,
556 * Changing these numbers is a pain. Don't do it. If you ever use a
557 * number it can't be re-used right away so there may be gaps.
558 * We select these in order by type so if the order matters, then give
559 * it a number below 100-999,9000-9999 ranges. */
561 PARAM_CLEARED = 101,
562 FILTER_VALUE = 102,
564 PARAM_VALUE = 1001,
565 BUF_SIZE = 1002,
566 USER_DATA = 1003,
567 CAPPED_DATA = 1004,
568 RETURN_VALUE = 1005,
569 DEREFERENCE = 1006,
570 RANGE_CAP = 1007,
571 LOCK_HELD = 1008,
572 LOCK_RELEASED = 1009,
573 ABSOLUTE_LIMITS = 1010,
574 LIMITED_VALUE = 1011,
575 ADDED_VALUE = 1012,
576 PARAM_FREED = 1013,
577 DATA_SOURCE = 1014,
578 FUZZY_MAX = 1015,
579 STR_LEN = 1016,
582 void debug_sql(const char *sql);
583 void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
584 void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct smatch_state *state));
585 void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
586 void add_returned_member_callback(int owner, void (*callback)(int return_id, char *return_ranges, char *printed_name, struct smatch_state *state));
587 void select_call_implies_hook(int type, void (*callback)(struct expression *arg, char *value));
588 struct range_list *db_return_vals(struct expression *expr);
589 char *return_state_to_var_sym(struct expression *expr, int param, char *key, struct symbol **sym);
590 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym);
591 const char *get_param_name(struct sm_state *sm);
593 #define run_sql(call_back, sql...) \
594 do { \
595 char sql_txt[1024]; \
596 if (option_no_db) \
597 break; \
598 snprintf(sql_txt, 1024, sql); \
599 debug_sql(sql_txt); \
600 sql_exec(call_back, sql_txt); \
601 } while (0)
603 /* like run_sql() but for the in-memory database */
604 #define mem_sql(call_back, sql...) \
605 do { \
606 char sql_txt[1024]; \
608 snprintf(sql_txt, sizeof(sql_txt), sql); \
609 sm_debug("in-mem: %s\n", sql_txt); \
610 sql_mem_exec(call_back, sql_txt); \
611 } while (0)
613 void sql_insert_return_states(int return_id, const char *return_ranges,
614 int type, int param, const char *key, const char *value);
615 void sql_insert_caller_info(struct expression *call, int type, int param,
616 const char *key, const char *value);
617 void sql_insert_function_ptr(const char *fn, const char *struct_name);
618 void sql_insert_return_values(const char *return_values);
619 void sql_insert_call_implies(int type, int param, int value);
620 void sql_insert_function_type_size(const char *member, const char *ranges);
621 void sql_insert_local_values(const char *name, const char *value);
622 void sql_insert_function_type_value(const char *type, const char *value);
624 void sql_select_return_states(const char *cols, struct expression *call,
625 int (*callback)(void*, int, char**, char**));
626 void sql_select_caller_info(const char *cols, struct symbol *sym,
627 int (*callback)(void*, int, char**, char**));
628 void sql_select_call_implies(const char *cols, struct expression *call,
629 int (*callback)(void*, int, char**, char**));
631 void sql_exec(int (*callback)(void*, int, char**, char**), const char *sql);
632 void sql_mem_exec(int (*callback)(void*, int, char**, char**), const char *sql);
634 void open_smatch_db(void);
636 /* smatch_files.c */
637 int open_data_file(const char *filename);
638 struct token *get_tokens_file(const char *filename);
640 /* smatch.c */
641 extern char *option_debug_check;
642 extern char *option_project_str;
643 extern char *data_dir;
644 extern int option_no_data;
645 extern int option_spammy;
646 extern int option_full_path;
647 extern int option_param_mapper;
648 extern int option_call_tree;
649 extern int num_checks;
651 enum project_type {
652 PROJ_NONE,
653 PROJ_KERNEL,
654 PROJ_WINE,
656 extern enum project_type option_project;
657 const char *check_name(unsigned short id);
660 /* smatch_buf_size.c */
661 int get_array_size(struct expression *expr);
662 int get_array_size_bytes(struct expression *expr);
663 int get_array_size_bytes_min(struct expression *expr);
664 int get_array_size_bytes_max(struct expression *expr);
665 struct range_list *get_array_size_bytes_rl(struct expression *expr);
666 int get_real_array_size(struct expression *expr);
667 /* smatch_strlen.c */
668 int get_implied_strlen(struct expression *expr, struct range_list **rl);
669 int get_size_from_strlen(struct expression *expr);
671 /* smatch_capped.c */
672 int is_capped(struct expression *expr);
673 int is_capped_var_sym(const char *name, struct symbol *sym);
675 /* check_user_data.c */
676 int is_user_macro(struct expression *expr);
677 int is_user_data(struct expression *expr);
678 int is_capped_user_data(struct expression *expr);
680 /* check_locking.c */
681 void print_held_locks();
683 /* check_assigned_expr.c */
684 struct expression *get_assigned_expr(struct expression *expr);
686 /* smatch_comparison.c */
687 int get_comparison(struct expression *left, struct expression *right);
688 int get_comparison_strings(const char *one, const char *two);
689 void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
690 char *expr_equal_to_param(struct expression *expr);
691 char *expr_lte_to_param(struct expression *expr);
693 /* smatch_sval.c */
694 sval_t *sval_alloc(sval_t sval);
695 sval_t *sval_alloc_permanent(sval_t sval);
696 sval_t sval_blank(struct expression *expr);
697 sval_t sval_type_val(struct symbol *type, long long val);
698 sval_t sval_from_val(struct expression *expr, long long val);
699 int sval_unsigned(sval_t sval);
700 int sval_signed(sval_t sval);
701 int sval_bits(sval_t sval);
702 int sval_positive_bits(sval_t sval);
703 int sval_bits_used(sval_t sval);
704 int sval_is_negative(sval_t sval);
705 int sval_is_positive(sval_t sval);
706 int sval_is_min(sval_t sval);
707 int sval_is_max(sval_t sval);
708 int sval_is_a_min(sval_t sval);
709 int sval_is_a_max(sval_t sval);
710 int sval_is_negative_min(sval_t sval);
711 int sval_cmp(sval_t one, sval_t two);
712 int sval_cmp_t(struct symbol *type, sval_t one, sval_t two);
713 int sval_cmp_val(sval_t one, long long val);
714 sval_t sval_min(sval_t one, sval_t two);
715 sval_t sval_max(sval_t one, sval_t two);
716 int sval_too_low(struct symbol *type, sval_t sval);
717 int sval_too_high(struct symbol *type, sval_t sval);
718 int sval_fits(struct symbol *type, sval_t sval);
719 sval_t sval_cast(struct symbol *type, sval_t sval);
720 sval_t sval_preop(sval_t sval, int op);
721 sval_t sval_binop(sval_t left, int op, sval_t right);
722 int sval_binop_overflows(sval_t left, int op, sval_t right);
723 const char *sval_to_str(sval_t sval);
724 const char *sval_to_numstr(sval_t sval);
725 sval_t ll_to_sval(long long val);
727 /* smatch_string_list.c */
728 int list_has_string(struct string_list *str_list, char *str);
729 void insert_string(struct string_list **str_list, char *str);
730 struct string_list *clone_str_list(struct string_list *orig);
731 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
733 /* smatch_clear_buffer.c */
734 int is_uninitialized(struct expression *expr);
735 int has_uninitialized_members(struct expression *expr);
737 /* smatch_start_states.c */
738 struct state_list *get_start_states(void);
740 /* smatch_recurse.c */
741 int has_symbol(struct expression *expr, struct symbol *sym);
742 int has_variable(struct expression *expr, struct expression *var);
743 int has_inc_dec(struct expression *expr);
745 /* smatch_stored_conditions.c */
746 struct smatch_state *get_stored_condition(struct expression *expr);
748 /* check_string_len.c */
749 int get_formatted_string_size(struct expression *call, int arg);
751 #endif /* !SMATCH_H_ */