]> Git Repo - binutils.git/blobdiff - gdb/cplus-dem.c
Globs of changes. See the ChangeLog for details. Most related to
[binutils.git] / gdb / cplus-dem.c
index e7f9d86686bd3576c74f282d009041f76e9f4559..afe9ee7b291a309f133f7f0fb8424bd33b20fda4 100644 (file)
@@ -1,32 +1,27 @@
 /* Demangler for GNU C++ 
-   Copyright (C) 1989 Free Software Foundation, Inc.
+   Copyright 1989, 1991 Free Software Foundation, Inc.
    written by James Clark ([email protected])
    
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-/* This is for g++ 1.36.1 (November 6 version). It will probably
-   require changes for any other version.
-
-   Modified for g++ 1.36.2 (November 18 version).
-
-   Modified for g++ 1.90.06 (December 31 version).  */
+/* This is for g++ 1.95.03 (November 13 verison).  */
 
 /* This file exports one function
 
    char *cplus_demangle (const char *name, int mode)
-   
+
    If NAME is a mangled function name produced by GNU C++, then
    a pointer to a malloced string giving a C++ representation
    of the name will be returned; otherwise NULL will be returned.
@@ -54,22 +49,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* define this if names don't start with _ */
 /* #define nounderscore 1 */
 
-#include <stdio.h>
-#include <ctype.h>
-
 /* GDB-specific, FIXME.  */
 #include "defs.h"
-#include "param.h"
+
+#include <ctype.h>
 
 #ifdef USG
 #include <memory.h>
 #include <string.h>
 #else
 #include <strings.h>
-#define memcpy(s1, s2, n) bcopy ((s2), (s1), (n))
-#define memcmp(s1, s2, n) bcmp ((s2), (s1), (n))
-#define strchr index 
-#define strrchr rindex
 #endif
 
 /* This is '$' on systems where the assembler can deal with that.
@@ -89,18 +78,6 @@ extern char *cplus_demangle (const char *type, int mode);
 extern char *cplus_demangle ();
 #endif
 
-#ifdef __STDC__
-/* GDB prototypes these as void* in defs.h, so we better too, at least
-   as long as we're including defs.h.  */
-extern void *xmalloc (int);
-extern void *xrealloc (char *, int);
-extern void free (void *);
-#else
-extern char *xmalloc ();
-extern char *xrealloc ();
-extern void free ();
-#endif
-
 static char **typevec = 0;
 static int ntypes = 0;
 static int typevec_size = 0;
