@@ -1019,15 +1019,21 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
1019
1019
throw 0 ;
1020
1020
}
1021
1021
1022
- typet final_type=follow (declaration.type ());
1023
-
1024
1022
// anonymous member?
1025
- if (declaration.declarators ().empty () &&
1026
- final_type.get_bool (ID_C_is_anonymous))
1023
+ if (
1024
+ declaration.declarators ().empty () &&
1025
+ ((declaration.type ().id () == ID_struct_tag &&
1026
+ follow_tag (to_struct_tag_type (declaration.type ()))
1027
+ .get_bool (ID_C_is_anonymous)) ||
1028
+ (declaration.type ().id () == ID_union_tag &&
1029
+ follow_tag (to_union_tag_type (declaration.type ()))
1030
+ .get_bool (ID_C_is_anonymous)) ||
1031
+ declaration.type ().get_bool (ID_C_is_anonymous)))
1027
1032
{
1028
1033
// we only allow this on struct/union types
1029
- if (final_type.id ()!=ID_union &&
1030
- final_type.id ()!=ID_struct)
1034
+ if (
1035
+ declaration.type ().id () != ID_union_tag &&
1036
+ declaration.type ().id () != ID_struct_tag)
1031
1037
{
1032
1038
error ().source_location =declaration.type ().source_location ();
1033
1039
error () << " member declaration does not declare anything"
@@ -1423,8 +1429,14 @@ void cpp_typecheckt::convert_anon_struct_union_member(
1423
1429
const irep_idt &access,
1424
1430
struct_typet::componentst &components)
1425
1431
{
1432
+ const struct_union_typet &final_type =
1433
+ declaration.type ().id () == ID_struct_tag
1434
+ ? static_cast <const struct_union_typet &>(
1435
+ follow_tag (to_struct_tag_type (declaration.type ())))
1436
+ : static_cast <const struct_union_typet &>(
1437
+ follow_tag (to_union_tag_type (declaration.type ())));
1426
1438
symbolt &struct_union_symbol =
1427
- symbol_table.get_writeable_ref (follow (declaration. type ()) .get (ID_name));
1439
+ symbol_table.get_writeable_ref (final_type .get (ID_name));
1428
1440
1429
1441
if (declaration.storage_spec ().is_static () ||
1430
1442
declaration.storage_spec ().is_mutable ())
@@ -1477,13 +1489,15 @@ bool cpp_typecheckt::get_component(
1477
1489
const irep_idt &component_name,
1478
1490
exprt &member)
1479
1491
{
1480
- const typet &followed_type=follow (object.type ());
1481
-
1482
1492
PRECONDITION (
1483
- followed_type. id () == ID_struct || followed_type. id () == ID_union );
1493
+ object. type (). id () == ID_struct_tag || object. type (). id () == ID_union_tag );
1484
1494
1485
- struct_union_typet final_type=
1486
- to_struct_union_type (followed_type);
1495
+ struct_union_typet final_type =
1496
+ object.type ().id () == ID_struct_tag
1497
+ ? static_cast <const struct_union_typet &>(
1498
+ follow_tag (to_struct_tag_type (object.type ())))
1499
+ : static_cast <const struct_union_typet &>(
1500
+ follow_tag (to_union_tag_type (object.type ())));
1487
1501
1488
1502
const struct_union_typet::componentst &components=
1489
1503
final_type.components ();
@@ -1529,14 +1543,22 @@ bool cpp_typecheckt::get_component(
1529
1543
1530
1544
return true ; // component found
1531
1545
}
1532
- else if (follow (component.type ()).find (ID_C_unnamed_object).is_not_nil ())
1546
+ else if (
1547
+ (component.type ().id () == ID_struct_tag &&
1548
+ follow_tag (to_struct_tag_type (component.type ()))
1549
+ .find (ID_C_unnamed_object)
1550
+ .is_not_nil ()) ||
1551
+ (component.type ().id () == ID_union_tag &&
1552
+ follow_tag (to_union_tag_type (component.type ()))
1553
+ .find (ID_C_unnamed_object)
1554
+ .is_not_nil ()) ||
1555
+ component.type ().find (ID_C_unnamed_object).is_not_nil ())
1533
1556
{
1534
1557
// could be anonymous union or struct
1535
1558
1536
- const typet &component_type=follow (component.type ());
1537
-
1538
- if (component_type.id ()==ID_union ||
1539
- component_type.id ()==ID_struct)
1559
+ if (
1560
+ component.type ().id () == ID_union_tag ||
1561
+ component.type ().id () == ID_struct_tag)
1540
1562
{
1541
1563
// recursive call!
1542
1564
if (get_component (source_location, tmp, component_name, member))
@@ -1680,18 +1702,17 @@ bool cpp_typecheckt::subtype_typecast(
1680
1702
1681
1703
void cpp_typecheckt::make_ptr_typecast (
1682
1704
exprt &expr,
1683
- const typet &dest_type)
1705
+ const pointer_typet &dest_type)
1684
1706
{
1685
1707
typet src_type=expr.type ();
1686
1708
1687
1709
PRECONDITION (src_type.id () == ID_pointer);
1688
- PRECONDITION (dest_type.id () == ID_pointer);
1689
1710
1690
- const struct_typet &src_struct = to_struct_type (
1691
- static_cast < const typet &>( follow (to_pointer_type (src_type).base_type () )));
1711
+ const struct_typet &src_struct =
1712
+ follow_tag ( to_struct_tag_type (to_pointer_type (src_type).base_type ()));
1692
1713
1693
- const struct_typet &dest_struct = to_struct_type (
1694
- static_cast < const typet &>( follow ( to_pointer_type ( dest_type) .base_type () )));
1714
+ const struct_typet &dest_struct =
1715
+ follow_tag ( to_struct_tag_type ( dest_type.base_type ()));
1695
1716
1696
1717
PRECONDITION (
1697
1718
subtype_typecast (src_struct, dest_struct) ||
0 commit comments