Go to the documentation of this file.
32 for(std::size_t i=0; i<new_parameters.size(); i++)
34 if(i<old_parameters.size() &&
35 old_parameters[i].has_default_argument() &&
36 !new_parameters[i].has_default_argument())
39 new_parameters[i].default_argument()=old_parameters[i].default_argument();
62 error() <<
"class templates must not be anonymous" <<
eom;
69 error() <<
"simple name expected as class template tag" <<
eom;
80 base_name, template_type, partial_specialization_args);
90 cpp_scopet::TEMPLATE);
94 const symbolt &previous=
lookup((*id_set.begin())->identifier);
95 if(previous.
name!=symbol_name || id_set.
size()>1)
98 str <<
"template declaration of '" << base_name.
c_str()
99 <<
" does not match previous declaration\n";
100 str <<
"location of previous definition: " << previous.
location;
112 symbolt &previous_symbol=*maybe_symbol;
116 bool previous_has_body=
120 if(has_body && previous_has_body)
123 error() <<
"template struct '" << base_name <<
"' defined previously\n"
124 <<
"location of previous definition: " << previous_symbol.
location
137 previous_symbol.
type.
swap(declaration);
140 std::cout <<
"*****\n";
142 std::cout <<
"*****\n";
143 std::cout <<
"II: " << symbol_name <<
'\n';
162 "symbol should be in template scope");
171 symbol.
name=symbol_name;
187 error() <<
"cpp_typecheckt::typecheck_compound_type: "
188 <<
"symbol_table.move() failed"
204 "symbol should be in template scope");
224 error() <<
"function template must have simple name" <<
eom;
247 symbol_tablet::symbolst::const_iterator previous_symbol=
252 bool previous_has_value =
256 if(has_value && previous_has_value)
259 error() <<
"function template symbol '" << base_name
260 <<
"' declared previously\n"
261 <<
"location of previous definition: "
262 << previous_symbol->second.location <<
eom;
278 symbol.
name=symbol_name;
293 error() <<
"cpp_typecheckt::typecheck_compound_type: "
294 <<
"symbol_table.move() failed"
325 if(cpp_name.
get_sub().size()==4 &&
326 cpp_name.
get_sub()[0].id()==ID_name &&
327 cpp_name.
get_sub()[1].id()==ID_template_args &&
328 cpp_name.
get_sub()[2].id()==
"::" &&
329 cpp_name.
get_sub()[3].id()==ID_name)
332 else if(cpp_name.
get_sub().size()==5 &&
333 cpp_name.
get_sub()[0].id()==ID_name &&
334 cpp_name.
get_sub()[1].id()==ID_template_args &&
335 cpp_name.
get_sub()[2].id()==
"::" &&
336 cpp_name.
get_sub()[3].id()==ID_operator)
345 error() <<
"bad template name" <<
eom;
352 cpp_name.
get_sub().front().get(ID_identifier),
360 error() <<
"class template '"
361 << cpp_name.
get_sub().front().get(ID_identifier) <<
"' not found"
365 else if(id_set.size()>1)
368 error() <<
"class template '"
369 << cpp_name.
get_sub().front().get(ID_identifier) <<
"' is ambiguous"
377 error() <<
"class template '"
378 << cpp_name.
get_sub().front().get(ID_identifier)
379 <<
"' is not a template" <<
eom;
383 const cpp_idt &cpp_id=**(id_set.begin());
386 exprt &template_methods =
387 static_cast<exprt &
>(template_symbol.
value.
add(ID_template_methods));
394 const irept &instantiated_with =
395 template_symbol.
value.
add(ID_instantiated_with);
397 for(std::size_t i=0; i<instantiated_with.
get_sub().size(); i++)
401 instantiated_with.
get_sub()[i]);
415 decl_tmp.
remove(ID_template_type);
416 decl_tmp.
remove(ID_is_template);
428 std::string identifier=
436 for(template_typet::template_parameterst::const_iterator
444 if(it->id()==ID_type)
454 if(!partial_specialization_args.
arguments().empty())
456 identifier+=
"_specialized_to_<";
459 for(cpp_template_args_non_tct::argumentst::const_iterator
460 it=partial_specialization_args.
arguments().begin();
461 it!=partial_specialization_args.
arguments().end();
470 if(it->id() == ID_type || it->id() == ID_ambiguous)
485 const typet &function_type)
489 std::string identifier=
491 partial_specialization_args);
506 assert(type.
id()==ID_struct);
514 error() <<
"qualifiers not expected here" <<
eom;
518 if(cpp_name.
get_sub().size()!=2 ||
519 cpp_name.
get_sub()[0].id()!=ID_name ||
520 cpp_name.
get_sub()[1].id()!=ID_template_args)
525 error() <<
"bad template-class-specialization name" <<
eom;
530 cpp_name.
get_sub()[0].get(ID_identifier);
545 for(cpp_scopest::id_sett::iterator
550 cpp_scopest::id_sett::iterator next=it;
553 if(
lookup((*it)->identifier).type.find(ID_specialization_of).is_not_nil())
563 error() <<
"class template '" << base_name <<
"' not found" <<
eom;
566 else if(id_set.size()>1)
569 error() <<
"class template '" << base_name <<
"' is ambiguous" <<
eom;
573 symbol_tablet::symbolst::const_iterator s_it=
578 const symbolt &template_symbol=s_it->second;
583 error() <<
"expected a template" <<
eom;
595 template_args_non_tc);
623 declaration.
declarators().front().type().id()!=ID_function_type)
626 error() <<
"expected function template specialization" <<
eom;
637 assert(!cpp_name.
get_sub().empty());
639 if(cpp_name.
get_sub().back().id()==ID_template_args)
642 if(cpp_name.
get_sub().size()!=2 ||
643 cpp_name.
get_sub()[0].id()!=ID_name ||
644 cpp_name.
get_sub()[1].id()!=ID_template_args)
649 error() <<
"bad template-function-specialization name" <<
eom;
653 std::string base_name=
654 cpp_name.
get_sub()[0].get(ID_identifier).c_str();
662 error() <<
"template function '" << base_name <<
"' not found" <<
eom;
665 else if(id_set.size()>1)
668 error() <<
"template function '" << base_name <<
"' is ambiguous" <<
eom;
672 const symbolt &template_symbol=
673 lookup((*id_set.begin())->identifier);
683 typet specialization;
684 specialization.
swap(declarator);
700 new_declaration.
remove(ID_template_type);
701 new_declaration.
remove(ID_is_template);
702 new_declaration.
set(ID_C_template,
"");
713 assert(type.
id()==ID_template);
727 unsigned anon_count=0;
729 for(template_typet::template_parameterst::iterator
730 it=parameters.begin();
731 it!=parameters.end();
734 exprt ¶meter=*it;
756 error() <<
"template parameter must be simple name" <<
eom;
771 if(declaration.
get_bool(ID_is_type))
787 parameter.
add(ID_C_default_value)=declarator.
value();
803 cpp_declarator_converter.
convert(declaration, declarator);
815 parameter.
add(ID_C_default_value)=default_value;
821 return template_scope;
828 const symbolt &template_symbol,
849 if(parameters.size()<args.size())
852 error() <<
"too many template arguments (expected "
853 << parameters.size() <<
", but got "
854 << args.size() <<
")" <<
eom;
863 for(std::size_t i=0; i<parameters.size(); i++)
875 error() <<
"not enough template arguments (expected "
876 << parameters.size() <<
", but got " << args.size()
891 assert(i<args.size());
895 if(parameter.
id()==ID_type)
897 if(arg.
id()==ID_type)
901 else if(arg.
id() == ID_ambiguous)
905 arg=
exprt(ID_type, t);
910 error() <<
"expected type, but got expression" <<
eom;
916 if(arg.
id()==ID_type)
919 error() <<
"expected expression, but got type" <<
eom;
922 else if(arg.
id() == ID_ambiguous)
938 template_scope!=
nullptr,
940 "template_scope is null");
962 assert(args.size()==parameters.size());
975 error() <<
"invalid use of 'virtual' in template declaration"
983 error() <<
"template declaration for typedef" <<
eom;
1001 error() <<
"class template not expected to have declarators"
1007 if(type.
id()!=ID_struct)
1010 error() <<
"expected class template" <<
eom;
1018 type.
find(ID_tag))).has_template_args())
1035 error() <<
"non-class template is expected to have a declarator"
class cpp_scopet & new_scope(const irep_idt &new_scope_name)
void convert(cpp_linkage_spect &)
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
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 char * c_str() const
void salvage_default_arguments(const template_typet &old_type, template_typet &new_type)
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
The type of an expression, extends irept.
cpp_template_args_non_tct & to_cpp_template_args_non_tc(irept &irep)
cpp_declarationt & to_cpp_declaration(irept &irep)
const irept & find(const irep_idt &name) const
typet type
Type of symbol.
void typecheck_class_template(cpp_declarationt &declaration)
cpp_scopet & typecheck_template_parameters(template_typet &type)
a template parameter symbol that is a type
symbolt & convert(const typet &type, const cpp_storage_spect &storage_spec, const cpp_member_spect &member_spec, cpp_declaratort &declarator)
Base class for all expressions.
cpp_template_args_non_tct & partial_specialization_args()
irep_idt base_name
Base (non-scoped) name.
void convert_class_template_specialization(cpp_declarationt &declaration)
A struct tag type, i.e., struct_typet with an identifier.
unsigned template_counter
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
bool is_class_template() const
Expression to hold a symbol (variable)
cpp_idt & put_into_scope(const symbolt &symbol, cpp_scopet &scope, bool is_friend=false)
const declaratorst & declarators() const
const cpp_member_spect & member_spec() const
std::string class_template_identifier(const irep_idt &base_name, const template_typet &template_type, const cpp_template_args_non_tct &partial_specialization_args)
irep_idt pretty_name
Language-specific display name.
void swap(template_mapt &template_map)
typet & type()
Return the type of the expression.
std::string function_template_identifier(const irep_idt &base_name, const template_typet &template_type, const typet &function_type)
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void typecheck_type(typet &) override
void typecheck_class_template_member(cpp_declarationt &declaration)
typecheck class template members; these can be methods or static members
irep_idt mode
Language mode.
mstreamt & result() const
void typecheck_function_template(cpp_declarationt &declaration)
typecheck function templates
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 set(const irep_idt &name, const irep_idt &value)
template_parameterst & template_parameters()
#define PRECONDITION(CONDITION)
const source_locationt & source_location() const
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
std::vector< template_parametert > template_parameterst
bool is_simple_name() const
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
bool simplify(exprt &expr, const namespacet &ns)
symbol_tablet & symbol_table
bool is_template_parameter
void set_specialization_of(const irep_idt &id)
const irep_idt & id() const
source_locationt & add_source_location()
void convert_template_declaration(cpp_declarationt &declaration)
bool is_qualified() const
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
void cpp_convert_plain_type(typet &type, message_handlert &message_handler)
cpp_template_args_tct typecheck_template_args(const source_locationt &source_location, const symbolt &template_symbol, const cpp_template_args_non_tct &template_args)
virtual symbolt * get_writeable(const irep_idt &name) override
Find a symbol in the symbol table for read-write access.
void typecheck_expr(exprt &) override
exprt value
Initial value of symbol.
message_handlert & get_message_handler()
An expression denoting a type.
bool has_default_argument() const
bool has_template_args() const
irept & add(const irep_idt &name)
const source_locationt & source_location() const
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.
exprt & default_argument()
const symbolst & symbols
Read-only field, used to look up symbols given their names.
void implicit_typecast(exprt &expr, const typet &type) override
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
void set(const template_parametert ¶meter, const exprt &value)
There are a large number of kinds of tree structured or tree-like data in CPROVER.
exprt::operandst argumentst
void convert_template_function_or_member_specialization(cpp_declarationt &declaration)
void build(const template_typet &template_type, const cpp_template_args_tct &template_args)
std::string cpp_expr2name(const exprt &expr)
void remove(const irep_idt &name)
source_locationt & add_source_location()
irep_idt module
Name of module the symbol belongs to.
irep_idt get_base_name() const
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()
cpp_idt & insert(const irep_idt &_base_name)
typet merge_type(const typet &declaration_type) const