@@ -102,6 +102,10 @@ static std::vector<exprt> instantiate_not_contains(
102
102
const std::map<exprt, std::set<exprt>>& index_set,
103
103
const string_constraint_generatort &generator);
104
104
105
+ static exprt get_array (
106
+ std::function<exprt(const exprt&)> super_get,
107
+ const exprt &arr);
108
+
105
109
// / Convert exprt to a specific type. Throw bad_cast if conversion
106
110
// / cannot be performed
107
111
// / Generic case doesn't exist, specialize for different types accordingly
@@ -902,10 +906,15 @@ void string_refinementt::add_lemma(
902
906
// / \par parameters: an expression representing an array and an expression
903
907
// / representing an integer
904
908
// / \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)
906
915
{
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);
909
918
size_val=simplify_expr (size_val, ns);
910
919
typet char_type=arr.type ().subtype ();
911
920
typet index_type=size.type ();
@@ -933,7 +942,7 @@ exprt string_refinementt::get_array(const exprt &arr, const exprt &size) const
933
942
array_typet ret_type (char_type, from_integer (n, index_type));
934
943
array_exprt ret (ret_type);
935
944
936
- if (n>generator. max_string_length )
945
+ if (n>max_string_length)
937
946
{
938
947
#if 0
939
948
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
984
993
// / get a model of an array of unknown size and infer the size if possible
985
994
// / \par parameters: an expression representing an array
986
995
// / \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)
988
999
{
989
- exprt arr_model=supert::get (arr);
1000
+ exprt arr_model=super_get (arr);
990
1001
if (arr_model.id ()==ID_array)
991
1002
{
992
1003
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)
1016
1027
// / solver to constant expressions given by the current model
1017
1028
void string_refinementt::debug_model ()
1018
1029
{
1030
+ const auto super_get = [this ](const exprt& expr) {
1031
+ return supert::get (expr);
1032
+ };
1019
1033
const std::string indent (" " );
1020
1034
for (auto it : symbol_resolve)
1021
1035
{
@@ -1031,7 +1045,11 @@ void string_refinementt::debug_model()
1031
1045
1032
1046
exprt len=supert::get (elength);
1033
1047
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);
1035
1053
if (arr.id ()==ID_array)
1036
1054
debug () << indent << indent << " as_string: \" "
1037
1055
<< string_of_array (to_array_expr (arr)) << " \"\n " ;
@@ -1053,7 +1071,7 @@ void string_refinementt::debug_model()
1053
1071
debug () << " - " << from_expr (ns, " " , to_symbol_expr (it.first )) << " :\n " ;
1054
1072
debug () << indent << indent << " resolved: "
1055
1073
<< from_expr (ns, " " , arr) << " \n " ;
1056
- exprt arr_model=get_array (arr);
1074
+ exprt arr_model=get_array (super_get, arr);
1057
1075
debug () << indent << indent << " char_array: "
1058
1076
<< from_expr (ns, " " , arr_model) << eom;
1059
1077
}
@@ -1977,6 +1995,9 @@ exprt substitute_array_lists(exprt expr, size_t string_max_length)
1977
1995
// / \return an expression
1978
1996
exprt string_refinementt::get (const exprt &expr) const
1979
1997
{
1998
+ const auto super_get = [this ](const exprt& expr) {
1999
+ return supert::get (expr);
2000
+ };
1980
2001
exprt ecopy (expr);
1981
2002
replace_expr (symbol_resolve, ecopy);
1982
2003
if (is_char_array (ns, ecopy.type ()))
@@ -1987,7 +2008,12 @@ exprt string_refinementt::get(const exprt &expr) const
1987
2008
1988
2009
auto it=found_length.find (ecopy);
1989
2010
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 );
1991
2017
}
1992
2018
else if (ecopy.id ()==ID_struct)
1993
2019
{
@@ -1996,7 +2022,12 @@ exprt string_refinementt::get(const exprt &expr) const
1996
2022
const exprt &content=string->content ();
1997
2023
const exprt &length=string->length ();
1998
2024
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);
2000
2031
ecopy=string_exprt (length, arr, string->type ());
2001
2032
}
2002
2033
}
0 commit comments