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