Skip to content

Commit b3deba9

Browse files
committed
C front-end: Replace uses of namespacet::follow
This is deprecated. Use suitable variants of `follow_tag` instead.
1 parent e7b0557 commit b3deba9

10 files changed

+210
-233
lines changed

src/ansi-c/anonymous_member.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "anonymous_member.h"
1313

14+
#include <util/c_types.h>
1415
#include <util/namespace.h>
1516
#include <util/std_expr.h>
1617

@@ -26,11 +27,10 @@ static member_exprt make_member_expr(
2627
result.set(ID_C_lvalue, true);
2728

2829
// todo: should to typedef chains properly
29-
const typet &type=
30-
ns.follow(struct_union.type());
31-
30+
const auto &tag_type = to_struct_or_union_tag_type(struct_union.type());
3231
if(
33-
type.get_bool(ID_C_constant) || struct_union.type().get_bool(ID_C_constant))
32+
ns.follow_struct_or_union_tag(tag_type).get_bool(ID_C_constant) ||
33+
struct_union.type().get_bool(ID_C_constant))
3434
{
3535
result.type().set(ID_C_constant, true);
3636
}
@@ -43,13 +43,9 @@ exprt get_component_rec(
4343
const irep_idt &component_name,
4444
const namespacet &ns)
4545
{
46-
const struct_union_typet &struct_union_type=
47-
to_struct_union_type(ns.follow(struct_union.type()));
48-
49-
const struct_union_typet::componentst &components=
50-
struct_union_type.components();
46+
const auto &tag_type = to_struct_or_union_tag_type(struct_union.type());
5147

52-
for(const auto &comp : components)
48+
for(const auto &comp : ns.follow_struct_or_union_tag(tag_type).components())
5349
{
5450
const typet &type = comp.type();
5551

@@ -76,13 +72,9 @@ bool has_component_rec(
7672
const irep_idt &component_name,
7773
const namespacet &ns)
7874
{
79-
const struct_union_typet &struct_union_type=
80-
to_struct_union_type(ns.follow(type));
81-
82-
const struct_union_typet::componentst &components=
83-
struct_union_type.components();
75+
const auto &tag_type = to_struct_or_union_tag_type(type);
8476

85-
for(const auto &comp : components)
77+
for(const auto &comp : ns.follow_struct_or_union_tag(tag_type).components())
8678
{
8779
if(comp.get_name()==component_name)
8880
{

src/ansi-c/c_typecast.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,17 @@ typet c_typecastt::follow_with_qualifiers(const typet &src_type)
289289
// collect qualifiers
290290
c_qualifierst qualifiers(src_type);
291291

292-
while(result_type.id() == ID_struct_tag || result_type.id() == ID_union_tag)
292+
if(
293+
auto struct_tag_type = type_try_dynamic_cast<struct_tag_typet>(result_type))
294+
{
295+
const typet &followed_type = ns.follow_tag(*struct_tag_type);
296+
result_type = followed_type;
297+
qualifiers += c_qualifierst(followed_type);
298+
}
299+
else if(
300+
auto union_tag_type = type_try_dynamic_cast<union_tag_typet>(result_type))
293301
{
294-
const typet &followed_type = ns.follow(result_type);
302+
const typet &followed_type = ns.follow_tag(*union_tag_type);
295303
result_type = followed_type;
296304
qualifiers += c_qualifierst(followed_type);
297305
}

src/ansi-c/c_typecheck_base.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
5353
{
5454
bool is_function=symbol.type.id()==ID_code;
5555

56-
const typet &final_type=follow(symbol.type);
57-
5856
// set a few flags
5957
symbol.is_lvalue=!symbol.is_type && !symbol.is_macro;
6058

@@ -91,15 +89,15 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
9189
}
9290

9391
// set the pretty name
94-
if(symbol.is_type && final_type.id() == ID_struct)
92+
if(symbol.is_type && symbol.type.id() == ID_struct)
9593
{
9694
symbol.pretty_name="struct "+id2string(symbol.base_name);
9795
}
98-
else if(symbol.is_type && final_type.id() == ID_union)
96+
else if(symbol.is_type && symbol.type.id() == ID_union)
9997
{
10098
symbol.pretty_name="union "+id2string(symbol.base_name);
10199
}
102-
else if(symbol.is_type && final_type.id() == ID_c_enum)
100+
else if(symbol.is_type && symbol.type.id() == ID_c_enum)
103101
{
104102
symbol.pretty_name="enum "+id2string(symbol.base_name);
105103
}
@@ -191,8 +189,8 @@ void c_typecheck_baset::typecheck_redefinition_type(
191189
symbolt &old_symbol,
192190
symbolt &new_symbol)
193191
{
194-
const typet &final_old=follow(old_symbol.type);
195-
const typet &final_new=follow(new_symbol.type);
192+
const typet &final_old = old_symbol.type;
193+
const typet &final_new = new_symbol.type;
196194

197195
// see if we had something incomplete before
198196
if(
@@ -260,16 +258,16 @@ void c_typecheck_baset::typecheck_redefinition_type(
260258
else if(
261259
config.ansi_c.os == configt::ansi_ct::ost::OS_WIN &&
262260
final_new.id() == ID_pointer && final_old.id() == ID_pointer &&
263-
follow(to_pointer_type(final_new).base_type()).id() == ID_c_enum &&
264-
follow(to_pointer_type(final_old).base_type()).id() == ID_c_enum)
261+
to_pointer_type(final_new).base_type().id() == ID_c_enum &&
262+
to_pointer_type(final_old).base_type().id() == ID_c_enum)
265263
{
266264
// under Windows, ignore this silently;
267265
// MSC doesn't think this is a problem, but GCC complains.
268266
}
269267
else
270268
{
271269
// see if it changed
272-
if(follow(new_symbol.type)!=follow(old_symbol.type))
270+
if(new_symbol.type != old_symbol.type)
273271
{
274272
error().source_location=new_symbol.location;
275273
error() << "type symbol '" << new_symbol.display_name()
@@ -321,8 +319,8 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
321319
symbolt &old_symbol,
322320
symbolt &new_symbol)
323321
{
324-
const typet &final_old=follow(old_symbol.type);
325-
const typet &initial_new=follow(new_symbol.type);
322+
const typet &final_old = old_symbol.type;
323+
const typet &initial_new = new_symbol.type;
326324

327325
if(
328326
final_old.id() == ID_array &&
@@ -351,7 +349,7 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
351349
if(new_symbol.type.id() != ID_code && !new_symbol.is_macro)
352350
do_initializer(new_symbol);
353351

354-
const typet &final_new=follow(new_symbol.type);
352+
const typet &final_new = new_symbol.type;
355353

356354
// K&R stuff?
357355
if(old_symbol.type.id()==ID_KnR)
@@ -548,9 +546,10 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
548546
// int (*f) ();
549547
}
550548
else if(
551-
final_old.id() == ID_struct && final_new.id() == ID_struct &&
549+
final_old.id() == ID_struct_tag && final_new.id() == ID_struct_tag &&
552550
is_instantiation_of_flexible_array(
553-
to_struct_type(final_old), to_struct_type(final_new)))
551+
follow_tag(to_struct_tag_type(final_old)),
552+
follow_tag(to_struct_tag_type(final_new))))
554553
{
555554
old_symbol.type = new_symbol.type;
556555
}

src/ansi-c/c_typecheck_code.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,13 @@ bool c_typecheck_baset::is_complete_type(const typet &type) const
387387
}
388388
else if(type.id()==ID_vector)
389389
return is_complete_type(to_vector_type(type).element_type());
390-
else if(type.id() == ID_struct_tag || type.id() == ID_union_tag)
390+
else if(auto struct_tag_type = type_try_dynamic_cast<struct_tag_typet>(type))
391391
{
392-
return is_complete_type(follow(type));
392+
return is_complete_type(follow_tag(*struct_tag_type));
393+
}
394+
else if(auto union_tag_type = type_try_dynamic_cast<union_tag_typet>(type))
395+
{
396+
return is_complete_type(follow_tag(*union_tag_type));
393397
}
394398

395399
return true;

src/ansi-c/c_typecheck_expr.cpp

+37-45
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
451451
exprt default_match=nil_exprt();
452452
exprt assoc_match=nil_exprt();
453453

454-
const typet &op_type = follow(op.type());
454+
const typet &op_type = op.type();
455455

456456
for(const auto &irep : generic_associations)
457457
{
458458
if(irep.get(ID_type_arg) == ID_default)
459459
default_match = static_cast<const exprt &>(irep.find(ID_value));
460-
else if(
461-
op_type == follow(static_cast<const typet &>(irep.find(ID_type_arg))))
460+
else if(op_type == static_cast<const typet &>(irep.find(ID_type_arg)))
462461
{
463462
assoc_match = static_cast<const exprt &>(irep.find(ID_value));
464463
}
@@ -590,11 +589,9 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
590589

591590
for(const auto &op : member.operands())
592591
{
593-
type = follow(type);
594-
595592
if(op.id() == ID_member)
596593
{
597-
if(type.id()!=ID_union && type.id()!=ID_struct)
594+
if(type.id() != ID_union_tag && type.id() != ID_struct_tag)
598595
{
599596
error().source_location = expr.source_location();
600597
error() << "offsetof of member expects struct/union type, "
@@ -607,20 +604,20 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
607604

608605
while(!found)
609606
{
610-
PRECONDITION(type.id() == ID_union || type.id() == ID_struct);
607+
PRECONDITION(type.id() == ID_union_tag || type.id() == ID_struct_tag);
611608

612-
const struct_union_typet &struct_union_type=
613-
to_struct_union_type(type);
609+
const struct_union_typet &struct_union_type =
610+
follow_struct_or_union_tag(to_struct_or_union_tag_type(type));
614611

615612
// direct member?
616613
if(struct_union_type.has_component(component_name))
617614
{
618615
found=true;
619616

620-
if(type.id()==ID_struct)
617+
if(type.id() == ID_struct_tag)
621618
{
622-
auto o_opt =
623-
member_offset_expr(to_struct_type(type), component_name, *this);
619+
auto o_opt = member_offset_expr(
620+
follow_tag(to_struct_tag_type(type)), component_name, *this);
624621

625622
if(!o_opt.has_value())
626623
{
@@ -650,10 +647,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
650647
{
651648
if(has_component_rec(c.type(), component_name, *this))
652649
{
653-
if(type.id()==ID_struct)
650+
if(type.id() == ID_struct_tag)
654651
{
655652
auto o_opt = member_offset_expr(
656-
to_struct_type(type), c.get_name(), *this);
653+
follow_tag(to_struct_tag_type(type)), c.get_name(), *this);
657654

658655
if(!o_opt.has_value())
659656
{
@@ -669,9 +666,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
669666
o_opt.value(), size_type()));
670667
}
671668

672-
typet tmp = follow(c.type());
669+
typet tmp = c.type();
673670
type=tmp;
674-
CHECK_RETURN(type.id() == ID_union || type.id() == ID_struct);
671+
CHECK_RETURN(
672+
type.id() == ID_union_tag || type.id() == ID_struct_tag);
675673
found2=true;
676674
break; // we run into another iteration of the outer loop
677675
}
@@ -1377,7 +1375,7 @@ void c_typecheck_baset::typecheck_expr_rel(
13771375

13781376
if(expr.id()==ID_equal || expr.id()==ID_notequal)
13791377
{
1380-
if(follow(o_type0)==follow(o_type1))
1378+
if(o_type0 == o_type1)
13811379
{
13821380
if(o_type0.id() != ID_array)
13831381
{
@@ -1530,10 +1528,7 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15301528
exprt &op0 = to_unary_expr(expr).op();
15311529
typet type=op0.type();
15321530

1533-
type = follow(type);
1534-
1535-
if(type.id()!=ID_struct &&
1536-
type.id()!=ID_union)
1531+
if(type.id() != ID_struct_tag && type.id() != ID_union_tag)
15371532
{
15381533
error().source_location = expr.source_location();
15391534
error() << "member operator requires structure type "
@@ -1542,8 +1537,8 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15421537
throw 0;
15431538
}
15441539

1545-
const struct_union_typet &struct_union_type=
1546-
to_struct_union_type(type);
1540+
const struct_union_typet &struct_union_type =
1541+
follow_struct_or_union_tag(to_struct_or_union_tag_type(type));
15471542

15481543
if(struct_union_type.is_incomplete())
15491544
{
@@ -1585,8 +1580,12 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15851580
if(op0.get_bool(ID_C_lvalue))
15861581
expr.set(ID_C_lvalue, true);
15871582

1588-
if(op0.type().get_bool(ID_C_constant) || type.get_bool(ID_C_constant))
1583+
if(
1584+
op0.type().get_bool(ID_C_constant) ||
1585+
struct_union_type.get_bool(ID_C_constant))
1586+
{
15891587
expr.type().set(ID_C_constant, true);
1588+
}
15901589

15911590
// copy method identifier
15921591
const irep_idt &identifier=component.get(ID_C_identifier);
@@ -3649,11 +3648,10 @@ exprt c_typecheck_baset::do_special_functions(
36493648

36503649
// The value doesn't matter at all, we only care about the type.
36513650
// Need to sync with typeclass.h.
3652-
typet type = follow(object.type());
3653-
36543651
// use underlying type for bit fields
3655-
if(type.id() == ID_c_bit_field)
3656-
type = to_c_bit_field_type(type).underlying_type();
3652+
const typet &type = object.type().id() == ID_c_bit_field
3653+
? to_c_bit_field_type(object.type()).underlying_type()
3654+
: object.type();
36573655

36583656
unsigned type_number;
36593657

@@ -3665,23 +3663,17 @@ exprt c_typecheck_baset::do_special_functions(
36653663
}
36663664
else
36673665
{
3668-
type_number =
3669-
type.id() == ID_empty
3670-
? 0u
3671-
: (type.id() == ID_bool || type.id() == ID_c_bool)
3672-
? 4u
3673-
: (type.id() == ID_pointer || type.id() == ID_array)
3674-
? 5u
3675-
: type.id() == ID_floatbv
3676-
? 8u
3677-
: (type.id() == ID_complex &&
3678-
to_complex_type(type).subtype().id() == ID_floatbv)
3679-
? 9u
3680-
: type.id() == ID_struct
3681-
? 12u
3682-
: type.id() == ID_union
3683-
? 13u
3684-
: 1u; // int, short, char, enum_tag
3666+
type_number = type.id() == ID_empty ? 0u
3667+
: (type.id() == ID_bool || type.id() == ID_c_bool) ? 4u
3668+
: (type.id() == ID_pointer || type.id() == ID_array) ? 5u
3669+
: type.id() == ID_floatbv ? 8u
3670+
: (type.id() == ID_complex &&
3671+
to_complex_type(type).subtype().id() == ID_floatbv)
3672+
? 9u
3673+
: type.id() == ID_struct_tag ? 12u
3674+
: type.id() == ID_union_tag
3675+
? 13u
3676+
: 1u; // int, short, char, enum_tag
36853677
}
36863678

36873679
exprt tmp=from_integer(type_number, expr.type());

0 commit comments

Comments
 (0)