]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/error.c
Daily bump.
[gcc.git] / gcc / cp / error.c
CommitLineData
8d08fdba
MS
1/* Call-backs for C++ error reporting.
2 This code is non-reentrant.
faa25e97 3 Copyright (C) 1993, 94-97, 1998 Free Software Foundation, Inc.
8d08fdba
MS
4
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
MS
28
29typedef char* cp_printer ();
30
31#define A args_as_string
32#define C code_as_string
33#define D decl_as_string
34#define E expr_as_string
35#define L language_as_string
36#define O op_as_string
37#define P parm_as_string
c91a56d2 38#define Q assop_as_string
8d08fdba 39#define T type_as_string
f30432d7 40#define V cv_as_string
8d08fdba
MS
41
42#define _ (cp_printer *) 0
43cp_printer * cp_printers[256] =
44{
45/*0 1 2 3 4 5 6 7 8 9 A B C D E F */
46 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */
47 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */
48 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */
49 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */
50 _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */
c91a56d2 51 P, Q, _, _, T, _, V, _, _, _, _, _, _, _, _, _, /* 0x50 */
8d08fdba
MS
52 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */
53 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */
54};
55#undef C
56#undef D
57#undef E
58#undef L
59#undef O
60#undef P
c91a56d2 61#undef Q
8d08fdba 62#undef T
f30432d7 63#undef V
8d08fdba
MS
64#undef _
65
66#define obstack_chunk_alloc xmalloc
67#define obstack_chunk_free free
68
69/* Obstack where we build text strings for overloading, etc. */
70static struct obstack scratch_obstack;
71static char *scratch_firstobj;
72
73# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
74# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
75# define OB_PUTC2(C1,C2) \
76 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
77# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
78# define OB_PUTID(ID) \
79 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
80 IDENTIFIER_LENGTH (ID)))
81# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
82# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
83# define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
84 OB_PUTCP (digit_buffer); } while (0)
51c184be 85# define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
8d08fdba
MS
86
87# define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
88
49c249e1
JM
89enum pad { none, before, after };
90
91static void dump_type PROTO((tree, int));
294471c3 92static void dump_type_real PROTO((tree, int, int));
07389efe 93static void dump_simple_decl PROTO((tree, tree, int));
49c249e1
JM
94static void dump_decl PROTO((tree, int));
95static void dump_function_decl PROTO((tree, int));
96static void dump_expr PROTO((tree, int));
97static void dump_unary_op PROTO((char *, tree, int));
98static void dump_binary_op PROTO((char *, tree));
294471c3
MM
99static void dump_aggr_type PROTO((tree, int, int));
100static void dump_type_prefix PROTO((tree, int, int));
101static void dump_type_suffix PROTO((tree, int, int));
49c249e1
JM
102static void dump_function_name PROTO((tree));
103static void dump_expr_list PROTO((tree));
104static void dump_global_iord PROTO((tree));
105static void dump_readonly_or_volatile PROTO((tree, enum pad));
b2bb2710 106static void dump_char PROTO((int));
49c249e1
JM
107static char *aggr_variety PROTO((tree));
108static tree ident_fndecl PROTO((tree));
8d08fdba
MS
109
110void
111init_error ()
112{
113 gcc_obstack_init (&scratch_obstack);
114 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
115}
116
8d08fdba
MS
117static void
118dump_readonly_or_volatile (t, p)
119 tree t;
120 enum pad p;
121{
122 if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
123 {
124 if (p == before) OB_PUTC (' ');
125 if (TYPE_READONLY (t))
126 OB_PUTS ("const");
00595019
MS
127 if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
128 OB_PUTC (' ');
8d08fdba
MS
129 if (TYPE_VOLATILE (t))
130 OB_PUTS ("volatile");
131 if (p == after) OB_PUTC (' ');
132 }
133}
134
135/* This must be large enough to hold any printed integer or floating-point
136 value. */
137static char digit_buffer[128];
138
e92cc029
MS
139/* Dump into the obstack a human-readable equivalent of TYPE. */
140
8d08fdba 141static void
294471c3 142dump_type_real (t, v, canonical_name)
8d08fdba
MS
143 tree t;
144 int v; /* verbose? */
6df38d6d 145 int canonical_name;
8d08fdba
MS
146{
147 if (t == NULL_TREE)
148 return;
149
150 if (TYPE_PTRMEMFUNC_P (t))
151 goto offset_type;
152
153 switch (TREE_CODE (t))
154 {
155 case ERROR_MARK:
51c184be 156 OB_PUTS ("{error}");
8d08fdba
MS
157 break;
158
159 case UNKNOWN_TYPE:
51c184be 160 OB_PUTS ("{unknown type}");
8d08fdba
MS
161 break;
162
163 case TREE_LIST:
164 /* i.e. function taking no arguments */
165 if (t != void_list_node)
166 {
294471c3 167 dump_type_real (TREE_VALUE (t), v, canonical_name);
8d08fdba
MS
168 /* Can this happen other than for default arguments? */
169 if (TREE_PURPOSE (t) && v)
170 {
171 OB_PUTS (" = ");
49c249e1 172 dump_expr (TREE_PURPOSE (t), 0);
8d08fdba
MS
173 }
174 if (TREE_CHAIN (t))
175 {
176 if (TREE_CHAIN (t) != void_list_node)
177 {
178 OB_PUTC2 (',', ' ');
294471c3 179 dump_type_real (TREE_CHAIN (t), v, canonical_name);
8d08fdba
MS
180 }
181 }
182 else OB_PUTS (" ...");
183 }
184 break;
185
186 case IDENTIFIER_NODE:
187 OB_PUTID (t);
188 break;
189
190 case TREE_VEC:
294471c3 191 dump_type_real (BINFO_TYPE (t), v, canonical_name);
8d08fdba
MS
192 break;
193
194 case RECORD_TYPE:
195 case UNION_TYPE:
196 case ENUMERAL_TYPE:
197 if (TYPE_LANG_SPECIFIC (t)
198 && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
199 {
200 if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
49c249e1 201 dump_readonly_or_volatile (t, after);
294471c3 202 dump_type_real (SIGNATURE_TYPE (t), v, canonical_name);
8d08fdba
MS
203 if (IS_SIGNATURE_POINTER (t))
204 OB_PUTC ('*');
205 else
206 OB_PUTC ('&');
207 }
208 else
294471c3 209 dump_aggr_type (t, v, canonical_name);
8d08fdba
MS
210 break;
211
212 case TYPE_DECL:
67c2a928 213 case TEMPLATE_DECL:
7177d104 214 dump_decl (t, v);
8d08fdba
MS
215 break;
216
37c46b43
MS
217 case COMPLEX_TYPE:
218 OB_PUTS ("complex ");
294471c3 219 dump_type_real (TREE_TYPE (t), v, canonical_name);
37c46b43
MS
220 break;
221
8d08fdba
MS
222 case INTEGER_TYPE:
223 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
224 OB_PUTS ("unsigned ");
225 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
226 OB_PUTS ("signed ");
227
228 /* fall through. */
229 case REAL_TYPE:
230 case VOID_TYPE:
2986ae00 231 case BOOLEAN_TYPE:
8d08fdba 232 dump_readonly_or_volatile (t, after);
294471c3 233 OB_PUTID (TYPE_IDENTIFIER (canonical_name ? TYPE_MAIN_VARIANT (t) : t));
8d08fdba
MS
234 break;
235
73b0fce8
KL
236 case TEMPLATE_TEMPLATE_PARM:
237 if (!CLASSTYPE_TEMPLATE_INFO (t))
238 {
239 /* For parameters inside template signature. */
240 if (TYPE_IDENTIFIER (t))
241 OB_PUTID (TYPE_IDENTIFIER (t));
242 else
243 OB_PUTS ("{anonymous template template parm}");
244 }
245 else
246 {
247 int i;
248 tree args = CLASSTYPE_TI_ARGS (t);
249 OB_PUTID (TYPE_IDENTIFIER (t));
250 OB_PUTC ('<');
251 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
252 {
253 tree arg = TREE_VEC_ELT (args, i);
254 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
255 || TREE_CODE (arg) == TEMPLATE_DECL)
294471c3 256 dump_type_real (arg, 0, canonical_name);
73b0fce8
KL
257 else
258 dump_expr (arg, 0);
259 if (i < TREE_VEC_LENGTH (args)-1)
260 OB_PUTC2 (',', ' ');
261 }
262 OB_PUTC ('>');
263 }
264 break;
265
8d08fdba 266 case TEMPLATE_TYPE_PARM:
922ddba4 267 dump_readonly_or_volatile (t, after);
ec255269
MS
268 if (TYPE_IDENTIFIER (t))
269 OB_PUTID (TYPE_IDENTIFIER (t));
270 else
271 OB_PUTS ("{anonymous template type parm}");
8d08fdba
MS
272 break;
273
8d08fdba
MS
274 /* This is not always necessary for pointers and such, but doing this
275 reduces code size. */
276 case ARRAY_TYPE:
277 case POINTER_TYPE:
278 case REFERENCE_TYPE:
279 case OFFSET_TYPE:
280 offset_type:
281 case FUNCTION_TYPE:
282 case METHOD_TYPE:
294471c3
MM
283 dump_type_prefix (t, v, canonical_name);
284 dump_type_suffix (t, v, canonical_name);
8d08fdba
MS
285 break;
286
5566b478
MS
287 case TYPENAME_TYPE:
288 OB_PUTS ("typename ");
294471c3 289 dump_type_real (TYPE_CONTEXT (t), 0, canonical_name);
5566b478
MS
290 OB_PUTS ("::");
291 OB_PUTID (TYPE_IDENTIFIER (t));
292 break;
293
8d08fdba 294 default:
51c184be
MS
295 sorry ("`%s' not supported by dump_type",
296 tree_code_name[(int) TREE_CODE (t)]);
8d08fdba
MS
297 }
298}
299
51c184be
MS
300static char *
301aggr_variety (t)
8d08fdba 302 tree t;
8d08fdba 303{
8d08fdba 304 if (TREE_CODE (t) == ENUMERAL_TYPE)
51c184be 305 return "enum";
8d08fdba 306 else if (TREE_CODE (t) == UNION_TYPE)
51c184be 307 return "union";
8d08fdba 308 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
51c184be 309 return "class";
8d08fdba 310 else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
51c184be 311 return "signature";
8d08fdba 312 else
51c184be
MS
313 return "struct";
314}
315
294471c3
MM
316static void
317dump_type (t, v)
318 tree t;
319 int v; /* verbose? */
320{
321 dump_type_real (t, v, 0);
322}
323
e92cc029
MS
324/* Print out a class declaration, in the form `class foo'. */
325
51c184be 326static void
294471c3 327dump_aggr_type (t, v, canonical_name)
51c184be
MS
328 tree t;
329 int v; /* verbose? */
294471c3 330 int canonical_name;
51c184be
MS
331{
332 tree name;
333 char *variety = aggr_variety (t);
8d08fdba
MS
334
335 dump_readonly_or_volatile (t, after);
336
337 if (v > 0)
338 {
339 OB_PUTCP (variety);
340 OB_PUTC (' ');
341 }
342
294471c3 343 name = TYPE_NAME (canonical_name ? TYPE_MAIN_VARIANT (t) : t);
8d08fdba 344
2c73f9f5 345 if (name && DECL_CONTEXT (name) && DECL_CONTEXT (name) != global_namespace)
8d08fdba
MS
346 {
347 /* FUNCTION_DECL or RECORD_TYPE */
348 dump_decl (DECL_CONTEXT (name), 0);
349 OB_PUTC2 (':', ':');
350 }
351
ddd5a7c1 352 /* kludge around weird behavior on g++.brendan/line1.C */
f30432d7 353 if (name && TREE_CODE (name) != IDENTIFIER_NODE)
8d08fdba
MS
354 name = DECL_NAME (name);
355
f30432d7 356 if (name == 0 || ANON_AGGRNAME_P (name))
8d08fdba 357 {
51c184be 358 OB_PUTS ("{anonymous");
8d08fdba
MS
359 if (!v)
360 {
361 OB_PUTC (' ');
362 OB_PUTCP (variety);
363 }
51c184be 364 OB_PUTC ('}');
8d08fdba
MS
365 }
366 else
367 OB_PUTID (name);
368}
369
370/* Dump into the obstack the initial part of the output for a given type.
371 This is necessary when dealing with things like functions returning
372 functions. Examples:
373
374 return type of `int (* fee ())()': pointer -> function -> int. Both
375 pointer (and reference and offset) and function (and member) types must
376 deal with prefix and suffix.
377
378 Arrays must also do this for DECL nodes, like int a[], and for things like
379 int *[]&. */
380
381static void
294471c3 382dump_type_prefix (t, v, canonical_name)
8d08fdba
MS
383 tree t;
384 int v; /* verbosity */
294471c3 385 int canonical_name;
8d08fdba
MS
386{
387 if (TYPE_PTRMEMFUNC_P (t))
388 {
389 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
390 goto offset_type;
391 }
392
393 switch (TREE_CODE (t))
394 {
395 case POINTER_TYPE:
396 {
397 tree sub = TREE_TYPE (t);
398
294471c3 399 dump_type_prefix (sub, v, canonical_name);
8d08fdba
MS
400 /* A tree for a member pointer looks like pointer to offset,
401 so let the OFFSET_TYPE case handle it. */
402 if (TREE_CODE (sub) != OFFSET_TYPE)
403 {
404 switch (TREE_CODE (sub))
405 {
406 /* We don't want int ( *)() */
407 case FUNCTION_TYPE:
408 case METHOD_TYPE:
409 break;
410
39211cd5
MS
411 case ARRAY_TYPE:
412 OB_PUTC2 (' ', '(');
413 break;
414
8d08fdba
MS
415 case POINTER_TYPE:
416 /* We don't want "char * *" */
417 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
418 break;
419 /* But we do want "char *const *" */
420
421 default:
422 OB_PUTC (' ');
423 }
424 OB_PUTC ('*');
425 dump_readonly_or_volatile (t, none);
426 }
427 }
428 break;
429
430 case REFERENCE_TYPE:
431 {
432 tree sub = TREE_TYPE (t);
294471c3 433 dump_type_prefix (sub, v, canonical_name);
8d08fdba
MS
434
435 switch (TREE_CODE (sub))
436 {
2986ae00
MS
437 case ARRAY_TYPE:
438 OB_PUTC2 (' ', '(');
439 break;
440
8d08fdba
MS
441 case POINTER_TYPE:
442 /* We don't want "char * &" */
443 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
444 break;
445 /* But we do want "char *const &" */
446
447 default:
448 OB_PUTC (' ');
449 }
450 }
451 OB_PUTC ('&');
452 dump_readonly_or_volatile (t, none);
453 break;
454
455 case OFFSET_TYPE:
456 offset_type:
294471c3 457 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
51c184be
MS
458 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
459 {
460 OB_PUTC (' ');
294471c3 461 dump_type_real (TYPE_OFFSET_BASETYPE (t), 0, canonical_name);
51c184be
MS
462 OB_PUTC2 (':', ':');
463 }
8d08fdba
MS
464 OB_PUTC ('*');
465 dump_readonly_or_volatile (t, none);
466 break;
467
468 /* Can only be reached through function pointer -- this would not be
469 correct if FUNCTION_DECLs used it. */
470 case FUNCTION_TYPE:
294471c3 471 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
8d08fdba
MS
472 OB_PUTC2 (' ', '(');
473 break;
474
475 case METHOD_TYPE:
294471c3 476 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
8d08fdba 477 OB_PUTC2 (' ', '(');
294471c3 478 dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0, canonical_name);
8d08fdba
MS
479 OB_PUTC2 (':', ':');
480 break;
481
482 case ARRAY_TYPE:
294471c3 483 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
8d08fdba
MS
484 break;
485
486 case ENUMERAL_TYPE:
487 case ERROR_MARK:
488 case IDENTIFIER_NODE:
489 case INTEGER_TYPE:
2986ae00 490 case BOOLEAN_TYPE:
8d08fdba
MS
491 case REAL_TYPE:
492 case RECORD_TYPE:
493 case TEMPLATE_TYPE_PARM:
73b0fce8 494 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
495 case TREE_LIST:
496 case TYPE_DECL:
497 case TREE_VEC:
8d08fdba
MS
498 case UNION_TYPE:
499 case UNKNOWN_TYPE:
500 case VOID_TYPE:
5566b478 501 case TYPENAME_TYPE:
37c46b43 502 case COMPLEX_TYPE:
294471c3 503 dump_type_real (t, v, canonical_name);
8d08fdba
MS
504 break;
505
506 default:
51c184be
MS
507 sorry ("`%s' not supported by dump_type_prefix",
508 tree_code_name[(int) TREE_CODE (t)]);
8d08fdba
MS
509 }
510}
511
512static void
294471c3 513dump_type_suffix (t, v, canonical_name)
8d08fdba
MS
514 tree t;
515 int v; /* verbose? */
294471c3 516 int canonical_name;
8d08fdba
MS
517{
518 if (TYPE_PTRMEMFUNC_P (t))
519 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
520
521 switch (TREE_CODE (t))
522 {
523 case POINTER_TYPE:
524 case REFERENCE_TYPE:
525 case OFFSET_TYPE:
39211cd5
MS
526 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
527 OB_PUTC (')');
294471c3 528 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
8d08fdba
MS
529 break;
530
531 /* Can only be reached through function pointer */
532 case FUNCTION_TYPE:
533 case METHOD_TYPE:
534 {
535 tree arg;
536 OB_PUTC2 (')', '(');
537 arg = TYPE_ARG_TYPES (t);
538 if (TREE_CODE (t) == METHOD_TYPE)
539 arg = TREE_CHAIN (arg);
540
541 if (arg)
542 dump_type (arg, v);
543 else
544 OB_PUTS ("...");
545 OB_PUTC (')');
546 if (TREE_CODE (t) == METHOD_TYPE)
547 dump_readonly_or_volatile
548 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
294471c3 549 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
8d08fdba
MS
550 break;
551 }
552
553 case ARRAY_TYPE:
554 OB_PUTC ('[');
555 if (TYPE_DOMAIN (t))
5156628f
MS
556 {
557 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
558 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
559 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
560 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0), 0);
561 else
562 dump_expr (fold (build_binary_op
563 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
564 integer_one_node, 1)), 0);
565 }
8d08fdba 566 OB_PUTC (']');
294471c3 567 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
8d08fdba
MS
568 break;
569
570 case ENUMERAL_TYPE:
571 case ERROR_MARK:
572 case IDENTIFIER_NODE:
573 case INTEGER_TYPE:
2986ae00 574 case BOOLEAN_TYPE:
8d08fdba
MS
575 case REAL_TYPE:
576 case RECORD_TYPE:
577 case TEMPLATE_TYPE_PARM:
73b0fce8 578 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
579 case TREE_LIST:
580 case TYPE_DECL:
581 case TREE_VEC:
8d08fdba
MS
582 case UNION_TYPE:
583 case UNKNOWN_TYPE:
584 case VOID_TYPE:
5566b478 585 case TYPENAME_TYPE:
37c46b43 586 case COMPLEX_TYPE:
8d08fdba
MS
587 break;
588
589 default:
51c184be
MS
590 sorry ("`%s' not supported by dump_type_suffix",
591 tree_code_name[(int) TREE_CODE (t)]);
8d08fdba
MS
592 }
593}
594
595/* Return a function declaration which corresponds to the IDENTIFIER_NODE
596 argument. */
e92cc029 597
49c249e1 598static tree
8d08fdba
MS
599ident_fndecl (t)
600 tree t;
601{
700f8a87 602 tree n = lookup_name (t, 0);
8d08fdba 603
f30432d7
MS
604 if (n == NULL_TREE)
605 return NULL_TREE;
606
8d08fdba
MS
607 if (TREE_CODE (n) == FUNCTION_DECL)
608 return n;
609 else if (TREE_CODE (n) == TREE_LIST
610 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
611 return TREE_VALUE (n);
8926095f
MS
612
613 my_friendly_abort (66);
614 return NULL_TREE;
8d08fdba
MS
615}
616
617#ifndef NO_DOLLAR_IN_LABEL
618# define GLOBAL_THING "_GLOBAL_$"
619#else
620# ifndef NO_DOT_IN_LABEL
621# define GLOBAL_THING "_GLOBAL_."
622# else
623# define GLOBAL_THING "_GLOBAL__"
624# endif
625#endif
626
627#define GLOBAL_IORD_P(NODE) \
fc378698 628 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
8d08fdba 629
49c249e1 630static void
8d08fdba
MS
631dump_global_iord (t)
632 tree t;
633{
634 char *name = IDENTIFIER_POINTER (t);
635
636 OB_PUTS ("(static ");
637 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
638 OB_PUTS ("initializers");
639 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
640 OB_PUTS ("destructors");
641 else
642 my_friendly_abort (352);
643
644 OB_PUTS (" for ");
645 OB_PUTCP (input_filename);
646 OB_PUTC (')');
647}
648
07389efe
MM
649static void
650dump_simple_decl (t, type, v)
651 tree t;
652 tree type;
653 int v;
654{
655 if (v > 0)
656 {
657 dump_type_prefix (type, v, 0);
658 OB_PUTC (' ');
659 dump_readonly_or_volatile (t, after);
660 }
6eb3bb27 661 if (DECL_CLASS_SCOPE_P (t))
07389efe
MM
662 {
663 dump_type (DECL_CONTEXT (t), 0);
664 OB_PUTC2 (':', ':');
665 }
666 if (DECL_NAME (t))
667 dump_decl (DECL_NAME (t), v);
668 else
669 OB_PUTS ("{anon}");
670 if (v > 0)
671 dump_type_suffix (type, v, 0);
672}
673
8d08fdba
MS
674static void
675dump_decl (t, v)
676 tree t;
677 int v; /* verbosity */
678{
679 if (t == NULL_TREE)
680 return;
681
682 switch (TREE_CODE (t))
683 {
684 case ERROR_MARK:
685 OB_PUTS (" /* decl error */ ");
686 break;
687
7177d104 688 case TYPE_DECL:
8d2733ca
MS
689 {
690 /* Don't say 'typedef class A' */
fc378698 691 if (DECL_ARTIFICIAL (t))
8d2733ca 692 {
a9936d39
MM
693 if (v > 0 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
694 /* Say `class T' not just `T'. */
695 OB_PUTS ("class ");
696
fc378698 697 dump_type (TREE_TYPE (t), v);
8d2733ca
MS
698 break;
699 }
700 }
701 if (v > 0)
702 OB_PUTS ("typedef ");
07389efe
MM
703 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
704 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), v);
7177d104
MS
705 break;
706
8d08fdba 707 case VAR_DECL:
b7484fbe 708 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
8d08fdba
MS
709 {
710 OB_PUTS ("vtable for ");
711 dump_type (DECL_CONTEXT (t), v);
712 break;
713 }
714 /* else fall through */
715 case FIELD_DECL:
716 case PARM_DECL:
07389efe 717 dump_simple_decl (t, TREE_TYPE (t), v);
8d08fdba
MS
718 break;
719
a9aedbc2 720 case NAMESPACE_DECL:
2c73f9f5 721 if (DECL_CONTEXT (t) != global_namespace)
30394414 722 {
2c73f9f5 723 dump_decl (DECL_CONTEXT (t), v);
30394414
JM
724 OB_PUTC2 (':',':');
725 }
a9aedbc2
MS
726 OB_PUTID (DECL_NAME (t));
727 break;
728
8d08fdba
MS
729 case ARRAY_REF:
730 dump_decl (TREE_OPERAND (t, 0), v);
731 OB_PUTC ('[');
732 dump_decl (TREE_OPERAND (t, 1), v);
733 OB_PUTC (']');
734 break;
735
736 /* So that we can do dump_decl in dump_aggr_type and have it work for
737 both class and function scope. */
738 case RECORD_TYPE:
739 case UNION_TYPE:
740 case ENUMERAL_TYPE:
741 dump_type (t, v);
742 break;
743
8d08fdba
MS
744 case TYPE_EXPR:
745 my_friendly_abort (69);
746 break;
747
748 /* These special cases are duplicated here so that other functions
e92cc029 749 can feed identifiers to cp_error and get them demangled properly. */
8d08fdba 750 case IDENTIFIER_NODE:
f30432d7
MS
751 { tree f;
752 if (DESTRUCTOR_NAME_P (t)
753 && (f = ident_fndecl (t))
754 && DECL_LANGUAGE (f) == lang_cplusplus)
755 {
756 OB_PUTC ('~');
757 dump_decl (DECL_NAME (f), 0);
758 }
759 else if (IDENTIFIER_TYPENAME_P (t))
760 {
761 OB_PUTS ("operator ");
762 /* Not exactly IDENTIFIER_TYPE_VALUE. */
763 dump_type (TREE_TYPE (t), 0);
764 break;
765 }
766 else if (IDENTIFIER_OPNAME_P (t))
767 {
768 char *name_string = operator_name_string (t);
769 OB_PUTS ("operator ");
770 OB_PUTCP (name_string);
771 }
772 else
773 OB_PUTID (t);
774 }
8d08fdba
MS
775 break;
776
777 case FUNCTION_DECL:
778 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
779 dump_global_iord (DECL_ASSEMBLER_NAME (t));
da20811c
JM
780 else if (! DECL_LANG_SPECIFIC (t))
781 OB_PUTS ("{internal}");
8d08fdba
MS
782 else
783 dump_function_decl (t, v);
784 break;
785
786 case TEMPLATE_DECL:
51c184be 787 {
98c1c668
JM
788 tree orig_args = DECL_TEMPLATE_PARMS (t);
789 tree args;
790 int i;
791 for (args = orig_args = nreverse (orig_args);
792 args;
793 args = TREE_CHAIN (args))
51c184be 794 {
98c1c668 795 int len = TREE_VEC_LENGTH (TREE_VALUE (args));
a292b002 796
98c1c668
JM
797 OB_PUTS ("template <");
798 for (i = 0; i < len; i++)
a292b002 799 {
98c1c668
JM
800 tree arg = TREE_VEC_ELT (TREE_VALUE (args), i);
801 tree defval = TREE_PURPOSE (arg);
802 arg = TREE_VALUE (arg);
803 if (TREE_CODE (arg) == TYPE_DECL)
804 {
73b0fce8 805 if (DECL_NAME (arg))
b7a29012
JM
806 {
807 OB_PUTS ("class ");
808 OB_PUTID (DECL_NAME (arg));
809 }
73b0fce8 810 else
b7a29012 811 OB_PUTS ("class");
98c1c668
JM
812 }
813 else
814 dump_decl (arg, 1);
815
816 if (defval)
817 {
818 OB_PUTS (" = ");
e7e66632
KL
819 if (TREE_CODE (arg) == TYPE_DECL
820 || TREE_CODE (arg) == TEMPLATE_DECL)
67c2a928
JM
821 dump_type (defval, 1);
822 else
e7e66632 823 dump_expr (defval, 1);
98c1c668 824 }
a292b002 825
98c1c668
JM
826 OB_PUTC2 (',', ' ');
827 }
828 if (len != 0)
829 OB_UNPUT (2);
830 OB_PUTC2 ('>', ' ');
51c184be 831 }
98c1c668 832 nreverse(orig_args);
8d08fdba 833
5566b478
MS
834 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
835 dump_type (TREE_TYPE (t), v);
6467930b
MS
836 else if (TREE_TYPE (t) == NULL_TREE)
837 my_friendly_abort (353);
51c184be
MS
838 else switch (NEXT_CODE (t))
839 {
840 case METHOD_TYPE:
841 case FUNCTION_TYPE:
842 dump_function_decl (t, v);
843 break;
844
845 default:
abff8e06
JM
846 /* This case can occur with some illegal code. */
847 dump_type (TREE_TYPE (t), v);
51c184be
MS
848 }
849 }
8d08fdba
MS
850 break;
851
74cd8397
JM
852 case TEMPLATE_ID_EXPR:
853 {
854 tree args;
aa36c081
JM
855 tree name = TREE_OPERAND (t, 0);
856 if (is_overloaded_fn (name))
857 name = DECL_NAME (get_first_fn (name));
858 dump_decl (name, v);
74cd8397
JM
859 OB_PUTC ('<');
860 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
861 {
73b0fce8
KL
862 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't'
863 || TREE_CODE (TREE_VALUE (args)) == TEMPLATE_DECL)
74cd8397
JM
864 dump_type (TREE_VALUE (args), 0);
865 else
866 dump_expr (TREE_VALUE (args), 0);
867 if (TREE_CHAIN (args))
868 OB_PUTC2 (',', ' ');
869 }
870 OB_PUTC ('>');
871 }
872 break;
873
0fb9f1c3 874 case LOOKUP_EXPR:
f9d94ea4 875 dump_decl (TREE_OPERAND (t, 0), v);
0fb9f1c3
JM
876 break;
877
8d08fdba
MS
878 case LABEL_DECL:
879 OB_PUTID (DECL_NAME (t));
880 break;
881
882 case CONST_DECL:
6467930b 883 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
03555413 884 || (DECL_INITIAL (t) &&
f84b4be9 885 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
07389efe 886 dump_simple_decl (t, TREE_TYPE (t), v);
224c649b
BH
887 else if (DECL_NAME (t))
888 dump_decl (DECL_NAME (t), v);
03555413 889 else if (DECL_INITIAL (t))
8d08fdba 890 dump_expr (DECL_INITIAL (t), 0);
03555413
MM
891 else
892 OB_PUTS ("enumerator");
8d08fdba
MS
893 break;
894
cffa8729
MS
895 case USING_DECL:
896 OB_PUTS ("using ");
897 dump_type (DECL_INITIAL (t), 0);
898 OB_PUTS ("::");
899 OB_PUTID (DECL_NAME (t));
900 break;
901
8d08fdba 902 default:
51c184be
MS
903 sorry ("`%s' not supported by dump_decl",
904 tree_code_name[(int) TREE_CODE (t)]);
8d08fdba
MS
905 }
906}
907
908/* Pretty printing for announce_function. T is the declaration of the
909 function we are interested in seeing. V is non-zero if we should print
910 the type that this function returns. */
911
912static void
913dump_function_decl (t, v)
914 tree t;
915 int v;
916{
98c1c668
JM
917 tree name;
918 tree fntype;
919 tree parmtypes;
8d08fdba 920 tree cname = NULL_TREE;
8d08fdba 921
98c1c668
JM
922 if (TREE_CODE (t) == TEMPLATE_DECL)
923 t = DECL_TEMPLATE_RESULT (t);
924
925 name = DECL_ASSEMBLER_NAME (t);
926 fntype = TREE_TYPE (t);
927 parmtypes = TYPE_ARG_TYPES (fntype);
928
8d08fdba
MS
929 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
930 if (DECL_CONTEXT (t))
931 cname = DECL_CLASS_CONTEXT (t);
932 /* this is for partially instantiated template methods */
933 else if (TREE_CODE (fntype) == METHOD_TYPE)
934 cname = TREE_TYPE (TREE_VALUE (parmtypes));
935
936 v = (v > 0);
937
938 if (v)
939 {
940 if (DECL_STATIC_FUNCTION_P (t))
941 OB_PUTS ("static ");
942
943 if (! IDENTIFIER_TYPENAME_P (name)
944 && ! DECL_CONSTRUCTOR_P (t)
945 && ! DESTRUCTOR_NAME_P (name))
946 {
294471c3 947 dump_type_prefix (TREE_TYPE (fntype), 1, 0);
8d08fdba
MS
948 OB_PUTC (' ');
949 }
950 }
951
952 if (cname)
953 {
954 dump_type (cname, 0);
955 OB_PUTC2 (':', ':');
956 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
957 parmtypes = TREE_CHAIN (parmtypes);
958 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
959 /* Skip past "in_charge" identifier. */
960 parmtypes = TREE_CHAIN (parmtypes);
961 }
962
f30432d7 963 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
8d08fdba
MS
964 parmtypes = TREE_CHAIN (parmtypes);
965
966 dump_function_name (t);
967
968 OB_PUTC ('(');
969
970 if (parmtypes)
971 dump_type (parmtypes, v);
972 else
973 OB_PUTS ("...");
974
975 OB_PUTC (')');
976
977 if (v && ! IDENTIFIER_TYPENAME_P (name))
294471c3 978 dump_type_suffix (TREE_TYPE (fntype), 1, 0);
8d08fdba
MS
979
980 if (TREE_CODE (fntype) == METHOD_TYPE)
981 {
982 if (IS_SIGNATURE (cname))
983 /* We look at the type pointed to by the `optr' field of `this.' */
984 dump_readonly_or_volatile
985 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
986 else
987 dump_readonly_or_volatile
988 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
989 }
990}
991
992/* Handle the function name for a FUNCTION_DECL node, grokking operators
993 and destructors properly. */
e92cc029 994
8d08fdba
MS
995static void
996dump_function_name (t)
997 tree t;
998{
999 tree name = DECL_NAME (t);
1000
1001 /* There ought to be a better way to find out whether or not something is
1002 a destructor. */
f30432d7
MS
1003 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
1004 && DECL_LANGUAGE (t) == lang_cplusplus)
8d08fdba
MS
1005 {
1006 OB_PUTC ('~');
1007 dump_decl (name, 0);
1008 }
1009 else if (IDENTIFIER_TYPENAME_P (name))
1010 {
1011 /* This cannot use the hack that the operator's return
1012 type is stashed off of its name because it may be
1013 used for error reporting. In the case of conflicting
1014 declarations, both will have the same name, yet
1015 the types will be different, hence the TREE_TYPE field
1016 of the first name will be clobbered by the second. */
1017 OB_PUTS ("operator ");
1018 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1019 }
1020 else if (IDENTIFIER_OPNAME_P (name))
1021 {
1022 char *name_string = operator_name_string (name);
1023 OB_PUTS ("operator ");
1024 OB_PUTCP (name_string);
1025 }
1026 else
1027 dump_decl (name, 0);
386b8a85 1028
75650646 1029 if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t))
386b8a85 1030 {
75650646
MM
1031 tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE;
1032
1033 if (args != NULL_TREE
1034 && DECL_CONTEXT (t) != NULL_TREE
1035 && uses_template_parms (DECL_CONTEXT (t))
1036 /* This next clause checks that there is only one level of
1037 template arguments. In that case, they are the
1038 arguments for the class context. */
1039 && (TREE_CODE (args) == TREE_LIST
1040 || (TREE_CODE (args) == TREE_VEC
1041 && TREE_VEC_ELT (args, 0) != NULL_TREE
1042 && TREE_CODE (TREE_VEC_ELT (args, 0)) != TREE_VEC)))
1043 /* We have something like this:
1044
1045 template <class T> struct S { void f(); };
1046
1047 and we are printing S<int>::f(). This is a template
1048 instantiation, but we don't print anything after the f. */
1049 ;
1050 else
386b8a85 1051 {
75650646 1052 OB_PUTC ('<');
386b8a85 1053
75650646
MM
1054 /* Be careful only to print things when we have them, so as not
1055 to crash producing error messages. */
1056 if (args)
1057 {
1058 if (TREE_CODE (args) == TREE_LIST)
386b8a85 1059 {
75650646
MM
1060 tree arg;
1061 int need_comma = 0;
386b8a85 1062
75650646 1063 for (arg = args; arg; arg = TREE_CHAIN (arg))
386b8a85 1064 {
75650646
MM
1065 tree a = TREE_VALUE (arg);
1066
1067 if (need_comma)
1068 OB_PUTS (", ");
1069
1070 if (a)
1071 {
73b0fce8
KL
1072 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1073 || TREE_CODE (a) == TEMPLATE_DECL)
75650646
MM
1074 dump_type (a, 0);
1075 else
1076 dump_expr (a, 0);
1077 }
386b8a85 1078
75650646
MM
1079 need_comma = 1;
1080 }
386b8a85 1081 }
75650646 1082 else if (TREE_CODE (args) == TREE_VEC)
386b8a85 1083 {
75650646
MM
1084 int i;
1085 int need_comma = 0;
386b8a85 1086
75650646
MM
1087 if (TREE_VEC_LENGTH (args) > 0
1088 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1089 args = TREE_VEC_ELT (args,
1090 TREE_VEC_LENGTH (args) - 1);
386b8a85 1091
75650646 1092 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
386b8a85 1093 {
75650646
MM
1094 tree a = TREE_VEC_ELT (args, i);
1095
1096 if (need_comma)
1097 OB_PUTS (", ");
1098
1099 if (a)
1100 {
73b0fce8
KL
1101 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1102 || TREE_CODE (a) == TEMPLATE_DECL)
75650646
MM
1103 dump_type (a, 0);
1104 else
1105 dump_expr (a, 0);
1106 }
386b8a85 1107
75650646
MM
1108 need_comma = 1;
1109 }
386b8a85
JM
1110 }
1111 }
75650646 1112 OB_PUTC ('>');
386b8a85 1113 }
386b8a85 1114 }
8d08fdba
MS
1115}
1116
1117static void
1118dump_char (c)
b2bb2710 1119 int c;
8d08fdba
MS
1120{
1121 switch (c)
1122 {
a0a33927 1123 case TARGET_NEWLINE:
8d08fdba
MS
1124 OB_PUTS ("\\n");
1125 break;
a0a33927 1126 case TARGET_TAB:
8d08fdba
MS
1127 OB_PUTS ("\\t");
1128 break;
a0a33927 1129 case TARGET_VT:
8d08fdba
MS
1130 OB_PUTS ("\\v");
1131 break;
a0a33927 1132 case TARGET_BS:
8d08fdba
MS
1133 OB_PUTS ("\\b");
1134 break;
a0a33927 1135 case TARGET_CR:
8d08fdba
MS
1136 OB_PUTS ("\\r");
1137 break;
a0a33927 1138 case TARGET_FF:
8d08fdba
MS
1139 OB_PUTS ("\\f");
1140 break;
a0a33927 1141 case TARGET_BELL:
8d08fdba
MS
1142 OB_PUTS ("\\a");
1143 break;
1144 case '\\':
1145 OB_PUTS ("\\\\");
1146 break;
1147 case '\'':
1148 OB_PUTS ("\\'");
1149 break;
1150 case '\"':
1151 OB_PUTS ("\\\"");
1152 break;
1153 default:
faa25e97 1154 if (ISPRINT (c))
8d08fdba
MS
1155 OB_PUTC (c);
1156 else
1157 {
1158 sprintf (digit_buffer, "\\%03o", (int) c);
1159 OB_PUTCP (digit_buffer);
1160 }
1161 }
1162}
1163
1164/* Print out a list of initializers (subr of dump_expr) */
e92cc029 1165
8d08fdba
MS
1166static void
1167dump_expr_list (l)
1168 tree l;
1169{
1170 while (l)
1171 {
1172 dump_expr (TREE_VALUE (l), 0);
1173 if (TREE_CHAIN (l))
1174 OB_PUTC2 (',', ' ');
1175 l = TREE_CHAIN (l);
1176 }
1177}
1178
1179/* Print out an expression */
e92cc029 1180
8d08fdba
MS
1181static void
1182dump_expr (t, nop)
1183 tree t;
1184 int nop; /* suppress parens */
1185{
1186 switch (TREE_CODE (t))
1187 {
1188 case VAR_DECL:
1189 case PARM_DECL:
1190 case FIELD_DECL:
1191 case CONST_DECL:
1192 case FUNCTION_DECL:
ec255269 1193 case TEMPLATE_DECL:
6b57ac29 1194 case NAMESPACE_DECL:
8d08fdba
MS
1195 dump_decl (t, -1);
1196 break;
1197
1198 case INTEGER_CST:
1199 {
1200 tree type = TREE_TYPE (t);
1201 my_friendly_assert (type != 0, 81);
1202
1203 /* If it's an enum, output its tag, rather than its value. */
1204 if (TREE_CODE (type) == ENUMERAL_TYPE)
1205 {
1206 char *p = enum_name_string (t, type);
1207 OB_PUTCP (p);
1208 }
b7484fbe
MS
1209 else if (type == boolean_type_node)
1210 {
72b7eeff
MS
1211 if (t == boolean_false_node
1212 || (TREE_INT_CST_LOW (t) == 0
1213 && TREE_INT_CST_HIGH (t) == 0))
b7484fbe
MS
1214 OB_PUTS ("false");
1215 else if (t == boolean_true_node)
1216 OB_PUTS ("true");
b7484fbe
MS
1217 }
1218 else if (type == char_type_node)
8d08fdba
MS
1219 {
1220 OB_PUTC ('\'');
1221 dump_char (TREE_INT_CST_LOW (t));
1222 OB_PUTC ('\'');
1223 }
1224 else if (TREE_INT_CST_HIGH (t)
1225 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1226 {
1227 tree val = t;
1228 if (TREE_INT_CST_HIGH (val) < 0)
1229 {
1230 OB_PUTC ('-');
1231 val = build_int_2 (~TREE_INT_CST_LOW (val),
1232 -TREE_INT_CST_HIGH (val));
1233 }
1234 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1235 systems? */
1236 {
1237 static char format[10]; /* "%x%09999x\0" */
1238 if (!format[0])
1239 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1240 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1241 TREE_INT_CST_LOW (val));
1242 OB_PUTCP (digit_buffer);
1243 }
1244 }
1245 else
1246 OB_PUTI (TREE_INT_CST_LOW (t));
1247 }
1248 break;
1249
1250 case REAL_CST:
1251#ifndef REAL_IS_NOT_DOUBLE
1252 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1253#else
1254 {
1255 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
a703fb38 1256 size_t i;
8d08fdba
MS
1257 strcpy (digit_buffer, "0x");
1258 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1259 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1260 }
1261#endif
1262 OB_PUTCP (digit_buffer);
1263 break;
1264
1265 case STRING_CST:
1266 {
1267 char *p = TREE_STRING_POINTER (t);
1268 int len = TREE_STRING_LENGTH (t) - 1;
1269 int i;
1270
1271 OB_PUTC ('\"');
1272 for (i = 0; i < len; i++)
1273 dump_char (p[i]);
1274 OB_PUTC ('\"');
1275 }
1276 break;
1277
1278 case COMPOUND_EXPR:
1279 dump_binary_op (",", t);
1280 break;
1281
1282 case COND_EXPR:
1283 OB_PUTC ('(');
1284 dump_expr (TREE_OPERAND (t, 0), 0);
1285 OB_PUTS (" ? ");
1286 dump_expr (TREE_OPERAND (t, 1), 0);
1287 OB_PUTS (" : ");
1288 dump_expr (TREE_OPERAND (t, 2), 0);
1289 OB_PUTC (')');
1290 break;
1291
1292 case SAVE_EXPR:
1293 if (TREE_HAS_CONSTRUCTOR (t))
1294 {
1295 OB_PUTS ("new ");
1296 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1297 PARM_DECL_EXPR (t) = 1;
1298 }
1299 else
1300 {
6060a796 1301 dump_expr (TREE_OPERAND (t, 0), 0);
8d08fdba
MS
1302 }
1303 break;
1304
02531345 1305 case AGGR_INIT_EXPR:
8d08fdba
MS
1306 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1307 OB_PUTC ('(');
42976354
BK
1308 if (TREE_OPERAND (t, 1))
1309 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
8d08fdba
MS
1310 OB_PUTC (')');
1311 break;
1312
1313 case CALL_EXPR:
1314 {
1315 tree fn = TREE_OPERAND (t, 0);
1316 tree args = TREE_OPERAND (t, 1);
1317
1318 if (TREE_CODE (fn) == ADDR_EXPR)
1319 fn = TREE_OPERAND (fn, 0);
1320
6467930b 1321 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
8d08fdba
MS
1322 {
1323 tree ob = TREE_VALUE (args);
1324 if (TREE_CODE (ob) == ADDR_EXPR)
1325 {
1326 dump_expr (TREE_OPERAND (ob, 0), 0);
1327 OB_PUTC ('.');
1328 }
1329 else if (TREE_CODE (ob) != PARM_DECL
1330 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1331 {
1332 dump_expr (ob, 0);
1333 OB_PUTC2 ('-', '>');
1334 }
1335 args = TREE_CHAIN (args);
1336 }
1337 dump_expr (fn, 0);
fc378698 1338 OB_PUTC ('(');
8d08fdba
MS
1339 dump_expr_list (args);
1340 OB_PUTC (')');
1341 }
1342 break;
1343
8d08fdba
MS
1344 case TARGET_EXPR:
1345 /* Note that this only works for G++ target exprs. If somebody
1346 builds a general TARGET_EXPR, there's no way to represent that
1347 it initializes anything other that the parameter slot for the
1348 default argument. Note we may have cleared out the first
1349 operand in expand_expr, so don't go killing ourselves. */
1350 if (TREE_OPERAND (t, 1))
1351 dump_expr (TREE_OPERAND (t, 1), 0);
1352 break;
1353
1354 case MODIFY_EXPR:
1355 case PLUS_EXPR:
1356 case MINUS_EXPR:
1357 case MULT_EXPR:
1358 case TRUNC_DIV_EXPR:
1359 case TRUNC_MOD_EXPR:
1360 case MIN_EXPR:
1361 case MAX_EXPR:
1362 case LSHIFT_EXPR:
1363 case RSHIFT_EXPR:
1364 case BIT_IOR_EXPR:
1365 case BIT_XOR_EXPR:
1366 case BIT_AND_EXPR:
1367 case BIT_ANDTC_EXPR:
1368 case TRUTH_ANDIF_EXPR:
1369 case TRUTH_ORIF_EXPR:
1370 case LT_EXPR:
1371 case LE_EXPR:
1372 case GT_EXPR:
1373 case GE_EXPR:
1374 case EQ_EXPR:
1375 case NE_EXPR:
1376 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1377 break;
1378
1379 case CEIL_DIV_EXPR:
1380 case FLOOR_DIV_EXPR:
1381 case ROUND_DIV_EXPR:
1382 dump_binary_op ("/", t);
1383 break;
1384
1385 case CEIL_MOD_EXPR:
1386 case FLOOR_MOD_EXPR:
1387 case ROUND_MOD_EXPR:
1388 dump_binary_op ("%", t);
1389 break;
1390
1391 case COMPONENT_REF:
1392 {
1393 tree ob = TREE_OPERAND (t, 0);
1394 if (TREE_CODE (ob) == INDIRECT_REF)
1395 {
1396 ob = TREE_OPERAND (ob, 0);
1397 if (TREE_CODE (ob) != PARM_DECL
1398 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1399 {
1400 dump_expr (ob, 0);
1401 OB_PUTC2 ('-', '>');
1402 }
1403 }
1404 else
1405 {
1406 dump_expr (ob, 0);
1407 OB_PUTC ('.');
1408 }
1409 dump_expr (TREE_OPERAND (t, 1), 1);
1410 }
1411 break;
1412
28cbf42c
MS
1413 case ARRAY_REF:
1414 dump_expr (TREE_OPERAND (t, 0), 0);
1415 OB_PUTC ('[');
1416 dump_expr (TREE_OPERAND (t, 1), 0);
1417 OB_PUTC (']');
1418 break;
1419
8d08fdba
MS
1420 case CONVERT_EXPR:
1421 dump_unary_op ("+", t, nop);
1422 break;
1423
1424 case ADDR_EXPR:
1425 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1426 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1427 dump_expr (TREE_OPERAND (t, 0), 0);
1428 else
1429 dump_unary_op ("&", t, nop);
1430 break;
1431
1432 case INDIRECT_REF:
1433 if (TREE_HAS_CONSTRUCTOR (t))
1434 {
1435 t = TREE_OPERAND (t, 0);
1436 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1437 dump_expr (TREE_OPERAND (t, 0), 0);
1438 OB_PUTC ('(');
1439 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1440 OB_PUTC (')');
1441 }
1442 else
1443 {
6467930b
MS
1444 if (TREE_OPERAND (t,0) != NULL_TREE
1445 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
8d08fdba
MS
1446 dump_expr (TREE_OPERAND (t, 0), nop);
1447 else
1448 dump_unary_op ("*", t, nop);
1449 }
1450 break;
1451
1452 case NEGATE_EXPR:
1453 case BIT_NOT_EXPR:
1454 case TRUTH_NOT_EXPR:
1455 case PREDECREMENT_EXPR:
1456 case PREINCREMENT_EXPR:
1457 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1458 break;
1459
1460 case POSTDECREMENT_EXPR:
1461 case POSTINCREMENT_EXPR:
1462 OB_PUTC ('(');
1463 dump_expr (TREE_OPERAND (t, 0), 0);
1464 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1465 OB_PUTC (')');
1466 break;
1467
1468 case NON_LVALUE_EXPR:
1469 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1470 should be another level of INDIRECT_REF so that I don't have to do
1471 this. */
6467930b 1472 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
8d08fdba
MS
1473 {
1474 tree next = TREE_TYPE (TREE_TYPE (t));
1475
1476 while (TREE_CODE (next) == POINTER_TYPE)
1477 next = TREE_TYPE (next);
1478
1479 if (TREE_CODE (next) == FUNCTION_TYPE)
1480 {
1481 if (!nop) OB_PUTC ('(');
1482 OB_PUTC ('*');
1483 dump_expr (TREE_OPERAND (t, 0), 1);
1484 if (!nop) OB_PUTC (')');
1485 break;
1486 }
1487 /* else FALLTHRU */
1488 }
1489 dump_expr (TREE_OPERAND (t, 0), 0);
1490 break;
1491
1492 case NOP_EXPR:
1493 dump_expr (TREE_OPERAND (t, 0), nop);
1494 break;
1495
1496 case CONSTRUCTOR:
9a3b49ac
MS
1497 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1498 {
1499 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1500
1501 if (integer_all_onesp (idx))
1502 {
1503 tree pfn = PFN_FROM_PTRMEMFUNC (t);
49c249e1 1504 dump_expr (pfn, 0);
9a3b49ac
MS
1505 break;
1506 }
1507 if (TREE_CODE (idx) == INTEGER_CST
1508 && TREE_INT_CST_HIGH (idx) == 0)
1509 {
1510 tree virtuals;
1511 unsigned HOST_WIDE_INT n;
1512
1513 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1514 t = TYPE_METHOD_BASETYPE (t);
1515 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1516
1517 n = TREE_INT_CST_LOW (idx);
1518
1519 /* Map vtable index back one, to allow for the null pointer to
1520 member. */
1521 --n;
1522
1523 while (n > 0 && virtuals)
1524 {
1525 --n;
1526 virtuals = TREE_CHAIN (virtuals);
1527 }
1528 if (virtuals)
1529 {
49c249e1 1530 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
9a3b49ac
MS
1531 break;
1532 }
1533 }
1534 }
8d08fdba 1535 OB_PUTC ('{');
6467930b 1536 dump_expr_list (CONSTRUCTOR_ELTS (t));
8d08fdba
MS
1537 OB_PUTC ('}');
1538 break;
1539
51c184be
MS
1540 case OFFSET_REF:
1541 {
1542 tree ob = TREE_OPERAND (t, 0);
1543 if (TREE_CODE (ob) == NOP_EXPR
1544 && TREE_OPERAND (ob, 0) == error_mark_node
1545 && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1546 /* A::f */
1547 dump_expr (TREE_OPERAND (t, 1), 0);
1548 else
1549 {
4ac14744
MS
1550 dump_expr (TREE_OPERAND (t, 0), 0);
1551 OB_PUTS (" .* ");
1552 dump_expr (TREE_OPERAND (t, 1), 0);
51c184be
MS
1553 }
1554 break;
1555 }
1556
f84b4be9 1557 case TEMPLATE_PARM_INDEX:
050367a3 1558 dump_decl (TEMPLATE_PARM_DECL (t), -1);
de22184b 1559 break;
5566b478
MS
1560
1561 case IDENTIFIER_NODE:
1562 OB_PUTID (t);
1563 break;
1564
1565 case SCOPE_REF:
1566 dump_type (TREE_OPERAND (t, 0), 0);
1567 OB_PUTS ("::");
1568 dump_expr (TREE_OPERAND (t, 1), 0);
1569 break;
1570
1571 case CAST_EXPR:
e349ee73
MS
1572 if (TREE_OPERAND (t, 0) == NULL_TREE
1573 || TREE_CHAIN (TREE_OPERAND (t, 0)))
e76a2646
MS
1574 {
1575 dump_type (TREE_TYPE (t), 0);
1576 OB_PUTC ('(');
6467930b 1577 dump_expr_list (TREE_OPERAND (t, 0));
e76a2646
MS
1578 OB_PUTC (')');
1579 }
1580 else
1581 {
1582 OB_PUTC ('(');
1583 dump_type (TREE_TYPE (t), 0);
1584 OB_PUTC (')');
1585 OB_PUTC ('(');
1586 dump_expr_list (TREE_OPERAND (t, 0));
1587 OB_PUTC (')');
1588 }
1589 break;
1590
1591 case LOOKUP_EXPR:
1592 OB_PUTID (TREE_OPERAND (t, 0));
1593 break;
1594
5a11e05b
BK
1595 case ARROW_EXPR:
1596 dump_expr (TREE_OPERAND (t, 0), nop);
1597 OB_PUTS ("->");
1598 break;
1599
e76a2646 1600 case SIZEOF_EXPR:
abff8e06
JM
1601 case ALIGNOF_EXPR:
1602 if (TREE_CODE (t) == SIZEOF_EXPR)
1603 OB_PUTS ("sizeof (");
1604 else
1605 {
1606 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1607 OB_PUTS ("__alignof__ (");
1608 }
e76a2646
MS
1609 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1610 dump_type (TREE_OPERAND (t, 0), 0);
1611 else
1612 dump_unary_op ("*", t, 0);
1613 OB_PUTC (')');
1614 break;
5566b478 1615
da20811c
JM
1616 case DEFAULT_ARG:
1617 OB_PUTS ("{unparsed}");
1618 break;
1619
6748b643
JM
1620 case TRY_CATCH_EXPR:
1621 case WITH_CLEANUP_EXPR:
1622 case CLEANUP_POINT_EXPR:
1623 dump_expr (TREE_OPERAND (t, 0), nop);
1624 break;
1625
00595019
MS
1626 case TREE_LIST:
1627 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1628 {
1629 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1630 break;
1631 }
1632 /* else fall through */
1633
8d08fdba
MS
1634 /* This list is incomplete, but should suffice for now.
1635 It is very important that `sorry' does not call
1636 `report_error_function'. That could cause an infinite loop. */
1637 default:
1638 sorry ("`%s' not supported by dump_expr",
1639 tree_code_name[(int) TREE_CODE (t)]);
1640
1641 /* fall through to ERROR_MARK... */
1642 case ERROR_MARK:
51c184be 1643 OB_PUTCP ("{error}");
8d08fdba
MS
1644 break;
1645 }
1646}
1647
1648static void
1649dump_binary_op (opstring, t)
1650 char *opstring;
1651 tree t;
1652{
1653 OB_PUTC ('(');
1654 dump_expr (TREE_OPERAND (t, 0), 1);
1655 OB_PUTC (' ');
1656 OB_PUTCP (opstring);
1657 OB_PUTC (' ');
1658 dump_expr (TREE_OPERAND (t, 1), 1);
1659 OB_PUTC (')');
1660}
1661
1662static void
1663dump_unary_op (opstring, t, nop)
1664 char *opstring;
1665 tree t;
1666 int nop;
1667{
1668 if (!nop) OB_PUTC ('(');
1669 OB_PUTCP (opstring);
1670 dump_expr (TREE_OPERAND (t, 0), 1);
1671 if (!nop) OB_PUTC (')');
1672}
1673
1674char *
5566b478
MS
1675fndecl_as_string (fndecl, print_ret_type_p)
1676 tree fndecl;
8d08fdba
MS
1677 int print_ret_type_p;
1678{
1679 return decl_as_string (fndecl, print_ret_type_p);
1680}
1681
e1467ff2 1682/* Same, but handle a _TYPE.
8d08fdba 1683 Called from convert_to_reference, mangle_class_name_for_template,
294471c3
MM
1684 build_unary_op, and GNU_xref_decl. If CANONICAL_NAME is non-zero,
1685 when describing a typedef, we use the name of the type described,
1686 rather than the name of the typedef. */
e92cc029 1687
8d08fdba 1688char *
294471c3 1689type_as_string_real (typ, v, canonical_name)
8d08fdba
MS
1690 tree typ;
1691 int v;
294471c3 1692 int canonical_name;
8d08fdba
MS
1693{
1694 OB_INIT ();
1695
294471c3 1696 dump_type_real (typ, v, canonical_name);
8d08fdba
MS
1697
1698 OB_FINISH ();
1699
1700 return (char *)obstack_base (&scratch_obstack);
1701}
1702
294471c3
MM
1703
1704char *
1705type_as_string (typ, v)
1706 tree typ;
1707 int v;
1708{
1709 return type_as_string_real (typ, v, 0);
1710}
1711
8d08fdba
MS
1712char *
1713expr_as_string (decl, v)
1714 tree decl;
7dee3f36 1715 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
1716{
1717 OB_INIT ();
1718
1719 dump_expr (decl, 1);
1720
1721 OB_FINISH ();
1722
1723 return (char *)obstack_base (&scratch_obstack);
1724}
1725
1726/* A cross between type_as_string and fndecl_as_string.
1727 Only called from substitute_nice_name. */
e92cc029 1728
8d08fdba
MS
1729char *
1730decl_as_string (decl, v)
1731 tree decl;
1732 int v;
1733{
1734 OB_INIT ();
1735
1736 dump_decl (decl, v);
1737
1738 OB_FINISH ();
1739
1740 return (char *)obstack_base (&scratch_obstack);
1741}
1742
2ba25f50
MS
1743/* Generate the three forms of printable names for lang_printable_name. */
1744
1745char *
1746lang_decl_name (decl, v)
1747 tree decl;
1748 int v;
1749{
1750 if (v >= 2)
1751 return decl_as_string (decl, 1);
1752
1753 OB_INIT ();
1754
6eb3bb27 1755 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2ba25f50
MS
1756 {
1757 tree cname;
1758 if (TREE_CODE (decl) == FUNCTION_DECL)
1759 cname = DECL_CLASS_CONTEXT (decl);
1760 else
1761 cname = DECL_CONTEXT (decl);
1762 dump_type (cname, 0);
1763 OB_PUTC2 (':', ':');
1764 }
1765
1766 if (TREE_CODE (decl) == FUNCTION_DECL)
1767 dump_function_name (decl);
1768 else
1769 dump_decl (DECL_NAME (decl), 0);
1770
1771 OB_FINISH ();
1772
1773 return (char *)obstack_base (&scratch_obstack);
1774}
1775
1776
8d08fdba
MS
1777char *
1778cp_file_of (t)
1779 tree t;
1780{
1781 if (TREE_CODE (t) == PARM_DECL)
1782 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1783 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 1784 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
8d08fdba
MS
1785 else
1786 return DECL_SOURCE_FILE (t);
1787}
1788
1789int
1790cp_line_of (t)
1791 tree t;
1792{
f376e137 1793 int line = 0;
8d08fdba 1794 if (TREE_CODE (t) == PARM_DECL)
f376e137
MS
1795 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1796 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
1797 t = TREE_TYPE (t);
1798
1799 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 1800 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
8d08fdba 1801 else
f376e137
MS
1802 line = DECL_SOURCE_LINE (t);
1803
1804 if (line == 0)
1805 return lineno;
1806
1807 return line;
8d08fdba
MS
1808}
1809
1810char *
1811code_as_string (c, v)
1812 enum tree_code c;
7dee3f36 1813 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
1814{
1815 return tree_code_name [c];
1816}
1817
1818char *
1819language_as_string (c, v)
1820 enum languages c;
7dee3f36 1821 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
1822{
1823 switch (c)
1824 {
1825 case lang_c:
1826 return "C";
1827
1828 case lang_cplusplus:
1829 return "C++";
1830
31b72b87
PB
1831 case lang_java:
1832 return "Java";
1833
8d08fdba
MS
1834 default:
1835 my_friendly_abort (355);
8926095f 1836 return 0;
8d08fdba
MS
1837 }
1838}
1839
1840/* Return the proper printed version of a parameter to a C++ function. */
e92cc029 1841
8d08fdba
MS
1842char *
1843parm_as_string (p, v)
7dee3f36
KG
1844 int p;
1845 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
1846{
1847 if (p < 0)
1848 return "`this'";
1849
1850 sprintf (digit_buffer, "%d", p+1);
1851 return digit_buffer;
1852}
1853
1854char *
1855op_as_string (p, v)
1856 enum tree_code p;
7dee3f36 1857 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
1858{
1859 static char buf[] = "operator ";
1860
1861 if (p == 0)
51c184be 1862 return "{unknown}";
8d08fdba
MS
1863
1864 strcpy (buf + 9, opname_tab [p]);
1865 return buf;
1866}
1867
c91a56d2
MS
1868char *
1869assop_as_string (p, v)
1870 enum tree_code p;
7dee3f36 1871 int v ATTRIBUTE_UNUSED;
c91a56d2
MS
1872{
1873 static char buf[] = "operator ";
1874
1875 if (p == 0)
1876 return "{unknown}";
1877
1878 strcpy (buf + 9, assignop_tab [p]);
1879 return buf;
1880}
1881
8d08fdba
MS
1882char *
1883args_as_string (p, v)
1884 tree p;
1885 int v;
1886{
1887 if (p == NULL_TREE)
c73964b2 1888 return "";
8d08fdba 1889
c73964b2
MS
1890 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1891 return type_as_string (p, v);
1892
1893 OB_INIT ();
1894 for (; p; p = TREE_CHAIN (p))
1895 {
a6967cc0
JM
1896 if (TREE_VALUE (p) == null_node)
1897 OB_PUTS ("NULL");
1898 else
1899 dump_type (error_type (TREE_VALUE (p)), v);
c73964b2
MS
1900 if (TREE_CHAIN (p))
1901 OB_PUTS (", ");
1902 }
1903 OB_FINISH ();
1904 return (char *)obstack_base (&scratch_obstack);
8d08fdba 1905}
f30432d7
MS
1906
1907char *
1908cv_as_string (p, v)
1909 tree p;
7dee3f36 1910 int v ATTRIBUTE_UNUSED;
f30432d7
MS
1911{
1912 OB_INIT ();
1913
1914 dump_readonly_or_volatile (p, before);
1915
1916 OB_FINISH ();
1917
1918 return (char *)obstack_base (&scratch_obstack);
1919}
This page took 0.518674 seconds and 5 git commands to generate.