OSDN Git Service

PR fortran/18540
[pf3gnuchains/gcc-fork.git] / libiberty / cp-demangle.c
index e5b396c..109d533 100644 (file)
@@ -25,7 +25,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 
 */
 
 /* This code implements a demangler for the g++ V3 ABI.  The ABI is
@@ -210,7 +210,7 @@ struct d_print_template
   /* Next template on the list.  */
   struct d_print_template *next;
   /* This template.  */
-  const struct demangle_component *template;
+  const struct demangle_component *template_decl;
 };
 
 /* A list of type modifiers.  This is used while printing.  */
@@ -520,6 +520,9 @@ d_dump (struct demangle_component *dc, int indent)
     case DEMANGLE_COMPONENT_REFTEMP:
       printf ("reference temporary\n");
       break;
+    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
+      printf ("hidden alias\n");
+      break;
     case DEMANGLE_COMPONENT_RESTRICT:
       printf ("restrict\n");
       break;
@@ -733,6 +736,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
     case DEMANGLE_COMPONENT_JAVA_CLASS:
     case DEMANGLE_COMPONENT_GUARD:
     case DEMANGLE_COMPONENT_REFTEMP:
+    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
     case DEMANGLE_COMPONENT_POINTER:
     case DEMANGLE_COMPONENT_REFERENCE:
     case DEMANGLE_COMPONENT_COMPLEX:
@@ -1439,6 +1443,7 @@ d_operator_name (struct d_info *di)
                   ::= TF <type>
                   ::= TJ <type>
                   ::= GR <name>
+                 ::= GA <encoding>
 */
 
 static struct demangle_component *
@@ -1529,6 +1534,10 @@ d_special_name (struct d_info *di)
          return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, d_name (di),
                              NULL);
 
+       case 'A':
+         return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
+                             d_encoding (di, 0), NULL);
+
        default:
          return NULL;
        }
@@ -1930,7 +1939,7 @@ d_function_type (struct d_info *di)
   return ret;
 }
 
-/* <bare-function-type> ::= <type>+  */
+/* <bare-function-type> ::= [J]<type>+  */
 
 static struct demangle_component *
 d_bare_function_type (struct d_info *di, int has_return_type)
@@ -1938,13 +1947,22 @@ d_bare_function_type (struct d_info *di, int has_return_type)
   struct demangle_component *return_type;
   struct demangle_component *tl;
   struct demangle_component **ptl;
+  char peek;
+
+  /* Detect special qualifier indicating that the first argument
+     is the return type.  */
+  peek = d_peek_char (di);
+  if (peek == 'J')
+    {
+      d_advance (di, 1);
+      has_return_type = 1;
+    }
 
   return_type = NULL;
   tl = NULL;
   ptl = &tl;
   while (1)
     {
-      char peek;
       struct demangle_component *type;
 
       peek = d_peek_char (di);
@@ -2328,7 +2346,11 @@ d_expr_primary (struct d_info *di)
        }
       s = d_str (di);
       while (d_peek_char (di) != 'E')
-       d_advance (di, 1);
+       {
+         if (d_peek_char (di) == '\0')
+           return NULL;
+         d_advance (di, 1);
+       }
       ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
     }
   if (d_next_char (di) != 'E')
@@ -2551,7 +2573,7 @@ d_print_resize (struct d_print_info *dpi, size_t add)
       char *newbuf;
 
       newalc = dpi->alc * 2;
-      newbuf = realloc (dpi->buf, newalc);
+      newbuf = (char *) realloc (dpi->buf, newalc);
       if (newbuf == NULL)
        {
          free (dpi->buf);
@@ -2629,7 +2651,7 @@ cplus_demangle_print (int options, const struct demangle_component *dc,
   dpi.options = options;
 
   dpi.alc = estimate + 1;
-  dpi.buf = malloc (dpi.alc);
+  dpi.buf = (char *) malloc (dpi.alc);
   if (dpi.buf == NULL)
     {
       *palc = 1;
@@ -2730,7 +2752,7 @@ d_print_comp (struct d_print_info *dpi,
          {
            dpt.next = dpi->templates;
            dpi->templates = &dpt;
-           dpt.template = typed_name;
+           dpt.template_decl = typed_name;
          }
 
        /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
@@ -2826,7 +2848,7 @@ d_print_comp (struct d_print_info *dpi,
            return;
          }
        i = dc->u.s_number.number;
-       for (a = d_right (dpi->templates->template);
+       for (a = d_right (dpi->templates->template_decl);
             a != NULL;
             a = d_right (a))
          {
@@ -2931,6 +2953,11 @@ d_print_comp (struct d_print_info *dpi,
       d_print_comp (dpi, d_left (dc));
       return;
 
+    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
+      d_append_string_constant (dpi, "hidden alias for ");
+      d_print_comp (dpi, d_left (dc));
+      return;
+
     case DEMANGLE_COMPONENT_SUB_STD:
       d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);
       return;
@@ -3007,13 +3034,16 @@ d_print_comp (struct d_print_info *dpi,
 
     case DEMANGLE_COMPONENT_FUNCTION_TYPE:
       {
+       if ((dpi->options & DMGL_RET_POSTFIX) != 0)
+         d_print_function_type (dpi, dc, dpi->modifiers);
+
+       /* Print return type if present */
        if (d_left (dc) != NULL)
          {
            struct d_print_mod dpm;
 
            /* We must pass this type down as a modifier in order to
               print it in the right location.  */
-
            dpm.next = dpi->modifiers;
            dpi->modifiers = &dpm;
            dpm.mod = dc;
@@ -3027,10 +3057,14 @@ d_print_comp (struct d_print_info *dpi,
            if (dpm.printed)
              return;
 
-           d_append_char (dpi, ' ');
+           /* In standard prefix notation, there is a space between the
+              return type and the function signature.  */
+           if ((dpi->options & DMGL_RET_POSTFIX) == 0)
+             d_append_char (dpi, ' ');
          }
 
-       d_print_function_type (dpi, dc, dpi->modifiers);
+       if ((dpi->options & DMGL_RET_POSTFIX) == 0) 
+         d_print_function_type (dpi, dc, dpi->modifiers);
 
        return;
       }
@@ -3683,7 +3717,7 @@ d_print_cast (struct d_print_info *dpi,
 
       dpt.next = dpi->templates;
       dpi->templates = &dpt;
-      dpt.template = d_left (dc);
+      dpt.template_decl = d_left (dc);
 
       d_print_comp (dpi, d_left (d_left (dc)));
 
@@ -3764,7 +3798,7 @@ d_demangle (const char* mangled, int options, size_t *palc)
     {
       char *r;
 
-      r = malloc (40 + len - 11);
+      r = (char *) malloc (40 + len - 11);
       if (r == NULL)
        *palc = 1;
       else
@@ -3985,7 +4019,8 @@ java_demangle_v3 (const char* mangled)
   char *from;
   char *to;
 
-  demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS, &alc);
+  demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX, 
+                         &alc);
 
   if (demangled == NULL)
     return NULL;