Skip to content

Commit a2cff1e

Browse files
authored
Merge pull request #3740 from diffblue/cpp-template_parameter_symbol_type-only
C++: introduce template parameter symbol type
2 parents e1e2009 + 7fd2cf7 commit a2cff1e

5 files changed

+52
-7
lines changed

src/cpp/cpp_template_parameter.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,48 @@ struct template_parametert:public exprt
6161
}
6262
};
6363

64+
/// a template parameter symbol that is a type
65+
struct template_parameter_symbol_typet : public typet
66+
{
67+
public:
68+
explicit template_parameter_symbol_typet(const irep_idt &identifier)
69+
: typet(ID_template_parameter_symbol_type)
70+
{
71+
set_identifier(identifier);
72+
}
73+
74+
void set_identifier(const irep_idt &identifier)
75+
{
76+
set(ID_identifier, identifier);
77+
}
78+
79+
const irep_idt &get_identifier() const
80+
{
81+
return get(ID_identifier);
82+
}
83+
};
84+
85+
/// \brief Cast a typet to a \ref template_parameter_symbol_typet.
86+
///
87+
/// This is an unchecked conversion. \a type must be known to be
88+
/// \ref template_parameter_symbol_typet. Will fail with a
89+
/// precondition violation if type doesn't match.
90+
///
91+
/// \param type: Source type.
92+
/// \return Object of type \ref template_parameter_symbol_typet.
93+
inline const template_parameter_symbol_typet &
94+
to_template_parameter_symbol_type(const typet &type)
95+
{
96+
PRECONDITION(type.id() == ID_template_parameter_symbol_type);
97+
return static_cast<const template_parameter_symbol_typet &>(type);
98+
}
99+
100+
/// \copydoc to_template_parameter_symbol_type(const typet &)
101+
inline template_parameter_symbol_typet &
102+
to_template_parameter_symbol_type(typet &type)
103+
{
104+
PRECONDITION(type.id() == ID_template_parameter_symbol_type);
105+
return static_cast<template_parameter_symbol_typet &>(type);
106+
}
107+
64108
#endif // CPROVER_CPP_CPP_TEMPLATE_PARAMETER_H

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,9 +2283,9 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
22832283
if(e.id()!=ID_type)
22842284
continue; // expressions are definitively not a scope
22852285

2286-
if(e.type().id() == ID_symbol_type)
2286+
if(e.type().id() == ID_template_parameter_symbol_type)
22872287
{
2288-
symbol_typet type=to_symbol_type(e.type());
2288+
auto type = to_template_parameter_symbol_type(e.type());
22892289

22902290
while(true)
22912291
{
@@ -2294,8 +2294,8 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
22942294
const symbolt &symbol=cpp_typecheck.lookup(identifier);
22952295
assert(symbol.is_type);
22962296

2297-
if(symbol.type.id() == ID_symbol_type)
2298-
type=to_symbol_type(symbol.type);
2297+
if(symbol.type.id() == ID_template_parameter_symbol_type)
2298+
type = to_template_parameter_symbol_type(symbol.type);
22992299
else if(symbol.type.id()==ID_struct ||
23002300
symbol.type.id()==ID_union ||
23012301
symbol.type.id()==ID_c_enum)

src/cpp/cpp_typecheck_template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters(
774774
// is it a type or not?
775775
if(declaration.get_bool(ID_is_type))
776776
{
777-
parameter = exprt(ID_type, symbol_typet(identifier));
777+
parameter = type_exprt(template_parameter_symbol_typet(identifier));
778778
parameter.type().add_source_location()=declaration.find_source_location();
779779
}
780780
else

src/cpp/template_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ void template_mapt::apply(typet &type) const
3737
apply(subtype);
3838
}
3939
}
40-
else if(type.id() == ID_symbol_type)
40+
else if(type.id() == ID_template_parameter_symbol_type)
4141
{
4242
type_mapt::const_iterator m_it =
43-
type_map.find(to_symbol_type(type).get_identifier());
43+
type_map.find(to_template_parameter_symbol_type(type).get_identifier());
4444

4545
if(m_it!=type_map.end())
4646
{

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ IREP_ID_ONE(template_function_instance)
414414
IREP_ID_ONE(template_type)
415415
IREP_ID_ONE(template_args)
416416
IREP_ID_ONE(template_parameter)
417+
IREP_ID_ONE(template_parameter_symbol_type)
417418
IREP_ID_ONE(template_parameters)
418419
IREP_ID_TWO(C_template, #template)
419420
IREP_ID_TWO(C_template_arguments, #template_arguments)

0 commit comments

Comments
 (0)