@@ -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_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_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