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