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.
This commit is contained in:
Nathan Sidwell 2022-03-08 13:00:35 -08:00
parent 7a3f38a966
commit 451894cadc
3 changed files with 56 additions and 7 deletions

View File

@ -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. */

View File

@ -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));

View File

@ -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]