Go to the documentation of this file.
36 for(
const auto &expr : arguments)
44 expr.id() != ID_ambiguous,
"template argument must not be ambiguous");
46 if(expr.id()==ID_type)
48 const typet &type=expr.type();
49 if(type.
id() == ID_symbol_type)
51 else if(type.
id() == ID_struct_tag ||
52 type.
id() == ID_union_tag)
72 error() <<
"template argument expression expected to be "
73 <<
"scalar constant, but got `"
92 out <<
"instantiating `" << symbol.
pretty_name <<
"' with <";
96 if(a_it != e.full_template_args.arguments().begin())
99 if(a_it->id()==ID_type)
105 out <<
"> at " << e.source_location <<
'\n';
111 const symbolt &template_symbol,
119 if(full_template_args.
arguments().empty())
123 <<
"' is a template; thus, expected template arguments"
143 symbol_tablet::symbolst::const_iterator s_it=
151 new_symbol.
name=identifier;
154 new_symbol.
type=
typet(ID_incomplete_struct);
157 new_symbol.
type.
set(ID_C_class,
true);
158 new_symbol.
type.
set(ID_template_class_instance,
true);
161 ID_specialization_template_args, specialization_template_args);
162 new_symbol.
type.
set(ID_full_template_args, full_template_args);
163 new_symbol.
type.
set(ID_identifier, template_symbol.
name);
164 new_symbol.
mode=template_symbol.
mode;
176 id.prefix=template_scope->
prefix+
179 id.class_identifier=s_ptr->
name;
189 if(type.
id() != ID_symbol_type)
197 if(t_type.
id()==ID_incomplete_struct &&
198 t_type.
get_bool(ID_template_class_instance))
204 t_type.
find(ID_specialization_template_args)),
206 t_type.
find(ID_full_template_args)));
218 const symbolt &template_symbol,
221 const typet &specialization)
224 std::cout <<
"instantiate_template: " << template_symbol.
name <<
'\n';
230 error() <<
"reached maximum template recursion depth ("
241 std::cout <<
"L: " << source_location <<
'\n';
242 std::cout <<
"I: " << template_symbol.
name <<
'\n';
247 bool specialization_given=specialization.
is_not_nil();
257 if(it!=specialization_template_args.
arguments().begin())
259 if(it->id()==ID_type)
264 std::cout <<
">\n\n";
268 if(full_template_args.
arguments().empty())
272 <<
"' is a template; thus, expected template arguments"
284 if(template_scope==
nullptr)
287 error() <<
"identifier: " << template_symbol.
name <<
'\n'
288 <<
"template instantiation error: scope not found" <<
eom;
298 new_decl.
remove(ID_is_template);
299 new_decl.
remove(ID_template_type);
300 new_decl.
set(ID_C_template, template_symbol.
name);
301 new_decl.
set(ID_C_template_arguments, specialization_template_args);
314 bool is_template_method=
316 new_decl.
type().
id()!=ID_struct;
320 if(is_template_method)
327 cpp_scopest::id_mapt::iterator scope_it=
340 const cpp_idt &cpp_id = **id_set.begin();
349 symb.
type.
id()==ID_struct)
368 cpp_scopest::id_mapt::value_type(subscope_name, &sub_scope));
376 irept &instantiated_with = s.
value.
add(ID_instantiated_with);
377 instantiated_with.
get_sub().push_back(specialization_template_args);
381 std::cout <<
"CLASS MAP:\n";
390 if(specialization_given)
392 if(declaration_type.
id()==ID_struct)
394 declaration_type=specialization;
399 irept tmp=specialization;
405 new_decl.
type().
swap(declaration_type);
408 if(new_decl.
type().
id()==ID_struct)
414 const exprt &template_methods =
static_cast<const exprt &
>(
415 template_symbol.
value.
find(ID_template_methods));
417 for(
auto &tm : template_methods.
operands())
423 static_cast<const irept &
>(tm));
439 std::cout <<
"METHOD MAP:\n";
443 method_decl.
remove(ID_template_type);
444 method_decl.
remove(ID_is_template);
454 new_symb.
type.
set(ID_C_template, template_type);
455 new_symb.
type.
set(ID_C_template_arguments, specialization_template_args);
458 std::cout <<
"instance symbol: " << new_symb.
name <<
"\n\n";
459 std::cout <<
"template type: " << template_type.
pretty() <<
"\n\n";
465 if(is_template_method)
474 error() <<
"invalid use of `virtual' in template declaration"
482 error() <<
"template declaration for typedef" <<
eom;
492 error() <<
"invalid storage class specified for template field"
500 assert(!access.
empty());
501 assert(symb.
type.
id()==ID_struct);
void convert(cpp_linkage_spect &)
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const symbolt & instantiate_template(const source_locationt &source_location, const symbolt &symbol, const cpp_template_args_tct &specialization_template_args, const cpp_template_args_tct &full_template_args, const typet &specialization=typet(ID_nil))
void convert_non_template_declaration(cpp_declarationt &declaration)
const cpp_storage_spect & storage_spec() const
cpp_scopet & get_parent() const
void elaborate_class_template(const typet &type)
elaborate class template instances
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
std::string template_suffix(const cpp_template_args_tct &template_args)
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
void add_using_scope(cpp_scopet &other)
The type of an expression, extends irept.
void show_instantiation_stack(std::ostream &)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
cpp_declarationt & to_cpp_declaration(irept &irep)
typet type
Type of symbol.
cpp_scopet & typecheck_template_parameters(template_typet &type)
irept & add(const irep_namet &name)
const irept & find(const irep_namet &name) const
cpp_scopet & get_scope(const irep_idt &identifier)
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
const symbolt & class_template_symbol(const source_locationt &source_location, const symbolt &template_symbol, const cpp_template_args_tct &specialization_template_args, const cpp_template_args_tct &full_template_args)
instantiation_stackt instantiation_stack
bool is_true() const
Return whether the expression is a constant representing true.
cpp_idt & put_into_scope(const symbolt &symbol, cpp_scopet &scope, bool is_friend=false)
void apply(exprt &dest) const
const declaratorst & declarators() const
bool is_false() const
Return whether the expression is a constant representing false.
const cpp_member_spect & member_spec() const
irep_idt pretty_name
Language-specific display name.
virtual void make_constant(exprt &expr)
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
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().
bool get_bool(const irep_namet &name) const
irep_idt mode
Language mode.
mstreamt & result() const
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
void typecheck_compound_declarator(const symbolt &symbol, const cpp_declarationt &declaration, cpp_declaratort &declarator, struct_typet::componentst &components, const irep_idt &access, bool is_static, bool is_typedef, bool is_mutable)
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
cpp_scopet & current_scope()
source_locationt source_location
void print(std::ostream &out) const
const source_locationt & source_location() const
symbol_tablet & symbol_table
const irep_idt & id() const
void remove(const irep_namet &name)
source_locationt & add_source_location()
const symbol_typet & to_symbol_type(const typet &type)
Cast a typet to a symbol_typet.
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
virtual symbolt * get_writeable(const irep_idt &name) override
Find a symbol in the symbol table for read-write access.
exprt value
Initial value of symbol.
std::string cpp_type2name(const typet &type)
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
void set(const irep_namet &name, const irep_idt &value)
bool has_unassigned() const
Base class for tree-like data structures with sharing.
std::string to_string(const typet &) override
exprt::operandst argumentst
void build(const template_typet &template_type, const cpp_template_args_tct &template_args)
#define forall_expr(it, expr)
template_mapt template_map
const source_locationt & source_location() const
irep_idt name
The unique identifier.
template_typet & template_type()
const std::string integer2string(const mp_integer &n, unsigned base)