@@ -27,17 +27,22 @@ enum class symbol_kindt
27
27
F_ALL
28
28
};
29
29
30
+ // / Find identifiers with id ID_symbol of the sub expressions and the subs with
31
+ // / ID in \p subs_to_find
32
+ // / considering both free and bound variables, as well as any type tags.
30
33
static bool find_symbols (
31
34
symbol_kindt,
32
35
const typet &,
33
36
std::function<bool (const symbol_exprt &)>,
34
- std::unordered_set<irep_idt> &bindings);
37
+ std::unordered_set<irep_idt> &bindings,
38
+ const std::vector<irep_idt> &subs_to_find);
35
39
36
40
static bool find_symbols (
37
41
symbol_kindt kind,
38
42
const exprt &src,
39
43
std::function<bool (const symbol_exprt &)> op,
40
- std::unordered_set<irep_idt> &bindings)
44
+ std::unordered_set<irep_idt> &bindings,
45
+ const std::vector<irep_idt> &subs_to_find)
41
46
{
42
47
if (kind == symbol_kindt::F_EXPR_FREE)
43
48
{
@@ -48,10 +53,12 @@ static bool find_symbols(
48
53
for (const auto &v : binding_expr.variables ())
49
54
new_bindings.insert (v.get_identifier ());
50
55
51
- if (!find_symbols (kind, binding_expr.where (), op, new_bindings))
56
+ if (!find_symbols (
57
+ kind, binding_expr.where (), op, new_bindings, subs_to_find))
52
58
return false ;
53
59
54
- return find_symbols (kind, binding_expr.type (), op, bindings);
60
+ return find_symbols (
61
+ kind, binding_expr.type (), op, bindings, subs_to_find);
55
62
}
56
63
else if (src.id () == ID_let)
57
64
{
@@ -60,23 +67,38 @@ static bool find_symbols(
60
67
for (const auto &v : let_expr.variables ())
61
68
new_bindings.insert (v.get_identifier ());
62
69
63
- if (!find_symbols (kind, let_expr.where (), op, new_bindings))
70
+ if (!find_symbols (kind, let_expr.where (), op, new_bindings, subs_to_find ))
64
71
return false ;
65
72
66
- if (!find_symbols (kind, let_expr.op1 (), op, new_bindings))
73
+ if (!find_symbols (kind, let_expr.op1 (), op, new_bindings, subs_to_find ))
67
74
return false ;
68
75
69
- return find_symbols (kind, let_expr.type (), op, bindings);
76
+ return find_symbols (kind, let_expr.type (), op, bindings, subs_to_find );
70
77
}
71
78
}
72
79
73
80
for (const auto &src_op : src.operands ())
74
81
{
75
- if (!find_symbols (kind, src_op, op, bindings))
82
+ if (!find_symbols (kind, src_op, op, bindings, subs_to_find ))
76
83
return false ;
77
84
}
78
85
79
- if (!find_symbols (kind, src.type (), op, bindings))
86
+ // Go over all named subs with id in subs_to_find
87
+ // and find symbols recursively.
88
+ for (const auto &sub_to_find : subs_to_find)
89
+ {
90
+ auto sub_expr = static_cast <const exprt &>(src.find (sub_to_find));
91
+ if (sub_expr.is_not_nil ())
92
+ {
93
+ for (const auto &sub_op : sub_expr.operands ())
94
+ {
95
+ if (!find_symbols (kind, sub_op, op, bindings, subs_to_find))
96
+ return false ;
97
+ }
98
+ }
99
+ }
100
+
101
+ if (!find_symbols (kind, src.type (), op, bindings, subs_to_find))
80
102
return false ;
81
103
82
104
if (src.id () == ID_symbol)
@@ -95,46 +117,58 @@ static bool find_symbols(
95
117
}
96
118
}
97
119
98
- const irept &c_sizeof_type= src.find (ID_C_c_sizeof_type);
120
+ const irept &c_sizeof_type = src.find (ID_C_c_sizeof_type);
99
121
100
122
if (
101
- c_sizeof_type.is_not_nil () &&
102
- !find_symbols (
103
- kind, static_cast <const typet &>(c_sizeof_type), op, bindings))
123
+ c_sizeof_type.is_not_nil () && !find_symbols (
124
+ kind,
125
+ static_cast <const typet &>(c_sizeof_type),
126
+ op,
127
+ bindings,
128
+ subs_to_find))
104
129
{
105
130
return false ;
106
131
}
107
132
108
133
const irept &va_arg_type=src.find (ID_C_va_arg_type);
109
134
110
135
if (
111
- va_arg_type.is_not_nil () &&
112
- !find_symbols (kind, static_cast <const typet &>(va_arg_type), op, bindings))
136
+ va_arg_type.is_not_nil () && !find_symbols (
137
+ kind,
138
+ static_cast <const typet &>(va_arg_type),
139
+ op,
140
+ bindings,
141
+ subs_to_find))
113
142
{
114
143
return false ;
115
144
}
116
145
117
146
return true ;
118
147
}
119
148
149
+ // / Find identifiers with id ID_symbol of the sub expressions and the subs with
150
+ // / ID in \p subs_to_find
151
+ // / considering both free and bound variables, as well as any type tags.
120
152
static bool find_symbols (
121
153
symbol_kindt kind,
122
154
const typet &src,
123
155
std::function<bool (const symbol_exprt &)> op,
124
- std::unordered_set<irep_idt> &bindings)
156
+ std::unordered_set<irep_idt> &bindings,
157
+ const std::vector<irep_idt> &subs_to_find)
125
158
{
126
159
if (kind != symbol_kindt::F_TYPE_NON_PTR || src.id () != ID_pointer)
127
160
{
128
161
if (
129
162
src.has_subtype () &&
130
- !find_symbols (kind, to_type_with_subtype (src).subtype (), op, bindings))
163
+ !find_symbols (
164
+ kind, to_type_with_subtype (src).subtype (), op, bindings, subs_to_find))
131
165
{
132
166
return false ;
133
167
}
134
168
135
169
for (const typet &subtype : to_type_with_subtypes (src).subtypes ())
136
170
{
137
- if (!find_symbols (kind, subtype, op, bindings))
171
+ if (!find_symbols (kind, subtype, op, bindings, subs_to_find ))
138
172
return false ;
139
173
}
140
174
@@ -155,26 +189,27 @@ static bool find_symbols(
155
189
156
190
for (const auto &c : struct_union_type.components ())
157
191
{
158
- if (!find_symbols (kind, c, op, bindings))
192
+ if (!find_symbols (kind, c, op, bindings, subs_to_find ))
159
193
return false ;
160
194
}
161
195
}
162
196
else if (src.id ()==ID_code)
163
197
{
164
198
const code_typet &code_type=to_code_type (src);
165
- if (!find_symbols (kind, code_type.return_type (), op, bindings))
199
+ if (!find_symbols (kind, code_type.return_type (), op, bindings, subs_to_find ))
166
200
return false ;
167
201
168
202
for (const auto &p : code_type.parameters ())
169
203
{
170
- if (!find_symbols (kind, p, op, bindings))
204
+ if (!find_symbols (kind, p, op, bindings, subs_to_find ))
171
205
return false ;
172
206
}
173
207
}
174
208
else if (src.id ()==ID_array)
175
209
{
176
210
// do the size -- the subtype is already done
177
- if (!find_symbols (kind, to_array_type (src).size (), op, bindings))
211
+ if (!find_symbols (
212
+ kind, to_array_type (src).size (), op, bindings, subs_to_find))
178
213
return false ;
179
214
}
180
215
else if (
@@ -204,19 +239,21 @@ static bool find_symbols(
204
239
static bool find_symbols (
205
240
symbol_kindt kind,
206
241
const typet &type,
207
- std::function<bool (const symbol_exprt &)> op)
242
+ std::function<bool (const symbol_exprt &)> op,
243
+ const std::vector<irep_idt> &subs_to_find = {})
208
244
{
209
245
std::unordered_set<irep_idt> bindings;
210
- return find_symbols (kind, type, op, bindings);
246
+ return find_symbols (kind, type, op, bindings, subs_to_find );
211
247
}
212
248
213
249
static bool find_symbols (
214
250
symbol_kindt kind,
215
251
const exprt &src,
216
- std::function<bool (const symbol_exprt &)> op)
252
+ std::function<bool (const symbol_exprt &)> op,
253
+ const std::vector<irep_idt> &subs_to_find = {})
217
254
{
218
255
std::unordered_set<irep_idt> bindings;
219
- return find_symbols (kind, src, op, bindings);
256
+ return find_symbols (kind, src, op, bindings, subs_to_find );
220
257
}
221
258
222
259
void find_symbols (const exprt &src, std::set<symbol_exprt> &dest)
@@ -278,20 +315,34 @@ void find_non_pointer_type_symbols(
278
315
});
279
316
}
280
317
281
- void find_type_and_expr_symbols (const exprt &src, find_symbols_sett &dest)
318
+ void find_type_and_expr_symbols (
319
+ const exprt &src,
320
+ find_symbols_sett &dest,
321
+ const std::vector<irep_idt> &subs_to_find)
282
322
{
283
- find_symbols (symbol_kindt::F_ALL, src, [&dest](const symbol_exprt &e) {
284
- dest.insert (e.get_identifier ());
285
- return true ;
286
- });
323
+ find_symbols (
324
+ symbol_kindt::F_ALL,
325
+ src,
326
+ [&dest](const symbol_exprt &e) {
327
+ dest.insert (e.get_identifier ());
328
+ return true ;
329
+ },
330
+ subs_to_find);
287
331
}
288
332
289
- void find_type_and_expr_symbols (const typet &src, find_symbols_sett &dest)
333
+ void find_type_and_expr_symbols (
334
+ const typet &src,
335
+ find_symbols_sett &dest,
336
+ const std::vector<irep_idt> &subs_to_find)
290
337
{
291
- find_symbols (symbol_kindt::F_ALL, src, [&dest](const symbol_exprt &e) {
292
- dest.insert (e.get_identifier ());
293
- return true ;
294
- });
338
+ find_symbols (
339
+ symbol_kindt::F_ALL,
340
+ src,
341
+ [&dest](const symbol_exprt &e) {
342
+ dest.insert (e.get_identifier ());
343
+ return true ;
344
+ },
345
+ subs_to_find);
295
346
}
296
347
297
348
void find_symbols (const exprt &src, find_symbols_sett &dest)
0 commit comments