1*1f5207b7SJohn Levon /*
2*1f5207b7SJohn Levon * Copyright (C) 2009 Dan Carpenter.
3*1f5207b7SJohn Levon *
4*1f5207b7SJohn Levon * This program is free software; you can redistribute it and/or
5*1f5207b7SJohn Levon * modify it under the terms of the GNU General Public License
6*1f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2
7*1f5207b7SJohn Levon * of the License, or (at your option) any later version.
8*1f5207b7SJohn Levon *
9*1f5207b7SJohn Levon * This program is distributed in the hope that it will be useful,
10*1f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*1f5207b7SJohn Levon * GNU General Public License for more details.
13*1f5207b7SJohn Levon *
14*1f5207b7SJohn Levon * You should have received a copy of the GNU General Public License
15*1f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16*1f5207b7SJohn Levon */
17*1f5207b7SJohn Levon
18*1f5207b7SJohn Levon #include "smatch.h"
19*1f5207b7SJohn Levon
20*1f5207b7SJohn Levon ALLOCATOR(tracker, "trackers");
21*1f5207b7SJohn Levon
alloc_tracker(int owner,const char * name,struct symbol * sym)22*1f5207b7SJohn Levon struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym)
23*1f5207b7SJohn Levon {
24*1f5207b7SJohn Levon struct tracker *tmp;
25*1f5207b7SJohn Levon
26*1f5207b7SJohn Levon tmp = __alloc_tracker(0);
27*1f5207b7SJohn Levon tmp->name = alloc_string(name);
28*1f5207b7SJohn Levon tmp->owner = owner;
29*1f5207b7SJohn Levon tmp->sym = sym;
30*1f5207b7SJohn Levon return tmp;
31*1f5207b7SJohn Levon }
32*1f5207b7SJohn Levon
add_tracker(struct tracker_list ** list,int owner,const char * name,struct symbol * sym)33*1f5207b7SJohn Levon void add_tracker(struct tracker_list **list, int owner, const char *name,
34*1f5207b7SJohn Levon struct symbol *sym)
35*1f5207b7SJohn Levon {
36*1f5207b7SJohn Levon struct tracker *tmp;
37*1f5207b7SJohn Levon
38*1f5207b7SJohn Levon if (in_tracker_list(*list, owner, name, sym))
39*1f5207b7SJohn Levon return;
40*1f5207b7SJohn Levon tmp = alloc_tracker(owner, name, sym);
41*1f5207b7SJohn Levon add_ptr_list(list, tmp);
42*1f5207b7SJohn Levon }
43*1f5207b7SJohn Levon
add_tracker_expr(struct tracker_list ** list,int owner,struct expression * expr)44*1f5207b7SJohn Levon void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr)
45*1f5207b7SJohn Levon {
46*1f5207b7SJohn Levon char *name;
47*1f5207b7SJohn Levon struct symbol *sym;
48*1f5207b7SJohn Levon
49*1f5207b7SJohn Levon name = expr_to_var_sym(expr, &sym);
50*1f5207b7SJohn Levon if (!name || !sym)
51*1f5207b7SJohn Levon goto free;
52*1f5207b7SJohn Levon add_tracker(list, owner, name, sym);
53*1f5207b7SJohn Levon free:
54*1f5207b7SJohn Levon free_string(name);
55*1f5207b7SJohn Levon }
56*1f5207b7SJohn Levon
free_tracker(struct tracker * t)57*1f5207b7SJohn Levon static void free_tracker(struct tracker *t)
58*1f5207b7SJohn Levon {
59*1f5207b7SJohn Levon free_string(t->name);
60*1f5207b7SJohn Levon __free_tracker(t);
61*1f5207b7SJohn Levon }
62*1f5207b7SJohn Levon
del_tracker(struct tracker_list ** list,int owner,const char * name,struct symbol * sym)63*1f5207b7SJohn Levon void del_tracker(struct tracker_list **list, int owner, const char *name,
64*1f5207b7SJohn Levon struct symbol *sym)
65*1f5207b7SJohn Levon {
66*1f5207b7SJohn Levon struct tracker *tmp;
67*1f5207b7SJohn Levon
68*1f5207b7SJohn Levon FOR_EACH_PTR(*list, tmp) {
69*1f5207b7SJohn Levon if (tmp->owner == owner && tmp->sym == sym
70*1f5207b7SJohn Levon && !strcmp(tmp->name, name)) {
71*1f5207b7SJohn Levon DELETE_CURRENT_PTR(tmp);
72*1f5207b7SJohn Levon free_tracker(tmp);
73*1f5207b7SJohn Levon return;
74*1f5207b7SJohn Levon }
75*1f5207b7SJohn Levon } END_FOR_EACH_PTR(tmp);
76*1f5207b7SJohn Levon }
77*1f5207b7SJohn Levon
in_tracker_list(struct tracker_list * list,int owner,const char * name,struct symbol * sym)78*1f5207b7SJohn Levon int in_tracker_list(struct tracker_list *list, int owner, const char *name,
79*1f5207b7SJohn Levon struct symbol *sym)
80*1f5207b7SJohn Levon {
81*1f5207b7SJohn Levon struct tracker *tmp;
82*1f5207b7SJohn Levon
83*1f5207b7SJohn Levon FOR_EACH_PTR(list, tmp) {
84*1f5207b7SJohn Levon if (tmp->owner == owner && tmp->sym == sym
85*1f5207b7SJohn Levon && !strcmp(tmp->name, name))
86*1f5207b7SJohn Levon return 1;
87*1f5207b7SJohn Levon } END_FOR_EACH_PTR(tmp);
88*1f5207b7SJohn Levon return 0;
89*1f5207b7SJohn Levon }
90*1f5207b7SJohn Levon
free_tracker_list(struct tracker_list ** list)91*1f5207b7SJohn Levon void free_tracker_list(struct tracker_list **list)
92*1f5207b7SJohn Levon {
93*1f5207b7SJohn Levon __free_ptr_list((struct ptr_list **)list);
94*1f5207b7SJohn Levon }
95*1f5207b7SJohn Levon
free_trackers_and_list(struct tracker_list ** list)96*1f5207b7SJohn Levon void free_trackers_and_list(struct tracker_list **list)
97*1f5207b7SJohn Levon {
98*1f5207b7SJohn Levon struct tracker *tmp;
99*1f5207b7SJohn Levon
100*1f5207b7SJohn Levon FOR_EACH_PTR(*list, tmp) {
101*1f5207b7SJohn Levon free_tracker(tmp);
102*1f5207b7SJohn Levon } END_FOR_EACH_PTR(tmp);
103*1f5207b7SJohn Levon free_tracker_list(list);
104*1f5207b7SJohn Levon }
105*1f5207b7SJohn Levon
106