Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_links.c
+++ new/usr/src/tools/smatch/src/smatch_links.c
1 1 /*
2 2 * Copyright (C) 2014 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 /*
19 19 * Some helper functions for managing links.
20 20 *
21 21 */
22 22
23 23 #include "smatch.h"
24 24 #include "smatch_slist.h"
25 25
26 26 static struct smatch_state *alloc_link(struct var_sym_list *links)
27 27 {
28 28 struct smatch_state *state;
29 29 static char buf[256];
30 30 struct var_sym *tmp;
31 31 int i;
32 32
33 33 state = __alloc_smatch_state(0);
34 34
35 35 i = 0;
36 36 FOR_EACH_PTR(links, tmp) {
37 37 if (!i++) {
38 38 snprintf(buf, sizeof(buf), "%s", tmp->var);
39 39 } else {
40 40 append(buf, ", ", sizeof(buf));
41 41 append(buf, tmp->var, sizeof(buf));
42 42 }
43 43 } END_FOR_EACH_PTR(tmp);
44 44
45 45 state->name = alloc_sname(buf);
46 46 state->data = links;
47 47 return state;
48 48 }
49 49
50 50 struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2)
51 51 {
52 52 struct var_sym_list *new_links;
53 53
54 54 if (s1 == &undefined)
55 55 return s2;
56 56 if (s2 == &undefined)
57 57 return s1;
58 58
59 59 if (var_sym_lists_equiv(s1->data, s2->data))
60 60 return s1;
61 61
62 62 new_links = clone_var_sym_list(s1->data);
63 63 merge_var_sym_list(&new_links, s2->data);
64 64
65 65 return alloc_link(new_links);
66 66 }
67 67
68 68 void store_link(int link_id, const char *var, struct symbol *sym, const char *link_name, struct symbol *link_sym)
69 69 {
70 70
71 71 struct smatch_state *old_state;
72 72 struct var_sym_list *links;
73 73
74 74 if (!cur_func_sym)
75 75 return;
76 76
77 77 old_state = get_state(link_id, var, sym);
78 78 if (old_state)
79 79 links = clone_var_sym_list(old_state->data);
80 80 else
81 81 links = NULL;
82 82
83 83 add_var_sym(&links, link_name, link_sym);
84 84 set_state(link_id, var, sym, alloc_link(links));
85 85 }
86 86
87 87 static void match_link_modify(struct sm_state *sm, struct expression *mod_expr)
88 88 {
89 89 struct var_sym_list *links;
90 90 struct var_sym *tmp;
91 91
92 92 links = sm->state->data;
93 93
94 94 FOR_EACH_PTR(links, tmp) {
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
95 95 set_state(sm->owner - 1, tmp->var, tmp->sym, &undefined);
96 96 } END_FOR_EACH_PTR(tmp);
97 97 set_state(sm->owner, sm->name, sm->sym, &undefined);
98 98 }
99 99
100 100 void set_up_link_functions(int id, int link_id)
101 101 {
102 102 if (id + 1 != link_id)
103 103 sm_fatal("FATAL ERROR: links need to be registered directly after the check");
104 104
105 + set_dynamic_states(link_id);
105 106 add_merge_hook(link_id, &merge_link_states);
106 107 add_modification_hook(link_id, &match_link_modify);
107 108 // free link at the end of function
108 109 }
109 110
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX