34 for(
const auto &expr : arguments)
42 expr.id() != ID_ambiguous,
"template argument must not be ambiguous");
44 if(expr.id()==ID_type)
46 const typet &type=expr.type();
47 if(type.
id() == ID_struct_tag || type.
id() == ID_union_tag)
56 if(e.
id() == ID_symbol)
77 error() <<
"template argument expression expected to be "
78 <<
"scalar constant, but got '" <<
to_string(e) <<
"'" <<
eom;
96 out <<
"instantiating '" << symbol.
pretty_name <<
"' with <";
100 if(a_it != e.full_template_args.arguments().begin())
103 if(a_it->id()==ID_type)
109 out <<
"> at " << e.source_location <<
'\n';
116 const std::string &suffix)
123 if(id_set.size() == 1)
125 cpp_idt &cpp_id = **id_set.begin();
135 sub_scope.
suffix = suffix;
138 const std::string subscope_name =
141 cpp_scopest::id_mapt::value_type(subscope_name, &sub_scope));
149 const symbolt &template_symbol,
156 if(full_template_args.
arguments().empty())
160 <<
"' is a template; thus, expected template arguments" <<
eom;
178 symbol_table_baset::symbolst::const_iterator s_it =
186 new_symbol.pretty_name=template_symbol.
pretty_name;
187 new_symbol.location=template_symbol.
location;
189 new_symbol.type.set(ID_tag, template_symbol.
type.
find(ID_tag));
191 new_symbol.type.set(ID_C_class,
true);
192 new_symbol.type.set(ID_template_class_instance,
true);
193 new_symbol.type.add_source_location()=template_symbol.
location;
195 ID_specialization_template_args, specialization_template_args);
196 new_symbol.type.set(ID_full_template_args, full_template_args);
197 new_symbol.type.set(ID_identifier, template_symbol.
name);
198 new_symbol.base_name=template_symbol.
base_name;
210 id.class_identifier=s_ptr->
name;
220 if(type.
id() != ID_struct_tag)
228 if(t_type.
id() == ID_struct && t_type.
get_bool(ID_template_class_instance))
234 t_type.
find(ID_specialization_template_args)),
236 t_type.
find(ID_full_template_args)));
248 const symbolt &template_symbol,
251 const typet &specialization)
254 std::cout <<
"instantiate_template: " << template_symbol.
name <<
'\n';
260 error() <<
"reached maximum template recursion depth ("
271 std::cout <<
"L: " << source_location <<
'\n';
272 std::cout <<
"I: " << template_symbol.
name <<
'\n';
277 bool specialization_given=specialization.
is_not_nil();
282 "should never get 'unassigned' here");
284 !full_template_args.
has_unassigned(),
"should never get 'unassigned' here");
290 if(it!=specialization_template_args.
arguments().begin())
292 if(it->id()==ID_type)
297 std::cout <<
">\n\n";
301 if(full_template_args.
arguments().empty())
305 <<
"' is a template; thus, expected template arguments" <<
eom;
316 if(template_scope==
nullptr)
319 error() <<
"identifier: " << template_symbol.
name <<
'\n'
320 <<
"template instantiation error: scope not found" <<
eom;
330 new_decl.
remove(ID_is_template);
331 new_decl.
remove(ID_template_type);
332 new_decl.
set(ID_C_template, template_symbol.
name);
333 new_decl.
set(ID_C_template_arguments, specialization_template_args);
346 bool is_template_method=
348 new_decl.
type().
id()!=ID_struct;
352 if(is_template_method)
366 const cpp_idt &cpp_id = **id_set.begin();
371 "id must be class or symbol");
377 symb.
type.
id()==ID_struct)
391 irept &instantiated_with = s.
value.
add(ID_instantiated_with);
392 instantiated_with.
get_sub().push_back(specialization_template_args);
396 std::cout <<
"CLASS MAP:\n";
405 if(specialization_given)
407 if(declaration_type.
id()==ID_struct)
409 declaration_type=specialization;
414 irept tmp=specialization;
420 new_decl.
type().
swap(declaration_type);
423 if(new_decl.
type().
id()==ID_struct)
429 const exprt &template_methods =
static_cast<const exprt &
>(
430 template_symbol.
value.
find(ID_template_methods));
432 for(
auto &tm : template_methods.
operands())
438 static_cast<const irept &
>(tm));
454 std::cout <<
"METHOD MAP:\n";
458 method_decl.
remove(ID_template_type);
459 method_decl.
remove(ID_is_template);
469 new_symb.
type.
set(ID_C_template, template_type);
470 new_symb.
type.
set(ID_C_template_arguments, specialization_template_args);
473 std::cout <<
"instance symbol: " << new_symb.
name <<
"\n\n";
474 std::cout <<
"template type: " << template_type.
pretty() <<
"\n\n";
480 if(is_template_method)
489 error() <<
"invalid use of `virtual' in template declaration"
497 error() <<
"template declaration for typedef" <<
eom;
507 error() <<
"invalid storage class specified for template field"
Generic exception types primarily designed for use with invariants.
symbol_table_baset & symbol_table
virtual void make_constant(exprt &expr)
const declaratorst & declarators() const
const cpp_storage_spect & storage_spec() const
const cpp_member_spect & member_spec() const
template_typet & template_type()
bool is_template_scope() const
cpp_scopet & current_scope()
cpp_idt & put_into_scope(const symbolt &symbol, cpp_scopet &scope, bool is_friend=false)
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
cpp_scopet & get_parent() const
void add_using_scope(cpp_scopet &other)
std::set< cpp_idt * > id_sett
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
exprt::operandst argumentst
bool has_unassigned() const
std::string template_suffix(const cpp_template_args_tct &template_args)
instantiation_stackt instantiation_stack
template_mapt template_map
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)
void convert_non_template_declaration(cpp_declarationt &declaration)
bool cpp_is_pod(const typet &type) const
void show_instantiation_stack(std::ostream &)
void convert(cpp_linkage_spect &)
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
cpp_scopet & typecheck_template_parameters(template_typet &type)
std::string to_string(const typet &) override
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{})
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)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
bool is_true() const
Return whether the expression is a constant representing true.
const source_locationt & source_location() const
bool is_false() const
Return whether the expression is a constant representing false.
typet & type()
Return the type of the expression.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
bool get_bool(const irep_idt &name) const
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void remove(const irep_idt &name)
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
irept & add(const irep_idt &name)
source_locationt source_location
mstreamt & result() const
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
Structure type, corresponds to C style structs.
const componentst & components() const
void make_incomplete()
A struct/union may be incomplete.
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
virtual bool move(symbolt &symbol, symbolt *&new_symbol)=0
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt pretty_name
Language-specific display name.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
void build(const template_typet &template_type, const cpp_template_args_tct &template_args)
void print(std::ostream &out) const
void apply(exprt &dest) const
Symbol table entry describing a data typeThis is a symbol generated as part of type checking.
The type of an expression, extends irept.
const source_locationt & source_location() const
source_locationt & add_source_location()
cpp_declarationt & to_cpp_declaration(irept &irep)
std::string cpp_type2name(const typet &type)
C++ Language Type Checking.
#define forall_expr(it, expr)
const std::string & id2string(const irep_idt &d)
const std::string integer2string(const mp_integer &n, unsigned base)
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
#define CHECK_RETURN(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.