OSDN Git Service

* cp-demangle.c (cplus_demangle_type): decltype, pack expansion
[pf3gnuchains/gcc-fork.git] / libiberty / cp-demangle.c
index 75706b3..0ed8397 100644 (file)
@@ -1,5 +1,5 @@
 /* Demangler for g++ V3 ABI.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@wasabisystems.com>.
 
@@ -278,8 +278,6 @@ struct d_growable_string
 enum { D_PRINT_BUFFER_LENGTH = 256 };
 struct d_print_info
 {
-  /* The options passed to the demangler.  */
-  int options;
   /* Fixed-length allocated buffer for demangled data, flushed to the
      callback with a NUL termination once full.  */
   char buf[D_PRINT_BUFFER_LENGTH];
@@ -302,6 +300,8 @@ struct d_print_info
   /* The current index into any template argument packs we are using
      for printing.  */
   int pack_index;
+  /* Number of d_print_flush calls so far.  */
+  unsigned long int flush_count;
 };
 
 #ifdef CP_DEMANGLE_DEBUG
@@ -320,6 +320,9 @@ static struct demangle_component *
 d_make_name (struct d_info *, const char *, int);
 
 static struct demangle_component *
+d_make_demangle_mangled_name (struct d_info *, const char *);
+
+static struct demangle_component *
 d_make_builtin_type (struct d_info *,
                      const struct demangle_builtin_type_info *);
 
@@ -414,6 +417,9 @@ static struct demangle_component *d_lambda (struct d_info *);
 
 static struct demangle_component *d_unnamed_type (struct d_info *);
 
+static struct demangle_component *
+d_clone_suffix (struct d_info *, struct demangle_component *);
+
 static int
 d_add_substitution (struct d_info *, struct demangle_component *);
 
@@ -431,7 +437,7 @@ static void
 d_growable_string_callback_adapter (const char *, size_t, void *);
 
 static void
-d_print_init (struct d_print_info *, int, demangle_callbackref, void *);
+d_print_init (struct d_print_info *, demangle_callbackref, void *);
 
 static inline void d_print_error (struct d_print_info *);
 
@@ -449,32 +455,32 @@ static inline void d_append_string (struct d_print_info *, const char *);
 static inline char d_last_char (struct d_print_info *);
 
 static void
-d_print_comp (struct d_print_info *, const struct demangle_component *);
+d_print_comp (struct d_print_info *, int, const struct demangle_component *);
 
 static void
 d_print_java_identifier (struct d_print_info *, const char *, int);
 
 static void
-d_print_mod_list (struct d_print_info *, struct d_print_mod *, int);
+d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int);
 
 static void
-d_print_mod (struct d_print_info *, const struct demangle_component *);
+d_print_mod (struct d_print_info *, int, const struct demangle_component *);
 
 static void
-d_print_function_type (struct d_print_info *,
+d_print_function_type (struct d_print_info *, int,
                        const struct demangle_component *,
                        struct d_print_mod *);
 
 static void
-d_print_array_type (struct d_print_info *,
+d_print_array_type (struct d_print_info *, int,
                     const struct demangle_component *,
                     struct d_print_mod *);
 
 static void
-d_print_expr_op (struct d_print_info *, const struct demangle_component *);
+d_print_expr_op (struct d_print_info *, int, const struct demangle_component *);
 
 static void
-d_print_cast (struct d_print_info *, const struct demangle_component *);
+d_print_cast (struct d_print_info *, int, const struct demangle_component *);
 
 static int d_demangle_callback (const char *, int,
                                 demangle_callbackref, void *);
@@ -579,6 +585,12 @@ d_dump (struct demangle_component *dc, int indent)
     case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
       printf ("hidden alias\n");
       break;
+    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
+      printf ("transaction clone\n");
+      break;
+    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
+      printf ("non-transaction clone\n");
+      break;
     case DEMANGLE_COMPONENT_RESTRICT:
       printf ("restrict\n");
       break;
@@ -726,7 +738,7 @@ cplus_demangle_fill_ctor (struct demangle_component *p,
   if (p == NULL
       || name == NULL
       || (int) kind < gnu_v3_complete_object_ctor
-      || (int) kind > gnu_v3_complete_object_allocating_ctor)
+      || (int) kind > gnu_v3_object_ctor_group)
     return 0;
   p->type = DEMANGLE_COMPONENT_CTOR;
   p->u.s_ctor.kind = kind;
@@ -745,7 +757,7 @@ cplus_demangle_fill_dtor (struct demangle_component *p,
   if (p == NULL
       || name == NULL
       || (int) kind < gnu_v3_deleting_dtor
-      || (int) kind > gnu_v3_base_object_dtor)
+      || (int) kind > gnu_v3_object_dtor_group)
     return 0;
   p->type = DEMANGLE_COMPONENT_DTOR;
   p->u.s_dtor.kind = kind;
@@ -799,6 +811,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
     case DEMANGLE_COMPONENT_LITERAL_NEG:
     case DEMANGLE_COMPONENT_COMPOUND_NAME:
     case DEMANGLE_COMPONENT_VECTOR_TYPE:
+    case DEMANGLE_COMPONENT_CLONE:
       if (left == NULL || right == NULL)
        return NULL;
       break;
@@ -816,6 +829,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
     case DEMANGLE_COMPONENT_GUARD:
     case DEMANGLE_COMPONENT_REFTEMP:
     case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
+    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
+    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
     case DEMANGLE_COMPONENT_POINTER:
     case DEMANGLE_COMPONENT_REFERENCE:
     case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
@@ -867,6 +882,17 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
   return p;
 }
 
+/* Add a new demangle mangled name component.  */
+
+static struct demangle_component *
+d_make_demangle_mangled_name (struct d_info *di, const char *s)
+{
+  if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z')
+    return d_make_name (di, s, strlen (s));
+  d_advance (di, 2);
+  return d_encoding (di, 0);
+}
+
 /* Add a new name component.  */
 
 static struct demangle_component *
@@ -1020,7 +1046,7 @@ d_make_sub (struct d_info *di, const char *name, int len)
   return p;
 }
 
-/* <mangled-name> ::= _Z <encoding>
+/* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
 
    TOP_LEVEL is non-zero when called at the top level.  */
 
