summaryrefslogtreecommitdiffstats
path: root/libiberty
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-03-08 10:53:39 -0800
committerNathan Sidwell <nathan@acm.org>2022-05-18 03:58:55 -0700
commit65851d65fb36e847a9b8ef3b0519f06d29865a14 (patch)
tree47d29098e9f89fc6696255364f0f7e147ea726ec /libiberty
parent'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run' (diff)
downloadgcc-65851d65fb36e847a9b8ef3b0519f06d29865a14.tar.gz
gcc-65851d65fb36e847a9b8ef3b0519f06d29865a14.tar.bz2
gcc-65851d65fb36e847a9b8ef3b0519f06d29865a14.tar.xz
demangler: Reorganize for module demangling
Module demangling requires some changes in how substitutions are handled. This adjusts things to make that possible. libiberty/ * cp-demangle.c (d_name): Add SUBSTABLE parameter, push substitution if requested. Adjust unscoped name handling. (d_prefix): Reorder main loop. Adjust all calls. (d_unqualified_name): Add SCOPE parameter, create qualified name here. Adjust all calls. (cplus_demangle_type): Do not handle 'S' here, leave all to d_class_enum_type. (d_class_enum_type): Add SUBSTABLE parameter.
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/cp-demangle.c222
1 files changed, 83 insertions, 139 deletions
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index fc618fa7383..cf451c5aff2 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -425,13 +425,14 @@ is_ctor_dtor_or_conversion (struct demangle_component *);
425 425
426static struct demangle_component *d_encoding (struct d_info *, int); 426static struct demangle_component *d_encoding (struct d_info *, int);
427 427
428static struct demangle_component *d_name (struct d_info *); 428static struct demangle_component *d_name (struct d_info *, int substable);
429 429
430static struct demangle_component *d_nested_name (struct d_info *); 430static struct demangle_component *d_nested_name (struct d_info *);
431 431
432static struct demangle_component *d_prefix (struct d_info *, int); 432static struct demangle_component *d_prefix (struct d_info *, int);
433 433
434static struct demangle_component *d_unqualified_name (struct d_info *); 434static struct demangle_component *d_unqualified_name (struct d_info *,
435 struct demangle_component *scope);
435 436
436static struct demangle_component *d_source_name (struct d_info *); 437static struct demangle_component *d_source_name (struct d_info *);
437 438
@@ -462,7 +463,7 @@ static struct demangle_component *
462d_bare_function_type (struct d_info *, int); 463d_bare_function_type (struct d_info *, int);
463 464
464static struct demangle_component * 465static struct demangle_component *
465d_class_enum_type (struct d_info *); 466d_class_enum_type (struct d_info *, int);
466 467
467static struct demangle_component *d_array_type (struct d_info *); 468static struct demangle_component *d_array_type (struct d_info *);
468 469
@@ -1323,7 +1324,7 @@ d_encoding (struct d_info *di, int top_level)
1323 dc = d_special_name (di); 1324 dc = d_special_name (di);
1324 else 1325 else
1325 { 1326 {
1326 dc = d_name (di); 1327 dc = d_name (di, 0);
1327 1328
1328 if (!dc) 1329 if (!dc)
1329 /* Failed already. */; 1330 /* Failed already. */;
@@ -1417,80 +1418,64 @@ d_abi_tags (struct d_info *di, struct demangle_component *dc)
1417*/ 1418*/
1418 1419
1419static struct demangle_component * 1420static struct demangle_component *
1420d_name (struct d_info *di) 1421d_name (struct d_info *di, int substable)
1421{ 1422{
1422 char peek = d_peek_char (di); 1423 char peek = d_peek_char (di);
1423 struct demangle_component *dc; 1424 struct demangle_component *dc = NULL;
1425 int subst = 0;
1424 1426
1425 switch (peek) 1427 switch (peek)
1426 { 1428 {
1427 case 'N': 1429 case 'N':
1428 return d_nested_name (di); 1430 dc = d_nested_name (di);
1431 break;
1429 1432
1430 case 'Z': 1433 case 'Z':
1431 return d_local_name (di); 1434 dc = d_local_name (di);
1435 break;
1432 1436
1433 case 'U': 1437 case 'U':
1434 return d_unqualified_name (di); 1438 dc = d_unqualified_name (di, NULL);
1439 break;
1435 1440
1436 case 'S': 1441 case 'S':
1437 { 1442 {
1438 int subst; 1443 if (d_peek_next_char (di) == 't')
1439
1440 if (d_peek_next_char (di) != 't')
1441 {
1442 dc = d_substitution (di, 0);
1443 subst = 1;
1444 }
1445 else
1446 { 1444 {
1447 d_advance (di, 2); 1445 d_advance (di, 2);
1448 dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, 1446 dc = d_make_name (di, "std", 3);
1449 d_make_name (di, "std", 3),
1450 d_unqualified_name (di));
1451 di->expansion += 3; 1447 di->expansion += 3;
1452 subst = 0;
1453 }
1454
1455 if (d_peek_char (di) != 'I')
1456 {
1457 /* The grammar does not permit this case to occur if we
1458 called d_substitution() above (i.e., subst == 1). We
1459 don't bother to check. */
1460 } 1448 }
1461 else 1449 else
1462 { 1450 {
1463 /* This is <template-args>, which means that we just saw 1451 dc = d_substitution (di, 0);
1464 <unscoped-template-name>, which is a substitution 1452 if (!dc)
1465 candidate if we didn't just get it from a 1453 return NULL;
1466 substitution. */ 1454 subst = 1;
1467 if (! subst)
1468 {
1469 if (! d_add_substitution (di, dc))
1470 return NULL;
1471 }
1472 dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1473 d_template_args (di));
1474 } 1455 }
1475
1476 return dc;
1477 } 1456 }
1457 /* FALLTHROUGH */
1478 1458
1479 case 'L': 1459 case 'L':
1480 default: 1460 default:
1481 dc = d_unqualified_name (di); 1461 if (!subst)
1462 dc = d_unqualified_name (di, dc);
1482 if (d_peek_char (di) == 'I') 1463 if (d_peek_char (di) == 'I')
1483 { 1464 {
1484 /* This is <template-args>, which means that we just saw 1465 /* This is <template-args>, which means that we just saw
1485 <unscoped-template-name>, which is a substitution 1466 <unscoped-template-name>, which is a substitution
1486 candidate. */ 1467 candidate. */
1487 if (! d_add_substitution (di, dc)) 1468 if (!subst && !d_add_substitution (di, dc))
1488 return NULL; 1469 return NULL;
1489 dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc, 1470 dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1490 d_template_args (di)); 1471 d_template_args (di));
1472 subst = 0;
1491 } 1473 }
1492 return dc; 1474 break;
1493 } 1475 }
1476 if (substable && !subst && !d_add_substitution (di, dc))
1477 return NULL;
1478 return dc;
1494} 1479}
1495 1480
1496/* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E 1481/* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
@@ -1546,54 +1531,51 @@ d_nested_name (struct d_info *di)
1546 if not (in an unresolved-name). */ 1531 if not (in an unresolved-name). */
1547 1532
1548static struct demangle_component * 1533static struct demangle_component *
1549d_prefix (struct d_info *di, int subst) 1534d_prefix (struct d_info *di, int substable)
1550{ 1535{
1551 struct demangle_component *ret = NULL; 1536 struct demangle_component *ret = NULL;
1552 1537
1553 while (1) 1538 for (;;)
1554 { 1539 {
1555 char peek; 1540 char peek = d_peek_char (di);
1556 enum demangle_component_type comb_type;
1557 struct demangle_component *dc;
1558
1559 peek = d_peek_char (di);
1560 if (peek == '\0')
1561 return NULL;
1562 1541
1563 /* The older code accepts a <local-name> here, but I don't see 1542 /* The older code accepts a <local-name> here, but I don't see
1564 that in the grammar. The older code does not accept a 1543 that in the grammar. The older code does not accept a
1565 <template-param> here. */ 1544 <template-param> here. */
1566 1545
1567 comb_type = DEMANGLE_COMPONENT_QUAL_NAME; 1546 if (peek == 'D'
1568 if (peek == 'D') 1547 && (d_peek_next_char (di) == 'T'
1548 || d_peek_next_char (di) == 't'))
1569 { 1549 {
1570 char peek2 = d_peek_next_char (di); 1550 /* Decltype. */
1571 if (peek2 == 'T' || peek2 == 't') 1551 if (ret)
1572 /* Decltype. */ 1552 return NULL;
1573 dc = cplus_demangle_type (di); 1553 ret = cplus_demangle_type (di);
1574 else
1575 /* Destructor name. */
1576 dc = d_unqualified_name (di);
1577 } 1554 }
1578 else if (IS_DIGIT (peek)
1579 || IS_LOWER (peek)
1580 || peek == 'C'
1581 || peek == 'U'
1582 || peek == 'L')
1583 dc = d_unqualified_name (di);
1584 else if (peek == 'S') 1555 else if (peek == 'S')
1585 dc = d_substitution (di, 1); 1556 {
1557 if (ret)
1558 return NULL;
1559 ret = d_substitution (di, 1);
1560 if (!ret)
1561 return NULL;
1562 continue;
1563 }
1586 else if (peek == 'I') 1564 else if (peek == 'I')
1587 { 1565 {
1588 if (ret == NULL) 1566 if (ret == NULL)
1589 return NULL; 1567 return NULL;
1590 comb_type = DEMANGLE_COMPONENT_TEMPLATE; 1568 struct demangle_component *dc = d_template_args (di);
1591 dc = d_template_args (di); 1569 if (!dc)
1570 return NULL;
1571 ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, dc);
1592 } 1572 }
1593 else if (peek == 'T') 1573 else if (peek == 'T')
1594 dc = d_template_param (di); 1574 {
1595 else if (peek == 'E') 1575 if (ret)
1596 return ret; 1576 return NULL;
1577 ret = d_template_param (di);
1578 }
1597 else if (peek == 'M') 1579 else if (peek == 'M')
1598 { 1580 {
1599 /* Initializer scope for a lambda. We don't need to represent 1581 /* Initializer scope for a lambda. We don't need to represent
@@ -1602,22 +1584,21 @@ d_prefix (struct d_info *di, int subst)
1602 if (ret == NULL) 1584 if (ret == NULL)
1603 return NULL; 1585 return NULL;
1604 d_advance (di, 1); 1586 d_advance (di, 1);
1605 continue;
1606 } 1587 }
1607 else 1588 else
1608 return NULL; 1589 ret = d_unqualified_name (di, ret);
1609 1590
1610 if (ret == NULL) 1591 if (!ret)
1611 ret = dc; 1592 break;
1612 else
1613 ret = d_make_comp (di, comb_type, ret, dc);
1614 1593
1615 if (peek != 'S' && d_peek_char (di) != 'E' && subst) 1594 if (d_peek_char (di) == 'E')
1616 { 1595 break;
1617 if (! d_add_substitution (di, ret)) 1596
1618 return NULL; 1597 if (substable && !d_add_substitution (di, ret))
1619 } 1598 return NULL;
1620 } 1599 }
1600
1601 return ret;
1621} 1602}
1622 1603
1623/* <unqualified-name> ::= <operator-name> [<abi-tags>] 1604/* <unqualified-name> ::= <operator-name> [<abi-tags>]
@@ -1629,7 +1610,7 @@ d_prefix (struct d_info *di, int subst)
1629*/ 1610*/
1630 1611
1631static struct demangle_component * 1612static struct demangle_component *
1632d_unqualified_name (struct d_info *di) 1613d_unqualified_name (struct d_info *di, struct demangle_component *scope)
1633{ 1614{
1634 struct demangle_component *ret; 1615 struct demangle_component *ret;
1635 char peek; 1616 char peek;
@@ -1709,6 +1690,9 @@ d_unqualified_name (struct d_info *di)
1709 1690
1710 if (d_peek_char (di) == 'B') 1691 if (d_peek_char (di) == 'B')
1711 ret = d_abi_tags (di, ret); 1692 ret = d_abi_tags (di, ret);
1693 if (scope)
1694 ret = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, scope, ret);
1695
1712 return ret; 1696 return ret;
1713} 1697}
1714 1698
@@ -2149,11 +2133,11 @@ d_special_name (struct d_info *di)
2149 2133
2150 case 'H': 2134 case 'H':
2151 return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT, 2135 return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT,
2152 d_name (di), NULL); 2136 d_name (di, 0), NULL);
2153 2137
2154 case 'W': 2138 case 'W':
2155 return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER, 2139 return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER,
2156 d_name (di), NULL); 2140 d_name (di, 0), NULL);
2157 2141
2158 case 'A': 2142 case 'A':
2159 return d_make_comp (di, DEMANGLE_COMPONENT_TPARM_OBJ, 2143 return d_make_comp (di, DEMANGLE_COMPONENT_TPARM_OBJ,
@@ -2169,11 +2153,11 @@ d_special_name (struct d_info *di)
2169 { 2153 {
2170 case 'V': 2154 case 'V':
2171 return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, 2155 return d_make_comp (di, DEMANGLE_COMPONENT_GUARD,
2172 d_name (di), NULL); 2156 d_name (di, 0), NULL);
2173 2157
2174 case 'R': 2158 case 'R':
2175 { 2159 {
2176 struct demangle_component *name = d_name (di); 2160 struct demangle_component *name = d_name (di, 0);
2177 return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name, 2161 return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name,
2178 d_number_component (di)); 2162 d_number_component (di));
2179 } 2163 }
@@ -2504,13 +2488,6 @@ cplus_demangle_type (struct d_info *di)
2504 ret = d_function_type (di); 2488 ret = d_function_type (di);
2505 break; 2489 break;
2506 2490
2507 case '0': case '1': case '2': case '3': case '4':
2508 case '5': case '6': case '7': case '8': case '9':
2509 case 'N':
2510 case 'Z':
2511 ret = d_class_enum_type (di);
2512 break;
2513
2514 case 'A': 2491 case 'A':
2515 ret = d_array_type (di); 2492 ret = d_array_type (di);
2516 break; 2493 break;
@@ -2581,39 +2558,6 @@ cplus_demangle_type (struct d_info *di)
2581 } 2558 }
2582 break; 2559 break;
2583 2560
2584 case 'S':
2585 /* If this is a special substitution, then it is the start of
2586 <class-enum-type>. */
2587 {
2588 char peek_next;
2589
2590 peek_next = d_peek_next_char (di);
2591 if (IS_DIGIT (peek_next)
2592 || peek_next == '_'
2593 || IS_UPPER (peek_next))
2594 {
2595 ret = d_substitution (di, 0);
2596 /* The substituted name may have been a template name and
2597 may be followed by tepmlate args. */
2598 if (d_peek_char (di) == 'I')
2599 ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2600 d_template_args (di));
2601 else
2602 can_subst = 0;
2603 }
2604 else
2605 {
2606 ret = d_class_enum_type (di);
2607 /* If the substitution was a complete type, then it is not
2608 a new substitution candidate. However, if the
2609 substitution was followed by template arguments, then
2610 the whole thing is a substitution candidate. */
2611 if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
2612 can_subst = 0;
2613 }
2614 }
2615 break;
2616
2617 case 'O': 2561 case 'O':
2618 d_advance (di, 1); 2562 d_advance (di, 1);
2619 ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE, 2563 ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE,
@@ -2754,7 +2698,7 @@ cplus_demangle_type (struct d_info *di)
2754 break; 2698 break;
2755 2699
2756 default: 2700 default:
2757 return NULL; 2701 return d_class_enum_type (di, 1);
2758 } 2702 }
2759 2703
2760 if (can_subst) 2704 if (can_subst)
@@ -3027,9 +2971,9 @@ d_bare_function_type (struct d_info *di, int has_return_type)
3027/* <class-enum-type> ::= <name> */ 2971/* <class-enum-type> ::= <name> */
3028 2972
3029static struct demangle_component * 2973static struct demangle_component *
3030d_class_enum_type (struct d_info *di) 2974d_class_enum_type (struct d_info *di, int substable)
3031{ 2975{
3032 return d_name (di); 2976 return d_name (di, substable);
3033} 2977}
3034 2978
3035/* <array-type> ::= A <(positive dimension) number> _ <(element) type> 2979/* <array-type> ::= A <(positive dimension) number> _ <(element) type>
@@ -3358,11 +3302,11 @@ d_unresolved_name (struct d_info *di)
3358 } 3302 }
3359 else 3303 else
3360 type = cplus_demangle_type (di); 3304 type = cplus_demangle_type (di);
3361 name = d_unqualified_name (di); 3305 name = d_unqualified_name (di, type);
3362 if (d_peek_char (di) == 'I') 3306 if (d_peek_char (di) == 'I')
3363 name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name, 3307 name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3364 d_template_args (di)); 3308 d_template_args (di));
3365 return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name); 3309 return name;
3366} 3310}
3367 3311
3368/* <expression> ::= <(unary) operator-name> <expression> 3312/* <expression> ::= <(unary) operator-name> <expression>
@@ -3431,7 +3375,7 @@ d_expression_1 (struct d_info *di)
3431 /* operator-function-id, i.e. operator+(t). */ 3375 /* operator-function-id, i.e. operator+(t). */
3432 d_advance (di, 2); 3376 d_advance (di, 2);
3433 3377
3434 name = d_unqualified_name (di); 3378 name = d_unqualified_name (di, NULL);
3435 if (name == NULL) 3379 if (name == NULL)
3436 return NULL; 3380 return NULL;
3437 if (d_peek_char (di) == 'I') 3381 if (d_peek_char (di) == 'I')
@@ -3539,7 +3483,7 @@ d_expression_1 (struct d_info *di)
3539 /* fold-expression. */ 3483 /* fold-expression. */
3540 left = d_operator_name (di); 3484 left = d_operator_name (di);
3541 else if (!strcmp (code, "di")) 3485 else if (!strcmp (code, "di"))
3542 left = d_unqualified_name (di); 3486 left = d_unqualified_name (di, NULL);
3543 else 3487 else
3544 left = d_expression_1 (di); 3488 left = d_expression_1 (di);
3545 if (!strcmp (code, "cl")) 3489 if (!strcmp (code, "cl"))
@@ -3557,7 +3501,7 @@ d_expression_1 (struct d_info *di)
3557 d_unqualified_name rather than d_expression_1 here for 3501 d_unqualified_name rather than d_expression_1 here for
3558 old mangled names that didn't add 'on' before operator 3502 old mangled names that didn't add 'on' before operator
3559 names. */ 3503 names. */
3560 right = d_unqualified_name (di); 3504 right = d_unqualified_name (di, NULL);
3561 if (d_peek_char (di) == 'I') 3505 if (d_peek_char (di) == 'I')
3562 right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, 3506 right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
3563 right, d_template_args (di)); 3507 right, d_template_args (di));
@@ -3767,7 +3711,7 @@ d_local_name (struct d_info *di)
3767 return NULL; 3711 return NULL;
3768 } 3712 }
3769 3713
3770 name = d_name (di); 3714 name = d_name (di, 0);
3771 3715
3772 if (name 3716 if (name
3773 /* Lambdas and unnamed types have internal discriminators 3717 /* Lambdas and unnamed types have internal discriminators