Changeset 1391 for branches/GNU/src/gcc/libiberty/cplus-dem.c
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libiberty/cplus-dem.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 11 11 License as published by the Free Software Foundation; either 12 12 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.) 13 22 14 23 Libiberty is distributed in the hope that it will be useful, … … 306 315 307 316 #define STRING_EMPTY(str) ((str) -> b == (str) -> p) 308 #define PREPEND_BLANK(str) {if (!STRING_EMPTY(str)) \309 string_prepend(str, " ");}310 317 #define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ 311 318 string_append(str, " ");} … … 517 524 518 525 static void 519 grow_vect PARAMS (( void**, size_t *, size_t, int));526 grow_vect PARAMS ((char **, size_t *, size_t, int)); 520 527 521 528 /* Translate count to integer, consuming tokens in the process. … … 939 946 static void 940 947 grow_vect (old_vect, size, min_size, element_size) 941 void**old_vect;948 char **old_vect; 942 949 size_t *size; 943 950 size_t min_size; … … 949 956 if (*size < min_size) 950 957 *size = min_size; 951 *old_vect = xrealloc (*old_vect, *size * element_size);958 *old_vect = (void *) xrealloc (*old_vect, *size * element_size); 952 959 } 953 960 } … … 972 979 int at_start_name; 973 980 int changed; 974 char *demangling_buffer = NULL; 975 size_t demangling_buffer_size = 0; 981 size_t demangled_size = 0; 976 982 977 983 changed = 0; … … 1001 1007 1002 1008 /* Make demangled big enough for possible expansion by operator name. */ 1003 grow_vect ( (void **) &(demangling_buffer),1004 &demangl ing_buffer_size, 2 * len0 + 1,1009 grow_vect (&demangled, 1010 &demangled_size, 2 * len0 + 1, 1005 1011 sizeof (char)); 1006 demangled = demangling_buffer;1007 1012 1008 1013 if (ISDIGIT ((unsigned char) mangled[len0 - 1])) { … … 1054 1059 1055 1060 Suppress: 1056 grow_vect ( (void **) &(demangling_buffer),1057 &demangl ing_buffer_size, strlen (mangled) + 3,1061 grow_vect (&demangled, 1062 &demangled_size, strlen (mangled) + 3, 1058 1063 sizeof (char)); 1059 demangled = demangling_buffer; 1064 1060 1065 if (mangled[0] == '<') 1061 1066 strcpy (demangled, mangled); … … 1209 1214 if (from->ntmpl_args) 1210 1215 to->tmpl_argvec 1211 = xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));1216 = (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0])); 1212 1217 1213 1218 for (i = 0; i < from->ntmpl_args; i++) … … 4881 4886 string_append (s, buf); 4882 4887 } 4883 4884 /* To generate a standalone demangler program for testing purposes,4885 just compile and link this file with -DMAIN and libiberty.a. When4886 run, it demangles each command line arg, or each stdin string, and4887 prints the result on stdout. */4888 4889 #ifdef MAIN4890 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 void4903 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 else4915 {4916 printf ("%s\n", result);4917 free (result);4918 }4919 }4920 4921 static void4922 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 void4938 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 327674962 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 void4982 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 occur4998 as a valid symbol component, in the standard assembler symbol4999 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 occur5009 as a valid symbol name component in an HP object file.5010 5011 Note that, since HP's compiler generates object code straight from5012 C++ source, without going through an assembler, its mangled5013 identifiers can use all sorts of characters that no assembler would5014 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__32OrdinaryCompareIndExpClassMemberFv5019 __ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv5020 5021 This still seems really weird to me, since nowhere else in this5022 file is there anything to recognize curly brackets, parens, etc.5023 I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me5024 this is right, but I still strongly suspect that there's a5025 misunderstanding here.5026 5027 If we decide it's better for c++filt to use HP's assembler syntax5028 to scrape identifiers out of its input, here's the definition of5029 the symbol name syntax from the HP assembler manual:5030 5031 Symbols are composed of uppercase and lowercase letters, decimal5032 digits, dollar symbol, period (.), ampersand (&), pound sign(#) and5033 underscore (_). A symbol can begin with a letter, digit underscore or5034 dollar sign. If a symbol begins with a digit, it must contain a5035 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 occur5046 as a valid symbol component in the GNU C++ V3 ABI mangling5047 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 int5059 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 else5100 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 else5114 {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 for5134 each demangling. Providing a default would allow the5135 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 else5174 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 void5189 fatal (str)5190 const char *str;5191 {5192 fprintf (stderr, "%s: %s\n", program_name, str);5193 exit (1);5194 }5195 5196 PTR5197 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 PTR5207 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 */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.