@@ -1028,6 +1054,8 @@ CP_STATIC_IF_GLIBCPP_V3
 struct demangle_component *
 cplus_demangle_mangled_name (struct d_info *di, int top_level)
 {
+  struct demangle_component *p;
+
   if (! d_check_char (di, '_')
       /* Allow missing _ if not at toplevel to work around a
         bug in G++ abi-version=2 mangling; see the comment in
@@ -1036,7 +1064,18 @@ cplus_demangle_mangled_name (struct d_info *di, int top_level)
     return NULL;
   if (! d_check_char (di, 'Z'))
     return NULL;
-  return d_encoding (di, top_level);
+  p = d_encoding (di, top_level);
+
+  /* If at top level and parsing parameters, check for a clone
+     suffix.  */
+  if (top_level && (di->options & DMGL_PARAMS) != 0)
+    while (d_peek_char (di) == '.'
+          && (IS_LOWER (d_peek_next_char (di))
+              || d_peek_next_char (di) == '_'
+              || IS_DIGIT (d_peek_next_char (di))))
+      p = d_clone_suffix (di, p);
+
+  return p;
 }
 
 /* Return whether a function should have a return type.  The argument
@@ -1266,6 +1305,7 @@ d_nested_name (struct d_info *di)
 /* <prefix> ::= <prefix> <unqualified-name>
             ::= <template-prefix> <template-args>
             ::= <template-param>
+            ::= <decltype>
             ::=
             ::= <substitution>
 
@@ -1294,10 +1334,19 @@ d_prefix (struct d_info *di)
         <template-param> here.  */
 
       comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
-      if (IS_DIGIT (peek)
+      if (peek == 'D')
+       {
+         char peek2 = d_peek_next_char (di);
+         if (peek2 == 'T' || peek2 == 't')
+           /* Decltype.  */
+           dc = cplus_demangle_type (di);
+         else
+           /* Destructor name.  */
+           dc = d_unqualified_name (di);
+       }
+      else if (IS_DIGIT (peek)
          || IS_LOWER (peek)
          || peek == 'C'
-         || peek == 'D'
          || peek == 'U'
          || peek == 'L')
        dc = d_unqualified_name (di);
@@ -1505,7 +1554,8 @@ d_identifier (struct d_info *di, int len)
 /* operator_name ::= many different two character encodings.
                  ::= cv <type>
                  ::= v <digit> <source-name>
-*/
+
+   This list is sorted for binary search.  */
 
 #define NL(s) s, (sizeof s) - 1
 
@@ -1517,6 +1567,8 @@ const struct demangle_operator_info cplus_demangle_operators[] =
   { "aa", NL ("&&"),        2 },
   { "ad", NL ("&"),         1 },
   { "an", NL ("&"),         2 },
+  { "at", NL ("alignof "),   1 },
+  { "az", NL ("alignof "),   1 },
   { "cl", NL ("()"),        2 },
   { "cm", NL (","),         2 },
   { "co", NL ("~"),         1 },
@@ -1562,8 +1614,6 @@ const struct demangle_operator_info cplus_demangle_operators[] =
   { "rs", NL (">>"),        2 },
   { "st", NL ("sizeof "),   1 },
   { "sz", NL ("sizeof "),   1 },
-  { "at", NL ("alignof "),   1 },
-  { "az", NL ("alignof "),   1 },
   { NULL, NULL, 0,          0 }
 };
 
@@ -1721,6 +1771,8 @@ d_java_resource (struct d_info *di)
                   ::= GR <name>
                  ::= GA <encoding>
                  ::= Gr <resource name>
+                 ::= GTt <encoding>
+                 ::= GTn <encoding>
 */
 
 static struct demangle_component *
@@ -1805,13 +1857,33 @@ d_special_name (struct d_info *di)
          return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL);
 
        case 'R':
-         return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, d_name (di),
-                             NULL);
+         {
+           struct demangle_component *name = d_name (di);
+           return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name,
+                               d_number_component (di));
+         }
 
        case 'A':
          return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
                              d_encoding (di, 0), NULL);
 
+       case 'T':
+         switch (d_next_char (di))
+           {
+           case 'n':
+             return d_make_comp (di, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
+                                 d_encoding (di, 0), NULL);
+           default:
+             /* ??? The proposal is that other letters (such as 'h') stand
+                for different variants of transaction cloning, such as
+                compiling directly for hardware transaction support.  But
+                they still should all be transactional clones of some sort
+                so go ahead and call them that.  */
+           case 't':
+             return d_make_comp (di, DEMANGLE_COMPONENT_TRANSACTION_CLONE,
+                                 d_encoding (di, 0), NULL);
+           }
+
        case 'r':
          return d_java_resource (di);
 
@@ -1895,6 +1967,9 @@ d_ctor_dtor_name (struct d_info *di)
          case '3':
            kind = gnu_v3_complete_object_allocating_ctor;
            break;
+         case '5':
+           kind = gnu_v3_object_ctor_group;
+           break;
          default:
            return NULL;
          }
@@ -1917,6 +1992,9 @@ d_ctor_dtor_name (struct d_info *di)
          case '2':
            kind = gnu_v3_base_object_dtor;
            break;
+         case '5':
+           kind = gnu_v3_object_dtor_group;
+           break;
          default:
            return NULL;
          }
@@ -1987,6 +2065,8 @@ cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
   /* 29 */ { NL ("half"),      NL ("half"),            D_PRINT_FLOAT },
   /* 30 */ { NL ("char16_t"),  NL ("char16_t"),        D_PRINT_DEFAULT },
   /* 31 */ { NL ("char32_t"),  NL ("char32_t"),        D_PRINT_DEFAULT },
+  /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
+            D_PRINT_DEFAULT },
 };
 
 CP_STATIC_IF_GLIBCPP_V3
@@ -2163,12 +2243,14 @@ cplus_demangle_type (struct d_info *di)
                             d_expression (di), NULL);
          if (ret && d_next_char (di) != 'E')
            ret = NULL;
+         can_subst = 1;
          break;
          
        case 'p':
          /* Pack expansion.  */
          ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
                             cplus_demangle_type (di), NULL);
+         can_subst = 1;
          break;
          
        case 'f':
@@ -2219,6 +2301,13 @@ cplus_demangle_type (struct d_info *di)
 
        case 'v':
          ret = d_vector_type (di);
+         can_subst = 1;
+         break;
+
+        case 'n':
+          /* decltype(nullptr) */
+         ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]);
+         di->expansion += ret->u.s_builtin.type->len;
          break;
 
        default:
