00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include "config.h"
00028 #endif
00029 #include "ansidecl.h"
00030 #include <stdio.h>
00031 #include "libiberty.h"
00032 #include "demangle.h"
00033 #ifdef HAVE_STRING_H
00034 #include <string.h>
00035 #endif
00036 #if HAVE_STDLIB_H
00037 # include <stdlib.h>
00038 #endif
00039
00040 struct line
00041 {
00042 size_t alloced;
00043 char *data;
00044 };
00045
00046 static unsigned int lineno;
00047
00048
00049
00050 #define LINELEN 80
00051
00052 static void
00053 getline(buf)
00054 struct line *buf;
00055 {
00056 char *data = buf->data;
00057 size_t alloc = buf->alloced;
00058 size_t count = 0;
00059 int c;
00060
00061 if (data == 0)
00062 {
00063 data = xmalloc (LINELEN);
00064 alloc = LINELEN;
00065 }
00066
00067
00068 while ((c = getchar()) == '#')
00069 {
00070 while ((c = getchar()) != EOF && c != '\n');
00071 lineno++;
00072 }
00073
00074
00075
00076 while (c != EOF && c != '\n')
00077 {
00078 if (count + 1 >= alloc)
00079 {
00080 alloc *= 2;
00081 data = xrealloc (data, alloc);
00082 }
00083 data[count++] = c;
00084 c = getchar();
00085 }
00086 lineno++;
00087 data[count] = '\0';
00088
00089 buf->data = data;
00090 buf->alloced = alloc;
00091 }
00092
00093 static void
00094 fail (lineno, opts, in, out, exp)
00095 int lineno;
00096 const char *opts;
00097 const char *in;
00098 const char *out;
00099 const char *exp;
00100 {
00101 printf ("\
00102 FAIL at line %d, options %s:\n\
00103 in: %s\n\
00104 out: %s\n\
00105 exp: %s\n",
00106 lineno, opts, in, out != NULL ? out : "(null)", exp);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 int
00128 main(argc, argv)
00129 int argc;
00130 char **argv;
00131 {
00132 enum demangling_styles style = auto_demangling;
00133 int no_params;
00134 int is_v3_ctor;
00135 int is_v3_dtor;
00136 struct line format;
00137 struct line input;
00138 struct line expect;
00139 char *result;
00140 int failures = 0;
00141 int tests = 0;
00142
00143 if (argc > 1)
00144 {
00145 fprintf (stderr, "usage: %s < test-set\n", argv[0]);
00146 return 2;
00147 }
00148
00149 format.data = 0;
00150 input.data = 0;
00151 expect.data = 0;
00152
00153 for (;;)
00154 {
00155 getline (&format);
00156 if (feof (stdin))
00157 break;
00158
00159 getline (&input);
00160 getline (&expect);
00161
00162 tests++;
00163
00164 no_params = 0;
00165 is_v3_ctor = 0;
00166 is_v3_dtor = 0;
00167 if (format.data[0] == '\0')
00168 style = auto_demangling;
00169 else if (format.data[0] != '-')
00170 {
00171 style = cplus_demangle_name_to_style (format.data);
00172 if (style == unknown_demangling)
00173 {
00174 printf ("FAIL at line %d: unknown demangling style %s\n",
00175 lineno, format.data);
00176 failures++;
00177 continue;
00178 }
00179 }
00180 else
00181 {
00182 char *p;
00183 char *opt;
00184
00185 p = format.data;
00186 while (*p != '\0')
00187 {
00188 char c;
00189
00190 opt = p;
00191 p += strcspn (p, " \t=");
00192 c = *p;
00193 *p = '\0';
00194 if (strcmp (opt, "--format") == 0 && c == '=')
00195 {
00196 char *fstyle;
00197
00198 *p = c;
00199 ++p;
00200 fstyle = p;
00201 p += strcspn (p, " \t");
00202 c = *p;
00203 *p = '\0';
00204 style = cplus_demangle_name_to_style (fstyle);
00205 if (style == unknown_demangling)
00206 {
00207 printf ("FAIL at line %d: unknown demangling style %s\n",
00208 lineno, fstyle);
00209 failures++;
00210 continue;
00211 }
00212 }
00213 else if (strcmp (opt, "--no-params") == 0)
00214 no_params = 1;
00215 else if (strcmp (opt, "--is-v3-ctor") == 0)
00216 is_v3_ctor = 1;
00217 else if (strcmp (opt, "--is-v3-dtor") == 0)
00218 is_v3_dtor = 1;
00219 else
00220 {
00221 printf ("FAIL at line %d: unrecognized option %s\n",
00222 lineno, opt);
00223 failures++;
00224 continue;
00225 }
00226 *p = c;
00227 p += strspn (p, " \t");
00228 }
00229 }
00230
00231 if (is_v3_ctor || is_v3_dtor)
00232 {
00233 char buf[20];
00234
00235 if (is_v3_ctor)
00236 {
00237 enum gnu_v3_ctor_kinds kc;
00238
00239 kc = is_gnu_v3_mangled_ctor (input.data);
00240 sprintf (buf, "%d", (int) kc);
00241 }
00242 else
00243 {
00244 enum gnu_v3_dtor_kinds kd;
00245
00246 kd = is_gnu_v3_mangled_dtor (input.data);
00247 sprintf (buf, "%d", (int) kd);
00248 }
00249
00250 if (strcmp (buf, expect.data) != 0)
00251 {
00252 fail (lineno, format.data, input.data, buf, expect.data);
00253 failures++;
00254 }
00255
00256 continue;
00257 }
00258
00259 cplus_demangle_set_style (style);
00260
00261 result = cplus_demangle (input.data,
00262 DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES);
00263
00264 if (result
00265 ? strcmp (result, expect.data)
00266 : strcmp (input.data, expect.data))
00267 {
00268 fail (lineno, format.data, input.data, result, expect.data);
00269 failures++;
00270 }
00271 free (result);
00272
00273 if (no_params)
00274 {
00275 getline (&expect);
00276 result = cplus_demangle (input.data, DMGL_ANSI|DMGL_TYPES);
00277
00278 if (result
00279 ? strcmp (result, expect.data)
00280 : strcmp (input.data, expect.data))
00281 {
00282 fail (lineno, format.data, input.data, result, expect.data);
00283 failures++;
00284 }
00285 free (result);
00286 }
00287 }
00288
00289 free (format.data);
00290 free (input.data);
00291 free (expect.data);
00292
00293 printf ("%s: %d tests, %d failures\n", argv[0], tests, failures);
00294 return failures ? 1 : 0;
00295 }