Skip to content

Commit b40a351

Browse files
committed
Use strong enum in cpp_id.h
1 parent 166c2bd commit b40a351

14 files changed

+91
-81
lines changed

src/cpp/cpp_declarator_converter.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ symbolt &cpp_declarator_convertert::convert(
100100
get_final_identifier();
101101

102102
// first see if it is a member
103-
if(scope->id_class==cpp_idt::CLASS && !is_friend)
103+
if(scope->id_class==cpp_idt::id_classt::CLASS && !is_friend)
104104
{
105105
// it's a member! it must be declared already
106106

@@ -238,13 +238,13 @@ symbolt &cpp_declarator_convertert::convert(
238238
cpp_scopet::id_sett id_set;
239239

240240
scope->lookup_identifier(
241-
symbol.name, cpp_idt::TEMPLATE_PARAMETER, id_set);
241+
symbol.name, cpp_idt::id_classt::TEMPLATE_PARAMETER, id_set);
242242

243243
if(id_set.empty())
244244
{
245245
cpp_idt &identifier=
246246
cpp_typecheck.cpp_scopes.put_into_scope(symbol, *scope);
247-
identifier.id_class=cpp_idt::TEMPLATE_PARAMETER;
247+
identifier.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER;
248248
}
249249
}
250250

@@ -618,13 +618,13 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
618618
cpp_typecheck.cpp_scopes.put_into_scope(*new_symbol, *scope, is_friend);
619619

620620
if(is_template)
621-
identifier.id_class=cpp_idt::TEMPLATE;
621+
identifier.id_class=cpp_idt::id_classt::TEMPLATE;
622622
else if(is_template_parameter)
623-
identifier.id_class=cpp_idt::TEMPLATE_PARAMETER;
623+
identifier.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER;
624624
else if(is_typedef)
625-
identifier.id_class=cpp_idt::TYPEDEF;
625+
identifier.id_class=cpp_idt::id_classt::TYPEDEF;
626626
else
627-
identifier.id_class=cpp_idt::SYMBOL;
627+
identifier.id_class=cpp_idt::id_classt::SYMBOL;
628628

629629
// do the value
630630
if(!new_symbol->is_type)

src/cpp/cpp_id.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cpp_idt::cpp_idt():
2929
is_static_member(false),
3030
is_scope(false),
3131
is_constructor(false),
32-
id_class(UNKNOWN),
32+
id_class(id_classt::UNKNOWN),
3333
this_expr(static_cast<const exprt &>(get_nil_irep())),
3434
compound_counter(0),
3535
parent(NULL)
@@ -163,20 +163,16 @@ std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class)
163163
{
164164
switch(id_class)
165165
{
166-
case cpp_idt::UNKNOWN: out << "UNKNOWN"; break;
167-
case cpp_idt::SYMBOL: out << "SYMBOL"; break;
168-
case cpp_idt::TYPEDEF: out << "TYPEDEF"; break;
169-
case cpp_idt::CLASS: out << "CLASS"; break;
170-
case cpp_idt::TEMPLATE: out << "TEMPLATE"; break;
171-
case cpp_idt::TEMPLATE_PARAMETER: out << "TEMPLATE_PARAMETER"; break;
172-
case cpp_idt::ROOT_SCOPE: out << "ROOT_SCOPE"; break;
173-
case cpp_idt::BLOCK_SCOPE: out << "BLOCK_SCOPE"; break;
174-
case cpp_idt::TEMPLATE_SCOPE: out << "TEMPLATE_SCOPE"; break;
175-
case cpp_idt::NAMESPACE: out << "NAMESPACE"; break;
176-
177-
default:
178-
out << "(OTHER)";
166+
case cpp_idt::id_classt::UNKNOWN: return out<<"UNKNOWN";
167+
case cpp_idt::id_classt::SYMBOL: return out<<"SYMBOL";
168+
case cpp_idt::id_classt::TYPEDEF: return out<<"TYPEDEF";
169+
case cpp_idt::id_classt::CLASS: return out<<"CLASS";
170+
case cpp_idt::id_classt::TEMPLATE: return out<<"TEMPLATE";
171+
case cpp_idt::id_classt::TEMPLATE_PARAMETER:return out<<"TEMPLATE_PARAMETER";
172+
case cpp_idt::id_classt::ROOT_SCOPE: return out<<"ROOT_SCOPE";
173+
case cpp_idt::id_classt::BLOCK_SCOPE: return out<<"BLOCK_SCOPE";
174+
case cpp_idt::id_classt::TEMPLATE_SCOPE: return out<<"TEMPLATE_SCOPE";
175+
case cpp_idt::id_classt::NAMESPACE: return out<<"NAMESPACE";
176+
default: return out << "(OTHER)";
179177
}
180-
181-
return out;
182178
}

