Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (21 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28dir.info
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libiberty/cplus-dem.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    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,
     
    306315
    307316#define STRING_EMPTY(str)       ((str) -> b == (str) -> p)
    308 #define PREPEND_BLANK(str)      {if (!STRING_EMPTY(str)) \
    309     string_prepend(str, " ");}
    310317#define APPEND_BLANK(str)       {if (!STRING_EMPTY(str)) \
    311318    string_append(str, " ");}
     
    517524
    518525static void
    519 grow_vect PARAMS ((void **, size_t *, size_t, int));
     526grow_vect PARAMS ((char **, size_t *, size_t, int));
    520527
    521528/* Translate count to integer, consuming tokens in the process.
     
    939946static void
    940947grow_vect (old_vect, size, min_size, element_size)
    941      void **old_vect;
     948     char **old_vect;
    942949     size_t *size;
    943950     size_t min_size;
     
    949956      if (*size < min_size)
    950957        *size = min_size;
    951       *old_vect = xrealloc (*old_vect, *size * element_size);
     958      *old_vect = (void *) xrealloc (*old_vect, *size * element_size);
    952959    }
    953960}
     
    972979  int at_start_name;
    973980  int changed;
    974   char *demangling_buffer = NULL;
    975   size_t demangling_buffer_size = 0;
     981  size_t demangled_size = 0;
    976982 
    977983  changed = 0;
     
    10011007 
    10021008  /* Make demangled big enough for possible expansion by operator name.  */
    1003   grow_vect ((void **) &(demangling_buffer),
    1004              &demangling_buffer_size,  2 * len0 + 1,
     1009  grow_vect (&demangled,
     1010             &demangled_size,  2 * len0 + 1,
    10051011             sizeof (char));
    1006   demangled = demangling_buffer;
    10071012 
    10081013  if (ISDIGIT ((unsigned char) mangled[len0 - 1])) {
     
    10541059 
    10551060 Suppress:
    1056   grow_vect ((void **) &(demangling_buffer),
    1057              &demangling_buffer_size,  strlen (mangled) + 3,
     1061  grow_vect (&demangled,
     1062             &demangled_size,  strlen (mangled) + 3,
    10581063             sizeof (char));
    1059   demangled = demangling_buffer;
     1064
    10601065  if (mangled[0] == '<')
    10611066     strcpy (demangled, mangled);
     
    12091214  if (from->ntmpl_args)
    12101215    to->tmpl_argvec
    1211       = xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
     1216      = (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
    12121217
    12131218  for (i = 0; i < from->ntmpl_args; i++)
     
    48814886  string_append (s, buf);
    48824887}
    4883 
    4884 /* To generate a standalone demangler program for testing purposes,
    4885    just compile and link this file with -DMAIN and libiberty.a.  When
    4886    run, it demangles each command line arg, or each stdin string, and
    4887    prints the result on stdout.  */
    4888 
    4889 #ifdef MAIN
    4890 
    4891 #include "getopt.h"
    4892 
    4893 static const char *program_name;
    4894 static const char *program_version = VERSION;
    4895 static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE;
    4896 
    4897 static void demangle_it PARAMS ((char *));
    4898 static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN;
    4899 static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN;
    4900 static void print_demangler_list PARAMS ((FILE *));
    4901 
    4902 static void
    4903 demangle_it (mangled_name)
    4904      char *mangled_name;
    4905 {
    4906   char *result;
    4907 
    4908   /* For command line args, also try to demangle type encodings.  */
    4909   result = cplus_demangle (mangled_name, flags | DMGL_TYPES);
    4910   if (result == NULL)
    4911     {
    4912       printf ("%s\n", mangled_name);
    4913     }
    4914   else
    4915     {
    4916       printf ("%s\n", result);
    4917       free (result);
    4918     }
    4919 }
    4920 
    4921 static void
    4922 print_demangler_list (stream)
    4923      FILE *stream;
    4924 {
    4925   const struct demangler_engine *demangler;
    4926 
    4927   fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
    4928  
    4929   for (demangler = libiberty_demanglers + 1;
    4930        demangler->demangling_style != unknown_demangling;
    4931        ++demangler)
    4932     fprintf (stream, ",%s", demangler->demangling_style_name);
    4933 
    4934   fprintf (stream, "}");
    4935 }
    4936 
    4937 static void
    4938 usage (stream, status)
    4939      FILE *stream;
    4940      int status;
    4941 {
    4942   fprintf (stream, "\
    4943 Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
    4944            program_name);
    4945 
    4946   fprintf (stream, "\
    4947        [-s ");
    4948   print_demangler_list (stream);
    4949   fprintf (stream, "]\n");
    4950 
    4951   fprintf (stream, "\
    4952        [--format ");
    4953   print_demangler_list (stream);
    4954   fprintf (stream, "]\n");
    4955 
    4956   fprintf (stream, "\
    4957        [--help] [--version] [arg...]\n");
    4958   exit (status);
    4959 }
    4960 
    4961 #define MBUF_SIZE 32767
    4962 char mbuffer[MBUF_SIZE];
    4963 
    4964 /* Defined in the automatically-generated underscore.c.  */
    4965 extern int prepends_underscore;
    4966 
    4967 int strip_underscore = 0;
    4968 
    4969 static const struct option long_options[] = {
    4970   {"strip-underscores", no_argument, 0, '_'},
    4971   {"format", required_argument, 0, 's'},
    4972   {"help", no_argument, 0, 'h'},
    4973   {"no-strip-underscores", no_argument, 0, 'n'},
    4974   {"version", no_argument, 0, 'v'},
    4975   {0, no_argument, 0, 0}
    4976 };
    4977 
    4978 /* More 'friendly' abort that prints the line and file.
    4979    config.h can #define abort fancy_abort if you like that sort of thing.  */
    4980 
    4981 void
    4982 fancy_abort ()
    4983 {
    4984   fatal ("Internal gcc abort.");
    4985 }
    4986 
    4987 
    4988 static const char *
    4989 standard_symbol_characters PARAMS ((void));
    4990 
    4991 static const char *
    4992 hp_symbol_characters PARAMS ((void));
    4993 
    4994 static const char *
    4995 gnu_v3_symbol_characters PARAMS ((void));
    4996 
    4997 /* Return the string of non-alnum characters that may occur
    4998    as a valid symbol component, in the standard assembler symbol
    4999    syntax.  */
    5000 
    5001 static const char *
    5002 standard_symbol_characters ()
    5003 {
    5004   return "_$.";
    5005 }
    5006 
    5007 
    5008 /* Return the string of non-alnum characters that may occur
    5009    as a valid symbol name component in an HP object file.
    5010 
    5011    Note that, since HP's compiler generates object code straight from
    5012    C++ source, without going through an assembler, its mangled
    5013    identifiers can use all sorts of characters that no assembler would
    5014    tolerate, so the alphabet this function creates is a little odd.
    5015    Here are some sample mangled identifiers offered by HP:
    5016 
    5017         typeid*__XT24AddressIndExpClassMember_
    5018         [Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv
    5019         __ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv
    5020 
    5021    This still seems really weird to me, since nowhere else in this
    5022    file is there anything to recognize curly brackets, parens, etc.
    5023    I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me
    5024    this is right, but I still strongly suspect that there's a
    5025    misunderstanding here.
    5026 
    5027    If we decide it's better for c++filt to use HP's assembler syntax
    5028    to scrape identifiers out of its input, here's the definition of
    5029    the symbol name syntax from the HP assembler manual:
    5030 
    5031        Symbols are composed of uppercase and lowercase letters, decimal
    5032        digits, dollar symbol, period (.), ampersand (&), pound sign(#) and
    5033        underscore (_). A symbol can begin with a letter, digit underscore or
    5034        dollar sign. If a symbol begins with a digit, it must contain a
    5035        non-digit character.
    5036 
    5037    So have fun.  */
    5038 static const char *
    5039 hp_symbol_characters ()
    5040 {
    5041   return "_$.<>#,*&[]:(){}";
    5042 }
    5043 
    5044 
    5045 /* Return the string of non-alnum characters that may occur
    5046    as a valid symbol component in the GNU C++ V3 ABI mangling
    5047    scheme.  */
    5048 
    5049 static const char *
    5050 gnu_v3_symbol_characters ()
    5051 {
    5052   return "_$.";
    5053 }
    5054 
    5055 
    5056 extern int main PARAMS ((int, char **));
    5057 
    5058 int
    5059 main (argc, argv)
    5060      int argc;
    5061      char **argv;
    5062 {
    5063   char *result;
    5064   int c;
    5065   const char *valid_symbols;
    5066   enum demangling_styles style = auto_demangling;
    5067 
    5068   program_name = argv[0];
    5069 
    5070   strip_underscore = prepends_underscore;
    5071 
    5072   while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF)
    5073     {
    5074       switch (c)
    5075         {
    5076         case '?':
    5077           usage (stderr, 1);
    5078           break;
    5079         case 'h':
    5080           usage (stdout, 0);
    5081         case 'n':
    5082           strip_underscore = 0;
    5083           break;
    5084         case 'v':
    5085           printf ("GNU %s (C++ demangler), version %s\n", program_name, program_version);
    5086           return (0);
    5087         case '_':
    5088           strip_underscore = 1;
    5089           break;
    5090         case 's':
    5091           {
    5092             style = cplus_demangle_name_to_style (optarg);
    5093             if (style == unknown_demangling)
    5094               {
    5095                 fprintf (stderr, "%s: unknown demangling style `%s'\n",
    5096                          program_name, optarg);
    5097                 return (1);
    5098               }
    5099             else
    5100               cplus_demangle_set_style (style);
    5101           }
    5102           break;
    5103         }
    5104     }
    5105 
    5106   if (optind < argc)
    5107     {
    5108       for ( ; optind < argc; optind++)
    5109         {
    5110           demangle_it (argv[optind]);
    5111         }
    5112     }
    5113   else
    5114     {
    5115       switch (current_demangling_style)
    5116         {
    5117         case gnu_demangling:
    5118         case lucid_demangling:
    5119         case arm_demangling:
    5120         case java_demangling:
    5121         case edg_demangling:
    5122         case gnat_demangling:
    5123         case auto_demangling:
    5124           valid_symbols = standard_symbol_characters ();
    5125           break;
    5126         case hp_demangling:
    5127           valid_symbols = hp_symbol_characters ();
    5128           break;
    5129         case gnu_v3_demangling:
    5130           valid_symbols = gnu_v3_symbol_characters ();
    5131           break;
    5132         default:
    5133           /* Folks should explicitly indicate the appropriate alphabet for
    5134              each demangling.  Providing a default would allow the
    5135              question to go unconsidered.  */
    5136           abort ();
    5137         }
    5138 
    5139       for (;;)
    5140         {
    5141           int i = 0;
    5142           c = getchar ();
    5143           /* Try to read a label.  */
    5144           while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c)))
    5145             {
    5146               if (i >= MBUF_SIZE-1)
    5147                 break;
    5148               mbuffer[i++] = c;
    5149               c = getchar ();
    5150             }
    5151           if (i > 0)
    5152             {
    5153               int skip_first = 0;
    5154 
    5155               if (mbuffer[0] == '.' || mbuffer[0] == '$')
    5156                 ++skip_first;
    5157               if (strip_underscore && mbuffer[skip_first] == '_')
    5158                 ++skip_first;
    5159 
    5160               if (skip_first > i)
    5161                 skip_first = i;
    5162 
    5163               mbuffer[i] = 0;
    5164               flags |= (int) style;
    5165               result = cplus_demangle (mbuffer + skip_first, flags);
    5166               if (result)
    5167                 {
    5168                   if (mbuffer[0] == '.')
    5169                     putc ('.', stdout);
    5170                   fputs (result, stdout);
    5171                   free (result);
    5172                 }
    5173               else
    5174                 fputs (mbuffer, stdout);
    5175 
    5176               fflush (stdout);
    5177             }
    5178           if (c == EOF)
    5179             break;
    5180           putchar (c);
    5181           fflush (stdout);
    5182         }
    5183     }
    5184 
    5185   return (0);
    5186 }
    5187 
    5188 static void
    5189 fatal (str)
    5190      const char *str;
    5191 {
    5192   fprintf (stderr, "%s: %s\n", program_name, str);
    5193   exit (1);
    5194 }
    5195 
    5196 PTR
    5197 xmalloc (size)
    5198   size_t size;
    5199 {
    5200   register PTR value = (PTR) malloc (size);
    5201   if (value == 0)
    5202     fatal ("virtual memory exhausted");
    5203   return value;
    5204 }
    5205 
    5206 PTR
    5207 xrealloc (ptr, size)
    5208   PTR ptr;
    5209   size_t size;
    5210 {
    5211   register PTR value = (PTR) realloc (ptr, size);
    5212   if (value == 0)
    5213     fatal ("virtual memory exhausted");
    5214   return value;
    5215 }
    5216 #endif  /* main */
Note: See TracChangeset for help on using the changeset viewer.