@@ -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
- const irept &va_arg_type= src.find (ID_C_va_arg_type);
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
@@ -148,33 +182,33 @@ static bool find_symbols(
148
182
}
149
183
}
150
184
151
- if (src.id ()==ID_struct ||
152
- src.id ()==ID_union)
185
+ if (src.id () == ID_struct || src.id () == ID_union)
153
186
{
154
- const struct_union_typet &struct_union_type= to_struct_union_type (src);
187
+ const struct_union_typet &struct_union_type = to_struct_union_type (src);
155
188
156
189
for (const auto &c : struct_union_type.components ())
157
190
{
158
- if (!find_symbols (kind, c, op, bindings))
191
+ if (!find_symbols (kind, c, op, bindings, subs_to_find ))
159
192
return false ;
160
193
}
161
194
}
162
- else if (src.id ()== ID_code)
195
+ else if (src.id () == ID_code)
163
196
{
164
- const code_typet &code_type= to_code_type (src);
165
- if (!find_symbols (kind, code_type.return_type (), op, bindings))
197
+ const code_typet &code_type = to_code_type (src);
198
+ if (!find_symbols (kind, code_type.return_type (), op, bindings, subs_to_find ))
166
199
return false ;
167
200
168
201
for (const auto &p : code_type.parameters ())
169
202
{
170
- if (!find_symbols (kind, p, op, bindings))
203
+ if (!find_symbols (kind, p, op, bindings, subs_to_find ))
171
204
return false ;
172
205
}
173
206
}
174
- else if (src.id ()== ID_array)
207
+ else if (src.id () == ID_array)
175
208
{
176
209
// do the size -- the subtype is already done
177
- if (!find_symbols (kind, to_array_type (src).size (), op, bindings))
210
+ if (!find_symbols (
211
+ kind, to_array_type (src).size (), op, bindings, subs_to_find))
178
212
return false ;
179
213
}
180
214
else if (
@@ -204,27 +238,33 @@ static bool find_symbols(
204
238
static bool find_symbols (
205
239
symbol_kindt kind,
206
240
const typet &type,
207
- std::function<bool (const symbol_exprt &)> op)
241
+ std::function<bool (const symbol_exprt &)> op,
242
+ const std::vector<irep_idt> &subs_to_find)
208
243
{
209
244
std::unordered_set<irep_idt> bindings;
210
- return find_symbols (kind, type, op, bindings);
245
+ return find_symbols (kind, type, op, bindings, subs_to_find );
211
246
}
212
247
213
248
static bool find_symbols (
214
249
symbol_kindt kind,
215
250
const exprt &src,
216
- std::function<bool (const symbol_exprt &)> op)
251
+ std::function<bool (const symbol_exprt &)> op,
252
+ const std::vector<irep_idt> &subs_to_find)
217
253
{
218
254
std::unordered_set<irep_idt> bindings;
219
- return find_symbols (kind, src, op, bindings);
255
+ return find_symbols (kind, src, op, bindings, subs_to_find );
220
256
}
221
257
222
258
void find_symbols (const exprt &src, std::set<symbol_exprt> &dest)
223
259
{
224
- find_symbols (symbol_kindt::F_EXPR, src, [&dest](const symbol_exprt &e) {
225
- dest.insert (e);
226
- return true ;
227
- });
260
+ find_symbols (
261
+ symbol_kindt::F_EXPR,
262
+ src,
263
+ [&dest](const symbol_exprt &e) {
264
+ dest.insert (e);
265
+ return true ;
266
+ },
267
+ {});
228
268
}
229
269
230
270
bool has_symbol_expr (
@@ -237,67 +277,96 @@ bool has_symbol_expr(
237
277
src,
238
278
[&identifier](const symbol_exprt &e) {
239
279
return e.get_identifier () != identifier;
240
- });
280
+ },
281
+ {});
241
282
}
242
283
243
284
void find_type_symbols (const exprt &src, find_symbols_sett &dest)
244
285
{
245
- find_symbols (symbol_kindt::F_TYPE, src, [&dest](const symbol_exprt &e) {
246
- dest.insert (e.get_identifier ());
247
- return true ;
248
- });
286
+ find_symbols (
287
+ symbol_kindt::F_TYPE,
288
+ src,
289
+ [&dest](const symbol_exprt &e) {
290
+ dest.insert (e.get_identifier ());
291
+ return true ;
292
+ },
293
+ {});
249
294
}
250
295
251
296
void find_type_symbols (const typet &src, find_symbols_sett &dest)
252
297
{
253
- find_symbols (symbol_kindt::F_TYPE, src, [&dest](const symbol_exprt &e) {
254
- dest.insert (e.get_identifier ());
255
- return true ;
256
- });
298
+ find_symbols (
299
+ symbol_kindt::F_TYPE,
300
+ src,
301
+ [&dest](const symbol_exprt &e) {
302
+ dest.insert (e.get_identifier ());
303
+ return true ;
304
+ },
305
+ {});
257
306
}
258
307
259
- void find_non_pointer_type_symbols (
260
- const exprt &src,
261
- find_symbols_sett &dest)
308
+ void find_non_pointer_type_symbols (const exprt &src, find_symbols_sett &dest)
262
309
{
263
310
find_symbols (
264
- symbol_kindt::F_TYPE_NON_PTR, src, [&dest](const symbol_exprt &e) {
311
+ symbol_kindt::F_TYPE_NON_PTR,
312
+ src,
313
+ [&dest](const symbol_exprt &e) {
265
314
dest.insert (e.get_identifier ());
266
315
return true ;
267
- });
316
+ },
317
+ {});
268
318
}
269
319
270
- void find_non_pointer_type_symbols (
271
- const typet &src,
272
- find_symbols_sett &dest)
320
+ void find_non_pointer_type_symbols (const typet &src, find_symbols_sett &dest)
273
321
{
274
322
find_symbols (
275
- symbol_kindt::F_TYPE_NON_PTR, src, [&dest](const symbol_exprt &e) {
323
+ symbol_kindt::F_TYPE_NON_PTR,
324
+ src,
325
+ [&dest](const symbol_exprt &e) {
276
326
dest.insert (e.get_identifier ());
277
327
return true ;
278
- });
328
+ },
329
+ {});
279
330
}
280
331
281
- void find_type_and_expr_symbols (const exprt &src, find_symbols_sett &dest)
332
+ void find_type_and_expr_symbols (
333
+ const exprt &src,
334
+ find_symbols_sett &dest,
335
+ const std::vector<irep_idt> &subs_to_find)
282
336
{
283
- find_symbols (symbol_kindt::F_ALL, src, [&dest](const symbol_exprt &e) {
284
- dest.insert (e.get_identifier ());
285
- return true ;
286
- });
337
+ find_symbols (
338
+ symbol_kindt::F_ALL,
339
+ src,
340
+ [&dest](const symbol_exprt &e) {
341
+ dest.insert (e.get_identifier ());
342
+ return true ;
343
+ },
344
+ subs_to_find);
287
345
}
288
346
289
- void find_type_and_expr_symbols (const typet &src, find_symbols_sett &dest)
347
+ void find_type_and_expr_symbols (
348
+ const typet &src,
349
+ find_symbols_sett &dest,
350
+ const std::vector<irep_idt> &subs_to_find)
290
351
{
291
- find_symbols (symbol_kindt::F_ALL, src, [&dest](const symbol_exprt &e) {
292
- dest.insert (e.get_identifier ());
293
- return true ;
294
- });
352
+ find_symbols (
353
+ symbol_kindt::F_ALL,
354
+ src,
355
+ [&dest](const symbol_exprt &e) {
356
+ dest.insert (e.get_identifier ());
357
+ return true ;
358
+ },
359
+ subs_to_find);
295
360
}
296
361
297
362
void find_symbols (const exprt &src, find_symbols_sett &dest)
298
363
{
299
- find_symbols (symbol_kindt::F_EXPR, src, [&dest](const symbol_exprt &e) {
300
- dest.insert (e.get_identifier ());
301
- return true ;
302
- });
364
+ find_symbols (
365
+ symbol_kindt::F_EXPR,
366
+ src,
367
+ [&dest](const symbol_exprt &e) {
368
+ dest.insert (e.get_identifier ());
369
+ return true ;
370
+ },
371
+ {});
303
372
}
0 commit comments