@@ -108,44 +85,81 @@ static int typevec_size = 0;
 const static struct optable {
   const char *in;
   const char *out;
+  int ansi;
 } optable[] = {
-  "nw", " new",                        /* new (1.92) */
-  "dl", " delete",             /* new (1.92) */
-  "new", " new",               /* old (1.91, and 1.x) */
-  "delete", " delete",         /* old (1.91, and 1.x) */
-  "ne", "!=",
-  "eq", "==",
-  "ge", ">=",
-  "gt", ">",
-  "le", "<=",
-  "lt", "<",
-  "plus", "+",
-  "minus", "-",
-  "mult", "*",
-  "convert", "+",      /* unary + */
-  "negate", "-",       /* unary - */
-  "trunc_mod", "%",
-  "trunc_div", "/",
-  "truth_andif", "&&",
-  "truth_orif", "||",
-  "truth_not", "!",
-  "postincrement", "++",
-  "postdecrement", "--",
-  "bit_ior", "|",
-  "bit_xor", "^",
-  "bit_and", "&",
-  "bit_not", "~",
-  "call", "()",
-  "cond", "?:",
-  "alshift", "<<",
-  "arshift", ">>",
-  "component", "->",
-  "indirect", "*",
-  "method_call", "->()",
-  "addr", "&",         /* unary & */
-  "array", "[]",
-  "compound", ",",
-  "nop", "",                   /* for operator= */
+  "nw", " new",        1,              /* new (1.92, ansi) */
+  "dl", " delete", 1,          /* new (1.92, ansi) */
+  "new", " new", 0,            /* old (1.91, and 1.x) */
+  "delete", " delete", 0,      /* old (1.91, and 1.x) */
+  "as", "=", 1,                        /* ansi */
+  "ne", "!=", 1,               /* old, ansi */
+  "eq", "==", 1,               /* old, ansi */
+  "ge", ">=", 1,               /* old, ansi */
+  "gt", ">", 1,                        /* old, ansi */
+  "le", "<=", 1,               /* old, ansi */
+  "lt", "<", 1,                        /* old, ansi */
+  "plus", "+", 0,              /* old */
+  "pl", "+", 1,                        /* ansi */
+  "apl", "+=", 1,              /* ansi */
+  "minus", "-", 0,             /* old */
+  "mi", "-", 1,                        /* ansi */
+  "ami", "-=", 1,              /* ansi */
+  "mult", "*", 0,              /* old */
+  "ml", "*", 1,                        /* ansi */
+  "aml", "*=", 1,              /* ansi */
+  "convert", "+", 0,           /* old (unary +) */
+  "negate", "-", 0,            /* old (unary -) */
+  "trunc_mod", "%", 0,         /* old */
+  "md", "%", 1,                        /* ansi */
+  "amd", "%=", 1,              /* ansi */
+  "trunc_div", "/", 0,         /* old */
+  "dv", "/", 1,                        /* ansi */
+  "adv", "/=", 1,              /* ansi */
+  "truth_andif", "&&", 0,      /* old */
+  "aa", "&&", 1,               /* ansi */
+  "truth_orif", "||", 0,       /* old */
+  "oo", "||", 1,               /* ansi */
+  "truth_not", "!", 0,         /* old */
+  "nt", "!", 1,                        /* ansi */
+  "postincrement", "++", 0,    /* old */
+  "pp", "++", 1,               /* ansi */
+  "postdecrement", "--", 0,    /* old */
+  "mm", "--", 1,               /* ansi */
+  "bit_ior", "|", 0,           /* old */
+  "or", "|", 1,                        /* ansi */
+  "aor", "|=", 1,              /* ansi */
+  "bit_xor", "^", 0,           /* old */
+  "er", "^", 1,                        /* ansi */
+  "aer", "^=", 1,              /* ansi */
+  "bit_and", "&", 0,           /* old */
+  "ad", "&", 1,                        /* ansi */
+  "aad", "&=", 1,              /* ansi */
+  "bit_not", "~", 0,           /* old */
+  "co", "~", 1,                        /* ansi */
+  "call", "()", 0,             /* old */
+  "cl", "()", 1,               /* ansi */
+  "alshift", "<<", 0,          /* old */
+  "ls", "<<", 1,               /* ansi */
+  "als", "<<=", 1,             /* ansi */
+  "arshift", ">>", 0,          /* old */
+  "rs", ">>", 1,               /* ansi */
+  "ars", ">>=", 1,             /* ansi */
+  "component", "->", 0,                /* old */
+  "rf", "->", 1,               /* ansi */
+  "indirect", "*", 0,          /* old */
+  "method_call", "->()", 0,    /* old */
+  "addr", "&", 0,              /* old (unary &) */
+  "array", "[]", 0,            /* old */
+  "vc", "[]", 1,               /* ansi */
+  "compound", ",", 0,          /* old */
+  "cm", ",", 1,                        /* ansi */
+  "cond", "?:", 0,             /* old */
+  "cn", "?:", 1,               /* psuedo-ansi */
+  "max", ">?", 0,              /* old */
+  "mx", ">?", 1,               /* psuedo-ansi */
+  "min", "<?", 0,              /* old */
+  "mn", "<?", 1,               /* psuedo-ansi */
+  "nop", "", 0,                        /* old (for operator=) */
 };
 
 /* Beware: these aren't '\0' terminated. */
@@ -156,60 +170,79 @@ typedef struct string {
   char *e;                     /* pointer after end of allocated space */
 } string;
 
