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