src/cpp/cpp_id.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ class cpp_idt
2626
public:
2727
cpp_idt();
2828

29-
typedef enum
29+
enum class id_classt
3030
{
31-
UNKNOWN, SYMBOL, TYPEDEF, CLASS, ENUM, TEMPLATE,
32-
TEMPLATE_PARAMETER, NAMESPACE, BLOCK_SCOPE,
33-
TEMPLATE_SCOPE, ROOT_SCOPE
34-
} id_classt;
31+
UNKNOWN,
32+
SYMBOL,
33+
TYPEDEF,
34+
CLASS,
35+
ENUM,
36+
TEMPLATE,
37+
TEMPLATE_PARAMETER,
38+
NAMESPACE,
39+
BLOCK_SCOPE,
40+
TEMPLATE_SCOPE,
41+
ROOT_SCOPE,
42+
};
3543

3644
bool is_member, is_method, is_static_member,
3745
is_scope, is_constructor;
@@ -40,22 +48,22 @@ class cpp_idt
4048

4149
bool is_class() const
4250
{
43-
return id_class==CLASS;
51+
return id_class==id_classt::CLASS;
4452
}
4553

4654
bool is_enum() const
4755
{
48-
return id_class==ENUM;
56+
return id_class==id_classt::ENUM;
4957
}
5058

5159
bool is_namespace() const
5260
{
53-
return id_class==NAMESPACE;
61+
return id_class==id_classt::NAMESPACE;
5462
}
5563

5664
bool is_typedef() const
5765
{
58-
return id_class==TYPEDEF;
66+
return id_class==id_classt::TYPEDEF;
5967
}
6068

6169
irep_idt identifier, base_name;

