Go to the documentation of this file.
21 template <
bool nondet>
43 template <
bool nondet>
50 if(type_id==ID_unsignedbv ||
51 type_id==ID_signedbv ||
52 type_id==ID_pointer ||
54 type_id==ID_c_bit_field ||
57 type_id==ID_floatbv ||
69 else if(type_id==ID_rational ||
81 else if(type_id==ID_verilog_signedbv ||
82 type_id==ID_verilog_unsignedbv)
90 std::string value(width,
'0');
98 else if(type_id==ID_complex)
106 expr_initializer_rec(
to_complex_type(type).subtype(), source_location);
107 if(!sub_zero.has_value())
116 else if(type_id==ID_array)
126 value.add_source_location()=source_location;
127 return std::move(value);
132 expr_initializer_rec(array_type.
element_type(), source_location);
133 if(!tmpval.has_value())
136 const auto array_size = numeric_cast<mp_integer>(array_type.
size());
138 array_type.
size().
id() == ID_infinity || !array_size.has_value() ||
146 return std::move(value);
154 numeric_cast_v<std::size_t>(*array_size), *tmpval);
155 value.add_source_location()=source_location;
156 return std::move(value);
159 else if(type_id==ID_vector)
164 expr_initializer_rec(vector_type.
element_type(), source_location);
165 if(!tmpval.has_value())
169 numeric_cast_v<mp_integer>(vector_type.
size());
175 value.
operands().resize(numeric_cast_v<std::size_t>(vector_size), *tmpval);
176 value.add_source_location()=source_location;
178 return std::move(value);
180 else if(type_id==ID_struct)
187 value.
operands().reserve(components.size());
189 for(
const auto &c : components)
191 if(c.type().id() == ID_code)
195 value.add_to_operands(std::move(code_value));
199 const auto member = expr_initializer_rec(c.type(), source_location);
200 if(!member.has_value())
203 value.add_to_operands(std::move(*member));
207 value.add_source_location()=source_location;
209 return std::move(value);
211 else if(type_id==ID_union)
219 return std::move(value);
223 if(!widest_member.has_value())
226 auto component_value =
227 expr_initializer_rec(widest_member->first.type(), source_location);
229 if(!component_value.has_value())
232 union_exprt value{widest_member->first.get_name(), *component_value, type};
235 return std::move(value);
237 else if(type_id==ID_c_enum_tag)
239 auto result = expr_initializer_rec(
242 if(!result.has_value())
246 result->type() = type;
250 else if(type_id==ID_struct_tag)
252 auto result = expr_initializer_rec(
255 if(!result.has_value())
259 result->type() = type;
263 else if(type_id==ID_union_tag)
265 auto result = expr_initializer_rec(
268 if(!result.has_value())
272 result->type() = type;
276 else if(type_id==ID_string)
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
optionalt< exprt > operator()(const typet &type, const source_locationt &source_location)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
The type of an expression, extends irept.
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
const std::size_t MAX_FLATTENED_ARRAY_SIZE
optionalt< 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...
Union constructor from single element.
Base class for all expressions.
std::vector< componentt > componentst
Vector constructor from list of elements.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
Magic numbers used throughout the codebase.
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
Struct constructor from list of elements.
const exprt & size() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const array_typet & type() const
const typet & element_type() const
The type of the elements of the vector.
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 single element.
expr_initializert(const namespacet &_ns)
const irep_idt & id() const
Union constructor to support unions without any member (a GCC/Clang feature).
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Complex constructor from a pair of numbers.
source_locationt & add_source_location()
nonstd::optional< T > optionalt
std::size_t get_width() const
A side_effect_exprt that returns a non-deterministically chosen value.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
optionalt< exprt > expr_initializer_rec(const typet &type, const source_locationt &source_location)
source_locationt & add_source_location()
unsignedbv_typet size_type()
A constant literal expression.
Array constructor from list of elements.
const typet & element_type() const
The type of the elements of the array.