1 /* Demangler test program,
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 Written by Zack Weinberg <zack@codesourcery.com
5 This file is part of GNU libiberty.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "libiberty.h"
36 static unsigned int lineno;
38 /* Safely read a single line of arbitrary length from standard input. */
46 char *data = buf->data;
47 size_t alloc = buf->alloced;
53 data = xmalloc (LINELEN);
57 /* Skip comment lines. */
58 while ((c = getchar()) == '#')
60 while ((c = getchar()) != EOF && c != '\n');
64 /* c is the first character on the line, and it's not a comment
65 line: copy this line into the buffer and return. */
66 while (c != EOF && c != '\n')
68 if (count + 1 >= alloc)
71 data = xrealloc (data, alloc);
84 fail (lineno, opts, in, out, exp)
92 FAIL at line %d, options %s:\n\
96 lineno, opts, in, out != NULL ? out : "(null)", exp);
99 /* The tester operates on a data file consisting of groups of lines:
101 input to be demangled
105 --format=<name> Sets the demangling style.
106 --no-params There are two lines of expected output; the first
107 is with DMGL_PARAMS, the second is without it.
108 --is-v3-ctor Calls is_gnu_v3_mangled_ctor on input; expected
109 output is an integer representing ctor_kind.
110 --is-v3-dtor Likewise, but for dtors.
112 For compatibility, just in case it matters, the options line may be
113 empty, to mean --format=auto. If it doesn't start with --, then it
114 may contain only a format name.
122 enum demangling_styles style;
135 fprintf (stderr, "usage: %s < test-set\n", argv[0]);
157 if (format.data[0] == '\0')
158 style = auto_demangling;
159 else if (format.data[0] != '-')
161 style = cplus_demangle_name_to_style (format.data);
162 if (style == unknown_demangling)
164 printf ("FAIL at line %d: unknown demangling style %s\n",
165 lineno, format.data);
181 p += strcspn (p, " \t=");
184 if (strcmp (opt, "--format") == 0 && c == '=')
191 p += strcspn (p, " \t");
194 style = cplus_demangle_name_to_style (fstyle);
195 if (style == unknown_demangling)
197 printf ("FAIL at line %d: unknown demangling style %s\n",
203 else if (strcmp (opt, "--no-params") == 0)
205 else if (strcmp (opt, "--is-v3-ctor") == 0)
207 else if (strcmp (opt, "--is-v3-dtor") == 0)
211 printf ("FAIL at line %d: unrecognized option %s\n",
217 p += strspn (p, " \t");
221 if (is_v3_ctor || is_v3_dtor)
227 enum gnu_v3_ctor_kinds kc;
229 kc = is_gnu_v3_mangled_ctor (input.data);
230 sprintf (buf, "%d", (int) kc);
234 enum gnu_v3_dtor_kinds kd;
236 kd = is_gnu_v3_mangled_dtor (input.data);
237 sprintf (buf, "%d", (int) kd);
240 if (strcmp (buf, expect.data) != 0)
242 fail (lineno, format.data, input.data, buf, expect.data);
249 cplus_demangle_set_style (style);
251 result = cplus_demangle (input.data,
252 DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES);
255 ? strcmp (result, expect.data)
256 : strcmp (input.data, expect.data))
258 fail (lineno, format.data, input.data, result, expect.data);
266 result = cplus_demangle (input.data, DMGL_ANSI|DMGL_TYPES);
269 ? strcmp (result, expect.data)
270 : strcmp (input.data, expect.data))
272 fail (lineno, format.data, input.data, result, expect.data);
283 printf ("%s: %d tests, %d failures\n", argv[0], tests, failures);
284 return failures ? 1 : 0;