@@ -2245,8 +2334,10 @@ static struct demangle_component **
 d_cv_qualifiers (struct d_info *di,
                  struct demangle_component **pret, int member_fn)
 {
+  struct demangle_component **pstart;
   char peek;
 
+  pstart = pret;
   peek = d_peek_char (di);
   while (peek == 'r' || peek == 'V' || peek == 'K')
     {
@@ -2283,6 +2374,28 @@ d_cv_qualifiers (struct d_info *di,
       peek = d_peek_char (di);
     }
 
+  if (!member_fn && peek == 'F')
+    {
+      while (pstart != pret)
+       {
+         switch ((*pstart)->type)
+           {
+           case DEMANGLE_COMPONENT_RESTRICT:
+             (*pstart)->type = DEMANGLE_COMPONENT_RESTRICT_THIS;
+             break;
+           case DEMANGLE_COMPONENT_VOLATILE:
+             (*pstart)->type = DEMANGLE_COMPONENT_VOLATILE_THIS;
+             break;
+           case DEMANGLE_COMPONENT_CONST:
+             (*pstart)->type = DEMANGLE_COMPONENT_CONST_THIS;
+             break;
+           default:
+             break;
+           }
+         pstart = &d_left (*pstart);
+       }
+    }
+
   return pret;
 }
 
@@ -2322,7 +2435,7 @@ d_parmlist (struct d_info *di)
       struct demangle_component *type;
 
       char peek = d_peek_char (di);
-      if (peek == '\0' || peek == 'E')
+      if (peek == '\0' || peek == 'E' || peek == '.')
        break;
       type = cplus_demangle_type (di);
       if (type == NULL)
@@ -2716,17 +2829,32 @@ d_expression (struct d_info *di)
       /* Function parameter used in a late-specified return type.  */
       int index;
       d_advance (di, 2);
-      index = d_compact_number (di);
-      if (index < 0)
-       return NULL;
-
+      if (d_peek_char (di) == 'T')
+       {
+         /* 'this' parameter.  */
+         d_advance (di, 1);
+         index = 0;
+       }
+      else
+       {
+         index = d_compact_number (di) + 1;
+         if (index == 0)
+           return NULL;
+       }
       return d_make_function_param (di, index);
     }
-  else if (IS_DIGIT (peek))
+  else if (IS_DIGIT (peek)
+          || (peek == 'o' && d_peek_next_char (di) == 'n'))
     {
       /* We can get an unqualified name as an expression in the case of
-         a dependent member access, i.e. decltype(T().i).  */
-      struct demangle_component *name = d_unqualified_name (di);
+         a dependent function call, i.e. decltype(f(t)).  */
+      struct demangle_component *name;
+
+      if (peek == 'o')
+       /* operator-function-id, i.e. operator+(t).  */
+       d_advance (di, 2);
+
+      name = d_unqualified_name (di);
       if (name == NULL)
        return NULL;
       if (d_peek_char (di) == 'I')
@@ -2784,10 +2912,18 @@ d_expression (struct d_info *di)
          {
            struct demangle_component *left;
            struct demangle_component *right;
+           const char *code = op->u.s_operator.op->code;
 
            left = d_expression (di);
-           if (!strcmp (op->u.s_operator.op->code, "cl"))
+           if (!strcmp (code, "cl"))
              right = d_exprlist (di);
+           else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
+             {
+               right = d_unqualified_name (di);
+               if (d_peek_char (di) == 'I')
+                 right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
+                                      right, d_template_args (di));
+             }
            else
              right = d_expression (di);
 
@@ -3027,6 +3163,33 @@ d_unnamed_type (struct d_info *di)
   return ret;
 }
 
+/* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
+*/
+
+static struct demangle_component *
+d_clone_suffix (struct d_info *di, struct demangle_component *encoding)
+{
+  const char *suffix = d_str (di);
+  const char *pend = suffix;
+  struct demangle_component *n;
+
+  if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_'))
+    {
+      pend += 2;
+      while (IS_LOWER (*pend) || *pend == '_')
+       ++pend;
+    }
+  while (*pend == '.' && IS_DIGIT (pend[1]))
+    {
+      pend += 2;
+      while (IS_DIGIT (*pend))
+       ++pend;
+    }
+  d_advance (di, pend - suffix);
+  n = d_make_name (di, suffix, pend - suffix);
+  return d_make_comp (di, DEMANGLE_COMPONENT_CLONE, encoding, n);
+}
+
 /* Add a new substitution.  */
 
 static int
@@ -3254,14 +3417,15 @@ d_growable_string_callback_adapter (const char *s, size_t l, void *opaque)
 /* Initialize a print information structure.  */
 
 static void
-d_print_init (struct d_print_info *dpi, int options,
-              demangle_callbackref callback, void *opaque)
+d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
+             void *opaque)
 {
-  dpi->options = options;
   dpi->len = 0;
   dpi->last_char = '\0';
   dpi->templates = NULL;
   dpi->modifiers = NULL;
+  dpi->pack_index = 0;
+  dpi->flush_count = 0;
 
   dpi->callback = callback;
   dpi->opaque = opaque;
@@ -3291,6 +3455,7 @@ d_print_flush (struct d_print_info *dpi)
   dpi->buf[dpi->len] = '\0';
   dpi->callback (dpi->buf, dpi->len, dpi->opaque);
   dpi->len = 0;
+  dpi->flush_count++;
 }
 
 /* Append characters and buffers for printing.  */
