Skip to content

Commit f5c1b29

Browse files
author
Lukasz A.J. Wrona
committed
static get_array
1 parent 7f11ccf commit f5c1b29

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

src/solvers/refinement/string_refinement.cpp

+41-10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ static std::vector<exprt> instantiate_not_contains(
102102
const std::map<exprt, std::set<exprt>>& index_set,
103103
const string_constraint_generatort &generator);
104104

105+
static exprt get_array(
106+
std::function<exprt(const exprt&)> super_get,
107+
const exprt &arr);
108+
105109
/// Convert exprt to a specific type. Throw bad_cast if conversion
106110
/// cannot be performed
107111
/// Generic case doesn't exist, specialize for different types accordingly
@@ -902,10 +906,15 @@ void string_refinementt::add_lemma(
902906
/// \par parameters: an expression representing an array and an expression
903907
/// representing an integer
904908
/// \return an array expression or an array_of_exprt
905-
exprt string_refinementt::get_array(const exprt &arr, const exprt &size) const
909+
static exprt get_array(
910+
std::function<exprt(const exprt&)> super_get,
911+
const namespacet &ns,
912+
std::size_t max_string_length,
913+
const exprt &arr,
914+
const exprt &size)
906915
{
907-
exprt arr_val=simplify_expr(get_array(arr), ns);
908-
exprt size_val=supert::get(size);
916+
exprt arr_val=simplify_expr(get_array(super_get, arr), ns);
917+
exprt size_val=super_get(size);
909918
size_val=simplify_expr(size_val, ns);
910919
typet char_type=arr.type().subtype();
911920
typet index_type=size.type();
@@ -933,7 +942,7 @@ exprt string_refinementt::get_array(const exprt &arr, const exprt &size) const
933942
array_typet ret_type(char_type, from_integer(n, index_type));
934943
array_exprt ret(ret_type);
935944

936-
if(n>generator.max_string_length)
945+
if(n>max_string_length)
937946
{
938947
#if 0
939948
debug() << "(sr::get_array) long string (size=" << n << ")" << eom;
@@ -984,9 +993,11 @@ exprt string_refinementt::get_array(const exprt &arr, const exprt &size) const
984993
/// get a model of an array of unknown size and infer the size if possible
985994
/// \par parameters: an expression representing an array
986995
/// \return an expression
987-
exprt string_refinementt::get_array(const exprt &arr) const
996+
static exprt get_array(
997+
std::function<exprt(const exprt&)> super_get,
998+
const exprt &arr)
988999
{
989-
exprt arr_model=supert::get(arr);
1000+
exprt arr_model=super_get(arr);
9901001
if(arr_model.id()==ID_array)
9911002
{
9921003
array_typet &arr_type=to_array_type(arr_model.type());
@@ -1016,6 +1027,9 @@ std::string string_refinementt::string_of_array(const array_exprt &arr)
10161027
/// solver to constant expressions given by the current model
10171028
void string_refinementt::debug_model()
10181029
{
1030+
const auto super_get = [this](const exprt& expr) {
1031+
return supert::get(expr);
1032+
};
10191033
const std::string indent(" ");
10201034
for(auto it : symbol_resolve)
10211035
{
@@ -1031,7 +1045,11 @@ void string_refinementt::debug_model()
10311045

10321046
exprt len=supert::get(elength);
10331047
len=simplify_expr(len, ns);
1034-
const exprt arr=get_array(econtent, len);
1048+
const exprt arr=get_array(
1049+
super_get,
1050+
ns,
1051+
generator.max_string_length,
1052+
econtent, len);
10351053
if(arr.id()==ID_array)
10361054
debug() << indent << indent << "as_string: \""
10371055
<< string_of_array(to_array_expr(arr)) << "\"\n";
@@ -1053,7 +1071,7 @@ void string_refinementt::debug_model()
10531071
debug() << "- " << from_expr(ns, "", to_symbol_expr(it.first)) << ":\n";
10541072
debug() << indent << indent << "resolved: "
10551073
<< from_expr(ns, "", arr) << "\n";
1056-
exprt arr_model=get_array(arr);
1074+
exprt arr_model=get_array(super_get, arr);
10571075
debug() << indent << indent << "char_array: "
10581076
<< from_expr(ns, "", arr_model) << eom;
10591077
}
@@ -1977,6 +1995,9 @@ exprt substitute_array_lists(exprt expr, size_t string_max_length)
19771995
/// \return an expression
19781996
exprt string_refinementt::get(const exprt &expr) const
19791997
{
1998+
const auto super_get = [this](const exprt& expr) {
1999+
return supert::get(expr);
2000+
};
19802001
exprt ecopy(expr);
19812002
replace_expr(symbol_resolve, ecopy);
19822003
if(is_char_array(ns, ecopy.type()))
@@ -1987,7 +2008,12 @@ exprt string_refinementt::get(const exprt &expr) const
19872008

19882009
auto it=found_length.find(ecopy);
19892010
if(it!=found_length.end())
1990-
return get_array(ecopy, it->second);
2011+
return get_array(
2012+
super_get,
2013+
ns,
2014+
generator.max_string_length,
2015+
ecopy,
2016+
it->second);
19912017
}
19922018
else if(ecopy.id()==ID_struct)
19932019
{
@@ -1996,7 +2022,12 @@ exprt string_refinementt::get(const exprt &expr) const
19962022
const exprt &content=string->content();
19972023
const exprt &length=string->length();
19982024

1999-
const exprt arr=get_array(content, length);
2025+
const exprt arr=get_array(
2026+
super_get,
2027+
ns,
2028+
generator.max_string_length,
2029+
content,
2030+
length);
20002031
ecopy=string_exprt(length, arr, string->type());
20012032
}
20022033
}

src/solvers/refinement/string_refinement.h

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ class string_refinementt final: public bv_refinementt
102102

103103
void debug_model();
104104

105-
exprt get_array(const exprt &arr, const exprt &size) const;
106-
exprt get_array(const exprt &arr) const;
107-
108105
std::string string_of_array(const array_exprt &arr);
109106
};
110107
#endif

0 commit comments

Comments
 (0)