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"
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.
118 For compatibility, just in case it matters, the options line may be
119 empty, to mean --format=auto. If it doesn't start with --, then it
120 may contain only a format name.
128 enum demangling_styles style
= auto_demangling
;
141 fprintf (stderr
, "usage: %s < test-set\n", argv
[0]);
163 if (format
.data
[0] == '\0')
164 style
= auto_demangling
;
165 else if (format
.data
[0] != '-')
167 style
= cplus_demangle_name_to_style (format
.data
);
168 if (style
== unknown_demangling
)
170 printf ("FAIL at line %d: unknown demangling style %s\n",
171 lineno
, format
.data
);
187 p
+= strcspn (p
, " \t=");
190 if (strcmp (opt
, "--format") == 0 && c
== '=')
197 p
+= strcspn (p
, " \t");
200 style
= cplus_demangle_name_to_style (fstyle
);
201 if (style
== unknown_demangling
)
203 printf ("FAIL at line %d: unknown demangling style %s\n",
209 else if (strcmp (opt
, "--no-params") == 0)
211 else if (strcmp (opt
, "--is-v3-ctor") == 0)
213 else if (strcmp (opt
, "--is-v3-dtor") == 0)
217 printf ("FAIL at line %d: unrecognized option %s\n",
223 p
+= strspn (p
, " \t");
227 if (is_v3_ctor
|| is_v3_dtor
)
233 enum gnu_v3_ctor_kinds kc
;
235 kc
= is_gnu_v3_mangled_ctor (input
.data
);
236 sprintf (buf
, "%d", (int) kc
);
240 enum gnu_v3_dtor_kinds kd
;
242 kd
= is_gnu_v3_mangled_dtor (input
.data
);
243 sprintf (buf
, "%d", (int) kd
);
246 if (strcmp (buf
, expect
.data
) != 0)
248 fail (lineno
, format
.data
, input
.data
, buf
, expect
.data
);
255 cplus_demangle_set_style (style
);
257 result
= cplus_demangle (input
.data
,
258 DMGL_PARAMS
|DMGL_ANSI
|DMGL_TYPES
);
261 ? strcmp (result
, expect
.data
)
262 : strcmp (input
.data
, expect
.data
))
264 fail (lineno
, format
.data
, input
.data
, result
, expect
.data
);
272 result
= cplus_demangle (input
.data
, DMGL_ANSI
|DMGL_TYPES
);
275 ? strcmp (result
, expect
.data
)
276 : strcmp (input
.data
, expect
.data
))
278 fail (lineno
, format
.data
, input
.data
, result
, expect
.data
);
289 printf ("%s: %d tests, %d failures\n", argv
[0], tests
, failures
);
290 return failures
? 1 : 0;