Skip to content

Commit 5bf23bb

Browse files
committed
Change interface of try_get_string_data_array()
Take the content field of a refined string expression instead of taking the whole refined string expression. This will allow it to be used from the string mutators constant propagation code in goto_symex.cpp.
1 parent 6c04eda commit 5bf23bb

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/util/simplify_expr.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ static simplify_exprt::resultt<> simplify_string_endswith(
158158
const namespacet &ns)
159159
{
160160
const refined_string_exprt &s1 = to_string_expr(expr.arguments().at(0));
161-
const auto s1_data_opt = try_get_string_data_array(s1, ns);
161+
const auto s1_data_opt = try_get_string_data_array(s1.content(), ns);
162162

163163
if(!s1_data_opt)
164164
return simplify_exprt::unchanged(expr);
165165

166166
const array_exprt &s1_data = s1_data_opt->get();
167167
const refined_string_exprt &s2 = to_string_expr(expr.arguments().at(1));
168-
const auto s2_data_opt = try_get_string_data_array(s2, ns);
168+
const auto s2_data_opt = try_get_string_data_array(s2.content(), ns);
169169

170170
if(!s2_data_opt)
171171
return simplify_exprt::unchanged(expr);
@@ -214,13 +214,13 @@ static simplify_exprt::resultt<> simplify_string_compare_to(
214214
const namespacet &ns)
215215
{
216216
const refined_string_exprt &s1 = to_string_expr(expr.arguments().at(0));
217-
const auto s1_data_opt = try_get_string_data_array(s1, ns);
217+
const auto s1_data_opt = try_get_string_data_array(s1.content(), ns);
218218

219219
if(!s1_data_opt)
220220
return simplify_exprt::unchanged(expr);
221221

222222
const refined_string_exprt &s2 = to_string_expr(expr.arguments().at(1));
223-
const auto s2_data_opt = try_get_string_data_array(s2, ns);
223+
const auto s2_data_opt = try_get_string_data_array(s2.content(), ns);
224224

225225
if(!s2_data_opt)
226226
return simplify_exprt::unchanged(expr);
@@ -285,7 +285,7 @@ static simplify_exprt::resultt<> simplify_string_index_of(
285285

286286
const refined_string_exprt &s1 = to_string_expr(expr.arguments().at(0));
287287

288-
const auto s1_data_opt = try_get_string_data_array(s1, ns);
288+
const auto s1_data_opt = try_get_string_data_array(s1.content(), ns);
289289

290290
if(!s1_data_opt)
291291
{
@@ -310,7 +310,7 @@ static simplify_exprt::resultt<> simplify_string_index_of(
310310
const refined_string_exprt &s2 =
311311
to_string_expr(expr.arguments().at(1));
312312

313-
const auto s2_data_opt = try_get_string_data_array(s2, ns);
313+
const auto s2_data_opt = try_get_string_data_array(s2.content(), ns);
314314

315315
if(!s2_data_opt)
316316
{
@@ -379,7 +379,7 @@ static simplify_exprt::resultt<> simplify_string_char_at(
379379

380380
const refined_string_exprt &s = to_string_expr(expr.arguments().at(0));
381381

382-
const auto char_seq_opt = try_get_string_data_array(s, ns);
382+
const auto char_seq_opt = try_get_string_data_array(s.content(), ns);
383383

384384
if(!char_seq_opt)
385385
{
@@ -420,7 +420,8 @@ static simplify_exprt::resultt<> simplify_string_startswith(
420420
auto &first_argument = to_string_expr(expr.arguments().at(0));
421421
auto &second_argument = to_string_expr(expr.arguments().at(1));
422422

423-
const auto first_value_opt = try_get_string_data_array(first_argument, ns);
423+
const auto first_value_opt =
424+
try_get_string_data_array(first_argument.content(), ns);
424425

425426
if(!first_value_opt)
426427
{
@@ -429,7 +430,8 @@ static simplify_exprt::resultt<> simplify_string_startswith(
429430

430431
const array_exprt &first_value = first_value_opt->get();
431432

432-
const auto second_value_opt = try_get_string_data_array(second_argument, ns);
433+
const auto second_value_opt =
434+
try_get_string_data_array(second_argument.content(), ns);
433435

434436
if(!second_value_opt)
435437
{
@@ -1666,21 +1668,21 @@ optionalt<std::string> simplify_exprt::expr2bits(
16661668
}
16671669

16681670
optionalt<std::reference_wrapper<const array_exprt>>
1669-
try_get_string_data_array(const refined_string_exprt &s, const namespacet &ns)
1671+
try_get_string_data_array(const exprt &content, const namespacet &ns)
16701672
{
1671-
if(s.content().id() != ID_address_of)
1673+
if(content.id() != ID_address_of)
16721674
{
16731675
return {};
16741676
}
16751677

1676-
const auto &content = to_address_of_expr(s.content());
1678+
const auto &array_pointer = to_address_of_expr(content);
16771679

1678-
if(content.object().id() != ID_index)
1680+
if(array_pointer.object().id() != ID_index)
16791681
{
16801682
return {};
16811683
}
16821684

1683-
const auto &array_start = to_index_expr(content.object());
1685+
const auto &array_start = to_index_expr(array_pointer.object());
16841686

16851687
if(array_start.array().id() != ID_symbol ||
16861688
array_start.array().type().id() != ID_array)

src/util/simplify_expr.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ bool simplify(
3131
// this is the preferred interface
3232
exprt simplify_expr(exprt src, const namespacet &ns);
3333

34-
/// Get char sequence from refined string expression
34+
/// Get char sequence from content field of a refined string expression
3535
///
36-
/// If `s.content()` is of the form `&id[e]`, where `id` is an array-typed
37-
/// symbol expression (and `e` is any expression), return the value of the
38-
/// symbol `id` (as given by the `value` field of the symbol in the namespace
39-
/// `ns`); otherwise return an empty optional.
36+
/// If `content` is of the form `&id[e]`, where `id` is an array-typed symbol
37+
/// expression (and `e` is any expression), return the value of the symbol `id`
38+
/// (as given by the `value` field of the symbol in the namespace `ns`);
39+
/// otherwise return an empty optional.
4040
///
41-
/// \param s: refined string expression
41+
/// \param content: content field of a refined string expression
4242
/// \param ns: namespace
4343
/// \return array expression representing the char sequence which forms the
4444
/// content of the refined string expression, empty optional if the content
4545
/// cannot be determined
4646
optionalt<std::reference_wrapper<const array_exprt>>
47-
try_get_string_data_array(const refined_string_exprt &s, const namespacet &ns);
47+
try_get_string_data_array(const exprt &content, const namespacet &ns);
4848

4949
#endif // CPROVER_UTIL_SIMPLIFY_EXPR_H

0 commit comments

Comments
 (0)