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));
98 const cpp_namet array(member_base_name, source_location);
100 exprt member(ID_member);
102 ID_component_cpp_name,
cpp_namet(member_base_name, source_location));
133 decl.
value().
set(ID_statement, ID_block);
137 ctor.
type().
id(ID_constructor);
138 ctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
159 std::string param_identifier(
"ref");
165 const cpp_namet cpp_parameter(param_identifier, source_location);
170 parameter_tor.
set(ID_name, cpp_parameter);
176 parameter_decl.
set(ID_type, ID_merged_type);
178 sub.push_back(cppcomp.
as_type());
179 irept constnd(ID_const);
180 sub.push_back(static_cast<const typet &>(constnd));
185 decl0.
add(ID_type).
add(ID_parameters).
get_sub().push_back(parameter_decl);
188 irept &initializers=decl0.
add(ID_member_initializers);
189 initializers.
id(ID_member_initializers);
197 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
202 copy_parent(source_location, parsymb.base_name, param_identifier, block);
205 irep_idt ctor_name=parsymb.base_name;
208 const cpp_namet cppname(ctor_name, source_location);
210 codet mem_init(ID_member_initializer);
212 mem_init.
set(ID_member, cppname);
222 for(
const auto &mem_c : components)
225 if(mem_c.get_bool(ID_is_vtptr))
227 const cpp_namet cppname(mem_c.get_base_name(), source_location);
229 const symbolt &virtual_table_symbol_type =
230 lookup(mem_c.type().subtype().get(ID_identifier));
233 id2string(virtual_table_symbol_type.name) +
"@" +
236 exprt var=virtual_table_symbol_var.symbol_expr();
238 assert(address.
type() == mem_c.type());
242 exprt ptrmember(ID_ptrmember);
243 ptrmember.
set(ID_component_name, mem_c.get_name());
252 mem_c.get_bool(ID_from_base) || mem_c.get_bool(ID_is_type) ||
253 mem_c.get_bool(ID_is_static) || mem_c.type().id() == ID_code)
258 const irep_idt &mem_name = mem_c.get_base_name();
260 const cpp_namet cppname(mem_name, source_location);
262 codet mem_init(ID_member_initializer);
263 mem_init.
set(ID_member, cppname);
266 exprt memberexpr(ID_member);
267 memberexpr.
set(ID_component_cpp_name, cppname);
271 if(mem_c.type().id() == ID_array)
272 memberexpr.
set(ID_C_array_ini,
true);
292 std::string arg_name(
"ref");
294 cpctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
295 cpctor.
type().
id(ID_symbol_type);
304 typet &declarator_type=declarator.
type();
308 declarator_name.
id(ID_cpp_name);
309 declarator_name.
get_sub().push_back(
irept(ID_operator));
312 declarator_type.
id(ID_function_type);
326 args_decl.
type().
id(ID_merged_type);
327 args_decl_type_sub.push_back(
330 args_decl_type_sub.push_back(
typet(ID_const));
337 args_decl_declor.
name() =
cpp_namet(arg_name, source_location);
341 args_decl_declor.
type().
set(ID_C_reference,
true);
355 declarator.
value().
id(ID_code);
356 declarator.
value().
set(ID_statement, ID_block);
361 std::string arg_name(
"ref");
366 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
370 copy_parent(source_location, symb.base_name, arg_name, block);
377 c.get_bool(ID_from_base) || c.get_bool(ID_is_type) ||
378 c.get_bool(ID_is_static) || c.get_bool(ID_is_vtptr) ||
379 c.type().id() == ID_code)
384 const irep_idt &mem_name = c.get_base_name();
386 if(c.type().id() == ID_array)
390 if(size_expr.
id()==ID_infinity)
403 copy_array(source_location, mem_name, i, arg_name, block);
406 copy_member(source_location, mem_name, arg_name, block);
410 block.operands().push_back(
exprt(ID_code));
414 ret_code.
set(ID_statement, ID_return);
428 const irept &initializers)
430 assert(initializers.
id()==ID_member_initializers);
434 const irept &initializer=*init_it;
442 if(has_template_args)
450 for(
const auto &b : bases)
464 error() <<
"invalid initializer `" << member_name.to_string()
471 irep_idt base_name=member_name.get_base_name();
474 for(
const auto &c : components)
476 if(c.get_base_name() != base_name)
481 !c.get_bool(ID_from_base) && !c.get_bool(ID_is_static) &&
482 c.type().id() != ID_code)
489 if(c.get_bool(ID_is_type))
491 if(c.type().id() != ID_symbol_type)
495 if(symb.
type.
id()!=ID_struct)
499 for(
const auto &b : bases)
512 c.get_bool(ID_from_base) && !c.get_bool(ID_is_type) &&
513 !c.get_bool(ID_is_static) && c.type().id() == ID_code &&
520 for(
const auto &b : bases)
523 member_type.
get(ID_identifier) ==
537 error() <<
"invalid initializer `" << base_name <<
"'" <<
eom;
558 assert(initializers.
id()==ID_member_initializers);
560 irept final_initializers(ID_member_initializers);
562 if(struct_union_type.
id()==ID_struct)
566 std::list<irep_idt> vbases;
573 codet cond(ID_ifthenelse);
579 while(!vbases.empty())
587 codet mem_init(ID_member_initializer);
588 mem_init.
set(ID_member, cppname);
594 final_initializers.move_to_sub(cond);
600 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
607 irep_idt ctor_name=ctorsymb.base_name;
615 irept initializer=*m_it;
622 if(!has_template_args)
629 for(
const auto &c : components)
632 c.get_base_name() == base_name && c.type().id() != ID_code &&
633 !c.get_bool(ID_is_type))
645 static_cast<const typet&
>(initializer.
find(ID_member));
649 if(member_type.
id() != ID_symbol_type)
656 final_initializers.move_to_sub(initializer);
667 codet mem_init(ID_member_initializer);
668 mem_init.
set(ID_member, cppname);
669 final_initializers.move_to_sub(mem_init);
672 if(b.get_bool(ID_virtual))
676 codet cond(ID_ifthenelse);
681 codet tmp(ID_member_initializer);
682 tmp.
swap(final_initializers.get_sub().back());
684 final_initializers.get_sub().back().swap(cond);
691 for(
const auto &c : components)
694 if(c.get_bool(ID_is_vtptr))
696 const cpp_namet cppname(c.get_base_name(), c.source_location());
698 const symbolt &virtual_table_symbol_type =
699 lookup(c.type().subtype().get(ID_identifier));
701 const symbolt &virtual_table_symbol_var =
705 exprt var=virtual_table_symbol_var.symbol_expr();
707 assert(address.
type() == c.type());
711 exprt ptrmember(ID_ptrmember);
712 ptrmember.
set(ID_component_name, c.get_name());
716 final_initializers.move_to_sub(assign);
721 c.get_bool(ID_from_base) || c.type().id() == ID_code ||
722 c.get_bool(ID_is_type) || c.get_bool(ID_is_static))
727 const irep_idt &mem_name = c.get_base_name();
734 irept &initializer=*m_it;
736 if(initializer.
get(ID_member)!=ID_cpp_name)
745 if(mem_name==base_name)
747 final_initializers.move_to_sub(initializer);
756 !found && c.type().id() == ID_pointer &&
757 c.type().get_bool(ID_C_reference))
760 error() <<
"reference must be explicitly initialized" <<
eom;
770 codet mem_init(ID_member_initializer);
771 mem_init.
set(ID_member, cppname);
772 final_initializers.move_to_sub(mem_init);
776 initializers.
swap(final_initializers);
800 if(parameters.size() < 2)
805 const typet ¶meter1_type=parameter1.
type();
814 for(std::size_t i=2; i<parameters.size(); i++)
816 if(parameters[i].default_value().is_nil())
837 if(
component.get_base_name() !=
"operator=")
The type of an expression, extends irept.
irep_idt name
The unique identifier.
bool find_cpctor(const symbolt &symbol) const
void set_function(const irep_idt &function)
const std::string & id2string(const irep_idt &d)
const type_with_subtypest & to_type_with_subtypes(const typet &type)
pointer_typet pointer_type(const typet &subtype)
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.
const exprt & as_expr() const
void move_to_sub(irept &irep)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
void full_member_initialization(const struct_union_typet &struct_union_type, irept &initializers)
Build the full initialization list of the constructor.
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
cpp_namet & to_cpp_name(irept &cpp_name)
std::vector< componentt > componentst
void move_to_operands(exprt &expr)
Move the given argument to the end of exprt's operands.
const symbol_typet & to_symbol_type(const typet &type)
Cast a typet to a symbol_typet.
std::vector< parametert > parameterst
void already_typechecked(irept &irep)
const componentst & components() const
typet & type()
Return the type of the expression.
#define CHECK_RETURN(CONDITION)
Structure type, corresponds to C style structs.
codet representation of an expression statement.
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.
void default_assignop_value(const symbolt &symbol, cpp_declaratort &declarator)
Generate code for the implicit default assignment operator.
const irep_idt & id() const
const declaratorst & declarators() const
const basest & bases() const
Get the collection of base classes/structs.
reference_typet reference_type(const typet &subtype)
void check_member_initializers(const struct_typet::basest &bases, const struct_typet::componentst &components, const irept &initializers)
Check a constructor initialization-list.
bool has_template_args() const
source_locationt source_location
bool cpp_is_pod(const typet &type) const
Operator to dereference a pointer.
void typecheck_type(typet &) override
API to expression classes.
bool is_reference(const typet &type)
Returns true if the type is a reference.
const irep_idt & get(const irep_namet &name) const
Base class for tree-like data structures with sharing.
C++ Language Type Checking.
bitvector_typet index_type()
#define Forall_irep(it, irep)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Operator to return the address of an object.
void default_assignop(const symbolt &symbol, cpp_declarationt &cpctor)
Generate declaration of the implicit default assignment operator.
void default_cpctor(const symbolt &, cpp_declarationt &cpctor) const
Generate code for implicit default copy constructor.
const source_locationt & source_location() const
irep_idt get_base_name() const
typet type
Type of symbol.
Base type for structs and unions.
void default_ctor(const source_locationt &source_location, const irep_idt &base_name, cpp_declarationt &ctor) const
Generate code for implicit default constructors.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool find_assignop(const symbolt &symbol) const
const typet & as_type() const
Base class for all expressions.
void get_virtual_bases(const struct_typet &type, std::list< irep_idt > &vbases) const
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
source_locationt & add_source_location()
const source_locationt & source_location() const
irept & add(const irep_namet &name)
The NIL type, i.e., an invalid type, no value.
source_locationt & add_source_location()
A codet representing sequential composition of program statements.
Data structure for representing an arbitrary statement in a program.
const typet & subtype() const
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions, goto_programs, exprts, etc.
An expression containing a side effect.
std::vector< baset > basest
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 irept & find(const irep_namet &name) const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const irep_idt & get_identifier() const
A codet representing an assignment in the program.
void set(const irep_namet &name, const irep_idt &value)
#define forall_irep(it, irep)