32 for(cpp_template_args_tct::argumentst::const_iterator
44 assert(expr.
id()!=
"ambiguous");
46 if(expr.
id()==ID_type)
49 if(type.
id()==ID_symbol)
69 error() <<
"template argument expression expected to be " 70 <<
"scalar constant, but got `" 86 for(instantiation_stackt::const_iterator
92 out <<
"instantiating `" << symbol.
pretty_name <<
"' with <";
94 forall_expr(a_it, s_it->full_template_args.arguments())
96 if(a_it!=s_it->full_template_args.arguments().begin())
99 if(a_it->id()==ID_type)
105 out <<
"> at " << s_it->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;
152 new_symbol.pretty_name=template_symbol.
pretty_name;
153 new_symbol.location=template_symbol.
location;
154 new_symbol.type=
typet(ID_incomplete_struct);
155 new_symbol.type.
set(ID_tag, template_symbol.
type.
find(ID_tag));
157 new_symbol.type.set(ID_C_class,
true);
158 new_symbol.type.set(ID_template_class_instance,
true);
159 new_symbol.type.add_source_location()=template_symbol.
location;
161 "specialization_template_args", specialization_template_args);
162 new_symbol.type.set(
"full_template_args", full_template_args);
163 new_symbol.type.set(ID_identifier, template_symbol.
name);
164 new_symbol.mode=template_symbol.
mode;
165 new_symbol.base_name=template_symbol.
base_name;
166 new_symbol.is_type=
true;
176 id.prefix=template_scope->
prefix+
179 id.class_identifier=s_ptr->
name;
189 if(type.
id()!=ID_symbol)
197 if(t_type.
id()==ID_incomplete_struct &&
198 t_type.
get_bool(ID_template_class_instance))
203 static_cast<const cpp_template_args_tct &>(
204 t_type.
find(
"specialization_template_args")),
205 static_cast<const cpp_template_args_tct &>(
206 t_type.
find(
"full_template_args")));
218 const symbolt &template_symbol,
221 const typet &specialization)
226 error() <<
"reached maximum template recursion depth (" 237 std::cout <<
"L: " << source_location <<
'\n';
238 std::cout <<
"I: " << template_symbol.
name <<
'\n';
243 bool specialization_given=specialization.
is_not_nil();
253 if(it!=specialization_template_args.
arguments().begin())
255 if(it->id()==ID_type)
264 if(full_template_args.
arguments().empty())
268 <<
"' is a template; thus, expected template arguments" 280 if(template_scope==
nullptr)
283 error() <<
"identifier: " << template_symbol.
name <<
'\n' 284 <<
"template instantiation error: scope not found" <<
eom;
294 new_decl.
remove(ID_is_template);
295 new_decl.
remove(ID_template_type);
296 new_decl.
set(ID_C_template, template_symbol.
name);
297 new_decl.
set(ID_C_template_arguments, specialization_template_args);
310 bool is_template_method=
312 new_decl.
type().
id()!=ID_struct;
316 if(is_template_method)
323 cpp_scopest::id_mapt::iterator scope_it=
345 symb.
type.
id()==ID_struct)
364 cpp_scopest::id_mapt::value_type(subscope_name, &sub_scope));
373 instantiated_with.
get_sub().push_back(specialization_template_args);
377 std::cout <<
"MAP:\n";
386 if(specialization_given)
388 if(declaration_type.
id()==ID_struct)
390 declaration_type=specialization;
395 irept tmp=specialization;
401 new_decl.
type().
swap(declaration_type);
404 if(new_decl.
type().
id()==ID_struct)
410 const exprt &template_methods=
411 static_cast<const exprt &
>(
412 template_symbol.
value.
find(
"template_methods"));
414 for(
auto &tm : template_methods.
operands())
420 static_cast<const irept &
>(tm));
436 method_decl.
remove(ID_template_type);
437 method_decl.
remove(ID_is_template);
447 if(is_template_method)
456 error() <<
"invalid use of `virtual' in template declaration" 464 error() <<
"template declaration for typedef" <<
eom;
474 error() <<
"invalid storage class specified for template field" 482 assert(!access.
empty());
483 assert(symb.
type.
id()==ID_struct);
The type of an expression.
irep_idt name
The unique identifier.
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
void apply(exprt &dest) const
const std::string & id2string(const irep_idt &d)
const cpp_storage_spect & storage_spec() const
void lookup(const irep_idt &base_name, lookup_kindt kind, id_sett &id_set)
const std::string integer2string(const mp_integer &n, unsigned base)
void convert_non_template_declaration(cpp_declarationt &declaration)
bool has_unassigned() const
virtual void make_constant(exprt &expr)
irep_idt mode
Language mode.
instantiation_stackt instantiation_stack
exprt::operandst argumentst
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))
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
#define forall_expr(it, expr)
cpp_scopet & get_parent() const
const symbol_typet & to_symbol_type(const typet &type)
Cast a generic typet to a symbol_typet.
void show_instantiation_stack(std::ostream &)
exprt value
Initial value of symbol.
const componentst & components() const
cpp_idt & put_into_scope(const symbolt &symbol, cpp_scopet &scope, bool is_friend=false)
template_mapt template_map
irep_idt pretty_name
Language-specific display name.
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
void build(const template_typet &template_type, const cpp_template_args_tct &template_args)
static mstreamt & eom(mstreamt &m)
bool get_bool(const irep_namet &name) const
cpp_scopet & typecheck_template_parameters(template_typet &type)
const cpp_member_spect & member_spec() const
void convert(cpp_linkage_spect &)
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)
symbol_tablet & symbol_table
virtual symbolt * get_writeable(const irep_idt &name) override
Find a symbol in the symbol table for read-write access.
const irep_idt & id() const
void elaborate_class_template(const typet &type)
elaborate class template instances
const declaratorst & declarators() const
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
source_locationt source_location
const irep_idt & get(const irep_namet &name) const
std::string cpp_type2name(const typet &type)
Base class for tree-like data structures with sharing.
C++ Language Type Checking.
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
std::string template_suffix(const cpp_template_args_tct &template_args)
const source_locationt & source_location() const
typet type
Type of symbol.
source_locationt location
Source code location of definition of symbol.
cpp_declarationt & to_cpp_declaration(irept &irep)
mstreamt & result() const
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)
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
cpp_scopet & current_scope()
source_locationt & add_source_location()
const source_locationt & source_location() const
irept & add(const irep_namet &name)
virtual std::string to_string(const typet &type)
const std::string & get_string(const irep_namet &name) const
cpp_scopet & get_scope(const irep_idt &identifier)
void remove(const irep_namet &name)
template_typet & template_type()
Generic exception types primarily designed for use with invariants.
std::set< cpp_idt * > id_sett
const irept & find(const irep_namet &name) const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().
void set(const irep_namet &name, const irep_idt &value)
void add_using_scope(cpp_scopet &other)
void print(std::ostream &out) const