Go to the documentation of this file.
40 std::ostream &out)
const
42 for(valuest::const_iterator
49 const entryt &e=v_it->second;
61 identifier=symbol.
name;
77 const auto &entries = object_map.
read();
79 o_it != entries.end();
86 if(o.
id()==ID_invalid || o.
id()==ID_unknown)
91 if(o.
type().
id()==ID_unknown)
99 result=
"<"+
from_expr(ns, identifier, o)+
", ";
108 if(o.
type().
id()==ID_unknown)
118 width+=result.size();
123 if(next != entries.end())
147 std::cout <<
"FLATTEN: Done.\n";
161 assert(seen.find(identifier + e.
suffix)==seen.end());
163 bool generalize_index =
false;
165 seen.insert(identifier + e.
suffix);
171 if(o.
type().
id()==
"#REF#")
173 if(seen.find(o.
get(ID_identifier))!=seen.end())
175 generalize_index =
true;
179 valuest::const_iterator fi =
values.find(o.
get(ID_identifier));
196 if(t_it->second && object_entry.second)
198 *t_it->second += *object_entry.second;
201 t_it->second.reset();
204 for(
const auto &object_entry : temp.
read())
205 insert(dest, object_entry);
209 insert(dest, object_entry);
214 for(
auto &object_entry : dest.
write())
215 object_entry.second.reset();
218 seen.erase(identifier + e.
suffix);
225 if(
object.
id()==ID_invalid ||
226 object.
id()==ID_unknown)
238 return std::move(od);
246 for(valuest::const_iterator
247 it=new_values.begin();
248 it!=new_values.end();
251 valuest::iterator it2=
values.find(it->first);
257 "value_set::dynamic_object") ||
259 "value_set::return_value"))
269 const entryt &new_e=it->second;
284 for(
const auto &object_entry : src.
read())
286 if(
insert(dest, object_entry))
301 for(
const auto &object_entry : object_map.
read())
304 if(
object.type().
id()==
"#REF#")
306 assert(
object.
id()==ID_symbol);
308 const irep_idt &ident =
object.get(ID_identifier);
309 valuest::const_iterator v_it =
values.find(ident);
320 if(t_it->second && object_entry.second)
322 *t_it->second += *object_entry.second;
325 t_it->second.reset();
327 flat_map.
write()[t_it->first]=t_it->second;
332 flat_map.
write()[object_entry.first] = object_entry.second;
335 std::vector<exprt> result;
336 for(
const auto &object_entry : flat_map.
read())
337 result.push_back(
to_expr(object_entry));
341 for(std::list<exprt>::const_iterator it=value_set.begin();
344 assert(it->type().id()!=
"#REF");
348 for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++)
349 std::cout <<
"GET_VALUE_SET: " <<
format(*it) <<
'\n';
370 const std::string &suffix,
371 const typet &original_type,
376 std::cout <<
"GET_VALUE_SET_REC EXPR: " <<
format(expr)
378 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
382 if(expr.
type().
id()==
"#REF#")
384 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
388 for(
const auto &object_entry : fi->second.object_map.read())
406 else if(expr.
id()==ID_unknown || expr.
id()==ID_invalid)
411 else if(expr.
id()==ID_index)
415 if(type.
id() == ID_array)
430 else if(expr.
id()==ID_member)
434 if(compound.is_not_nil())
439 type.
id() == ID_struct || type.
id() == ID_union,
440 "operand 0 of member expression must be struct or union");
442 const std::string &component_name =
448 "." + component_name + suffix,
456 else if(expr.
id()==ID_symbol)
461 valuest::const_iterator v_it=
values.find(ident);
468 else if(v_it!=
values.end())
476 else if(expr.
id()==ID_if)
495 else if(expr.
id()==ID_address_of)
501 else if(expr.
id()==ID_dereference)
507 if(object_map.
begin()!=object_map.
end())
509 for(
const auto &object_entry : object_map)
513 original_type, ns, recursion_set);
531 else if(expr.
id()==ID_typecast)
543 else if(expr.
id()==ID_plus || expr.
id()==ID_minus)
546 throw expr.
id_string()+
" expected to have at least two operands";
548 if(expr.
type().
id()==ID_pointer)
551 const exprt *ptr_operand=
nullptr;
554 if(it->type().id()==ID_pointer)
556 if(ptr_operand==
nullptr)
559 throw "more than one pointer operand in pointer arithmetic";
562 if(ptr_operand==
nullptr)
563 throw "pointer type sum expected to have pointer operand";
567 ptr_operand->
type(), ns, recursion_set);
569 for(
const auto &object_entry : pointer_expr_set.
read())
571 offsett offset = object_entry.second;
577 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op0());
581 *offset = (expr.
id() == ID_plus) ? *i : -*i;
585 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op1());
589 *offset = (expr.
id() == ID_plus) ? *i : -*i;
595 insert(dest, object_entry.first, offset);
601 else if(expr.
id()==ID_side_effect)
605 if(statement==ID_function_call)
608 throw "unexpected function_call sideeffect";
610 else if(statement==ID_allocate)
612 if(expr.
type().
id()!=ID_pointer)
613 throw "malloc expected to return pointer type";
617 const typet &dynamic_type=
618 static_cast<const typet &
>(expr.
find(ID_C_cxx_alloc_type));
629 else if(statement==ID_cpp_new ||
630 statement==ID_cpp_new_array)
633 assert(expr.
type().
id()==ID_pointer);
645 else if(expr.
id()==ID_struct)
651 else if(expr.
id()==ID_with)
654 throw "unexpected value in get_value_set: "+expr.
id_string();
656 else if(expr.
id()==ID_array_of ||
663 else if(expr.
id()==ID_dynamic_object)
668 const std::string name=
669 "value_set::dynamic_object"+
674 valuest::const_iterator v_it=
values.find(name);
691 if(src.
id()==ID_typecast)
693 assert(src.
type().
id()==ID_pointer);
709 for(
const auto &object_entry : object_map.
read())
713 if(
object.type().
id() ==
"#REF#")
715 const irep_idt &ident =
object.get(ID_identifier);
716 valuest::const_iterator vit =
values.find(ident);
721 dest.insert(
exprt(ID_unknown,
object.type()));
732 if(t_it->second && object_entry.second)
734 *t_it->second += *object_entry.second;
737 t_it->second.reset();
740 for(
const auto &o : omt.
read())
745 dest.insert(
to_expr(object_entry));
757 for(
const auto &object_entry : object_map.
read())
758 dest.insert(
to_expr(object_entry));
767 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr)
771 if(expr.
type().
id()==
"#REF#")
773 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
776 for(
const auto &object_entry : fi->second.object_map.read())
784 else if(expr.
id()==ID_symbol ||
785 expr.
id()==ID_dynamic_object ||
786 expr.
id()==ID_string_constant)
789 expr.
type().
id() == ID_array &&
799 else if(expr.
id()==ID_dereference)
812 for(
const auto &object_entry : temp.
read())
815 if(obj.
type().
id()==
"#REF#")
818 valuest::const_iterator v_it =
values.find(ident);
829 if(t_it->second && object_entry.second)
831 *t_it->second += *object_entry.second;
834 t_it->second.reset();
837 for(
const auto &t2_object_entry : t2.
read())
838 insert(dest, t2_object_entry);
846 insert(dest, object_entry);
850 for(expr_sett::const_iterator it=value_set.begin();
853 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
858 else if(expr.
id()==ID_index)
865 array_type.
id() == ID_array,
"index takes array-typed operand");
872 for(
const auto &object_entry : object_map)
876 if(
object.
id()==ID_unknown)
886 if(
object.type().
id() !=
"#REF#" &&
object.type() != array_type)
889 casted_index = index_expr;
891 offsett o = object_entry.second;
892 const auto i = numeric_cast<mp_integer>(offset);
902 insert(dest, casted_index, o);
908 else if(expr.
id()==ID_member)
910 const irep_idt &component_name=expr.
get(ID_component_name);
917 for(
const auto &object_entry : struct_references.
read())
920 const typet &obj_type =
object.type();
922 if(
object.
id()==ID_unknown)
925 obj_type.
id() != ID_struct && obj_type.
id() != ID_union &&
926 obj_type.
id() != ID_struct_tag && obj_type.
id() != ID_union_tag)
934 offsett o = object_entry.second;
945 insert(dest, member_expr, o);
951 else if(expr.
id()==ID_if)
967 std::cout <<
"ASSIGN LHS: " <<
format(lhs) <<
'\n';
968 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
980 if(type.
id()==ID_struct ||
987 for(struct_typet::componentst::const_iterator
992 const typet &subtype=c_it->type();
993 const irep_idt &name = c_it->get_name();
996 if(subtype.
id()==ID_code)
1003 if(rhs.
id()==ID_unknown ||
1004 rhs.
id()==ID_invalid)
1006 rhs_member=
exprt(rhs.
id(), subtype);
1011 throw "value_set_fit::assign type mismatch: "
1015 if(rhs.
id()==ID_struct ||
1016 rhs.
id()==ID_constant)
1021 else if(rhs.
id()==ID_with)
1025 const exprt &member_operand = rhs_with.where();
1028 member_operand.
get(ID_component_name);
1030 if(component_name==name)
1033 rhs_member = rhs_with.new_value();
1038 rhs_member=
exprt(ID_member, subtype);
1040 rhs_member.
set(ID_component_name, name);
1045 rhs_member=
exprt(ID_member, subtype);
1047 rhs_member.
set(ID_component_name, name);
1050 assign(lhs_member, rhs_member, ns);
1054 else if(type.
id()==ID_array)
1061 if(rhs.
id()==ID_unknown ||
1062 rhs.
id()==ID_invalid)
1073 if(rhs.
type() != type)
1074 throw "value_set_fit::assign type mismatch: "
1078 if(rhs.
id()==ID_array_of)
1082 else if(rhs.
id()==ID_array ||
1083 rhs.
id()==ID_constant)
1087 assign(lhs_index, *o_it, ns);
1090 else if(rhs.
id()==ID_with)
1097 assign(lhs_index, op0_index, ns);
1106 assign(lhs_index, rhs_index, ns);
1125 const std::string &suffix,
1130 std::cout <<
"ASSIGN_REC LHS: " <<
format(lhs) <<
'\n';
1131 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
1134 it!=values_rhs.
read().
end(); it++)
1135 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
1138 if(lhs.
type().
id()==
"#REF#")
1146 if(recursion_set.find(ident)!=recursion_set.end())
1148 recursion_set.insert(ident);
1150 for(
const auto &object_entry : temp.
read())
1154 if(
object.
id() != ID_unknown)
1155 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1158 recursion_set.erase(ident);
1161 else if(lhs.
id()==ID_symbol)
1166 "value_set::dynamic_object") ||
1168 "value_set::return_value") ||
1178 else if(lhs.
id()==ID_dynamic_object)
1183 const std::string name=
1184 "value_set::dynamic_object"+
1190 else if(lhs.
id()==ID_dereference)
1193 throw lhs.
id_string()+
" expected to have one operand";
1198 for(
const auto &object_entry : reference_set.
read())
1202 if(
object.
id()!=ID_unknown)
1203 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1206 else if(lhs.
id()==ID_index)
1210 if(type.
id() == ID_array)
1220 else if(lhs.
id()==ID_member)
1225 const std::string &component_name=lhs.
get_string(ID_component_name);
1230 type.
id() == ID_struct || type.
id() == ID_union,
1231 "operand 0 of member expression must be struct or union");
1236 "." + component_name + suffix,
1240 else if(lhs.
id()==
"valid_object" ||
1241 lhs.
id()==
"dynamic_type")
1245 else if(lhs.
id()==ID_string_constant)
1250 else if(lhs.
id() == ID_null_object)
1254 else if(lhs.
id()==ID_typecast)
1258 assign_rec(typecast_expr.
op(), values_rhs, suffix, ns, recursion_set);
1261 lhs.
id() ==
"zero_string" || lhs.
id() ==
"is_zero_string" ||
1262 lhs.
id() ==
"zero_string_length" || lhs.
id() == ID_address_of)
1266 else if(lhs.
id()==ID_byte_extract_little_endian ||
1267 lhs.
id()==ID_byte_extract_big_endian)
1273 throw "assign NYI: '" + lhs.
id_string() +
"'";
1291 for(std::size_t i=0; i<arguments.size(); i++)
1293 const std::string identifier=
"value_set::" +
id2string(
function) +
"::" +
1296 const symbol_exprt dummy_lhs(identifier, arguments[i].type());
1297 assign(dummy_lhs, arguments[i], ns);
1304 for(code_typet::parameterst::const_iterator
1305 it=parameter_types.begin();
1306 it!=parameter_types.end();
1309 const irep_idt &identifier=it->get_identifier();
1310 if(identifier.
empty())
1320 assign(actual_lhs, v_expr, ns);
1342 if(statement==ID_block)
1347 else if(statement==ID_function_call)
1352 else if(statement==ID_assign)
1355 throw "assignment expected to have two operands";
1359 else if(statement==ID_decl)
1362 throw "decl expected to have one operand";
1366 if(lhs.
id()!=ID_symbol)
1367 throw "decl expected to have symbol on lhs";
1371 else if(statement==ID_expression)
1375 else if(statement==ID_cpp_delete ||
1376 statement==ID_cpp_delete_array)
1380 else if(statement==
"lock" || statement==
"unlock")
1384 else if(statement==ID_asm)
1388 else if(statement==ID_nondet)
1392 else if(statement==ID_printf)
1396 else if(statement==ID_return)
1404 else if(statement==ID_fence)
1408 statement == ID_array_copy || statement == ID_array_replace ||
1409 statement == ID_array_set || statement == ID_array_equal)
1416 else if(statement == ID_havoc_object)
1422 "value_set_fit: unexpected statement: "+
id2string(statement);
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
entryt & get_entry(const idt &id, const std::string &suffix)
static const char * alloc_adapter_prefix
std::set< idt > flatten_seent
bool offset_is_zero(const offsett &offset) const
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
data_typet::iterator iterator
const irep_idt & display_name() const
Return language specific display name if present.
The type of an expression, extends irept.
std::vector< parametert > parameterst
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void assign(const exprt &lhs, const exprt &rhs, const namespacet &ns)
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
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.
void get_reference_set_sharing_rec(const exprt &expr, object_mapt &dest, const namespacet &ns) const
const irept & find(const irep_idt &name) const
Base type for structs and unions.
typet type
Type of symbol.
Representation of heap-allocated objects.
std::unordered_set< exprt, irep_hash > expr_sett
Split an expression into a base object and a (byte) offset.
void do_function_call(const irep_idt &function, const exprt::operandst &arguments, const namespacet &ns)
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
const type_with_subtypet & to_type_with_subtype(const typet &type)
Base class for all expressions.
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
void dereference_rec(const exprt &src, exprt &dest) const
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Type with a single subtype.
unsigned from_target_index
side_effect_exprt & to_side_effect_expr(exprt &expr)
void flatten(const entryt &e, object_mapt &dest) const
Expression to hold a symbol (variable)
void flatten_rec(const entryt &, object_mapt &, flatten_seent &) const
const irep_idt & get(const irep_idt &name) const
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void apply_code(const codet &code, const namespacet &ns)
unsigned int get_instance() const
Expression classes for byte-level operators.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
bool has_prefix(const std::string &s, const std::string &prefix)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const std::string & id2string(const irep_idt &d)
const exprt & compound() const
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
#define forall_operands(it, expr)
void set(const irep_idt &name, const irep_idt &value)
data_typet::const_iterator const_iterator
#define PRECONDITION(CONDITION)
const irep_idt & get_identifier() const
std::vector< exprt > get_value_set(const exprt &expr, const namespacet &ns) const
const std::string & id_string() const
bool simplify(exprt &expr, const namespacet &ns)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const std::string & get_string(const irep_idt &name) const
void assign_rec(const exprt &lhs, const object_mapt &values_rhs, const std::string &suffix, const namespacet &ns, assign_recursion_sett &recursion_set)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
std::map< idt, entryt > valuest
const irep_idt & id() const
std::vector< exprt > operandst
const parameterst & parameters() const
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
static const object_map_dt blank
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const irep_idt & get_statement() const
bool can_cast_expr< code_outputt >(const exprt &base)
bool is_zero() const
Return whether the expression is a constant representing 0.
Extract member of struct or union.
bool make_union(object_mapt &dest, const object_mapt &src) const
Deprecated expression utility functions.
void set_instance(unsigned int instance)
std::unordered_set< idt > assign_recursion_sett
void output(const namespacet &ns, std::ostream &out) const
std::unordered_set< idt > gvs_recursion_sett
goto_instruction_codet representation of a "return from a function" statement.
exprt to_expr(const object_map_dt::value_type &it) const
void do_end_function(const exprt &lhs, const namespacet &ns)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
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.
static object_numberingt object_numbering
const typet & base_type() const
The type of the data what we point to.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool can_cast_expr< code_inputt >(const exprt &base)
static numberingt< irep_idt > function_numbering
const typet & subtype() const
const code_blockt & to_code_block(const codet &code)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
void get_reference_set_sharing(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
optionalt< mp_integer > offsett
Represents the offset into an object: either a unique integer offset, or an unknown value,...
bool is_null_pointer(const constant_exprt &expr)
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
Operator to return the address of an object.
data_typet::value_type value_type
Semantic type conversion.
const exprt & return_value() const
The Boolean constant true.
bitvector_typet c_index_type()
const code_returnt & to_code_return(const goto_instruction_codet &code)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
void get_reference_set(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
irep_idt name
The unique identifier.
void add_var(const idt &id)
bool insert(object_mapt &dest, const object_map_dt::value_type &it) const
void get_value_set_rec(const exprt &expr, object_mapt &dest, const std::string &suffix, const typet &original_type, const namespacet &ns, gvs_recursion_sett &recursion_set) const
const typet & element_type() const
The type of the elements of the array.
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)