CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boolbv_member.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "boolbv.h"
10
11#include <util/c_types.h>
12#include <util/namespace.h>
13
15 const member_exprt &expr,
16 const bvt &union_bv,
17 const boolbvt &boolbv,
18 const namespacet &ns)
19{
20 const exprt &union_op = expr.compound();
21
23 union_op.type().id() == ID_union_tag
25 : to_union_type(union_op.type());
26
27 const irep_idt &component_name = expr.get_component_name();
29 union_op_type.get_component(component_name);
31 component.is_not_nil(),
32 "union type shall contain component accessed by member expression",
34 id2string(component_name));
35
36 const typet &subtype = component.type();
37 const std::size_t sub_width = boolbv.boolbv_width(subtype);
38
41
42 bvt result(sub_width, literalt{});
43 for(std::size_t i = 0; i < sub_width; ++i)
44 result[map_u.map_bit(i)] = union_bv[map_component.map_bit(i)];
45
46 return result;
47}
48
50{
51 const bvt &compound_bv = convert_bv(expr.compound());
52
53 const typet &compound_type = expr.compound().type();
54
55 if(compound_type.id() == ID_struct_tag || compound_type.id() == ID_struct)
56 {
58 compound_type.id() == ID_struct_tag
59 ? ns.follow_tag(to_struct_tag_type(compound_type))
60 : to_struct_type(compound_type);
61
62 const auto &member_bits =
64
66 member_bits.offset + member_bits.width <= compound_bv.size(),
67 "bitvector part corresponding to element shall be contained within the "
68 "full aggregate bitvector");
69
70 return bvt(
71 compound_bv.begin() + member_bits.offset,
72 compound_bv.begin() + member_bits.offset + member_bits.width);
73 }
74 else
75 {
77 compound_type.id() == ID_union_tag || compound_type.id() == ID_union);
78 return convert_member_union(expr, compound_bv, *this, ns);
79 }
80}
static bvt convert_member_union(const member_exprt &expr, const bvt &union_bv, const boolbvt &boolbv, const namespacet &ns)
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
Definition c_types.h:184
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Definition c_types.h:224
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
const namespacet & ns
Definition arrays.h:56
const membert & get_member(const struct_typet &type, const irep_idt &member) const
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition boolbv.cpp:39
virtual bvt convert_member(const member_exprt &expr)
boolbv_widtht bv_width
Definition boolbv.h:117
virtual endianness_mapt endianness_map(const typet &type, bool little_endian) const
Definition boolbv.h:109
virtual std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:103
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Maps a big-endian offset to a little-endian offset.
Base class for all expressions.
Definition expr.h:56
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition expr.cpp:147
const irep_idt & id() const
Definition irep.h:388
Extract member of struct or union.
Definition std_expr.h:2971
const exprt & compound() const
Definition std_expr.h:3020
irep_idt get_component_name() const
Definition std_expr.h:2993
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition namespace.cpp:49
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Structure type, corresponds to C style structs.
Definition std_types.h:231
The type of an expression, extends irept.
Definition type.h:29
The union type.
Definition c_types.h:147
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
std::vector< literalt > bvt
Definition literal.h:201
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Definition invariant.h:535
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
Definition std_expr.cpp:97
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition std_types.h:308
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition std_types.h:518