Go to the documentation of this file.
32 for(std::size_t i=0; i<
entries.size(); i++)
33 out <<
"STORE " << i <<
": " <<
map[i] <<
'\n';
97 if(expr.
id()==ID_typecast)
102 typecast_expr.type().id() == ID_signedbv ||
103 typecast_expr.type().id() == ID_unsignedbv)
105 const typet &op_type = typecast_expr.op().type();
107 if(op_type.
id() == ID_signedbv || op_type.
id() == ID_unsignedbv)
116 else if(op_type.
id() == ID_bool)
128 if(expr.
type().
id()==ID_pointer)
129 if(expr.
get(ID_value)==ID_NULL)
132 const auto i = numeric_cast<mp_integer>(expr);
143 if(expr.
id()==ID_member)
149 if(expr.
id()==ID_symbol)
164 if(expr.
id()==ID_address_of)
172 if(expr.
id()==ID_symbol)
174 else if(expr.
id()==ID_member)
176 else if(expr.
id()==ID_index)
179 if(index_expr.index().is_constant())
187 const std::pair<unsigned, unsigned> &p,
203 dest.insert(std::pair<unsigned, unsigned>(f, s));
215 bool constant_seen=
false;
238 for(
const auto &le :
le_set)
241 for(
const auto &ne :
ne_set)
247 const std::pair<unsigned, unsigned> &eq,
248 const std::pair<unsigned, unsigned> &ineq)
250 std::pair<unsigned, unsigned> n;
254 if(eq.first==ineq.first)
261 if(eq.first==ineq.second)
268 if(eq.second==ineq.first)
275 if(eq.second==ineq.second)
285 std::pair<unsigned, unsigned> s=p;
286 std::swap(s.first, s.second);
299 std::pair<unsigned, unsigned> s=p;
300 std::swap(s.first, s.second);
344 out <<
to_string(bounds.first) <<
" in " << bounds.second <<
'\n';
347 for(
const auto &le :
le_set)
352 for(
const auto &ne :
ne_set)
360 if(expr.
type()==type)
363 if(type.
id()==ID_unsignedbv)
387 if(expr.
type().
id()!=ID_bool)
388 throw "non-Boolean argument to strengthen()";
409 else if(expr.
id()==ID_not)
413 else if(expr.
id()==ID_and)
418 else if(expr.
id()==ID_le ||
426 if(rel.rhs().id() == ID_bitand)
440 std::pair<unsigned, unsigned> p;
445 const auto i0 = numeric_cast<mp_integer>(rel.op0());
446 const auto i1 = numeric_cast<mp_integer>(rel.op1());
452 else if(i1.has_value())
457 else if(expr.
id()==ID_lt)
461 else if(i1.has_value())
472 else if(expr.
id()==ID_equal)
476 const typet &op_type = equal_expr.op0().type();
478 if(op_type.
id() == ID_struct || op_type.
id() == ID_struct_tag)
482 for(
const auto &comp : struct_type.
components())
485 equal_expr.op0(), comp.get_name(), comp.type());
487 equal_expr.op1(), comp.get_name(), comp.type());
489 const equal_exprt equality(lhs_member_expr, rhs_member_expr);
501 if(equal_expr.op1().id() == ID_bitand)
503 const exprt &bitand_op = equal_expr.
op1();
507 auto tmp(equal_expr);
515 else if(equal_expr.op0().id() == ID_bitand)
517 auto tmp(equal_expr);
518 std::swap(tmp.op0(), tmp.op1());
524 if(equal_expr.op1().id() == ID_typecast)
529 else if(equal_expr.op0().id() == ID_typecast)
535 std::pair<unsigned, unsigned> p, s;
544 const auto i0 = numeric_cast<mp_integer>(equal_expr.op0());
545 const auto i1 = numeric_cast<mp_integer>(equal_expr.op1());
548 else if(i1.has_value())
552 std::swap(s.first, s.second);
560 else if(expr.
id()==ID_notequal)
564 std::pair<unsigned, unsigned> p;
590 if(expr.
type().
id()!=ID_bool)
591 throw "implies: non-Boolean expression";
602 else if(expr.
id()==ID_not)
606 else if(expr.
id()==ID_and)
614 else if(expr.
id()==ID_or)
620 else if(expr.
id()==ID_le ||
622 expr.
id()==ID_equal ||
623 expr.
id()==ID_notequal)
627 std::pair<unsigned, unsigned> p;
637 if(rel.id() == ID_le)
649 else if(rel.id() == ID_lt)
661 else if(rel.id() == ID_equal)
663 else if(rel.id() == ID_notequal)
679 const auto tmp = numeric_cast<mp_integer>(e_a);
686 if(e_a.
type().
id()==ID_unsignedbv)
690 bounds_mapt::const_iterator it=
bounds_map.find(a);
698 if(expr.
type().
id()!=ID_bool)
699 throw "nnf: non-Boolean expression";
711 else if(expr.
id()==ID_not)
718 else if(expr.
id()==ID_and)
726 else if(expr.
id()==ID_or)
734 else if(expr.
id()==ID_typecast)
739 typecast_expr.op().type().id() == ID_unsignedbv ||
740 typecast_expr.op().type().id() == ID_signedbv)
743 typecast_expr.op(),
from_integer(0, typecast_expr.op().type()));
752 else if(expr.
id()==ID_le)
759 std::swap(rel.lhs(), rel.rhs());
762 else if(expr.
id()==ID_lt)
769 std::swap(rel.lhs(), rel.rhs());
772 else if(expr.
id()==ID_ge)
780 std::swap(rel.lhs(), rel.rhs());
783 else if(expr.
id()==ID_gt)
791 std::swap(rel.lhs(), rel.rhs());
794 else if(expr.
id()==ID_equal)
797 expr.
id(ID_notequal);
799 else if(expr.
id()==ID_notequal)
813 if(expr.
id()==ID_address_of)
819 if(expr.
id()==ID_symbol ||
820 expr.
id()==ID_member)
835 bounds_mapt::const_iterator it=
bounds_map.find(a);
839 if(it->second.singleton())
856 if(expr.
type().
id()==ID_pointer)
920 std::size_t old_ne_set=
ne_set.size();
921 std::size_t old_le_set=
le_set.size();
931 old_ne_set!=
ne_set.size() ||
932 old_le_set!=
le_set.size())
942 for(bounds_mapt::iterator
947 bounds_mapt::const_iterator o_it=other.find(it->first);
949 if(o_it==other.end())
951 bounds_mapt::iterator next(it);
960 it->second.approx_union_with(o_it->second);
980 if(lhs.
id()==ID_symbol ||
987 else if(lhs.
id()==ID_index)
991 else if(lhs.
id()==ID_dereference)
996 else if(lhs.
id()==
"object_value")
1001 else if(lhs.
id()==ID_if)
1007 else if(lhs.
id()==ID_typecast)
1012 else if(lhs.
id()==
"valid_object")
1015 else if(lhs.
id()==
"dynamic_size")
1018 else if(lhs.
id()==ID_byte_extract_little_endian ||
1019 lhs.
id()==ID_byte_extract_big_endian)
1024 else if(lhs.
id() == ID_null_object ||
1025 lhs.
id() ==
"is_zero_string" ||
1026 lhs.
id() ==
"zero_string" ||
1027 lhs.
id() ==
"zero_string_length")
1032 throw "modifies: unexpected lhs: "+lhs.
id_string();
1056 if(statement==ID_block)
1061 else if(statement==ID_assign)
1064 throw "assignment expected to have two operands";
1068 else if(statement==ID_decl)
1075 else if(statement==ID_expression)
1079 else if(statement==ID_function_call)
1084 else if(statement==ID_cpp_delete ||
1085 statement==ID_cpp_delete_array)
1089 else if(statement==ID_printf)
1093 else if(statement==
"lock" ||
1094 statement==
"unlock" ||
1101 std::cerr << code.
pretty() <<
'\n';
1102 throw "invariant_sett: unexpected statement: "+
id2string(statement);
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
void strengthen(const exprt &expr)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
interval_templatet< mp_integer > boundst
size_type find(size_type a) const
#define Forall_operands(it, expr)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
tvt implies(const exprt &expr) const
std::set< std::pair< unsigned, unsigned > > ineq_sett
#define CHECK_RETURN(CONDITION)
void get_bounds(unsigned a, boundst &dest) const
void check_index(size_type a)
The type of an expression, extends irept.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void add_type_bounds(const exprt &expr, const typet &type)
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
tvt is_lt(std::pair< unsigned, unsigned > p) const
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
inv_object_storet & object_store
Base class for all expressions.
std::string to_string(unsigned n) const
void intersection(const unsigned_union_find &other)
tvt is_le(std::pair< unsigned, unsigned > p) const
void output(std::ostream &out) const
bool make_union_bounds_map(const bounds_mapt &other)
bool is_true() const
Return whether the expression is a constant representing true.
static void nnf(exprt &expr, bool negate=false)
std::vector< entryt > entries
bool is_false() const
Return whether the expression is a constant representing false.
void apply_code(const codet &code)
const codet & to_code(const exprt &expr)
Generic exception types primarily designed for use with invariants.
typet & type()
Return the type of the expression.
unsigned add(const exprt &expr)
size_type count(size_type a) const
Expression classes for byte-level operators.
static void intersection(ineq_sett &dest, const ineq_sett &other)
unsigned_union_find eq_set
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
void add_le(const std::pair< unsigned, unsigned > &p)
The null pointer constant.
const std::string & id2string(const irep_idt &d)
void make_union(size_type a, size_type b)
#define forall_operands(it, expr)
void add_eq(const std::pair< unsigned, unsigned > &eq)
const exprt & get_expr(unsigned n) const
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
bool get(const exprt &expr, unsigned &n)
API to expression classes for Pointers.
const std::string & id_string() const
const notequal_exprt & to_notequal_expr(const exprt &expr)
Cast an exprt to an notequal_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
void modifies(const exprt &lhs)
bool is_constant(unsigned n) const
The Boolean constant false.
optionalt< number_type > get_number(const key_type &a) const
std::string to_string(unsigned a) const
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
static void remove(ineq_sett &dest, unsigned a)
tvt implies_rec(const exprt &expr) const
void add_ne(const std::pair< unsigned, unsigned > &p)
bool has_le(const std::pair< unsigned, unsigned > &p) const
void output(std::ostream &out) const
std::size_t get_width() const
void add(const std::pair< unsigned, unsigned > &p, ineq_sett &dest)
interval_templatet< T > lower_interval(const T &l)
std::map< unsigned, boundst > bounds_mapt
Extract member of struct or union.
Deprecated expression utility functions.
const std::string & get_string(const irep_namet &name) const
Structure type, corresponds to C style structs.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
const irep_idt & get(const irep_namet &name) const
void assignment(const exprt &lhs, const exprt &rhs)
number_type number(const key_type &a)
std::string build_string(const exprt &expr) const
size_type count_roots() const
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
bool is_constant() const
Return whether the expression is a constant.
void simplify(exprt &expr) const
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
bool get_object(const exprt &expr, unsigned &n) const
bool make_union(const invariant_sett &other_invariants)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const irept & get_nil_irep()
tvt is_ne(std::pair< unsigned, unsigned > p) const
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
bool is_root(size_type a) const
exprt get_constant(const exprt &expr) const
static bool is_constant_address_rec(const exprt &expr)
Semantic type conversion.
The Boolean constant true.
void isolate(size_type a)
void strengthen_rec(const exprt &expr)
API to expression classes.
tvt is_eq(std::pair< unsigned, unsigned > p) const
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast an exprt to a binary_relation_exprt.
static bool is_constant_address(const exprt &expr)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
void add_bounds(unsigned a, const boundst &bound)
bool has_ne(const std::pair< unsigned, unsigned > &p) const
bool has_eq(const std::pair< unsigned, unsigned > &p) const
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
interval_templatet< T > upper_interval(const T &u)
Data structure for representing an arbitrary statement in a program.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const std::string integer2string(const mp_integer &n, unsigned base)