sval: update smatch_helper.c
[smatch.git] / smatch_tracker.c
blob044298220023623efceec54cd685c7b5b84c2b61
1 /*
2 * sparse/smatch_tracker.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 ALLOCATOR(tracker, "trackers");
14 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym)
16 struct tracker *tmp;
18 tmp = __alloc_tracker(0);
19 tmp->name = alloc_string(name);
20 tmp->owner = owner;
21 tmp->sym = sym;
22 return tmp;
25 void add_tracker(struct tracker_list **list, int owner, const char *name,
26 struct symbol *sym)
28 struct tracker *tmp;
30 if (in_tracker_list(*list, owner, name, sym))
31 return;
32 tmp = alloc_tracker(owner, name, sym);
33 add_ptr_list(list, tmp);
36 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr)
38 char *name;
39 struct symbol *sym;
41 name = get_variable_from_expr(expr, &sym);
42 if (!name || !sym)
43 goto free;
44 add_tracker(list, owner, name, sym);
45 free:
46 free_string(name);
49 static void free_tracker(struct tracker *t)
51 free_string(t->name);
52 __free_tracker(t);
55 void del_tracker(struct tracker_list **list, int owner, const char *name,
56 struct symbol *sym)
58 struct tracker *tmp;
60 FOR_EACH_PTR(*list, tmp) {
61 if (tmp->owner == owner && tmp->sym == sym
62 && !strcmp(tmp->name, name)) {
63 DELETE_CURRENT_PTR(tmp);
64 free_tracker(tmp);
65 return;
67 } END_FOR_EACH_PTR(tmp);
70 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
71 struct symbol *sym)
73 struct tracker *tmp;
75 FOR_EACH_PTR(list, tmp) {
76 if (tmp->owner == owner && tmp->sym == sym
77 && !strcmp(tmp->name, name))
78 return 1;
79 } END_FOR_EACH_PTR(tmp);
80 return 0;
83 void free_tracker_list(struct tracker_list **list)
85 __free_ptr_list((struct ptr_list **)list);
88 void free_trackers_and_list(struct tracker_list **list)
90 struct tracker *tmp;
92 FOR_EACH_PTR(*list, tmp) {
93 free_tracker(tmp);
94 } END_FOR_EACH_PTR(tmp);
95 free_tracker_list(list);