/[gnats]/gnats/libiberty/cplus-dem.c
ViewVC logotype

Diff of /gnats/libiberty/cplus-dem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by pdm, Mon Dec 10 23:03:26 2001 UTC revision 1.4 by chewie, Sat Nov 13 05:14:17 2004 UTC
# Line 1  Line 1 
1  /* Demangler for GNU C++  /* Demangler for GNU C++
2     Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,     Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
3     2000, 2001 Free Software Foundation, Inc.     2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4     Written by James Clark (jjc@jclark.uucp)     Written by James Clark (jjc@jclark.uucp)
5     Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling     Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
6     Modified by Satish Pai (pai@apollo.hp.com) for HP demangling     Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
# Line 11  modify it under the terms of the GNU Lib Line 11  modify it under the terms of the GNU Lib
11  License as published by the Free Software Foundation; either  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.  version 2 of the License, or (at your option) any later version.
13    
14    In addition to the permissions in the GNU Library General Public
15    License, the Free Software Foundation gives you unlimited permission
16    to link the compiled version of this file into combinations with other
17    programs, and to distribute those combinations without any restriction
18    coming from the use of this file.  (The Library Public License
19    restrictions do apply in other respects; for example, they cover
20    modification of the file, and distribution when not linked into a
21    combined executable.)
22    
23  Libiberty is distributed in the hope that it will be useful,  Libiberty is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Line 63  static char *ada_demangle  PARAMS ((cons Line 72  static char *ada_demangle  PARAMS ((cons
72    
73  extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;  extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
74    
 static const char *mystrstr PARAMS ((const char *, const char *));  
   
 static const char *  
 mystrstr (s1, s2)  
      const char *s1, *s2;  
 {  
   register const char *p = s1;  
   register int len = strlen (s2);  
   
   for (; (p = strchr (p, *s2)) != 0; p++)  
     {  
       if (strncmp (p, s2, len) == 0)  
         {  
           return (p);  
         }  
     }  
   return (0);  
 }  
   
75  /* In order to allow a single demangler executable to demangle strings  /* In order to allow a single demangler executable to demangle strings
76     using various common values of CPLUS_MARKER, as well as any specific     using various common values of CPLUS_MARKER, as well as any specific
77     one set at compile time, we maintain a string containing all the     one set at compile time, we maintain a string containing all the
# Line 157  struct work_stuff Line 147  struct work_stuff
147    
148  static const struct optable  static const struct optable
149  {  {
150    const char *in;    const char *const in;
151    const char *out;    const char *const out;
152    int flags;    const int flags;
153  } optable[] = {  } optable[] = {
154    {"nw",          " new",       DMGL_ANSI},     /* new (1.92,    ansi) */    {"nw",          " new",       DMGL_ANSI},     /* new (1.92,    ansi) */
155    {"dl",          " delete",    DMGL_ANSI},     /* new (1.92,    ansi) */    {"dl",          " delete",    DMGL_ANSI},     /* new (1.92,    ansi) */
# Line 256  typedef enum type_kind_t Line 246  typedef enum type_kind_t
246    tk_real    tk_real
247  } type_kind_t;  } type_kind_t;
248    
249  struct demangler_engine libiberty_demanglers[] =  const struct demangler_engine libiberty_demanglers[] =
250  {  {
251    {    {
252        NO_DEMANGLING_STYLE_STRING,
253        no_demangling,
254        "Demangling disabled"
255      }
256      ,
257      {
258      AUTO_DEMANGLING_STYLE_STRING,      AUTO_DEMANGLING_STYLE_STRING,
259        auto_demangling,        auto_demangling,
260        "Automatic selection based on executable"        "Automatic selection based on executable"
# Line 318  struct demangler_engine libiberty_demang Line 314  struct demangler_engine libiberty_demang
314  };  };
315    
316  #define STRING_EMPTY(str)       ((str) -> b == (str) -> p)  #define STRING_EMPTY(str)       ((str) -> b == (str) -> p)
 #define PREPEND_BLANK(str)      {if (!STRING_EMPTY(str)) \  
     string_prepend(str, " ");}  
317  #define APPEND_BLANK(str)       {if (!STRING_EMPTY(str)) \  #define APPEND_BLANK(str)       {if (!STRING_EMPTY(str)) \
318      string_append(str, " ");}      string_append(str, " ");}
319  #define LEN_STRING(str)         ( (STRING_EMPTY(str))?0:((str)->p - (str)->b))  #define LEN_STRING(str)         ( (STRING_EMPTY(str))?0:((str)->p - (str)->b))
# Line 529  recursively_demangle PARAMS ((struct wor Line 523  recursively_demangle PARAMS ((struct wor
523                                int));                                int));
524    
525  static void  static void
526  grow_vect PARAMS ((void **, size_t *, size_t, int));  grow_vect PARAMS ((char **, size_t *, size_t, int));
527    
528  /* Translate count to integer, consuming tokens in the process.  /* Translate count to integer, consuming tokens in the process.
529     Conversion terminates on the first non-digit character.     Conversion terminates on the first non-digit character.
# Line 568  consume_count (type) Line 562  consume_count (type)
562        (*type)++;        (*type)++;
563      }      }
564    
565      if (count < 0)
566        count = -1;
567    
568    return (count);    return (count);
569  }  }
570    
# Line 847  enum demangling_styles Line 844  enum demangling_styles
844  cplus_demangle_set_style (style)  cplus_demangle_set_style (style)
845       enum demangling_styles style;       enum demangling_styles style;
846  {  {
847    struct demangler_engine *demangler = libiberty_demanglers;    const struct demangler_engine *demangler = libiberty_demanglers;
848    
849    for (; demangler->demangling_style != unknown_demangling; ++demangler)    for (; demangler->demangling_style != unknown_demangling; ++demangler)
850      if (style == demangler->demangling_style)      if (style == demangler->demangling_style)
# Line 865  enum demangling_styles Line 862  enum demangling_styles
862  cplus_demangle_name_to_style (name)  cplus_demangle_name_to_style (name)
863       const char *name;       const char *name;
864  {  {
865    struct demangler_engine *demangler = libiberty_demanglers;    const struct demangler_engine *demangler = libiberty_demanglers;
866    
867    for (; demangler->demangling_style != unknown_demangling; ++demangler)    for (; demangler->demangling_style != unknown_demangling; ++demangler)
868      if (strcmp (name, demangler->demangling_style_name) == 0)      if (strcmp (name, demangler->demangling_style_name) == 0)
# Line 877  cplus_demangle_name_to_style (name) Line 874  cplus_demangle_name_to_style (name)
874  /* char *cplus_demangle (const char *mangled, int options)  /* char *cplus_demangle (const char *mangled, int options)
875    
876     If MANGLED is a mangled function name produced by GNU C++, then     If MANGLED is a mangled function name produced by GNU C++, then
877     a pointer to a malloced string giving a C++ representation     a pointer to a @code{malloc}ed string giving a C++ representation
878     of the name will be returned; otherwise NULL will be returned.     of the name will be returned; otherwise NULL will be returned.
879     It is the caller's responsibility to free the string which     It is the caller's responsibility to free the string which
880     is returned.     is returned.
# Line 909  cplus_demangle (mangled, options) Line 906  cplus_demangle (mangled, options)
906  {  {
907    char *ret;    char *ret;
908    struct work_stuff work[1];    struct work_stuff work[1];
909    
910      if (current_demangling_style == no_demangling)
911        return xstrdup (mangled);
912    
913    memset ((char *) work, 0, sizeof (work));    memset ((char *) work, 0, sizeof (work));
914    work->options = options;    work->options = options;
915    if ((work->options & DMGL_STYLE_MASK) == 0)    if ((work->options & DMGL_STYLE_MASK) == 0)
# Line 917  cplus_demangle (mangled, options) Line 918  cplus_demangle (mangled, options)
918    /* The V3 ABI demangling is implemented elsewhere.  */    /* The V3 ABI demangling is implemented elsewhere.  */
919    if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)    if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
920      {      {
921        ret = cplus_demangle_v3 (mangled);        ret = cplus_demangle_v3 (mangled, work->options);
922        if (ret || GNU_V3_DEMANGLING)        if (ret || GNU_V3_DEMANGLING)
923          return ret;          return ret;
924      }      }
# Line 944  cplus_demangle (mangled, options) Line 945  cplus_demangle (mangled, options)
945    
946  static void  static void
947  grow_vect (old_vect, size, min_size, element_size)  grow_vect (old_vect, size, min_size, element_size)
948       void **old_vect;       char **old_vect;
949       size_t *size;       size_t *size;
950       size_t min_size;       size_t min_size;
951       int element_size;       int element_size;
# Line 954  grow_vect (old_vect, size, min_size, ele Line 955  grow_vect (old_vect, size, min_size, ele
955        *size *= 2;        *size *= 2;
956        if (*size < min_size)        if (*size < min_size)
957          *size = min_size;          *size = min_size;
958        *old_vect = xrealloc (*old_vect, *size * element_size);        *old_vect = (void *) xrealloc (*old_vect, *size * element_size);
959      }      }
960  }  }
961    
# Line 977  ada_demangle (mangled, option) Line 978  ada_demangle (mangled, option)
978    char *demangled = NULL;    char *demangled = NULL;
979    int at_start_name;    int at_start_name;
980    int changed;    int changed;
981    char *demangling_buffer = NULL;    size_t demangled_size = 0;
   size_t demangling_buffer_size = 0;  
