|
20 | 20 | #include <unordered_set>
|
21 | 21 | #include "string_refinement_util.h"
|
22 | 22 |
|
| 23 | +/// Applies `f` on all strings contained in `e` that are not if-expressions. |
| 24 | +/// For instance on input `cond1?s1:cond2?s2:s3` we apply `f` on s1, s2 and s3. |
| 25 | +static void for_each_atomic_string( |
| 26 | + const array_string_exprt &e, |
| 27 | + const std::function<void(const array_string_exprt &)> f); |
| 28 | + |
23 | 29 | bool is_char_type(const typet &type)
|
24 | 30 | {
|
25 | 31 | return type.id() == ID_unsignedbv &&
|
@@ -225,21 +231,26 @@ const string_builtin_functiont &string_dependenciest::get_builtin_function(
|
225 | 231 | return *node.data;
|
226 | 232 | }
|
227 | 233 |
|
| 234 | +static void for_each_atomic_string( |
| 235 | + const array_string_exprt &e, |
| 236 | + const std::function<void(const array_string_exprt &)> f) |
| 237 | +{ |
| 238 | + if(e.id() != ID_if) |
| 239 | + return f(e); |
| 240 | + |
| 241 | + const auto if_expr = to_if_expr(e); |
| 242 | + for_each_atomic_string(to_array_string_expr(if_expr.true_case()), f); |
| 243 | + for_each_atomic_string(to_array_string_expr(if_expr.false_case()), f); |
| 244 | +} |
| 245 | + |
228 | 246 | void string_dependenciest::add_dependency(
|
229 | 247 | const array_string_exprt &e,
|
230 | 248 | const builtin_function_nodet &builtin_function_node)
|
231 | 249 | {
|
232 |
| - if(e.id() == ID_if) |
233 |
| - { |
234 |
| - const auto if_expr = to_if_expr(e); |
235 |
| - const auto &true_case = to_array_string_expr(if_expr.true_case()); |
236 |
| - const auto &false_case = to_array_string_expr(if_expr.false_case()); |
237 |
| - add_dependency(true_case, builtin_function_node); |
238 |
| - add_dependency(false_case, builtin_function_node); |
239 |
| - return; |
240 |
| - } |
241 |
| - string_nodet &string_node = get_node(e); |
242 |
| - string_node.dependencies.push_back(builtin_function_node.index); |
| 250 | + for_each_atomic_string(e, [&](const array_string_exprt &s) { //NOLINT |
| 251 | + string_nodet &string_node = get_node(s); |
| 252 | + string_node.dependencies.push_back(builtin_function_node.index); |
| 253 | + }); |
243 | 254 | }
|
244 | 255 |
|
245 | 256 | static void add_dependency_to_string_subexprs(
|
|
0 commit comments