-#ifdef __STDC__
-static void string_need (string *s, int n);
-static void string_delete (string *s);
-static void string_init (string *s);
-static void string_clear (string *s);
-static int string_empty (string *s);
-static void string_append (string *p, const char *s);
-static void string_appends (string *p, string *s);
-static void string_appendn (string *p, const char *s, int n);
-static void string_prepend (string *p, const char *s);
-#if 0
-static void string_prepends (string *p, string *s);
-#endif
-static void string_prependn (string *p, const char *s, int n);
-static int get_count (const char **type, int *count);
-static int do_args (const char **type, string *decl, int arg_mode);
-static int do_type (const char **type, string *result, int arg_mode);
-static int do_arg (const char **type, string *result, int arg_mode);
-static void munge_function_name (string *name, int arg_mode);
-static void remember_type (const char *type, int len);
-#else
-static void string_need ();
-static void string_delete ();
-static void string_init ();
-static void string_clear ();
-static int string_empty ();
-static void string_append ();
-static void string_appends ();
-static void string_appendn ();
-static void string_prepend ();
+static void
+string_need PARAMS ((string *, int));
+
+static void
+string_delete PARAMS ((string *));
+
+static void
+string_init PARAMS ((string *));
+
+static void
+string_clear PARAMS ((string *));
+
+static int
+string_empty PARAMS ((string *));
+
+static void
+string_append PARAMS ((string *, const char *));
+
+static void
+string_appends PARAMS ((string *, string *));
+
+static void
+string_appendn PARAMS ((string *, const char *, int));
+
+static void
+string_prepend PARAMS ((string *, const char *));
+
+static void
+string_prependn PARAMS ((string *, const char *, int));
+
+static int
+get_count PARAMS ((const char **, int *));
+
+static int
+do_args PARAMS ((const char **, string *, int));
+
+static int
+do_type PARAMS ((const char **, string *, int));
+
+static int
+do_arg PARAMS ((const char **, string *, int));
+
+static void
+munge_function_name PARAMS ((string *, int));
+
+static void
+remember_type PARAMS ((const char *, int));
+
 #if 0
-static void string_prepends ();
-#endif
-static void string_prependn ();
-static int get_count ();
-static int do_args ();
-static int do_type ();
-static int do_arg ();
-static int do_args ();
-static void munge_function_name ();
-static void remember_type ();
+static void
+string_prepends PARAMS ((string *, string *));
 #endif
 
+
 /* Takes operator name as e.g. "++" and returns mangled
-   operator name (e.g. "postincrement_expr"), or NULL if not found.  */
+   operator name (e.g. "postincrement_expr"), or NULL if not found.
+
+   If ARG_MODE == 1, return the ANSI name;
+   if ARG_MODE == 0 return the old GNU name.  */
 char *
-cplus_mangle_opname (opname)
+cplus_mangle_opname (opname, arg_mode)
      char *opname;
+     int arg_mode;
 {
   int i, len = strlen (opname);
 
+  if (arg_mode != 0 && arg_mode != 1)
+    error ("invalid arg_mode");
+
   for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)
     {
       if (strlen (optable[i].out) == len
+         && arg_mode == optable[i].ansi
          && memcmp (optable[i].out, opname, len) == 0)
        return (char *)optable[i].in;
     }
@@ -251,19 +284,39 @@ cplus_demangle (type, arg_mode)
       /* destructor */
       if (type[0] == '_' && type[1] == CPLUS_MARKER && type[2] == '_')
        {
-         destructor = 1;
-         p = type;
+         int n;
+         char *tem;
+
+         type += 3;            /* Get past _$_ at front.  */
+         while (isdigit (*type))
+           /* If there are digits at the front, it's because
+              of new 2.0 name mangling.  Just skip them.  */
+           type++;
+
+         n = strlen (type)*2 + 3 + 2 + 1;
+         tem = (char *) xmalloc (n);
+         strcpy (tem, type);
+         strcat (tem, "::~");
+         strcat (tem, type);
+         if (print_arg_types)
+           strcat (tem, "()");
+         return tem;
        }
       /* static data member */
-      if (*type != '_' && (strchr (type, CPLUS_MARKER) != NULL))
+      if (*type != '_' && (p = strchr (type, CPLUS_MARKER)) != NULL)
        {
-         static_type = 1;
-         p = type;
+         int n = strlen (type) + 2;
+         char *tem = (char *) xmalloc (n);
+         memcpy (tem, type, p - type);
+         strcpy (tem + (p - type), "::");
+         strcpy (tem + (p - type) + 2, p + 1);
+         return tem;
        }
