summaryrefslogtreecommitdiffstats
path: root/libiberty
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-08-29 20:04:24 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-08-30 01:14:18 +0200
commit34f3e0657a1fa976d989b22d18b3b2adf6ddd59b (patch)
treef42ebab871e2504b77aa9d328bb4b63abd7957be /libiberty
parentlibiberty: Add support for D `typeof(*null)' types (diff)
downloadgcc-34f3e0657a1fa976d989b22d18b3b2adf6ddd59b.tar.gz
gcc-34f3e0657a1fa976d989b22d18b3b2adf6ddd59b.tar.bz2
gcc-34f3e0657a1fa976d989b22d18b3b2adf6ddd59b.tar.xz
libiberty: Add support for demangling D function literals as template value parameters
The D language now allows instantiating templates using struct literals that have function literal fields as a value argument. libiberty/ChangeLog: * d-demangle.c (dlang_parse_arrayliteral): Add 'info' parameter. (dlang_parse_assocarray): Likewise. (dlang_parse_structlit): Likewise. (dlang_value): Likewise. Handle function literal symbols. (dlang_template_args): Pass 'info' to dlang_value. * testsuite/d-demangle-expected: Add new test.
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/d-demangle.c40
-rw-r--r--libiberty/testsuite/d-demangle-expected4
2 files changed, 31 insertions, 13 deletions
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index c34f91843de..d74cf47b1a9 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -191,7 +191,8 @@ static const char *dlang_function_args (string *, const char *,
191 191
192static const char *dlang_type (string *, const char *, struct dlang_info *); 192static const char *dlang_type (string *, const char *, struct dlang_info *);
193 193
194static const char *dlang_value (string *, const char *, const char *, char); 194static const char *dlang_value (string *, const char *, const char *, char,
195 struct dlang_info *);
195 196
196static const char *dlang_parse_qualified (string *, const char *, 197static const char *dlang_parse_qualified (string *, const char *,
197 struct dlang_info *, int); 198 struct dlang_info *, int);
@@ -1386,7 +1387,8 @@ dlang_parse_string (string *decl, const char *mangled)
1386/* Extract the static array value from MANGLED and append it to DECL. 1387/* Extract the static array value from MANGLED and append it to DECL.
1387 Return the remaining string on success or NULL on failure. */ 1388 Return the remaining string on success or NULL on failure. */
1388static const char * 1389static const char *
1389dlang_parse_arrayliteral (string *decl, const char *mangled) 1390dlang_parse_arrayliteral (string *decl, const char *mangled,
1391 struct dlang_info *info)
1390{ 1392{
1391 unsigned long elements; 1393 unsigned long elements;
1392 1394
@@ -1397,7 +1399,7 @@ dlang_parse_arrayliteral (string *decl, const char *mangled)
1397 string_append (decl, "["); 1399 string_append (decl, "[");
1398 while (elements--) 1400 while (elements--)
1399 { 1401 {
1400 mangled = dlang_value (decl, mangled, NULL, '\0'); 1402 mangled = dlang_value (decl, mangled, NULL, '\0', info);
1401 if (mangled == NULL) 1403 if (mangled == NULL)
1402 return NULL; 1404 return NULL;
1403 1405
@@ -1412,7 +1414,8 @@ dlang_parse_arrayliteral (string *decl, const char *mangled)
1412/* Extract the associative array value from MANGLED and append it to DECL. 1414/* Extract the associative array value from MANGLED and append it to DECL.
1413 Return the remaining string on success or NULL on failure. */ 1415 Return the remaining string on success or NULL on failure. */
1414static const char * 1416static const char *
1415dlang_parse_assocarray (string *decl, const char *mangled) 1417dlang_parse_assocarray (string *decl, const char *mangled,
1418 struct dlang_info *info)
1416{ 1419{
1417 unsigned long elements; 1420 unsigned long elements;
1418 1421
@@ -1423,12 +1426,12 @@ dlang_parse_assocarray (string *decl, const char *mangled)
1423 string_append (decl, "["); 1426 string_append (decl, "[");
1424 while (elements--) 1427 while (elements--)
1425 { 1428 {
1426 mangled = dlang_value (decl, mangled, NULL, '\0'); 1429 mangled = dlang_value (decl, mangled, NULL, '\0', info);
1427 if (mangled == NULL) 1430 if (mangled == NULL)
1428 return NULL; 1431 return NULL;
1429 1432
1430 string_append (decl, ":"); 1433 string_append (decl, ":");
1431 mangled = dlang_value (decl, mangled, NULL, '\0'); 1434 mangled = dlang_value (decl, mangled, NULL, '\0', info);
1432 if (mangled == NULL) 1435 if (mangled == NULL)
1433 return NULL; 1436 return NULL;
1434 1437
@@ -1443,7 +1446,8 @@ dlang_parse_assocarray (string *decl, const char *mangled)
1443/* Extract the struct literal value for NAME from MANGLED and append it to DECL. 1446/* Extract the struct literal value for NAME from MANGLED and append it to DECL.
1444 Return the remaining string on success or NULL on failure. */ 1447 Return the remaining string on success or NULL on failure. */
1445static const char * 1448static const char *
1446dlang_parse_structlit (string *decl, const char *mangled, const char *name) 1449dlang_parse_structlit (string *decl, const char *mangled, const char *name,
1450 struct dlang_info *info)
1447{ 1451{
1448 unsigned long args; 1452 unsigned long args;
1449 1453
@@ -1457,7 +1461,7 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name)
1457 string_append (decl, "("); 1461 string_append (decl, "(");
1458 while (args--) 1462 while (args--)
1459 { 1463 {
1460 mangled = dlang_value (decl, mangled, NULL, '\0'); 1464 mangled = dlang_value (decl, mangled, NULL, '\0', info);
1461 if (mangled == NULL) 1465 if (mangled == NULL)
1462 return NULL; 1466 return NULL;
1463 1467
@@ -1472,7 +1476,8 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name)
1472/* Extract the value from MANGLED and append it to DECL. 1476/* Extract the value from MANGLED and append it to DECL.
1473 Return the remaining string on success or NULL on failure. */ 1477 Return the remaining string on success or NULL on failure. */
1474static const char * 1478static const char *
1475dlang_value (string *decl, const char *mangled, const char *name, char type) 1479dlang_value (string *decl, const char *mangled, const char *name, char type,
1480 struct dlang_info *info)
1476{ 1481{
1477 if (mangled == NULL || *mangled == '\0') 1482 if (mangled == NULL || *mangled == '\0')
1478 return NULL; 1483 return NULL;
@@ -1533,15 +1538,24 @@ dlang_value (string *decl, const char *mangled, const char *name, char type)
1533 case 'A': 1538 case 'A':
1534 mangled++; 1539 mangled++;
1535 if (type == 'H') 1540 if (type == 'H')
1536 mangled = dlang_parse_assocarray (decl, mangled); 1541 mangled = dlang_parse_assocarray (decl, mangled, info);
1537 else 1542 else
1538 mangled = dlang_parse_arrayliteral (decl, mangled); 1543 mangled = dlang_parse_arrayliteral (decl, mangled, info);
1539 break; 1544 break;
1540 1545
1541 /* Struct values. */ 1546 /* Struct values. */
1542 case 'S': 1547 case 'S':
1543 mangled++; 1548 mangled++;
1544 mangled = dlang_parse_structlit (decl, mangled, name); 1549 mangled = dlang_parse_structlit (decl, mangled, name, info);
1550 break;
1551
1552 /* Function literal symbol. */
1553 case 'f':
1554 mangled++;
1555 if (strncmp (mangled, "_D", 2) != 0
1556 || !dlang_symbol_name_p (mangled + 2, info))
1557 return NULL;
1558 mangled = dlang_parse_mangle (decl, mangled, info);
1545 break; 1559 break;
1546 1560
1547 default: 1561 default:
@@ -1814,7 +1828,7 @@ dlang_template_args (string *decl, const char *mangled, struct dlang_info *info)
1814 string_need (&name, 1); 1828 string_need (&name, 1);
1815 *(name.p) = '\0'; 1829 *(name.p) = '\0';
1816 1830
1817 mangled = dlang_value (decl, mangled, name.b, type); 1831 mangled = dlang_value (decl, mangled, name.b, type, info);
1818 string_delete (&name); 1832 string_delete (&name);
1819 break; 1833 break;
1820 } 1834 }
diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected
index 00036e7810a..87ed8d330a8 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -1418,3 +1418,7 @@ std.algorithm.iteration.FilterResult!(std.typecons.Tuple!(int, "a", int, "b", in
1418--format=dlang 1418--format=dlang
1419_D3std3uni__T6toCaseS_DQvQt12toLowerIndexFNaNbNiNewZtVii1043S_DQCjQCi10toLowerTabFNaNbNiNemZwSQDo5ascii7toLowerTAyaZQDzFNaNeQmZ14__foreachbody2MFNaNeKmKwZ14__foreachbody3MFNaNeKwZi 1419_D3std3uni__T6toCaseS_DQvQt12toLowerIndexFNaNbNiNewZtVii1043S_DQCjQCi10toLowerTabFNaNbNiNemZwSQDo5ascii7toLowerTAyaZQDzFNaNeQmZ14__foreachbody2MFNaNeKmKwZ14__foreachbody3MFNaNeKwZi
1420std.uni.toCase!(std.uni.toLowerIndex(dchar), 1043, std.uni.toLowerTab(ulong), std.ascii.toLower, immutable(char)[]).toCase(immutable(char)[]).__foreachbody2(ref ulong, ref dchar).__foreachbody3(ref dchar) 1420std.uni.toCase!(std.uni.toLowerIndex(dchar), 1043, std.uni.toLowerTab(ulong), std.ascii.toLower, immutable(char)[]).toCase(immutable(char)[]).__foreachbody2(ref ulong, ref dchar).__foreachbody3(ref dchar)
1421#
1422--format=dlang
1423_D6mangle__T8fun21753VSQv6S21753S1f_DQBj10__lambda71MFNaNbNiNfZvZQCbQp
1424mangle.fun21753!(mangle.S21753(mangle.__lambda71())).fun21753