39 op1.
type().
set(ID_C_reference,
true);
61 cpp_namet op0(member_base_name, source_location);
64 op1.
add(ID_component_cpp_name,
cpp_namet(member_base_name, source_location));
93 const cpp_namet array(member_base_name, source_location);
95 exprt member(ID_member);
97 ID_component_cpp_name,
cpp_namet(member_base_name, source_location));
131 ctor.
type().
id(ID_constructor);
132 ctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
153 std::string param_identifier(
"ref");
159 const cpp_namet cpp_parameter(param_identifier, source_location);
164 parameter_tor.
set(ID_name, cpp_parameter);
170 parameter_decl.
set(ID_type, ID_merged_type);
172 sub.push_back(cppcomp.
as_type());
173 irept constnd(ID_const);
174 sub.push_back(
static_cast<const typet &
>(constnd));
179 decl0.
add(ID_type).
add(ID_parameters).
get_sub().push_back(parameter_decl);
182 irept &initializers=decl0.
add(ID_member_initializers);
183 initializers.
id(ID_member_initializers);
192 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
203 const cpp_namet cppname(ctor_name, source_location);
205 codet mem_init(ID_member_initializer);
207 mem_init.
set(ID_member, cppname);
217 for(
const auto &mem_c : components)
220 if(mem_c.get_bool(ID_is_vtptr))
222 const cpp_namet cppname(mem_c.get_base_name(), source_location);
224 const symbolt &virtual_table_symbol_type =
225 lookup(mem_c.type().subtype().get(ID_identifier));
233 assert(address.
type() == mem_c.type());
237 exprt ptrmember(ID_ptrmember);
238 ptrmember.
set(ID_component_name, mem_c.get_name());
247 mem_c.get_bool(ID_from_base) || mem_c.get_bool(ID_is_type) ||
248 mem_c.get_bool(ID_is_static) || mem_c.type().id() == ID_code)
253 const irep_idt &mem_name = mem_c.get_base_name();
255 const cpp_namet cppname(mem_name, source_location);
257 codet mem_init(ID_member_initializer);
258 mem_init.
set(ID_member, cppname);
261 exprt memberexpr(ID_member);
262 memberexpr.
set(ID_component_cpp_name, cppname);
266 if(mem_c.type().id() == ID_array)
267 memberexpr.
set(ID_C_array_ini,
true);
287 std::string arg_name(
"ref");
289 cpctor.
add(ID_storage_spec).
id(ID_cpp_storage_spec);
290 cpctor.
type().
id(ID_struct_tag);
300 typet &declarator_type=declarator.
type();
304 declarator_name.
id(ID_cpp_name);
305 declarator_name.
get_sub().push_back(
irept(ID_operator));
308 declarator_type.
id(ID_function_type);
322 args_decl.
type().
id(ID_merged_type);
323 args_decl_type_sub.push_back(
326 args_decl_type_sub.push_back(
typet(ID_const));
333 args_decl_declor.
name() =
cpp_namet(arg_name, source_location);
337 args_decl_declor.
type().
set(ID_C_reference,
true);
352 std::string arg_name(
"ref");
357 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
368 c.get_bool(ID_from_base) || c.get_bool(ID_is_type) ||
369 c.get_bool(ID_is_static) || c.get_bool(ID_is_vtptr) ||
370 c.type().id() == ID_code)
375 const irep_idt &mem_name = c.get_base_name();
377 if(c.type().id() == ID_array)
381 if(size_expr.
id()==ID_infinity)
389 const auto size = numeric_cast<mp_integer>(size_expr);
394 copy_array(source_location, mem_name, i, arg_name, block);
397 copy_member(source_location, mem_name, arg_name, block);
404 declarator.
value() = std::move(block);
418 const irept &initializers)
420 assert(initializers.
id()==ID_member_initializers);
422 for(
const auto &initializer : initializers.
get_sub())
424 assert(initializer.is_not_nil());
431 if(has_template_args)
439 for(
const auto &b : bases)
453 error() <<
"invalid initializer '" << member_name.
to_string() <<
"'"
463 for(
const auto &c : components)
465 if(c.get_base_name() != base_name)
470 !c.get_bool(ID_from_base) && !c.get_bool(ID_is_static) &&
471 c.type().id() != ID_code)
478 if(c.get_bool(ID_is_type))
480 if(c.type().id() != ID_struct_tag)
485 if(symb.
type.
id()!=ID_struct)
489 for(
const auto &b : bases)
502 c.get_bool(ID_from_base) && !c.get_bool(ID_is_type) &&
503 !c.get_bool(ID_is_static) && c.type().id() == ID_code &&
510 for(
const auto &b : bases)
513 member_type.
get(ID_identifier) ==
527 error() <<
"invalid initializer '" << base_name <<
"'" <<
eom;
547 assert(initializers.
id()==ID_member_initializers);
549 irept final_initializers(ID_member_initializers);
551 if(struct_union_type.
id()==ID_struct)
555 std::list<irep_idt> vbases;
562 while(!vbases.empty())
570 codet mem_init(ID_member_initializer);
571 mem_init.
set(ID_member, cppname);
578 cpp_namet(
"@most_derived").as_expr(), std::move(block));
585 DATA_INVARIANT(b.id() == ID_base,
"base class expression expected");
605 if(!has_template_args)
612 for(
const auto &c : components)
615 c.get_base_name() == base_name && c.type().id() != ID_code &&
616 !c.get_bool(ID_is_type))
628 static_cast<const typet&
>(initializer.find(ID_member));
632 if(member_type.
id() != ID_struct_tag)
650 codet mem_init(ID_member_initializer);
651 mem_init.
set(ID_member, cppname);
655 if(b.get_bool(ID_virtual))
657 codet tmp(ID_member_initializer);
661 cpp_namet(
"@most_derived").as_expr(), std::move(tmp));
663 final_initializers.
get_sub().back().swap(cond);
669 for(
const auto &c : components)
672 if(c.get_bool(ID_is_vtptr))
674 const cpp_namet cppname(c.get_base_name(), c.source_location());
676 const symbolt &virtual_table_symbol_type =
677 lookup(c.type().subtype().get(ID_identifier));
679 const symbolt &virtual_table_symbol_var =
685 assert(address.
type() == c.type());
689 exprt ptrmember(ID_ptrmember);
690 ptrmember.
set(ID_component_name, c.get_name());
699 c.get_bool(ID_from_base) || c.type().id() == ID_code ||
700 c.get_bool(ID_is_type) || c.get_bool(ID_is_static))
705 const irep_idt &mem_name = c.get_base_name();
710 for(
auto &initializer : initializers.
get_sub())
712 if(initializer.get(ID_member)!=ID_cpp_name)
721 if(mem_name==base_name)
732 !found && c.type().id() == ID_pointer &&
733 c.type().get_bool(ID_C_reference))
736 error() <<
"reference must be explicitly initialized" <<
eom;
746 codet mem_init(ID_member_initializer);
747 mem_init.
set(ID_member, cppname);
752 initializers.
swap(final_initializers);
776 if(parameters.size() < 2)
781 const typet ¶meter1_type=parameter1.
type();
790 for(std::size_t i=2; i<parameters.size(); i++)
792 if(parameters[i].default_value().is_nil())
813 if(
component.get_base_name() !=
"operator=")
bitvector_typet index_type()
reference_typet reference_type(const typet &subtype)
pointer_typet pointer_type(const typet &subtype)
Operator to return the address of an object.
static void make_already_typechecked(exprt &expr)
const exprt & size() const
A codet representing an assignment in the program.
A codet representing sequential composition of program statements.
void add(const codet &code)
codet representation of an expression statement.
codet representation of an if-then-else statement.
codet representation of a "return from a function" statement.
std::vector< parametert > parameterst
const typet & return_type() const
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
const declaratorst & declarators() const
const typet & as_type() const
irep_idt get_base_name() const
const source_locationt & source_location() const
bool has_template_args() const
std::string to_string() const
const exprt & as_expr() const
void default_assignop(const symbolt &symbol, cpp_declarationt &cpctor)
Generate declaration of the implicit default assignment operator.
void typecheck_type(typet &) override
void full_member_initialization(const struct_union_typet &struct_union_type, irept &initializers)
Build the full initialization list of the constructor.
bool cpp_is_pod(const typet &type) const
void default_cpctor(const symbolt &, cpp_declarationt &cpctor) const
Generate code for implicit default copy constructor.
bool find_assignop(const symbolt &symbol) const
void get_virtual_bases(const struct_typet &type, std::list< irep_idt > &vbases) const
void check_member_initializers(const struct_typet::basest &bases, const struct_typet::componentst &components, const irept &initializers)
Check a constructor initialization-list.
void default_assignop_value(const symbolt &symbol, cpp_declaratort &declarator)
Generate code for the implicit default assignment operator.
bool find_cpctor(const symbolt &symbol) const
void default_ctor(const source_locationt &source_location, const irep_idt &base_name, cpp_declarationt &ctor) const
Generate code for implicit default constructors.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
irept & add(const irep_namet &name)
void set(const irep_namet &name, const irep_idt &value)
const irept & find(const irep_namet &name) const
const irep_idt & id() const
void move_to_sub(irept &irep)
const irep_idt & get(const irep_namet &name) const
source_locationt source_location
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
A side_effect_exprt that performs an assignment.
void set_function(const irep_idt &function)
Structure type, corresponds to C style structs.
const basest & bases() const
Get the collection of base classes/structs.
std::vector< baset > basest
Base type for structs and unions.
const componentst & components() const
std::vector< componentt > componentst
irep_idt base_name
Base (non-scoped) name.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
const irep_idt & get_identifier() const
The type of an expression, extends irept.
const source_locationt & source_location() const
const typet & subtype() const
source_locationt & add_source_location()
cpp_namet & to_cpp_name(irept &cpp_name)
C++ Language Type Checking.
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.
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.
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 std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
bool is_reference(const typet &type)
Returns true if the type is a reference.
#define CHECK_RETURN(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const type_with_subtypest & to_type_with_subtypes(const typet &type)