summaryrefslogtreecommitdiffstats
path: root/libiberty
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-03-08 13:00:35 -0800
committerNathan Sidwell <nathan@acm.org>2022-05-17 11:10:03 -0700
commit451894cadcf1210883ceefb2d69a0ed2d6a8cd8b (patch)
tree1d02872b057666ed99f2fbd5d5abb1bcefb2293b /libiberty
parentPR105169 Fix references to discarded sections (diff)
downloadgcc-451894cadcf1210883ceefb2d69a0ed2d6a8cd8b.tar.gz
gcc-451894cadcf1210883ceefb2d69a0ed2d6a8cd8b.tar.bz2
gcc-451894cadcf1210883ceefb2d69a0ed2d6a8cd8b.tar.xz
demangler: Structured Bindings
C++ Structured bindings have a mangling that has yet to be formally documented. However, it's been around for a while and shows up for module support. include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_STRUCTURED_BINDING. libiberty/ * cp-demangle.c (d_make_comp): Adjust. (d_unqualified_name): Add 'DC' support. (d_count_template_scopes): Adjust. (d_print_comp_inner): Add structured binding. * testsuite/demangle-expected: Add testcases.
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/cp-demangle.c49
-rw-r--r--libiberty/testsuite/demangle-expected10
2 files changed, 53 insertions, 6 deletions
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 6dff7d28fcf..fc618fa7383 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -1020,6 +1020,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
1020 case DEMANGLE_COMPONENT_NULLARY: 1020 case DEMANGLE_COMPONENT_NULLARY:
1021 case DEMANGLE_COMPONENT_TRINARY_ARG2: 1021 case DEMANGLE_COMPONENT_TRINARY_ARG2:
1022 case DEMANGLE_COMPONENT_TPARM_OBJ: 1022 case DEMANGLE_COMPONENT_TPARM_OBJ:
1023 case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
1023 if (left == NULL) 1024 if (left == NULL)
1024 return NULL; 1025 return NULL;
1025 break; 1026 break;
@@ -1619,12 +1620,12 @@ d_prefix (struct d_info *di, int subst)
1619 } 1620 }
1620} 1621}
1621 1622
1622/* <unqualified-name> ::= <operator-name> 1623/* <unqualified-name> ::= <operator-name> [<abi-tags>]
1623 ::= <ctor-dtor-name> 1624 ::= <ctor-dtor-name> [<abi-tags>]
1624 ::= <source-name> 1625 ::= <source-name> [<abi-tags>]
1625 ::= <local-source-name> 1626 ::= <local-source-name> [<abi-tags>]
1626 1627 ::= DC <source-name>+ E [<abi-tags>]
1627 <local-source-name> ::= L <source-name> <discriminator> 1628 <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
1628*/ 1629*/
1629 1630
1630static struct demangle_component * 1631static struct demangle_component *
@@ -1655,6 +1656,28 @@ d_unqualified_name (struct d_info *di)
1655 d_source_name (di)); 1656 d_source_name (di));
1656 } 1657 }
1657 } 1658 }
1659 else if (peek == 'D' && d_peek_next_char (di) == 'C')
1660 {
1661 // structured binding
1662 d_advance (di, 2);
1663 struct demangle_component *prev = NULL;
1664 do
1665 {
1666 struct demangle_component *next =
1667 d_make_comp (di, DEMANGLE_COMPONENT_STRUCTURED_BINDING,
1668 d_source_name (di), NULL);
1669 if (prev)
1670 d_right (prev) = next;
1671 else
1672 ret = next;
1673 prev = next;
1674 }
1675 while (prev && d_peek_char (di) != 'E');
1676 if (prev)
1677 d_advance (di, 1);
1678 else
1679 ret = NULL;
1680 }
1658 else if (peek == 'C' || peek == 'D') 1681 else if (peek == 'C' || peek == 'D')
1659 ret = d_ctor_dtor_name (di); 1682 ret = d_ctor_dtor_name (di);
1660 else if (peek == 'L') 1683 else if (peek == 'L')
@@ -4179,6 +4202,7 @@ d_count_templates_scopes (struct d_print_info *dpi,
4179 case DEMANGLE_COMPONENT_CHARACTER: 4202 case DEMANGLE_COMPONENT_CHARACTER:
4180 case DEMANGLE_COMPONENT_NUMBER: 4203 case DEMANGLE_COMPONENT_NUMBER:
4181 case DEMANGLE_COMPONENT_UNNAMED_TYPE: 4204 case DEMANGLE_COMPONENT_UNNAMED_TYPE:
4205 case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
4182 break; 4206 break;
4183 4207
4184 case DEMANGLE_COMPONENT_TEMPLATE: 4208 case DEMANGLE_COMPONENT_TEMPLATE:
@@ -4850,6 +4874,19 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4850 d_append_char (dpi, ']'); 4874 d_append_char (dpi, ']');
4851 return; 4875 return;
4852 4876
4877 case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
4878 d_append_char (dpi, '[');
4879 for (;;)
4880 {
4881 d_print_comp (dpi, options, d_left (dc));
4882 dc = d_right (dc);
4883 if (!dc)
4884 break;
4885 d_append_string (dpi, ", ");
4886 }
4887 d_append_char (dpi, ']');
4888 return;
4889
4853 case DEMANGLE_COMPONENT_QUAL_NAME: 4890 case DEMANGLE_COMPONENT_QUAL_NAME:
4854 case DEMANGLE_COMPONENT_LOCAL_NAME: 4891 case DEMANGLE_COMPONENT_LOCAL_NAME:
4855 d_print_comp (dpi, options, d_left (dc)); 4892 d_print_comp (dpi, options, d_left (dc));
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index de54ad73cc8..2b0b531d4bf 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -1493,3 +1493,13 @@ decltype ({parm#1}.A::x) f<A>(A)
1493 1493
1494_Z2f6IP1AEDtptfp_gssr1A1BE1xET_ 1494_Z2f6IP1AEDtptfp_gssr1A1BE1xET_
1495decltype ({parm#1}->(::A::B::x)) f6<A*>(A*) 1495decltype ({parm#1}->(::A::B::x)) f6<A*>(A*)
1496
1497# Structured Bindings
1498_ZDC1a1bE
1499[a, b]
1500
1501_ZNStDC1aEE
1502std::[a]
1503
1504_ZN3NMSDC1aEE
1505NMS::[a]