34 exprt::operandst::const_iterator next_it=it;
37 if(next_it!=operands.end() && *next_it < *it)
47 std::sort(operands.begin(), operands.end());
67 { ID_plus, {ID_integer ,
76 { ID_mult, {ID_integer ,
91 { ID_bitand, {ID_unsignedbv ,
96 { ID_bitor, {ID_unsignedbv ,
101 { ID_bitxor, {ID_unsignedbv ,
138 bool no_change =
true;
150 for(
const auto &op :
as_const(expr).operands())
159 new_ops.reserve(
as_const(expr).operands().size());
161 for(
const auto &op :
as_const(expr).operands())
163 if(op.id() == expr.
id())
165 new_ops.reserve(new_ops.capacity() + op.operands().size() - 1);
167 for(
const auto &sub_op : op.operands())
168 new_ops.push_back(sub_op);
173 new_ops.push_back(op);
197 const std::string &bits,
206 !type_bits.has_value() ||
207 (type.
id() != ID_union && type.
id() != ID_union_tag &&
208 *type_bits != bits.
size()) ||
209 ((type.
id() == ID_union || type.
id() == ID_union_tag) &&
210 *type_bits < bits.size()))
216 type.
id() == ID_unsignedbv || type.
id() == ID_signedbv ||
217 type.
id() == ID_floatbv || type.
id() == ID_fixedbv ||
218 type.
id() == ID_c_bit_field || type.
id() == ID_pointer ||
219 type.
id() == ID_bv || type.
id() == ID_c_bool)
223 bits.find(
'1') == std::string::npos)
230 std::string tmp = bits;
234 std::reverse(tmp.begin(), tmp.end());
239 else if(type.
id() == ID_c_enum)
251 else if(type.
id() == ID_c_enum_tag)
263 else if(type.
id() == ID_union)
269 if(components.empty() && bits.empty())
281 else if(type.
id() == ID_union_tag)
293 else if(type.
id() == ID_struct)
307 std::string comp_bits = std::string(
309 numeric_cast_v<std::size_t>(m_offset_bits),
310 numeric_cast_v<std::size_t>(*m_size));
313 if(!comp.has_value())
315 result.add_to_operands(std::move(*comp));
317 m_offset_bits += *m_size;
320 return std::move(result);
322 else if(type.
id() == ID_struct_tag)
334 else if(type.
id() == ID_array)
337 const auto &size_expr = array_type.
size();
341 const std::size_t number_of_elements =
345 CHECK_RETURN(el_size_opt.has_value() && *el_size_opt > 0);
347 const std::size_t el_size = numeric_cast_v<std::size_t>(*el_size_opt);
352 for(std::size_t i = 0; i < number_of_elements; ++i)
354 std::string el_bits = std::string(bits, i * el_size, el_size);
359 result.add_to_operands(std::move(*el));
362 return std::move(result);
364 else if(type.
id() == ID_vector)
368 const std::size_t n_el = numeric_cast_v<std::size_t>(vector_type.
size());
370 const auto el_size_opt =
372 CHECK_RETURN(el_size_opt.has_value() && *el_size_opt > 0);
374 const std::size_t el_size = numeric_cast_v<std::size_t>(*el_size_opt);
379 for(std::size_t i = 0; i < n_el; ++i)
381 std::string el_bits = std::string(bits, i * el_size, el_size);
386 result.add_to_operands(std::move(*el));
389 return std::move(result);
391 else if(type.
id() == ID_complex)
396 CHECK_RETURN(sub_size_opt.has_value() && *sub_size_opt > 0);
398 const std::size_t sub_size = numeric_cast_v<std::size_t>(*sub_size_opt);
401 bits.substr(0, sub_size), complex_type.
subtype(), little_endian, ns);
403 bits.substr(sub_size), complex_type.
subtype(), little_endian, ns);
404 if(!real.has_value() || !imag.has_value())
413 std::optional<std::string>
424 type.
id() == ID_unsignedbv || type.
id() == ID_signedbv ||
425 type.
id() == ID_floatbv || type.
id() == ID_fixedbv ||
426 type.
id() == ID_c_bit_field || type.
id() == ID_bv ||
427 type.
id() == ID_c_bool)
433 std::string result(width,
' ');
440 else if(type.
id() == ID_pointer)
447 else if(type.
id() == ID_c_enum_tag)
452 else if(type.
id() == ID_c_enum)
460 else if(expr.
id() == ID_string_constant)
465 else if(expr.
id() == ID_union)
470 expr.
id() == ID_struct || expr.
id() == ID_array || expr.
id() == ID_vector ||
471 expr.
id() == ID_complex)
474 for(
const auto &op : expr.
operands())
476 auto tmp =
expr2bits(op, little_endian, ns);
479 result += tmp.value();
488 std::optional<std::reference_wrapper<const array_exprt>>
491 if(content.
id() != ID_address_of)
498 if(array_pointer.object().id() != ID_index)
503 const auto &array_start =
to_index_expr(array_pointer.object());
506 array_start.array().id() != ID_symbol ||
507 array_start.array().type().id() != ID_array)
514 const symbolt *symbol_ptr =
nullptr;
517 ns.
lookup(array.get_identifier(), symbol_ptr) ||
518 symbol_ptr->
value.
id() != ID_array)
525 return std::optional<std::reference_wrapper<const array_exprt>>(char_seq);
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
Array constructor from list of elements.
const typet & element_type() const
The type of the elements of the array.
const exprt & size() const
std::size_t get_width() const
Complex constructor from a pair of numbers.
Complex numbers made of pair of given subtype.
struct configt::ansi_ct ansi_c
A constant literal expression.
const irep_idt & get_value() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Union constructor to support unions without any member (a GCC/Clang feature).
Maps a big-endian offset to a little-endian offset.
size_t map_bit(size_t bit) const
Base class for all expressions.
std::vector< exprt > operandst
bool has_operands() const
Return true if there is at least one operand.
void reserve_operands(operandst::size_type n)
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
const irep_idt & id() const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The null pointer constant.
Struct constructor from list of elements.
Structure type, corresponds to C style structs.
const componentst & components() const
std::vector< componentt > componentst
exprt value
Initial value of symbol.
const typet & subtype() const
The type of an expression, extends irept.
Union constructor from single element.
Vector constructor from list of elements.
const constant_exprt & size() const
const typet & element_type() const
The type of the elements of the vector.
#define forall_expr(it, expr)
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...
Deprecated expression utility functions.
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
std::optional< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
struct saj_tablet saj_table[]
bool sort_operands(exprt::operandst &operands)
sort operands of an expression according to ordering defined by operator<
std::optional< std::reference_wrapper< const array_exprt > > try_get_string_data_array(const exprt &content, const namespacet &ns)
Get char sequence from content field of a refined string expression.
static const struct saj_tablet & get_sort_and_join_table_entry(const irep_idt &id, const irep_idt &type_id)
static bool is_associative_and_commutative_for_type(const struct saj_tablet &saj_entry, const irep_idt &type_id)
std::optional< std::string > expr2bits(const exprt &expr, bool little_endian, const namespacet &ns)
std::optional< exprt > bits2expr(const std::string &bits, const typet &type, bool little_endian, const namespacet &ns)
static bool sort_and_join(exprt &expr, bool do_sort)
bool join_operands(exprt &expr)
#define CHECK_RETURN(CONDITION)
#define PRECONDITION(CONDITION)
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
API to expression classes.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
const union_exprt & to_union_expr(const exprt &expr)
Cast an exprt to a union_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const string_constantt & to_string_constant(const exprt &expr)
produce canonical ordering for associative and commutative binary operators
const irep_idt type_ids[10]