src/cpp/cpp_instantiate_template.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ const symbolt &cpp_typecheckt::class_template_symbol(
201201
// put into template scope
202202
cpp_idt &id=cpp_scopes.put_into_scope(*s_ptr, *template_scope);
203203

204-
id.id_class=cpp_idt::CLASS;
204+
id.id_class=cpp_idt::id_classt::CLASS;
205205
id.is_scope=true;
206206
id.prefix=template_scope->prefix+
207207
id2string(s_ptr->base_name)+
208208
id2string(suffix)+"::";
209209
id.class_identifier=s_ptr->name;
210-
id.id_class=cpp_idt::CLASS;
210+
id.id_class=cpp_idt::id_classt::CLASS;
211211

212212
return *s_ptr;
213213
}
@@ -390,13 +390,13 @@ const symbolt &cpp_typecheckt::instantiate_template(
390390
// It has already been instantianted!
391391
const cpp_idt &cpp_id = **id_set.begin();
392392

393-
assert(cpp_id.id_class == cpp_idt::CLASS ||
394-
cpp_id.id_class == cpp_idt::SYMBOL);
393+
assert(cpp_id.id_class == cpp_idt::id_classt::CLASS ||
394+
cpp_id.id_class == cpp_idt::id_classt::SYMBOL);
395395

396396
const symbolt &symb=lookup(cpp_id.identifier);
397397

398398
// continue if the type is incomplete only
399-
if(cpp_id.id_class==cpp_idt::CLASS &&
399+
if(cpp_id.id_class==cpp_idt::id_classt::CLASS &&
400400
symb.type.id()==ID_struct)
401401
return symb;
402402
else if(symb.value.is_not_nil())
@@ -410,7 +410,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
410410
// set up a scope as subscope of the template scope
411411
cpp_scopet &sub_scope=
412412
cpp_scopes.current_scope().new_scope(subscope_name);
413-
sub_scope.id_class=cpp_idt::TEMPLATE_SCOPE;
413+
sub_scope.id_class=cpp_idt::id_classt::TEMPLATE_SCOPE;
414414
sub_scope.prefix=template_scope->get_parent().prefix;
415415
sub_scope.suffix=suffix;
416416
sub_scope.add_using_scope(template_scope->get_parent());

src/cpp/cpp_scope.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void cpp_scopet::lookup(
175175
}
176176

177177
if(!id_set.empty() &&
178-
id_class!=TEMPLATE) return; // done, upwards scopes are hidden
178+
id_class!=id_classt::TEMPLATE) return; // done, upwards scopes are hidden
179179

180180
// secondary scopes
181181
for(scope_listt::iterator
@@ -194,7 +194,7 @@ void cpp_scopet::lookup(
194194
return; // done
195195

196196
if(!id_set.empty() &&
197-
id_class!=TEMPLATE) return; // done, upwards scopes are hidden
197+
id_class!=id_classt::TEMPLATE) return; // done, upwards scopes are hidden
198198

199199
// ask parent, recursive call
200200
if(!is_root_scope())

src/cpp/cpp_scope.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,18 @@ class cpp_scopet:public cpp_idt
6969

7070
bool is_root_scope() const
7171
{
72-
return id_class==ROOT_SCOPE;
72+
return id_class==id_classt::ROOT_SCOPE;
7373
}
7474

7575
bool is_global_scope() const
7676
{
77-
return id_class==ROOT_SCOPE ||
78-
id_class==NAMESPACE;
77+
return id_class==id_classt::ROOT_SCOPE ||
78+
id_class==id_classt::NAMESPACE;
7979
}
8080

8181
bool is_template_scope() const
8282
{
83-
return id_class==TEMPLATE_SCOPE;
83+
return id_class==id_classt::TEMPLATE_SCOPE;
8484
}
8585

8686
cpp_scopet &get_parent() const
@@ -118,7 +118,7 @@ class cpp_root_scopet:public cpp_scopet
118118
public:
119119
cpp_root_scopet()
120120
{
121-
id_class=ROOT_SCOPE;
121+
id_class=id_classt::ROOT_SCOPE;
122122
identifier="::";
123123
}
124124
};

src/cpp/cpp_scopes.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Function: cpp_scopest::new_block_scope
2626
cpp_scopet &cpp_scopest::new_block_scope()
2727
{
2828
unsigned prefix=++current_scope().compound_counter;
29-
return new_scope(std::to_string(prefix), cpp_idt::BLOCK_SCOPE);
29+
return new_scope(std::to_string(prefix), cpp_idt::id_classt::BLOCK_SCOPE);
3030
}
3131

3232
/*******************************************************************\
@@ -57,7 +57,7 @@ cpp_idt &cpp_scopest::put_into_scope(
5757
{
5858
irep_idt block_base_name(std::string("$block:")+symbol.base_name.c_str());
5959
cpp_idt &id = scope.insert(block_base_name);
60-
id.id_class=cpp_idt::BLOCK_SCOPE;
60+
id.id_class=cpp_idt::id_classt::BLOCK_SCOPE;
6161
id.identifier=symbol.name;
6262
id.is_scope=true;
6363
id.prefix = id2string(scope.prefix) + id2string(symbol.base_name) + "::";
@@ -74,7 +74,7 @@ cpp_idt &cpp_scopest::put_into_scope(
7474

7575
cpp_idt &id=current_scope().insert(symbol.base_name);
7676
id.identifier=symbol.name;
77-
id.id_class = cpp_idt::SYMBOL;
77+
id.id_class = cpp_idt::id_classt::SYMBOL;
7878
if(id_map.find(symbol.name)==id_map.end())
7979
id_map[symbol.name]=&id;
8080
return id;
@@ -83,7 +83,7 @@ cpp_idt &cpp_scopest::put_into_scope(
8383
{
8484
cpp_idt &id=scope.insert(symbol.base_name);
8585
id.identifier=symbol.name;
86-
id.id_class = cpp_idt::SYMBOL;
86+
id.id_class = cpp_idt::id_classt::SYMBOL;
8787
if(id_map.find(symbol.name)==id_map.end())
8888
id_map[symbol.name]=&id;
8989
return id;

src/cpp/cpp_scopes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class cpp_scopest
4646

4747
cpp_scopet &new_namespace(const irep_idt &new_scope_name)
4848
{
49-
return new_scope(new_scope_name, cpp_idt::NAMESPACE);
49+
return new_scope(new_scope_name, cpp_idt::id_classt::NAMESPACE);
5050
}
5151

5252
cpp_scopet &new_block_scope();

src/cpp/cpp_typecheck_compound_type.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ void cpp_typecheckt::typecheck_compound_type(
269269
// put into dest_scope
270270
cpp_idt &id=cpp_scopes.put_into_scope(*new_symbol, *dest_scope);
271271

272-
id.id_class=cpp_idt::CLASS;
272+
id.id_class=cpp_idt::id_classt::CLASS;
273273
id.is_scope=true;
274274
id.prefix=cpp_scopes.current_scope().prefix+
275275
id2string(new_symbol->base_name)+
276276
cpp_scopes.current_scope().suffix+"::";
277277
id.class_identifier=new_symbol->name;
278-
id.id_class=cpp_idt::CLASS;
278+
id.id_class=cpp_idt::id_classt::CLASS;
279279

280280
if(has_body)
281281
typecheck_compound_body(*new_symbol);
@@ -856,7 +856,9 @@ void cpp_typecheckt::put_compound_into_scope(
856856
{
857857
// put the symbol into scope
858858
cpp_idt &id=cpp_scopes.current_scope().insert(base_name);
859-
id.id_class=compound.get_bool("is_type")?cpp_idt::TYPEDEF:cpp_idt::SYMBOL;
859+
id.id_class=compound.get_bool("is_type")?
860+
cpp_idt::id_classt::TYPEDEF:
861+
cpp_idt::id_classt::SYMBOL;
860862
id.identifier=name;
861863
id.class_identifier=cpp_scopes.current_scope().identifier;
862864
id.is_member=true;
@@ -870,7 +872,7 @@ void cpp_typecheckt::put_compound_into_scope(
870872
cpp_scopes.current_scope().insert(
871873
irep_idt(std::string("$block:") + base_name.c_str()));
872874

873-
id_block.id_class=cpp_idt::BLOCK_SCOPE;
875+
id_block.id_class=cpp_idt::id_classt::BLOCK_SCOPE;
874876
id_block.identifier=name;
875877
id_block.class_identifier=cpp_scopes.current_scope().identifier;
876878
id_block.is_method=true;
@@ -905,7 +907,9 @@ void cpp_typecheckt::put_compound_into_scope(
905907

906908
// put into the scope
907909
cpp_idt &id=cpp_scopes.current_scope().insert(base_name);
908-
id.id_class=compound.get_bool(ID_is_type)?cpp_idt::TYPEDEF:cpp_idt::SYMBOL;
910+
id.id_class=compound.get_bool(ID_is_type)?
911+
cpp_idt::id_classt::TYPEDEF:
912+
cpp_idt::id_classt::SYMBOL;
909913
id.identifier=name;
910914
id.class_identifier=cpp_scopes.current_scope().identifier;
911915
id.is_member=true;
@@ -1545,7 +1549,7 @@ void cpp_typecheckt::add_anonymous_members_to_scope(
15451549
}
15461550

15471551
cpp_idt &id=cpp_scopes.current_scope().insert(base_name);
1548-
id.id_class=cpp_idt::SYMBOL;
1552+
id.id_class=cpp_idt::id_classt::SYMBOL;
15491553
id.identifier=comp.get_name();
15501554
id.class_identifier=struct_union_symbol.name;
15511555
id.is_member=true;

src/cpp/cpp_typecheck_declaration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void cpp_typecheckt::convert_anonymous_union(
118118
}
119119

120120
cpp_idt &id=cpp_scopes.current_scope().insert(base_name);
121-
id.id_class = cpp_idt::SYMBOL;
121+
id.id_class = cpp_idt::id_classt::SYMBOL;
122122
id.identifier=it->get(ID_name);
123123
id.class_identifier=union_symbol.name;
124124
id.is_member=true;

src/cpp/cpp_typecheck_enum_type.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol)
8383
cpp_idt &scope_identifier=
8484
cpp_scopes.put_into_scope(*new_symbol);
8585

86-
scope_identifier.id_class=cpp_idt::SYMBOL;
86+
scope_identifier.id_class=cpp_idt::id_classt::SYMBOL;
8787

8888
++i;
8989
}
@@ -212,7 +212,7 @@ void cpp_typecheckt::typecheck_enum_type(typet &type)
212212
cpp_idt &scope_identifier=
213213
cpp_scopes.put_into_scope(*new_symbol, dest_scope);
214214

215-
scope_identifier.id_class=cpp_idt::CLASS;
215+
scope_identifier.id_class=cpp_idt::id_classt::CLASS;
216216

217217
typecheck_enum_body(*new_symbol);
218218
}

0 commit comments

Comments
 (0)