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