@@ -451,14 +451,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
451
451
exprt default_match=nil_exprt ();
452
452
exprt assoc_match=nil_exprt ();
453
453
454
- const typet &op_type = follow ( op.type () );
454
+ const typet &op_type = op.type ();
455
455
456
456
for (const auto &irep : generic_associations)
457
457
{
458
458
if (irep.get (ID_type_arg) == ID_default)
459
459
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)))
462
461
{
463
462
assoc_match = static_cast <const exprt &>(irep.find (ID_value));
464
463
}
@@ -590,11 +589,9 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
590
589
591
590
for (const auto &op : member.operands ())
592
591
{
593
- type = follow (type);
594
-
595
592
if (op.id () == ID_member)
596
593
{
597
- if (type.id ()!=ID_union && type.id ()!=ID_struct )
594
+ if (type.id () != ID_union_tag && type.id () != ID_struct_tag )
598
595
{
599
596
error ().source_location = expr.source_location ();
600
597
error () << " offsetof of member expects struct/union type, "
@@ -607,20 +604,23 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
607
604
608
605
while (!found)
609
606
{
610
- PRECONDITION (type.id () == ID_union || type.id () == ID_struct );
607
+ PRECONDITION (type.id () == ID_union_tag || type.id () == ID_struct_tag );
611
608
612
- const struct_union_typet &struct_union_type=
613
- to_struct_union_type (type);
609
+ const struct_union_typet &struct_union_type =
610
+ type.id () == ID_struct_tag ? static_cast <const struct_union_typet &>(
611
+ follow_tag (to_struct_tag_type (type)))
612
+ : static_cast <const struct_union_typet &>(
613
+ follow_tag (to_union_tag_type (type)));
614
614
615
615
// direct member?
616
616
if (struct_union_type.has_component (component_name))
617
617
{
618
618
found=true ;
619
619
620
- if (type.id ()==ID_struct )
620
+ if (type.id () == ID_struct_tag )
621
621
{
622
- auto o_opt =
623
- member_offset_expr ( to_struct_type (type), component_name, *this );
622
+ auto o_opt = member_offset_expr (
623
+ follow_tag ( to_struct_tag_type (type) ), component_name, *this );
624
624
625
625
if (!o_opt.has_value ())
626
626
{
@@ -650,10 +650,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
650
650
{
651
651
if (has_component_rec (c.type (), component_name, *this ))
652
652
{
653
- if (type.id ()==ID_struct )
653
+ if (type.id () == ID_struct_tag )
654
654
{
655
655
auto o_opt = member_offset_expr (
656
- to_struct_type ( type), c.get_name (), *this );
656
+ follow_tag ( to_struct_tag_type ( type) ), c.get_name (), *this );
657
657
658
658
if (!o_opt.has_value ())
659
659
{
@@ -669,9 +669,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
669
669
o_opt.value (), size_type ()));
670
670
}
671
671
672
- typet tmp = follow ( c.type () );
672
+ typet tmp = c.type ();
673
673
type=tmp;
674
- CHECK_RETURN (type.id () == ID_union || type.id () == ID_struct);
674
+ CHECK_RETURN (
675
+ type.id () == ID_union_tag || type.id () == ID_struct_tag);
675
676
found2=true ;
676
677
break ; // we run into another iteration of the outer loop
677
678
}
@@ -1375,7 +1376,7 @@ void c_typecheck_baset::typecheck_expr_rel(
1375
1376
1376
1377
if (expr.id ()==ID_equal || expr.id ()==ID_notequal)
1377
1378
{
1378
- if (follow ( o_type0)== follow ( o_type1) )
1379
+ if (o_type0 == o_type1)
1379
1380
{
1380
1381
if (o_type0.id () != ID_array)
1381
1382
{
@@ -1528,10 +1529,7 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
1528
1529
exprt &op0 = to_unary_expr (expr).op ();
1529
1530
typet type=op0.type ();
1530
1531
1531
- type = follow (type);
1532
-
1533
- if (type.id ()!=ID_struct &&
1534
- type.id ()!=ID_union)
1532
+ if (type.id () != ID_struct_tag && type.id () != ID_union_tag)
1535
1533
{
1536
1534
error ().source_location = expr.source_location ();
1537
1535
error () << " member operator requires structure type "
@@ -1540,8 +1538,11 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
1540
1538
throw 0 ;
1541
1539
}
1542
1540
1543
- const struct_union_typet &struct_union_type=
1544
- to_struct_union_type (type);
1541
+ const struct_union_typet &struct_union_type =
1542
+ type.id () == ID_struct_tag ? static_cast <const struct_union_typet &>(
1543
+ follow_tag (to_struct_tag_type (type)))
1544
+ : static_cast <const struct_union_typet &>(
1545
+ follow_tag (to_union_tag_type (type)));
1545
1546
1546
1547
if (struct_union_type.is_incomplete ())
1547
1548
{
@@ -1583,7 +1584,9 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
1583
1584
if (op0.get_bool (ID_C_lvalue))
1584
1585
expr.set (ID_C_lvalue, true );
1585
1586
1586
- if (op0.type ().get_bool (ID_C_constant) || type.get_bool (ID_C_constant))
1587
+ if (
1588
+ op0.type ().get_bool (ID_C_constant) ||
1589
+ struct_union_type.get_bool (ID_C_constant))
1587
1590
expr.type ().set (ID_C_constant, true );
1588
1591
1589
1592
// copy method identifier
@@ -3643,11 +3646,10 @@ exprt c_typecheck_baset::do_special_functions(
3643
3646
3644
3647
// The value doesn't matter at all, we only care about the type.
3645
3648
// Need to sync with typeclass.h.
3646
- typet type = follow (object.type ());
3647
-
3648
3649
// use underlying type for bit fields
3649
- if (type.id () == ID_c_bit_field)
3650
- type = to_c_bit_field_type (type).underlying_type ();
3650
+ const typet &type = object.type ().id () == ID_c_bit_field
3651
+ ? to_c_bit_field_type (object.type ()).underlying_type ()
3652
+ : object.type ();
3651
3653
3652
3654
unsigned type_number;
3653
3655
@@ -3659,23 +3661,17 @@ exprt c_typecheck_baset::do_special_functions(
3659
3661
}
3660
3662
else
3661
3663
{
3662
- type_number =
3663
- type.id () == ID_empty
3664
- ? 0u
3665
- : (type.id () == ID_bool || type.id () == ID_c_bool)
3666
- ? 4u
3667
- : (type.id () == ID_pointer || type.id () == ID_array)
3668
- ? 5u
3669
- : type.id () == ID_floatbv
3670
- ? 8u
3671
- : (type.id () == ID_complex &&
3672
- to_complex_type (type).subtype ().id () == ID_floatbv)
3673
- ? 9u
3674
- : type.id () == ID_struct
3675
- ? 12u
3676
- : type.id () == ID_union
3677
- ? 13u
3678
- : 1u ; // int, short, char, enum_tag
3664
+ type_number = type.id () == ID_empty ? 0u
3665
+ : (type.id () == ID_bool || type.id () == ID_c_bool) ? 4u
3666
+ : (type.id () == ID_pointer || type.id () == ID_array) ? 5u
3667
+ : type.id () == ID_floatbv ? 8u
3668
+ : (type.id () == ID_complex &&
3669
+ to_complex_type (type).subtype ().id () == ID_floatbv)
3670
+ ? 9u
3671
+ : type.id () == ID_struct_tag ? 12u
3672
+ : type.id () == ID_union_tag
3673
+ ? 13u
3674
+ : 1u ; // int, short, char, enum_tag
3679
3675
}
3680
3676
3681
3677
exprt tmp=from_integer (type_number, expr.type ());
0 commit comments