extra: delete the get_range_list() function
[smatch.git] / smatch_tracker.c
blob43106adb4cf59d69bd32e63d4c5c906096d77480
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 void del_tracker(struct tracker_list **list, int owner, const char *name,
50 struct symbol *sym)
52 struct tracker *tmp;
54 FOR_EACH_PTR(*list, tmp) {
55 if (tmp->owner == owner && tmp->sym == sym
56 && !strcmp(tmp->name, name)) {
57 DELETE_CURRENT_PTR(tmp);
58 __free_tracker(tmp);
59 return;
61 } END_FOR_EACH_PTR(tmp);
64 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
65 struct symbol *sym)
67 struct tracker *tmp;
69 FOR_EACH_PTR(list, tmp) {
70 if (tmp->owner == owner && tmp->sym == sym
71 && !strcmp(tmp->name, name))
72 return 1;
73 } END_FOR_EACH_PTR(tmp);
74 return 0;
77 struct tracker_list *clone_tracker_list(struct tracker_list *orig_list)
79 struct tracker *tmp;
80 struct tracker_list *to_list = NULL;
82 FOR_EACH_PTR(orig_list, tmp) {
83 add_ptr_list(&to_list, tmp);
84 } END_FOR_EACH_PTR(tmp);
86 return to_list;
89 void free_tracker_list(struct tracker_list **list)
91 __free_ptr_list((struct ptr_list **)list);
94 void free_trackers_and_list(struct tracker_list **list)
96 struct tracker *tmp;
98 FOR_EACH_PTR(*list, tmp) {
99 free_string(tmp->name);
100 __free_tracker(tmp);
101 } END_FOR_EACH_PTR(tmp);
102 free_tracker_list(list);