24 throw "update: unexpected operand 0 width";
38 const exprt &new_value,
41 if(d>=designators.size())
47 if(new_value_width!=new_value_bv.size())
48 throw "convert_update_rec: unexpected new_value size";
51 for(std::size_t i=0; i<new_value_width; i++)
53 DATA_INVARIANT(offset + i < bv.size(),
"update must be in bounds");
54 bv[offset+i]=new_value_bv[i];
60 const exprt &designator=designators[d];
62 if(designator.
id()==ID_index_designator)
64 if(type.
id()!=ID_array)
65 throw "update: index designator needs array";
68 throw "update: index designator takes one operand";
74 const exprt &size_expr = array_type.
size();
80 "array in update expression should be constant-sized");
83 const std::size_t size =
88 for(std::size_t i = 0; i != size; ++i)
90 std::size_t new_offset=offset+i*element_size;
93 designators, d+1, subtype, new_offset, new_value, tmp_bv);
98 for(std::size_t j=0; j<element_size; j++)
100 std::size_t idx=new_offset+j;
106 else if(designator.
id()==ID_member_designator)
108 const irep_idt &component_name=designator.
get(ID_component_name);
110 if(type.
id() == ID_struct || type.
id() == ID_struct_tag)
116 std::size_t struct_offset=0;
124 for(
const auto &c : components)
126 const typet &subtype = c.type();
129 if(c.get_name() == component_name)
135 struct_offset+=sub_width;
139 throw "update: failed to find struct component";
143 std::size_t new_offset=offset+struct_offset;
147 designators, d+1, new_type, new_offset, new_value, bv);
149 else if(type.
id() == ID_union || type.
id() == ID_union_tag)
159 throw "update: failed to find union component";
167 designators, d+1, new_type, offset, new_value, bv);
170 throw "update: member designator needs struct or union";
173 throw "update: unexpected designator";
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 typet & element_type() const
The type of the elements of the array.
const exprt & size() 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...
void convert_update_rec(const exprt::operandst &designator, std::size_t d, const typet &type, std::size_t offset, const exprt &new_value, bvt &bv)
virtual bvt convert_update(const update_exprt &)
virtual std::size_t boolbv_width(const typet &type) const
static bvt build_constant(const mp_integer &i, std::size_t width)
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
const irep_idt & get(const irep_idt &name) const
const irep_idt & id() const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
virtual literalt lselect(literalt a, literalt b, literalt c)=0
Structure type, corresponds to C style structs.
const componentt & get_component(const irep_idt &component_name) const
Get the reference to a component with given name.
const componentst & components() const
std::vector< componentt > componentst
The type of an expression, extends irept.
Operator to update elements in structs and arrays.
std::vector< literalt > bvt
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
const index_designatort & to_index_designator(const exprt &expr)
Cast an exprt to an index_designatort.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
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 struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.