]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/error.c
class.c (grow_method): Remove check for redeclaration.
[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));
104static void dump_char PROTO((char));
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)
5566b478 785 || TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM)
8d2733ca 786 goto general;
8d08fdba
MS
787 else
788 dump_expr (DECL_INITIAL (t), 0);
789 break;
790
cffa8729
MS
791 case USING_DECL:
792 OB_PUTS ("using ");
793 dump_type (DECL_INITIAL (t), 0);
794 OB_PUTS ("::");
795 OB_PUTID (DECL_NAME (t));
796 break;
797
8d08fdba 798 default:
51c184be
MS
799 sorry ("`%s' not supported by dump_decl",
800 tree_code_name[(int) TREE_CODE (t)]);
8d08fdba
MS
801 }
802}
803
804/* Pretty printing for announce_function. T is the declaration of the
805 function we are interested in seeing. V is non-zero if we should print
806 the type that this function returns. */
807
808static void
809dump_function_decl (t, v)
810 tree t;
811 int v;
812{
98c1c668
JM
813 tree name;
814 tree fntype;
815 tree parmtypes;
8d08fdba 816 tree cname = NULL_TREE;
8d08fdba 817
98c1c668
JM
818 if (TREE_CODE (t) == TEMPLATE_DECL)
819 t = DECL_TEMPLATE_RESULT (t);
820
821 name = DECL_ASSEMBLER_NAME (t);
822 fntype = TREE_TYPE (t);
823 parmtypes = TYPE_ARG_TYPES (fntype);
824
8d08fdba
MS
825 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
826 if (DECL_CONTEXT (t))
827 cname = DECL_CLASS_CONTEXT (t);
828 /* this is for partially instantiated template methods */
829 else if (TREE_CODE (fntype) == METHOD_TYPE)
830 cname = TREE_TYPE (TREE_VALUE (parmtypes));
831
832 v = (v > 0);
833
834 if (v)
835 {
836 if (DECL_STATIC_FUNCTION_P (t))
837 OB_PUTS ("static ");
838
839 if (! IDENTIFIER_TYPENAME_P (name)
840 && ! DECL_CONSTRUCTOR_P (t)
841 && ! DESTRUCTOR_NAME_P (name))
842 {
843 dump_type_prefix (TREE_TYPE (fntype), 1);
844 OB_PUTC (' ');
845 }
846 }
847
848 if (cname)
849 {
850 dump_type (cname, 0);
851 OB_PUTC2 (':', ':');
852 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
853 parmtypes = TREE_CHAIN (parmtypes);
854 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
855 /* Skip past "in_charge" identifier. */
856 parmtypes = TREE_CHAIN (parmtypes);
857 }
858
f30432d7 859 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
8d08fdba
MS
860 parmtypes = TREE_CHAIN (parmtypes);
861
862 dump_function_name (t);
863
864 OB_PUTC ('(');
865
866 if (parmtypes)
867 dump_type (parmtypes, v);
868 else
869 OB_PUTS ("...");
870
871 OB_PUTC (')');
872
873 if (v && ! IDENTIFIER_TYPENAME_P (name))
874 dump_type_suffix (TREE_TYPE (fntype), 1);
875
876 if (TREE_CODE (fntype) == METHOD_TYPE)
877 {
878 if (IS_SIGNATURE (cname))
879 /* We look at the type pointed to by the `optr' field of `this.' */
880 dump_readonly_or_volatile
881 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
882 else
883 dump_readonly_or_volatile
884 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
885 }
886}
887
888/* Handle the function name for a FUNCTION_DECL node, grokking operators
889 and destructors properly. */
e92cc029 890
8d08fdba
MS
891static void
892dump_function_name (t)
893 tree t;
894{
895 tree name = DECL_NAME (t);
896
897 /* There ought to be a better way to find out whether or not something is
898 a destructor. */
f30432d7
MS
899 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
900 && DECL_LANGUAGE (t) == lang_cplusplus)
8d08fdba
MS
901 {
902 OB_PUTC ('~');
903 dump_decl (name, 0);
904 }
905 else if (IDENTIFIER_TYPENAME_P (name))
906 {
907 /* This cannot use the hack that the operator's return
908 type is stashed off of its name because it may be
909 used for error reporting. In the case of conflicting
910 declarations, both will have the same name, yet
911 the types will be different, hence the TREE_TYPE field
912 of the first name will be clobbered by the second. */
913 OB_PUTS ("operator ");
914 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
915 }
916 else if (IDENTIFIER_OPNAME_P (name))
917 {
918 char *name_string = operator_name_string (name);
919 OB_PUTS ("operator ");
920 OB_PUTCP (name_string);
921 }
922 else
923 dump_decl (name, 0);
924}
925
926static void
927dump_char (c)
928 char c;
929{
930 switch (c)
931 {
a0a33927 932 case TARGET_NEWLINE:
8d08fdba
MS
933 OB_PUTS ("\\n");
934 break;
a0a33927 935 case TARGET_TAB:
8d08fdba
MS
936 OB_PUTS ("\\t");
937 break;
a0a33927 938 case TARGET_VT:
8d08fdba
MS
939 OB_PUTS ("\\v");
940 break;
a0a33927 941 case TARGET_BS:
8d08fdba
MS
942 OB_PUTS ("\\b");
943 break;
a0a33927 944 case TARGET_CR:
8d08fdba
MS
945 OB_PUTS ("\\r");
946 break;
a0a33927 947 case TARGET_FF:
8d08fdba
MS
948 OB_PUTS ("\\f");
949 break;
a0a33927 950 case TARGET_BELL:
8d08fdba
MS
951 OB_PUTS ("\\a");
952 break;
953 case '\\':
954 OB_PUTS ("\\\\");
955 break;
956 case '\'':
957 OB_PUTS ("\\'");
958 break;
959 case '\"':
960 OB_PUTS ("\\\"");
961 break;
962 default:
963 if (isprint (c))
964 OB_PUTC (c);
965 else
966 {
967 sprintf (digit_buffer, "\\%03o", (int) c);
968 OB_PUTCP (digit_buffer);
969 }
970 }
971}
972
973/* Print out a list of initializers (subr of dump_expr) */
e92cc029 974
8d08fdba
MS
975static void
976dump_expr_list (l)
977 tree l;
978{
979 while (l)
980 {
981 dump_expr (TREE_VALUE (l), 0);
982 if (TREE_CHAIN (l))
983 OB_PUTC2 (',', ' ');
984 l = TREE_CHAIN (l);
985 }
986}
987
988/* Print out an expression */
e92cc029 989
8d08fdba
MS
990static void
991dump_expr (t, nop)
992 tree t;
993 int nop; /* suppress parens */
994{
995 switch (TREE_CODE (t))
996 {
997 case VAR_DECL:
998 case PARM_DECL:
999 case FIELD_DECL:
1000 case CONST_DECL:
1001 case FUNCTION_DECL:
ec255269 1002 case TEMPLATE_DECL:
8d08fdba
MS
1003 dump_decl (t, -1);
1004 break;
1005
1006 case INTEGER_CST:
1007 {
1008 tree type = TREE_TYPE (t);
1009 my_friendly_assert (type != 0, 81);
1010
1011 /* If it's an enum, output its tag, rather than its value. */
1012 if (TREE_CODE (type) == ENUMERAL_TYPE)
1013 {
1014 char *p = enum_name_string (t, type);
1015 OB_PUTCP (p);
1016 }
b7484fbe
MS
1017 else if (type == boolean_type_node)
1018 {
72b7eeff
MS
1019 if (t == boolean_false_node
1020 || (TREE_INT_CST_LOW (t) == 0
1021 && TREE_INT_CST_HIGH (t) == 0))
b7484fbe
MS
1022 OB_PUTS ("false");
1023 else if (t == boolean_true_node)
1024 OB_PUTS ("true");
b7484fbe
MS
1025 }
1026 else if (type == char_type_node)
8d08fdba
MS
1027 {
1028 OB_PUTC ('\'');
1029 dump_char (TREE_INT_CST_LOW (t));
1030 OB_PUTC ('\'');
1031 }
1032 else if (TREE_INT_CST_HIGH (t)
1033 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1034 {
1035 tree val = t;
1036 if (TREE_INT_CST_HIGH (val) < 0)
1037 {
1038 OB_PUTC ('-');
1039 val = build_int_2 (~TREE_INT_CST_LOW (val),
1040 -TREE_INT_CST_HIGH (val));
1041 }
1042 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1043 systems? */
1044 {
1045 static char format[10]; /* "%x%09999x\0" */
1046 if (!format[0])
1047 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1048 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1049 TREE_INT_CST_LOW (val));
1050 OB_PUTCP (digit_buffer);
1051 }
1052 }
1053 else
1054 OB_PUTI (TREE_INT_CST_LOW (t));
1055 }
1056 break;
1057
1058 case REAL_CST:
1059#ifndef REAL_IS_NOT_DOUBLE
1060 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1061#else
1062 {
1063 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1064 int i;
1065 strcpy (digit_buffer, "0x");
1066 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1067 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1068 }
1069#endif
1070 OB_PUTCP (digit_buffer);
1071 break;
1072
1073 case STRING_CST:
1074 {
1075 char *p = TREE_STRING_POINTER (t);
1076 int len = TREE_STRING_LENGTH (t) - 1;
1077 int i;
1078
1079 OB_PUTC ('\"');
1080 for (i = 0; i < len; i++)
1081 dump_char (p[i]);
1082 OB_PUTC ('\"');
1083 }
1084 break;
1085
1086 case COMPOUND_EXPR:
1087 dump_binary_op (",", t);
1088 break;
1089
1090 case COND_EXPR:
1091 OB_PUTC ('(');
1092 dump_expr (TREE_OPERAND (t, 0), 0);
1093 OB_PUTS (" ? ");
1094 dump_expr (TREE_OPERAND (t, 1), 0);
1095 OB_PUTS (" : ");
1096 dump_expr (TREE_OPERAND (t, 2), 0);
1097 OB_PUTC (')');
1098 break;
1099
1100 case SAVE_EXPR:
1101 if (TREE_HAS_CONSTRUCTOR (t))
1102 {
1103 OB_PUTS ("new ");
1104 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1105 PARM_DECL_EXPR (t) = 1;
1106 }
1107 else
1108 {
6060a796 1109 dump_expr (TREE_OPERAND (t, 0), 0);
8d08fdba
MS
1110 }
1111 break;
1112
1113 case NEW_EXPR:
1114 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1115 OB_PUTC ('(');
42976354
BK
1116 if (TREE_OPERAND (t, 1))
1117 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
8d08fdba
MS
1118 OB_PUTC (')');
1119 break;
1120
1121 case CALL_EXPR:
1122 {
1123 tree fn = TREE_OPERAND (t, 0);
1124 tree args = TREE_OPERAND (t, 1);
1125
1126 if (TREE_CODE (fn) == ADDR_EXPR)
1127 fn = TREE_OPERAND (fn, 0);
1128
6467930b 1129 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
8d08fdba
MS
1130 {
1131 tree ob = TREE_VALUE (args);
1132 if (TREE_CODE (ob) == ADDR_EXPR)
1133 {
1134 dump_expr (TREE_OPERAND (ob, 0), 0);
1135 OB_PUTC ('.');
1136 }
1137 else if (TREE_CODE (ob) != PARM_DECL
1138 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1139 {
1140 dump_expr (ob, 0);
1141 OB_PUTC2 ('-', '>');
1142 }
1143 args = TREE_CHAIN (args);
1144 }
1145 dump_expr (fn, 0);
fc378698 1146 OB_PUTC ('(');
8d08fdba
MS
1147 dump_expr_list (args);
1148 OB_PUTC (')');
1149 }
1150 break;
1151
8d08fdba
MS
1152 case TARGET_EXPR:
1153 /* Note that this only works for G++ target exprs. If somebody
1154 builds a general TARGET_EXPR, there's no way to represent that
1155 it initializes anything other that the parameter slot for the
1156 default argument. Note we may have cleared out the first
1157 operand in expand_expr, so don't go killing ourselves. */
1158 if (TREE_OPERAND (t, 1))
1159 dump_expr (TREE_OPERAND (t, 1), 0);
1160 break;
1161
1162 case MODIFY_EXPR:
1163 case PLUS_EXPR:
1164 case MINUS_EXPR:
1165 case MULT_EXPR:
1166 case TRUNC_DIV_EXPR:
1167 case TRUNC_MOD_EXPR:
1168 case MIN_EXPR:
1169 case MAX_EXPR:
1170 case LSHIFT_EXPR:
1171 case RSHIFT_EXPR:
1172 case BIT_IOR_EXPR:
1173 case BIT_XOR_EXPR:
1174 case BIT_AND_EXPR:
1175 case BIT_ANDTC_EXPR:
1176 case TRUTH_ANDIF_EXPR:
1177 case TRUTH_ORIF_EXPR:
1178 case LT_EXPR:
1179 case LE_EXPR:
1180 case GT_EXPR:
1181 case GE_EXPR:
1182 case EQ_EXPR:
1183 case NE_EXPR:
1184 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1185 break;
1186
1187 case CEIL_DIV_EXPR:
1188 case FLOOR_DIV_EXPR:
1189 case ROUND_DIV_EXPR:
1190 dump_binary_op ("/", t);
1191 break;
1192
1193 case CEIL_MOD_EXPR:
1194 case FLOOR_MOD_EXPR:
1195 case ROUND_MOD_EXPR:
1196 dump_binary_op ("%", t);
1197 break;
1198
1199 case COMPONENT_REF:
1200 {
1201 tree ob = TREE_OPERAND (t, 0);
1202 if (TREE_CODE (ob) == INDIRECT_REF)
1203 {
1204 ob = TREE_OPERAND (ob, 0);
1205 if (TREE_CODE (ob) != PARM_DECL
1206 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1207 {
1208 dump_expr (ob, 0);
1209 OB_PUTC2 ('-', '>');
1210 }
1211 }
1212 else
1213 {
1214 dump_expr (ob, 0);
1215 OB_PUTC ('.');
1216 }
1217 dump_expr (TREE_OPERAND (t, 1), 1);
1218 }
1219 break;
1220
28cbf42c
MS
1221 case ARRAY_REF:
1222 dump_expr (TREE_OPERAND (t, 0), 0);
1223 OB_PUTC ('[');
1224 dump_expr (TREE_OPERAND (t, 1), 0);
1225 OB_PUTC (']');
1226 break;
1227
8d08fdba
MS
1228 case CONVERT_EXPR:
1229 dump_unary_op ("+", t, nop);
1230 break;
1231
1232 case ADDR_EXPR:
1233 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1234 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1235 dump_expr (TREE_OPERAND (t, 0), 0);
1236 else
1237 dump_unary_op ("&", t, nop);
1238 break;
1239
1240 case INDIRECT_REF:
1241 if (TREE_HAS_CONSTRUCTOR (t))
1242 {
1243 t = TREE_OPERAND (t, 0);
1244 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1245 dump_expr (TREE_OPERAND (t, 0), 0);
1246 OB_PUTC ('(');
1247 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1248 OB_PUTC (')');
1249 }
1250 else
1251 {
6467930b
MS
1252 if (TREE_OPERAND (t,0) != NULL_TREE
1253 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
8d08fdba
MS
1254 dump_expr (TREE_OPERAND (t, 0), nop);
1255 else
1256 dump_unary_op ("*", t, nop);
1257 }
1258 break;
1259
1260 case NEGATE_EXPR:
1261 case BIT_NOT_EXPR:
1262 case TRUTH_NOT_EXPR:
1263 case PREDECREMENT_EXPR:
1264 case PREINCREMENT_EXPR:
1265 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1266 break;
1267
1268 case POSTDECREMENT_EXPR:
1269 case POSTINCREMENT_EXPR:
1270 OB_PUTC ('(');
1271 dump_expr (TREE_OPERAND (t, 0), 0);
1272 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1273 OB_PUTC (')');
1274 break;
1275
1276 case NON_LVALUE_EXPR:
1277 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1278 should be another level of INDIRECT_REF so that I don't have to do
1279 this. */
6467930b 1280 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
8d08fdba
MS
1281 {
1282 tree next = TREE_TYPE (TREE_TYPE (t));
1283
1284 while (TREE_CODE (next) == POINTER_TYPE)
1285 next = TREE_TYPE (next);
1286
1287 if (TREE_CODE (next) == FUNCTION_TYPE)
1288 {
1289 if (!nop) OB_PUTC ('(');
1290 OB_PUTC ('*');
1291 dump_expr (TREE_OPERAND (t, 0), 1);
1292 if (!nop) OB_PUTC (')');
1293 break;
1294 }
1295 /* else FALLTHRU */
1296 }
1297 dump_expr (TREE_OPERAND (t, 0), 0);
1298 break;
1299
1300 case NOP_EXPR:
1301 dump_expr (TREE_OPERAND (t, 0), nop);
1302 break;
1303
1304 case CONSTRUCTOR:
9a3b49ac
MS
1305 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1306 {
1307 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1308
1309 if (integer_all_onesp (idx))
1310 {
1311 tree pfn = PFN_FROM_PTRMEMFUNC (t);
49c249e1 1312 dump_expr (pfn, 0);
9a3b49ac
MS
1313 break;
1314 }
1315 if (TREE_CODE (idx) == INTEGER_CST
1316 && TREE_INT_CST_HIGH (idx) == 0)
1317 {
1318 tree virtuals;
1319 unsigned HOST_WIDE_INT n;
1320
1321 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1322 t = TYPE_METHOD_BASETYPE (t);
1323 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1324
1325 n = TREE_INT_CST_LOW (idx);
1326
1327 /* Map vtable index back one, to allow for the null pointer to
1328 member. */
1329 --n;
1330
1331 while (n > 0 && virtuals)
1332 {
1333 --n;
1334 virtuals = TREE_CHAIN (virtuals);
1335 }
1336 if (virtuals)
1337 {
49c249e1 1338 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
9a3b49ac
MS
1339 break;
1340 }
1341 }
1342 }
8d08fdba 1343 OB_PUTC ('{');
6467930b 1344 dump_expr_list (CONSTRUCTOR_ELTS (t));
8d08fdba
MS
1345 OB_PUTC ('}');
1346 break;
1347
51c184be
MS
1348 case OFFSET_REF:
1349 {
1350 tree ob = TREE_OPERAND (t, 0);
1351 if (TREE_CODE (ob) == NOP_EXPR
1352 && TREE_OPERAND (ob, 0) == error_mark_node
1353 && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1354 /* A::f */
1355 dump_expr (TREE_OPERAND (t, 1), 0);
1356 else
1357 {
4ac14744
MS
1358 dump_expr (TREE_OPERAND (t, 0), 0);
1359 OB_PUTS (" .* ");
1360 dump_expr (TREE_OPERAND (t, 1), 0);
51c184be
MS
1361 }
1362 break;
1363 }
1364
5566b478 1365 case TEMPLATE_CONST_PARM:
de22184b
MS
1366 if (current_template_parms)
1367 {
98c1c668
JM
1368 int i;
1369 tree parms;
1370 tree r;
1371
1372 for (parms = current_template_parms;
1373 TREE_CHAIN (parms);
1374 parms = TREE_CHAIN (parms))
1375 ;
1376
1377 r = TREE_VEC_ELT (TREE_VALUE (parms),
1378 TEMPLATE_CONST_IDX (t));
de22184b
MS
1379 dump_decl (TREE_VALUE (r), -1);
1380 }
1381 else
1382 {
1383 OB_PUTS ("<tparm ");
1384 OB_PUTI (TEMPLATE_CONST_IDX (t));
1385 OB_PUTS (">");
1386 }
1387 break;
5566b478
MS
1388
1389 case IDENTIFIER_NODE:
1390 OB_PUTID (t);
1391 break;
1392
1393 case SCOPE_REF:
1394 dump_type (TREE_OPERAND (t, 0), 0);
1395 OB_PUTS ("::");
1396 dump_expr (TREE_OPERAND (t, 1), 0);
1397 break;
1398
1399 case CAST_EXPR:
e349ee73
MS
1400 if (TREE_OPERAND (t, 0) == NULL_TREE
1401 || TREE_CHAIN (TREE_OPERAND (t, 0)))
e76a2646
MS
1402 {
1403 dump_type (TREE_TYPE (t), 0);
1404 OB_PUTC ('(');
6467930b 1405 dump_expr_list (TREE_OPERAND (t, 0));
e76a2646
MS
1406 OB_PUTC (')');
1407 }
1408 else
1409 {
1410 OB_PUTC ('(');
1411 dump_type (TREE_TYPE (t), 0);
1412 OB_PUTC (')');
1413 OB_PUTC ('(');
1414 dump_expr_list (TREE_OPERAND (t, 0));
1415 OB_PUTC (')');
1416 }
1417 break;
1418
1419 case LOOKUP_EXPR:
1420 OB_PUTID (TREE_OPERAND (t, 0));
1421 break;
1422
1423 case SIZEOF_EXPR:
1424 OB_PUTS ("sizeof (");
1425 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1426 dump_type (TREE_OPERAND (t, 0), 0);
1427 else
1428 dump_unary_op ("*", t, 0);
1429 OB_PUTC (')');
1430 break;
5566b478 1431
da20811c
JM
1432 case DEFAULT_ARG:
1433 OB_PUTS ("{unparsed}");
1434 break;
1435
00595019
MS
1436 case TREE_LIST:
1437 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1438 {
1439 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1440 break;
1441 }
1442 /* else fall through */
1443
8d08fdba
MS
1444 /* This list is incomplete, but should suffice for now.
1445 It is very important that `sorry' does not call
1446 `report_error_function'. That could cause an infinite loop. */
1447 default:
1448 sorry ("`%s' not supported by dump_expr",
1449 tree_code_name[(int) TREE_CODE (t)]);
1450
1451 /* fall through to ERROR_MARK... */
1452 case ERROR_MARK:
1453 error:
51c184be 1454 OB_PUTCP ("{error}");
8d08fdba
MS
1455 break;
1456 }
1457}
1458
1459static void
1460dump_binary_op (opstring, t)
1461 char *opstring;
1462 tree t;
1463{
1464 OB_PUTC ('(');
1465 dump_expr (TREE_OPERAND (t, 0), 1);
1466 OB_PUTC (' ');
1467 OB_PUTCP (opstring);
1468 OB_PUTC (' ');
1469 dump_expr (TREE_OPERAND (t, 1), 1);
1470 OB_PUTC (')');
1471}
1472
1473static void
1474dump_unary_op (opstring, t, nop)
1475 char *opstring;
1476 tree t;
1477 int nop;
1478{
1479 if (!nop) OB_PUTC ('(');
1480 OB_PUTCP (opstring);
1481 dump_expr (TREE_OPERAND (t, 0), 1);
1482 if (!nop) OB_PUTC (')');
1483}
1484
1485char *
5566b478
MS
1486fndecl_as_string (fndecl, print_ret_type_p)
1487 tree fndecl;
8d08fdba
MS
1488 int print_ret_type_p;
1489{
1490 return decl_as_string (fndecl, print_ret_type_p);
1491}
1492
1493/* Same, but handtype a _TYPE.
1494 Called from convert_to_reference, mangle_class_name_for_template,
1495 build_unary_op, and GNU_xref_decl. */
e92cc029 1496
8d08fdba
MS
1497char *
1498type_as_string (typ, v)
1499 tree typ;
1500 int v;
1501{
1502 OB_INIT ();
1503
1504 dump_type (typ, v);
1505
1506 OB_FINISH ();
1507
1508 return (char *)obstack_base (&scratch_obstack);
1509}
1510
1511char *
1512expr_as_string (decl, v)
1513 tree decl;
1514 int v;
1515{
1516 OB_INIT ();
1517
1518 dump_expr (decl, 1);
1519
1520 OB_FINISH ();
1521
1522 return (char *)obstack_base (&scratch_obstack);
1523}
1524
1525/* A cross between type_as_string and fndecl_as_string.
1526 Only called from substitute_nice_name. */
e92cc029 1527
8d08fdba
MS
1528char *
1529decl_as_string (decl, v)
1530 tree decl;
1531 int v;
1532{
1533 OB_INIT ();
1534
1535 dump_decl (decl, v);
1536
1537 OB_FINISH ();
1538
1539 return (char *)obstack_base (&scratch_obstack);
1540}
1541
2ba25f50
MS
1542/* Generate the three forms of printable names for lang_printable_name. */
1543
1544char *
1545lang_decl_name (decl, v)
1546 tree decl;
1547 int v;
1548{
1549 if (v >= 2)
1550 return decl_as_string (decl, 1);
1551
1552 OB_INIT ();
1553
1554 if (v == 1 && DECL_CONTEXT (decl)
1555 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
1556 {
1557 tree cname;
1558 if (TREE_CODE (decl) == FUNCTION_DECL)
1559 cname = DECL_CLASS_CONTEXT (decl);
1560 else
1561 cname = DECL_CONTEXT (decl);
1562 dump_type (cname, 0);
1563 OB_PUTC2 (':', ':');
1564 }
1565
1566 if (TREE_CODE (decl) == FUNCTION_DECL)
1567 dump_function_name (decl);
1568 else
1569 dump_decl (DECL_NAME (decl), 0);
1570
1571 OB_FINISH ();
1572
1573 return (char *)obstack_base (&scratch_obstack);
1574}
1575
1576
8d08fdba
MS
1577char *
1578cp_file_of (t)
1579 tree t;
1580{
1581 if (TREE_CODE (t) == PARM_DECL)
1582 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1583 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 1584 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
8d08fdba
MS
1585 else
1586 return DECL_SOURCE_FILE (t);
1587}
1588
1589int
1590cp_line_of (t)
1591 tree t;
1592{
f376e137 1593 int line = 0;
8d08fdba 1594 if (TREE_CODE (t) == PARM_DECL)
f376e137
MS
1595 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1596 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
1597 t = TREE_TYPE (t);
1598
1599 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 1600 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
8d08fdba 1601 else
f376e137
MS
1602 line = DECL_SOURCE_LINE (t);
1603
1604 if (line == 0)
1605 return lineno;
1606
1607 return line;
8d08fdba
MS
1608}
1609
1610char *
1611code_as_string (c, v)
1612 enum tree_code c;
1613 int v;
1614{
1615 return tree_code_name [c];
1616}
1617
1618char *
1619language_as_string (c, v)
1620 enum languages c;
8926095f 1621 int v;
8d08fdba
MS
1622{
1623 switch (c)
1624 {
1625 case lang_c:
1626 return "C";
1627
1628 case lang_cplusplus:
1629 return "C++";
1630
1631 default:
1632 my_friendly_abort (355);
8926095f 1633 return 0;
8d08fdba
MS
1634 }
1635}
1636
1637/* Return the proper printed version of a parameter to a C++ function. */
e92cc029 1638
8d08fdba
MS
1639char *
1640parm_as_string (p, v)
8926095f 1641 int p, v;
8d08fdba
MS
1642{
1643 if (p < 0)
1644 return "`this'";
1645
1646 sprintf (digit_buffer, "%d", p+1);
1647 return digit_buffer;
1648}
1649
1650char *
1651op_as_string (p, v)
1652 enum tree_code p;
8926095f 1653 int v;
8d08fdba
MS
1654{
1655 static char buf[] = "operator ";
1656
1657 if (p == 0)
51c184be 1658 return "{unknown}";
8d08fdba
MS
1659
1660 strcpy (buf + 9, opname_tab [p]);
1661 return buf;
1662}
1663
c91a56d2
MS
1664char *
1665assop_as_string (p, v)
1666 enum tree_code p;
1667 int v;
1668{
1669 static char buf[] = "operator ";
1670
1671 if (p == 0)
1672 return "{unknown}";
1673
1674 strcpy (buf + 9, assignop_tab [p]);
1675 return buf;
1676}
1677
8d08fdba
MS
1678char *
1679args_as_string (p, v)
1680 tree p;
1681 int v;
1682{
1683 if (p == NULL_TREE)
c73964b2 1684 return "";
8d08fdba 1685
c73964b2
MS
1686 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1687 return type_as_string (p, v);
1688
1689 OB_INIT ();
1690 for (; p; p = TREE_CHAIN (p))
1691 {
d11ad92e 1692 dump_type (error_type (TREE_VALUE (p)), v);
c73964b2
MS
1693 if (TREE_CHAIN (p))
1694 OB_PUTS (", ");
1695 }
1696 OB_FINISH ();
1697 return (char *)obstack_base (&scratch_obstack);
8d08fdba 1698}
f30432d7
MS
1699
1700char *
1701cv_as_string (p, v)
1702 tree p;
1703 int v;
1704{
1705 OB_INIT ();
1706
1707 dump_readonly_or_volatile (p, before);
1708
1709 OB_FINISH ();
1710
1711 return (char *)obstack_base (&scratch_obstack);
1712}
This page took 0.412186 seconds and 5 git commands to generate.