@@ -3351,9 +3516,9 @@ cplus_demangle_print_callback (int options,
 {
   struct d_print_info dpi;
 
-  d_print_init (&dpi, options, callback, opaque);
+  d_print_init (&dpi, callback, opaque);
 
-  d_print_comp (&dpi, dc);
+  d_print_comp (&dpi, options, dc);
 
   d_print_flush (&dpi);
 
@@ -3453,6 +3618,7 @@ d_find_pack (struct d_print_info *dpi,
     case DEMANGLE_COMPONENT_PACK_EXPANSION:
       return NULL;
       
+    case DEMANGLE_COMPONENT_LAMBDA:
     case DEMANGLE_COMPONENT_NAME:
     case DEMANGLE_COMPONENT_OPERATOR:
     case DEMANGLE_COMPONENT_BUILTIN_TYPE:
@@ -3495,7 +3661,7 @@ d_pack_length (const struct demangle_component *dc)
    if needed.  */
 
 static void
-d_print_subexpr (struct d_print_info *dpi,
+d_print_subexpr (struct d_print_info *dpi, int options,
                 const struct demangle_component *dc)
 {
   int simple = 0;
@@ -3504,7 +3670,7 @@ d_print_subexpr (struct d_print_info *dpi,
     simple = 1;
   if (!simple)
     d_append_char (dpi, '(');
-  d_print_comp (dpi, dc);
+  d_print_comp (dpi, options, dc);
   if (!simple)
     d_append_char (dpi, ')');
 }
@@ -3512,9 +3678,13 @@ d_print_subexpr (struct d_print_info *dpi,
 /* Subroutine to handle components.  */
 
 static void
-d_print_comp (struct d_print_info *dpi,
+d_print_comp (struct d_print_info *dpi, int options,
               const struct demangle_component *dc)
 {
+  /* Magic variable to let reference smashing skip over the next modifier
+     without needing to modify *dc.  */
+  const struct demangle_component *mod_inner = NULL;
+
   if (dc == NULL)
     {
       d_print_error (dpi);
@@ -3526,7 +3696,7 @@ d_print_comp (struct d_print_info *dpi,
   switch (dc->type)
     {
     case DEMANGLE_COMPONENT_NAME:
-      if ((dpi->options & DMGL_JAVA) == 0)
+      if ((options & DMGL_JAVA) == 0)
        d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len);
       else
        d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
@@ -3534,12 +3704,12 @@ d_print_comp (struct d_print_info *dpi,
 
     case DEMANGLE_COMPONENT_QUAL_NAME:
     case DEMANGLE_COMPONENT_LOCAL_NAME:
-      d_print_comp (dpi, d_left (dc));
-      if ((dpi->options & DMGL_JAVA) == 0)
+      d_print_comp (dpi, options, d_left (dc));
+      if ((options & DMGL_JAVA) == 0)
        d_append_string (dpi, "::");
       else
        d_append_char (dpi, '.');
-      d_print_comp (dpi, d_right (dc));
+      d_print_comp (dpi, options, d_right (dc));
       return;
 
     case DEMANGLE_COMPONENT_TYPED_NAME:
@@ -3629,7 +3799,7 @@ d_print_comp (struct d_print_info *dpi,
              }
          }
 
-       d_print_comp (dpi, d_right (dc));
+       d_print_comp (dpi, options, d_right (dc));
 
        if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
          dpi->templates = dpt.next;
@@ -3642,7 +3812,7 @@ d_print_comp (struct d_print_info *dpi,
            if (! adpm[i].printed)
              {
                d_append_char (dpi, ' ');
-               d_print_mod (dpi, adpm[i].mod);
+               d_print_mod (dpi, options, adpm[i].mod);
              }
          }
 
@@ -3665,7 +3835,7 @@ d_print_comp (struct d_print_info *dpi,
 
         dcl = d_left (dc);
 
-        if ((dpi->options & DMGL_JAVA) != 0
+        if ((options & DMGL_JAVA) != 0
             && dcl->type == DEMANGLE_COMPONENT_NAME
             && dcl->u.s_name.len == 6
             && strncmp (dcl->u.s_name.s, "JArray", 6) == 0)
@@ -3673,16 +3843,16 @@ d_print_comp (struct d_print_info *dpi,
             /* Special-case Java arrays, so that JArray<TYPE> appears
                instead as TYPE[].  */
 
-            d_print_comp (dpi, d_right (dc));
+            d_print_comp (dpi, options, d_right (dc));
             d_append_string (dpi, "[]");
           }
         else
           {
-           d_print_comp (dpi, dcl);
+           d_print_comp (dpi, options, dcl);
            if (d_last_char (dpi) == '<')
              d_append_char (dpi, ' ');
            d_append_char (dpi, '<');
-           d_print_comp (dpi, d_right (dc));
+           d_print_comp (dpi, options, d_right (dc));
            /* Avoid generating two consecutive '>' characters, to avoid
               the C++ syntactic ambiguity.  */
            if (d_last_char (dpi) == '>')
@@ -3717,7 +3887,7 @@ d_print_comp (struct d_print_info *dpi,
        hold_dpt = dpi->templates;
        dpi->templates = hold_dpt->next;
 
-       d_print_comp (dpi, a);
+       d_print_comp (dpi, options, a);
 
        dpi->templates = hold_dpt;
 
@@ -3725,79 +3895,91 @@ d_print_comp (struct d_print_info *dpi,
       }
 
     case DEMANGLE_COMPONENT_CTOR:
-      d_print_comp (dpi, dc->u.s_ctor.name);
+      d_print_comp (dpi, options, dc->u.s_ctor.name);
       return;
 
     case DEMANGLE_COMPONENT_DTOR:
       d_append_char (dpi, '~');
-      d_print_comp (dpi, dc->u.s_dtor.name);
+      d_print_comp (dpi, options, dc->u.s_dtor.name);
       return;
 
     case DEMANGLE_COMPONENT_VTABLE:
       d_append_string (dpi, "vtable for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_VTT:
       d_append_string (dpi, "VTT for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
       d_append_string (dpi, "construction vtable for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       d_append_string (dpi, "-in-");
-      d_print_comp (dpi, d_right (dc));
+      d_print_comp (dpi, options, d_right (dc));
       return;
 
     case DEMANGLE_COMPONENT_TYPEINFO:
       d_append_string (dpi, "typeinfo for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_TYPEINFO_NAME:
       d_append_string (dpi, "typeinfo name for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_TYPEINFO_FN:
       d_append_string (dpi, "typeinfo fn for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_THUNK:
       d_append_string (dpi, "non-virtual thunk to ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
       d_append_string (dpi, "virtual thunk to ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_COVARIANT_THUNK:
       d_append_string (dpi, "covariant return thunk to ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_JAVA_CLASS:
       d_append_string (dpi, "java Class for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_GUARD:
       d_append_string (dpi, "guard variable for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_REFTEMP:
-      d_append_string (dpi, "reference temporary for ");
-      d_print_comp (dpi, d_left (dc));
+      d_append_string (dpi, "reference temporary #");
+      d_print_comp (dpi, options, d_right (dc));
+      d_append_string (dpi, " for ");
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
       d_append_string (dpi, "hidden alias for ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
+      d_append_string (dpi, "transaction clone for ");
+      d_print_comp (dpi, options, d_left (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
+      d_append_string (dpi, "non-transaction clone for ");
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_SUB_STD:
@@ -3824,22 +4006,50 @@ d_print_comp (struct d_print_info *dpi,
                  break;
                if (pdpm->mod->type == dc->type)
                  {
-                   d_print_comp (dpi, d_left (dc));
+                   d_print_comp (dpi, options, d_left (dc));
                    return;
                  }
              }
          }
       }
+      goto modifier;
+
+    case DEMANGLE_COMPONENT_REFERENCE:
+    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
+      {
+       /* Handle reference smashing: & + && = &.  */
+       const struct demangle_component *sub = d_left (dc);
+       if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
+         {
+           struct demangle_component *a = d_lookup_template_argument (dpi, sub);
+           if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
+             a = d_index_template_argument (a, dpi->pack_index);
+
+           if (a == NULL)
+             {
+               d_print_error (dpi);
+               return;
+             }
+
+           sub = a;
+         }
+
+       if (sub->type == DEMANGLE_COMPONENT_REFERENCE
+           || sub->type == dc->type)
+         dc = sub;
+       else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE)
+         mod_inner = d_left (sub);
+      }
       /* Fall through.  */
+
     case DEMANGLE_COMPONENT_RESTRICT_THIS:
     case DEMANGLE_COMPONENT_VOLATILE_THIS:
     case DEMANGLE_COMPONENT_CONST_THIS:
     case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
     case DEMANGLE_COMPONENT_POINTER:
-    case DEMANGLE_COMPONENT_REFERENCE:
-    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
     case DEMANGLE_COMPONENT_COMPLEX:
     case DEMANGLE_COMPONENT_IMAGINARY:
+    modifier:
       {
        /* We keep a list of modifiers on the stack.  */
        struct d_print_mod dpm;
@@ -3850,12 +4060,15 @@ d_print_comp (struct d_print_info *dpi,
        dpm.printed = 0;
        dpm.templates = dpi->templates;
 
-       d_print_comp (dpi, d_left (dc));
+       if (!mod_inner)
+         mod_inner = d_left (dc);
+
+       d_print_comp (dpi, options, mod_inner);
 
        /* If the modifier didn't get printed by the type, print it
           now.  */
        if (! dpm.printed)
-         d_print_mod (dpi, dc);
+         d_print_mod (dpi, options, dc);
 
        dpi->modifiers = dpm.next;
 
@@ -3863,7 +4076,7 @@ d_print_comp (struct d_print_info *dpi,
       }
 
     case DEMANGLE_COMPONENT_BUILTIN_TYPE:
-      if ((dpi->options & DMGL_JAVA) == 0)
+      if ((options & DMGL_JAVA) == 0)
        d_append_buffer (dpi, dc->u.s_builtin.type->name,
                         dc->u.s_builtin.type->len);
       else
@@ -3872,16 +4085,21 @@ d_print_comp (struct d_print_info *dpi,
       return;
 
     case DEMANGLE_COMPONENT_VENDOR_TYPE:
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_FUNCTION_TYPE:
       {
-       if ((dpi->options & DMGL_RET_POSTFIX) != 0)
-         d_print_function_type (dpi, dc, dpi->modifiers);
+       if ((options & DMGL_RET_POSTFIX) != 0)
+         d_print_function_type (dpi,
+                                options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
+                                dc, dpi->modifiers);
 
        /* Print return type if present */
-       if (d_left (dc) != NULL)
+       if (d_left (dc) != NULL && (options & DMGL_RET_POSTFIX) != 0)
+         d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
+                       d_left (dc));
+       else if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0)
          {
            struct d_print_mod dpm;
 
@@ -3893,7 +4111,8 @@ d_print_comp (struct d_print_info *dpi,
            dpm.printed = 0;
            dpm.templates = dpi->templates;
 
-           d_print_comp (dpi, d_left (dc));
+           d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
+                         d_left (dc));
 
            dpi->modifiers = dpm.next;
 
@@ -3902,12 +4121,14 @@ d_print_comp (struct d_print_info *dpi,
 
            /* In standard prefix notation, there is a space between the
               return type and the function signature.  */
-           if ((dpi->options & DMGL_RET_POSTFIX) == 0)
+           if ((options & DMGL_RET_POSTFIX) == 0)
              d_append_char (dpi, ' ');
          }
 
-       if ((dpi->options & DMGL_RET_POSTFIX) == 0) 
-         d_print_function_type (dpi, dc, dpi->modifiers);
+       if ((options & DMGL_RET_POSTFIX) == 0)
+         d_print_function_type (dpi,
+                                options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
+                                dc, dpi->modifiers);
 
        return;
       }
@@ -3960,7 +4181,7 @@ d_print_comp (struct d_print_info *dpi,
            pdpm = pdpm->next;
          }
 
-       d_print_comp (dpi, d_right (dc));
+       d_print_comp (dpi, options, d_right (dc));
 
        dpi->modifiers = hold_modifiers;
 
@@ -3970,10 +4191,10 @@ d_print_comp (struct d_print_info *dpi,
        while (i > 1)
          {
            --i;
-           d_print_mod (dpi, adpm[i].mod);
+           d_print_mod (dpi, options, adpm[i].mod);
          }
 
-       d_print_array_type (dpi, dc, dpi->modifiers);
+       d_print_array_type (dpi, options, dc, dpi->modifiers);
 
        return;
       }
@@ -3989,12 +4210,12 @@ d_print_comp (struct d_print_info *dpi,
        dpm.printed = 0;
        dpm.templates = dpi->templates;
 
-       d_print_comp (dpi, d_right (dc));
+       d_print_comp (dpi, options, d_right (dc));
 
        /* If the modifier didn't get printed by the type, print it
           now.  */
        if (! dpm.printed)
-         d_print_mod (dpi, dc);
+         d_print_mod (dpi, options, dc);
 
        dpi->modifiers = dpm.next;
 
@@ -4008,7 +4229,7 @@ d_print_comp (struct d_print_info *dpi,
       if (dc->u.s_fixed.length->u.s_builtin.type
          != &cplus_demangle_builtin_types['i'-'a'])
        {
-         d_print_comp (dpi, dc->u.s_fixed.length);
+         d_print_comp (dpi, options, dc->u.s_fixed.length);
          d_append_char (dpi, ' ');
        }
       if (dc->u.s_fixed.accum)
@@ -4020,16 +4241,22 @@ d_print_comp (struct d_print_info *dpi,
     case DEMANGLE_COMPONENT_ARGLIST:
     case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
       if (d_left (dc) != NULL)
-       d_print_comp (dpi, d_left (dc));
+       d_print_comp (dpi, options, d_left (dc));
       if (d_right (dc) != NULL)
        {
          size_t len;
+         unsigned long int flush_count;
+         /* Make sure ", " isn't flushed by d_append_string, otherwise
+            dpi->len -= 2 wouldn't work.  */
+         if (dpi->len >= sizeof (dpi->buf) - 2)
+           d_print_flush (dpi);
          d_append_string (dpi, ", ");
          len = dpi->len;
-         d_print_comp (dpi, d_right (dc));
+         flush_count = dpi->flush_count;
+         d_print_comp (dpi, options, d_right (dc));
          /* If that didn't print anything (which can happen with empty
             template argument packs), remove the comma and space.  */
-         if (dpi->len == len)
+         if (dpi->flush_count == flush_count && dpi->len == len)
            dpi->len -= 2;
        }
       return;
@@ -4049,24 +4276,63 @@ d_print_comp (struct d_print_info *dpi,
 
     case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
       d_append_string (dpi, "operator ");
-      d_print_comp (dpi, dc->u.s_extended_operator.name);
+      d_print_comp (dpi, options, dc->u.s_extended_operator.name);
       return;
 
     case DEMANGLE_COMPONENT_CAST:
       d_append_string (dpi, "operator ");
-      d_print_cast (dpi, dc);
+      d_print_cast (dpi, options, dc);
       return;
 
     case DEMANGLE_COMPONENT_UNARY:
-      if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST)
-       d_print_expr_op (dpi, d_left (dc));
+      if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
+         && d_left (dc)->u.s_operator.op->len == 1
+         && d_left (dc)->u.s_operator.op->name[0] == '&'
+         && d_right (dc)->type == DEMANGLE_COMPONENT_TYPED_NAME
+         && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_QUAL_NAME
+         && d_right (d_right (dc))->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
+       {
+         /* Address of a function (therefore in an expression context) must
+            have its argument list suppressed.
+
+            unary operator ... dc
+              operator & ... d_left (dc)
+              typed name ... d_right (dc)
+                qualified name ... d_left (d_right (dc))
+                  <names>
+                function type ... d_right (d_right (dc))
+                  argument list
+                    <arguments>  */
+
+         d_print_expr_op (dpi, options, d_left (dc));
+         d_print_comp (dpi, options, d_left (d_right (dc)));
+         return;
+       }
+      else if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
+              && d_left (dc)->u.s_operator.op->len == 1
+              && d_left (dc)->u.s_operator.op->name[0] == '&'
+              && d_right (dc)->type == DEMANGLE_COMPONENT_QUAL_NAME)
+       {
+         /* Keep also already processed variant without the argument list.
+
+            unary operator ... dc
+              operator & ... d_left (dc)
+              qualified name ... d_right (dc)
+                <names>  */
+
+         d_print_expr_op (dpi, options, d_left (dc));
+         d_print_comp (dpi, options, d_right (dc));
+         return;
+       }
+      else if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST)
+       d_print_expr_op (dpi, options, d_left (dc));
       else
        {
          d_append_char (dpi, '(');
-         d_print_cast (dpi, d_left (dc));
+         d_print_cast (dpi, options, d_left (dc));
          d_append_char (dpi, ')');
        }
-      d_print_subexpr (dpi, d_right (dc));
+      d_print_subexpr (dpi, options, d_right (dc));
       return;
 
     case DEMANGLE_COMPONENT_BINARY:
@@ -4084,18 +4350,32 @@ d_print_comp (struct d_print_info *dpi,
          && d_left (dc)->u.s_operator.op->name[0] == '>')
        d_append_char (dpi, '(');
 
-      d_print_subexpr (dpi, d_left (d_right (dc)));
+      if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") == 0
+          && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_TYPED_NAME)
+       {
+         /* Function call used in an expression should not have printed types
+            of the function arguments.  Values of the function arguments still
+            get printed below.  */
+
+         const struct demangle_component *func = d_left (d_right (dc));
+
+         if (d_right (func)->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
+           d_print_error (dpi);
+         d_print_subexpr (dpi, options, d_left (func));
+       }
+      else
+       d_print_subexpr (dpi, options, d_left (d_right (dc)));
       if (strcmp (d_left (dc)->u.s_operator.op->code, "ix") == 0)
        {
          d_append_char (dpi, '[');
-         d_print_comp (dpi, d_right (d_right (dc)));
+         d_print_comp (dpi, options, d_right (d_right (dc)));
          d_append_char (dpi, ']');
        }
       else
        {
          if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0)
-           d_print_expr_op (dpi, d_left (dc));
-         d_print_subexpr (dpi, d_right (d_right (dc)));
+           d_print_expr_op (dpi, options, d_left (dc));
+         d_print_subexpr (dpi, options, d_right (d_right (dc)));
        }
 
       if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
@@ -4117,11 +4397,11 @@ d_print_comp (struct d_print_info *dpi,
          d_print_error (dpi);
          return;
        }
-      d_print_subexpr (dpi, d_left (d_right (dc)));
-      d_print_expr_op (dpi, d_left (dc));
-      d_print_subexpr (dpi, d_left (d_right (d_right (dc))));
+      d_print_subexpr (dpi, options, d_left (d_right (dc)));
+      d_print_expr_op (dpi, options, d_left (dc));
+      d_print_subexpr (dpi, options, d_left (d_right (d_right (dc))));
       d_append_string (dpi, " : ");
-      d_print_subexpr (dpi, d_right (d_right (d_right (dc))));
+      d_print_subexpr (dpi, options, d_right (d_right (d_right (dc))));
       return;
 
     case DEMANGLE_COMPONENT_TRINARY_ARG1:
@@ -4152,7 +4432,7 @@ d_print_comp (struct d_print_info *dpi,
                  {
                    if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
                      d_append_char (dpi, '-');
-                   d_print_comp (dpi, d_right (dc));
+                   d_print_comp (dpi, options, d_right (dc));
                    switch (tp)
                      {
                      default:
@@ -4202,13 +4482,13 @@ d_print_comp (struct d_print_info *dpi,
          }
 
        d_append_char (dpi, '(');
-       d_print_comp (dpi, d_left (dc));
+       d_print_comp (dpi, options, d_left (dc));
        d_append_char (dpi, ')');
        if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
          d_append_char (dpi, '-');
        if (tp == D_PRINT_FLOAT)
          d_append_char (dpi, '[');
-       d_print_comp (dpi, d_right (dc));
+       d_print_comp (dpi, options, d_right (dc));
        if (tp == D_PRINT_FLOAT)
          d_append_char (dpi, ']');
       }
@@ -4220,12 +4500,12 @@ d_print_comp (struct d_print_info *dpi,
 
     case DEMANGLE_COMPONENT_JAVA_RESOURCE:
       d_append_string (dpi, "java resource ");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       return;
 
     case DEMANGLE_COMPONENT_COMPOUND_NAME:
-      d_print_comp (dpi, d_left (dc));
-      d_print_comp (dpi, d_right (dc));
+      d_print_comp (dpi, options, d_left (dc));
+      d_print_comp (dpi, options, d_right (dc));
       return;
 
     case DEMANGLE_COMPONENT_CHARACTER:
@@ -4234,7 +4514,7 @@ d_print_comp (struct d_print_info *dpi,
 
     case DEMANGLE_COMPONENT_DECLTYPE:
       d_append_string (dpi, "decltype (");
-      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, options, d_left (dc));
       d_append_char (dpi, ')');
       return;
 
@@ -4248,7 +4528,7 @@ d_print_comp (struct d_print_info *dpi,
            /* d_find_pack won't find anything if the only packs involved
               in this expansion are function parameter packs; in that
               case, just print the pattern and "...".  */
-           d_print_subexpr (dpi, d_left (dc));
+           d_print_subexpr (dpi, options, d_left (dc));
            d_append_string (dpi, "...");
            return;
          }
@@ -4258,7 +4538,7 @@ d_print_comp (struct d_print_info *dpi,
        for (i = 0; i < len; ++i)
          {
            dpi->pack_index = i;
-           d_print_comp (dpi, dc);
+           d_print_comp (dpi, options, dc);
            if (i < len-1)
              d_append_string (dpi, ", ");
          }
@@ -4266,24 +4546,32 @@ d_print_comp (struct d_print_info *dpi,
       return;
 
     case DEMANGLE_COMPONENT_FUNCTION_PARAM:
-      d_append_string (dpi, "{parm#");
-      d_append_num (dpi, dc->u.s_number.number + 1);
-      d_append_char (dpi, '}');
+      {
+       long num = dc->u.s_number.number;
+       if (num == 0)
+         d_append_string (dpi, "this");
+       else
+         {
+           d_append_string (dpi, "{parm#");
+           d_append_num (dpi, num);
+           d_append_char (dpi, '}');
+         }
+      }
       return;
 
     case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
       d_append_string (dpi, "global constructors keyed to ");
-      d_print_comp (dpi, dc->u.s_binary.left);
+      d_print_comp (dpi, options, dc->u.s_binary.left);
       return;
 
     case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
       d_append_string (dpi, "global destructors keyed to ");
-      d_print_comp (dpi, dc->u.s_binary.left);
+      d_print_comp (dpi, options, dc->u.s_binary.left);
       return;
 
     case DEMANGLE_COMPONENT_LAMBDA:
       d_append_string (dpi, "{lambda(");
-      d_print_comp (dpi, dc->u.s_unary_num.sub);
+      d_print_comp (dpi, options, dc->u.s_unary_num.sub);
       d_append_string (dpi, ")#");
       d_append_num (dpi, dc->u.s_unary_num.num + 1);
       d_append_char (dpi, '}');
@@ -4295,6 +4583,13 @@ d_print_comp (struct d_print_info *dpi,
       d_append_char (dpi, '}');
       return;
 
+    case DEMANGLE_COMPONENT_CLONE:
+      d_print_comp (dpi, options, d_left (dc));
+      d_append_string (dpi, " [clone ");
+      d_print_comp (dpi, options, d_right (dc));
+      d_append_char (dpi, ']');
+      return;
+
     default:
       d_print_error (dpi);
       return;
@@ -4357,7 +4652,7 @@ d_print_java_identifier (struct d_print_info *dpi, const char *name, int len)
    qualifiers on this after printing a function.  */
 
 static void
-d_print_mod_list (struct d_print_info *dpi,
+d_print_mod_list (struct d_print_info *dpi, int options,
                   struct d_print_mod *mods, int suffix)
 {
   struct d_print_template *hold_dpt;
@@ -4371,7 +4666,7 @@ d_print_mod_list (struct d_print_info *dpi,
              || mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS
              || mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS)))
     {
-      d_print_mod_list (dpi, mods->next, suffix);
+      d_print_mod_list (dpi, options, mods->next, suffix);
       return;
     }
 
@@ -4382,13 +4677,13 @@ d_print_mod_list (struct d_print_info *dpi,
 
   if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
     {
-      d_print_function_type (dpi, mods->mod, mods->next);
+      d_print_function_type (dpi, options, mods->mod, mods->next);
       dpi->templates = hold_dpt;
       return;
     }
   else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
     {
-      d_print_array_type (dpi, mods->mod, mods->next);
+      d_print_array_type (dpi, options, mods->mod, mods->next);
       dpi->templates = hold_dpt;
       return;
     }
@@ -4404,10 +4699,10 @@ d_print_mod_list (struct d_print_info *dpi,
 
       hold_modifiers = dpi->modifiers;
       dpi->modifiers = NULL;
-      d_print_comp (dpi, d_left (mods->mod));
+      d_print_comp (dpi, options, d_left (mods->mod));
       dpi->modifiers = hold_modifiers;
 
-      if ((dpi->options & DMGL_JAVA) == 0)
+      if ((options & DMGL_JAVA) == 0)
        d_append_string (dpi, "::");
       else
        d_append_char (dpi, '.');
@@ -4427,23 +4722,23 @@ d_print_mod_list (struct d_print_info *dpi,
             || dc->type == DEMANGLE_COMPONENT_CONST_THIS)
        dc = d_left (dc);
 
-      d_print_comp (dpi, dc);
+      d_print_comp (dpi, options, dc);
 
       dpi->templates = hold_dpt;
       return;
     }
 
-  d_print_mod (dpi, mods->mod);
+  d_print_mod (dpi, options, mods->mod);
 
   dpi->templates = hold_dpt;
 
-  d_print_mod_list (dpi, mods->next, suffix);
+  d_print_mod_list (dpi, options, mods->next, suffix);
 }
 
 /* Print a modifier.  */
 
 static void
-d_print_mod (struct d_print_info *dpi,
+d_print_mod (struct d_print_info *dpi, int options,
              const struct demangle_component *mod)
 {
   switch (mod->type)
@@ -4462,11 +4757,11 @@ d_print_mod (struct d_print_info *dpi,
       return;
     case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
       d_append_char (dpi, ' ');
-      d_print_comp (dpi, d_right (mod));
+      d_print_comp (dpi, options, d_right (mod));
       return;
     case DEMANGLE_COMPONENT_POINTER:
       /* There is no pointer symbol in Java.  */
-      if ((dpi->options & DMGL_JAVA) == 0)
+      if ((options & DMGL_JAVA) == 0)
        d_append_char (dpi, '*');
       return;
     case DEMANGLE_COMPONENT_REFERENCE:
@@ -4484,22 +4779,22 @@ d_print_mod (struct d_print_info *dpi,
     case DEMANGLE_COMPONENT_PTRMEM_TYPE:
       if (d_last_char (dpi) != '(')
        d_append_char (dpi, ' ');
-      d_print_comp (dpi, d_left (mod));
+      d_print_comp (dpi, options, d_left (mod));
       d_append_string (dpi, "::*");
       return;
     case DEMANGLE_COMPONENT_TYPED_NAME:
-      d_print_comp (dpi, d_left (mod));
+      d_print_comp (dpi, options, d_left (mod));
       return;
     case DEMANGLE_COMPONENT_VECTOR_TYPE:
-      d_append_string (dpi, " vector[");
-      d_print_comp (dpi, d_left (mod));
-      d_append_char (dpi, ']');
+      d_append_string (dpi, " __vector(");
+      d_print_comp (dpi, options, d_left (mod));
+      d_append_char (dpi, ')');
       return;
 
     default:
       /* Otherwise, we have something that won't go back on the
         modifier stack, so we can just print it.  */
-      d_print_comp (dpi, mod);
+      d_print_comp (dpi, options, mod);
       return;
     }
 }
@@ -4507,25 +4802,22 @@ d_print_mod (struct d_print_info *dpi,
 /* Print a function type, except for the return type.  */
 
 static void
-d_print_function_type (struct d_print_info *dpi,
+d_print_function_type (struct d_print_info *dpi, int options,
                        const struct demangle_component *dc,
                        struct d_print_mod *mods)
 {
   int need_paren;
-  int saw_mod;
   int need_space;
   struct d_print_mod *p;
   struct d_print_mod *hold_modifiers;
 
   need_paren = 0;
-  saw_mod = 0;
   need_space = 0;
   for (p = mods; p != NULL; p = p->next)
     {
       if (p->printed)
        break;
 
-      saw_mod = 1;
       switch (p->mod->type)
        {
        case DEMANGLE_COMPONENT_POINTER:
@@ -4554,9 +4846,6 @@ d_print_function_type (struct d_print_info *dpi,
        break;
     }
 
-  if (d_left (dc) != NULL && ! saw_mod)
-    need_paren = 1;
-
   if (need_paren)
     {
       if (! need_space)
@@ -4573,7 +4862,7 @@ d_print_function_type (struct d_print_info *dpi,
   hold_modifiers = dpi->modifiers;
   dpi->modifiers = NULL;
 
-  d_print_mod_list (dpi, mods, 0);
+  d_print_mod_list (dpi, options, mods, 0);
 
   if (need_paren)
     d_append_char (dpi, ')');
@@ -4581,11 +4870,11 @@ d_print_function_type (struct d_print_info *dpi,
   d_append_char (dpi, '(');
 
   if (d_right (dc) != NULL)
-    d_print_comp (dpi, d_right (dc));
+    d_print_comp (dpi, options, d_right (dc));
 
   d_append_char (dpi, ')');
 
-  d_print_mod_list (dpi, mods, 1);
+  d_print_mod_list (dpi, options, mods, 1);
 
   dpi->modifiers = hold_modifiers;
 }
@@ -4593,7 +4882,7 @@ d_print_function_type (struct d_print_info *dpi,
 /* Print an array type, except for the element type.  */
 
 static void
-d_print_array_type (struct d_print_info *dpi,
+d_print_array_type (struct d_print_info *dpi, int options,
                     const struct demangle_component *dc,
                     struct d_print_mod *mods)
 {
@@ -4627,7 +4916,7 @@ d_print_array_type (struct d_print_info *dpi,
       if (need_paren)
        d_append_string (dpi, " (");
 
-      d_print_mod_list (dpi, mods, 0);
+      d_print_mod_list (dpi, options, mods, 0);
 
       if (need_paren)
        d_append_char (dpi, ')');
@@ -4639,7 +4928,7 @@ d_print_array_type (struct d_print_info *dpi,
   d_append_char (dpi, '[');
 
   if (d_left (dc) != NULL)
-    d_print_comp (dpi, d_left (dc));
+    d_print_comp (dpi, options, d_left (dc));
 
   d_append_char (dpi, ']');
 }
@@ -4647,24 +4936,24 @@ d_print_array_type (struct d_print_info *dpi,
 /* Print an operator in an expression.  */
 
 static void
-d_print_expr_op (struct d_print_info *dpi,
+d_print_expr_op (struct d_print_info *dpi, int options,
                  const struct demangle_component *dc)
 {
   if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
     d_append_buffer (dpi, dc->u.s_operator.op->name,
                     dc->u.s_operator.op->len);
   else
-    d_print_comp (dpi, dc);
+    d_print_comp (dpi, options, dc);
 }
 
 /* Print a cast.  */
 
 static void
-d_print_cast (struct d_print_info *dpi,
+d_print_cast (struct d_print_info *dpi, int options,
               const struct demangle_component *dc)
 {
   if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
-    d_print_comp (dpi, d_left (dc));
+    d_print_comp (dpi, options, d_left (dc));
   else
     {
       struct d_print_mod *hold_dpm;
@@ -4682,14 +4971,14 @@ d_print_cast (struct d_print_info *dpi,
       dpi->templates = &dpt;
       dpt.template_decl = d_left (dc);
 
-      d_print_comp (dpi, d_left (d_left (dc)));
+      d_print_comp (dpi, options, d_left (d_left (dc)));
 
       dpi->templates = dpt.next;
 
       if (d_last_char (dpi) == '<')
        d_append_char (dpi, ' ');
       d_append_char (dpi, '<');
-      d_print_comp (dpi, d_right (d_left (dc)));
+      d_print_comp (dpi, options, d_right (d_left (dc)));
       /* Avoid generating two consecutive '>' characters, to avoid
         the C++ syntactic ambiguity.  */
       if (d_last_char (dpi) == '>')
@@ -4795,7 +5084,7 @@ d_demangle_callback (const char *mangled, int options,
                          (type == DCT_GLOBAL_CTORS
                           ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
                           : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
-                         d_make_name (&di, d_str (&di), strlen (d_str (&di))),
+                         d_make_demangle_mangled_name (&di, d_str (&di)),
                          NULL);
        d_advance (&di, strlen (d_str (&di)));
        break;