* demangler: Structured Bindings
@ 2022-05-17 18:12 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2022-05-17 18:12 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
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.
This adds it to the demangler.
nathan
--
Nathan Sidwell
[-- Attachment #2: 0001-demangler-Structured-Bindings.patch --]
[-- Type: text/x-patch, Size: 4527 bytes --]
From 451894cadcf1210883ceefb2d69a0ed2d6a8cd8b Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
Date: Tue, 8 Mar 2022 13:00:35 -0800
Subject: [PATCH 1/2] 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.
---
include/demangle.h | 4 ++-
libiberty/cp-demangle.c | 49 +++++++++++++++++++++++----
libiberty/testsuite/demangle-expected | 10 ++++++
3 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/include/demangle.h b/include/demangle.h
index 402308f769f..44a27374d4f 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -449,7 +449,9 @@ enum demangle_component_type
/* A cloned function. */
DEMANGLE_COMPONENT_CLONE,
DEMANGLE_COMPONENT_NOEXCEPT,
- DEMANGLE_COMPONENT_THROW_SPEC
+ DEMANGLE_COMPONENT_THROW_SPEC,
+
+ DEMANGLE_COMPONENT_STRUCTURED_BINDING
};
/* Types which are only used internally. */
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,
case DEMANGLE_COMPONENT_NULLARY:
case DEMANGLE_COMPONENT_TRINARY_ARG2:
case DEMANGLE_COMPONENT_TPARM_OBJ:
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
if (left == NULL)
return NULL;
break;
@@ -1619,12 +1620,12 @@ d_prefix (struct d_info *di, int subst)
}
}
-/* <unqualified-name> ::= <operator-name>
- ::= <ctor-dtor-name>
- ::= <source-name>
- ::= <local-source-name>
-
- <local-source-name> ::= L <source-name> <discriminator>
+/* <unqualified-name> ::= <operator-name> [<abi-tags>]
+ ::= <ctor-dtor-name> [<abi-tags>]
+ ::= <source-name> [<abi-tags>]
+ ::= <local-source-name> [<abi-tags>]
+ ::= DC <source-name>+ E [<abi-tags>]
+ <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
*/
static struct demangle_component *
@@ -1655,6 +1656,28 @@ d_unqualified_name (struct d_info *di)
d_source_name (di));
}
}
+ else if (peek == 'D' && d_peek_next_char (di) == 'C')
+ {
+ // structured binding
+ d_advance (di, 2);
+ struct demangle_component *prev = NULL;
+ do
+ {
+ struct demangle_component *next =
+ d_make_comp (di, DEMANGLE_COMPONENT_STRUCTURED_BINDING,
+ d_source_name (di), NULL);
+ if (prev)
+ d_right (prev) = next;
+ else
+ ret = next;
+ prev = next;
+ }
+ while (prev && d_peek_char (di) != 'E');
+ if (prev)
+ d_advance (di, 1);
+ else
+ ret = NULL;
+ }
else if (peek == 'C' || peek == 'D')
ret = d_ctor_dtor_name (di);
else if (peek == 'L')
@@ -4179,6 +4202,7 @@ d_count_templates_scopes (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_CHARACTER:
case DEMANGLE_COMPONENT_NUMBER:
case DEMANGLE_COMPONENT_UNNAMED_TYPE:
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
break;
case DEMANGLE_COMPONENT_TEMPLATE:
@@ -4850,6 +4874,19 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
d_append_char (dpi, ']');
return;
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
+ d_append_char (dpi, '[');
+ for (;;)
+ {
+ d_print_comp (dpi, options, d_left (dc));
+ dc = d_right (dc);
+ if (!dc)
+ break;
+ d_append_string (dpi, ", ");
+ }
+ d_append_char (dpi, ']');
+ return;
+
case DEMANGLE_COMPONENT_QUAL_NAME:
case DEMANGLE_COMPONENT_LOCAL_NAME:
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)
_Z2f6IP1AEDtptfp_gssr1A1BE1xET_
decltype ({parm#1}->(::A::B::x)) f6<A*>(A*)
+
+# Structured Bindings
+_ZDC1a1bE
+[a, b]
+
+_ZNStDC1aEE
+std::[a]
+
+_ZN3NMSDC1aEE
+NMS::[a]
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-17 18:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 18:12 demangler: Structured Bindings Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).