30 #include <unordered_set> 62 const std::function<
exprt(
const exprt &)> &
get,
65 bool use_counter_example,
88 const std::vector<exprt> ¤t_constraints);
93 const exprt &formula);
117 const std::function<
exprt(
const exprt &)> &super_get,
126 const bool left_propagate);
135 template <
typename T>
137 const std::map<std::size_t, T> &index_value)
139 std::vector<T> result;
140 if(!index_value.empty())
142 result.resize(index_value.rbegin()->first+1);
143 for(
auto it=index_value.rbegin(); it!=index_value.rend(); ++it)
145 const std::size_t index=it->first;
146 const T &value = it->second;
147 const auto next=std::next(it);
148 const std::size_t leftmost_index_to_pad=
149 next!=index_value.rend()
152 for(std::size_t j=leftmost_index_to_pad; j<=index; j++)
169 loop_bound_(info.refinement_bound),
184 std::size_t count_current=0;
187 const exprt &s=i.first;
188 stream <<
"IS(" <<
format(s) <<
")=={" << eom;
190 for(
const auto &j : i.second)
192 const auto it=index_set.
current.find(i.first);
193 if(it!=index_set.
current.end() && it->second.find(j)!=it->second.end())
198 stream <<
" " <<
format(j) <<
";" << eom;
201 stream <<
"}" << eom;
203 stream << count <<
" elements in index set (" << count_current
204 <<
" newly added)" << eom;
234 std::vector<exprt> lemmas;
235 for(
const auto &i : index_set.
current)
237 for(
const auto &univ_axiom : axioms.
universal)
239 for(
const auto &j : i.second)
240 lemmas.push_back(
instantiate(stream, univ_axiom, i.first, j));
245 for(
const auto &instance :
247 lemmas.push_back(instance);
256 std::vector<equal_exprt> &equations)
262 expr_try_dynamic_cast<function_application_exprt>(eq.rhs()))
272 std::vector<equal_exprt> &equations)
287 if(expr.
id() == ID_equal && value)
307 const std::vector<equal_exprt> &equations,
312 const std::string log_message =
313 "WARNING string_refinement.cpp generate_symbol_resolution_from_equations:";
317 const exprt &lhs = eq.lhs();
318 const exprt &rhs = eq.rhs();
319 if(lhs.
id()!=ID_symbol)
321 stream << log_message <<
"non symbol lhs: " <<
format(lhs)
322 <<
" with rhs: " <<
format(rhs) << eom;
328 stream << log_message <<
"non equal types lhs: " <<
format(lhs)
329 <<
"\n####################### rhs: " <<
format(rhs) << eom;
335 solver.make_union(lhs, rhs);
337 else if(rhs.
id() == ID_function_application)
345 if(rhs.
type().
id() == ID_struct)
348 for(
const auto &comp : struct_type.
components())
355 solver.make_union(lhs_data, rhs_data);
361 stream << log_message <<
"non struct with char pointer subexpr " 376 std::vector<exprt> result;
378 result.push_back(lhs);
379 else if(lhs.
type().
id() == ID_struct)
382 for(
const auto &comp : struct_type.
components())
387 result.end(), strings_in_comp.begin(), strings_in_comp.end());
399 std::vector<exprt> result;
404 result.push_back(*it);
405 it.next_sibling_or_parent();
407 else if(it->id() == ID_symbol)
411 it.next_sibling_or_parent();
439 for(
const auto &comp : struct_type.
components())
445 equal_exprt(lhs_data, rhs_data), symbol_resolve, ns);
459 std::vector<equal_exprt> &equations,
464 const std::string log_message =
465 "WARNING string_refinement.cpp " 466 "string_identifiers_resolution_from_equations:";
471 std::unordered_set<size_t> required_equations;
472 std::stack<size_t> equations_to_treat;
474 for(std::size_t i = 0; i < equations.size(); ++i)
477 if(eq.
rhs().
id() == ID_function_application)
479 if(required_equations.insert(i).second)
480 equations_to_treat.push(i);
483 for(
const auto &expr : rhs_strings)
484 equation_map.
add(i, expr);
492 for(
const auto &expr : lhs_strings)
493 equation_map.
add(i, expr);
495 if(lhs_strings.empty())
497 stream << log_message <<
"non struct with string subtype " 503 equation_map.
add(i, expr);
508 while(!equations_to_treat.empty())
510 const std::size_t i = equations_to_treat.top();
511 equations_to_treat.pop();
516 if(required_equations.insert(j).second)
517 equations_to_treat.push(j);
523 for(
const std::size_t i : required_equations)
530 static void output_equations(
532 std::ostream &output,
533 const std::vector<equal_exprt> &equations)
535 for(std::size_t i = 0; i < equations.size(); ++i)
536 output <<
" [" << i <<
"] " <<
format(equations[i].lhs())
537 <<
" == " <<
format(equations[i].rhs()) << std::endl;
608 debug() <<
"dec_solve: Initial set of equations" <<
eom;
612 debug() <<
"dec_solve: Build symbol solver from equations" <<
eom;
617 debug() <<
"symbol resolve:" <<
eom;
625 debug() <<
"symbol resolve string:" <<
eom;
626 for(
const auto &pair : string_id_symbol_resolve.
to_vector())
632 debug() <<
"dec_solve: Replacing char pointer symbols" <<
eom;
635 debug() <<
"dec_solve: Replacing string ids in function applications" <<
eom;
651 debug() <<
"dec_solve: compute dependency graph and remove function " 652 <<
"applications captured by the dependencies:" <<
eom;
653 std::vector<exprt> local_equations;
657 local_equations.push_back(eq);
665 debug() <<
"dec_solve: add constraints" <<
eom;
673 debug() <<
"dec_solve: arrays_of_pointers:" <<
eom;
677 <<
" : " <<
format(pair.second.type()) <<
eom;
681 for(
const auto &eq : local_equations)
699 "string constraints satisfy their invariant"));
703 const auto not_contains_constraints =
706 not_contains_constraints.begin(),
707 not_contains_constraints.end(),
716 const auto &witness_type = [&] {
729 const auto get = [
this](
const exprt &expr) {
return this->
get(expr); };
735 std::vector<exprt> counter_examples;
746 debug() <<
"check_SAT: the model is correct" <<
eom;
749 debug() <<
"check_SAT: got SAT but the model is not correct" <<
eom;
753 debug() <<
"check_SAT: got UNSAT or ERROR" <<
eom;
760 for(
const auto &instance :
776 std::vector<exprt> counter_examples;
787 debug() <<
"check_SAT: the model is correct" <<
eom;
791 debug() <<
"check_SAT: got SAT but the model is not correct, refining..." 807 error() <<
"dec_solve: current index set is empty, " 808 <<
"this should not happen" <<
eom;
813 debug() <<
"dec_solve: current index set is empty, " 814 <<
"adding counter examples" <<
eom;
815 for(
const auto &counter : counter_examples)
820 for(
const auto &instance :
830 debug() <<
"check_SAT: default return " <<
static_cast<int>(res) <<
eom;
834 debug() <<
"string_refinementt::dec_solve reached the maximum number" 835 <<
"of steps allowed" <<
eom;
845 const bool simplify_lemma)
852 exprt simple_lemma=lemma;
859 debug() <<
"string_refinementt::add_lemma : tautology" <<
eom;
870 if(it->id() == ID_array && it->operands().empty())
875 it.next_sibling_or_parent();
895 const std::function<
exprt(
const exprt &)> &super_get,
903 exprt size_val=super_get(size);
910 if(size_val.
id()!=ID_constant)
912 stream <<
"(sr::get_array) string of unknown size: " <<
format(size_val)
920 stream <<
"(sr::get_array) size is not valid" << eom;
923 std::size_t n = *n_opt;
927 stream <<
"(sr::get_array) long string (size " <<
format(arr.
length())
928 <<
" = " << n <<
") " <<
format(arr) << eom;
929 stream <<
"(sr::get_array) consider reducing string-max-input-length so " 930 "that no string exceeds " 933 "make sure all functions returning strings are loaded" 935 stream <<
"(sr::get_array) this can also happen on invalid object access" 953 if(arr.
type().
id()!=ID_array)
954 return std::string(
"");
957 auto n = numeric_cast_v<std::size_t>(size_expr);
969 const std::function<
exprt(
const exprt &)> &super_get,
975 stream <<
"- " <<
format(arr) <<
":\n";
976 stream << std::string(4,
' ') <<
"- type: " <<
format(arr.
type()) << eom;
977 const auto arr_model_opt =
981 stream << std::string(4,
' ') <<
"- char_array: " <<
format(*arr_model_opt)
983 stream << std::string(4,
' ') <<
"- type : " <<
format(arr_model_opt->type())
986 stream << std::string(4,
' ') <<
"- simplified_char_array: " <<
format(simple)
989 const auto concretized_array =
get_array(
992 stream << std::string(4,
' ')
993 <<
"- concretized_char_array: " <<
format(*concretized_array)
997 const auto array_expr =
998 expr_try_dynamic_cast<array_exprt>(*concretized_array))
1000 stream << std::string(4,
' ') <<
"- as_string: \"" 1004 stream << std::string(2,
' ') <<
"- warning: not an array" << eom;
1005 return *concretized_array;
1009 stream << std::string(4,
' ') <<
"- incomplete model" << eom;
1019 const std::function<
exprt(
const exprt &)> &super_get,
1020 const std::vector<symbol_exprt> &boolean_symbols,
1021 const std::vector<symbol_exprt> &index_symbols)
1023 stream <<
"debug_model:" <<
'\n';
1026 const auto arr = pointer_array.second;
1028 super_get, ns, stream, arr);
1030 stream <<
"- " <<
format(arr) <<
":\n" 1031 <<
" - pointer: " <<
format(pointer_array.first) <<
"\n" 1035 for(
const auto &symbol : boolean_symbols)
1037 stream <<
" - " << symbol.get_identifier() <<
": " 1038 <<
format(super_get(symbol)) <<
'\n';
1041 for(
const auto &symbol : index_symbols)
1043 stream <<
" - " << symbol.get_identifier() <<
": " 1044 <<
format(super_get(symbol)) <<
'\n';
1064 const bool left_propagate)
1083 const exprt default_val = symbol_generator(
"out_of_bound_access",
char_type);
1093 const bool left_propagate)
1101 return if_exprt(if_expr.
cond(), true_case, false_case);
1108 const bool left_propagate)
1111 if(
auto array_of = expr_try_dynamic_cast<array_of_exprt>(array))
1112 return array_of->op();
1113 if(
auto array_with = expr_try_dynamic_cast<with_exprt>(array))
1115 *array_with, index_expr.
index(), left_propagate);
1116 if(
auto array_expr = expr_try_dynamic_cast<array_exprt>(array))
1118 *array_expr, index_expr.
index(), symbol_generator);
1119 if(
auto if_expr = expr_try_dynamic_cast<if_exprt>(array))
1121 *if_expr, index_expr.
index(), symbol_generator, left_propagate);
1124 array.
is_nil() || array.
id() == ID_symbol,
1126 "in case the array is unknown, it should be a symbol or nil, id: ")
1138 const bool left_propagate)
1140 if(
const auto index_expr = expr_try_dynamic_cast<index_exprt>(expr))
1174 const bool left_propagate)
1193 const std::function<
exprt(
const exprt &)> &
get)
1206 std::vector<exprt> conjuncts;
1207 conjuncts.reserve(numeric_cast_v<std::size_t>(ube - lbe));
1211 const exprt s0_char =
1214 conjuncts.push_back(
equal_exprt(s0_char, s1_char));
1224 template <
typename T>
1228 const T &axiom_in_model,
1229 const exprt &negaxiom,
1230 const exprt &with_concretized_arrays)
1232 stream << std::string(4,
' ') <<
"- axiom:\n" << std::string(6,
' ');
1234 stream <<
'\n' << std::string(4,
' ') <<
"- axiom_in_model:\n" 1235 << std::string(6,
' ');
1236 stream <<
to_string(axiom_in_model) <<
'\n' 1237 << std::string(4,
' ') <<
"- negated_axiom:\n" 1238 << std::string(6,
' ') <<
format(negaxiom) <<
'\n';
1239 stream << std::string(4,
' ') <<
"- negated_axiom_with_concretized_arrays:\n" 1240 << std::string(6,
' ') <<
format(with_concretized_arrays) <<
'\n';
1248 const std::function<
exprt(
const exprt &)> &
get,
1251 bool use_counter_example,
1256 const auto gen_symbol = [&](
const irep_idt &id,
const typet &type)
1262 stream <<
"string_refinementt::check_axioms:" << eom;
1264 stream <<
"symbol_resolve:" << eom;
1265 auto pairs = symbol_resolve.
to_vector();
1266 for(
const auto &pair : pairs)
1267 stream <<
" - " <<
format(pair.first) <<
" --> " <<
format(pair.second)
1281 std::map<size_t, exprt> violated;
1283 stream <<
"string_refinement::check_axioms: " << axioms.
universal.size()
1284 <<
" universal axioms:" << eom;
1285 for(
size_t i=0; i<axioms.
universal.size(); i++)
1297 stream << std::string(2,
' ') << i <<
".\n";
1298 const exprt with_concretized_arrays =
1301 stream, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
1304 const auto &witness =
1307 stream << std::string(4,
' ') <<
"- violated_for: " 1309 violated[i]=*witness;
1312 stream << std::string(4,
' ') <<
"- correct" << eom;
1316 std::map<std::size_t, exprt> violated_not_contains;
1319 <<
" not_contains axioms" << eom;
1320 for(std::size_t i = 0; i < axioms.
not_contains.size(); i++)
1324 "not_contains_univ_var", nc_axiom.
s0().
length().
type());
1326 nc_axiom, univ_var, [&](
const exprt &expr) {
1329 stream << std::string(2,
' ') << i <<
".\n";
1331 stream, nc_axiom, nc_axiom, negated_axiom, negated_axiom);
1334 const auto witness =
1337 stream << std::string(4,
' ') <<
"- violated_for: " 1339 violated_not_contains[i]=*witness;
1343 if(violated.empty() && violated_not_contains.empty())
1345 stream <<
"no violated property" << eom;
1346 return {
true, std::vector<exprt>() };
1350 stream << violated.size()
1351 <<
" universal string axioms can be violated" << eom;
1352 stream << violated_not_contains.size()
1353 <<
" not_contains string axioms can be violated" << eom;
1355 if(use_counter_example)
1357 std::vector<exprt> lemmas;
1359 for(
const auto &v : violated)
1361 const exprt &val=v.second;
1372 lemmas.push_back(counter);
1375 for(
const auto &v : violated_not_contains)
1377 const exprt &val=v.second;
1384 std::set<std::pair<exprt, exprt>> indices;
1385 indices.insert(std::pair<exprt, exprt>(comp_val, func_val));
1387 axiom, indices, generator)[0];
1388 lemmas.push_back(counter);
1390 return {
false, lemmas };
1393 return {
false, std::vector<exprt>() };
1403 std::map<exprt, int> elems;
1405 std::list<std::pair<exprt, bool> > to_process;
1406 to_process.emplace_back(f,
true);
1408 while(!to_process.empty())
1410 exprt cur=to_process.back().first;
1411 bool positive=to_process.back().second;
1412 to_process.pop_back();
1413 if(cur.
id()==ID_plus)
1415 for(
const auto &op : cur.
operands())
1416 to_process.emplace_back(op, positive);
1418 else if(cur.
id()==ID_minus)
1420 to_process.emplace_back(cur.
op1(), !positive);
1421 to_process.emplace_back(cur.
op0(), positive);
1423 else if(cur.
id()==ID_unary_minus)
1425 to_process.emplace_back(cur.
op0(), !positive);
1430 elems[cur]=elems[cur]+1;
1432 elems[cur]=elems[cur]-1;
1445 std::map<exprt, int> &m,
1457 for(
const auto &term : m)
1460 const exprt &t=term.first;
1461 int second=negated?(-term.second):term.second;
1462 if(t.
id()==ID_constant)
1492 for(
int i=1; i<second; i++)
1501 for(
int i=-1; i>second; i--)
1539 exprt positive, negative;
1549 auto it=elems.find(qvar);
1553 if(it->second==1 || it->second==-1)
1555 neg=(it->second==1);
1562 "a proper function must have exactly one " 1563 "occurrences after reduction, or it cancelled out, and it does not" 1565 stream <<
"in string_refinementt::compute_inverse_function:" 1566 <<
" warning: occurrences of qvar cancelled out " <<
messaget::eom;
1611 for(
const auto &axiom : axioms.
universal)
1624 const std::vector<exprt> ¤t_constraints)
1626 for(
const auto &axiom : current_constraints)
1638 if(array_expr.
id()==ID_if)
1645 if(array_expr.
type().
id() == ID_array)
1648 accu.push_back(array_expr);
1652 for(
const auto &operand : array_expr.
operands())
1670 const bool is_size_t =
numeric_cast<std::size_t>(i).has_value();
1671 if(i.
id()!=ID_constant || is_size_t)
1673 std::vector<exprt> sub_arrays;
1675 for(
const auto &sub : sub_arrays)
1676 if(index_set.
cumulative[sub].insert(i).second)
1677 index_set.
current[sub].insert(i);
1700 const exprt &upper_bound,
1705 if(s.
id() == ID_array)
1707 for(std::size_t j = 0; j < s.
operands().size(); ++j)
1711 if(
auto ite = expr_try_dynamic_cast<if_exprt>(s))
1737 const auto &s = index_expr.
array();
1739 it.next_sibling_or_parent();
1763 it.next_sibling_or_parent();
1782 const exprt &formula)
1784 std::list<exprt> to_process;
1785 to_process.push_back(formula);
1787 while(!to_process.empty())
1789 exprt cur=to_process.back();
1790 to_process.pop_back();
1799 if(s.
id() != ID_array)
1805 to_process.push_back(*it);
1817 static std::unordered_set<exprt, irep_hash>
1821 auto index_str_containing_qvar = [&](
const exprt &e) {
1822 if(
auto index_expr = expr_try_dynamic_cast<index_exprt>(e))
1824 const auto &arr = index_expr->
array();
1825 const auto str_it = std::find(arr.depth_begin(), arr.depth_end(), str);
1832 if(index_str_containing_qvar(e))
1858 str.
id() == ID_array || indexes.
size() <= 1,
1859 "non constant array should always be accessed at the same index");
1861 for(
const auto &index : indexes)
1863 const exprt univ_var_value =
1871 conjuncts.push_back(instance);
1903 const auto &index_set1=index_set.
cumulative.find(
s1.content());
1904 const auto ¤t_index_set0=index_set.
current.find(s0.
content());
1905 const auto ¤t_index_set1=index_set.
current.find(
s1.content());
1909 current_index_set0!=index_set.
current.end() &&
1910 current_index_set1!=index_set.
current.end())
1912 typedef std::pair<exprt, exprt> expr_pairt;
1913 std::set<expr_pairt> index_pairs;
1915 for(
const auto &ic0 : current_index_set0->second)
1916 for(
const auto &i1 : index_set1->second)
1917 index_pairs.insert(expr_pairt(ic0, i1));
1918 for(
const auto &ic1 : current_index_set1->second)
1919 for(
const auto &i0 : index_set0->second)
1920 index_pairs.insert(expr_pairt(i0, ic1));
1936 for(
auto &operand : expr.
operands())
1939 if(expr.
id() == ID_array_list)
1949 for(
size_t i=0; i<expr.
operands().size(); i+=2)
1953 const auto index_value =
numeric_cast<std::size_t>(index);
1955 (index_value && *index_value<string_max_length))
1973 const auto super_get = [
this](
const exprt &expr) {
1983 std::reference_wrapper<const exprt> current(index_expr->
array());
1984 while(current.get().id() == ID_if)
1989 current = std::cref(if_expr.
true_case());
1990 else if(cond.is_false())
1996 const auto index =
get(index_expr->
index());
1997 const exprt unknown =
2002 if(
const auto index_value = numeric_cast<std::size_t>(index))
2003 return sparse_array->at(*index_value);
2004 return sparse_array->to_if_expression(index);
2008 array.is_nil() || array.id() == ID_symbol,
2010 "apart from symbols, array valuations can be interpreted as " 2011 "sparse arrays, id: ") +
2022 const auto from_dependencies =
2024 return *from_dependencies;
2027 const auto arr_model_opt =
2029 return *arr_model_opt;
2034 if(
const auto n = numeric_cast<std::size_t>(length))
2059 satcheck_no_simplifiert sat_check;
2080 [&](
const exprt &expr)
2084 indices[index_expr->
array()].push_back(index_expr->
index());
2101 it->id() != ID_plus && it->id() != ID_minus &&
2102 it->id() != ID_unary_minus && *it != var)
2107 it.next_sibling_or_parent();
2128 if(it->id() == ID_index)
2129 it.next_sibling_or_parent();
2151 for(
const auto &pair : body_indices)
2154 const exprt rep=pair.second.back();
2155 for(
size_t j=0; j<pair.second.size()-1; j++)
2157 const exprt i=pair.second[j];
2162 stream <<
"Indices not equal: " <<
to_string(constraint)
2163 <<
", str: " <<
format(pair.first) << eom;
2171 stream <<
"f is not linear: " <<
to_string(constraint)
2172 <<
", str: " <<
format(pair.first) << eom;
2180 stream <<
"Universal variable outside of index:" <<
to_string(constraint)
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
static std::vector< exprt > generate_instantiations(messaget::mstreamt &stream, const string_constraint_generatort &generator, const index_set_pairt &index_set, const string_axiomst &axioms)
Instantiation of all constraints.
The type of an expression.
static void display_index_set(messaget::mstreamt &stream, const index_set_pairt &index_set)
Write index set to the given stream, use for debugging.
array_exprt concretize(std::size_t size, const typet &index_type) const
Convert to an array representation, ignores elements at index >= size.
static exprt sum_over_map(std::map< exprt, int > &m, const typet &type, bool negated=false)
static std::pair< bool, std::vector< exprt > > check_axioms(const string_axiomst &axioms, string_constraint_generatort &generator, const std::function< exprt(const exprt &)> &get, messaget::mstreamt &stream, const namespacet &ns, bool use_counter_example, const union_find_replacet &symbol_resolve)
Check axioms takes the model given by the underlying solver and answers whether it satisfies the stri...
static std::unordered_set< exprt, irep_hash > find_indexes(const exprt &expr, const exprt &str, const symbol_exprt &qvar)
Find indexes of str used in expr that contains qvar, for instance with arguments (str[k+1]=='a'), str, and k, the function should return k+1.
static exprt instantiate(messaget::mstreamt &stream, const string_constraintt &axiom, const exprt &str, const exprt &val)
Substitute qvar the universally quantified variable of axiom, by an index val, in axiom...
void add_constraints(string_constraint_generatort &generatort)
For all builtin call on which a test (or an unsupported buitin) result depends, add the corresponding...
const std::set< array_string_exprt > & get_created_strings() const
Set of strings that have been created by the generator.
A generic base class for relations, i.e., binary predicates.
const std::string & id2string(const irep_idt &d)
static exprt get_char_array_and_concretize(const std::function< exprt(const exprt &)> &super_get, const namespacet &ns, messaget::mstreamt &stream, const array_string_exprt &arr)
Debugging function which finds the valuation of the given array in super_get and concretize unknown c...
std::vector< equal_exprt > equations
std::map< exprt, std::vector< exprt > > array_index_mapt
literalt convert(const exprt &expr) override
const exprt & univ_lower_bound() const
const std::vector< string_constraintt > & get_constraints() const
bool equality_propagation
exprt get_witness_of(const string_not_contains_constraintt &c, const exprt &univ_val) const
exprt simplify_expr(const exprt &src, const namespacet &ns)
void clean_cache()
Clean the cache used by eval
bool has_subtype(const typet &type, const std::function< bool(const typet &)> &pred, const namespacet &ns)
returns true if any of the contained types satisfies pred
union_find_replacet string_identifiers_resolution_from_equations(std::vector< equal_exprt > &equations, const namespacet &ns, messaget::mstreamt &stream)
Symbol resolution for expressions of type string typet.
Deprecated expression utility functions.
static optionalt< exprt > find_counter_example(const namespacet &ns, const exprt &axiom, const symbol_exprt &var)
Creates a solver with axiom as the only formula added and runs it.
bool add_node(string_dependenciest &dependencies, const equal_exprt &equation, array_poolt &array_pool)
When right hand side of equation is a builtin_function add a "string_builtin_function" node to the gr...
const std::vector< exprt > & get_lemmas() const
Axioms are of three kinds: universally quantified string constraint, not contains string constraints ...
const irep_idt & get_identifier() const
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by a canonical element of the set they belong to.
string_refinementt constructor arguments
bool is_char_pointer_type(const typet &type)
For now, any unsigned bitvector type is considered a character.
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
std::map< exprt, std::set< exprt > > current
const componentst & components() const
symbol_exprt fresh_univ_index(const irep_idt &prefix, const typet &type)
generate an index symbol to be used as an universaly quantified variable
static void update_index_set(index_set_pairt &index_set, const namespacet &ns, const std::vector< exprt > ¤t_constraints)
Add to the index set all the indices that appear in the formulas.
exprt get_length(const array_string_exprt &s) const
Associate an actual finite length to infinite arrays.
The trinary if-then-else operator.
static exprt substitute_array_access(const index_exprt &index_expr, const std::function< symbol_exprt(const irep_idt &, const typet &)> &symbol_generator, const bool left_propagate)
const std::vector< string_not_contains_constraintt > & get_not_contains_constraints() const
depth_iteratort depth_begin()
exprt univ_within_bounds() const
static union_find_replacet generate_symbol_resolution_from_equations(const std::vector< equal_exprt > &equations, const namespacet &ns, messaget::mstreamt &stream)
Add association for each char pointer in the equation.
Magic numbers used throughout the codebase.
A constant literal expression.
static bool validate(const string_refinementt::infot &info)
auto expr_dynamic_cast(TExpr &base) -> typename detail::expr_dynamic_cast_return_typet< T, TExpr >::type
Cast a reference to a generic exprt to a specific derived class.
static optionalt< exprt > get_array(const std::function< exprt(const exprt &)> &super_get, const namespacet &ns, messaget::mstreamt &stream, const array_string_exprt &arr)
Get a model of an array and put it in a certain form.
static mstreamt & eom(mstreamt &m)
void clear_constraints()
Clear all constraints and lemmas.
#define INVARIANT(CONDITION, REASON)
void l_set_to_true(literalt a)
exprt substitute_array_lists(exprt expr, size_t string_max_length)
Replace array-lists by 'with' expressions.
const std::vector< symbol_exprt > & get_boolean_symbols() const
Boolean symbols for the results of some string functions.
Extract member of struct or union.
void operator()(const exprt &expr) override
string_dependenciest dependencies
string_refinementt(const infot &)
static void add_to_index_set(index_set_pairt &index_set, const namespacet &ns, const exprt &s, exprt i)
Add i to the index set all the indices that appear in the formula.
bool can_cast_expr< function_application_exprt >(const exprt &base)
exprt conjunction(const exprt::operandst &op)
static void substitute_array_access_in_place(exprt &expr, const std::function< symbol_exprt(const irep_idt &, const typet &)> &symbol_generator, const bool left_propagate)
Auxiliary function for substitute_array_access Performs the same operation but modifies the argument ...
static std::vector< T > fill_in_map_as_vector(const std::map< std::size_t, T > &index_value)
Convert index-value map to a vector of values.
const exprt & exists_lower_bound() const
const irep_idt & id() const
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
exprt make_union(const exprt &a, const exprt &b)
Keeps a map of symbols to expressions, such as none of the mapped values exist as a key...
static void get_sub_arrays(const exprt &array_expr, std::vector< exprt > &accu)
An expression representing an array of characters can be in the form of an if expression for instance...
void visit(class expr_visitort &visitor)
An expression denoting infinity.
Defines related function for string constraints.
std::vector< exprt > instantiate_not_contains(const string_not_contains_constraintt &axiom, const std::set< std::pair< exprt, exprt >> &index_pairs, const string_constraint_generatort &generator)
Instantiates a quantified formula representing not_contains by substituting the quantifiers and gener...
#define CHARACTER_FOR_UNKNOWN
optionalt< exprt > eval(const array_string_exprt &s, const std::function< exprt(const exprt &)> &get_value) const
Attempt to evaluate the given string from the dependencies and valuation of strings on which it depen...
Constraints to encode non containement of strings.
int solver(std::istream &in)
std::map< exprt, std::set< exprt > > cumulative
static bool universal_only_in_index(const string_constraintt &constr)
The universally quantified variable is only allowed to occur in index expressions in the body of a st...
Represents arrays by the indexes up to which the value remains the same.
exprt simplify_sum(const exprt &f)
static bool is_valid_string_constraint(messaget::mstreamt &stream, const namespacet &ns, const string_constraintt &constraint)
Checks the data invariant for string_constraintt.
nonstd::optional< T > optionalt
void add(const std::size_t i, const exprt &expr)
Record the fact that equation i contains expression expr
union_find_replacet symbol_resolve
const std::size_t MAX_CONCRETE_STRING_SIZE
static bool is_valid_string_constraint(messaget::mstreamt &stream, const namespacet &ns, const string_constraintt &constraint)
#define PRECONDITION(CONDITION)
#define forall_operands(it, expr)
std::vector< exprt > instantiate_not_contains(const string_not_contains_constraintt &axiom, const std::set< std::pair< exprt, exprt >> &index_pairs, const string_constraint_generatort &generator)
bool has_char_pointer_subtype(const typet &type, const namespacet &ns)
array constructor from single element
bitvector_typet index_type()
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
const exprt & premise() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
decision_proceduret::resultt dec_solve() override
The unary minus expression.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast a generic exprt to a constant_exprt.
decision_proceduret::resultt dec_solve() override
Main decision procedure of the solver.
static bool is_linear_arithmetic_expr(const exprt &expr, const symbol_exprt &var)
static exprt negation_of_not_contains_constraint(const string_not_contains_constraintt &constraint, const symbol_exprt &univ_var, const std::function< exprt(const exprt &)> &get)
Negates the constraint to be fed to a solver.
static bool find_qvar(const exprt &index, const symbol_exprt &qvar)
look for the symbol and return true if it is found
string_constraint_generatort generator
const std::unordered_map< exprt, array_string_exprt, irep_hash > & get_arrays_of_pointers() const
std::vector< exprt > operandst
static exprt to_if_expression(const with_exprt &expr, const exprt &index)
Creates an if_expr corresponding to the result of accessing the array at the given index...
String support via creating string constraints and progressively instantiating the universal constrai...
std::vector< string_constraintt > universal
bool has_char_array_subexpr(const exprt &expr, const namespacet &ns)
static void make_char_array_pointer_associations(string_constraint_generatort &generator, std::vector< equal_exprt > &equations)
Fill the array_pointer correspondence and replace the right hand sides of the corresponding equations...
static void initial_index_set(index_set_pairt &index_set, const namespacet &ns, const string_constraintt &axiom)
const equal_exprt & to_equal_expr(const exprt &expr)
Cast a generic exprt to an equal_exprt.
exprt get(const exprt &expr) const override
Similar interface to union-find for expressions, with a function for replacing sub-expressions by the...
std::vector< exprt > find_expressions(const std::size_t i)
Maps equation to expressions contained in them and conversely expressions to equations that contain t...
static void add_string_equation_to_symbol_resolution(const equal_exprt &eq, union_find_replacet &symbol_resolve, const namespacet &ns)
Given an equation on strings, mark these strings as belonging to the same set in the symbol_resolve s...
static std::string string_of_array(const array_exprt &arr)
convert the content of a string to a more readable representation.
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
const exprt & exists_upper_bound() const
Base class for all expressions.
static std::vector< exprt > extract_strings(const exprt &expr)
optionalt< exprt > make_array_pointer_association(const function_application_exprt &expr)
Associate array to pointer, and array to length.
void set_to(const exprt &expr, bool value) override
Record the constraints to ensure that the expression is true when the boolean is true and false other...
std::set< exprt > seen_instances
Operator to update elements in structs and arrays.
std::string to_string(const string_constraintt &expr)
Used for debug printing.
exprt to_if_expression(const exprt &index) const
static std::map< exprt, int > map_representation_of_sum(const exprt &f)
#define string_refinement_invariantt(reason)
static void debug_check_axioms_step(messaget::mstreamt &stream, const T &axiom, const T &axiom_in_model, const exprt &negaxiom, const exprt &with_concretized_arrays)
Debugging function which outputs the different steps an axiom goes through to be checked in check axi...
Universally quantified string constraint
const exprt & univ_upper_bound() const
static optionalt< interval_sparse_arrayt > of_expr(const exprt &expr, const exprt &extra_value)
If the expression is an array_exprt or a with_exprt uses the appropriate constructor, otherwise returns empty optional.
static std::vector< exprt > extract_strings_from_lhs(const exprt &lhs)
This is meant to be used on the lhs of an equation with string subtype.
Expression to hold a symbol (variable)
depth_iteratort depth_end()
void debug_model(const string_constraint_generatort &generator, messaget::mstreamt &stream, const namespacet &ns, const std::function< exprt(const exprt &)> &super_get, const std::vector< symbol_exprt > &boolean_symbols, const std::vector< symbol_exprt > &index_symbols)
Display part of the current model by mapping the variables created by the solver to constant expressi...
exprt get(const exprt &expr) const override
Evaluates the given expression in the valuation found by string_refinementt::dec_solve.
std::string utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
Construct a string from a constant array.
const typet & subtype() const
#define DATA_INVARIANT(CONDITION, REASON)
void set_to(const exprt &expr, bool value) override
std::map< string_not_contains_constraintt, symbol_exprt > witness
const array_string_exprt & s0() const
bool is_char_type(const typet &type)
For now, any unsigned bitvector type of width smaller or equal to 16 is considered a character...
bool is_char_array_type(const typet &type, const namespacet &ns)
Distinguish char array from other types.
std::vector< std::size_t > find_equations(const exprt &expr)
const std::vector< symbol_exprt > & get_index_symbols() const
Symbols used in existential quantifications.
std::vector< exprt > current_constraints
static array_index_mapt gather_indices(const exprt &expr)
const index_exprt & to_index_expr(const exprt &expr)
Cast a generic exprt to an index_exprt.
bitvector_typet char_type()
array constructor from list of elements
void replace_symbols_in_equations(const union_find_replacet &symbol_resolve, std::vector< equal_exprt > &equations)
index_set_pairt index_sets
std::vector< string_not_contains_constraintt > not_contains
std::vector< std::pair< exprt, exprt > > to_vector() const
array_string_exprt & to_array_string_expr(exprt &expr)
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
static exprt compute_inverse_function(messaget::mstreamt &stream, const exprt &qvar, const exprt &val, const exprt &f)
bool simplify(exprt &expr, const namespacet &ns)
symbol_generatort fresh_symbol
void output_dot(std::ostream &stream) const
void add_lemma(const exprt &lemma, bool simplify_lemma=true)
Add the given lemma to the solver.
const array_string_exprt & s1() const
find_qvar_visitort(const exprt &qvar)