Skip to content

Commit 56ca42a

Browse files
authored
Merge pull request #3741 from diffblue/cpp-tag-types
C++: use struct and union tag types
2 parents a2cff1e + dda0a18 commit 56ca42a

6 files changed

+21
-33
lines changed

src/cpp/cpp_instantiate_template.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ const symbolt &cpp_typecheckt::class_template_symbol(
187187
void cpp_typecheckt::elaborate_class_template(
188188
const typet &type)
189189
{
190-
if(type.id() != ID_symbol_type)
190+
if(type.id() != ID_struct_tag)
191191
return;
192192

193-
const symbolt &symbol = lookup(to_symbol_type(type));
193+
const symbolt &symbol = lookup(to_struct_tag_type(type));
194194

195195
// Make a copy, as instantiate will destroy the symbol type!
196196
const typet t_type=symbol.type;

src/cpp/cpp_typecheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class cpp_typecheckt:public c_typecheck_baset
222222

223223
void elaborate_class_template(
224224
const source_locationt &source_location,
225-
const symbol_typet &type);
225+
const struct_tag_typet &type);
226226

227227
unsigned template_counter;
228228
unsigned anon_counter;

src/cpp/cpp_typecheck_constructor.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void cpp_typecheckt::default_assignop(
292292
std::string arg_name("ref");
293293

294294
cpctor.add(ID_storage_spec).id(ID_cpp_storage_spec);
295-
cpctor.type().id(ID_symbol_type);
295+
cpctor.type().id(ID_struct_tag);
296296
cpctor.type().add(ID_identifier).id(symbol.name);
297297
cpctor.operands().push_back(exprt(ID_cpp_declarator));
298298
cpctor.add_source_location()=source_location;
@@ -488,7 +488,7 @@ void cpp_typecheckt::check_member_initializers(
488488
// Maybe it is a parent constructor?
489489
if(c.get_bool(ID_is_type))
490490
{
491-
if(c.type().id() != ID_symbol_type)
491+
if(c.type().id() != ID_struct_tag)
492492
continue;
493493

494494
const symbolt &symb = lookup(to_symbol_type(c.type()).get_identifier());
@@ -646,7 +646,7 @@ void cpp_typecheckt::full_member_initialization(
646646

647647
typecheck_type(member_type);
648648

649-
if(member_type.id() != ID_symbol_type)
649+
if(member_type.id() != ID_struct_tag)
650650
break;
651651

652652
if(

src/cpp/cpp_typecheck_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr)
583583
// TODO: need to resolve an incomplete struct (template) here
584584
// go into scope of first operand
585585
if(
586-
expr.op0().type().id() == ID_symbol_type &&
586+
expr.op0().type().id() == ID_struct_tag &&
587587
follow(expr.op0().type()).id() == ID_struct)
588588
{
589589
const irep_idt &struct_identifier=

src/cpp/cpp_typecheck_resolve.cpp

+13-25
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,13 @@ exprt cpp_typecheck_resolvet::convert_identifier(
337337
{
338338
e.type()=c_enum_tag_typet(symbol.name);
339339
}
340-
else // will need to do struct, union
340+
else if(symbol.type.id() == ID_struct)
341341
{
342-
e.type()=symbol_typet(symbol.name);
342+
e.type() = struct_tag_typet(symbol.name);
343+
}
344+
else if(symbol.type.id() == ID_union)
345+
{
346+
e.type() = union_tag_typet(symbol.name);
343347
}
344348
}
345349
else if(symbol.is_macro)
@@ -908,7 +912,7 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
908912
cpp_typecheck.cpp_scopes.current_scope().print(std::cout);
909913
std::cout << "X: " << id_set.size() << '\n';
910914
#endif
911-
symbol_typet instance=
915+
struct_tag_typet instance =
912916
disambiguate_template_classes(final_base_name, id_set, template_args);
913917

914918
instance.add_source_location()=source_location;
@@ -954,7 +958,7 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
954958
// the "::" triggers template elaboration
955959
if(!cpp_typecheck.cpp_scopes.current_scope().class_identifier.empty())
956960
{
957-
symbol_typet instance(
961+
struct_tag_typet instance(
958962
cpp_typecheck.cpp_scopes.current_scope().class_identifier);
959963
cpp_typecheck.elaborate_class_template(instance);
960964
}
@@ -996,7 +1000,7 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
9961000
}
9971001

9981002
/// disambiguate partial specialization
999-
symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
1003+
struct_tag_typet cpp_typecheck_resolvet::disambiguate_template_classes(
10001004
const irep_idt &base_name,
10011005
const cpp_scopest::id_sett &id_set,
10021006
const cpp_template_args_non_tct &full_template_args)
@@ -1192,7 +1196,7 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
11921196
throw 0;
11931197
}
11941198

1195-
symbol_typet result(instance.name);
1199+
struct_tag_typet result(instance.name);
11961200
result.add_source_location()=source_location;
11971201

11981202
return result;
@@ -1206,7 +1210,7 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
12061210
match.specialization_args,
12071211
match.full_args);
12081212

1209-
symbol_typet result(instance.name);
1213+
struct_tag_typet result(instance.name);
12101214
result.add_source_location()=source_location;
12111215

12121216
return result;
@@ -2072,7 +2076,7 @@ void cpp_typecheck_resolvet::apply_template_args(
20722076
template_args_tc,
20732077
template_args_tc);
20742078

2075-
expr=exprt(ID_type, symbol_typet(new_symbol.name));
2079+
expr = type_exprt(struct_tag_typet(new_symbol.name));
20762080
expr.add_source_location()=source_location;
20772081
}
20782082
else
@@ -2208,21 +2212,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
22082212
irep_idt identifier=id.identifier;
22092213

22102214
if(id.is_member)
2211-
{
2212-
struct_typet struct_type=
2213-
static_cast<const struct_typet &>(
2214-
cpp_typecheck.lookup(id.class_identifier).type);
2215-
const exprt pcomp=struct_type.get_component(identifier);
2216-
assert(pcomp.is_not_nil());
2217-
assert(pcomp.get_bool(ID_is_type));
2218-
const typet &type=pcomp.type();
2219-
assert(type.id()!=ID_struct);
2220-
2221-
if(type.id() == ID_symbol_type)
2222-
identifier = to_symbol_type(type).get_identifier();
2223-
else
2224-
continue;
2225-
}
2215+
continue;
22262216

22272217
while(true)
22282218
{
@@ -2240,8 +2230,6 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
22402230
new_set.insert(&class_id);
22412231
break;
22422232
}
2243-
else if(symbol.type.id() == ID_symbol_type)
2244-
identifier = to_symbol_type(symbol.type).get_identifier();
22452233
else
22462234
break;
22472235
}

src/cpp/cpp_typecheck_resolve.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class cpp_typecheck_resolvet
7171
resolve_identifierst &identifiers,
7272
const wantt want);
7373

74-
symbol_typet disambiguate_template_classes(
74+
struct_tag_typet disambiguate_template_classes(
7575
const irep_idt &base_name,
7676
const cpp_scopest::id_sett &id_set,
7777
const cpp_template_args_non_tct &template_args);

0 commit comments

Comments
 (0)