Go to the documentation of this file.
38 error() <<
"expected type as initializer for '" << symbol.
base_name <<
"'"
56 <<
"' is declared as reference but is not initialized" <<
eom;
82 symbol.
type.
id() == ID_pointer &&
84 symbol.
value.
id() == ID_address_of &&
97 for(
const auto ¶meter : code_type.
parameters())
99 exprt new_object(ID_new_object, parameter.type());
100 new_object.
set(ID_C_lvalue,
true);
102 if(parameter.get_this())
108 fargs.
operands.push_back(new_object);
119 "symbol type must match");
121 if(resolved_expr.
id()==ID_symbol)
126 else if(resolved_expr.
id()==ID_member)
130 lookup(resolved_expr.
get(ID_component_name)).symbol_expr());
154 if(symbol.
value.
id()==ID_initializer_list ||
155 symbol.
value.
id()==ID_string_constant)
186 ops.push_back(symbol.
value);
191 if(constructor.has_value())
192 symbol.
value = constructor.value();
206 if(final_type.
id()==ID_struct)
210 if(struct_type.is_incomplete())
213 error() <<
"cannot zero-initialize incomplete struct" <<
eom;
217 for(
const auto &
component : struct_type.components())
235 final_type.
id() == ID_array &&
239 const exprt &size_expr=array_type.
size();
241 if(size_expr.
id()==ID_infinity)
256 else if(final_type.
id()==ID_union)
260 if(union_type.is_incomplete())
263 error() <<
"cannot zero-initialize incomplete union" <<
eom;
272 for(
const auto &
component : union_type.components())
281 const auto size_int =
282 numeric_cast<mp_integer>(component_size_opt.value_or(
nil_exprt()));
283 if(size_int.has_value())
285 if(*size_int > max_comp_size)
287 max_comp_size = *size_int;
297 exprt member(ID_member);
299 member.
set(ID_component_cpp_name, cpp_name);
303 else if(final_type.
id()==ID_c_enum)
319 assign.
lhs().
type().
set(ID_C_constant,
false);
323 ops.push_back(assign);
328 if(!value.has_value())
331 error() <<
"cannot zero-initialize '" <<
to_string(final_type) <<
"'"
340 assign.
lhs().
type().
set(ID_C_constant,
false);
344 ops.push_back(assign);
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
#define UNREACHABLE
This should be used to mark dead code.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
static exprt conditional_cast(const exprt &expr, const typet &type)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
const irept & find(const irep_idt &name) const
typet type
Type of symbol.
exprt::operandst operands
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
Base class for all expressions.
optionalt< codet > cpp_constructor(const source_locationt &source_location, const exprt &object, const exprt::operandst &operands)
irep_idt base_name
Base (non-scoped) name.
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
void zero_initializer(const exprt &object, const typet &type, const source_locationt &source_location, exprt::operandst &ops)
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
Expression to hold a symbol (variable)
Fixed-width bit-vector with unsigned binary interpretation.
const irep_idt & get(const irep_idt &name) const
const exprt & size() const
bool cpp_is_pod(const typet &type) const
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void typecheck_type(typet &) override
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
static void make_already_typechecked(exprt &expr)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
void convert_initializer(symbolt &symbol)
Initialize an object with a value.
const exprt & compound() const
source_locationt source_location
void reference_initializer(exprt &expr, const typet &type)
A reference to type "cv1 T1" is initialized by an expression of type "cv2 T2" as follows:
void set(const irep_idt &name, const irep_idt &value)
bool simplify(exprt &expr, const namespacet &ns)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
A codet representing an assignment in the program.
const irep_idt & id() const
std::vector< exprt > operandst
const parameterst & parameters() const
Extract member of struct or union.
void typecheck_expr(exprt &) override
exprt value
Initial value of symbol.
message_handlert & get_message_handler()
bool is_reference(const typet &type)
Returns true if the type is a reference.
irept & add(const irep_idt &name)
void typecheck_code(codet &) override
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
source_locationt location
Source code location of definition of symbol.
static bool has_auto(const typet &type)
const typet & base_type() const
The type of the data what we point to.
void implicit_typecast(exprt &expr, const typet &type) override
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
void cpp_convert_auto(typet &dest, const typet &src, message_handlert &message_handler)
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
std::string to_string(const typet &) override
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
Operator to return the address of an object.
source_locationt & add_source_location()
const irep_idt & get_base_name() const
exprt resolve(const cpp_namet &cpp_name, const cpp_typecheck_resolvet::wantt want, const cpp_typecheck_fargst &fargs, bool fail_with_exception=true)
bitvector_typet c_index_type()
const source_locationt & source_location() const
irep_idt name
The unique identifier.
cpp_namet & to_cpp_name(irept &cpp_name)
const typet & element_type() const
The type of the elements of the array.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.