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