]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/error.c
toplev.c (rest_of_compilation): Rebuild label notes after post-reload splitting pass...
[gcc.git] / gcc / cp / error.c
CommitLineData
8d08fdba
MS
1/* Call-backs for C++ error reporting.
2 This code is non-reentrant.
d6a8bdff 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
158991b7 4 Free Software Foundation, Inc.
8d08fdba
MS
5 This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
8d08fdba
MS
21
22#include "config.h"
8d052bc7 23#include "system.h"
8d08fdba
MS
24#include "tree.h"
25#include "cp-tree.h"
26#include "obstack.h"
54f92bfb 27#include "toplev.h"
8d08fdba 28
e1def31b 29typedef const char *cp_printer ();
8d08fdba 30
8d08fdba
MS
31#define obstack_chunk_alloc xmalloc
32#define obstack_chunk_free free
33
34/* Obstack where we build text strings for overloading, etc. */
35static struct obstack scratch_obstack;
36static char *scratch_firstobj;
37
38# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
39# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
40# define OB_PUTC2(C1,C2) \
41 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
42# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
43# define OB_PUTID(ID) \
44 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
45 IDENTIFIER_LENGTH (ID)))
46# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
47# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
71e89f27 48# define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
8d08fdba
MS
49 OB_PUTCP (digit_buffer); } while (0)
50
0aafb128 51# define OB_END_TEMPLATE_ID() \
9e93bc9d 52 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
0aafb128 53 && obstack_next_free (&scratch_obstack)[-1] == '>') \
9e93bc9d 54 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
0aafb128 55
8d08fdba
MS
56# define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
57
49c249e1
JM
58enum pad { none, before, after };
59
158991b7
KG
60static const char *args_to_string PARAMS ((tree, int));
61static const char *assop_to_string PARAMS ((enum tree_code, int));
62static const char *code_to_string PARAMS ((enum tree_code, int));
63static const char *cv_to_string PARAMS ((tree, int));
64static const char *decl_to_string PARAMS ((tree, int));
65static const char *expr_to_string PARAMS ((tree, int));
66static const char *fndecl_to_string PARAMS ((tree, int));
158991b7
KG
67static const char *op_to_string PARAMS ((enum tree_code, int));
68static const char *parm_to_string PARAMS ((int, int));
69static const char *type_to_string PARAMS ((tree, int));
9e93bc9d 70
158991b7
KG
71static void dump_type PARAMS ((tree, enum tree_string_flags));
72static void dump_simple_decl PARAMS ((tree, tree, enum tree_string_flags));
73static void dump_decl PARAMS ((tree, enum tree_string_flags));
74static void dump_template_decl PARAMS ((tree, enum tree_string_flags));
75static void dump_function_decl PARAMS ((tree, enum tree_string_flags));
76static void dump_expr PARAMS ((tree, enum tree_string_flags));
77static void dump_unary_op PARAMS ((const char *, tree, enum tree_string_flags));
78static void dump_binary_op PARAMS ((const char *, tree, enum tree_string_flags));
79static void dump_aggr_type PARAMS ((tree, enum tree_string_flags));
80static enum pad dump_type_prefix PARAMS ((tree, enum tree_string_flags));
81static void dump_type_suffix PARAMS ((tree, enum tree_string_flags));
82static void dump_function_name PARAMS ((tree, enum tree_string_flags));
83static void dump_expr_list PARAMS ((tree, enum tree_string_flags));
84static void dump_global_iord PARAMS ((tree));
85static enum pad dump_qualifiers PARAMS ((tree, enum pad));
86static void dump_char PARAMS ((int));
87static void dump_parameters PARAMS ((tree, enum tree_string_flags));
88static void dump_exception_spec PARAMS ((tree, enum tree_string_flags));
89static const char *aggr_variety PARAMS ((tree));
90static tree ident_fndecl PARAMS ((tree));
91static void dump_template_argument PARAMS ((tree, enum tree_string_flags));
92static void dump_template_argument_list PARAMS ((tree, enum tree_string_flags));
93static void dump_template_parameter PARAMS ((tree, enum tree_string_flags));
94static void dump_template_bindings PARAMS ((tree, tree));
95static void dump_scope PARAMS ((tree, enum tree_string_flags));
96static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
9e93bc9d
NS
97
98#define A args_to_string
99#define C code_to_string
100#define D decl_to_string
101#define E expr_to_string
102#define F fndecl_to_string
103#define L language_to_string
104#define O op_to_string
105#define P parm_to_string
106#define Q assop_to_string
107#define T type_to_string
108#define V cv_to_string
109
110#define o (cp_printer *) 0
111cp_printer * cp_printers[256] =
112{
113/*0 1 2 3 4 5 6 7 8 9 A B C D E F */
114 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
115 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
116 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
117 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
118 o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
119 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
120 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
121 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
122};
123#undef C
124#undef D
125#undef E
126#undef F
127#undef L
128#undef O
129#undef P
130#undef Q
131#undef T
132#undef V
133#undef o
8d08fdba
MS
134
135void
136init_error ()
137{
138 gcc_obstack_init (&scratch_obstack);
139 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
140}
141
9e93bc9d 142/* Dump a scope, if deemed necessary. */
bbcec105 143
9e93bc9d
NS
144static void
145dump_scope (scope, flags)
bbcec105 146 tree scope;
9e93bc9d 147 enum tree_string_flags flags;
bbcec105 148{
9e93bc9d
NS
149 if (scope == NULL_TREE)
150 return;
151
152 if (TREE_CODE (scope) == NAMESPACE_DECL)
153 {
154 if (scope != global_namespace)
155 {
156 dump_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
157 | TS_FUNC_NORETURN | TS_DECL_TYPE);
158 OB_PUTS ("::");
159 }
160 else if (flags & TS_PEDANTIC_NAME)
161 OB_PUTS ("::");
162 }
163 else if (AGGREGATE_TYPE_P (scope))
164 {
165 dump_type (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
166 | TS_FUNC_NORETURN | TS_DECL_TYPE);
167 OB_PUTS ("::");
168 }
169 else if ((flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE))
170 && TREE_CODE (scope) == FUNCTION_DECL)
171 {
172 dump_function_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
173 | TS_FUNC_NORETURN | TS_DECL_TYPE);
174 OB_PUTS ("::");
175 }
bbcec105
JM
176}
177
9e93bc9d
NS
178/* Dump type qualifiers, providing padding as requested. Return an
179 indication of whether we dumped something. */
180
181static enum pad
91063b51 182dump_qualifiers (t, p)
8d08fdba
MS
183 tree t;
184 enum pad p;
185{
9e93bc9d
NS
186 static const int masks[] =
187 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
188 static const char *const names[] =
189 {"const", "volatile", "__restrict"};
190 int ix;
191 int quals = TYPE_QUALS (t);
192 int do_after = p == after;
193
194 if (quals)
8d08fdba 195 {
9e93bc9d
NS
196 for (ix = 0; ix != 3; ix++)
197 if (masks[ix] & quals)
198 {
199 if (p == before)
200 OB_PUTC (' ');
201 p = before;
202 OB_PUTCP (names[ix]);
203 }
204 if (do_after)
205 OB_PUTC (' ');
8d08fdba 206 }
9e93bc9d
NS
207 else
208 p = none;
209 return p;
8d08fdba
MS
210}
211
212/* This must be large enough to hold any printed integer or floating-point
213 value. */
214static char digit_buffer[128];
215
612c671a 216/* Dump the template ARGument under control of FLAGS. */
5f77d6cc
GDR
217
218static void
612c671a
GDR
219dump_template_argument (arg, flags)
220 tree arg;
9e93bc9d 221 enum tree_string_flags flags;
5f77d6cc 222{
2f939d94 223 if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
612c671a 224 dump_type (arg, flags & ~TS_AGGR_TAGS);
5f77d6cc 225 else
612c671a 226 dump_expr (arg, (flags | TS_EXPR_PARENS) & ~TS_AGGR_TAGS);
5f77d6cc
GDR
227}
228
612c671a
GDR
229/* Dump a template-argument-list ARGS (always a TREE_VEC) under control
230 of FLAGS. */
231
232static void
233dump_template_argument_list (args, flags)
234 tree args;
235 enum tree_string_flags flags;
236{
237 int n = TREE_VEC_LENGTH (args);
238 int need_comma = 0;
239 int i;
240
241 for (i = 0; i< n; ++i)
242 {
243 if (need_comma)
244 OB_PUTS (", ");
245 dump_template_argument (TREE_VEC_ELT (args, i), flags);
246 need_comma = 1;
247 }
248}
249
250/* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
251
252static void
253dump_template_parameter (parm, flags)
254 tree parm;
255 enum tree_string_flags flags;
256{
257 tree p = TREE_VALUE (parm);
258 tree a = TREE_PURPOSE (parm);
259
260 if (TREE_CODE (p) == TYPE_DECL)
261 {
262 if (flags & TS_DECL_TYPE)
263 {
264 OB_PUTS ("class");
265 if (DECL_NAME (p))
266 {
267 OB_PUTC (' ');
268 OB_PUTID (DECL_NAME (p));
269 }
270 }
271 else if (DECL_NAME (p))
272 OB_PUTID (DECL_NAME (p));
273 else
274 OB_PUTS ("{template default argument error}");
275 }
276 else
277 dump_decl (p, flags | TS_DECL_TYPE);
278
279 if ((flags & TS_PARM_DEFAULTS) && a != NULL_TREE)
280 {
281 OB_PUTS (" = ");
282 if (TREE_CODE (a) == TYPE_DECL || TREE_CODE (a) == TEMPLATE_DECL)
283 dump_type (a, flags & ~TS_CHASE_TYPEDEFS);
284 else
285 dump_expr (a, flags | TS_EXPR_PARENS);
286 }
287}
288
289/* Dump, under control of FLAGS, a template-parameter-list binding.
290 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
291 TREE_VEC. */
292
293static void
b5ac18ea 294dump_template_bindings (parms, args)
612c671a 295 tree parms, args;
612c671a 296{
612c671a
GDR
297 int need_comma = 0;
298
299 while (parms)
300 {
301 tree p = TREE_VALUE (parms);
b5ac18ea
MM
302 int lvl = TMPL_PARMS_DEPTH (parms);
303 int arg_idx = 0;
612c671a
GDR
304 int i;
305
306 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
b5ac18ea 307 {
2bb5d995
JM
308 tree arg = NULL_TREE;
309
310 /* Don't crash if we had an invalid argument list. */
311 if (TMPL_ARGS_DEPTH (args) >= lvl)
312 {
313 tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
314 if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
315 arg = TREE_VEC_ELT (lvl_args, arg_idx);
316 }
b5ac18ea
MM
317
318 if (need_comma)
319 OB_PUTS (", ");
320 dump_template_parameter (TREE_VEC_ELT (p, i), TS_PLAIN);
321 OB_PUTS (" = ");
322 if (arg)
323 dump_template_argument (arg, TS_PLAIN);
324 else
325 OB_PUTS ("{missing}");
612c671a 326
b5ac18ea
MM
327 ++arg_idx;
328 need_comma = 1;
329 }
612c671a
GDR
330
331 parms = TREE_CHAIN (parms);
332 }
333}
334
9e93bc9d
NS
335/* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
336 controls the format. */
e92cc029 337
8d08fdba 338static void
9e93bc9d 339dump_type (t, flags)
8d08fdba 340 tree t;
9e93bc9d 341 enum tree_string_flags flags;
8d08fdba
MS
342{
343 if (t == NULL_TREE)
344 return;
345
346 if (TYPE_PTRMEMFUNC_P (t))
347 goto offset_type;
348
349 switch (TREE_CODE (t))
350 {
8d08fdba 351 case UNKNOWN_TYPE:
51c184be 352 OB_PUTS ("{unknown type}");
8d08fdba
MS
353 break;
354
dcd08efc
JM
355 case TREE_LIST:
356 /* A list of function parms. */
9e93bc9d 357 dump_parameters (t, flags);
dcd08efc
JM
358 break;
359
8d08fdba
MS
360 case IDENTIFIER_NODE:
361 OB_PUTID (t);
362 break;
363
364 case TREE_VEC:
9e93bc9d 365 dump_type (BINFO_TYPE (t), flags);
8d08fdba
MS
366 break;
367
368 case RECORD_TYPE:
369 case UNION_TYPE:
370 case ENUMERAL_TYPE:
9e93bc9d 371 dump_aggr_type (t, flags);
8d08fdba
MS
372 break;
373
374 case TYPE_DECL:
9e93bc9d
NS
375 if (flags & TS_CHASE_TYPEDEFS)
376 {
377 dump_type (DECL_ORIGINAL_TYPE (t)
378 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
379 break;
380 }
381 /* else fallthrough */
382
67c2a928 383 case TEMPLATE_DECL:
009425e1 384 case NAMESPACE_DECL:
9e93bc9d 385 dump_decl (t, flags & ~TS_DECL_TYPE);
8d08fdba 386 break;
9e93bc9d 387
37c46b43
MS
388 case COMPLEX_TYPE:
389 OB_PUTS ("complex ");
9e93bc9d 390 dump_type (TREE_TYPE (t), flags);
37c46b43
MS
391 break;
392
8d08fdba
MS
393 case INTEGER_TYPE:
394 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
395 OB_PUTS ("unsigned ");
396 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
397 OB_PUTS ("signed ");
398
399 /* fall through. */
400 case REAL_TYPE:
401 case VOID_TYPE:
2986ae00 402 case BOOLEAN_TYPE:
3df095e2
MM
403 {
404 tree type;
91063b51 405 dump_qualifiers (t, after);
9e93bc9d 406 type = flags & TS_CHASE_TYPEDEFS ? TYPE_MAIN_VARIANT (t) : t;
3df095e2
MM
407 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
408 OB_PUTID (TYPE_IDENTIFIER (type));
409 else
410 /* Types like intQI_type_node and friends have no names.
411 These don't come up in user error messages, but it's nice
412 to be able to print them from the debugger. */
413 OB_PUTS ("{anonymous}");
414 }
8d08fdba
MS
415 break;
416
73b0fce8 417 case TEMPLATE_TEMPLATE_PARM:
7ddedda4 418 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t))
73b0fce8
KL
419 {
420 /* For parameters inside template signature. */
421 if (TYPE_IDENTIFIER (t))
422 OB_PUTID (TYPE_IDENTIFIER (t));
423 else
612c671a 424 OB_PUTS ("{anonymous template template parameter}");
73b0fce8
KL
425 }
426 else
427 {
7ddedda4 428 tree args = TYPE_TI_ARGS (t);
73b0fce8
KL
429 OB_PUTID (TYPE_IDENTIFIER (t));
430 OB_PUTC ('<');
612c671a 431 dump_template_argument_list (args, flags);
0aafb128 432 OB_END_TEMPLATE_ID ();
73b0fce8
KL
433 }
434 break;
435
8d08fdba 436 case TEMPLATE_TYPE_PARM:
91063b51 437 dump_qualifiers (t, after);
ec255269
MS
438 if (TYPE_IDENTIFIER (t))
439 OB_PUTID (TYPE_IDENTIFIER (t));
440 else
612c671a 441 OB_PUTS ("{anonymous template type parameter}");
8d08fdba
MS
442 break;
443
8d08fdba
MS
444 /* This is not always necessary for pointers and such, but doing this
445 reduces code size. */
446 case ARRAY_TYPE:
447 case POINTER_TYPE:
448 case REFERENCE_TYPE:
449 case OFFSET_TYPE:
450 offset_type:
451 case FUNCTION_TYPE:
452 case METHOD_TYPE:
9e93bc9d
NS
453 {
454 dump_type_prefix (t, flags);
455 dump_type_suffix (t, flags);
8d08fdba 456 break;
9e93bc9d 457 }
5566b478
MS
458 case TYPENAME_TYPE:
459 OB_PUTS ("typename ");
4b054b80 460 dump_type (TYPE_CONTEXT (t), flags & ~TS_AGGR_TAGS);
5566b478 461 OB_PUTS ("::");
9e93bc9d 462 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
5566b478
MS
463 break;
464
b894fc05
JM
465 case TYPEOF_TYPE:
466 OB_PUTS ("__typeof (");
9e93bc9d 467 dump_expr (TYPE_FIELDS (t), flags & ~TS_EXPR_PARENS);
b894fc05
JM
468 OB_PUTC (')');
469 break;
470
8d08fdba 471 default:
51c184be
MS
472 sorry ("`%s' not supported by dump_type",
473 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
474 /* Fall through to error. */
475
476 case ERROR_MARK:
612c671a 477 OB_PUTS ("{type error}");
9e93bc9d 478 break;
8d08fdba
MS
479 }
480}
481
9e93bc9d
NS
482/* Return the name of the supplied aggregate, or enumeral type. */
483
9c0758dd 484static const char *
51c184be 485aggr_variety (t)
8d08fdba 486 tree t;
8d08fdba 487{
8d08fdba 488 if (TREE_CODE (t) == ENUMERAL_TYPE)
51c184be 489 return "enum";
8d08fdba 490 else if (TREE_CODE (t) == UNION_TYPE)
51c184be 491 return "union";
8d08fdba 492 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
51c184be 493 return "class";
8d08fdba 494 else
51c184be
MS
495 return "struct";
496}
497
9e93bc9d
NS
498/* Print out a class declaration T under the control of FLAGS,
499 in the form `class foo'. */
e92cc029 500
51c184be 501static void
9e93bc9d 502dump_aggr_type (t, flags)
51c184be 503 tree t;
9e93bc9d 504 enum tree_string_flags flags;
51c184be
MS
505{
506 tree name;
9c0758dd 507 const char *variety = aggr_variety (t);
9e93bc9d
NS
508 int typdef = 0;
509 int tmplate = 0;
8d08fdba 510
91063b51 511 dump_qualifiers (t, after);
8d08fdba 512
9e93bc9d 513 if (flags & TS_AGGR_TAGS)
8d08fdba
MS
514 {
515 OB_PUTCP (variety);
516 OB_PUTC (' ');
517 }
518
9e93bc9d
NS
519 if (flags & TS_CHASE_TYPEDEFS)
520 t = TYPE_MAIN_VARIANT (t);
8d08fdba 521
9e93bc9d
NS
522 name = TYPE_NAME (t);
523
524 if (name)
8d08fdba 525 {
9e93bc9d
NS
526 typdef = !DECL_ARTIFICIAL (name);
527 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
528 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
370af2d5 529 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
9e93bc9d
NS
530 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
531 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
532 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
533 dump_scope (CP_DECL_CONTEXT (name), flags | TS_FUNC_SCOPE);
534 if (tmplate)
535 {
536 /* Because the template names are mangled, we have to locate
537 the most general template, and use that name. */
538 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
539
540 while (DECL_TEMPLATE_INFO (tpl))
541 tpl = DECL_TI_TEMPLATE (tpl);
542 name = tpl;
543 }
544 name = DECL_NAME (name);
8d08fdba
MS
545 }
546
f30432d7 547 if (name == 0 || ANON_AGGRNAME_P (name))
8d08fdba 548 {
51c184be 549 OB_PUTS ("{anonymous");
9e93bc9d 550 if (!(flags & TS_AGGR_TAGS))
8d08fdba
MS
551 {
552 OB_PUTC (' ');
553 OB_PUTCP (variety);
554 }
51c184be 555 OB_PUTC ('}');
8d08fdba
MS
556 }
557 else
558 OB_PUTID (name);
9e93bc9d
NS
559 if (tmplate)
560 dump_template_parms (TYPE_TEMPLATE_INFO (t),
561 !CLASSTYPE_USE_TEMPLATE (t),
562 flags & ~TS_TEMPLATE_PREFIX);
8d08fdba
MS
563}
564
565/* Dump into the obstack the initial part of the output for a given type.
566 This is necessary when dealing with things like functions returning
567 functions. Examples:
568
569 return type of `int (* fee ())()': pointer -> function -> int. Both
570 pointer (and reference and offset) and function (and member) types must
571 deal with prefix and suffix.
572
573 Arrays must also do this for DECL nodes, like int a[], and for things like
9e93bc9d
NS
574 int *[]&.
575
576 Return indicates how you should pad an object name after this. I.e. you
577 want to pad non-*, non-& cores, but not pad * or & types. */
8d08fdba 578
9e93bc9d
NS
579static enum pad
580dump_type_prefix (t, flags)
8d08fdba 581 tree t;
9e93bc9d 582 enum tree_string_flags flags;
8d08fdba 583{
9e93bc9d
NS
584 enum pad padding = before;
585
8d08fdba
MS
586 if (TYPE_PTRMEMFUNC_P (t))
587 {
588 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
589 goto offset_type;
590 }
591
592 switch (TREE_CODE (t))
593 {
594 case POINTER_TYPE:
91063b51 595 case REFERENCE_TYPE:
8d08fdba
MS
596 {
597 tree sub = TREE_TYPE (t);
598
9e93bc9d 599 padding = dump_type_prefix (sub, flags);
8d08fdba
MS
600 /* A tree for a member pointer looks like pointer to offset,
601 so let the OFFSET_TYPE case handle it. */
91063b51 602 if (!TYPE_PTRMEM_P (t))
8d08fdba 603 {
9e93bc9d
NS
604 if (padding != none)
605 OB_PUTC (' ');
606 if (TREE_CODE (sub) == ARRAY_TYPE)
607 OB_PUTC ('(');
608 OB_PUTC ("&*"[TREE_CODE (t) == POINTER_TYPE]);
609 padding = dump_qualifiers (t, none);
8d08fdba
MS
610 }
611 }
8d08fdba
MS
612 break;
613
614 case OFFSET_TYPE:
615 offset_type:
9e93bc9d 616 padding = dump_type_prefix (TREE_TYPE (t), flags);
51c184be
MS
617 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
618 {
9e93bc9d
NS
619 if (padding != none)
620 OB_PUTC (' ');
621 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
622 OB_PUTS ("::");
51c184be 623 }
8d08fdba 624 OB_PUTC ('*');
9e93bc9d 625 padding = dump_qualifiers (t, none);
8d08fdba
MS
626 break;
627
628 /* Can only be reached through function pointer -- this would not be
629 correct if FUNCTION_DECLs used it. */
630 case FUNCTION_TYPE:
9e93bc9d
NS
631 padding = dump_type_prefix (TREE_TYPE (t), flags);
632 if (padding != none)
633 OB_PUTC (' ');
634 OB_PUTC ('(');
635 padding = none;
8d08fdba
MS
636 break;
637
638 case METHOD_TYPE:
9e93bc9d
NS
639 padding = dump_type_prefix (TREE_TYPE (t), flags);
640 if (padding != none)
641 OB_PUTC (' ');
642 OB_PUTC ('(');
643 padding = none;
644 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
645 OB_PUTS ("::");
8d08fdba
MS
646 break;
647
648 case ARRAY_TYPE:
9e93bc9d 649 padding = dump_type_prefix (TREE_TYPE (t), flags);
8d08fdba
MS
650 break;
651
652 case ENUMERAL_TYPE:
8d08fdba
MS
653 case IDENTIFIER_NODE:
654 case INTEGER_TYPE:
2986ae00 655 case BOOLEAN_TYPE:
8d08fdba
MS
656 case REAL_TYPE:
657 case RECORD_TYPE:
658 case TEMPLATE_TYPE_PARM:
73b0fce8 659 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
660 case TREE_LIST:
661 case TYPE_DECL:
662 case TREE_VEC:
8d08fdba
MS
663 case UNION_TYPE:
664 case UNKNOWN_TYPE:
665 case VOID_TYPE:
5566b478 666 case TYPENAME_TYPE:
37c46b43 667 case COMPLEX_TYPE:
9e93bc9d
NS
668 dump_type (t, flags);
669 padding = before;
8d08fdba
MS
670 break;
671
672 default:
51c184be
MS
673 sorry ("`%s' not supported by dump_type_prefix",
674 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
675
676 case ERROR_MARK:
677 OB_PUTS ("{typeprefixerror}");
678 break;
8d08fdba 679 }
9e93bc9d 680 return padding;
8d08fdba
MS
681}
682
9e93bc9d
NS
683/* Dump the suffix of type T, under control of FLAGS. This is the part
684 which appears after the identifier (or function parms). */
685
8d08fdba 686static void
9e93bc9d 687dump_type_suffix (t, flags)
8d08fdba 688 tree t;
9e93bc9d 689 enum tree_string_flags flags;
8d08fdba
MS
690{
691 if (TYPE_PTRMEMFUNC_P (t))
692 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
693
694 switch (TREE_CODE (t))
695 {
696 case POINTER_TYPE:
697 case REFERENCE_TYPE:
698 case OFFSET_TYPE:
39211cd5
MS
699 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
700 OB_PUTC (')');
9e93bc9d 701 dump_type_suffix (TREE_TYPE (t), flags);
8d08fdba
MS
702 break;
703
704 /* Can only be reached through function pointer */
705 case FUNCTION_TYPE:
706 case METHOD_TYPE:
707 {
708 tree arg;
4995028c 709 OB_PUTC (')');
8d08fdba
MS
710 arg = TYPE_ARG_TYPES (t);
711 if (TREE_CODE (t) == METHOD_TYPE)
712 arg = TREE_CHAIN (arg);
713
4995028c
NS
714 /* Function pointers don't have default args. Not in standard C++,
715 anyway; they may in g++, but we'll just pretend otherwise. */
9e93bc9d 716 dump_parameters (arg, flags & ~TS_PARM_DEFAULTS);
4995028c 717
8d08fdba 718 if (TREE_CODE (t) == METHOD_TYPE)
91063b51 719 dump_qualifiers
8d08fdba 720 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
9e93bc9d
NS
721 dump_type_suffix (TREE_TYPE (t), flags);
722 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
8d08fdba
MS
723 break;
724 }
725
726 case ARRAY_TYPE:
727 OB_PUTC ('[');
728 if (TYPE_DOMAIN (t))
5156628f 729 {
665f2503
RK
730 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
731 OB_PUTI (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
5156628f 732 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
9e93bc9d
NS
733 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
734 flags & ~TS_EXPR_PARENS);
5156628f 735 else
ab76ca54 736 dump_expr (fold (cp_build_binary_op
5156628f 737 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
9e93bc9d
NS
738 integer_one_node)),
739 flags & ~TS_EXPR_PARENS);
5156628f 740 }
8d08fdba 741 OB_PUTC (']');
9e93bc9d 742 dump_type_suffix (TREE_TYPE (t), flags);
8d08fdba
MS
743 break;
744
745 case ENUMERAL_TYPE:
8d08fdba
MS
746 case IDENTIFIER_NODE:
747 case INTEGER_TYPE:
2986ae00 748 case BOOLEAN_TYPE:
8d08fdba
MS
749 case REAL_TYPE:
750 case RECORD_TYPE:
751 case TEMPLATE_TYPE_PARM:
73b0fce8 752 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
753 case TREE_LIST:
754 case TYPE_DECL:
755 case TREE_VEC:
8d08fdba
MS
756 case UNION_TYPE:
757 case UNKNOWN_TYPE:
758 case VOID_TYPE:
5566b478 759 case TYPENAME_TYPE:
37c46b43 760 case COMPLEX_TYPE:
8d08fdba
MS
761 break;
762
763 default:
51c184be
MS
764 sorry ("`%s' not supported by dump_type_suffix",
765 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
766
767 case ERROR_MARK:
768 /* Don't mark it here, we should have already done in
769 dump_type_prefix. */
770 break;
8d08fdba
MS
771 }
772}
773
774/* Return a function declaration which corresponds to the IDENTIFIER_NODE
775 argument. */
e92cc029 776
49c249e1 777static tree
8d08fdba
MS
778ident_fndecl (t)
779 tree t;
780{
700f8a87 781 tree n = lookup_name (t, 0);
8d08fdba 782
f30432d7
MS
783 if (n == NULL_TREE)
784 return NULL_TREE;
785
8d08fdba
MS
786 if (TREE_CODE (n) == FUNCTION_DECL)
787 return n;
788 else if (TREE_CODE (n) == TREE_LIST
789 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
790 return TREE_VALUE (n);
8926095f
MS
791
792 my_friendly_abort (66);
793 return NULL_TREE;
8d08fdba
MS
794}
795
796#ifndef NO_DOLLAR_IN_LABEL
797# define GLOBAL_THING "_GLOBAL_$"
798#else
799# ifndef NO_DOT_IN_LABEL
800# define GLOBAL_THING "_GLOBAL_."
801# else
802# define GLOBAL_THING "_GLOBAL__"
803# endif
804#endif
805
806#define GLOBAL_IORD_P(NODE) \
fc378698 807 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
8d08fdba 808
49c249e1 809static void
8d08fdba
MS
810dump_global_iord (t)
811 tree t;
812{
9c0758dd 813 const char *name = IDENTIFIER_POINTER (t);
8d08fdba
MS
814
815 OB_PUTS ("(static ");
816 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
817 OB_PUTS ("initializers");
818 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
819 OB_PUTS ("destructors");
820 else
821 my_friendly_abort (352);
822
823 OB_PUTS (" for ");
824 OB_PUTCP (input_filename);
825 OB_PUTC (')');
826}
827
07389efe 828static void
9e93bc9d 829dump_simple_decl (t, type, flags)
07389efe
MM
830 tree t;
831 tree type;
9e93bc9d 832 enum tree_string_flags flags;
07389efe 833{
9e93bc9d 834 if (flags & TS_DECL_TYPE)
07389efe 835 {
9e93bc9d
NS
836 if (dump_type_prefix (type, flags) != none)
837 OB_PUTC (' ');
07389efe 838 }
9e93bc9d
NS
839 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
840 dump_scope (CP_DECL_CONTEXT (t), flags);
07389efe 841 if (DECL_NAME (t))
9e93bc9d 842 dump_decl (DECL_NAME (t), flags);
07389efe 843 else
612c671a 844 OB_PUTS ("{anonymous}");
9e93bc9d
NS
845 if (flags & TS_DECL_TYPE)
846 dump_type_suffix (type, flags);
07389efe
MM
847}
848
9e93bc9d
NS
849/* Dump a human readable string for the decl T under control of FLAGS. */
850
8d08fdba 851static void
9e93bc9d 852dump_decl (t, flags)
8d08fdba 853 tree t;
9e93bc9d 854 enum tree_string_flags flags;
8d08fdba
MS
855{
856 if (t == NULL_TREE)
857 return;
858
859 switch (TREE_CODE (t))
860 {
7177d104 861 case TYPE_DECL:
8d2733ca
MS
862 {
863 /* Don't say 'typedef class A' */
fc378698 864 if (DECL_ARTIFICIAL (t))
8d2733ca 865 {
9e93bc9d
NS
866 if ((flags & TS_DECL_TYPE)
867 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
a9936d39
MM
868 /* Say `class T' not just `T'. */
869 OB_PUTS ("class ");
870
9e93bc9d 871 dump_type (TREE_TYPE (t), flags);
8d2733ca
MS
872 break;
873 }
874 }
9e93bc9d 875 if (flags & TS_DECORATE)
8d2733ca 876 OB_PUTS ("typedef ");
07389efe 877 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
9e93bc9d
NS
878 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
879 flags);
7177d104
MS
880 break;
881
8d08fdba 882 case VAR_DECL:
b7484fbe 883 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
8d08fdba
MS
884 {
885 OB_PUTS ("vtable for ");
52bf7d5d 886 if (TYPE_P (DECL_CONTEXT (t)))
9e93bc9d 887 dump_type (DECL_CONTEXT (t), flags);
52bf7d5d
MM
888 else
889 /* This case can arise with -fno-vtable-thunks. See
890 expand_upcast_fixups. It's not clear what to print
891 here. */
892 OB_PUTS ("{unknown type}");
8d08fdba
MS
893 break;
894 }
895 /* else fall through */
896 case FIELD_DECL:
897 case PARM_DECL:
9e93bc9d 898 dump_simple_decl (t, TREE_TYPE (t), flags);
8d08fdba
MS
899 break;
900
f6a898ba
AO
901 case RESULT_DECL:
902 OB_PUTS ("{return} ");
903 dump_simple_decl (t, TREE_TYPE (t), flags);
904 break;
905
a9aedbc2 906 case NAMESPACE_DECL:
9e93bc9d 907 dump_scope (CP_DECL_CONTEXT (t), flags);
0c8feefe 908 if (DECL_NAME (t) == anonymous_namespace_name)
612c671a 909 OB_PUTS ("{unnamed}");
0c8feefe
MM
910 else
911 OB_PUTID (DECL_NAME (t));
a9aedbc2
MS
912 break;
913
3e3f722c 914 case SCOPE_REF:
9e93bc9d 915 dump_decl (TREE_OPERAND (t, 0), flags & ~TS_DECL_TYPE);
3e3f722c 916 OB_PUTS ("::");
9e93bc9d 917 dump_decl (TREE_OPERAND (t, 1), flags);
3e3f722c
ML
918 break;
919
8d08fdba 920 case ARRAY_REF:
9e93bc9d 921 dump_decl (TREE_OPERAND (t, 0), flags);
8d08fdba 922 OB_PUTC ('[');
9e93bc9d 923 dump_decl (TREE_OPERAND (t, 1), flags);
8d08fdba
MS
924 OB_PUTC (']');
925 break;
926
9e93bc9d 927 /* So that we can do dump_decl on an aggr type. */
8d08fdba
MS
928 case RECORD_TYPE:
929 case UNION_TYPE:
930 case ENUMERAL_TYPE:
9e93bc9d 931 dump_type (t, flags);
8d08fdba
MS
932 break;
933
8d08fdba
MS
934 case TYPE_EXPR:
935 my_friendly_abort (69);
936 break;
937
938 /* These special cases are duplicated here so that other functions
e92cc029 939 can feed identifiers to cp_error and get them demangled properly. */
8d08fdba 940 case IDENTIFIER_NODE:
f30432d7
MS
941 { tree f;
942 if (DESTRUCTOR_NAME_P (t)
943 && (f = ident_fndecl (t))
944 && DECL_LANGUAGE (f) == lang_cplusplus)
945 {
946 OB_PUTC ('~');
9e93bc9d 947 dump_decl (DECL_NAME (f), flags);
f30432d7
MS
948 }
949 else if (IDENTIFIER_TYPENAME_P (t))
950 {
951 OB_PUTS ("operator ");
952 /* Not exactly IDENTIFIER_TYPE_VALUE. */
9e93bc9d 953 dump_type (TREE_TYPE (t), flags);
f30432d7
MS
954 break;
955 }
f30432d7
MS
956 else
957 OB_PUTID (t);
958 }
8d08fdba
MS
959 break;
960
8f032717
MM
961 case OVERLOAD:
962 t = OVL_CURRENT (t);
963 /* Fall through. */
964
8d08fdba
MS
965 case FUNCTION_DECL:
966 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
967 dump_global_iord (DECL_ASSEMBLER_NAME (t));
da20811c
JM
968 else if (! DECL_LANG_SPECIFIC (t))
969 OB_PUTS ("{internal}");
9e93bc9d
NS
970 else if (flags & TS_PEDANTIC_NAME)
971 dump_function_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
8d08fdba 972 else
9e93bc9d 973 dump_function_decl (t, flags);
8d08fdba
MS
974 break;
975
976 case TEMPLATE_DECL:
9e93bc9d
NS
977 if (flags & TS_PEDANTIC_NAME)
978 dump_template_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
979 else
980 dump_template_decl (t, flags);
8d08fdba
MS
981 break;
982
74cd8397
JM
983 case TEMPLATE_ID_EXPR:
984 {
985 tree args;
aa36c081
JM
986 tree name = TREE_OPERAND (t, 0);
987 if (is_overloaded_fn (name))
988 name = DECL_NAME (get_first_fn (name));
9e93bc9d 989 dump_decl (name, flags);
74cd8397
JM
990 OB_PUTC ('<');
991 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
992 {
612c671a 993 dump_template_argument (TREE_VALUE (args), flags);
74cd8397 994 if (TREE_CHAIN (args))
9e93bc9d 995 OB_PUTS (", ");
74cd8397 996 }
0aafb128 997 OB_END_TEMPLATE_ID ();
74cd8397
JM
998 }
999 break;
1000
0fb9f1c3 1001 case LOOKUP_EXPR:
9e93bc9d 1002 dump_decl (TREE_OPERAND (t, 0), flags);
0fb9f1c3
JM
1003 break;
1004
8d08fdba
MS
1005 case LABEL_DECL:
1006 OB_PUTID (DECL_NAME (t));
1007 break;
1008
1009 case CONST_DECL:
6467930b 1010 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
03555413 1011 || (DECL_INITIAL (t) &&
f84b4be9 1012 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
9e93bc9d 1013 dump_simple_decl (t, TREE_TYPE (t), flags);
224c649b 1014 else if (DECL_NAME (t))
9e93bc9d 1015 dump_decl (DECL_NAME (t), flags);
03555413 1016 else if (DECL_INITIAL (t))
9e93bc9d 1017 dump_expr (DECL_INITIAL (t), flags | TS_EXPR_PARENS);
03555413
MM
1018 else
1019 OB_PUTS ("enumerator");
8d08fdba
MS
1020 break;
1021
cffa8729
MS
1022 case USING_DECL:
1023 OB_PUTS ("using ");
9e93bc9d 1024 dump_type (DECL_INITIAL (t), flags);
cffa8729
MS
1025 OB_PUTS ("::");
1026 OB_PUTID (DECL_NAME (t));
1027 break;
1028
8d08fdba 1029 default:
51c184be
MS
1030 sorry ("`%s' not supported by dump_decl",
1031 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
1032 /* Fallthrough to error. */
1033
1034 case ERROR_MARK:
612c671a 1035 OB_PUTS ("{declaration error}");
9e93bc9d
NS
1036 break;
1037 }
1038}
1039
1040/* Dump a template declaration T under control of FLAGS. This means the
1041 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1042
1043static void
1044dump_template_decl (t, flags)
1045 tree t;
1046 enum tree_string_flags flags;
1047{
b5ac18ea
MM
1048 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1049 tree parms;
9e93bc9d
NS
1050 int i;
1051
1052 if (flags & TS_TEMPLATE_PREFIX)
1053 {
b5ac18ea
MM
1054 for (parms = orig_parms = nreverse (orig_parms);
1055 parms;
1056 parms = TREE_CHAIN (parms))
9e93bc9d 1057 {
b5ac18ea
MM
1058 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1059 int len = TREE_VEC_LENGTH (inner_parms);
9e93bc9d
NS
1060
1061 OB_PUTS ("template <");
1062 for (i = 0; i < len; i++)
1063 {
9e93bc9d
NS
1064 if (i)
1065 OB_PUTS (", ");
b5ac18ea 1066 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
9e93bc9d
NS
1067 }
1068 OB_END_TEMPLATE_ID ();
1069 OB_PUTC (' ');
1070 }
b5ac18ea 1071 nreverse(orig_parms);
9e93bc9d 1072 /* If we've shown the template<args> prefix, we'd better show the
b5ac18ea 1073 decl's type too. */
9e93bc9d
NS
1074 flags |= TS_DECL_TYPE;
1075 }
1076 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1077 dump_type (TREE_TYPE (t),
1078 ((flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1079 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0)));
1080 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1081 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TS_TEMPLATE_PLAIN);
1082 else if (TREE_TYPE (t) == NULL_TREE)
1083 my_friendly_abort (353);
1084 else
1085 switch (NEXT_CODE (t))
1086 {
1087 case METHOD_TYPE:
1088 case FUNCTION_TYPE:
1089 dump_function_decl (t, flags | TS_TEMPLATE_PLAIN);
1090 break;
1091 default:
1092 /* This case can occur with some illegal code. */
1093 dump_type (TREE_TYPE (t),
1094 (flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1095 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0));
8d08fdba
MS
1096 }
1097}
1098
4995028c 1099/* Pretty print a function decl. There are several ways we want to print a
9e93bc9d 1100 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
4995028c
NS
1101 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1102 is %D which doesn't print the throw specs, and %F which does. */
8d08fdba
MS
1103
1104static void
9e93bc9d 1105dump_function_decl (t, flags)
8d08fdba 1106 tree t;
9e93bc9d 1107 enum tree_string_flags flags;
8d08fdba 1108{
98c1c668
JM
1109 tree fntype;
1110 tree parmtypes;
8d08fdba 1111 tree cname = NULL_TREE;
612c671a
GDR
1112 tree template_args = NULL_TREE;
1113 tree template_parms = NULL_TREE;
9e93bc9d 1114 int show_return = !(flags & TS_FUNC_NORETURN) && (flags & TS_DECL_TYPE);
8d08fdba 1115
98c1c668
JM
1116 if (TREE_CODE (t) == TEMPLATE_DECL)
1117 t = DECL_TEMPLATE_RESULT (t);
1118
612c671a 1119 /* Pretty print template instantiations only. */
f9817201 1120 if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
612c671a 1121 {
f9a7ae04
MM
1122 tree tmpl;
1123
612c671a 1124 template_args = DECL_TI_ARGS (t);
f9a7ae04
MM
1125 tmpl = most_general_template (t);
1126 if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1127 {
1128 template_parms = DECL_TEMPLATE_PARMS (tmpl);
1129 t = tmpl;
1130 }
612c671a
GDR
1131 }
1132
98c1c668
JM
1133 fntype = TREE_TYPE (t);
1134 parmtypes = TYPE_ARG_TYPES (fntype);
1135
2642b9bf 1136 if (DECL_CLASS_SCOPE_P (t))
4f1c5b7d 1137 cname = DECL_CONTEXT (t);
8d08fdba
MS
1138 /* this is for partially instantiated template methods */
1139 else if (TREE_CODE (fntype) == METHOD_TYPE)
1140 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1141
9e93bc9d
NS
1142 if (!(flags & TS_DECORATE))
1143 /* OK */;
1144 else if (DECL_STATIC_FUNCTION_P (t))
1145 OB_PUTS ("static ");
4c6b7393 1146 else if (TYPE_POLYMORPHIC_P (t))
9e93bc9d
NS
1147 OB_PUTS ("virtual ");
1148
1149 /* Print the return type? */
1150 if (show_return)
1151 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1152 && !DECL_DESTRUCTOR_P (t);
1153 if (show_return)
8d08fdba 1154 {
9e93bc9d
NS
1155 if (dump_type_prefix (TREE_TYPE (fntype), flags) != none)
1156 OB_PUTC (' ');
8d08fdba
MS
1157 }
1158
61cd552e 1159 /* Print the function name. */
8d08fdba
MS
1160 if (cname)
1161 {
9e93bc9d
NS
1162 dump_type (cname, flags);
1163 OB_PUTS ("::");
2642b9bf 1164 }
9e93bc9d
NS
1165 else
1166 dump_scope (CP_DECL_CONTEXT (t), flags);
8d08fdba 1167
9e93bc9d 1168 dump_function_name (t, flags);
8d08fdba 1169
9e93bc9d 1170 if (!(flags & TS_DECL_TYPE))
61cd552e 1171 return;
9e93bc9d
NS
1172 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1173 /* Skip "this" parameter. */
1174 parmtypes = TREE_CHAIN (parmtypes);
1175
454fa7a7
MM
1176 /* Skip past the "in_charge" parameter. */
1177 if (DECL_HAS_IN_CHARGE_PARM_P (t))
9e93bc9d
NS
1178 parmtypes = TREE_CHAIN (parmtypes);
1179
1180 dump_parameters (parmtypes, flags);
4995028c 1181
9e93bc9d
NS
1182 if (show_return)
1183 dump_type_suffix (TREE_TYPE (fntype), flags);
8d08fdba
MS
1184
1185 if (TREE_CODE (fntype) == METHOD_TYPE)
6eabb241
MM
1186 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1187 before);
4995028c 1188
9e93bc9d
NS
1189 if (flags & TS_FUNC_THROW)
1190 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
612c671a
GDR
1191
1192 /* If T is a template instantiation, dump the parameter binding. */
1193 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1194 {
1195 OB_PUTS (" [with ");
b5ac18ea 1196 dump_template_bindings (template_parms, template_args);
612c671a
GDR
1197 OB_PUTC (']');
1198 }
4995028c
NS
1199}
1200
9e93bc9d
NS
1201/* Print a parameter list. If this is for a member function, the
1202 member object ptr (and any other hidden args) should have
1203 already been removed. */
4995028c
NS
1204
1205static void
9e93bc9d 1206dump_parameters (parmtypes, flags)
4995028c 1207 tree parmtypes;
9e93bc9d 1208 enum tree_string_flags flags;
4995028c
NS
1209{
1210 int first;
9e93bc9d 1211 OB_PUTS (" (");
4995028c
NS
1212
1213 for (first = 1; parmtypes != void_list_node;
1214 parmtypes = TREE_CHAIN (parmtypes))
1215 {
1216 if (!first)
9e93bc9d 1217 OB_PUTS (", ");
4995028c
NS
1218 first = 0;
1219 if (!parmtypes)
1220 {
1221 OB_PUTS ("...");
1222 break;
1223 }
9e93bc9d 1224 dump_type (TREE_VALUE (parmtypes), flags);
4995028c 1225
9e93bc9d 1226 if ((flags & TS_PARM_DEFAULTS) && TREE_PURPOSE (parmtypes))
4995028c
NS
1227 {
1228 OB_PUTS (" = ");
9e93bc9d 1229 dump_expr (TREE_PURPOSE (parmtypes), flags | TS_EXPR_PARENS);
4995028c
NS
1230 }
1231 }
1232
1233 OB_PUTC (')');
1234}
1235
1236/* Print an exception specification. T is the exception specification. */
1237
1238static void
9e93bc9d 1239dump_exception_spec (t, flags)
4995028c 1240 tree t;
9e93bc9d 1241 enum tree_string_flags flags;
4995028c
NS
1242{
1243 if (t)
1244 {
1245 OB_PUTS (" throw (");
1246 if (TREE_VALUE (t) != NULL_TREE)
1247 while (1)
1248 {
9e93bc9d 1249 dump_type (TREE_VALUE (t), flags);
4995028c
NS
1250 t = TREE_CHAIN (t);
1251 if (!t)
1252 break;
9e93bc9d 1253 OB_PUTS (", ");
4995028c
NS
1254 }
1255 OB_PUTC (')');
1256 }
8d08fdba
MS
1257}
1258
1259/* Handle the function name for a FUNCTION_DECL node, grokking operators
1260 and destructors properly. */
e92cc029 1261
8d08fdba 1262static void
9e93bc9d 1263dump_function_name (t, flags)
8d08fdba 1264 tree t;
9e93bc9d 1265 enum tree_string_flags flags;
8d08fdba
MS
1266{
1267 tree name = DECL_NAME (t);
1268
aa45967f 1269 if (DECL_DESTRUCTOR_P (t))
8d08fdba
MS
1270 {
1271 OB_PUTC ('~');
9e93bc9d 1272 dump_decl (name, TS_PLAIN);
8d08fdba 1273 }
aa45967f 1274 else if (DECL_CONV_FN_P (t))
8d08fdba
MS
1275 {
1276 /* This cannot use the hack that the operator's return
1277 type is stashed off of its name because it may be
1278 used for error reporting. In the case of conflicting
1279 declarations, both will have the same name, yet
1280 the types will be different, hence the TREE_TYPE field
1281 of the first name will be clobbered by the second. */
1282 OB_PUTS ("operator ");
9e93bc9d 1283 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
8d08fdba
MS
1284 }
1285 else if (IDENTIFIER_OPNAME_P (name))
596ea4e5 1286 OB_PUTID (name);
8d08fdba 1287 else
9e93bc9d 1288 dump_decl (name, flags);
386b8a85 1289
9e93bc9d 1290 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
05fd666b 1291 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
36a117a5
MM
1292 && (DECL_TEMPLATE_SPECIALIZATION (t)
1293 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1294 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1295 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
9e93bc9d
NS
1296 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1297}
75650646 1298
9e93bc9d
NS
1299/* Dump the template parameters from the template info INFO under control of
1300 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1301 specialization (partial or complete). For partial specializations we show
1302 the specialized parameter values. For a primary template we show no
1303 decoration. */
1304
1305static void
1306dump_template_parms (info, primary, flags)
1307 tree info;
1308 int primary;
1309 enum tree_string_flags flags;
1310{
1311 tree args = info ? TI_ARGS (info) : NULL_TREE;
1312
1313 if (primary && flags & TS_TEMPLATE_PLAIN)
1314 return;
1315 flags &= ~(TS_AGGR_TAGS | TS_TEMPLATE_PLAIN);
1316 OB_PUTC ('<');
1317
1318 /* Be careful only to print things when we have them, so as not
36a117a5 1319 to crash producing error messages. */
9e93bc9d
NS
1320 if (args && !primary)
1321 {
1322 int len = 0;
1323 int ix = 0;
1324 int need_comma = 0;
1325
1326 if (TREE_CODE (args) == TREE_VEC)
1327 {
1328 if (TREE_VEC_LENGTH (args) > 0
1329 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1330 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1331
1332 len = TREE_VEC_LENGTH (args);
1333 }
1334 else if (TREE_CODE (args) == TREE_LIST)
1335 len = -1;
1336 while (ix != len && args)
1337 {
1338 tree arg;
1339 if (len >= 0)
1340 {
1341 arg = TREE_VEC_ELT (args, ix);
1342 ix++;
1343 }
1344 else
1345 {
1346 arg = TREE_VALUE (args);
1347 args = TREE_CHAIN (args);
1348 }
1349 if (need_comma)
1350 OB_PUTS (", ");
1351
1352 if (!arg)
612c671a 1353 OB_PUTS ("{template parameter error}");
9e93bc9d 1354 else
612c671a 1355 dump_template_argument (arg, flags);
9e93bc9d
NS
1356 need_comma = 1;
1357 }
1358 }
9e93bc9d
NS
1359 else if (primary)
1360 {
1361 tree tpl = TI_TEMPLATE (info);
1362 tree parms = DECL_TEMPLATE_PARMS (tpl);
1363 int len, ix;
1364
1365 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1366 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1367
1368 for (ix = 0; ix != len; ix++)
1369 {
1370 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1371
1372 if (ix)
1373 OB_PUTS (", ");
1374
1375 dump_decl (parm, flags & ~TS_DECL_TYPE);
1376 }
386b8a85 1377 }
9e93bc9d 1378 OB_END_TEMPLATE_ID ();
8d08fdba
MS
1379}
1380
1381static void
1382dump_char (c)
b2bb2710 1383 int c;
8d08fdba
MS
1384{
1385 switch (c)
1386 {
a0a33927 1387 case TARGET_NEWLINE:
8d08fdba
MS
1388 OB_PUTS ("\\n");
1389 break;
a0a33927 1390 case TARGET_TAB:
8d08fdba
MS
1391 OB_PUTS ("\\t");
1392 break;
a0a33927 1393 case TARGET_VT:
8d08fdba
MS
1394 OB_PUTS ("\\v");
1395 break;
a0a33927 1396 case TARGET_BS:
8d08fdba
MS
1397 OB_PUTS ("\\b");
1398 break;
a0a33927 1399 case TARGET_CR:
8d08fdba
MS
1400 OB_PUTS ("\\r");
1401 break;
a0a33927 1402 case TARGET_FF:
8d08fdba
MS
1403 OB_PUTS ("\\f");
1404 break;
a0a33927 1405 case TARGET_BELL:
8d08fdba
MS
1406 OB_PUTS ("\\a");
1407 break;
1408 case '\\':
1409 OB_PUTS ("\\\\");
1410 break;
1411 case '\'':
1412 OB_PUTS ("\\'");
1413 break;
1414 case '\"':
1415 OB_PUTS ("\\\"");
1416 break;
1417 default:
faa25e97 1418 if (ISPRINT (c))
8d08fdba
MS
1419 OB_PUTC (c);
1420 else
1421 {
1422 sprintf (digit_buffer, "\\%03o", (int) c);
1423 OB_PUTCP (digit_buffer);
1424 }
1425 }
1426}
1427
1428/* Print out a list of initializers (subr of dump_expr) */
e92cc029 1429
8d08fdba 1430static void
9e93bc9d 1431dump_expr_list (l, flags)
8d08fdba 1432 tree l;
9e93bc9d 1433 enum tree_string_flags flags;
8d08fdba
MS
1434{
1435 while (l)
1436 {
9e93bc9d 1437 dump_expr (TREE_VALUE (l), flags | TS_EXPR_PARENS);
8d08fdba 1438 l = TREE_CHAIN (l);
9e93bc9d
NS
1439 if (l)
1440 OB_PUTS (", ");
8d08fdba
MS
1441 }
1442}
1443
9e93bc9d 1444/* Print out an expression E under control of FLAGS. */
e92cc029 1445
8d08fdba 1446static void
9e93bc9d 1447dump_expr (t, flags)
8d08fdba 1448 tree t;
9e93bc9d 1449 enum tree_string_flags flags;
8d08fdba
MS
1450{
1451 switch (TREE_CODE (t))
1452 {
1453 case VAR_DECL:
1454 case PARM_DECL:
1455 case FIELD_DECL:
1456 case CONST_DECL:
1457 case FUNCTION_DECL:
ec255269 1458 case TEMPLATE_DECL:
6b57ac29 1459 case NAMESPACE_DECL:
5d73aa63 1460 case OVERLOAD:
9e93bc9d 1461 dump_decl (t, flags & ~TS_DECL_TYPE);
8d08fdba
MS
1462 break;
1463
1464 case INTEGER_CST:
1465 {
1466 tree type = TREE_TYPE (t);
1467 my_friendly_assert (type != 0, 81);
1468
1469 /* If it's an enum, output its tag, rather than its value. */
1470 if (TREE_CODE (type) == ENUMERAL_TYPE)
1471 {
fa40aa12
NS
1472 tree values = TYPE_VALUES (type);
1473
1474 for (; values;
1475 values = TREE_CHAIN (values))
1476 if (tree_int_cst_equal (TREE_VALUE (values), t))
1477 break;
1478
1479 if (values)
1480 OB_PUTID (TREE_PURPOSE (values));
1481 else
1482 {
1483 /* Value must have been cast. */
1484 OB_PUTC ('(');
1485 dump_type (type, flags);
1486 OB_PUTC (')');
1487 goto do_int;
1488 }
8d08fdba 1489 }
b7484fbe
MS
1490 else if (type == boolean_type_node)
1491 {
665f2503 1492 if (t == boolean_false_node || integer_zerop (t))
b7484fbe
MS
1493 OB_PUTS ("false");
1494 else if (t == boolean_true_node)
1495 OB_PUTS ("true");
b7484fbe
MS
1496 }
1497 else if (type == char_type_node)
8d08fdba
MS
1498 {
1499 OB_PUTC ('\'');
665f2503 1500 dump_char (tree_low_cst (t, 0));
8d08fdba
MS
1501 OB_PUTC ('\'');
1502 }
fa40aa12 1503 else
8d08fdba 1504 {
fa40aa12
NS
1505 do_int:
1506 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t)
1507 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
8d08fdba 1508 {
fa40aa12
NS
1509 tree val = t;
1510
1511 if (tree_int_cst_sgn (val) < 0)
1512 {
1513 OB_PUTC ('-');
1514 val = build_int_2 (-TREE_INT_CST_LOW (val),
1515 ~TREE_INT_CST_HIGH (val)
1516 + !TREE_INT_CST_LOW (val));
1517 }
1518 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1519 systems? */
1520 {
1521 static char format[10]; /* "%x%09999x\0" */
1522 if (!format[0])
1523 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1524 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1525 TREE_INT_CST_LOW (val));
1526 OB_PUTCP (digit_buffer);
1527 }
8d08fdba 1528 }
fa40aa12
NS
1529 else
1530 OB_PUTI (TREE_INT_CST_LOW (t));
8d08fdba 1531 }
8d08fdba
MS
1532 }
1533 break;
1534
1535 case REAL_CST:
1536#ifndef REAL_IS_NOT_DOUBLE
1537 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1538#else
1539 {
9c0758dd 1540 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
a703fb38 1541 size_t i;
8d08fdba
MS
1542 strcpy (digit_buffer, "0x");
1543 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1544 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1545 }
1546#endif
1547 OB_PUTCP (digit_buffer);
1548 break;
1549
61a127b3
MM
1550 case PTRMEM_CST:
1551 OB_PUTC ('&');
9e93bc9d 1552 dump_type (PTRMEM_CST_CLASS (t), flags);
61a127b3
MM
1553 OB_PUTS ("::");
1554 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1555 break;
1556
8d08fdba
MS
1557 case STRING_CST:
1558 {
9c0758dd 1559 const char *p = TREE_STRING_POINTER (t);
8d08fdba
MS
1560 int len = TREE_STRING_LENGTH (t) - 1;
1561 int i;
1562
1563 OB_PUTC ('\"');
1564 for (i = 0; i < len; i++)
1565 dump_char (p[i]);
1566 OB_PUTC ('\"');
1567 }
1568 break;
1569
1570 case COMPOUND_EXPR:
9e93bc9d
NS
1571 OB_PUTC ('(');
1572 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1573 OB_PUTS (", ");
1574 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1575 OB_PUTC (')');
8d08fdba
MS
1576 break;
1577
1578 case COND_EXPR:
1579 OB_PUTC ('(');
9e93bc9d 1580 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1581 OB_PUTS (" ? ");
9e93bc9d 1582 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba 1583 OB_PUTS (" : ");
9e93bc9d 1584 dump_expr (TREE_OPERAND (t, 2), flags | TS_EXPR_PARENS);
8d08fdba
MS
1585 OB_PUTC (')');
1586 break;
1587
1588 case SAVE_EXPR:
1589 if (TREE_HAS_CONSTRUCTOR (t))
1590 {
1591 OB_PUTS ("new ");
9e93bc9d 1592 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
8d08fdba
MS
1593 }
1594 else
1595 {
9e93bc9d 1596 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1597 }
1598 break;
1599
02531345 1600 case AGGR_INIT_EXPR:
27b8d0cd
MM
1601 {
1602 tree fn = NULL_TREE;
1603
1604 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1605 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1606
1607 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1608 {
1609 if (DECL_CONSTRUCTOR_P (fn))
1610 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1611 else
1612 dump_decl (fn, 0);
1613 }
1614 else
1615 dump_expr (TREE_OPERAND (t, 0), 0);
1616 }
8d08fdba 1617 OB_PUTC ('(');
42976354 1618 if (TREE_OPERAND (t, 1))
9e93bc9d 1619 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
8d08fdba
MS
1620 OB_PUTC (')');
1621 break;
1622
1623 case CALL_EXPR:
1624 {
1625 tree fn = TREE_OPERAND (t, 0);
1626 tree args = TREE_OPERAND (t, 1);
1627
1628 if (TREE_CODE (fn) == ADDR_EXPR)
1629 fn = TREE_OPERAND (fn, 0);
1630
6467930b 1631 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
8d08fdba
MS
1632 {
1633 tree ob = TREE_VALUE (args);
1634 if (TREE_CODE (ob) == ADDR_EXPR)
1635 {
9e93bc9d 1636 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1637 OB_PUTC ('.');
1638 }
1639 else if (TREE_CODE (ob) != PARM_DECL
1640 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1641 {
9e93bc9d
NS
1642 dump_expr (ob, flags | TS_EXPR_PARENS);
1643 OB_PUTS ("->");
8d08fdba
MS
1644 }
1645 args = TREE_CHAIN (args);
1646 }
9e93bc9d 1647 dump_expr (fn, flags | TS_EXPR_PARENS);
fc378698 1648 OB_PUTC ('(');
9e93bc9d 1649 dump_expr_list (args, flags);
8d08fdba
MS
1650 OB_PUTC (')');
1651 }
1652 break;
1653
285baa06
JM
1654 case NEW_EXPR:
1655 {
1656 tree type = TREE_OPERAND (t, 1);
1657 if (NEW_EXPR_USE_GLOBAL (t))
1658 OB_PUTS ("::");
1659 OB_PUTS ("new ");
1660 if (TREE_OPERAND (t, 0))
1661 {
1662 OB_PUTC ('(');
9e93bc9d 1663 dump_expr_list (TREE_OPERAND (t, 0), flags);
285baa06
JM
1664 OB_PUTS (") ");
1665 }
1666 if (TREE_CODE (type) == ARRAY_REF)
1667 type = build_cplus_array_type
1668 (TREE_OPERAND (type, 0),
fed3cef0
RK
1669 build_index_type (fold (build (MINUS_EXPR, integer_type_node,
1670 TREE_OPERAND (type, 1),
1671 integer_one_node))));
9e93bc9d 1672 dump_type (type, flags);
285baa06
JM
1673 if (TREE_OPERAND (t, 2))
1674 {
1675 OB_PUTC ('(');
9e93bc9d 1676 dump_expr_list (TREE_OPERAND (t, 2), flags);
285baa06
JM
1677 OB_PUTC (')');
1678 }
1679 }
1680 break;
1681
8d08fdba
MS
1682 case TARGET_EXPR:
1683 /* Note that this only works for G++ target exprs. If somebody
1684 builds a general TARGET_EXPR, there's no way to represent that
1685 it initializes anything other that the parameter slot for the
1686 default argument. Note we may have cleared out the first
1687 operand in expand_expr, so don't go killing ourselves. */
1688 if (TREE_OPERAND (t, 1))
9e93bc9d 1689 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba
MS
1690 break;
1691
b3ab27f3 1692 case INIT_EXPR:
8d08fdba
MS
1693 case MODIFY_EXPR:
1694 case PLUS_EXPR:
1695 case MINUS_EXPR:
1696 case MULT_EXPR:
1697 case TRUNC_DIV_EXPR:
1698 case TRUNC_MOD_EXPR:
1699 case MIN_EXPR:
1700 case MAX_EXPR:
1701 case LSHIFT_EXPR:
1702 case RSHIFT_EXPR:
1703 case BIT_IOR_EXPR:
1704 case BIT_XOR_EXPR:
1705 case BIT_AND_EXPR:
1706 case BIT_ANDTC_EXPR:
1707 case TRUTH_ANDIF_EXPR:
1708 case TRUTH_ORIF_EXPR:
1709 case LT_EXPR:
1710 case LE_EXPR:
1711 case GT_EXPR:
1712 case GE_EXPR:
1713 case EQ_EXPR:
1714 case NE_EXPR:
2adeacc9 1715 case EXACT_DIV_EXPR:
596ea4e5 1716 dump_binary_op (operator_name_info[(int) TREE_CODE (t)].name, t, flags);
8d08fdba
MS
1717 break;
1718
1719 case CEIL_DIV_EXPR:
1720 case FLOOR_DIV_EXPR:
1721 case ROUND_DIV_EXPR:
9e93bc9d 1722 dump_binary_op ("/", t, flags);
8d08fdba
MS
1723 break;
1724
1725 case CEIL_MOD_EXPR:
1726 case FLOOR_MOD_EXPR:
1727 case ROUND_MOD_EXPR:
9e93bc9d 1728 dump_binary_op ("%", t, flags);
8d08fdba
MS
1729 break;
1730
1731 case COMPONENT_REF:
1732 {
1733 tree ob = TREE_OPERAND (t, 0);
1734 if (TREE_CODE (ob) == INDIRECT_REF)
1735 {
1736 ob = TREE_OPERAND (ob, 0);
1737 if (TREE_CODE (ob) != PARM_DECL
1738 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1739 {
9e93bc9d
NS
1740 dump_expr (ob, flags | TS_EXPR_PARENS);
1741 OB_PUTS ("->");
8d08fdba
MS
1742 }
1743 }
1744 else
1745 {
9e93bc9d 1746 dump_expr (ob, flags | TS_EXPR_PARENS);
8d08fdba
MS
1747 OB_PUTC ('.');
1748 }
9e93bc9d 1749 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
8d08fdba
MS
1750 }
1751 break;
1752
28cbf42c 1753 case ARRAY_REF:
9e93bc9d 1754 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
28cbf42c 1755 OB_PUTC ('[');
9e93bc9d 1756 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
28cbf42c
MS
1757 OB_PUTC (']');
1758 break;
1759
8d08fdba 1760 case CONVERT_EXPR:
b72801e2 1761 if (VOID_TYPE_P (TREE_TYPE (t)))
df39af7d 1762 {
b72801e2
NS
1763 OB_PUTC ('(');
1764 dump_type (TREE_TYPE (t), flags);
1765 OB_PUTC (')');
9e93bc9d 1766 dump_expr (TREE_OPERAND (t, 0), flags);
df39af7d
JM
1767 }
1768 else
9e93bc9d 1769 dump_unary_op ("+", t, flags);
8d08fdba
MS
1770 break;
1771
1772 case ADDR_EXPR:
1773 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
fd74ca0b
MM
1774 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
1775 /* An ADDR_EXPR can have reference type. In that case, we
1776 shouldn't print the `&' doing so indicates to the user
1777 that the expression has pointer type. */
1778 || (TREE_TYPE (t)
1779 && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
9e93bc9d 1780 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1781 else
9e93bc9d 1782 dump_unary_op ("&", t, flags);
8d08fdba
MS
1783 break;
1784
1785 case INDIRECT_REF:
1786 if (TREE_HAS_CONSTRUCTOR (t))
1787 {
1788 t = TREE_OPERAND (t, 0);
1789 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
9e93bc9d 1790 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1791 OB_PUTC ('(');
9e93bc9d 1792 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
8d08fdba
MS
1793 OB_PUTC (')');
1794 }
1795 else
1796 {
6467930b 1797 if (TREE_OPERAND (t,0) != NULL_TREE
5082a355 1798 && TREE_TYPE (TREE_OPERAND (t, 0))
6467930b 1799 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
9e93bc9d 1800 dump_expr (TREE_OPERAND (t, 0), flags);
8d08fdba 1801 else
9e93bc9d 1802 dump_unary_op ("*", t, flags);
8d08fdba
MS
1803 }
1804 break;
1805
1806 case NEGATE_EXPR:
1807 case BIT_NOT_EXPR:
1808 case TRUTH_NOT_EXPR:
1809 case PREDECREMENT_EXPR:
1810 case PREINCREMENT_EXPR:
596ea4e5 1811 dump_unary_op (operator_name_info [(int)TREE_CODE (t)].name, t, flags);
8d08fdba
MS
1812 break;
1813
1814 case POSTDECREMENT_EXPR:
1815 case POSTINCREMENT_EXPR:
1816 OB_PUTC ('(');
9e93bc9d 1817 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
596ea4e5 1818 OB_PUTCP (operator_name_info[(int)TREE_CODE (t)].name);
8d08fdba
MS
1819 OB_PUTC (')');
1820 break;
1821
1822 case NON_LVALUE_EXPR:
1823 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1824 should be another level of INDIRECT_REF so that I don't have to do
1825 this. */
6467930b 1826 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
8d08fdba
MS
1827 {
1828 tree next = TREE_TYPE (TREE_TYPE (t));
1829
1830 while (TREE_CODE (next) == POINTER_TYPE)
1831 next = TREE_TYPE (next);
1832
1833 if (TREE_CODE (next) == FUNCTION_TYPE)
1834 {
9e93bc9d
NS
1835 if (flags & TS_EXPR_PARENS)
1836 OB_PUTC ('(');
8d08fdba 1837 OB_PUTC ('*');
9e93bc9d
NS
1838 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
1839 if (flags & TS_EXPR_PARENS)
1840 OB_PUTC (')');
8d08fdba
MS
1841 break;
1842 }
1843 /* else FALLTHRU */
1844 }
9e93bc9d 1845 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1846 break;
1847
1848 case NOP_EXPR:
9e93bc9d 1849 dump_expr (TREE_OPERAND (t, 0), flags);
8d08fdba
MS
1850 break;
1851
89c6e7ac
MM
1852 case EXPR_WITH_FILE_LOCATION:
1853 dump_expr (EXPR_WFL_NODE (t), flags);
1854 break;
1855
8d08fdba 1856 case CONSTRUCTOR:
9a3b49ac
MS
1857 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1858 {
1859 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1860
1861 if (integer_all_onesp (idx))
1862 {
1863 tree pfn = PFN_FROM_PTRMEMFUNC (t);
9e93bc9d 1864 dump_unary_op ("&", pfn, flags | TS_EXPR_PARENS);
9a3b49ac
MS
1865 break;
1866 }
e08a8f45
MM
1867 else if (TREE_CODE (idx) == INTEGER_CST
1868 && tree_int_cst_equal (idx, integer_zero_node))
1869 {
1870 /* A NULL pointer-to-member constant. */
1871 OB_PUTS ("((");
9e93bc9d 1872 dump_type (TREE_TYPE (t), flags);
e08a8f45
MM
1873 OB_PUTS (") 0)");
1874 break;
1875 }
665f2503 1876 else if (host_integerp (idx, 0))
9a3b49ac
MS
1877 {
1878 tree virtuals;
1879 unsigned HOST_WIDE_INT n;
1880
1881 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1882 t = TYPE_METHOD_BASETYPE (t);
83f2ccf4 1883 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
9a3b49ac 1884
da3d4dfa 1885 n = tree_low_cst (idx, 0) - first_vfun_index (t);
9a3b49ac
MS
1886
1887 /* Map vtable index back one, to allow for the null pointer to
1888 member. */
1889 --n;
1890
1891 while (n > 0 && virtuals)
1892 {
1893 --n;
1894 virtuals = TREE_CHAIN (virtuals);
1895 }
1896 if (virtuals)
1897 {
31f8e4f3 1898 dump_expr (BV_FN (virtuals),
9e93bc9d 1899 flags | TS_EXPR_PARENS);
9a3b49ac
MS
1900 break;
1901 }
1902 }
1903 }
8d08fdba 1904 OB_PUTC ('{');
9e93bc9d 1905 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
8d08fdba
MS
1906 OB_PUTC ('}');
1907 break;
1908
51c184be
MS
1909 case OFFSET_REF:
1910 {
1911 tree ob = TREE_OPERAND (t, 0);
51924768 1912 if (is_dummy_object (ob))
61a127b3 1913 {
05e0b2f4
JM
1914 t = TREE_OPERAND (t, 1);
1915 if (TREE_CODE (t) == FUNCTION_DECL)
61a127b3 1916 /* A::f */
9e93bc9d 1917 dump_expr (t, flags | TS_EXPR_PARENS);
05e0b2f4 1918 else if (BASELINK_P (t))
9e93bc9d 1919 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TS_EXPR_PARENS);
61a127b3 1920 else
9e93bc9d 1921 dump_decl (t, flags);
61a127b3 1922 }
51c184be
MS
1923 else
1924 {
bbcec105
JM
1925 if (TREE_CODE (ob) == INDIRECT_REF)
1926 {
9e93bc9d 1927 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
bbcec105
JM
1928 OB_PUTS (" ->* ");
1929 }
1930 else
1931 {
9e93bc9d 1932 dump_expr (ob, flags | TS_EXPR_PARENS);
bbcec105
JM
1933 OB_PUTS (" .* ");
1934 }
9e93bc9d 1935 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
51c184be
MS
1936 }
1937 break;
1938 }
1939
f84b4be9 1940 case TEMPLATE_PARM_INDEX:
9e93bc9d 1941 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TS_DECL_TYPE);
de22184b 1942 break;
5566b478
MS
1943
1944 case IDENTIFIER_NODE:
1945 OB_PUTID (t);
1946 break;
1947
1948 case SCOPE_REF:
9e93bc9d 1949 dump_type (TREE_OPERAND (t, 0), flags);
5566b478 1950 OB_PUTS ("::");
9e93bc9d 1951 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
5566b478
MS
1952 break;
1953
1954 case CAST_EXPR:
e349ee73
MS
1955 if (TREE_OPERAND (t, 0) == NULL_TREE
1956 || TREE_CHAIN (TREE_OPERAND (t, 0)))
e76a2646 1957 {
9e93bc9d 1958 dump_type (TREE_TYPE (t), flags);
e76a2646 1959 OB_PUTC ('(');
9e93bc9d 1960 dump_expr_list (TREE_OPERAND (t, 0), flags);
e76a2646
MS
1961 OB_PUTC (')');
1962 }
1963 else
1964 {
1965 OB_PUTC ('(');
9e93bc9d 1966 dump_type (TREE_TYPE (t), flags);
e76a2646
MS
1967 OB_PUTC (')');
1968 OB_PUTC ('(');
9e93bc9d 1969 dump_expr_list (TREE_OPERAND (t, 0), flags);
e76a2646
MS
1970 OB_PUTC (')');
1971 }
1972 break;
1973
1974 case LOOKUP_EXPR:
1975 OB_PUTID (TREE_OPERAND (t, 0));
1976 break;
1977
5a11e05b 1978 case ARROW_EXPR:
9e93bc9d 1979 dump_expr (TREE_OPERAND (t, 0), flags);
5a11e05b
BK
1980 OB_PUTS ("->");
1981 break;
1982
e76a2646 1983 case SIZEOF_EXPR:
abff8e06
JM
1984 case ALIGNOF_EXPR:
1985 if (TREE_CODE (t) == SIZEOF_EXPR)
1986 OB_PUTS ("sizeof (");
1987 else
1988 {
1989 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1990 OB_PUTS ("__alignof__ (");
1991 }
2f939d94 1992 if (TYPE_P (TREE_OPERAND (t, 0)))
9e93bc9d 1993 dump_type (TREE_OPERAND (t, 0), flags);
e76a2646 1994 else
9e93bc9d 1995 dump_unary_op ("*", t, flags | TS_EXPR_PARENS);
e76a2646
MS
1996 OB_PUTC (')');
1997 break;
5566b478 1998
da20811c
JM
1999 case DEFAULT_ARG:
2000 OB_PUTS ("{unparsed}");
2001 break;
2002
6748b643
JM
2003 case TRY_CATCH_EXPR:
2004 case WITH_CLEANUP_EXPR:
2005 case CLEANUP_POINT_EXPR:
9e93bc9d 2006 dump_expr (TREE_OPERAND (t, 0), flags);
6748b643
JM
2007 break;
2008
40242ccf 2009 case PSEUDO_DTOR_EXPR:
9e93bc9d 2010 dump_expr (TREE_OPERAND (t, 2), flags);
40242ccf 2011 OB_PUTS (".");
9e93bc9d 2012 dump_type (TREE_OPERAND (t, 0), flags);
40242ccf 2013 OB_PUTS ("::~");
9e93bc9d 2014 dump_type (TREE_OPERAND (t, 1), flags);
40242ccf
MM
2015 break;
2016
7ac7b28f 2017 case TEMPLATE_ID_EXPR:
9e93bc9d 2018 dump_decl (t, flags);
7ac7b28f
MM
2019 break;
2020
558475f0
MM
2021 case STMT_EXPR:
2022 /* We don't yet have a way of dumping statements in a
2023 human-readable format. */
2024 OB_PUTS ("{ ... }");
2025 break;
2026
0045e0bc
MM
2027 case BIND_EXPR:
2028 OB_PUTS ("{ ");
9e93bc9d 2029 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
2030 OB_PUTS ("} ");
2031 break;
2032
2033 case LOOP_EXPR:
2034 OB_PUTS ("while (1) { ");
9e93bc9d 2035 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
2036 OB_PUTS ("} ");
2037 break;
2038
2039 case EXIT_EXPR:
2040 OB_PUTS ("if (");
9e93bc9d 2041 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
2042 OB_PUTS (") break; ");
2043 break;
2044
00595019
MS
2045 case TREE_LIST:
2046 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2047 {
2048 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
2049 break;
2050 }
2051 /* else fall through */
2052
8d08fdba
MS
2053 /* This list is incomplete, but should suffice for now.
2054 It is very important that `sorry' does not call
2055 `report_error_function'. That could cause an infinite loop. */
2056 default:
2057 sorry ("`%s' not supported by dump_expr",
2058 tree_code_name[(int) TREE_CODE (t)]);
2059
2060 /* fall through to ERROR_MARK... */
2061 case ERROR_MARK:
612c671a 2062 OB_PUTCP ("{expression error}");
8d08fdba
MS
2063 break;
2064 }
2065}
2066
2067static void
9e93bc9d 2068dump_binary_op (opstring, t, flags)
9c0758dd 2069 const char *opstring;
8d08fdba 2070 tree t;
9e93bc9d 2071 enum tree_string_flags flags;
8d08fdba
MS
2072{
2073 OB_PUTC ('(');
9e93bc9d 2074 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 2075 OB_PUTC (' ');
2adeacc9
MM
2076 if (opstring)
2077 OB_PUTCP (opstring);
2078 else
2079 OB_PUTS ("<unknown operator>");
8d08fdba 2080 OB_PUTC (' ');
9e93bc9d 2081 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba
MS
2082 OB_PUTC (')');
2083}
2084
2085static void
9e93bc9d 2086dump_unary_op (opstring, t, flags)
9c0758dd 2087 const char *opstring;
8d08fdba 2088 tree t;
9e93bc9d 2089 enum tree_string_flags flags;
8d08fdba 2090{
9e93bc9d
NS
2091 if (flags & TS_EXPR_PARENS)
2092 OB_PUTC ('(');
8d08fdba 2093 OB_PUTCP (opstring);
9e93bc9d
NS
2094 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2095 if (flags & TS_EXPR_PARENS)
2096 OB_PUTC (')');
8d08fdba
MS
2097}
2098
9e93bc9d
NS
2099/* Exported interface to stringifying types, exprs and decls under TS_*
2100 control. */
4995028c 2101
e1def31b 2102const char *
9e93bc9d
NS
2103type_as_string (typ, flags)
2104 tree typ;
2105 enum tree_string_flags flags;
8d08fdba 2106{
4995028c
NS
2107 OB_INIT ();
2108
9e93bc9d
NS
2109 dump_type (typ, flags);
2110
4995028c
NS
2111 OB_FINISH ();
2112
2113 return (char *)obstack_base (&scratch_obstack);
8d08fdba
MS
2114}
2115
e1def31b 2116const char *
9e93bc9d
NS
2117expr_as_string (decl, flags)
2118 tree decl;
2119 enum tree_string_flags flags;
8d08fdba
MS
2120{
2121 OB_INIT ();
2122
9e93bc9d 2123 dump_expr (decl, flags);
8d08fdba
MS
2124
2125 OB_FINISH ();
2126
2127 return (char *)obstack_base (&scratch_obstack);
2128}
2129
e1def31b 2130const char *
9e93bc9d 2131decl_as_string (decl, flags)
8d08fdba 2132 tree decl;
9e93bc9d 2133 enum tree_string_flags flags;
8d08fdba
MS
2134{
2135 OB_INIT ();
2136
9e93bc9d 2137 dump_decl (decl, flags);
8d08fdba
MS
2138
2139 OB_FINISH ();
2140
2141 return (char *)obstack_base (&scratch_obstack);
2142}
2143
e1def31b 2144const char *
9e93bc9d
NS
2145context_as_string (context, flags)
2146 tree context;
2147 enum tree_string_flags flags;
8d08fdba
MS
2148{
2149 OB_INIT ();
9e93bc9d
NS
2150
2151 dump_scope (context, flags);
2152
8d08fdba
MS
2153 OB_FINISH ();
2154
2155 return (char *)obstack_base (&scratch_obstack);
2156}
2157
2ba25f50
MS
2158/* Generate the three forms of printable names for lang_printable_name. */
2159
e1def31b 2160const char *
2ba25f50
MS
2161lang_decl_name (decl, v)
2162 tree decl;
2163 int v;
2164{
2165 if (v >= 2)
9e93bc9d 2166 return decl_as_string (decl, TS_DECL_TYPE);
2ba25f50
MS
2167
2168 OB_INIT ();
2169
6eb3bb27 2170 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2ba25f50 2171 {
4f1c5b7d 2172 dump_type (CP_DECL_CONTEXT (decl), TS_PLAIN);
9e93bc9d 2173 OB_PUTS ("::");
2ba25f50
MS
2174 }
2175
2176 if (TREE_CODE (decl) == FUNCTION_DECL)
9e93bc9d 2177 dump_function_name (decl, TS_PLAIN);
2ba25f50 2178 else
9e93bc9d 2179 dump_decl (DECL_NAME (decl), TS_PLAIN);
2ba25f50
MS
2180
2181 OB_FINISH ();
2182
2183 return (char *)obstack_base (&scratch_obstack);
2184}
2ba25f50 2185
e1def31b 2186const char *
8d08fdba
MS
2187cp_file_of (t)
2188 tree t;
2189{
741f2839 2190 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
8d08fdba 2191 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2f939d94 2192 else if (TYPE_P (t))
d2e5ee5c 2193 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
8f032717
MM
2194 else if (TREE_CODE (t) == OVERLOAD)
2195 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
8d08fdba
MS
2196 else
2197 return DECL_SOURCE_FILE (t);
2198}
2199
2200int
2201cp_line_of (t)
2202 tree t;
2203{
f376e137 2204 int line = 0;
741f2839 2205 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
f376e137 2206 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
f3400fe2
JM
2207 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2208 && TYPE_MAIN_DECL (TREE_TYPE (t)))
f376e137
MS
2209 t = TREE_TYPE (t);
2210
2f939d94 2211 if (TYPE_P (t))
d2e5ee5c 2212 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
8f032717
MM
2213 else if (TREE_CODE (t) == OVERLOAD)
2214 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
8d08fdba 2215 else
f376e137
MS
2216 line = DECL_SOURCE_LINE (t);
2217
2218 if (line == 0)
2219 return lineno;
2220
2221 return line;
8d08fdba
MS
2222}
2223
9e93bc9d
NS
2224/* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2225 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2226 function. */
2227
2228static const char *
2229decl_to_string (decl, verbose)
2230 tree decl;
2231 int verbose;
2232{
2233 enum tree_string_flags flags = 0;
d67cdbc3 2234
9e93bc9d
NS
2235 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2236 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2237 flags = TS_AGGR_TAGS;
2238 if (verbose)
2239 flags |= TS_DECL_TYPE | TS_DECORATE | TS_PARM_DEFAULTS;
2240 else if (TREE_CODE (decl) == FUNCTION_DECL)
2241 flags |= TS_DECL_TYPE | TS_FUNC_NORETURN;
2242 flags |= TS_TEMPLATE_PREFIX;
2243
2244 OB_INIT ();
2245
2246 dump_decl (decl, flags);
2247
2248 OB_FINISH ();
2249
2250 return (char *)obstack_base (&scratch_obstack);
2251}
2252
2253static const char *
2254expr_to_string (decl, verbose)
2255 tree decl;
2256 int verbose ATTRIBUTE_UNUSED;
2257{
2258 OB_INIT ();
2259
2260 dump_expr (decl, 0);
2261
2262 OB_FINISH ();
2263
2264 return (char *)obstack_base (&scratch_obstack);
2265}
2266
2267static const char *
2268fndecl_to_string (fndecl, verbose)
2269 tree fndecl;
2270 int verbose;
2271{
2272 enum tree_string_flags flags;
2273
2274 flags = TS_FUNC_THROW | TS_DECL_TYPE;
2275 if (verbose)
2276 flags |= TS_PARM_DEFAULTS;
2277 OB_INIT ();
2278
2279 dump_decl (fndecl, flags);
2280
2281 OB_FINISH ();
2282
2283 return (char *)obstack_base (&scratch_obstack);
2284}
2285
2286
2287static const char *
2288code_to_string (c, v)
8d08fdba 2289 enum tree_code c;
7dee3f36 2290 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2291{
2292 return tree_code_name [c];
2293}
2294
421844e7 2295const char *
9e93bc9d 2296language_to_string (c, v)
8d08fdba 2297 enum languages c;
7dee3f36 2298 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2299{
2300 switch (c)
2301 {
2302 case lang_c:
2303 return "C";
2304
2305 case lang_cplusplus:
2306 return "C++";
2307
31b72b87
PB
2308 case lang_java:
2309 return "Java";
2310
8d08fdba
MS
2311 default:
2312 my_friendly_abort (355);
8926095f 2313 return 0;
8d08fdba
MS
2314 }
2315}
2316
2317/* Return the proper printed version of a parameter to a C++ function. */
e92cc029 2318
9e93bc9d
NS
2319static const char *
2320parm_to_string (p, v)
7dee3f36
KG
2321 int p;
2322 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2323{
2324 if (p < 0)
2325 return "`this'";
2326
2327 sprintf (digit_buffer, "%d", p+1);
2328 return digit_buffer;
2329}
2330
9e93bc9d
NS
2331static const char *
2332op_to_string (p, v)
8d08fdba 2333 enum tree_code p;
7dee3f36 2334 int v ATTRIBUTE_UNUSED;
8d08fdba 2335{
596ea4e5 2336 tree id;
8d08fdba 2337
596ea4e5
AS
2338 id = operator_name_info[(int) p].identifier;
2339 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
8d08fdba
MS
2340}
2341
9e93bc9d
NS
2342static const char *
2343type_to_string (typ, verbose)
2344 tree typ;
2345 int verbose;
2346{
2347 enum tree_string_flags flags;
2348
2349 flags = 0;
2350 if (verbose)
2351 flags |= TS_AGGR_TAGS;
2352 flags |= TS_TEMPLATE_PREFIX;
2353
2354 OB_INIT ();
2355
2356 dump_type (typ, flags);
2357
2358 OB_FINISH ();
2359
2360 return (char *)obstack_base (&scratch_obstack);
2361}
2362
2363static const char *
2364assop_to_string (p, v)
c91a56d2 2365 enum tree_code p;
7dee3f36 2366 int v ATTRIBUTE_UNUSED;
c91a56d2 2367{
596ea4e5 2368 tree id;
c91a56d2 2369
596ea4e5
AS
2370 id = assignment_operator_name_info[(int) p].identifier;
2371 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
c91a56d2
MS
2372}
2373
9e93bc9d
NS
2374static const char *
2375args_to_string (p, verbose)
8d08fdba 2376 tree p;
9e93bc9d 2377 int verbose;
8d08fdba 2378{
9e93bc9d
NS
2379 enum tree_string_flags flags = 0;
2380 if (verbose)
2381 flags |= TS_AGGR_TAGS;
2382
8d08fdba 2383 if (p == NULL_TREE)
c73964b2 2384 return "";
8d08fdba 2385
2f939d94 2386 if (TYPE_P (TREE_VALUE (p)))
9e93bc9d 2387 return type_as_string (p, flags);
c73964b2
MS
2388
2389 OB_INIT ();
2390 for (; p; p = TREE_CHAIN (p))
2391 {
a6967cc0
JM
2392 if (TREE_VALUE (p) == null_node)
2393 OB_PUTS ("NULL");
2394 else
9e93bc9d 2395 dump_type (error_type (TREE_VALUE (p)), flags);
c73964b2
MS
2396 if (TREE_CHAIN (p))
2397 OB_PUTS (", ");
2398 }
2399 OB_FINISH ();
2400 return (char *)obstack_base (&scratch_obstack);
8d08fdba 2401}
f30432d7 2402
9e93bc9d
NS
2403static const char *
2404cv_to_string (p, v)
f30432d7 2405 tree p;
7dee3f36 2406 int v ATTRIBUTE_UNUSED;
f30432d7
MS
2407{
2408 OB_INIT ();
2409
91063b51 2410 dump_qualifiers (p, before);
f30432d7
MS
2411
2412 OB_FINISH ();
2413
2414 return (char *)obstack_base (&scratch_obstack);
2415}
This page took 1.035666 seconds and 5 git commands to generate.