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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include "libiberty.h"
42 static unsigned int lineno
;
44 /* Safely read a single line of arbitrary length from standard input. */
52 char *data
= buf
->data
;
53 size_t alloc
= buf
->alloced
;
59 data
= xmalloc (LINELEN
);
63 /* Skip comment lines. */
64 while ((c
= getchar()) == '#')
66 while ((c
= getchar()) != EOF
&& c
!= '\n');
70 /* c is the first character on the line, and it's not a comment
71 line: copy this line into the buffer and return. */
72 while (c
!= EOF
&& c
!= '\n')
74 if (count
+ 1 >= alloc
)
77 data
= xrealloc (data
, alloc
);
90 fail (lineno
, opts
, in
, out
, exp
)
98 FAIL at line %d, options %s:\n\
102 lineno
, opts
, in
, out
!= NULL
? out
: "(null)", exp
);
105 /* The tester operates on a data file consisting of groups of lines:
107 input to be demangled
111 --format=<name> Sets the demangling style.
112 --no-params There are two lines of expected output; the first
113 is with DMGL_PARAMS, the second is without it.
114 --is-v3-ctor Calls is_gnu_v3_mangled_ctor on input; expected
115 output is an integer representing ctor_kind.
116 --is-v3-dtor Likewise, but for dtors.
117 --ret-postfix Passes the DMGL_RET_POSTFIX option
119 For compatibility, just in case it matters, the options line may be
120 empty, to mean --format=auto. If it doesn't start with --, then it
121 may contain only a format name.
129 enum demangling_styles style
= auto_demangling
;
143 fprintf (stderr
, "usage: %s < test-set\n", argv
[0]);
166 if (format
.data
[0] == '\0')
167 style
= auto_demangling
;
168 else if (format
.data
[0] != '-')
170 style
= cplus_demangle_name_to_style (format
.data
);
171 if (style
== unknown_demangling
)
173 printf ("FAIL at line %d: unknown demangling style %s\n",
174 lineno
, format
.data
);
190 p
+= strcspn (p
, " \t=");
193 if (strcmp (opt
, "--format") == 0 && c
== '=')
200 p
+= strcspn (p
, " \t");
203 style
= cplus_demangle_name_to_style (fstyle
);
204 if (style
== unknown_demangling
)
206 printf ("FAIL at line %d: unknown demangling style %s\n",
212 else if (strcmp (opt
, "--no-params") == 0)
214 else if (strcmp (opt
, "--is-v3-ctor") == 0)
216 else if (strcmp (opt
, "--is-v3-dtor") == 0)
218 else if (strcmp (opt
, "--ret-postfix") == 0)
222 printf ("FAIL at line %d: unrecognized option %s\n",
228 p
+= strspn (p
, " \t");
232 if (is_v3_ctor
|| is_v3_dtor
)
238 enum gnu_v3_ctor_kinds kc
;
240 kc
= is_gnu_v3_mangled_ctor (input
.data
);
241 sprintf (buf
, "%d", (int) kc
);
245 enum gnu_v3_dtor_kinds kd
;
247 kd
= is_gnu_v3_mangled_dtor (input
.data
);
248 sprintf (buf
, "%d", (int) kd
);
251 if (strcmp (buf
, expect
.data
) != 0)
253 fail (lineno
, format
.data
, input
.data
, buf
, expect
.data
);
260 cplus_demangle_set_style (style
);
262 result
= cplus_demangle (input
.data
,
263 DMGL_PARAMS
|DMGL_ANSI
|DMGL_TYPES
264 |(ret_postfix
? DMGL_RET_POSTFIX
: 0));
267 ? strcmp (result
, expect
.data
)
268 : strcmp (input
.data
, expect
.data
))
270 fail (lineno
, format
.data
, input
.data
, result
, expect
.data
);
278 result
= cplus_demangle (input
.data
, DMGL_ANSI
|DMGL_TYPES
);
281 ? strcmp (result
, expect
.data
)
282 : strcmp (input
.data
, expect
.data
))
284 fail (lineno
, format
.data
, input
.data
, result
, expect
.data
);
295 printf ("%s: %d tests, %d failures\n", argv
[0], tests
, failures
);
296 return failures
? 1 : 0;