30 std::size_t bit_field_bits = 0;
34 if(comp.get_name() == member)
37 if(comp.type().id() == ID_c_bit_field)
41 result += bit_field_bits / 8;
44 else if(comp.type().id() == ID_bool)
47 result += bit_field_bits / 8;
53 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
55 if(!sub_size.has_value())
73 for(
const auto &comp : components)
75 if(comp.get_name()==member)
79 if(!member_bits.has_value())
82 offset += *member_bits;
95 return (*bits + 7) / 8;
103 if(type.
id()==ID_array)
111 if(!size.has_value())
114 return (*sub) * (*size);
116 else if(type.
id()==ID_vector)
126 return (*sub) * size;
128 else if(type.
id()==ID_complex)
137 else if(type.
id()==ID_struct)
144 const typet &subtype = c.type();
147 if(!sub_size.has_value())
155 else if(type.
id()==ID_union)
164 const typet &subtype = c.type();
167 if(!sub_size.has_value())
170 if(*sub_size > result)
176 else if(type.
id()==ID_signedbv ||
177 type.
id()==ID_unsignedbv ||
178 type.
id()==ID_fixedbv ||
179 type.
id()==ID_floatbv ||
181 type.
id()==ID_c_bool ||
182 type.
id()==ID_c_bit_field)
186 else if(type.
id()==ID_c_enum)
190 else if(type.
id()==ID_c_enum_tag)
194 else if(type.
id()==ID_bool)
198 else if(type.
id()==ID_pointer)
206 else if(type.
id() == ID_symbol_type)
210 else if(type.
id() == ID_union_tag)
214 else if(type.
id() == ID_struct_tag)
218 else if(type.
id()==ID_code)
222 else if(type.
id()==ID_string)
236 if(type.
id()==ID_struct)
239 else if(type.
id()==ID_union)
251 std::size_t bit_field_bits=0;
255 if(c.get_name() == member)
258 if(c.type().id() == ID_c_bit_field)
262 const std::size_t bytes = bit_field_bits / 8;
267 else if(c.type().id() == ID_bool)
270 const std::size_t bytes = bit_field_bits / 8;
278 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
279 const typet &subtype = c.type();
296 if(type.
id()==ID_array)
301 if(array_type.subtype().id() == ID_bool)
314 exprt size = array_type.size();
325 return std::move(result);
327 else if(type.
id()==ID_vector)
332 if(vector_type.subtype().id() == ID_bool)
356 return std::move(result);
358 else if(type.
id()==ID_complex)
369 return std::move(result);
371 else if(type.
id()==ID_struct)
376 std::size_t bit_field_bits=0;
380 if(c.type().id() == ID_c_bit_field)
384 const std::size_t bytes = bit_field_bits / 8;
389 else if(c.type().id() == ID_bool)
392 const std::size_t bytes = bit_field_bits / 8;
400 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
401 const typet &subtype = c.type();
414 else if(type.
id()==ID_union)
425 const typet &subtype = c.type();
430 if(!sub_bits.has_value())
444 if(max_bytes<sub_bytes)
465 else if(type.
id()==ID_signedbv ||
466 type.
id()==ID_unsignedbv ||
467 type.
id()==ID_fixedbv ||
468 type.
id()==ID_floatbv ||
470 type.
id()==ID_c_bool ||
471 type.
id()==ID_c_bit_field)
474 std::size_t bytes=width/8;
479 else if(type.
id()==ID_c_enum)
483 std::size_t bytes=width/8;
488 else if(type.
id()==ID_c_enum_tag)
492 else if(type.
id()==ID_bool)
496 else if(type.
id()==ID_pointer)
503 std::size_t bytes=width/8;
508 else if(type.
id() == ID_symbol_type)
512 else if(type.
id() == ID_union_tag)
516 else if(type.
id() == ID_struct_tag)
520 else if(type.
id()==ID_code)
524 else if(type.
id()==ID_string)
535 if(expr.
id()==ID_symbol)
543 else if(expr.
id()==ID_index)
548 "index into array expected, found " +
558 if(sub_size.has_value() && *sub_size > 0)
562 return (*o) + (*i) * (*sub_size);
568 else if(expr.
id()==ID_member)
578 if(type.
id()==ID_union)
588 else if(expr.
id()==ID_string_constant)
599 static_cast<const typet &
>(expr.
find(ID_C_c_sizeof_type));
608 !type_size.has_value() || *type_size < 0 || !val.has_value() ||
609 *val < *type_size || (*type_size == 0 && *val > 0))
617 "sizeof value does not fit size_type");
623 remainder = *val % *type_size;
628 exprt result(ID_sizeof, t);
629 result.
set(ID_type_arg, type);
645 const typet &target_type_raw,
652 if(expr.
type() != target_type_raw)
653 result.
type() = target_type_raw;
659 offset_bytes == 0 && expr.
type().
id() == ID_pointer &&
660 target_type_raw.
id() == ID_pointer)
667 if(!target_size_bits.has_value())
670 if(source_type.
id()==ID_struct)
678 if(!m_size_bits.has_value())
684 offset_bytes * 8 >= m_offset_bits && m_offset_bits % 8 == 0 &&
685 offset_bytes * 8 + *target_size_bits <= m_offset_bits + *m_size_bits)
689 member, offset_bytes - m_offset_bits / 8, target_type_raw, ns);
692 m_offset_bits += *m_size_bits;
695 else if(source_type.
id()==ID_array)
703 !elem_size_bits.has_value() || *elem_size_bits == 0 ||
704 *elem_size_bits % 8 != 0)
709 if(*target_size_bits <= *elem_size_bits)
711 const mp_integer elem_size_bytes = *elem_size_bits / 8;
715 offset_bytes % elem_size_bytes,
731 const typet &target_type,
736 if(!offset_bytes.has_value())
The type of an expression, extends irept.
exprt size_of_expr(const typet &type, const namespacet &ns)
Semantic type conversion.
exprt member_offset_expr(const member_exprt &member_expr, const namespacet &ns)
A base class for relations, i.e., binary predicates.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
bool base_type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Check types for equality across all levels of hierarchy.
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
optionalt< mp_integer > member_offset_bits(const struct_typet &type, const irep_idt &member, const namespacet &ns)
std::vector< componentt > componentst
exprt build_sizeof_expr(const constant_exprt &expr, const namespacet &ns)
const componentst & components() const
The trinary if-then-else operator.
typet & type()
Return the type of the expression.
unsignedbv_typet size_type()
A constant literal expression.
Structure type, corresponds to C style structs.
bool get_bool(const irep_namet &name) const
const typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Extract member of struct or union.
const irep_idt & id() const
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
Expression classes for byte-level operators.
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.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
nonstd::optional< T > optionalt
API to expression classes.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const exprt & size() const
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const exprt & size() const
The plus expression Associativity is not specified.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
bitvector_typet index_type()
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
std::size_t get_width() const
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
Binary multiplication Associativity is not specified.
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
Base type for structs and unions.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Base class for all expressions.
const exprt & struct_op() const
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
optionalt< mp_integer > compute_pointer_offset(const exprt &expr, const namespacet &ns)
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const exprt & get_original_expr() const
irep_idt get_component_name() const
bool is_ssa_expr(const exprt &expr)
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const std::string & id_string() const
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
const typet & subtype() const
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions, goto_programs, exprts, etc.
void make_typecast(const typet &_type)
Create a typecast_exprt to the given type.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const irept & find(const irep_namet &name) const
void set(const irep_namet &name, const irep_idt &value)
bool simplify(exprt &expr, const namespacet &ns)
irep_idt byte_extract_id()