Skip to content

Commit fd9dd34

Browse files
committed
goto-instrument: Replace uses of namespacet::follow
This is deprecated. Use suitable variants of `follow_tag` instead.
1 parent e7b0557 commit fd9dd34

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/goto-instrument/dump_c.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,11 @@ void dump_ct::convert_compound(
573573
typet comp_type_to_use = comp.type();
574574
if(is_anon)
575575
{
576-
comp_type_to_use = ns.follow(comp.type());
576+
comp_type_to_use =
577+
(comp.type().id() == ID_struct_tag || comp.type().id() == ID_union_tag)
578+
? ns.follow_struct_or_union_tag(
579+
to_struct_or_union_tag_type(comp.type()))
580+
: comp.type();
577581
comp_type_to_use.remove(ID_tag);
578582
if(
579583
recursive && (comp_type_to_use.id() == ID_struct ||
@@ -1353,8 +1357,9 @@ void dump_ct::cleanup_expr(exprt &expr)
13531357

13541358
if(expr.id()==ID_struct)
13551359
{
1356-
struct_typet type=
1357-
to_struct_type(ns.follow(expr.type()));
1360+
struct_typet type = expr.type().id() == ID_struct_tag
1361+
? ns.follow_tag(to_struct_tag_type(expr.type()))
1362+
: to_struct_type(expr.type());
13581363

13591364
struct_union_typet::componentst old_components;
13601365
old_components.swap(type.components());
@@ -1382,7 +1387,9 @@ void dump_ct::cleanup_expr(exprt &expr)
13821387
else if(expr.id()==ID_union)
13831388
{
13841389
union_exprt &u=to_union_expr(expr);
1385-
const union_typet &u_type_f=to_union_type(ns.follow(u.type()));
1390+
const union_typet &u_type_f = u.type().id() == ID_union_tag
1391+
? ns.follow_tag(to_union_tag_type(u.type()))
1392+
: to_union_type(u.type());
13861393

13871394
if(!u.type().get_bool(ID_C_transparent_union) &&
13881395
!u_type_f.get_bool(ID_C_transparent_union))
@@ -1440,7 +1447,10 @@ void dump_ct::cleanup_expr(exprt &expr)
14401447
code_typet::parameterst::const_iterator it=parameters.begin();
14411448
for(auto &argument : arguments)
14421449
{
1443-
const typet &type=ns.follow(it->type());
1450+
const typet &type = it->type().id() == ID_union_tag
1451+
? static_cast<const typet &>(ns.follow_tag(
1452+
to_union_tag_type(it->type())))
1453+
: it->type();
14441454
if(type.id()==ID_union &&
14451455
type.get_bool(ID_C_transparent_union))
14461456
{
@@ -1494,7 +1504,9 @@ void dump_ct::cleanup_expr(exprt &expr)
14941504
{
14951505
const union_exprt &union_expr = to_union_expr(bu.op());
14961506
const union_typet &union_type =
1497-
to_union_type(ns.follow(union_expr.type()));
1507+
union_expr.type().id() == ID_union_tag
1508+
? ns.follow_tag(to_union_tag_type(union_expr.type()))
1509+
: to_union_type(union_expr.type());
14981510

14991511
for(const auto &comp : union_type.components())
15001512
{
@@ -1524,9 +1536,14 @@ void dump_ct::cleanup_expr(exprt &expr)
15241536
else if(
15251537
bu.op().id() == ID_side_effect &&
15261538
to_side_effect_expr(bu.op()).get_statement() == ID_nondet &&
1527-
ns.follow(bu.op().type()).id() == ID_union && bu.offset().is_zero())
1539+
(bu.op().type().id() == ID_union ||
1540+
bu.op().type().id() == ID_union_tag) &&
1541+
bu.offset().is_zero())
15281542
{
1529-
const union_typet &union_type = to_union_type(ns.follow(bu.op().type()));
1543+
const union_typet &union_type =
1544+
bu.op().type().id() == ID_union_tag
1545+
? ns.follow_tag(to_union_tag_type(bu.op().type()))
1546+
: to_union_type(bu.op().type());
15301547

15311548
for(const auto &comp : union_type.components())
15321549
{
@@ -1542,7 +1559,7 @@ void dump_ct::cleanup_expr(exprt &expr)
15421559

15431560
std::optional<exprt> clean_init;
15441561
if(
1545-
ns.follow(bu.type()).id() == ID_union &&
1562+
(bu.type().id() == ID_union || bu.type().id() == ID_union_tag) &&
15461563
bu.source_location().get_function().empty())
15471564
{
15481565
clean_init = zero_initializer(bu.op().type(), source_locationt{}, ns)
@@ -1553,7 +1570,10 @@ void dump_ct::cleanup_expr(exprt &expr)
15531570

15541571
if(clean_init.has_value() && bu.op() == *clean_init)
15551572
{
1556-
const union_typet &union_type = to_union_type(ns.follow(bu.type()));
1573+
const union_typet &union_type =
1574+
bu.type().id() == ID_union_tag
1575+
? ns.follow_tag(to_union_tag_type(bu.type()))
1576+
: to_union_type(bu.type());
15571577

15581578
for(const auto &comp : union_type.components())
15591579
{

src/goto-instrument/goto_program2code.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,6 @@ void goto_program2codet::add_local_types(const typet &type)
13801380
{
13811381
if(type.id() == ID_struct_tag || type.id() == ID_union_tag)
13821382
{
1383-
const typet &full_type=ns.follow(type);
1384-
13851383
const irep_idt &identifier = to_tag_type(type).get_identifier();
13861384
const symbolt &symbol = ns.lookup(identifier);
13871385

@@ -1390,7 +1388,10 @@ void goto_program2codet::add_local_types(const typet &type)
13901388
!type_names_set.insert(identifier).second)
13911389
return;
13921390

1393-
for(const auto &c : to_struct_union_type(full_type).components())
1391+
const auto &components =
1392+
ns.follow_struct_or_union_tag(to_struct_or_union_tag_type(type))
1393+
.components();
1394+
for(const auto &c : components)
13941395
add_local_types(c.type());
13951396

13961397
type_names.push_back(identifier);

0 commit comments

Comments
 (0)