Variant gcc-13-14
Applies to 13.2.0, 14.2.0. Source flavors: linux, darwin_arm64.
+200 −4 2 files
gcc/c-family/c-ada-spec.cc
+166−4modified
| @@ -701 +701 @@static tree *to_dump = NULL; | |||
| 701 | 701 | static int to_dump_count = 0; | |
| 702 | 702 | static tree current_namespace = NULL_TREE; | |
| 703 | 703 | | |
| 704 | Added line. enum ada_name_role | ||
| 705 | Added line. { | ||
| 706 | Added line. ADA_NAME_SOURCE, | ||
| 707 | Added line. ADA_NAME_QUALIFIED_METHOD, | ||
| 708 | Added line. ADA_NAME_RENAMED_METHOD, | ||
| 709 | Added line. ADA_NAME_TEMPLATE_INSTANCE, | ||
| 710 | Added line. ADA_NAME_AS_BASE, | ||
| 711 | Added line. ADA_NAME_SYNTHETIC_FIELD, | ||
| 712 | Added line. ADA_NAME_FORMAL | ||
| 713 | Added line. }; | ||
| 714 | Added line. | ||
| 715 | Added line. static const char *allocate_ada_name (const char *, tree, ada_name_role, | ||
| 716 | Added line. tree, const char *, const char *); | ||
| 717 | Added line. | ||
| 704 | 718 | static void pp_ada_namespace_name (pretty_printer *, tree); | |
| 705 | 719 | | |
| 706 | 720 | /* Return the innermost named C++ namespace containing NODE. Anonymous | |
| @@ -1459 +1473 @@pp_ada_namespace_name (pretty_printer *pp, tree ns) | |||
| 1459 | 1473 | bool space_found = false; | |
| 1460 | 1474 | char *name = to_ada_name (IDENTIFIER_POINTER (DECL_NAME (ns)), | |
| 1461 | 1475 | &space_found); | |
| 1462 | Removed line. pp_string (pp, name); | ||
| 1476 | Added line. const char *allocated | ||
| 1477 | Added line. = allocate_ada_name (name, DECL_NAME (ns), ADA_NAME_SOURCE, | ||
| 1478 | Added line. DECL_CONTEXT (ns), | ||
| 1479 | Added line. LOCATION_FILE (decl_sloc (ns, false)), "_Case_"); | ||
| 1480 | Added line. pp_string (pp, allocated); | ||
| 1463 | 1481 | free (name); | |
| 1464 | 1482 | } | |
| 1465 | 1483 | | |
| @@ -1501 +1519 @@static bool package_prefix = true; | |||
| 1501 | 1519 | static tree current_template = NULL_TREE; | |
| 1502 | 1520 | static tree current_template_instance = NULL_TREE; | |
| 1503 | 1521 | | |
| 1522 | Added line. struct allocated_ada_name | ||
| 1523 | Added line. { | ||
| 1524 | Added line. hashval_t hash; | ||
| 1525 | Added line. tree identity; | ||
| 1526 | Added line. tree scope; | ||
| 1527 | Added line. const char *file; | ||
| 1528 | Added line. ada_name_role role; | ||
| 1529 | Added line. char *name; | ||
| 1530 | Added line. | ||
| 1531 | Added line. ~allocated_ada_name () { free (name); } | ||
| 1532 | Added line. }; | ||
| 1533 | Added line. | ||
| 1534 | Added line. struct allocated_ada_name_hasher : delete_ptr_hash<allocated_ada_name> | ||
| 1535 | Added line. { | ||
| 1536 | Added line. static inline hashval_t hash (allocated_ada_name *entry) | ||
| 1537 | Added line. { return entry->hash; } | ||
| 1538 | Added line. static inline bool equal (allocated_ada_name *a, allocated_ada_name *b) | ||
| 1539 | Added line. { | ||
| 1540 | Added line. return (a->identity == b->identity && a->scope == b->scope | ||
| 1541 | Added line. && a->file == b->file | ||
| 1542 | Added line. && a->role == b->role); | ||
| 1543 | Added line. } | ||
| 1544 | Added line. }; | ||
| 1545 | Added line. | ||
| 1546 | Added line. struct occupied_ada_name | ||
| 1547 | Added line. { | ||
| 1548 | Added line. hashval_t hash; | ||
| 1549 | Added line. tree scope; | ||
| 1550 | Added line. const char *file; | ||
| 1551 | Added line. char *name; | ||
| 1552 | Added line. | ||
| 1553 | Added line. ~occupied_ada_name () { free (name); } | ||
| 1554 | Added line. }; | ||
| 1555 | Added line. | ||
| 1556 | Added line. struct occupied_ada_name_hasher : delete_ptr_hash<occupied_ada_name> | ||
| 1557 | Added line. { | ||
| 1558 | Added line. static inline hashval_t hash (occupied_ada_name *entry) | ||
| 1559 | Added line. { return entry->hash; } | ||
| 1560 | Added line. static inline bool equal (occupied_ada_name *a, occupied_ada_name *b) | ||
| 1561 | Added line. { | ||
| 1562 | Added line. return (a->scope == b->scope && a->file == b->file | ||
| 1563 | Added line. && !strcmp (a->name, b->name)); | ||
| 1564 | Added line. } | ||
| 1565 | Added line. }; | ||
| 1566 | Added line. | ||
| 1567 | Added line. typedef hash_table<allocated_ada_name_hasher> allocated_ada_name_table; | ||
| 1568 | Added line. typedef hash_table<occupied_ada_name_hasher> occupied_ada_name_table; | ||
| 1569 | Added line. static allocated_ada_name_table *allocated_ada_names; | ||
| 1570 | Added line. static occupied_ada_name_table *occupied_ada_names; | ||
| 1571 | Added line. | ||
| 1572 | Added line. /* Return a lower-case copy of NAME for Ada-insensitive comparison. */ | ||
| 1573 | Added line. | ||
| 1574 | Added line. static char * | ||
| 1575 | Added line. fold_ada_name (const char *name) | ||
| 1576 | Added line. { | ||
| 1577 | Added line. char *folded = xstrdup (name); | ||
| 1578 | Added line. for (char *p = folded; *p; ++p) | ||
| 1579 | Added line. *p = TOLOWER (*p); | ||
| 1580 | Added line. return folded; | ||
| 1581 | Added line. } | ||
| 1582 | Added line. | ||
| 1583 | Added line. /* Allocate a stable Ada name for IDENTITY and ROLE in SCOPE. PREFERRED is | ||
| 1584 | Added line. retained when it is unique. Only an actual collision receives SUFFIX and | ||
| 1585 | Added line. a deterministic ordinal. */ | ||
| 1586 | Added line. | ||
| 1587 | Added line. static const char * | ||
| 1588 | Added line. allocate_ada_name (const char *preferred, tree identity, ada_name_role role, | ||
| 1589 | Added line. tree scope, const char *file, const char *suffix) | ||
| 1590 | Added line. { | ||
| 1591 | Added line. allocated_ada_name query; | ||
| 1592 | Added line. query.identity = identity; | ||
| 1593 | Added line. query.scope = scope; | ||
| 1594 | Added line. query.file = file; | ||
| 1595 | Added line. query.role = role; | ||
| 1596 | Added line. query.name = NULL; | ||
| 1597 | Added line. query.hash = (htab_hash_pointer (identity) ^ htab_hash_pointer (scope) | ||
| 1598 | Added line. ^ htab_hash_pointer (file) ^ (hashval_t) role); | ||
| 1599 | Added line. allocated_ada_name *existing | ||
| 1600 | Added line. = allocated_ada_names->find_with_hash (&query, query.hash); | ||
| 1601 | Added line. if (existing) | ||
| 1602 | Added line. return existing->name; | ||
| 1603 | Added line. | ||
| 1604 | Added line. char *candidate = xstrdup (preferred); | ||
| 1605 | Added line. unsigned int ordinal = 1; | ||
| 1606 | Added line. while (true) | ||
| 1607 | Added line. { | ||
| 1608 | Added line. char *folded = fold_ada_name (candidate); | ||
| 1609 | Added line. occupied_ada_name occupied_query; | ||
| 1610 | Added line. occupied_query.scope = scope; | ||
| 1611 | Added line. occupied_query.file = file; | ||
| 1612 | Added line. occupied_query.name = folded; | ||
| 1613 | Added line. occupied_query.hash = (htab_hash_string (folded) | ||
| 1614 | Added line. ^ htab_hash_pointer (scope) | ||
| 1615 | Added line. ^ htab_hash_pointer (file)); | ||
| 1616 | Added line. occupied_ada_name *occupied_existing | ||
| 1617 | Added line. = occupied_ada_names->find_with_hash (&occupied_query, | ||
| 1618 | Added line. occupied_query.hash); | ||
| 1619 | Added line. if (!occupied_existing) | ||
| 1620 | Added line. { | ||
| 1621 | Added line. occupied_ada_name **occupied_slot | ||
| 1622 | Added line. = occupied_ada_names->find_slot_with_hash (&occupied_query, | ||
| 1623 | Added line. occupied_query.hash, INSERT); | ||
| 1624 | Added line. occupied_query.name = NULL; | ||
| 1625 | Added line. occupied_ada_name *occupied = new occupied_ada_name; | ||
| 1626 | Added line. occupied->hash = occupied_query.hash; | ||
| 1627 | Added line. occupied->scope = scope; | ||
| 1628 | Added line. occupied->file = file; | ||
| 1629 | Added line. occupied->name = folded; | ||
| 1630 | Added line. *occupied_slot = occupied; | ||
| 1631 | Added line. break; | ||
| 1632 | Added line. } | ||
| 1633 | Added line. | ||
| 1634 | Added line. occupied_query.name = NULL; | ||
| 1635 | Added line. free (folded); | ||
| 1636 | Added line. free (candidate); | ||
| 1637 | Added line. ++ordinal; | ||
| 1638 | Added line. const size_t length = strlen (preferred) + strlen (suffix) + 24; | ||
| 1639 | Added line. candidate = XNEWVEC (char, length); | ||
| 1640 | Added line. snprintf (candidate, length, "%s%s%u", preferred, suffix, ordinal); | ||
| 1641 | Added line. } | ||
| 1642 | Added line. | ||
| 1643 | Added line. allocated_ada_name **slot | ||
| 1644 | Added line. = allocated_ada_names->find_slot_with_hash (&query, query.hash, INSERT); | ||
| 1645 | Added line. allocated_ada_name *allocated = new allocated_ada_name; | ||
| 1646 | Added line. allocated->hash = query.hash; | ||
| 1647 | Added line. allocated->identity = identity; | ||
| 1648 | Added line. allocated->scope = scope; | ||
| 1649 | Added line. allocated->file = file; | ||
| 1650 | Added line. allocated->role = role; | ||
| 1651 | Added line. allocated->name = candidate; | ||
| 1652 | Added line. *slot = allocated; | ||
| 1653 | Added line. return allocated->name; | ||
| 1654 | Added line. } | ||
| 1655 | Added line. | ||
| 1504 | 1656 | /* Dump in BUFFER the name of an identifier NODE of type TYPE, following Ada | |
| 1505 | 1657 | syntax. LIMITED_ACCESS indicates whether NODE can be accessed through a | |
| 1506 | 1658 | limited 'with' clause rather than a regular 'with' clause. */ | |
| @@ -1513 +1665 @@pp_ada_tree_identifier (pretty_printer *buffer, tree node, tree type, | |||
| 1513 | 1665 | bool space_found = false; | |
| 1514 | 1666 | char *s = to_ada_name (name, &space_found); | |
| 1515 | 1667 | tree decl = get_underlying_decl (type); | |
| 1668 | Added line. const char *allocated = s; | ||
| 1669 | Added line. if (cpp_check && decl) | ||
| 1670 | Added line. allocated = allocate_ada_name (s, node, ADA_NAME_SOURCE, | ||
| 1671 | Added line. DECL_CONTEXT (decl), | ||
| 1672 | Added line. LOCATION_FILE (decl_sloc (decl, false)), | ||
| 1673 | Added line. "_Case_"); | ||
| 1516 | 1674 | | |
| 1517 | 1675 | bool external_decl = false; | |
| 1518 | 1676 | if (decl) | |
| @@ -1560 +1718 @@pp_ada_tree_identifier (pretty_printer *buffer, tree node, tree type, | |||
| 1560 | 1718 | || named_namespace_context (decl) != current_namespace)) | |
| 1561 | 1719 | { | |
| 1562 | 1720 | pp_string (buffer, "Class_"); | |
| 1563 | Removed line. pp_string (buffer, s); | ||
| 1721 | Added line. pp_string (buffer, allocated); | ||
| 1564 | 1722 | pp_dot (buffer); | |
| 1565 | 1723 | } | |
| 1566 | 1724 | } | |
| @@ -1589 +1747 @@pp_ada_tree_identifier (pretty_printer *buffer, tree node, tree type, | |||
| 1589 | 1747 | pp_string (buffer, "unsigned_long_long"); | |
| 1590 | 1748 | } | |
| 1591 | 1749 | else | |
| 1592 | Removed line. pp_string(buffer, s); | ||
| 1750 | Added line. pp_string(buffer, allocated); | ||
| 1593 | 1751 | else | |
| 1594 | 1752 | if (!strcmp (s, "u_Bool") || !strcmp (s, "bool")) | |
| 1595 | 1753 | { | |
| @@ -1602 +1760 @@pp_ada_tree_identifier (pretty_printer *buffer, tree node, tree type, | |||
| 1602 | 1760 | pp_string (buffer, "bool"); | |
| 1603 | 1761 | } | |
| 1604 | 1762 | else | |
| 1605 | Removed line. pp_string(buffer, s); | ||
| 1763 | Added line. pp_string(buffer, allocated); | ||
| 1606 | 1764 | | |
| 1607 | 1765 | free (s); | |
| 1608 | 1766 | } | |
| @@ -3873 +4031 @@dump_ada_specs (void (*collect_all_refs)(const char *), | |||
| 3873 | 4031 | bitmap_obstack_initialize (NULL); | |
| 3874 | 4032 | | |
| 3875 | 4033 | overloaded_names = init_overloaded_names (); | |
| 4034 | Added line. allocated_ada_names = new allocated_ada_name_table (64); | ||
| 4035 | Added line. occupied_ada_names = new occupied_ada_name_table (64); | ||
| 3876 | 4036 | | |
| 3877 | 4037 | /* Iterate over the list of files to dump specs for. */ | |
| 3878 | 4038 | for (int i = 0; i < source_refs_used; i++) | |
| @@ -3885 +4045 @@dump_ada_specs (void (*collect_all_refs)(const char *), | |||
| 3885 | 4045 | /* Free various tables. */ | |
| 3886 | 4046 | free (source_refs); | |
| 3887 | 4047 | delete overloaded_names; | |
| 4048 | Added line. delete allocated_ada_names; | ||
| 4049 | Added line. delete occupied_ada_names; | ||
| 3888 | 4050 | | |
| 3889 | 4051 | bitmap_obstack_release (NULL); | |
| 3890 | 4052 | } | |
gcc/testsuite/g++.dg/ada-spec/casefold-identity.C
+34−0new file
| @@ -0 +1 @@ | |||
| 1 | Added line. /* { dg-do compile } */ | ||
| 2 | Added line. /* { dg-options "-fdump-ada-spec-slim" } */ | ||
| 3 | Added line. /* { dg-final { scan-file casefold_identity_c.ads "type ITEM_Case_2" } } */ | ||
| 4 | Added line. /* { dg-final { scan-file casefold_identity_c.ads "subtype ALIAS_Case_2" } } */ | ||
| 5 | Added line. /* { dg-final { scan-file casefold_identity_c.ads "VALUE_Case_2" } } */ | ||
| 6 | Added line. /* { dg-final { scan-file casefold_identity_c.ads "VaLuE_Case_3" } } */ | ||
| 7 | Added line. /* { dg-final { scan-file casefold_identity_c.ads "function MEASURE_Case_2" } } */ | ||
| 8 | Added line. | ||
| 9 | Added line. struct Item | ||
| 10 | Added line. { | ||
| 11 | Added line. int value; | ||
| 12 | Added line. }; | ||
| 13 | Added line. | ||
| 14 | Added line. struct ITEM | ||
| 15 | Added line. { | ||
| 16 | Added line. double value; | ||
| 17 | Added line. }; | ||
| 18 | Added line. | ||
| 19 | Added line. using Alias = Item; | ||
| 20 | Added line. using ALIAS = ITEM; | ||
| 21 | Added line. | ||
| 22 | Added line. struct Fields | ||
| 23 | Added line. { | ||
| 24 | Added line. int value; | ||
| 25 | Added line. int VALUE; | ||
| 26 | Added line. int VaLuE; | ||
| 27 | Added line. }; | ||
| 28 | Added line. | ||
| 29 | Added line. int measure (Item item) { return item.value; } | ||
| 30 | Added line. int MEASURE (ITEM item) { return static_cast<int> (item.value); } | ||
| 31 | Added line. int combine (Fields fields) | ||
| 32 | Added line. { return fields.value + fields.VALUE + fields.VaLuE; } | ||
| 33 | Added line. | ||
| 34 | Added line. /* { dg-final { cleanup-ada-spec } } */ | ||
| 35 | | ||