Skip to content

Commit 68558ce

Browse files
Define a for_each_atomic_string helper function
This could be used in several places in this file.
1 parent 2900b71 commit 68558ce

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/solvers/refinement/string_refinement_util.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <unordered_set>
2121
#include "string_refinement_util.h"
2222

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+
2329
bool is_char_type(const typet &type)
2430
{
2531
return type.id() == ID_unsignedbv &&
@@ -225,21 +231,26 @@ const string_builtin_functiont &string_dependenciest::get_builtin_function(
225231
return *node.data;
226232
}
227233

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+
228246
void string_dependenciest::add_dependency(
229247
const array_string_exprt &e,
230248
const builtin_function_nodet &builtin_function_node)
231249
{
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+
});
243254
}
244255

245256
static void add_dependency_to_string_subexprs(

0 commit comments

Comments
 (0)