@@ -2091,23 +2091,26 @@ static void update_index_set(
2091
2091
// / \param [in] expr: the expression to search
2092
2092
// / \param [in] str: the string which must be indexed
2093
2093
// / \param [in] qvar: the universal variable that must be in the index
2094
- // / \return an index expression in `expr` on `str` containing `qvar`
2095
- static exprt find_index (
2096
- const exprt &expr, const exprt &str, const symbol_exprt &qvar)
2094
+ // / \return an index expression in `expr` on `str` containing `qvar`. Returns
2095
+ // / an empty optional when `expr` does not contain `str`.
2096
+ static optionalt<exprt>
2097
+ find_index (const exprt &expr, const exprt &str, const symbol_exprt &qvar)
2097
2098
{
2098
- const auto it=std::find_if (
2099
- expr.depth_begin (),
2100
- expr.depth_end (),
2101
- [&] (const exprt &e) -> bool
2102
- {
2103
- return e.id ()==ID_index
2104
- && to_index_expr (e).array ()==str
2105
- && find_qvar (to_index_expr (e).index (), qvar);
2099
+ const auto it = std::find_if (
2100
+ expr.depth_begin (), expr.depth_end (), [&](const exprt &e) { // NOLINT
2101
+ if (auto index_expr = expr_try_dynamic_cast<index_exprt>(e))
2102
+ {
2103
+ const auto &arr = index_expr->array ();
2104
+ const auto str_it = std::find (arr.depth_begin (), arr.depth_end (), str);
2105
+ return str_it != arr.depth_end () &&
2106
+ find_qvar (index_expr->index (), qvar);
2107
+ }
2108
+ return false ;
2106
2109
});
2107
2110
2108
- return it== expr.depth_end ()
2109
- ? nil_exprt ()
2110
- : to_index_expr (*it). index () ;
2111
+ if (it != expr.depth_end () )
2112
+ return to_index_expr (*it). index ();
2113
+ return {} ;
2111
2114
}
2112
2115
2113
2116
// / Instantiates a string constraint by substituting the quantifiers.
@@ -2128,11 +2131,11 @@ static exprt instantiate(
2128
2131
const exprt &str,
2129
2132
const exprt &val)
2130
2133
{
2131
- const exprt idx = find_index (axiom.body (), str, axiom.univ_var ());
2132
- if (idx.is_nil ())
2134
+ const optionalt< exprt> idx = find_index (axiom.body (), str, axiom.univ_var ());
2135
+ if (! idx.has_value ())
2133
2136
return true_exprt ();
2134
2137
2135
- const exprt r = compute_inverse_function (stream, axiom.univ_var (), val, idx);
2138
+ const exprt r = compute_inverse_function (stream, axiom.univ_var (), val, * idx);
2136
2139
implies_exprt instance (
2137
2140
and_exprt (
2138
2141
binary_relation_exprt (axiom.univ_var (), ID_ge, axiom.lower_bound ()),
0 commit comments