]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
demangler: Structured Bindings
authorNathan Sidwell <nathan@acm.org>
Tue, 8 Mar 2022 21:00:35 +0000 (13:00 -0800)
committerNathan Sidwell <nathan@acm.org>
Tue, 17 May 2022 18:10:03 +0000 (11:10 -0700)
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
libiberty/cp-demangle.c
libiberty/testsuite/demangle-expected

index 402308f769f1376f8ee80a7bf9d56aa52154ff1e..44a27374d4f4c883b26fdfab528db59fbd231e2e 100644 (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.  */
index 6dff7d28fcf2e6bda72c07c6783d3f373c005bb3..fc618fa7383e2b6dcd202538ea44ef9ed79096a9 100644 (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));
index de54ad73cc8ee3d36f3b52b3bbdeeaf77d694852..2b0b531d4bf69e42595eb8fb4a76f8bd1f9564dd 100644 (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]