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