Go to the documentation of this file.
33 for(
const auto &expr : arguments)
41 expr.id() != ID_ambiguous,
"template argument must not be ambiguous");
43 if(expr.id()==ID_type)
45 const typet &type=expr.type();
46 if(type.
id() == ID_struct_tag || type.
id() == ID_union_tag)
55 if(e.
id() == ID_symbol)
76 error() <<
"template argument expression expected to be "
77 <<
"scalar constant, but got '" <<
to_string(e) <<
"'" <<
eom;
95 out <<
"instantiating '" << symbol.
pretty_name <<
"' with <";
99 if(a_it != e.full_template_args.arguments().begin())
102 if(a_it->id()==ID_type)
108 out <<
"> at " << e.source_location <<
'\n';
115 const std::string &suffix)
122 if(id_set.size() == 1)
124 cpp_idt &cpp_id = **id_set.begin();
134 sub_scope.
suffix = suffix;
137 const std::string subscope_name =
140 cpp_scopest::id_mapt::value_type(subscope_name, &sub_scope));
148 const symbolt &template_symbol,
156 if(full_template_args.
arguments().empty())
160 <<
"' is a template; thus, expected template arguments" <<
eom;
178 symbol_tablet::symbolst::const_iterator s_it=
186 new_symbol.
name=identifier;
193 new_symbol.
type.
set(ID_C_class,
true);
194 new_symbol.
type.
set(ID_template_class_instance,
true);
197 ID_specialization_template_args, specialization_template_args);
198 new_symbol.
type.
set(ID_full_template_args, full_template_args);
199 new_symbol.
type.
set(ID_identifier, template_symbol.
name);
200 new_symbol.
mode=template_symbol.
mode;
214 id.class_identifier=s_ptr->
name;
224 if(type.
id() != ID_struct_tag)
232 if(t_type.
id() == ID_struct && t_type.
get_bool(ID_template_class_instance))
238 t_type.
find(ID_specialization_template_args)),
240 t_type.
find(ID_full_template_args)));
252 const symbolt &template_symbol,
255 const typet &specialization)
258 std::cout <<
"instantiate_template: " << template_symbol.
name <<
'\n';
264 error() <<
"reached maximum template recursion depth ("
275 std::cout <<
"L: " << source_location <<
'\n';
276 std::cout <<
"I: " << template_symbol.
name <<
'\n';
281 bool specialization_given=specialization.
is_not_nil();
291 if(it!=specialization_template_args.
arguments().begin())
293 if(it->id()==ID_type)
298 std::cout <<
">\n\n";
302 if(full_template_args.
arguments().empty())
306 <<
"' is a template; thus, expected template arguments" <<
eom;
317 if(template_scope==
nullptr)
320 error() <<
"identifier: " << template_symbol.
name <<
'\n'
321 <<
"template instantiation error: scope not found" <<
eom;
331 new_decl.
remove(ID_is_template);
332 new_decl.
remove(ID_template_type);
333 new_decl.
set(ID_C_template, template_symbol.
name);
334 new_decl.
set(ID_C_template_arguments, specialization_template_args);
347 bool is_template_method=
349 new_decl.
type().
id()!=ID_struct;
353 if(is_template_method)
367 const cpp_idt &cpp_id = **id_set.begin();
376 symb.
type.
id()==ID_struct)
390 irept &instantiated_with = s.
value.
add(ID_instantiated_with);
391 instantiated_with.
get_sub().push_back(specialization_template_args);
395 std::cout <<
"CLASS MAP:\n";
404 if(specialization_given)
406 if(declaration_type.
id()==ID_struct)
408 declaration_type=specialization;
413 irept tmp=specialization;
419 new_decl.
type().
swap(declaration_type);
422 if(new_decl.
type().
id()==ID_struct)
428 const exprt &template_methods =
static_cast<const exprt &
>(
429 template_symbol.
value.
find(ID_template_methods));
431 for(
auto &tm : template_methods.
operands())
437 static_cast<const irept &
>(tm));
453 std::cout <<
"METHOD MAP:\n";
457 method_decl.
remove(ID_template_type);
458 method_decl.
remove(ID_is_template);
468 new_symb.
type.
set(ID_C_template, template_type);
469 new_symb.
type.
set(ID_C_template_arguments, specialization_template_args);
472 std::cout <<
"instance symbol: " << new_symb.
name <<
"\n\n";
473 std::cout <<
"template type: " << template_type.
pretty() <<
"\n\n";
479 if(is_template_method)
488 error() <<
"invalid use of `virtual' in template declaration"
496 error() <<
"template declaration for typedef" <<
eom;
506 error() <<
"invalid storage class specified for template field"
514 assert(!access.
empty());
515 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.
void convert_non_template_declaration(cpp_declarationt &declaration)
const cpp_storage_spect & storage_spec() const
cpp_scopet & get_parent() const
cpp_scopet & sub_scope_for_instantiation(cpp_scopet &template_scope, const std::string &suffix)
Set up a scope as subscope of the template scope.
void elaborate_class_template(const typet &type)
elaborate class template instances
std::set< cpp_idt * > id_sett
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
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)
#define CHECK_RETURN(CONDITION)
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)
const irept & find(const irep_idt &name) const
typet type
Type of symbol.
cpp_scopet & typecheck_template_parameters(template_typet &type)
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
void make_incomplete()
A struct/union may be incomplete.
bool is_true() const
Return whether the expression is a constant representing true.
Expression to hold a symbol (variable)
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
const irep_idt & get(const irep_idt &name) const
irep_idt pretty_name
Language-specific display name.
virtual void make_constant(exprt &expr)
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().
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)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
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
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
void print(std::ostream &out) const
void set(const irep_idt &name, const irep_idt &value)
const source_locationt & source_location() const
const irep_idt & get_identifier() const
symbol_tablet & symbol_table
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
source_locationt & add_source_location()
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
exprt value
Initial value of symbol.
Structure type, corresponds to C style structs.
irept & add(const irep_idt &name)
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=uninitialized_typet{})
std::string cpp_type2name(const typet &type)
source_locationt location
Source code location of definition of symbol.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
bool has_unassigned() const
There are a large number of kinds of tree structured or tree-like data in CPROVER.
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)
void remove(const irep_idt &name)
template_mapt template_map
bool is_template_scope() const
const source_locationt & source_location() const
irep_idt name
The unique identifier.
bool get_bool(const irep_idt &name) const
template_typet & template_type()
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const std::string integer2string(const mp_integer &n, unsigned base)