29 std::size_t bit_field_bits = 0;
33 if(comp.get_name() == member)
36 if(comp.type().id() == ID_c_bit_field)
40 result += bit_field_bits / 8;
43 else if(comp.type().id() == ID_bool)
46 result += bit_field_bits / 8;
52 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
54 if(!sub_size.has_value())
72 for(
const auto &comp : components)
74 if(comp.get_name()==member)
78 if(!member_bits.has_value())
81 offset += *member_bits;
94 return (*bits + 7) / 8;
102 if(type.
id()==ID_array)
109 const auto size = numeric_cast<mp_integer>(
to_array_type(type).size());
110 if(!size.has_value())
113 return (*sub) * (*size);
115 else if(type.
id()==ID_vector)
125 return (*sub) * size;
127 else if(type.
id()==ID_complex)
136 else if(type.
id()==ID_struct)
143 const typet &subtype = c.type();
146 if(!sub_size.has_value())
154 else if(type.
id()==ID_union)
163 if(widest_member.has_value())
164 return widest_member->second;
168 else if(type.
id()==ID_signedbv ||
169 type.
id()==ID_unsignedbv ||
170 type.
id()==ID_fixedbv ||
171 type.
id()==ID_floatbv ||
173 type.
id()==ID_c_bool ||
174 type.
id()==ID_c_bit_field)
178 else if(type.
id()==ID_c_enum)
182 else if(type.
id()==ID_c_enum_tag)
186 else if(type.
id()==ID_bool)
190 else if(type.
id()==ID_pointer)
198 else if(type.
id() == ID_union_tag)
202 else if(type.
id() == ID_struct_tag)
206 else if(type.
id()==ID_code)
210 else if(type.
id()==ID_string)
223 if(type.
id()==ID_struct)
226 else if(type.
id()==ID_union)
239 std::size_t bit_field_bits=0;
243 if(c.get_name() == member)
246 if(c.type().id() == ID_c_bit_field)
250 const std::size_t bytes = bit_field_bits / 8;
255 else if(c.type().id() == ID_bool)
258 const std::size_t bytes = bit_field_bits / 8;
266 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
267 const typet &subtype = c.type();
269 if(!sub_size.has_value())
271 result =
plus_exprt(result, sub_size.value());
280 if(type.
id()==ID_array)
285 if(array_type.subtype().id() == ID_bool)
302 const auto size_casted =
307 else if(type.
id()==ID_vector)
312 if(vector_type.subtype().id() == ID_bool)
329 const auto size_casted =
334 else if(type.
id()==ID_complex)
343 else if(type.
id()==ID_struct)
348 std::size_t bit_field_bits=0;
352 if(c.type().id() == ID_c_bit_field)
356 const std::size_t bytes = bit_field_bits / 8;
361 else if(c.type().id() == ID_bool)
364 const std::size_t bytes = bit_field_bits / 8;
372 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
373 const typet &subtype = c.type();
375 if(!sub_size_opt.has_value())
378 result =
plus_exprt(result, sub_size_opt.value());
384 else if(type.
id()==ID_union)
395 const typet &subtype = c.type();
400 if(!sub_bits.has_value())
405 if(!sub_size_opt.has_value())
407 sub_size = sub_size_opt.value();
415 if(max_bytes<sub_bytes)
436 else if(type.
id()==ID_signedbv ||
437 type.
id()==ID_unsignedbv ||
438 type.
id()==ID_fixedbv ||
439 type.
id()==ID_floatbv ||
441 type.
id()==ID_c_bool ||
442 type.
id()==ID_c_bit_field)
445 std::size_t bytes=width/8;
450 else if(type.
id()==ID_c_enum)
454 std::size_t bytes=width/8;
459 else if(type.
id()==ID_c_enum_tag)
463 else if(type.
id()==ID_bool)
467 else if(type.
id()==ID_pointer)
474 std::size_t bytes=width/8;
479 else if(type.
id() == ID_union_tag)
483 else if(type.
id() == ID_struct_tag)
487 else if(type.
id()==ID_code)
491 else if(type.
id()==ID_string)
502 if(expr.
id()==ID_symbol)
510 else if(expr.
id()==ID_index)
515 "index into array expected, found " +
525 if(sub_size.has_value() && *sub_size > 0)
527 const auto i = numeric_cast<mp_integer>(index_expr.
index());
529 return (*o) + (*i) * (*sub_size);
535 else if(expr.
id()==ID_member)
545 if(type.
id()==ID_union)
555 else if(expr.
id()==ID_string_constant)
565 static_cast<const typet &
>(expr.
find(ID_C_c_sizeof_type));
571 auto val = numeric_cast<mp_integer>(expr);
574 !type_size.has_value() || *type_size < 0 || !val.has_value() ||
575 *val < *type_size || (*type_size == 0 && *val > 0))
583 "sizeof value does not fit size_type");
589 remainder = *val % *type_size;
594 exprt result(ID_sizeof, t);
595 result.
set(ID_type_arg, type);
608 const typet &target_type_raw,
611 if(offset_bytes == 0 && expr.
type() == target_type_raw)
615 if(expr.
type() != target_type_raw)
616 result.
type() = target_type_raw;
622 offset_bytes == 0 && expr.
type().
id() == ID_pointer &&
623 target_type_raw.
id() == ID_pointer)
630 if(!target_size_bits.has_value())
633 if(source_type.
id()==ID_struct)
641 if(!m_size_bits.has_value())
647 offset_bytes * 8 >= m_offset_bits && m_offset_bits % 8 == 0 &&
648 offset_bytes * 8 + *target_size_bits <= m_offset_bits + *m_size_bits)
652 member, offset_bytes - m_offset_bits / 8, target_type_raw, ns);
655 m_offset_bits += *m_size_bits;
658 else if(source_type.
id()==ID_array)
666 elem_size_bits.has_value() && *elem_size_bits > 0 &&
667 *elem_size_bits % 8 == 0 && *target_size_bits <= *elem_size_bits)
669 const mp_integer elem_size_bytes = *elem_size_bits / 8;
670 const auto offset_inside_elem = offset_bytes % elem_size_bytes;
671 const auto target_size_bytes = *target_size_bits / 8;
673 if(offset_inside_elem + target_size_bytes <= elem_size_bytes)
695 const typet &target_type,
698 const auto offset_bytes = numeric_cast<mp_integer>(offset);
700 if(!offset_bytes.has_value())
Expression classes for byte-level operators.
bitvector_typet index_type()
unsignedbv_typet size_type()
A base class for relations, i.e., binary predicates whose two operands have the same type.
std::size_t get_width() const
A constant literal expression.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
typet & type()
Return the type of the expression.
std::size_t size() const
Amount of nodes this expression tree contains.
The trinary if-then-else operator.
void set(const irep_namet &name, const irep_idt &value)
bool get_bool(const irep_namet &name) const
const irept & find(const irep_namet &name) const
const std::string & id_string() const
const irep_idt & id() const
Extract member of struct or union.
const exprt & struct_op() const
irep_idt get_component_name() const
Binary multiplication Associativity is not specified.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
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...
The plus expression Associativity is not specified.
Structure type, corresponds to C style structs.
Base type for structs and unions.
const componentst & components() const
std::vector< componentt > componentst
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
const typet & subtype() const
optionalt< std::pair< struct_union_typet::componentt, mp_integer > > find_widest_union_component(const namespacet &ns) const
Determine the member of maximum bit width in a union type.
const constant_exprt & size() const
nonstd::optional< T > optionalt
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
optionalt< mp_integer > member_offset_bits(const struct_typet &type, const irep_idt &member, const namespacet &ns)
optionalt< exprt > get_subexpression_at_offset(const exprt &expr, const mp_integer &offset_bytes, const typet &target_type_raw, const namespacet &ns)
optionalt< mp_integer > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
optionalt< mp_integer > compute_pointer_offset(const exprt &expr, const namespacet &ns)
optionalt< exprt > build_sizeof_expr(const constant_exprt &expr, const namespacet &ns)
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
optionalt< exprt > member_offset_expr(const member_exprt &member_expr, const namespacet &ns)
bool simplify(exprt &expr, const namespacet &ns)
exprt simplify_expr(exprt src, const namespacet &ns)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
bool is_ssa_expr(const exprt &expr)
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
API to expression classes.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_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 bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_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 array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_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.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
irep_idt byte_extract_id()