-      /* virtual table "_vt$" */
+      /* virtual table "_vt$"  */
       if (type[0] == '_' && type[1] == 'v' && type[2] == 't' && type[3] == CPLUS_MARKER)
        {
-         char *tem = (char *) xmalloc (strlen (type + 4) + 14 + 1);
+         int n = strlen (type + 4) + 14 + 1;
+         char *tem = (char *) xmalloc (n);
          strcpy (tem, type + 4);
          strcat (tem, " virtual table");
          return tem;
@@ -283,17 +336,34 @@ cplus_demangle (type, arg_mode)
     }
   else if (p == type)
     {
-      if (!isdigit (p[2]))
+      if (!isdigit (p[2]) && ('t' != p[2]))
        {
-         string_delete (&decl);
-         return NULL;
+         p += 1;
+         while (*p != '\0' && !(*p == '_' && p[1] == '_'))
+           p++;
+         string_appendn (&decl, type, p - type);
+         string_need (&decl, 1);
+         *(decl.p) = '\0';
+         munge_function_name (&decl, 1);
+         if (decl.b[0] == '_')
+           {
+             string_delete (&decl);
+             return NULL;
+           }
+         else
+           p += 2;
+       }
+      else
+       {
+         constructor = 1;
+         p += 2;
        }
-      constructor = 1;
-      p += 2;
     }
   else
     {
       string_appendn (&decl, type, p - type);
+      string_need (&decl, 1);
+      *(decl.p) = '\0';
       munge_function_name (&decl, arg_mode);
       p += 2;
     }
@@ -1048,7 +1118,10 @@ munge_function_name (name, arg_mode)
      string *name;
      int arg_mode;
 {
-  if (!string_empty (name) && name->p - name->b >= 3 
+  if (string_empty (name))
+    return;
+
+  if (name->p - name->b >= 3 
       && name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == CPLUS_MARKER)
     {
       int i;
@@ -1087,8 +1160,7 @@ munge_function_name (name, arg_mode)
        }
       return;
     }
-  else if (!string_empty (name) && name->p - name->b >= 5
-          && memcmp (name->b, "type$", 5) == 0)
+  else if (name->p - name->b >= 5 && memcmp (name->b, "type$", 5) == 0)
     {
       /* type conversion operator */
       string type;
@@ -1102,6 +1174,60 @@ munge_function_name (name, arg_mode)
          return;
        }
     }
+  /* ANSI.  */
+  else if (name->b[2] == 'o' && name->b[3] == 'p')
+    {
+      /* type conversion operator.  */
+      string type;
+      const char *tem = name->b + 4;
+      if (do_type (&tem, &type, arg_mode))
+       {
+         string_clear (name);
+         string_append (name, "operator ");
+         string_appends (name, &type);
+         string_delete (&type);
+         return;
+       }
+    }
+  else if (name->b[0] == '_' && name->b[1] == '_'
+          && name->b[2] >= 'a' && name->b[2] <= 'z'
+          && name->b[3] >= 'a' && name->b[3] <= 'z')
+    {
+      int i;
+
+      if (name->b[4] == '\0')
+       {
+         /* Operator.  */
+         for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)
+           {
+             if (strlen (optable[i].in) == 2
+                 && memcmp (optable[i].in, name->b + 2, 2) == 0)
+               {
+                 string_clear (name);
+                 string_append (name, "operator");
+                 string_append (name, optable[i].out);
+                 return;
+               }
+           }
+       }
+      else
+       {
+         if (name->b[2] != 'a' || name->b[5] != '\0')
+           return;
+         /* Assignment.  */
+         for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)
+           {
+             if (strlen (optable[i].in) == 3
+                 && memcmp (optable[i].in, name->b + 2, 3) == 0)
+               {
+                 string_clear (name);
+                 string_append (name, "operator");
+                 string_append (name, optable[i].out);
+                 return;
+               }
+           }
+       }
+    }
 }
 
 /* a mini string-handling package */
This page took 0.03923 seconds and 4 git commands to generate.