From 451894cadcf1210883ceefb2d69a0ed2d6a8cd8b Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 8 Mar 2022 13:00:35 -0800 Subject: 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. --- libiberty/cp-demangle.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'libiberty/cp-demangle.c') diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 6dff7d2..fc618fa 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) } } -/* ::= - ::= - ::= - ::= - - ::= L +/* ::= [] + ::= [] + ::= [] + ::= [] + ::= DC + E [] + ::= L [] */ 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)); -- cgit v1.1