Go to the documentation of this file.
42 op1.
type().
set(ID_C_reference,
true);
64 cpp_namet op0(member_base_name, source_location);
67 op1.
add(ID_component_cpp_name,
cpp_namet(member_base_name, source_location));
96 const cpp_namet array(member_base_name, source_location);
98 exprt member(ID_member);
100 ID_component_cpp_name,
cpp_namet(member_base_name, source_location));
134 ctor.
type().
id(ID_constructor);
135 ctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
156 std::string param_identifier(
"ref");
162 const cpp_namet cpp_parameter(param_identifier, source_location);
167 parameter_tor.
set(ID_name, cpp_parameter);
173 parameter_decl.
set(ID_type, ID_merged_type);
175 sub.push_back(cppcomp.
as_type());
176 irept constnd(ID_const);
177 sub.push_back(
static_cast<const typet &
>(constnd));
182 decl0.
add(ID_type).
add(ID_parameters).
get_sub().push_back(parameter_decl);
185 irept &initializers=decl0.
add(ID_member_initializers);
186 initializers.
id(ID_member_initializers);
195 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
206 const cpp_namet cppname(ctor_name, source_location);
208 codet mem_init(ID_member_initializer);
210 mem_init.
set(ID_member, cppname);
220 for(
const auto &mem_c : components)
223 if(mem_c.get_bool(ID_is_vtptr))
225 const cpp_namet cppname(mem_c.get_base_name(), source_location);
227 const symbolt &virtual_table_symbol_type =
228 lookup(mem_c.type().subtype().get(ID_identifier));
236 assert(address.
type() == mem_c.type());
240 exprt ptrmember(ID_ptrmember);
241 ptrmember.
set(ID_component_name, mem_c.get_name());
250 mem_c.get_bool(ID_from_base) || mem_c.get_bool(ID_is_type) ||
251 mem_c.get_bool(ID_is_static) || mem_c.type().id() == ID_code)
256 const irep_idt &mem_name = mem_c.get_base_name();
258 const cpp_namet cppname(mem_name, source_location);
260 codet mem_init(ID_member_initializer);
261 mem_init.
set(ID_member, cppname);
264 exprt memberexpr(ID_member);
265 memberexpr.
set(ID_component_cpp_name, cppname);
269 if(mem_c.type().id() == ID_array)
270 memberexpr.
set(ID_C_array_ini,
true);
290 std::string arg_name(
"ref");
292 cpctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
293 cpctor.
type().
id(ID_struct_tag);
303 typet &declarator_type=declarator.
type();
307 declarator_name.
id(ID_cpp_name);
308 declarator_name.
get_sub().push_back(
irept(ID_operator));
311 declarator_type.
id(ID_function_type);
325 args_decl.
type().
id(ID_merged_type);
326 args_decl_type_sub.push_back(
329 args_decl_type_sub.push_back(
typet(ID_const));
336 args_decl_declor.
name() =
cpp_namet(arg_name, source_location);
340 args_decl_declor.
type().
set(ID_C_reference,
true);
355 std::string arg_name(
"ref");
360 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
371 c.get_bool(ID_from_base) || c.get_bool(ID_is_type) ||
372 c.get_bool(ID_is_static) || c.get_bool(ID_is_vtptr) ||
373 c.type().id() == ID_code)
378 const irep_idt &mem_name = c.get_base_name();
380 if(c.type().id() == ID_array)
384 if(size_expr.
id()==ID_infinity)
392 const auto size = numeric_cast<mp_integer>(size_expr);
397 copy_array(source_location, mem_name, i, arg_name, block);
400 copy_member(source_location, mem_name, arg_name, block);
407 declarator.
value() = std::move(block);
421 const irept &initializers)
423 assert(initializers.
id()==ID_member_initializers);
427 const irept &initializer=*init_it;
435 if(has_template_args)
443 for(
const auto &b : bases)
457 error() <<
"invalid initializer '" << member_name.
to_string() <<
"'"
467 for(
const auto &c : components)
469 if(c.get_base_name() != base_name)
474 !c.get_bool(ID_from_base) && !c.get_bool(ID_is_static) &&
475 c.type().id() != ID_code)
482 if(c.get_bool(ID_is_type))
484 if(c.type().id() != ID_struct_tag)
489 if(symb.
type.
id()!=ID_struct)
493 for(
const auto &b : bases)
506 c.get_bool(ID_from_base) && !c.get_bool(ID_is_type) &&
507 !c.get_bool(ID_is_static) && c.type().id() == ID_code &&
514 for(
const auto &b : bases)
517 member_type.
get(ID_identifier) ==
531 error() <<
"invalid initializer '" << base_name <<
"'" <<
eom;
552 assert(initializers.
id()==ID_member_initializers);
554 irept final_initializers(ID_member_initializers);
556 if(struct_union_type.
id()==ID_struct)
560 std::list<irep_idt> vbases;
567 while(!vbases.empty())
575 codet mem_init(ID_member_initializer);
576 mem_init.
set(ID_member, cppname);
583 cpp_namet(
"@most_derived").as_expr(), std::move(block));
590 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
605 irept initializer=*m_it;
612 if(!has_template_args)
619 for(
const auto &c : components)
622 c.get_base_name() == base_name && c.type().id() != ID_code &&
623 !c.get_bool(ID_is_type))
635 static_cast<const typet&
>(initializer.
find(ID_member));
639 if(member_type.
id() != ID_struct_tag)
657 codet mem_init(ID_member_initializer);
658 mem_init.
set(ID_member, cppname);
662 if(b.get_bool(ID_virtual))
664 codet tmp(ID_member_initializer);
668 cpp_namet(
"@most_derived").as_expr(), std::move(tmp));
670 final_initializers.
get_sub().back().swap(cond);
676 for(
const auto &c : components)
679 if(c.get_bool(ID_is_vtptr))
681 const cpp_namet cppname(c.get_base_name(), c.source_location());
683 const symbolt &virtual_table_symbol_type =
684 lookup(c.type().subtype().get(ID_identifier));
686 const symbolt &virtual_table_symbol_var =
692 assert(address.
type() == c.type());
696 exprt ptrmember(ID_ptrmember);
697 ptrmember.
set(ID_component_name, c.get_name());
706 c.get_bool(ID_from_base) || c.type().id() == ID_code ||
707 c.get_bool(ID_is_type) || c.get_bool(ID_is_static))
712 const irep_idt &mem_name = c.get_base_name();
719 irept &initializer=*m_it;
721 if(initializer.
get(ID_member)!=ID_cpp_name)
730 if(mem_name==base_name)
741 !found && c.type().id() == ID_pointer &&
742 c.type().get_bool(ID_C_reference))
745 error() <<
"reference must be explicitly initialized" <<
eom;
755 codet mem_init(ID_member_initializer);
756 mem_init.
set(ID_member, cppname);
761 initializers.
swap(final_initializers);
785 if(parameters.size() < 2)
790 const typet ¶meter1_type=parameter1.
type();
799 for(std::size_t i=2; i<parameters.size(); i++)
801 if(parameters[i].default_value().is_nil())
822 if(
component.get_base_name() !=
"operator=")
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
const irep_idt & get_identifier() const
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A codet representing sequential composition of program statements.
const typet & subtype() const
void set_function(const irep_idt &function)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
void move_to_sub(irept &irep)
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< parametert > parameterst
Base type for structs and unions.
typet type
Type of symbol.
Operator to dereference a pointer.
irept & add(const irep_namet &name)
const irept & find(const irep_namet &name) const
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
const type_with_subtypest & to_type_with_subtypes(const typet &type)
void default_assignop_value(const symbolt &symbol, cpp_declaratort &declarator)
Generate code for the implicit default assignment operator.
Base class for all expressions.
std::vector< componentt > componentst
irep_idt base_name
Base (non-scoped) name.
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
bitvector_typet index_type()
#define Forall_irep(it, irep)
codet representation of an if-then-else statement.
const declaratorst & declarators() const
const exprt & size() const
bool cpp_is_pod(const typet &type) const
typet & type()
Return the type of the expression.
void typecheck_type(typet &) override
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void default_ctor(const source_locationt &source_location, const irep_idt &base_name, cpp_declarationt &ctor) const
Generate code for implicit default constructors.
static void copy_parent(const source_locationt &source_location, const irep_idt &parent_base_name, const irep_idt &arg_name, exprt &block)
Generate code to copy the parent.
void get_virtual_bases(const struct_typet &type, std::list< irep_idt > &vbases) const
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,...
const std::string & id2string(const irep_idt &d)
source_locationt source_location
const source_locationt & source_location() const
void check_member_initializers(const struct_typet::basest &bases, const struct_typet::componentst &components, const irept &initializers)
Check a constructor initialization-list.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
A side_effect_exprt that performs an assignment.
const basest & bases() const
Get the collection of base classes/structs.
pointer_typet pointer_type(const typet &subtype)
const irep_idt & id() const
std::vector< baset > basest
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
void add(const codet &code)
static void copy_array(const source_locationt &source_location, const irep_idt &member_base_name, mp_integer i, const irep_idt &arg_name, exprt &block)
Generate code to copy the member.
const parameterst & parameters() const
source_locationt & add_source_location()
C++ Language Type Checking.
void full_member_initialization(const struct_union_typet &struct_union_type, irept &initializers)
Build the full initialization list of the constructor.
static void copy_member(const source_locationt &source_location, const irep_idt &member_base_name, const irep_idt &arg_name, exprt &block)
Generate code to copy the member.
reference_typet reference_type(const typet &subtype)
#define forall_irep(it, irep)
bool has_template_args() const
Structure type, corresponds to C style structs.
const source_locationt & source_location() const
codet representation of a "return from a function" statement.
bool is_reference(const typet &type)
Returns true if the type is a reference.
const irep_idt & get(const irep_namet &name) const
void set(const irep_namet &name, const irep_idt &value)
const exprt & as_expr() const
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
const typet & return_type() const
There are a large number of kinds of tree structured or tree-like data in CPROVER.
bool find_assignop(const symbolt &symbol) const
Operator to return the address of an object.
source_locationt & add_source_location()
A codet representing an assignment in the program.
irep_idt get_base_name() const
bool find_cpctor(const symbolt &symbol) const
void default_assignop(const symbolt &symbol, cpp_declarationt &cpctor)
Generate declaration of the implicit default assignment operator.
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
void default_cpctor(const symbolt &, cpp_declarationt &cpctor) const
Generate code for implicit default copy constructor.
API to expression classes.
const source_locationt & source_location() const
irep_idt name
The unique identifier.
std::string to_string() const
cpp_namet & to_cpp_name(irept &cpp_name)
codet representation of an expression statement.
const typet & as_type() const
Data structure for representing an arbitrary statement in a program.