try handle do {} while (i-- > 0)
[smatch.git] / smatch_tracker.c
blob2b50de0d37cede7c05fd09af82f0ca5a7f11f203
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 del_tracker(struct tracker_list **list, int owner, const char *name,
37 struct symbol *sym)
39 struct tracker *tmp;
41 FOR_EACH_PTR(*list, tmp) {
42 if (tmp->owner == owner && tmp->sym == sym
43 && !strcmp(tmp->name, name)) {
44 DELETE_CURRENT_PTR(tmp);
45 __free_tracker(tmp);
46 return;
48 } END_FOR_EACH_PTR(tmp);
51 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
52 struct symbol *sym)
54 struct tracker *tmp;
56 FOR_EACH_PTR(list, tmp) {
57 if (tmp->owner == owner && tmp->sym == sym
58 && !strcmp(tmp->name, name))
59 return 1;
60 } END_FOR_EACH_PTR(tmp);
61 return 0;
64 void free_tracker_list(struct tracker_list **list)
66 __free_ptr_list((struct ptr_list **)list);
69 void free_trackers_and_list(struct tracker_list **list)
71 struct tracker *tmp;
73 FOR_EACH_PTR(*list, tmp) {
74 free_string(tmp->name);
75 __free_tracker(tmp);
76 } END_FOR_EACH_PTR(tmp);
77 free_tracker_list(list);