Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/cplus-dem.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Demangler for GNU C++
    22   Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
    3    2000 Free Software Foundation, Inc.
     3   2000, 2001 Free Software Foundation, Inc.
    44   Written by James Clark (jjc@jclark.uucp)
    55   Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
     
    1111License as published by the Free Software Foundation; either
    1212version 2 of the License, or (at your option) any later version.
     13
     14In addition to the permissions in the GNU Library General Public
     15License, the Free Software Foundation gives you unlimited permission
     16to link the compiled version of this file into combinations with other
     17programs, and to distribute those combinations without any restriction
     18coming from the use of this file.  (The Library Public License
     19restrictions do apply in other respects; for example, they cover
     20modification of the file, and distribution when not linked into a
     21combined executable.)
    1322
    1423Libiberty is distributed in the hope that it will be useful,
     
    6372
    6473extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
    65 
    66 static const char *mystrstr PARAMS ((const char *, const char *));
    67 
    68 static const char *
    69 mystrstr (s1, s2)
    70      const char *s1, *s2;
    71 {
    72   register const char *p = s1;
    73   register int len = strlen (s2);
    74 
    75   for (; (p = strchr (p, *s2)) != 0; p++)
    76     {
    77       if (strncmp (p, s2, len) == 0)
    78         {
    79           return (p);
    80         }
    81     }
    82   return (0);
    83 }
    8474
    8575/* In order to allow a single demangler executable to demangle strings
     
    158148static const struct optable
    159149{
    160   const char *in;
    161   const char *out;
    162   int flags;
     150  const char *const in;
     151  const char *const out;
     152  const int flags;
    163153} optable[] = {
    164154  {"nw",          " new",       DMGL_ANSI},     /* new (1.92,    ansi) */
     
    257247} type_kind_t;
    258248
    259 struct demangler_engine libiberty_demanglers[] =
    260 {
     249const struct demangler_engine libiberty_demanglers[] =
     250{
     251  {
     252    NO_DEMANGLING_STYLE_STRING,
     253    no_demangling,
     254    "Demangling disabled"
     255  }
     256  ,
    261257  {
    262258    AUTO_DEMANGLING_STYLE_STRING,
     
    319315
    320316#define STRING_EMPTY(str)       ((str) -> b == (str) -> p)
    321 #define PREPEND_BLANK(str)      {if (!STRING_EMPTY(str)) \
    322     string_prepend(str, " ");}
    323317#define APPEND_BLANK(str)       {if (!STRING_EMPTY(str)) \
    324318    string_append(str, " ");}
     
    530524
    531525static void
    532 grow_vect PARAMS ((void **, size_t *, size_t, int));
     526grow_vect PARAMS ((char **, size_t *, size_t, int));
    533527
    534528/* Translate count to integer, consuming tokens in the process.
     
    568562      (*type)++;
    569563    }
     564
     565  if (count < 0)
     566    count = -1;
    570567
    571568  return (count);
     
    848845     enum demangling_styles style;
    849846{
    850   struct demangler_engine *demangler = libiberty_demanglers;
     847  const struct demangler_engine *demangler = libiberty_demanglers;
    851848
    852849  for (; demangler->demangling_style != unknown_demangling; ++demangler)
     
    866863     const char *name;
    867864{
    868   struct demangler_engine *demangler = libiberty_demanglers;
     865  const struct demangler_engine *demangler = libiberty_demanglers;
    869866
    870867  for (; demangler->demangling_style != unknown_demangling; ++demangler)
     
    878875
    879876   If MANGLED is a mangled function name produced by GNU C++, then
    880    a pointer to a malloced string giving a C++ representation
     877   a pointer to a @code{malloc}ed string giving a C++ representation
    881878   of the name will be returned; otherwise NULL will be returned.
    882879   It is the caller's responsibility to free the string which
     
    910907  char *ret;
    911908  struct work_stuff work[1];
     909
     910  if (current_demangling_style == no_demangling)
     911    return xstrdup (mangled);
     912
    912913  memset ((char *) work, 0, sizeof (work));
    913914  work->options = options;
     
    918919  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
    919920    {
    920       ret = cplus_demangle_v3 (mangled);
     921      ret = cplus_demangle_v3 (mangled, work->options);
    921922      if (ret || GNU_V3_DEMANGLING)
    922923        return ret;
     924    }
     925
     926  if (JAVA_DEMANGLING)
     927    {
     928      ret = java_demangle_v3 (mangled);
     929      if (ret)
     930        return ret;
    923931    }
    924932
     
    938946static void
    939947grow_vect (old_vect, size, min_size, element_size)
    940      void **old_vect;
     948     char **old_vect;
    941949     size_t *size;
    942950     size_t min_size;
     
    948956      if (*size < min_size)
    949957        *size = min_size;
    950       *old_vect = xrealloc (*old_vect, *size * element_size);
     958      *old_vect = (void *) xrealloc (*old_vect, *size * element_size);
    951959    }
    952960}
     
    971979  int at_start_name;
    972980  int changed;
    973   char *demangling_buffer = NULL;
    974   size_t demangling_buffer_size = 0;
     981  size_t demangled_size = 0;
    975982 
    976983  changed = 0;
     
    10001007 
    10011008  /* Make demangled big enough for possible expansion by operator name.  */
    1002   grow_vect ((void **) &(demangling_buffer),
    1003              &demangling_buffer_size,  2 * len0 + 1,
     1009  grow_vect (&demangled,
     1010             &demangled_size,  2 * len0 + 1,
    10041011             sizeof (char));
    1005   demangled = demangling_buffer;
    10061012 
    10071013  if (ISDIGIT ((unsigned char) mangled[len0 - 1])) {
     
    10531059 
    10541060 Suppress:
    1055   grow_vect ((void **) &(demangling_buffer),
    1056              &demangling_buffer_size,  strlen (mangled) + 3,
     1061  grow_vect (&demangled,
     1062             &demangled_size,  strlen (mangled) + 3,
    10571063             sizeof (char));
    1058   demangled = demangling_buffer;
     1064
    10591065  if (mangled[0] == '<')
    10601066     strcpy (demangled, mangled);
     
    10681074   to be able to demangle a name with a B, K or n code, we need to
    10691075   have a longer term memory of what types have been seen. The original
    1070    now intializes and cleans up the squangle code info, while internal
     1076   now initializes and cleans up the squangle code info, while internal
    10711077   calls go directly to this routine to avoid resetting that info. */
    10721078
     
    12081214  if (from->ntmpl_args)
    12091215    to->tmpl_argvec
    1210       = xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
     1216      = (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
    12111217
    12121218  for (i = 0; i < from->ntmpl_args; i++)
     
    14331439                string_append (&s, SCOPE_STRING (work));
    14341440                string_prepends (declp, &s);
     1441                string_delete (&s);
    14351442              }
    14361443            oldmangled = NULL;
     
    15121519              /* Read the return type. */
    15131520              string return_type;
    1514               string_init (&return_type);
    15151521
    15161522              (*mangled)++;
     
    17871793      /* By default, we let the number decide whether we shall consume an
    17881794         underscore.  */
    1789       int consume_following_underscore = 0;
     1795      int multidigit_without_leading_underscore = 0;
    17901796      int leave_following_underscore = 0;
    17911797
    17921798      success = 0;
    17931799
    1794       /* Negative numbers are indicated with a leading `m'.  */
    1795       if (**mangled == 'm')
    1796         {
    1797           string_appendn (s, "-", 1);
    1798           (*mangled)++;
    1799         }
    1800       else if (mangled[0][0] == '_' && mangled[0][1] == 'm')
    1801         {
    1802           /* Since consume_count_with_underscores does not handle the
    1803              `m'-prefix we must do it here, using consume_count and
    1804              adjusting underscores: we have to consume the underscore
    1805              matching the prepended one.  */
    1806           consume_following_underscore = 1;
    1807           string_appendn (s, "-", 1);
    1808           (*mangled) += 2;
    1809         }
    1810       else if (**mangled == '_')
    1811         {
    1812           /* Do not consume a following underscore;
    1813              consume_following_underscore will consume what should be
    1814              consumed.  */
     1800      if (**mangled == '_')
     1801        {
     1802          if (mangled[0][1] == 'm')
     1803            {
     1804              /* Since consume_count_with_underscores does not handle the
     1805                 `m'-prefix we must do it here, using consume_count and
     1806                 adjusting underscores: we have to consume the underscore
     1807                 matching the prepended one.  */
     1808              multidigit_without_leading_underscore = 1;
     1809              string_appendn (s, "-", 1);
     1810              (*mangled) += 2;
     1811            }
     1812          else
     1813            {
     1814              /* 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
     1821        {
     1822          /* Negative numbers are indicated with a leading `m'.  */
     1823          if (**mangled == 'm')
     1824          {
     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. */
    18151835          leave_following_underscore = 1;
    18161836        }
     
    18201840         the leading underscore (that we consumed) if it is to handle
    18211841         multi-digit numbers.  */
    1822       if (consume_following_underscore)
     1842      if (multidigit_without_leading_underscore)
    18231843        value = consume_count (mangled);
    18241844      else
     
    18381858             underscore, we need to do something more radical.  */
    18391859
    1840           if ((value > 9 || consume_following_underscore)
     1860          if ((value > 9 || multidigit_without_leading_underscore)
    18411861              && ! leave_following_underscore
    18421862              && **mangled == '_')
     
    18461866          success = 1;
    18471867        }
    1848     }
     1868      }
    18491869
    18501870  return success;
     
    22342254  /* Check if ARM template with "__pt__" in it ("parameterized type") */
    22352255  /* Allow HP also here, because HP's cfront compiler follows ARM to some extent */
    2236   if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = mystrstr (mangled, "__pt__")))
     2256  if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = strstr (mangled, "__pt__")))
    22372257    {
    22382258      int len;
     
    22492269  if (AUTO_DEMANGLING || EDG_DEMANGLING)
    22502270    {
    2251       if ((*anchor = mystrstr (mangled, "__tm__"))
    2252           || (*anchor = mystrstr (mangled, "__ps__"))
    2253           || (*anchor = mystrstr (mangled, "__pt__")))
     2271      if ((*anchor = strstr (mangled, "__tm__"))
     2272          || (*anchor = strstr (mangled, "__ps__"))
     2273          || (*anchor = strstr (mangled, "__pt__")))
    22542274        {
    22552275          int len;
     
    22642284            }
    22652285        }
    2266       else if ((*anchor = mystrstr (mangled, "__S")))
     2286      else if ((*anchor = strstr (mangled, "__S")))
    22672287        {
    22682288          int len;
     
    23142334      while (1)
    23152335        {
    2316           string_clear (&arg);
     2336          string_delete (&arg);
    23172337          switch (**mangled)
    23182338            {
     
    23712391      /* should do error checking here */
    23722392      while (args < e) {
    2373         string_clear (&arg);
     2393        string_delete (&arg);
    23742394
    23752395        /* Check for type or literal here */
     
    23862406            string_append (&arg, "(");
    23872407            string_appends (&arg, &type_str);
     2408            string_delete (&type_str);
    23882409            string_append (&arg, ")");
    23892410            if (*args != 'L')
     
    24032424          default:
    24042425            /* Not handling other HP cfront stuff */
    2405             if (!do_type (work, &args, &arg))
    2406               goto cfront_template_args_done;
     2426            {
     2427              const char* old_args = args;
     2428              if (!do_type (work, &args, &arg))
     2429                goto cfront_template_args_done;
     2430
     2431              /* Fail if we didn't make any progress: prevent infinite loop. */
     2432              if (args == old_args)
     2433                return;
     2434            }
    24072435          }
    24082436        string_appends (declp, &arg);
     
    25652593     "__"-sequence.  This is the normal case.  */
    25662594  if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
    2567       || mystrstr (scan + 2, "__") == NULL)
     2595      || strstr (scan + 2, "__") == NULL)
    25682596    {
    25692597      demangle_function_name (work, mangled, declp, scan);
     
    27082736  /*  This block of code is a reduction in strength time optimization
    27092737      of:
    2710       scan = mystrstr (*mangled, "__"); */
     2738      scan = strstr (*mangled, "__"); */
    27112739
    27122740  {
     
    28002828              scan++;
    28012829            }
    2802           if ((scan = mystrstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
     2830          if ((scan = strstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
    28032831            {
    28042832              /* No separator (I.E. "__not_mangled"), or empty signature
     
    33363364          else
    33373365            {
     3366              string_delete (&last_name);
    33383367              success = do_type (work, mangled, &last_name);
    33393368              if (!success)
     
    34783507  const char *remembered_type;
    34793508  int type_quals;
    3480   string btype;
    34813509  type_kind_t tk = tk_none;
    34823510
    3483   string_init (&btype);
    34843511  string_init (&decl);
    34853512  string_init (result);
     
    35993626                do_type (work, mangled, &temp);
    36003627                string_prepends (&decl, &temp);
     3628                string_delete (&temp);
    36013629              }
    36023630            else if (**mangled == 't')
     
    36093637                  {
    36103638                    string_prependn (&decl, temp.b, temp.p - temp.b);
    3611                     string_clear (&temp);
     3639                    string_delete (&temp);
    36123640                  }
    36133641                else
     
    37893817  char buf[10];
    37903818  unsigned int dec = 0;
    3791   string btype;
    37923819  type_kind_t tk = tk_integral;
    3793 
    3794   string_init (&btype);
    37953820
    37963821  /* First pick off any type qualifiers.  There can be more than one.  */
     
    39653990    case 't':
    39663991      {
     3992        string btype;
     3993        string_init (&btype);
    39673994        success = demangle_template (work, mangled, &btype, 0, 1, 1);
    39683995        string_appends (result, &btype);
     3996        string_delete (&btype);
    39693997        break;
    39703998      }
     
    41684196     type vector when processing a repeated type.  */
    41694197  if (work->previous_argument)
    4170     string_clear (work->previous_argument);
     4198    string_delete (work->previous_argument);
    41714199  else
    4172     {
    4173       work->previous_argument = (string*) xmalloc (sizeof (string));
    4174       string_init (work->previous_argument);
    4175     }
     4200    work->previous_argument = (string*) xmalloc (sizeof (string));
    41764201
    41774202  if (!do_type (work, mangled, work->previous_argument))
     
    45374562  /* Restore the previous_argument field.  */
    45384563  if (work->previous_argument)
    4539     string_delete (work->previous_argument);
     4564    {
     4565      string_delete (work->previous_argument);
     4566      free ((char *) work->previous_argument);
     4567    }
    45404568  work->previous_argument = saved_previous_argument;
    45414569  --work->forgetting_types;
     
    48624890  string_append (s, buf);
    48634891}
    4864 
    4865 /* To generate a standalone demangler program for testing purposes,
    4866    just compile and link this file with -DMAIN and libiberty.a.  When
    4867    run, it demangles each command line arg, or each stdin string, and
    4868    prints the result on stdout.  */
    4869 
    4870 #ifdef MAIN
    4871 
    4872 #include "getopt.h"
    4873 
    4874 static const char *program_name;
    4875 static const char *program_version = VERSION;
    4876 static int flags = DMGL_PARAMS | DMGL_ANSI;
    4877 
    4878 static void demangle_it PARAMS ((char *));
    4879 static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN;
    4880 static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN;
    4881 static void print_demangler_list PARAMS ((FILE *));
    4882 
    4883 static void
    4884 demangle_it (mangled_name)
    4885      char *mangled_name;
    4886 {
    4887   char *result;
    4888 
    4889   result = cplus_demangle (mangled_name, flags);
    4890   if (result == NULL)
    4891     {
    4892       printf ("%s\n", mangled_name);
    4893     }
    4894   else
    4895     {
    4896       printf ("%s\n", result);
    4897       free (result);
    4898     }
    4899 }
    4900 
    4901 static void
    4902 print_demangler_list (stream)
    4903      FILE *stream;
    4904 {
    4905   struct demangler_engine *demangler;
    4906 
    4907   fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
    4908  
    4909   for (demangler = libiberty_demanglers + 1;
    4910        demangler->demangling_style != unknown_demangling;
    4911        ++demangler)
    4912     fprintf (stream, ",%s", demangler->demangling_style_name);
    4913 
    4914   fprintf (stream, "}");
    4915 }
    4916 
    4917 static void
    4918 usage (stream, status)
    4919      FILE *stream;
    4920      int status;
    4921 {
    4922   fprintf (stream, "\
    4923 Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
    4924            program_name);
    4925 
    4926   fprintf (stream, "\
    4927        [-s ");
    4928   print_demangler_list (stream);
    4929   fprintf (stream, "]\n");
    4930 
    4931   fprintf (stream, "\
    4932        [--format ");
    4933   print_demangler_list (stream);
    4934   fprintf (stream, "]\n");
    4935 
    4936   fprintf (stream, "\
    4937        [--help] [--version] [arg...]\n");
    4938   exit (status);
    4939 }
    4940 
    4941 #define MBUF_SIZE 32767
    4942 char mbuffer[MBUF_SIZE];
    4943 
    4944 /* Defined in the automatically-generated underscore.c.  */
    4945 extern int prepends_underscore;
    4946 
    4947 int strip_underscore = 0;
    4948 
    4949 static struct option long_options[] = {
    4950   {"strip-underscores", no_argument, 0, '_'},
    4951   {"format", required_argument, 0, 's'},
    4952   {"help", no_argument, 0, 'h'},
    4953   {"java", no_argument, 0, 'j'},
    4954   {"no-strip-underscores", no_argument, 0, 'n'},
    4955   {"version", no_argument, 0, 'v'},
    4956   {0, no_argument, 0, 0}
    4957 };
    4958 
    4959 /* More 'friendly' abort that prints the line and file.
    4960    config.h can #define abort fancy_abort if you like that sort of thing.  */
    4961 
    4962 void
    4963 fancy_abort ()
    4964 {
    4965   fatal ("Internal gcc abort.");
    4966 }
    4967 
    4968 
    4969 static const char *
    4970 standard_symbol_characters PARAMS ((void));
    4971 
    4972 static const char *
    4973 hp_symbol_characters PARAMS ((void));
    4974 
    4975 static const char *
    4976 gnu_v3_symbol_characters PARAMS ((void));
    4977 
    4978 /* Return the string of non-alnum characters that may occur
    4979    as a valid symbol component, in the standard assembler symbol
    4980    syntax.  */
    4981 
    4982 static const char *
    4983 standard_symbol_characters ()
    4984 {
    4985   return "_$.";
    4986 }
    4987 
    4988 
    4989 /* Return the string of non-alnum characters that may occur
    4990    as a valid symbol name component in an HP object file.
    4991 
    4992    Note that, since HP's compiler generates object code straight from
    4993    C++ source, without going through an assembler, its mangled
    4994    identifiers can use all sorts of characters that no assembler would
    4995    tolerate, so the alphabet this function creates is a little odd.
    4996    Here are some sample mangled identifiers offered by HP:
    4997 
    4998         typeid*__XT24AddressIndExpClassMember_
    4999         [Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv
    5000         __ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv
    5001 
    5002    This still seems really weird to me, since nowhere else in this
    5003    file is there anything to recognize curly brackets, parens, etc.
    5004    I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me
    5005    this is right, but I still strongly suspect that there's a
    5006    misunderstanding here.
    5007 
    5008    If we decide it's better for c++filt to use HP's assembler syntax
    5009    to scrape identifiers out of its input, here's the definition of
    5010    the symbol name syntax from the HP assembler manual:
    5011 
    5012        Symbols are composed of uppercase and lowercase letters, decimal
    5013        digits, dollar symbol, period (.), ampersand (&), pound sign(#) and
    5014        underscore (_). A symbol can begin with a letter, digit underscore or
    5015        dollar sign. If a symbol begins with a digit, it must contain a
    5016        non-digit character.
    5017 
    5018    So have fun.  */
    5019 static const char *
    5020 hp_symbol_characters ()
    5021 {
    5022   return "_$.<>#,*&[]:(){}";
    5023 }
    5024 
    5025 
    5026 /* Return the string of non-alnum characters that may occur
    5027    as a valid symbol component in the GNU C++ V3 ABI mangling
    5028    scheme.  */
    5029 
    5030 static const char *
    5031 gnu_v3_symbol_characters ()
    5032 {
    5033   return "_$.";
    5034 }
    5035 
    5036 
    5037 extern int main PARAMS ((int, char **));
    5038 
    5039 int
    5040 main (argc, argv)
    5041      int argc;
    5042      char **argv;
    5043 {
    5044   char *result;
    5045   int c;
    5046   const char *valid_symbols;
    5047 
    5048   program_name = argv[0];
    5049 
    5050   strip_underscore = prepends_underscore;
    5051 
    5052   while ((c = getopt_long (argc, argv, "_ns:j", long_options, (int *) 0)) != EOF)
    5053     {
    5054       switch (c)
    5055         {
    5056         case '?':
    5057           usage (stderr, 1);
    5058           break;
    5059         case 'h':
    5060           usage (stdout, 0);
    5061         case 'n':
    5062           strip_underscore = 0;
    5063           break;
    5064         case 'v':
    5065           printf ("GNU %s (C++ demangler), version %s\n", program_name, program_version);
    5066           return (0);
    5067         case '_':
    5068           strip_underscore = 1;
    5069           break;
    5070         case 'j':
    5071           flags |= DMGL_JAVA;
    5072           break;
    5073         case 's':
    5074           {
    5075             enum demangling_styles style;
    5076 
    5077             style = cplus_demangle_name_to_style (optarg);
    5078             if (style == unknown_demangling)
    5079               {
    5080                 fprintf (stderr, "%s: unknown demangling style `%s'\n",
    5081                          program_name, optarg);
    5082                 return (1);
    5083               }
    5084             else
    5085               cplus_demangle_set_style (style);
    5086           }
    5087           break;
    5088         }
    5089     }
    5090 
    5091   if (optind < argc)
    5092     {
    5093       for ( ; optind < argc; optind++)
    5094         {
    5095           demangle_it (argv[optind]);
    5096         }
    5097     }
    5098   else
    5099     {
    5100       switch (current_demangling_style)
    5101         {
    5102         case gnu_demangling:
    5103         case lucid_demangling:
    5104         case arm_demangling:
    5105         case java_demangling:
    5106         case edg_demangling:
    5107         case gnat_demangling:
    5108         case auto_demangling:
    5109           valid_symbols = standard_symbol_characters ();
    5110           break;
    5111         case hp_demangling:
    5112           valid_symbols = hp_symbol_characters ();
    5113           break;
    5114         case gnu_v3_demangling:
    5115           valid_symbols = gnu_v3_symbol_characters ();
    5116           break;
    5117         default:
    5118           /* Folks should explicitly indicate the appropriate alphabet for
    5119              each demangling.  Providing a default would allow the
    5120              question to go unconsidered.  */
    5121           abort ();
    5122         }
    5123 
    5124       for (;;)
    5125         {
    5126           int i = 0;
    5127           c = getchar ();
    5128           /* Try to read a label.  */
    5129           while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c)))
    5130             {
    5131               if (i >= MBUF_SIZE-1)
    5132                 break;
    5133               mbuffer[i++] = c;
    5134               c = getchar ();
    5135             }
    5136           if (i > 0)
    5137             {
    5138               int skip_first = 0;
    5139 
    5140               if (mbuffer[0] == '.')
    5141                 ++skip_first;
    5142               if (strip_underscore && mbuffer[skip_first] == '_')
    5143                 ++skip_first;
    5144 
    5145               if (skip_first > i)
    5146                 skip_first = i;
    5147 
    5148               mbuffer[i] = 0;
    5149 
    5150               result = cplus_demangle (mbuffer + skip_first, flags);
    5151               if (result)
    5152                 {
    5153                   if (mbuffer[0] == '.')
    5154                     putc ('.', stdout);
    5155                   fputs (result, stdout);
    5156                   free (result);
    5157                 }
    5158               else
    5159                 fputs (mbuffer, stdout);
    5160 
    5161               fflush (stdout);
    5162             }
    5163           if (c == EOF)
    5164             break;
    5165           putchar (c);
    5166           fflush (stdout);
    5167         }
    5168     }
    5169 
    5170   return (0);
    5171 }
    5172 
    5173 static void
    5174 fatal (str)
    5175      const char *str;
    5176 {
    5177   fprintf (stderr, "%s: %s\n", program_name, str);
    5178   exit (1);
    5179 }
    5180 
    5181 PTR
    5182 xmalloc (size)
    5183   size_t size;
    5184 {
    5185   register PTR value = (PTR) malloc (size);
    5186   if (value == 0)
    5187     fatal ("virtual memory exhausted");
    5188   return value;
    5189 }
    5190 
    5191 PTR
    5192 xrealloc (ptr, size)
    5193   PTR ptr;
    5194   size_t size;
    5195 {
    5196   register PTR value = (PTR) realloc (ptr, size);
    5197   if (value == 0)
    5198     fatal ("virtual memory exhausted");
    5199   return value;
    5200 }
    5201 #endif  /* main */
Note: See TracChangeset for help on using the changeset viewer.