Skip to content

Commit 356ab40

Browse files
author
Daniel Kroening
authored
Merge pull request #3060 from diffblue/cpp-struct_tag
C++: use struct tag instead of symbol_type
2 parents 060ec5d + d2f803a commit 356ab40

10 files changed

+57
-28
lines changed

src/cpp/cpp_declarator_converter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ symbolt &cpp_declarator_convertert::convert(
105105
// adjust type if it's a non-static member function
106106
if(final_type.id()==ID_code)
107107
cpp_typecheck.add_this_to_method_type(
108-
scope->identifier, final_type, method_qualifier);
108+
cpp_typecheck.lookup(scope->identifier),
109+
to_code_type(final_type),
110+
method_qualifier);
109111

110112
get_final_identifier();
111113

src/cpp/cpp_exception_id.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ void cpp_exception_list_rec(
3838
cpp_exception_list_rec(src.subtype(), ns, "_ptr"+suffix, dest);
3939
}
4040
}
41+
else if(src.id() == ID_union_tag)
42+
{
43+
cpp_exception_list_rec(ns.follow_tag(to_union_tag_type(src)), ns, suffix, dest);
44+
}
4145
else if(src.id()==ID_union)
4246
{
4347
// just get tag
4448
dest.push_back("union_"+src.get_string(ID_tag));
4549
}
50+
else if(src.id() == ID_struct_tag)
51+
{
52+
cpp_exception_list_rec(ns.follow_tag(to_struct_tag_type(src)), ns, suffix, dest);
53+
}
4654
else if(src.id()==ID_struct)
4755
{
4856
// just get tag

src/cpp/cpp_instantiate_template.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ std::string cpp_typecheckt::template_suffix(
4848
const typet &type=expr.type();
4949
if(type.id() == ID_symbol_type)
5050
result += id2string(to_symbol_type(type).get_identifier());
51+
else if(type.id() == ID_struct_tag ||
52+
type.id() == ID_union_tag)
53+
result += id2string(to_tag_type(type).get_identifier());
5154
else
5255
result+=cpp_type2name(type);
5356
}

src/cpp/cpp_is_pod.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ bool cpp_typecheckt::cpp_is_pod(const typet &type) const
8282
DATA_INVARIANT(symb.is_type, "type symbol is a type");
8383
return cpp_is_pod(symb.type);
8484
}
85+
else if(type.id() == ID_struct_tag ||
86+
type.id() == ID_union_tag)
87+
{
88+
const symbolt &symb = lookup(to_tag_type(type));
89+
DATA_INVARIANT(symb.is_type, "tag symbol is a type");
90+
return cpp_is_pod(symb.type);
91+
}
8592

8693
// everything else is POD
8794
return true;

src/cpp/cpp_typecheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ class cpp_typecheckt:public c_typecheck_baset
395395
static bool has_auto(const typet &type);
396396

397397
void typecheck_member_function(
398-
const irep_idt &compound_identifier,
398+
const symbolt &compound_symbol,
399399
struct_typet::componentt &component,
400400
irept &initializers,
401401
const typet &method_qualifier,
402402
exprt &value);
403403

404404
void add_this_to_method_type(
405-
const irep_idt &compound_identifier,
406-
typet &method_type,
405+
const symbolt &compound_symbol,
406+
code_typet &method_type,
407407
const typet &method_qualifier);
408408

409409
// for function overloading

src/cpp/cpp_typecheck_bases.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type)
4343
// elaborate any class template instances given as bases
4444
elaborate_class_template(base_symbol_expr.type());
4545

46+
if(base_symbol_expr.type().id() == ID_struct_tag)
47+
base_symbol_expr.type().id(ID_symbol_type);
48+
4649
if(base_symbol_expr.type().id() != ID_symbol_type)
4750
{
4851
error().source_location=name.source_location();

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ void cpp_typecheckt::typecheck_compound_type(
273273
}
274274
else
275275
{
276-
// create type symbol
277-
symbol_typet symbol_type(symbol_name);
278-
qualifiers.write(symbol_type);
279-
type.swap(symbol_type);
276+
// create struct tag
277+
struct_tag_typet tag_type(symbol_name);
278+
qualifiers.write(tag_type);
279+
type.swap(tag_type);
280280
}
281281
}
282282

@@ -509,7 +509,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
509509
if(!is_virtual)
510510
{
511511
typecheck_member_function(
512-
symbol.name, component, initializers,
512+
symbol, component, initializers,
513513
method_qualifier, value);
514514

515515
if(!value.is_nil() && !is_static)
@@ -540,7 +540,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
540540
}
541541

542542
typecheck_member_function(
543-
symbol.name,
543+
symbol,
544544
component,
545545
initializers,
546546
method_qualifier,
@@ -569,7 +569,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
569569
// add a virtual-table pointer
570570
struct_typet::componentt compo(
571571
id2string(symbol.name) + "::@vtable_pointer",
572-
pointer_type(symbol_typet(vt_name)));
572+
pointer_type(struct_tag_typet(vt_name)));
573573
compo.set_base_name("@vtable_pointer");
574574
compo.set_pretty_name(id2string(symbol.base_name) + "@vtable_pointer");
575575
compo.set(ID_is_vtptr, true);
@@ -1262,7 +1262,7 @@ void cpp_typecheckt::move_member_initializers(
12621262
}
12631263

