Make some kernel specific stuff depend on -p=kernel
[smatch.git] / smatch_containers.c
blobcb4721bacb7088aa052dbd4fbc5a3564279826c5
1 /*
2 * sparse/smatch_containers.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 static struct tracker_list *member_list;
15 int is_member(struct expression *expr)
17 if (expr->type == EXPR_DEREF)
18 return 1;
19 return 0;
22 void set_default_state(int owner, struct smatch_state *state)
24 default_state[owner] = state;
27 void reset_on_container_modified(int owner, struct expression *expr)
29 char *name;
30 struct symbol *sym;
32 return; /* this stuff is taking too long */
34 if (!is_member(expr))
35 return;
37 expr = strip_expr(expr);
38 name = get_variable_from_expr(expr, &sym);
39 if (!name || !sym)
40 goto free;
41 add_tracker(&member_list, owner, name, sym);
42 free:
43 free_string(name);
46 static void match_assign_call(struct expression *expr)
48 struct tracker *tmp;
49 struct symbol *sym;
50 char *name;
51 struct expression *left;
53 left = strip_expr(expr->left);
54 name = get_variable_from_expr(left, &sym);
55 if (!name || !sym)
56 goto free;
58 FOR_EACH_PTR(member_list, tmp) {
59 if (!default_state[tmp->owner])
60 continue;
61 if (tmp->sym == sym
62 && !strncmp(tmp->name, name, strlen(name))) {
63 set_state(tmp->owner, tmp->name, tmp->sym, default_state[tmp->owner]);
64 goto free;
66 } END_FOR_EACH_PTR(tmp);
67 free:
68 free_string(name);
71 static void match_func_end(struct symbol *sym)
73 free_trackers_and_list(&member_list);
76 void register_containers(int id)
78 add_hook(&match_assign_call, CALL_ASSIGNMENT_HOOK);
79 add_hook(&match_func_end, END_FUNC_HOOK);