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