12641264
void cpp_typecheckt::typecheck_member_function(
1265-
const irep_idt &compound_identifier,
1265+
const symbolt &compound_symbol,
12661266
struct_typet::componentt &component,
12671267
irept &initializers,
12681268
const typet &method_qualifier,
@@ -1283,10 +1283,7 @@ void cpp_typecheckt::typecheck_member_function(
12831283
}
12841284
else
12851285
{
1286-
add_this_to_method_type(
1287-
compound_identifier,
1288-
type,
1289-
method_qualifier);
1286+
add_this_to_method_type(compound_symbol, type, method_qualifier);
12901287
}
12911288

12921289
if(value.id() == ID_cpp_not_typechecked && value.has_operands())
@@ -1344,11 +1341,11 @@ void cpp_typecheckt::typecheck_member_function(
13441341
}
13451342

13461343
void cpp_typecheckt::add_this_to_method_type(
1347-
const irep_idt &compound_symbol,
1348-
typet &type,
1344+
const symbolt &compound_symbol,
1345+
code_typet &type,
13491346
const typet &method_qualifier)
13501347
{
1351-
code_typet::parameterst &parameters=to_code_type(type).parameters();
1348+
code_typet::parameterst &parameters = type.parameters();
13521349

13531350
parameters.insert(
13541351
parameters.begin(), code_typet::parametert());
@@ -1359,7 +1356,12 @@ void cpp_typecheckt::add_this_to_method_type(
13591356
parameter.set_base_name(ID_this);
13601357
parameter.set_this();
13611358

1362-
typet subtype=symbol_typet(compound_symbol);
1359+
typet subtype;
1360+
1361+
if(compound_symbol.type.id() == ID_union)
1362+
subtype = union_tag_typet(compound_symbol.name);
1363+
else
1364+
subtype = struct_tag_typet(compound_symbol.name);
13631365

13641366
if(has_const(method_qualifier))
13651367
subtype.set(ID_C_constant, true);
@@ -1455,7 +1457,7 @@ void cpp_typecheckt::convert_anon_struct_union_member(
14551457
if(struct_union_symbol.type.id() == ID_union)
14561458
compound_type = union_tag_typet(struct_union_symbol.name);
14571459
else
1458-
compound_type = symbol_typet(struct_union_symbol.name);
1460+
compound_type = struct_tag_typet(struct_union_symbol.name);
14591461

14601462
struct_typet::componentt component(identifier, compound_type);
14611463
component.set_access(access);

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void cpp_typecheckt::typecheck_expr_main(exprt &expr)
120120
{
121121
// these appear to have type "struct _GUID"
122122
// and they are lvalues!
123-
expr.type()=symbol_typet("tag-_GUID");
123+
expr.type() = struct_tag_typet("tag-_GUID");
124124
follow(expr.type());
125125
expr.set(ID_C_lvalue, true);
126126
}
@@ -717,7 +717,7 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
717717
if(args.size() > 0 && args[0].get(ID_C_base_name)==ID_this)
718718
{
719719
// it's a pointer to member function
720-
const symbol_typet symbol(code_type.get(ID_C_member_name));
720+
const struct_tag_typet symbol(code_type.get(ID_C_member_name));
721721
expr.op0().type().add("to-member")=symbol;
722722

723723
if(code_type.get_bool(ID_C_is_virtual))
@@ -980,11 +980,11 @@ void cpp_typecheckt::typecheck_expr_explicit_constructor_call(exprt &expr)
980980
{
981981
assert(expr.type().id()==ID_struct);
982982

983-
symbol_typet symb(expr.type().get(ID_name));
984-
symb.add_source_location()=expr.source_location();
983+
struct_tag_typet tag(expr.type().get(ID_name));
984+
tag.add_source_location() = expr.source_location();
985985

986986
exprt e=expr;
987-
new_temporary(e.source_location(), symb, e.operands(), expr);
987+
new_temporary(e.source_location(), tag, e.operands(), expr);
988988
}
989989
}
990990

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ void cpp_typecheck_resolvet::remove_duplicates(
162162
id = to_symbol_expr(old_id).get_identifier();
163163
else if(old_id.id() == ID_type && old_id.type().id() == ID_symbol_type)
164164
id = to_symbol_type(old_id.type()).get_identifier();
165+
else if(old_id.id() == ID_type && old_id.type().id() == ID_struct_tag)
166+
id = to_struct_tag_type(old_id.type()).get_identifier();
167+
else if(old_id.id() == ID_type && old_id.type().id() == ID_union_tag)
168+
id = to_union_tag_type(old_id.type()).get_identifier();
165169

166170
if(id=="")
167171
{

src/cpp/cpp_typecheck_virtual_table.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol)
7474
vt_symb_var.mode=ID_cpp;
7575
vt_symb_var.module=module;
7676
vt_symb_var.location=vt_symb_type.location;
77-
vt_symb_var.type=symbol_typet(vt_symb_type.name);
77+
vt_symb_var.type = struct_tag_typet(vt_symb_type.name);
7878
vt_symb_var.is_lvalue=true;
7979
vt_symb_var.is_static_lifetime=true;
8080

8181
// do the values
8282
const struct_typet &vt_type=to_struct_type(vt_symb_type.type);
8383

84-
struct_exprt values(symbol_typet(vt_symb_type.name));
84+
struct_exprt values(struct_tag_typet(vt_symb_type.name));
8585

8686
for(const auto &compo : vt_type.components())
8787
{

0 commit comments

Comments
 (0)