Skip to content

Commit 27d9bc1

Browse files
Utility functions for getting array from arguments
1 parent 673b3a4 commit 27d9bc1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/solvers/refinement/string_refinement_util.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ bool has_char_array_subexpr(const exprt &expr, const namespacet &ns)
7575
return false;
7676
}
7777

78+
optionalt<refined_string_exprt> get_char_array_of_argument(const exprt &expr)
79+
{
80+
if(!is_refined_string_type(expr.type()))
81+
return {};
82+
if(const auto e = expr_try_dynamic_cast<refined_string_exprt>(expr))
83+
return *e;
84+
return {};
85+
}
86+
87+
refined_string_exprt get_refined_string_expr_value(const exprt &expr)
88+
{
89+
PRECONDITION(is_refined_string_type(expr.type()));
90+
return expr_dynamic_cast<refined_string_exprt>(expr);
91+
}
92+
7893
sparse_arrayt::sparse_arrayt(const with_exprt &expr)
7994
{
8095
auto ref = std::ref(static_cast<const exprt &>(expr));

src/solvers/refinement/string_refinement_util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ bool has_string_subtype(const typet &type);
6767
/// \return true if a subexpression of `expr` is an array of characters
6868
bool has_char_array_subexpr(const exprt &expr, const namespacet &ns);
6969

70+
/// \param expr: an expression
71+
/// \return a refined_string_exprt if expr is of type refined_string_type and
72+
/// has the right structure for a refined_string_exprt
73+
optionalt<refined_string_exprt> get_char_array_of_argument(const exprt &expr);
74+
75+
/// \param expr: an expression
76+
/// \return a refined_string_exprt, an invariant will fail if expr is of type
77+
/// refined_string_type or cannot be cast to a refined_string_exprt
78+
refined_string_exprt get_refined_string_expr_value(const exprt &expr);
79+
7080
struct index_set_pairt
7181
{
7282
std::map<exprt, std::set<exprt>> cumulative;

0 commit comments

Comments
 (0)