35 const exprt &init_expr)
46 const exprt &init_expr);
52 const exprt &init_expr)
56 if(type_id==ID_unsignedbv ||
57 type_id==ID_signedbv ||
58 type_id==ID_pointer ||
60 type_id==ID_c_bit_field ||
63 type_id==ID_floatbv ||
67 if(init_expr.
id() == ID_nondet)
77 else if(type_id==ID_rational ||
81 if(init_expr.
id() == ID_nondet)
91 else if(type_id==ID_verilog_signedbv ||
92 type_id==ID_verilog_unsignedbv)
95 if(init_expr.
id() == ID_nondet)
100 std::string value(width,
'0');
110 else if(type_id==ID_complex)
113 if(init_expr.
id() == ID_nondet)
119 if(!sub_zero.has_value())
130 else if(type_id==ID_array)
140 value.add_source_location()=source_location;
141 return std::move(value);
147 if(!tmpval.has_value())
150 const auto array_size = numeric_cast<mp_integer>(array_type.
size());
152 array_type.
size().
id() == ID_infinity || !array_size.has_value() ||
155 if(init_expr.
id() == ID_nondet)
160 return std::move(value);
168 numeric_cast_v<std::size_t>(*array_size), *tmpval);
169 value.add_source_location()=source_location;
170 return std::move(value);
173 else if(type_id==ID_vector)
178 vector_type.
element_type(), source_location, init_expr);
179 if(!tmpval.has_value())
183 numeric_cast_v<mp_integer>(vector_type.
size());
189 value.
operands().resize(numeric_cast_v<std::size_t>(vector_size), *tmpval);
190 value.add_source_location()=source_location;
192 return std::move(value);
194 else if(type_id==ID_struct)
201 value.
operands().reserve(components.size());
203 for(
const auto &c : components)
206 c.type().id() != ID_code,
"struct member must not be of code type");
210 if(!member.has_value())
213 value.add_to_operands(std::move(*member));
216 value.add_source_location()=source_location;
218 return std::move(value);
220 else if(type_id==ID_union)
228 return std::move(value);
232 if(!widest_member.has_value())
236 widest_member->first.type(), source_location, init_expr);
238 if(!component_value.has_value())
241 union_exprt value{widest_member->first.get_name(), *component_value, type};
244 return std::move(value);
246 else if(type_id==ID_c_enum_tag)
251 if(!result.has_value())
255 result->type() = type;
259 else if(type_id==ID_struct_tag)
264 if(!result.has_value())
268 result->type() = type;
272 else if(type_id==ID_union_tag)
277 if(!result.has_value())
281 result->type() = type;
285 else if(type_id==ID_string)
288 if(init_expr.
id() == ID_nondet)
344 const exprt &init_byte_expr)
357 if(expr.
type() == out_type)
382 const exprt &init_byte_expr,
383 const typet &output_type,
386 const auto init_type_as_bitvector =
387 type_try_dynamic_cast<bitvector_typet>(init_byte_expr.
type());
390 (init_type_as_bitvector &&
392 init_byte_expr.
type().
id() == ID_bool);
395 const auto simplified_init_expr =
simplify_expr(init_byte_expr, ns);
396 if(
const auto output_bv = type_try_dynamic_cast<bitvector_typet>(output_type))
398 const auto out_width = output_bv->get_width();
403 if(simplified_init_expr.is_constant())
405 const auto init_size = init_type_as_bitvector->get_width();
412 const auto output_value =
413 make_bvrep(out_width, [&init_size, &init_value](std::size_t index) {
417 return source_index < init_size &&
443 values.push_back(casted_init_byte_expr);
444 for(
size_t i = 1; i < size; ++i)
447 casted_init_byte_expr,
451 values.size() == 1 ? values[0]
API to expression classes for bitvectors.
bool can_cast_type< signedbv_typet >(const typet &type)
Check whether a reference to a typet is a signedbv_typet.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
bool can_cast_type< unsignedbv_typet >(const typet &type)
Check whether a reference to a typet is a unsignedbv_typet.
byte_extract_exprt make_byte_extract(const exprt &_op, const exprt &_offset, const typet &_type)
Construct a byte_extract_exprt with endianness and byte width matching the current configuration.
Expression classes for byte-level operators.
bitvector_typet char_type()
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 array_typet & type() const
Array constructor from single element.
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.
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).
std::optional< exprt > expr_initializer_rec(const typet &type, const source_locationt &source_location, const exprt &init_expr)
std::optional< exprt > operator()(const typet &type, const source_locationt &source_location, const exprt &init_expr)
expr_initializert(const namespacet &_ns)
Base class for all expressions.
std::vector< exprt > operandst
source_locationt & add_source_location()
bool is_zero() const
Return whether the expression is a constant representing 0.
typet & type()
Return the type of the expression.
const irep_idt & id() const
A base class for multi-ary expressions Associativity is not specified.
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...
A side_effect_exprt that returns a non-deterministically chosen value.
Struct constructor from list of elements.
const componentst & components() const
std::vector< componentt > componentst
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
source_locationt & add_source_location()
Union constructor from single element.
std::optional< 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.
Fixed-width bit-vector with unsigned binary interpretation.
Vector constructor from list of elements.
const constant_exprt & size() const
const typet & element_type() const
The type of the elements of the vector.
exprt duplicate_per_byte(const exprt &init_byte_expr, const typet &output_type, const namespacet &ns)
Builds an expression of the given output type with each of its bytes initialized to the given initial...
static exprt cast_or_reinterpret(const exprt &expr, const typet &out_type)
Typecast the input to the output if this is a signed/unsigned bv.
std::optional< exprt > nondet_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create a non-deterministic value for type type, with all subtypes independently expanded as non-deter...
std::optional< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
std::optional< exprt > expr_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns, const exprt &init_byte_expr)
Create a value for type type, with all subtype bytes initialized to the given value.
Expression Initialization.
Magic numbers used throughout the codebase.
const std::size_t MAX_FLATTENED_ARRAY_SIZE
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 constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_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.