Skip to content

Commit ca54005

Browse files
authored
Merge pull request #4264 from diffblue/cleanout-symbol_type
remove symbol_typet [blocks: #4056]
2 parents be4cee2 + 44858f2 commit ca54005

36 files changed

+95
-343
lines changed

src/analyses/invariant_propagation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ bool invariant_propagationt::check_type(const typet &type) const
191191
return false;
192192
else if(type.id()==ID_array)
193193
return false;
194-
else if(type.id() == ID_symbol_type)
195-
return check_type(ns.follow(type));
196194
else if(type.id()==ID_unsignedbv ||
197195
type.id()==ID_signedbv)
198196
return true;

src/ansi-c/c_typecheck_base.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
415415
to_array_type(final_new).size().is_not_nil() &&
416416
final_old.subtype()==final_new.subtype())
417417
{
418-
// we don't do symbol types for arrays anymore
419-
PRECONDITION(old_symbol.type.id() != ID_symbol_type);
420418
old_symbol.type=new_symbol.type;
421419
}
422420
else if(

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
504504

505505
const typet &type=designator.back().subtype;
506506
const typet &full_type=follow(type);
507-
CHECK_RETURN(full_type.id() != ID_symbol_type);
508507

509508
// do we initialize a scalar?
510509
if(full_type.id()!=ID_struct &&

src/ansi-c/expr2c.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -440,43 +440,6 @@ std::string expr2ct::convert_rec(
440440
{
441441
return convert_array_type(src, qualifiers, declarator);
442442
}
443-
else if(src.id() == ID_symbol_type)
444-
{
445-
symbol_typet symbolic_type=to_symbol_type(src);
446-
const irep_idt &typedef_identifer=symbolic_type.get(ID_typedef);
447-
448-
// Providing we have a valid identifer, we can just use that rather than
449-
// trying to find the concrete type
450-
if(typedef_identifer!="")
451-
{
452-
return q+id2string(typedef_identifer)+d;
453-
}
454-
else
455-
{
456-
const typet &followed=ns.follow(src);
457-
458-
if(followed.id()==ID_struct)
459-
{
460-
std::string dest=q+"struct";
461-
const irep_idt &tag=to_struct_type(followed).get_tag();
462-
if(tag!="")
463-
dest+=" "+id2string(tag);
464-
dest+=d;
465-
return dest;
466-
}
467-
else if(followed.id()==ID_union)
468-
{
469-
std::string dest=q+"union";
470-
const irep_idt &tag=to_union_type(followed).get_tag();
471-
if(tag!="")
472-
dest+=" "+id2string(tag);
473-
dest+=d;
474-
return dest;
475-
}
476-
else
477-
return convert_rec(followed, new_qualifiers, declarator);
478-
}
479-
}
480443
else if(src.id()==ID_struct_tag)
481444
{
482445
const struct_tag_typet &struct_tag_type=

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ void cpp_typecheckt::typecheck_friend_declaration(
894894

895895
// TODO
896896
// typecheck_type(ftype);
897-
// assert(ftype.id()==ID_symbol_type);
898897
// symbol.type.add("ID_C_friends").move_to_sub(ftype);
899898

900899
return;

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ void cpp_typecheckt::check_member_initializers(
442442
for(const auto &b : bases)
443443
{
444444
if(
445-
to_symbol_type(member_type).get_identifier() ==
446-
to_symbol_type(b.type()).get_identifier())
445+
to_struct_tag_type(member_type).get_identifier() ==
446+
to_struct_tag_type(b.type()).get_identifier())
447447
{
448448
ok=true;
449449
break;
@@ -483,14 +483,15 @@ void cpp_typecheckt::check_member_initializers(
483483
if(c.type().id() != ID_struct_tag)
484484
continue;
485485

486-
const symbolt &symb = lookup(to_symbol_type(c.type()).get_identifier());
486+
const symbolt &symb =
487+
lookup(to_struct_tag_type(c.type()).get_identifier());
487488
if(symb.type.id()!=ID_struct)
488489
break;
489490

490491
// check for a direct parent
491492
for(const auto &b : bases)
492493
{
493-
if(symb.name == to_symbol_type(b.type()).get_identifier())
494+
if(symb.name == to_struct_tag_type(b.type()).get_identifier())
494495
{
495496
ok=true;
496497
break;
@@ -513,7 +514,7 @@ void cpp_typecheckt::check_member_initializers(
513514
{
514515
if(
515516
member_type.get(ID_identifier) ==
516-
to_symbol_type(b.type()).get_identifier())
517+
to_struct_tag_type(b.type()).get_identifier())
517518
{
518519
ok=true;
519520
break;
@@ -638,8 +639,8 @@ void cpp_typecheckt::full_member_initialization(
638639
break;
639640

640641
if(
641-
to_symbol_type(b.type()).get_identifier() ==
642-
to_symbol_type(member_type).get_identifier())
642+
to_struct_tag_type(b.type()).get_identifier() ==
643+
to_struct_tag_type(member_type).get_identifier())
643644
{
644645
final_initializers.move_to_sub(initializer);
645646
found=true;

src/cpp/cpp_typecheck_template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters(
808808
809809
if(cpp_declarator_converter.is_typedef)
810810
{
811-
parameter = exprt(ID_type, symbol_typet(symbol.name));
811+
parameter = exprt(ID_type, struct_tag_typet(symbol.name));
812812
parameter.type().add_source_location()=declaration.find_location();
813813
}
814814
else

src/goto-instrument/dump_c.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ void dump_ct::operator()(std::ostream &os)
6161
{
6262
typet &type=it2->type();
6363

64-
if(type.id() == ID_symbol_type && type.get_bool(ID_C_transparent_union))
64+
if(type.id() == ID_union_tag && type.get_bool(ID_C_transparent_union))
6565
{
66-
symbolt new_type_sym=
67-
ns.lookup(to_symbol_type(type).get_identifier());
66+
symbolt new_type_sym =
67+
ns.lookup(to_union_tag_type(type).get_identifier());
6868

6969
new_type_sym.name=id2string(new_type_sym.name)+"$transparent";
7070
new_type_sym.type.set(ID_C_transparent_union, true);
7171

7272
// we might have it already, in which case this has no effect
7373
symbols_transparent.add(new_type_sym);
7474

75-
to_symbol_type(type).set_identifier(new_type_sym.name);
75+
to_union_tag_type(type).set_identifier(new_type_sym.name);
7676
type.remove(ID_C_transparent_union);
7777
}
7878
}
@@ -181,9 +181,16 @@ void dump_ct::operator()(std::ostream &os)
181181

182182
if(type_id==ID_c_enum)
183183
convert_compound_enum(symbol.type, global_decl_stream);
184+
else if(type_id == ID_struct)
185+
{
186+
global_decl_stream << type_to_string(struct_tag_typet{symbol.name})
187+
<< ";\n\n";
188+
}
184189
else
185-
global_decl_stream << type_to_string(symbol_typet(symbol.name))
190+
{
191+
global_decl_stream << type_to_string(union_tag_typet{symbol.name})
186192
<< ";\n\n";
193+
}
187194
}
188195
}
189196
else if(symbol.is_static_lifetime && symbol.type.id()!=ID_code)
@@ -297,10 +304,12 @@ void dump_ct::convert_compound_declaration(
297304
return;
298305

299306
// do compound type body
300-
if(symbol.type.id()==ID_struct ||
301-
symbol.type.id()==ID_union ||
302-
symbol.type.id()==ID_c_enum)
303-
convert_compound(symbol.type, symbol_typet(symbol.name), true, os_body);
307+
if(symbol.type.id() == ID_struct)
308+
convert_compound(symbol.type, struct_tag_typet(symbol.name), true, os_body);
309+
else if(symbol.type.id() == ID_union)
310+
convert_compound(symbol.type, union_tag_typet(symbol.name), true, os_body);
311+
else if(symbol.type.id() == ID_c_enum)
312+
convert_compound(symbol.type, c_enum_tag_typet(symbol.name), true, os_body);
304313
}
305314

306315
void dump_ct::convert_compound(
@@ -309,16 +318,7 @@ void dump_ct::convert_compound(
309318
bool recursive,
310319
std::ostream &os)
311320
{
312-
if(type.id() == ID_symbol_type)
313-
{
314-
const symbolt &symbol=
315-
ns.lookup(to_symbol_type(type).get_identifier());
316-
DATA_INVARIANT(symbol.is_type, "symbol expected to be type symbol");
317-
318-
if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers))
319-
convert_compound(symbol.type, unresolved, recursive, os);
320-
}
321-
else if(
321+
if(
322322
type.id() == ID_c_enum_tag || type.id() == ID_struct_tag ||
323323
type.id() == ID_union_tag)
324324
{
@@ -346,7 +346,13 @@ void dump_ct::convert_compound(
346346
it!=syms.end();
347347
++it)
348348
{
349-
symbol_typet s_type(*it);
349+
const symbolt &type_symbol = ns.lookup(*it);
350+
irep_idt tag_kind =
351+
type_symbol.type.id() == ID_c_enum
352+
? ID_c_enum_tag
353+
: (type_symbol.type.id() == ID_union ? ID_union_tag
354+
: ID_struct_tag);
355+
tag_typet s_type(tag_kind, *it);
350356
convert_compound(s_type, s_type, recursive, os);
351357
}
352358
}
@@ -378,7 +384,7 @@ void dump_ct::convert_compound(
378384
UNREACHABLE;
379385
/*
380386
assert(parent_it->id() == ID_base);
381-
assert(parent_it->get(ID_type) == ID_symbol_type);
387+
assert(parent_it->get(ID_type) == ID_struct_tag);
382388
383389
const irep_idt &base_id=
384390
parent_it->find(ID_type).get(ID_identifier);
@@ -657,12 +663,6 @@ void dump_ct::collect_typedefs_rec(
657663
{
658664
collect_typedefs_rec(type.subtype(), early, local_deps);
659665
}
660-
else if(type.id() == ID_symbol_type)
661-
{
662-
const symbolt &symbol=
663-
ns.lookup(to_symbol_type(type).get_identifier());
664-
collect_typedefs_rec(symbol.type, early, local_deps);
665-
}
666666
else if(
667667
type.id() == ID_c_enum_tag || type.id() == ID_struct_tag ||
668668
type.id() == ID_union_tag)
@@ -1183,7 +1183,11 @@ void dump_ct::insert_local_type_decls(
11831183
// a comment block ...
11841184
std::ostringstream os_body;
11851185
os_body << *it << " */\n";
1186-
convert_compound(type, symbol_typet(*it), false, os_body);
1186+
irep_idt tag_kind =
1187+
type.id() == ID_c_enum
1188+
? ID_c_enum_tag
1189+
: (type.id() == ID_union ? ID_union_tag : ID_struct_tag);
1190+
convert_compound(type, tag_typet(tag_kind, *it), false, os_body);
11871191
os_body << "/*";
11881192

11891193
code_skipt skip;

src/goto-instrument/goto_program2code.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,31 +1410,22 @@ goto_programt::const_targett goto_program2codet::convert_catch(
14101410

14111411
void goto_program2codet::add_local_types(const typet &type)
14121412
{
1413-
if(type.id() == ID_symbol_type)
1413+
if(type.id() == ID_struct_tag || type.id() == ID_union_tag)
14141414
{
14151415
const typet &full_type=ns.follow(type);
14161416

1417-
if(full_type.id()==ID_pointer ||
1418-
full_type.id()==ID_array)
1419-
{
1420-
add_local_types(full_type.subtype());
1421-
}
1422-
else if(full_type.id()==ID_struct ||
1423-
full_type.id()==ID_union)
1424-
{
1425-
const irep_idt &identifier=to_symbol_type(type).get_identifier();
1426-
const symbolt &symbol=ns.lookup(identifier);
1417+
const irep_idt &identifier = to_tag_type(type).get_identifier();
1418+
const symbolt &symbol = ns.lookup(identifier);
14271419

1428-
if(symbol.location.get_function().empty() ||
1429-
!type_names_set.insert(identifier).second)
1430-
return;
1420+
if(
1421+
symbol.location.get_function().empty() ||
1422+
!type_names_set.insert(identifier).second)
1423+
return;
14311424

1432-
for(const auto &c : to_struct_union_type(full_type).components())
1433-
add_local_types(c.type());
1425+
for(const auto &c : to_struct_union_type(full_type).components())
1426+
add_local_types(c.type());
14341427

1435-
assert(!identifier.empty());
1436-
type_names.push_back(identifier);
1437-
}
1428+
type_names.push_back(identifier);
14381429
}
14391430
else if(type.id()==ID_c_enum_tag)
14401431
{
@@ -1633,9 +1624,9 @@ void goto_program2codet::remove_const(typet &type)
16331624
if(type.get_bool(ID_C_constant))
16341625
type.remove(ID_C_constant);
16351626

1636-
if(type.id() == ID_symbol_type)
1627+
if(type.id() == ID_struct_tag || type.id() == ID_union_tag)
16371628
{
1638-
const irep_idt &identifier=to_symbol_type(type).get_identifier();
1629+
const irep_idt &identifier = to_tag_type(type).get_identifier();
16391630
if(!const_removed.insert(identifier).second)
16401631
return;
16411632

@@ -1833,8 +1824,9 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
18331824
if(no_typecast)
18341825
return;
18351826

1836-
DATA_INVARIANT(expr.type().id() == ID_symbol_type,
1837-
"type of union/struct expressions");
1827+
DATA_INVARIANT(
1828+
expr.type().id() == ID_struct_tag || expr.type().id() == ID_union_tag,
1829+
"union/struct expressions should have a tag type");
18381830

18391831
const typet &t=expr.type();
18401832

src/goto-instrument/nondet_volatile.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ Date: September 2011
1616
#include <util/std_expr.h>
1717
#include <util/symbol_table.h>
1818

19-
bool is_volatile(
20-
const symbol_tablet &symbol_table,
21-
const typet &src)
19+
static bool is_volatile(const namespacet &ns, const typet &src)
2220
{
2321
if(src.get_bool(ID_C_volatile))
2422
return true;
2523

26-
if(src.id()==ID_symbol)
24+
if(
25+
src.id() == ID_struct_tag || src.id() == ID_union_tag ||
26+
src.id() == ID_c_enum_tag)
2727
{
28-
symbol_tablet::symbolst::const_iterator s_it=
29-
symbol_table.symbols.find(to_symbol_type(src).get_identifier());
30-
assert(s_it!=symbol_table.symbols.end());
31-
return is_volatile(symbol_table, s_it->second.type);
28+
return is_volatile(ns, ns.follow(src));
3229
}
3330

3431
return false;
@@ -42,7 +39,8 @@ void nondet_volatile_rhs(const symbol_tablet &symbol_table, exprt &expr)
4239
if(expr.id()==ID_symbol ||
4340
expr.id()==ID_dereference)
4441
{
45-
if(is_volatile(symbol_table, expr.type()))
42+
const namespacet ns(symbol_table);
43+
if(is_volatile(ns, expr.type()))
4644
{
4745
typet t=expr.type();
4846
t.remove(ID_C_volatile);

src/goto-programs/destructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ code_function_callt get_destructor(
1919
const namespacet &ns,
2020
const typet &type)
2121
{
22-
if(type.id() == ID_symbol_type)
22+
if(type.id() == ID_struct_tag)
2323
{
24-
return get_destructor(ns, ns.follow(type));
24+
return get_destructor(ns, ns.follow_tag(to_struct_tag_type(type)));
2525
}
2626
else if(type.id()==ID_struct)
2727
{

src/goto-programs/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,9 +1030,9 @@ mp_integer interpretert::get_size(const typet &type)
10301030
}
10311031
return subtype_size;
10321032
}
1033-
else if(type.id() == ID_symbol_type || type.id() == ID_struct_tag)
1033+
else if(type.id() == ID_struct_tag)
10341034
{
1035-
return get_size(ns.follow(type));
1035+
return get_size(ns.follow_tag(to_struct_tag_type(type)));
10361036
}
10371037

10381038
return 1;

src/goto-programs/json_expr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ static exprt simplify_json_expr(const exprt &src)
9797
/// \return a json object
9898
json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode)
9999
{
100-
if(type.id() == ID_symbol_type)
101-
return json(ns.follow(type), ns, mode);
102-
103100
json_objectt result;
104101

105102
if(type.id() == ID_unsignedbv)

0 commit comments

Comments
 (0)