982        
983    changed = 0;    changed = 0;
984    
# Line 1006  ada_demangle (mangled, option) Line 1006  ada_demangle (mangled, option)
1006      }      }
1007        
1008    /* Make demangled big enough for possible expansion by operator name.  */    /* Make demangled big enough for possible expansion by operator name.  */
1009    grow_vect ((void **) &(demangling_buffer),    grow_vect (&demangled,
1010               &demangling_buffer_size,  2 * len0 + 1,               &demangled_size,  2 * len0 + 1,
1011               sizeof (char));               sizeof (char));
   demangled = demangling_buffer;  
1012        
1013    if (ISDIGIT ((unsigned char) mangled[len0 - 1])) {    if (ISDIGIT ((unsigned char) mangled[len0 - 1])) {
1014      for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1)      for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1)
# Line 1059  ada_demangle (mangled, option) Line 1058  ada_demangle (mangled, option)
1058      return demangled;      return demangled;
1059        
1060   Suppress:   Suppress:
1061    grow_vect ((void **) &(demangling_buffer),    grow_vect (&demangled,
1062               &demangling_buffer_size,  strlen (mangled) + 3,               &demangled_size,  strlen (mangled) + 3,
1063               sizeof (char));               sizeof (char));
1064    demangled = demangling_buffer;  
1065    if (mangled[0] == '<')    if (mangled[0] == '<')
1066       strcpy (demangled, mangled);       strcpy (demangled, mangled);
1067    else    else
# Line 1074  ada_demangle (mangled, option) Line 1073  ada_demangle (mangled, option)
1073  /* This function performs most of what cplus_demangle use to do, but  /* This function performs most of what cplus_demangle use to do, but
1074     to be able to demangle a name with a B, K or n code, we need to     to be able to demangle a name with a B, K or n code, we need to
1075     have a longer term memory of what types have been seen. The original     have a longer term memory of what types have been seen. The original
1076     now intializes and cleans up the squangle code info, while internal     now initializes and cleans up the squangle code info, while internal
1077     calls go directly to this routine to avoid resetting that info. */     calls go directly to this routine to avoid resetting that info. */
1078    
1079  static char *  static char *
# Line 1214  work_stuff_copy_to_from (to, from) Line 1213  work_stuff_copy_to_from (to, from)
1213    
1214    if (from->ntmpl_args)    if (from->ntmpl_args)
1215      to->tmpl_argvec      to->tmpl_argvec
1216        = xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));        = (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
1217    
1218    for (i = 0; i < from->ntmpl_args; i++)    for (i = 0; i < from->ntmpl_args; i++)
1219      {      {
# Line 1439  demangle_signature (work, mangled, declp Line 1438  demangle_signature (work, mangled, declp
1438                {                {
1439                  string_append (&s, SCOPE_STRING (work));                  string_append (&s, SCOPE_STRING (work));
1440                  string_prepends (declp, &s);                  string_prepends (declp, &s);
1441                    string_delete (&s);
1442                }                }
1443              oldmangled = NULL;              oldmangled = NULL;
1444              expect_func = 1;              expect_func = 1;
# Line 1518  demangle_signature (work, mangled, declp Line 1518  demangle_signature (work, mangled, declp
1518              {              {
1519                /* Read the return type. */                /* Read the return type. */
1520                string return_type;                string return_type;
               string_init (&return_type);  
1521    
1522                (*mangled)++;                (*mangled)++;
1523                success = do_type (work, mangled, &return_type);                success = do_type (work, mangled, &return_type);
# Line 1793  demangle_integral_value (work, mangled, Line 1792  demangle_integral_value (work, mangled,
1792    
1793        /* By default, we let the number decide whether we shall consume an        /* By default, we let the number decide whether we shall consume an
1794           underscore.  */           underscore.  */
1795        int consume_following_underscore = 0;        int multidigit_without_leading_underscore = 0;
1796        int leave_following_underscore = 0;        int leave_following_underscore = 0;
1797    
1798        success = 0;        success = 0;
1799    
1800        /* Negative numbers are indicated with a leading `m'.  */        if (**mangled == '_')
1801        if (**mangled == 'm')          {
1802          {            if (mangled[0][1] == 'm')
1803            string_appendn (s, "-", 1);              {
1804            (*mangled)++;                /* Since consume_count_with_underscores does not handle the
1805          }                   `m'-prefix we must do it here, using consume_count and
1806        else if (mangled[0][0] == '_' && mangled[0][1] == 'm')                   adjusting underscores: we have to consume the underscore
1807          {                   matching the prepended one.  */
1808            /* Since consume_count_with_underscores does not handle the                multidigit_without_leading_underscore = 1;
1809               `m'-prefix we must do it here, using consume_count and                string_appendn (s, "-", 1);
1810               adjusting underscores: we have to consume the underscore                (*mangled) += 2;
1811               matching the prepended one.  */              }
1812            consume_following_underscore = 1;            else
1813            string_appendn (s, "-", 1);              {
1814            (*mangled) += 2;                /* Do not consume a following underscore;
1815                     consume_count_with_underscores will consume what
1816                     should be consumed.  */
1817                  leave_following_underscore = 1;
1818                }
1819          }          }
1820        else if (**mangled == '_')        else
1821          {          {
1822            /* Do not consume a following underscore;            /* Negative numbers are indicated with a leading `m'.  */
1823               consume_following_underscore will consume what should be            if (**mangled == 'm')
1824               consumed.  */            {
1825                string_appendn (s, "-", 1);
1826                (*mangled)++;
1827              }
1828              /* Since consume_count_with_underscores does not handle
1829                 multi-digit numbers that do not start with an underscore,
1830                 and this number can be an integer template parameter,
1831                 we have to call consume_count. */
1832              multidigit_without_leading_underscore = 1;
1833              /* These multi-digit numbers never end on an underscore,
1834                 so if there is one then don't eat it. */
1835            leave_following_underscore = 1;            leave_following_underscore = 1;
1836          }          }
1837    
# Line 1826  demangle_integral_value (work, mangled, Line 1839  demangle_integral_value (work, mangled,
1839           underscore, since consume_count_with_underscores expects           underscore, since consume_count_with_underscores expects
1840           the leading underscore (that we consumed) if it is to handle           the leading underscore (that we consumed) if it is to handle
1841           multi-digit numbers.  */           multi-digit numbers.  */
1842        if (consume_following_underscore)        if (multidigit_without_leading_underscore)
1843          value = consume_count (mangled);          value = consume_count (mangled);
1844        else        else
1845          value = consume_count_with_underscores (mangled);          value = consume_count_with_underscores (mangled);
# Line 1844  demangle_integral_value (work, mangled, Line 1857  demangle_integral_value (work, mangled,
1857               is wrong.  If other (arbitrary) cases are followed by an               is wrong.  If other (arbitrary) cases are followed by an
1858               underscore, we need to do something more radical.  */               underscore, we need to do something more radical.  */
1859    
1860            if ((value > 9 || consume_following_underscore)            if ((value > 9 || multidigit_without_leading_underscore)
1861                && ! leave_following_underscore                && ! leave_following_underscore
1862                && **mangled == '_')                && **mangled == '_')
1863              (*mangled)++;              (*mangled)++;
# Line 1852  demangle_integral_value (work, mangled, Line 1865  demangle_integral_value (work, mangled,
1865            /* All is well.  */            /* All is well.  */
1866            success = 1;            success = 1;
1867          }          }
1868      }        }
1869    
1870    return success;    return success;
1871  }  }
# Line 2030  demangle_template (work, mangled, tname, Line 2043  demangle_template (work, mangled, tname,
2043    const char *start;    const char *start;
2044    int is_java_array = 0;    int is_java_array = 0;
2045    string temp;    string temp;
   int bindex = 0;  
2046    
2047    (*mangled)++;    (*mangled)++;
2048    if (is_type)    if (is_type)
2049      {      {
       if (remember)  
         bindex = register_Btype (work);  
2050        start = *mangled;        start = *mangled;
2051        /* get template name */        /* get template name */
2052        if (**mangled == 'z')        if (**mangled == 'z')
# Line 2213  demangle_template (work, mangled, tname, Line 2223  demangle_template (work, mangled, tname,
2223      }      }
2224    
2225    if (is_type && remember)    if (is_type && remember)
2226      remember_Btype (work, tname->b, LEN_STRING (tname), bindex);      {
2227          const int bindex = register_Btype (work);
2228          remember_Btype (work, tname->b, LEN_STRING (tname), bindex);
2229        }
2230    
2231    /*    /*
2232      if (work -> static_type)      if (work -> static_type)
# Line 2240  arm_pt (work, mangled, n, anchor, args) Line 2253  arm_pt (work, mangled, n, anchor, args)
2253  {  {
2254    /* Check if ARM template with "__pt__" in it ("parameterized type") */    /* Check if ARM template with "__pt__" in it ("parameterized type") */
2255    /* Allow HP also here, because HP's cfront compiler follows ARM to some extent */    /* Allow HP also here, because HP's cfront compiler follows ARM to some extent */
2256    if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = mystrstr (mangled, "__pt__")))    if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = strstr (mangled, "__pt__")))
2257      {      {
2258        int len;        int len;
2259        *args = *anchor + 6;        *args = *anchor + 6;
# Line 2255  arm_pt (work, mangled, n, anchor, args) Line 2268  arm_pt (work, mangled, n, anchor, args)
2268      }      }
2269    if (AUTO_DEMANGLING || EDG_DEMANGLING)    if (AUTO_DEMANGLING || EDG_DEMANGLING)
2270      {      {
2271        if ((*anchor = mystrstr (mangled, "__tm__"))        if ((*anchor = strstr (mangled, "__tm__"))
2272            || (*anchor = mystrstr (mangled, "__ps__"))            || (*anchor = strstr (mangled, "__ps__"))
2273            || (*anchor = mystrstr (mangled, "__pt__")))            || (*anchor = strstr (mangled, "__pt__")))
2274          {          {
2275            int len;            int len;
2276            *args = *anchor + 6;            *args = *anchor + 6;
# Line 2270  arm_pt (work, mangled, n, anchor, args) Line 2283  arm_pt (work, mangled, n, anchor, args)
2283                return 1;                return 1;
2284              }              }
2285          }          }
2286        else if ((*anchor = mystrstr (mangled, "__S")))        else if ((*anchor = strstr (mangled, "__S")))
2287          {          {
2288            int len;            int len;
2289            *args = *anchor + 3;            *args = *anchor + 3;
# Line 2305  demangle_arm_hp_template (work, mangled, Line 2318  demangle_arm_hp_template (work, mangled,
2318    if (HP_DEMANGLING && ((*mangled)[n] == 'X'))    if (HP_DEMANGLING && ((*mangled)[n] == 'X'))
2319      {      {
2320        char *start_spec_args = NULL;        char *start_spec_args = NULL;
2321          int hold_options;
2322    
2323        /* First check for and omit template specialization pseudo-arguments,        /* First check for and omit template specialization pseudo-arguments,
2324           such as in "Spec<#1,#1.*>" */           such as in "Spec<#1,#1.*>" */
# Line 2317  demangle_arm_hp_template (work, mangled, Line 2331  demangle_arm_hp_template (work, mangled,
2331        string_init (&arg);        string_init (&arg);
2332        if (work->temp_start == -1) /* non-recursive call */        if (work->temp_start == -1) /* non-recursive call */
2333          work->temp_start = declp->p - declp->b;          work->temp_start = declp->p - declp->b;
2334    
2335          /* We want to unconditionally demangle parameter types in
2336             template parameters.  */
2337          hold_options = work->options;
2338          work->options |= DMGL_PARAMS;
2339    
2340        string_append (declp, "<");        string_append (declp, "<");
2341        while (1)        while (1)
2342          {          {
2343            string_clear (&arg);            string_delete (&arg);
2344            switch (**mangled)            switch (**mangled)
2345              {              {
2346                case 'T':                case 'T':
# Line 2363  demangle_arm_hp_template (work, mangled, Line 2383  demangle_arm_hp_template (work, mangled,
2383        string_delete (&arg);        string_delete (&arg);
2384        if (**mangled == '_')        if (**mangled == '_')
2385          (*mangled)++;          (*mangled)++;
2386          work->options = hold_options;
2387        return;        return;
2388      }      }
2389    /* ARM template? (Also handles HP cfront extensions) */    /* ARM template? (Also handles HP cfront extensions) */
2390    else if (arm_pt (work, *mangled, n, &p, &args))    else if (arm_pt (work, *mangled, n, &p, &args))
2391      {      {
2392          int hold_options;
2393        string type_str;        string type_str;
2394    
2395        string_init (&arg);        string_init (&arg);
2396        string_appendn (declp, *mangled, p - *mangled);        string_appendn (declp, *mangled, p - *mangled);
2397        if (work->temp_start == -1)  /* non-recursive call */        if (work->temp_start == -1)  /* non-recursive call */
2398          work->temp_start = declp->p - declp->b;          work->temp_start = declp->p - declp->b;
2399    
2400          /* We want to unconditionally demangle parameter types in
2401             template parameters.  */
2402          hold_options = work->options;
2403          work->options |= DMGL_PARAMS;
2404    
2405        string_append (declp, "<");        string_append (declp, "<");
2406        /* should do error checking here */        /* should do error checking here */
2407        while (args < e) {        while (args < e) {
2408          string_clear (&arg);          string_delete (&arg);
2409    
2410          /* Check for type or literal here */          /* Check for type or literal here */
2411          switch (*args)          switch (*args)
# Line 2392  demangle_arm_hp_template (work, mangled, Line 2420  demangle_arm_hp_template (work, mangled,
2420                goto cfront_template_args_done;                goto cfront_template_args_done;
2421              string_append (&arg, "(");              string_append (&arg, "(");
2422              string_appends (&arg, &type_str);              string_appends (&arg, &type_str);
2423                string_delete (&type_str);
2424              string_append (&arg, ")");              string_append (&arg, ")");
2425              if (*args != 'L')              if (*args != 'L')
2426                goto cfront_template_args_done;                goto cfront_template_args_done;
# Line 2409  demangle_arm_hp_template (work, mangled, Line 2438  demangle_arm_hp_template (work, mangled,
2438              break;              break;
2439            default:            default:
2440              /* Not handling other HP cfront stuff */              /* Not handling other HP cfront stuff */
2441              if (!do_type (work, &args, &arg))              {
2442                goto cfront_template_args_done;                const char* old_args = args;
2443                  if (!do_type (work, &args, &arg))
2444                    goto cfront_template_args_done;
2445    
2446                  /* Fail if we didn't make any progress: prevent infinite loop. */
2447                  if (args == old_args)
2448                    {
2449                      work->options = hold_options;
2450                      return;
2451                    }
2452                }
2453            }            }
2454          string_appends (declp, &arg);          string_appends (declp, &arg);
2455          string_append (declp, ",");          string_append (declp, ",");
# Line 2420  demangle_arm_hp_template (work, mangled, Line 2459  demangle_arm_hp_template (work, mangled,
2459        if (args >= e)        if (args >= e)
2460          --declp->p; /* remove extra comma */          --declp->p; /* remove extra comma */
2461        string_append (declp, ">");        string_append (declp, ">");
2462          work->options = hold_options;
2463      }      }
2464    else if (n>10 && strncmp (*mangled, "_GLOBAL_", 8) == 0    else if (n>10 && strncmp (*mangled, "_GLOBAL_", 8) == 0
2465             && (*mangled)[9] == 'N'             && (*mangled)[9] == 'N'
# Line 2571  iterate_demangle_function (work, mangled Line 2611  iterate_demangle_function (work, mangled
2611    /* Do not iterate for some demangling modes, or if there's only one    /* Do not iterate for some demangling modes, or if there's only one
2612       "__"-sequence.  This is the normal case.  */       "__"-sequence.  This is the normal case.  */
2613    if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING    if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
2614        || mystrstr (scan + 2, "__") == NULL)        || strstr (scan + 2, "__") == NULL)
2615      {      {
2616        demangle_function_name (work, mangled, declp, scan);        demangle_function_name (work, mangled, declp, scan);
2617        return 1;        return 1;
# Line 2714  demangle_prefix (work, mangled, declp) Line 2754  demangle_prefix (work, mangled, declp)
2754    
2755    /*  This block of code is a reduction in strength time optimization    /*  This block of code is a reduction in strength time optimization
2756        of:        of:
2757        scan = mystrstr (*mangled, "__"); */        scan = strstr (*mangled, "__"); */
2758    
2759    {    {
2760      scan = *mangled;      scan = *mangled;
# Line 2806  demangle_prefix (work, mangled, declp) Line 2846  demangle_prefix (work, mangled, declp)
2846              {              {
2847                scan++;                scan++;
2848              }              }
2849            if ((scan = mystrstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))            if ((scan = strstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
2850              {              {
2851                /* No separator (I.E. "__not_mangled"), or empty signature                /* No separator (I.E. "__not_mangled"), or empty signature
2852                   (I.E. "__not_mangled_either__") */                   (I.E. "__not_mangled_either__") */
# Line 3342  demangle_qualified (work, mangled, resul Line 3382  demangle_qualified (work, mangled, resul
3382              }              }
3383            else            else
3384              {              {
3385                  string_delete (&last_name);
3386                success = do_type (work, mangled, &last_name);                success = do_type (work, mangled, &last_name);
3387                if (!success)                if (!success)
3388                  break;                  break;
# Line 3484  do_type (work, mangled, result) Line 3525  do_type (work, mangled, result)
3525    string decl;    string decl;
3526    const char *remembered_type;    const char *remembered_type;
3527    int type_quals;    int type_quals;
   string btype;  
3528    type_kind_t tk = tk_none;    type_kind_t tk = tk_none;
3529    
   string_init (&btype);  
3530    string_init (&decl);    string_init (&decl);
3531    string_init (result);    string_init (result);
3532    
# Line 3605  do_type (work, mangled, result) Line 3644  do_type (work, mangled, result)
3644                  string temp;                  string temp;
3645                  do_type (work, mangled, &temp);                  do_type (work, mangled, &temp);
3646                  string_prepends (&decl, &temp);                  string_prepends (&decl, &temp);
3647                    string_delete (&temp);
3648                }                }
3649              else if (**mangled == 't')              else if (**mangled == 't')
3650                {                {
# Line 3615  do_type (work, mangled, result) Line 3655  do_type (work, mangled, result)
3655                  if (success)                  if (success)
3656                    {                    {
3657                      string_prependn (&decl, temp.b, temp.p - temp.b);                      string_prependn (&decl, temp.b, temp.p - temp.b);
3658                      string_clear (&temp);                      string_delete (&temp);
3659                    }                    }
3660                  else                  else
3661                    break;                    break;
# Line 3795  demangle_fund_type (work, mangled, resul Line 3835  demangle_fund_type (work, mangled, resul
3835    int success = 1;    int success = 1;
3836    char buf[10];    char buf[10];
3837    unsigned int dec = 0;    unsigned int dec = 0;
   string btype;  
3838    type_kind_t tk = tk_integral;    type_kind_t tk = tk_integral;
3839    
   string_init (&btype);  
   
3840    /* First pick off any type qualifiers.  There can be more than one.  */    /* First pick off any type qualifiers.  There can be more than one.  */
3841    
3842    while (!done)    while (!done)
# Line 3971  demangle_fund_type (work, mangled, resul Line 4008  demangle_fund_type (work, mangled, resul
4008        }        }
4009      case 't':      case 't':
4010        {        {
4011            string btype;
4012            string_init (&btype);
4013          success = demangle_template (work, mangled, &btype, 0, 1, 1);          success = demangle_template (work, mangled, &btype, 0, 1, 1);
4014          string_appends (result, &btype);          string_appends (result, &btype);
4015            string_delete (&btype);
4016          break;          break;
4017        }        }
4018      default:      default:
# Line 4174  do_arg (work, mangled, result) Line 4214  do_arg (work, mangled, result)
4214       do not want to add additional types to the back-referenceable       do not want to add additional types to the back-referenceable
4215       type vector when processing a repeated type.  */       type vector when processing a repeated type.  */
4216    if (work->previous_argument)    if (work->previous_argument)
4217      string_clear (work->previous_argument);      string_delete (work->previous_argument);
4218    else    else
4219      {      work->previous_argument = (string*) xmalloc (sizeof (string));
       work->previous_argument = (string*) xmalloc (sizeof (string));  
       string_init (work->previous_argument);  
     }  
4220    
4221    if (!do_type (work, mangled, work->previous_argument))    if (!do_type (work, mangled, work->previous_argument))
4222      return 0;      return 0;
# Line 4543  demangle_nested_args (work, mangled, dec Line 4580  demangle_nested_args (work, mangled, dec
4580    
4581    /* Restore the previous_argument field.  */    /* Restore the previous_argument field.  */
4582    if (work->previous_argument)    if (work->previous_argument)
4583      string_delete (work->previous_argument);      {
4584          string_delete (work->previous_argument);
4585          free ((char *) work->previous_argument);
4586        }
4587    work->previous_argument = saved_previous_argument;    work->previous_argument = saved_previous_argument;
4588    --work->forgetting_types;    --work->forgetting_types;
4589    work->nrepeats = saved_nrepeats;    work->nrepeats = saved_nrepeats;
# Line 4868  string_append_template_idx (s, idx) Line 4908  string_append_template_idx (s, idx)
4908    sprintf(buf, "T%d", idx);    sprintf(buf, "T%d", idx);
4909    string_append (s, buf);    string_append (s, buf);
4910  }  }
   
 /* To generate a standalone demangler program for testing purposes,  
    just compile and link this file with -DMAIN and libiberty.a.  When  
    run, it demangles each command line arg, or each stdin string, and  
    prints the result on stdout.  */  
   
 #ifdef MAIN  
   
 #include "getopt.h"  
   
 static const char *program_name;  
 static const char *program_version = VERSION;  
 static int flags = DMGL_PARAMS | DMGL_ANSI;  
   
 static void demangle_it PARAMS ((char *));  
 static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN;  
 static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN;  
 static void print_demangler_list PARAMS ((FILE *));  
   
 static void  
 demangle_it (mangled_name)  
      char *mangled_name;  
 {  
   char *result;  
   
   result = cplus_demangle (mangled_name, flags);  
   if (result == NULL)  
     {  
       printf ("%s\n", mangled_name);  
     }  
   else  
     {  
       printf ("%s\n", result);  
       free (result);  
     }  
 }  
   
 static void  
 print_demangler_list (stream)  
      FILE *stream;  
 {  
   struct demangler_engine *demangler;  
   
   fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);  
     
   for (demangler = libiberty_demanglers + 1;  
        demangler->demangling_style != unknown_demangling;  
        ++demangler)  
     fprintf (stream, ",%s", demangler->demangling_style_name);  
   
   fprintf (stream, "}");  
 }  
   
 static void  
 usage (stream, status)  
      FILE *stream;  
      int status;  
 {  
   fprintf (stream, "\  
 Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",  
            program_name);  
   
   fprintf (stream, "\  
        [-s ");  
   print_demangler_list (stream);  
   fprintf (stream, "]\n");  
   
   fprintf (stream, "\  
        [--format ");  
   print_demangler_list (stream);  
   fprintf (stream, "]\n");  
   
   fprintf (stream, "\  
        [--help] [--version] [arg...]\n");  
   exit (status);  
 }  
   
 #define MBUF_SIZE 32767  
 char mbuffer[MBUF_SIZE];  
   
 /* Defined in the automatically-generated underscore.c.  */  
 extern int prepends_underscore;  
   
 int strip_underscore = 0;  
   
 static struct option long_options[] = {  
   {"strip-underscores", no_argument, 0, '_'},  
   {"format", required_argument, 0, 's'},  
   {"help", no_argument, 0, 'h'},  
   {"no-strip-underscores", no_argument, 0, 'n'},  
   {"version", no_argument, 0, 'v'},  
   {0, no_argument, 0, 0}  
 };  
   
 /* More 'friendly' abort that prints the line and file.  
    config.h can #define abort fancy_abort if you like that sort of thing.  */  
   
 void  
 fancy_abort ()  
 {  
   fatal ("Internal gcc abort.");  
 }  
   
   
 static const char *  
 standard_symbol_characters PARAMS ((void));  
   
 static const char *  
 hp_symbol_characters PARAMS ((void));  
   
 static const char *  
 gnu_v3_symbol_characters PARAMS ((void));  
   
 /* Return the string of non-alnum characters that may occur  
    as a valid symbol component, in the standard assembler symbol  
    syntax.  */  
   
 static const char *  
 standard_symbol_characters ()  
 {  
   return "_$.";  
 }  
   
   
 /* Return the string of non-alnum characters that may occur  
    as a valid symbol name component in an HP object file.  
   
    Note that, since HP's compiler generates object code straight from  
    C++ source, without going through an assembler, its mangled  
    identifiers can use all sorts of characters that no assembler would  
    tolerate, so the alphabet this function creates is a little odd.  
    Here are some sample mangled identifiers offered by HP:  
   
         typeid*__XT24AddressIndExpClassMember_  
         [Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv  
         __ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv  
   
    This still seems really weird to me, since nowhere else in this  
    file is there anything to recognize curly brackets, parens, etc.  
    I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me  
    this is right, but I still strongly suspect that there's a  
    misunderstanding here.  
   
    If we decide it's better for c++filt to use HP's assembler syntax  
    to scrape identifiers out of its input, here's the definition of  
    the symbol name syntax from the HP assembler manual:  
   
        Symbols are composed of uppercase and lowercase letters, decimal  
        digits, dollar symbol, period (.), ampersand (&), pound sign(#) and  
        underscore (_). A symbol can begin with a letter, digit underscore or  
        dollar sign. If a symbol begins with a digit, it must contain a  
        non-digit character.  
   
    So have fun.  */  
 static const char *  
 hp_symbol_characters ()  
 {  
   return "_$.<>#,*&[]:(){}";  
 }  
   
   
 /* Return the string of non-alnum characters that may occur  
    as a valid symbol component in the GNU C++ V3 ABI mangling  
    scheme.  */  
   
 static const char *  
 gnu_v3_symbol_characters ()  
 {  
   return "_$.";  
 }  
   
   
 extern int main PARAMS ((int, char **));  
   
 int  
 main (argc, argv)  
      int argc;  
      char **argv;  
 {  
   char *result;  
   int c;  
   const char *valid_symbols;  
   enum demangling_styles style = auto_demangling;  
   
   program_name = argv[0];  
   
   strip_underscore = prepends_underscore;  
   
   while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF)  
     {  
       switch (c)  
         {  
         case '?':  
           usage (stderr, 1);  
           break;  
         case 'h':  
           usage (stdout, 0);  
         case 'n':  
           strip_underscore = 0;  
           break;  
         case 'v':  
           printf ("GNU %s (C++ demangler), version %s\n", program_name, program_version);  
           return (0);  
         case '_':  
           strip_underscore = 1;  
           break;  
         case 's':  
           {  
             style = cplus_demangle_name_to_style (optarg);  
             if (style == unknown_demangling)  
               {  
                 fprintf (stderr, "%s: unknown demangling style `%s'\n",  
                          program_name, optarg);  
                 return (1);  
               }  
             else  
               cplus_demangle_set_style (style);  
           }  
           break;  
         }  
     }  
   
   if (optind < argc)  
     {  
       for ( ; optind < argc; optind++)  
         {  
           demangle_it (argv[optind]);  
         }  
     }  
   else  
     {  
       switch (current_demangling_style)  
         {  
         case gnu_demangling:  
         case lucid_demangling:  
         case arm_demangling:  
         case java_demangling:  
         case edg_demangling:  
         case gnat_demangling:  
         case auto_demangling:  
           valid_symbols = standard_symbol_characters ();  
           break;  
         case hp_demangling:  
           valid_symbols = hp_symbol_characters ();  
           break;  
         case gnu_v3_demangling:  
           valid_symbols = gnu_v3_symbol_characters ();  
           break;  
         default:  
           /* Folks should explicitly indicate the appropriate alphabet for  
              each demangling.  Providing a default would allow the  
              question to go unconsidered.  */  
           abort ();  
         }  
   
       for (;;)  
         {  
           int i = 0;  
           c = getchar ();  
           /* Try to read a label.  */  
           while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c)))  
             {  
               if (i >= MBUF_SIZE-1)  
                 break;  
               mbuffer[i++] = c;  
               c = getchar ();  
             }  
           if (i > 0)  
             {  
               int skip_first = 0;  
   
               if (mbuffer[0] == '.')  
                 ++skip_first;  
               if (strip_underscore && mbuffer[skip_first] == '_')  
                 ++skip_first;  
   
               if (skip_first > i)  
                 skip_first = i;  
   
               mbuffer[i] = 0;  
               flags |= (int) style;  
               result = cplus_demangle (mbuffer + skip_first, flags);  
               if (result)  
                 {  
                   if (mbuffer[0] == '.')  
                     putc ('.', stdout);  
                   fputs (result, stdout);  
                   free (result);  
                 }  
               else  
                 fputs (mbuffer, stdout);  
   
               fflush (stdout);  
             }  
           if (c == EOF)  
             break;  
           putchar (c);  
           fflush (stdout);  
         }  
     }  
   
   return (0);  
 }  
   
 static void  
 fatal (str)  
      const char *str;  
 {  
   fprintf (stderr, "%s: %s\n", program_name, str);  
   exit (1);  
 }  
   
 PTR  
 xmalloc (size)  
   size_t size;  
 {  
   register PTR value = (PTR) malloc (size);  
   if (value == 0)  
     fatal ("virtual memory exhausted");  
   return value;  
 }  
   
 PTR  
 xrealloc (ptr, size)  
   PTR ptr;  
   size_t size;  
 {  
   register PTR value = (PTR) realloc (ptr, size);  
   if (value == 0)  
     fatal ("virtual memory exhausted");  
   return value;  
 }  
 #endif  /* main */  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26