]>
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 | 323 | OB_PUTS ("::"); |
7ac7b28f | 324 | dump_decl (TYPENAME_TYPE_FULLNAME (t), v); |
5566b478 MS |
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)), | |
337c90cc | 582 | integer_one_node)), 0); |
5156628f | 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 | ||
8f032717 MM |
809 | case OVERLOAD: |
810 | t = OVL_CURRENT (t); | |
811 | /* Fall through. */ | |
812 | ||
8d08fdba MS |
813 | case FUNCTION_DECL: |
814 | if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t))) | |
815 | dump_global_iord (DECL_ASSEMBLER_NAME (t)); | |
da20811c JM |
816 | else if (! DECL_LANG_SPECIFIC (t)) |
817 | OB_PUTS ("{internal}"); | |
8d08fdba MS |
818 | else |
819 | dump_function_decl (t, v); | |
820 | break; | |
821 | ||
822 | case TEMPLATE_DECL: | |
51c184be | 823 | { |
98c1c668 JM |
824 | tree orig_args = DECL_TEMPLATE_PARMS (t); |
825 | tree args; | |
826 | int i; | |
827 | for (args = orig_args = nreverse (orig_args); | |
828 | args; | |
829 | args = TREE_CHAIN (args)) | |
51c184be | 830 | { |
98c1c668 | 831 | int len = TREE_VEC_LENGTH (TREE_VALUE (args)); |
a292b002 | 832 | |
98c1c668 JM |
833 | OB_PUTS ("template <"); |
834 | for (i = 0; i < len; i++) | |
a292b002 | 835 | { |
98c1c668 JM |
836 | tree arg = TREE_VEC_ELT (TREE_VALUE (args), i); |
837 | tree defval = TREE_PURPOSE (arg); | |
838 | arg = TREE_VALUE (arg); | |
839 | if (TREE_CODE (arg) == TYPE_DECL) | |
840 | { | |
73b0fce8 | 841 | if (DECL_NAME (arg)) |
b7a29012 JM |
842 | { |
843 | OB_PUTS ("class "); | |
844 | OB_PUTID (DECL_NAME (arg)); | |
845 | } | |
73b0fce8 | 846 | else |
b7a29012 | 847 | OB_PUTS ("class"); |
98c1c668 JM |
848 | } |
849 | else | |
850 | dump_decl (arg, 1); | |
851 | ||
852 | if (defval) | |
853 | { | |
854 | OB_PUTS (" = "); | |
e7e66632 KL |
855 | if (TREE_CODE (arg) == TYPE_DECL |
856 | || TREE_CODE (arg) == TEMPLATE_DECL) | |
67c2a928 JM |
857 | dump_type (defval, 1); |
858 | else | |
e7e66632 | 859 | dump_expr (defval, 1); |
98c1c668 | 860 | } |
a292b002 | 861 | |
98c1c668 JM |
862 | OB_PUTC2 (',', ' '); |
863 | } | |
864 | if (len != 0) | |
865 | OB_UNPUT (2); | |
866 | OB_PUTC2 ('>', ' '); | |
51c184be | 867 | } |
98c1c668 | 868 | nreverse(orig_args); |
8d08fdba | 869 | |
5566b478 MS |
870 | if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL) |
871 | dump_type (TREE_TYPE (t), v); | |
52bf7d5d MM |
872 | else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL) |
873 | dump_decl (DECL_TEMPLATE_RESULT (t), v); | |
6467930b MS |
874 | else if (TREE_TYPE (t) == NULL_TREE) |
875 | my_friendly_abort (353); | |
51c184be MS |
876 | else switch (NEXT_CODE (t)) |
877 | { | |
878 | case METHOD_TYPE: | |
879 | case FUNCTION_TYPE: | |
880 | dump_function_decl (t, v); | |
881 | break; | |
882 | ||
883 | default: | |
abff8e06 JM |
884 | /* This case can occur with some illegal code. */ |
885 | dump_type (TREE_TYPE (t), v); | |
51c184be MS |
886 | } |
887 | } | |
8d08fdba MS |
888 | break; |
889 | ||
74cd8397 JM |
890 | case TEMPLATE_ID_EXPR: |
891 | { | |
892 | tree args; | |
aa36c081 JM |
893 | tree name = TREE_OPERAND (t, 0); |
894 | if (is_overloaded_fn (name)) | |
895 | name = DECL_NAME (get_first_fn (name)); | |
896 | dump_decl (name, v); | |
74cd8397 JM |
897 | OB_PUTC ('<'); |
898 | for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args)) | |
899 | { | |
73b0fce8 KL |
900 | if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't' |
901 | || TREE_CODE (TREE_VALUE (args)) == TEMPLATE_DECL) | |
74cd8397 JM |
902 | dump_type (TREE_VALUE (args), 0); |
903 | else | |
904 | dump_expr (TREE_VALUE (args), 0); | |
905 | if (TREE_CHAIN (args)) | |
906 | OB_PUTC2 (',', ' '); | |
907 | } | |
908 | OB_PUTC ('>'); | |
909 | } | |
910 | break; | |
911 | ||
0fb9f1c3 | 912 | case LOOKUP_EXPR: |
f9d94ea4 | 913 | dump_decl (TREE_OPERAND (t, 0), v); |
0fb9f1c3 JM |
914 | break; |
915 | ||
8d08fdba MS |
916 | case LABEL_DECL: |
917 | OB_PUTID (DECL_NAME (t)); | |
918 | break; | |
919 | ||
920 | case CONST_DECL: | |
6467930b | 921 | if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) |
03555413 | 922 | || (DECL_INITIAL (t) && |
f84b4be9 | 923 | TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX)) |
07389efe | 924 | dump_simple_decl (t, TREE_TYPE (t), v); |
224c649b BH |
925 | else if (DECL_NAME (t)) |
926 | dump_decl (DECL_NAME (t), v); | |
03555413 | 927 | else if (DECL_INITIAL (t)) |
8d08fdba | 928 | dump_expr (DECL_INITIAL (t), 0); |
03555413 MM |
929 | else |
930 | OB_PUTS ("enumerator"); | |
8d08fdba MS |
931 | break; |
932 | ||
cffa8729 MS |
933 | case USING_DECL: |
934 | OB_PUTS ("using "); | |
935 | dump_type (DECL_INITIAL (t), 0); | |
936 | OB_PUTS ("::"); | |
937 | OB_PUTID (DECL_NAME (t)); | |
938 | break; | |
939 | ||
8d08fdba | 940 | default: |
51c184be MS |
941 | sorry ("`%s' not supported by dump_decl", |
942 | tree_code_name[(int) TREE_CODE (t)]); | |
8d08fdba MS |
943 | } |
944 | } | |
945 | ||
4995028c NS |
946 | /* Pretty print a function decl. There are several ways we want to print a |
947 | function declaration. We use V to tell us what. | |
948 | V - 01 23 | |
949 | args - ++ ++ | |
950 | retval - -+ ++ | |
951 | default- -+ -+ | |
952 | throw - -- ++ | |
953 | As cp_error can only apply the '#' flag once to give 0 and 1 for V, there | |
954 | is %D which doesn't print the throw specs, and %F which does. */ | |
8d08fdba MS |
955 | |
956 | static void | |
957 | dump_function_decl (t, v) | |
958 | tree t; | |
959 | int v; | |
960 | { | |
98c1c668 JM |
961 | tree name; |
962 | tree fntype; | |
963 | tree parmtypes; | |
8d08fdba | 964 | tree cname = NULL_TREE; |
8d08fdba | 965 | |
98c1c668 JM |
966 | if (TREE_CODE (t) == TEMPLATE_DECL) |
967 | t = DECL_TEMPLATE_RESULT (t); | |
968 | ||
969 | name = DECL_ASSEMBLER_NAME (t); | |
970 | fntype = TREE_TYPE (t); | |
971 | parmtypes = TYPE_ARG_TYPES (fntype); | |
972 | ||
8d08fdba | 973 | /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */ |
2642b9bf | 974 | if (DECL_CLASS_SCOPE_P (t)) |
8d08fdba MS |
975 | cname = DECL_CLASS_CONTEXT (t); |
976 | /* this is for partially instantiated template methods */ | |
977 | else if (TREE_CODE (fntype) == METHOD_TYPE) | |
978 | cname = TREE_TYPE (TREE_VALUE (parmtypes)); | |
979 | ||
61cd552e MM |
980 | /* Print the return type. */ |
981 | if (v > 0) | |
8d08fdba MS |
982 | { |
983 | if (DECL_STATIC_FUNCTION_P (t)) | |
984 | OB_PUTS ("static "); | |
985 | ||
aa45967f | 986 | if (! DECL_CONV_FN_P (t) |
8d08fdba | 987 | && ! DECL_CONSTRUCTOR_P (t) |
aa45967f | 988 | && ! DECL_DESTRUCTOR_P (t)) |
8d08fdba | 989 | { |
294471c3 | 990 | dump_type_prefix (TREE_TYPE (fntype), 1, 0); |
8d08fdba MS |
991 | OB_PUTC (' '); |
992 | } | |
993 | } | |
994 | ||
61cd552e | 995 | /* Print the function name. */ |
8d08fdba MS |
996 | if (cname) |
997 | { | |
998 | dump_type (cname, 0); | |
999 | OB_PUTC2 (':', ':'); | |
1000 | if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes) | |
1001 | parmtypes = TREE_CHAIN (parmtypes); | |
1002 | if (DECL_CONSTRUCTOR_FOR_VBASE_P (t)) | |
1003 | /* Skip past "in_charge" identifier. */ | |
1004 | parmtypes = TREE_CHAIN (parmtypes); | |
1005 | } | |
2642b9bf JM |
1006 | else if (CP_DECL_CONTEXT (t) != global_namespace) |
1007 | { | |
1008 | dump_decl (DECL_CONTEXT (t), 0); | |
1009 | OB_PUTC2 (':',':'); | |
1010 | } | |
8d08fdba | 1011 | |
f30432d7 | 1012 | if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus) |
8d08fdba MS |
1013 | parmtypes = TREE_CHAIN (parmtypes); |
1014 | ||
1015 | dump_function_name (t); | |
61cd552e MM |
1016 | |
1017 | /* If V is negative, we don't print the argument types. */ | |
1018 | if (v < 0) | |
1019 | return; | |
1020 | ||
4995028c NS |
1021 | dump_parameters (parmtypes, v & 1, 0); |
1022 | ||
aa45967f | 1023 | if (v && ! DECL_CONV_FN_P (t)) |
294471c3 | 1024 | dump_type_suffix (TREE_TYPE (fntype), 1, 0); |
8d08fdba MS |
1025 | |
1026 | if (TREE_CODE (fntype) == METHOD_TYPE) | |
1027 | { | |
1028 | if (IS_SIGNATURE (cname)) | |
1029 | /* We look at the type pointed to by the `optr' field of `this.' */ | |
91063b51 | 1030 | dump_qualifiers |
8d08fdba MS |
1031 | (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before); |
1032 | else | |
91063b51 | 1033 | dump_qualifiers |
8d08fdba MS |
1034 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before); |
1035 | } | |
4995028c NS |
1036 | |
1037 | if (v >= 2) | |
1038 | dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), 0); | |
1039 | } | |
1040 | ||
1041 | /* Print a parameter list. V indicates if we show default values or not. If | |
1042 | these are for a member function, the member object ptr | |
1043 | (and any other hidden args) should have already been removed. */ | |
1044 | ||
1045 | static void | |
1046 | dump_parameters (parmtypes, v, canonical_name) | |
1047 | tree parmtypes; | |
1048 | int v; | |
1049 | int canonical_name; | |
1050 | { | |
1051 | int first; | |
1052 | OB_PUTC ('('); | |
1053 | ||
1054 | for (first = 1; parmtypes != void_list_node; | |
1055 | parmtypes = TREE_CHAIN (parmtypes)) | |
1056 | { | |
1057 | if (!first) | |
1058 | OB_PUTC2 (',', ' '); | |
1059 | first = 0; | |
1060 | if (!parmtypes) | |
1061 | { | |
1062 | OB_PUTS ("..."); | |
1063 | break; | |
1064 | } | |
1065 | dump_type_real (TREE_VALUE (parmtypes), 0, canonical_name); | |
1066 | ||
1067 | if (TREE_PURPOSE (parmtypes) && v) | |
1068 | { | |
1069 | OB_PUTS (" = "); | |
1070 | dump_expr (TREE_PURPOSE (parmtypes), 0); | |
1071 | } | |
1072 | } | |
1073 | ||
1074 | OB_PUTC (')'); | |
1075 | } | |
1076 | ||
1077 | /* Print an exception specification. T is the exception specification. */ | |
1078 | ||
1079 | static void | |
1080 | dump_exception_spec (t, canonical_name) | |
1081 | tree t; | |
1082 | int canonical_name; | |
1083 | { | |
1084 | if (t) | |
1085 | { | |
1086 | OB_PUTS (" throw ("); | |
1087 | if (TREE_VALUE (t) != NULL_TREE) | |
1088 | while (1) | |
1089 | { | |
1090 | dump_type_real (TREE_VALUE (t), 0, canonical_name); | |
1091 | t = TREE_CHAIN (t); | |
1092 | if (!t) | |
1093 | break; | |
1094 | OB_PUTC2 (',', ' '); | |
1095 | } | |
1096 | OB_PUTC (')'); | |
1097 | } | |
8d08fdba MS |
1098 | } |
1099 | ||
1100 | /* Handle the function name for a FUNCTION_DECL node, grokking operators | |
1101 | and destructors properly. */ | |
e92cc029 | 1102 | |
8d08fdba MS |
1103 | static void |
1104 | dump_function_name (t) | |
1105 | tree t; | |
1106 | { | |
1107 | tree name = DECL_NAME (t); | |
1108 | ||
aa45967f | 1109 | if (DECL_DESTRUCTOR_P (t)) |
8d08fdba MS |
1110 | { |
1111 | OB_PUTC ('~'); | |
1112 | dump_decl (name, 0); | |
1113 | } | |
aa45967f | 1114 | else if (DECL_CONV_FN_P (t)) |
8d08fdba MS |
1115 | { |
1116 | /* This cannot use the hack that the operator's return | |
1117 | type is stashed off of its name because it may be | |
1118 | used for error reporting. In the case of conflicting | |
1119 | declarations, both will have the same name, yet | |
1120 | the types will be different, hence the TREE_TYPE field | |
1121 | of the first name will be clobbered by the second. */ | |
1122 | OB_PUTS ("operator "); | |
1123 | dump_type (TREE_TYPE (TREE_TYPE (t)), 0); | |
1124 | } | |
1125 | else if (IDENTIFIER_OPNAME_P (name)) | |
1126 | { | |
1127 | char *name_string = operator_name_string (name); | |
1128 | OB_PUTS ("operator "); | |
1129 | OB_PUTCP (name_string); | |
1130 | } | |
1131 | else | |
1132 | dump_decl (name, 0); | |
386b8a85 | 1133 | |
36a117a5 MM |
1134 | if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t) |
1135 | && DECL_TEMPLATE_INFO (t) | |
1136 | && (DECL_TEMPLATE_SPECIALIZATION (t) | |
1137 | || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL | |
1138 | || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t)) | |
1139 | || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))) | |
386b8a85 | 1140 | { |
75650646 | 1141 | tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE; |
36a117a5 | 1142 | OB_PUTC ('<'); |
75650646 | 1143 | |
36a117a5 MM |
1144 | /* Be careful only to print things when we have them, so as not |
1145 | to crash producing error messages. */ | |
1146 | if (args) | |
386b8a85 | 1147 | { |
36a117a5 | 1148 | if (TREE_CODE (args) == TREE_LIST) |
75650646 | 1149 | { |
36a117a5 MM |
1150 | tree arg; |
1151 | int need_comma = 0; | |
1152 | ||
1153 | for (arg = args; arg; arg = TREE_CHAIN (arg)) | |
386b8a85 | 1154 | { |
36a117a5 | 1155 | tree a = TREE_VALUE (arg); |
386b8a85 | 1156 | |
36a117a5 MM |
1157 | if (need_comma) |
1158 | OB_PUTS (", "); | |
1159 | ||
1160 | if (a) | |
1161 | { | |
1162 | if (TREE_CODE_CLASS (TREE_CODE (a)) == 't' | |
1163 | || TREE_CODE (a) == TEMPLATE_DECL) | |
1164 | dump_type (a, 0); | |
1165 | else | |
1166 | dump_expr (a, 0); | |
75650646 | 1167 | } |
36a117a5 MM |
1168 | |
1169 | need_comma = 1; | |
386b8a85 | 1170 | } |
36a117a5 MM |
1171 | } |
1172 | else if (TREE_CODE (args) == TREE_VEC) | |
1173 | { | |
1174 | int i; | |
1175 | int need_comma = 0; | |
1176 | ||
1177 | if (TREE_VEC_LENGTH (args) > 0 | |
1178 | && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC) | |
1179 | args = TREE_VEC_ELT (args, | |
1180 | TREE_VEC_LENGTH (args) - 1); | |
1181 | ||
1182 | for (i = 0; i < TREE_VEC_LENGTH (args); i++) | |
386b8a85 | 1183 | { |
36a117a5 | 1184 | tree a = TREE_VEC_ELT (args, i); |
386b8a85 | 1185 | |
36a117a5 MM |
1186 | if (need_comma) |
1187 | OB_PUTS (", "); | |
1188 | ||
1189 | if (a) | |
1190 | { | |
1191 | if (TREE_CODE_CLASS (TREE_CODE (a)) == 't' | |
1192 | || TREE_CODE (a) == TEMPLATE_DECL) | |
1193 | dump_type (a, 0); | |
1194 | else | |
1195 | dump_expr (a, 0); | |
75650646 | 1196 | } |
36a117a5 MM |
1197 | |
1198 | need_comma = 1; | |
386b8a85 JM |
1199 | } |
1200 | } | |
1201 | } | |
36a117a5 | 1202 | OB_PUTC ('>'); |
386b8a85 | 1203 | } |
8d08fdba MS |
1204 | } |
1205 | ||
1206 | static void | |
1207 | dump_char (c) | |
b2bb2710 | 1208 | int c; |
8d08fdba MS |
1209 | { |
1210 | switch (c) | |
1211 | { | |
a0a33927 | 1212 | case TARGET_NEWLINE: |
8d08fdba MS |
1213 | OB_PUTS ("\\n"); |
1214 | break; | |
a0a33927 | 1215 | case TARGET_TAB: |
8d08fdba MS |
1216 | OB_PUTS ("\\t"); |
1217 | break; | |
a0a33927 | 1218 | case TARGET_VT: |
8d08fdba MS |
1219 | OB_PUTS ("\\v"); |
1220 | break; | |
a0a33927 | 1221 | case TARGET_BS: |
8d08fdba MS |
1222 | OB_PUTS ("\\b"); |
1223 | break; | |
a0a33927 | 1224 | case TARGET_CR: |
8d08fdba MS |
1225 | OB_PUTS ("\\r"); |
1226 | break; | |
a0a33927 | 1227 | case TARGET_FF: |
8d08fdba MS |
1228 | OB_PUTS ("\\f"); |
1229 | break; | |
a0a33927 | 1230 | case TARGET_BELL: |
8d08fdba MS |
1231 | OB_PUTS ("\\a"); |
1232 | break; | |
1233 | case '\\': | |
1234 | OB_PUTS ("\\\\"); | |
1235 | break; | |
1236 | case '\'': | |
1237 | OB_PUTS ("\\'"); | |
1238 | break; | |
1239 | case '\"': | |
1240 | OB_PUTS ("\\\""); | |
1241 | break; | |
1242 | default: | |
faa25e97 | 1243 | if (ISPRINT (c)) |
8d08fdba MS |
1244 | OB_PUTC (c); |
1245 | else | |
1246 | { | |
1247 | sprintf (digit_buffer, "\\%03o", (int) c); | |
1248 | OB_PUTCP (digit_buffer); | |
1249 | } | |
1250 | } | |
1251 | } | |
1252 | ||
1253 | /* Print out a list of initializers (subr of dump_expr) */ | |
e92cc029 | 1254 | |
8d08fdba MS |
1255 | static void |
1256 | dump_expr_list (l) | |
1257 | tree l; | |
1258 | { | |
1259 | while (l) | |
1260 | { | |
1261 | dump_expr (TREE_VALUE (l), 0); | |
1262 | if (TREE_CHAIN (l)) | |
1263 | OB_PUTC2 (',', ' '); | |
1264 | l = TREE_CHAIN (l); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | /* Print out an expression */ | |
e92cc029 | 1269 | |
8d08fdba MS |
1270 | static void |
1271 | dump_expr (t, nop) | |
1272 | tree t; | |
1273 | int nop; /* suppress parens */ | |
1274 | { | |
1275 | switch (TREE_CODE (t)) | |
1276 | { | |
1277 | case VAR_DECL: | |
1278 | case PARM_DECL: | |
1279 | case FIELD_DECL: | |
1280 | case CONST_DECL: | |
1281 | case FUNCTION_DECL: | |
ec255269 | 1282 | case TEMPLATE_DECL: |
6b57ac29 | 1283 | case NAMESPACE_DECL: |
8d08fdba MS |
1284 | dump_decl (t, -1); |
1285 | break; | |
1286 | ||
1287 | case INTEGER_CST: | |
1288 | { | |
1289 | tree type = TREE_TYPE (t); | |
1290 | my_friendly_assert (type != 0, 81); | |
1291 | ||
1292 | /* If it's an enum, output its tag, rather than its value. */ | |
1293 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
1294 | { | |
1295 | char *p = enum_name_string (t, type); | |
1296 | OB_PUTCP (p); | |
1297 | } | |
b7484fbe MS |
1298 | else if (type == boolean_type_node) |
1299 | { | |
72b7eeff MS |
1300 | if (t == boolean_false_node |
1301 | || (TREE_INT_CST_LOW (t) == 0 | |
1302 | && TREE_INT_CST_HIGH (t) == 0)) | |
b7484fbe MS |
1303 | OB_PUTS ("false"); |
1304 | else if (t == boolean_true_node) | |
1305 | OB_PUTS ("true"); | |
b7484fbe MS |
1306 | } |
1307 | else if (type == char_type_node) | |
8d08fdba MS |
1308 | { |
1309 | OB_PUTC ('\''); | |
1310 | dump_char (TREE_INT_CST_LOW (t)); | |
1311 | OB_PUTC ('\''); | |
1312 | } | |
1313 | else if (TREE_INT_CST_HIGH (t) | |
1314 | != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1))) | |
1315 | { | |
1316 | tree val = t; | |
1317 | if (TREE_INT_CST_HIGH (val) < 0) | |
1318 | { | |
1319 | OB_PUTC ('-'); | |
1320 | val = build_int_2 (~TREE_INT_CST_LOW (val), | |
1321 | -TREE_INT_CST_HIGH (val)); | |
1322 | } | |
1323 | /* Would "%x%0*x" or "%x%*0x" get zero-padding on all | |
1324 | systems? */ | |
1325 | { | |
1326 | static char format[10]; /* "%x%09999x\0" */ | |
1327 | if (!format[0]) | |
1328 | sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4); | |
1329 | sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val), | |
1330 | TREE_INT_CST_LOW (val)); | |
1331 | OB_PUTCP (digit_buffer); | |
1332 | } | |
1333 | } | |
1334 | else | |
1335 | OB_PUTI (TREE_INT_CST_LOW (t)); | |
1336 | } | |
1337 | break; | |
1338 | ||
1339 | case REAL_CST: | |
1340 | #ifndef REAL_IS_NOT_DOUBLE | |
1341 | sprintf (digit_buffer, "%g", TREE_REAL_CST (t)); | |
1342 | #else | |
1343 | { | |
1344 | unsigned char *p = (unsigned char *) &TREE_REAL_CST (t); | |
a703fb38 | 1345 | size_t i; |
8d08fdba MS |
1346 | strcpy (digit_buffer, "0x"); |
1347 | for (i = 0; i < sizeof TREE_REAL_CST (t); i++) | |
1348 | sprintf (digit_buffer + 2 + 2*i, "%02x", *p++); | |
1349 | } | |
1350 | #endif | |
1351 | OB_PUTCP (digit_buffer); | |
1352 | break; | |
1353 | ||
61a127b3 MM |
1354 | case PTRMEM_CST: |
1355 | OB_PUTC ('&'); | |
1356 | dump_type (PTRMEM_CST_CLASS (t), 0); | |
1357 | OB_PUTS ("::"); | |
1358 | OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t))); | |
1359 | break; | |
1360 | ||
8d08fdba MS |
1361 | case STRING_CST: |
1362 | { | |
1363 | char *p = TREE_STRING_POINTER (t); | |
1364 | int len = TREE_STRING_LENGTH (t) - 1; | |
1365 | int i; | |
1366 | ||
1367 | OB_PUTC ('\"'); | |
1368 | for (i = 0; i < len; i++) | |
1369 | dump_char (p[i]); | |
1370 | OB_PUTC ('\"'); | |
1371 | } | |
1372 | break; | |
1373 | ||
1374 | case COMPOUND_EXPR: | |
1375 | dump_binary_op (",", t); | |
1376 | break; | |
1377 | ||
1378 | case COND_EXPR: | |
1379 | OB_PUTC ('('); | |
1380 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1381 | OB_PUTS (" ? "); | |
1382 | dump_expr (TREE_OPERAND (t, 1), 0); | |
1383 | OB_PUTS (" : "); | |
1384 | dump_expr (TREE_OPERAND (t, 2), 0); | |
1385 | OB_PUTC (')'); | |
1386 | break; | |
1387 | ||
1388 | case SAVE_EXPR: | |
1389 | if (TREE_HAS_CONSTRUCTOR (t)) | |
1390 | { | |
1391 | OB_PUTS ("new "); | |
1392 | dump_type (TREE_TYPE (TREE_TYPE (t)), 0); | |
8d08fdba MS |
1393 | } |
1394 | else | |
1395 | { | |
6060a796 | 1396 | dump_expr (TREE_OPERAND (t, 0), 0); |
8d08fdba MS |
1397 | } |
1398 | break; | |
1399 | ||
02531345 | 1400 | case AGGR_INIT_EXPR: |
8d08fdba MS |
1401 | OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t))); |
1402 | OB_PUTC ('('); | |
42976354 BK |
1403 | if (TREE_OPERAND (t, 1)) |
1404 | dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1))); | |
8d08fdba MS |
1405 | OB_PUTC (')'); |
1406 | break; | |
1407 | ||
1408 | case CALL_EXPR: | |
1409 | { | |
1410 | tree fn = TREE_OPERAND (t, 0); | |
1411 | tree args = TREE_OPERAND (t, 1); | |
1412 | ||
1413 | if (TREE_CODE (fn) == ADDR_EXPR) | |
1414 | fn = TREE_OPERAND (fn, 0); | |
1415 | ||
6467930b | 1416 | if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE) |
8d08fdba MS |
1417 | { |
1418 | tree ob = TREE_VALUE (args); | |
1419 | if (TREE_CODE (ob) == ADDR_EXPR) | |
1420 | { | |
1421 | dump_expr (TREE_OPERAND (ob, 0), 0); | |
1422 | OB_PUTC ('.'); | |
1423 | } | |
1424 | else if (TREE_CODE (ob) != PARM_DECL | |
1425 | || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")) | |
1426 | { | |
1427 | dump_expr (ob, 0); | |
1428 | OB_PUTC2 ('-', '>'); | |
1429 | } | |
1430 | args = TREE_CHAIN (args); | |
1431 | } | |
1432 | dump_expr (fn, 0); | |
fc378698 | 1433 | OB_PUTC ('('); |
8d08fdba MS |
1434 | dump_expr_list (args); |
1435 | OB_PUTC (')'); | |
1436 | } | |
1437 | break; | |
1438 | ||
285baa06 JM |
1439 | case NEW_EXPR: |
1440 | { | |
1441 | tree type = TREE_OPERAND (t, 1); | |
1442 | if (NEW_EXPR_USE_GLOBAL (t)) | |
1443 | OB_PUTS ("::"); | |
1444 | OB_PUTS ("new "); | |
1445 | if (TREE_OPERAND (t, 0)) | |
1446 | { | |
1447 | OB_PUTC ('('); | |
1448 | dump_expr_list (TREE_OPERAND (t, 0)); | |
1449 | OB_PUTS (") "); | |
1450 | } | |
1451 | if (TREE_CODE (type) == ARRAY_REF) | |
1452 | type = build_cplus_array_type | |
1453 | (TREE_OPERAND (type, 0), | |
1454 | build_index_type (size_binop (MINUS_EXPR, TREE_OPERAND (type, 1), | |
1455 | integer_one_node))); | |
1456 | dump_type (type, 0); | |
1457 | if (TREE_OPERAND (t, 2)) | |
1458 | { | |
1459 | OB_PUTC ('('); | |
1460 | dump_expr_list (TREE_OPERAND (t, 2)); | |
1461 | OB_PUTC (')'); | |
1462 | } | |
1463 | } | |
1464 | break; | |
1465 | ||
8d08fdba MS |
1466 | case TARGET_EXPR: |
1467 | /* Note that this only works for G++ target exprs. If somebody | |
1468 | builds a general TARGET_EXPR, there's no way to represent that | |
1469 | it initializes anything other that the parameter slot for the | |
1470 | default argument. Note we may have cleared out the first | |
1471 | operand in expand_expr, so don't go killing ourselves. */ | |
1472 | if (TREE_OPERAND (t, 1)) | |
1473 | dump_expr (TREE_OPERAND (t, 1), 0); | |
1474 | break; | |
1475 | ||
1476 | case MODIFY_EXPR: | |
1477 | case PLUS_EXPR: | |
1478 | case MINUS_EXPR: | |
1479 | case MULT_EXPR: | |
1480 | case TRUNC_DIV_EXPR: | |
1481 | case TRUNC_MOD_EXPR: | |
1482 | case MIN_EXPR: | |
1483 | case MAX_EXPR: | |
1484 | case LSHIFT_EXPR: | |
1485 | case RSHIFT_EXPR: | |
1486 | case BIT_IOR_EXPR: | |
1487 | case BIT_XOR_EXPR: | |
1488 | case BIT_AND_EXPR: | |
1489 | case BIT_ANDTC_EXPR: | |
1490 | case TRUTH_ANDIF_EXPR: | |
1491 | case TRUTH_ORIF_EXPR: | |
1492 | case LT_EXPR: | |
1493 | case LE_EXPR: | |
1494 | case GT_EXPR: | |
1495 | case GE_EXPR: | |
1496 | case EQ_EXPR: | |
1497 | case NE_EXPR: | |
1498 | dump_binary_op (opname_tab[(int) TREE_CODE (t)], t); | |
1499 | break; | |
1500 | ||
1501 | case CEIL_DIV_EXPR: | |
1502 | case FLOOR_DIV_EXPR: | |
1503 | case ROUND_DIV_EXPR: | |
1504 | dump_binary_op ("/", t); | |
1505 | break; | |
1506 | ||
1507 | case CEIL_MOD_EXPR: | |
1508 | case FLOOR_MOD_EXPR: | |
1509 | case ROUND_MOD_EXPR: | |
1510 | dump_binary_op ("%", t); | |
1511 | break; | |
1512 | ||
1513 | case COMPONENT_REF: | |
1514 | { | |
1515 | tree ob = TREE_OPERAND (t, 0); | |
1516 | if (TREE_CODE (ob) == INDIRECT_REF) | |
1517 | { | |
1518 | ob = TREE_OPERAND (ob, 0); | |
1519 | if (TREE_CODE (ob) != PARM_DECL | |
1520 | || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")) | |
1521 | { | |
1522 | dump_expr (ob, 0); | |
1523 | OB_PUTC2 ('-', '>'); | |
1524 | } | |
1525 | } | |
1526 | else | |
1527 | { | |
1528 | dump_expr (ob, 0); | |
1529 | OB_PUTC ('.'); | |
1530 | } | |
1531 | dump_expr (TREE_OPERAND (t, 1), 1); | |
1532 | } | |
1533 | break; | |
1534 | ||
28cbf42c MS |
1535 | case ARRAY_REF: |
1536 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1537 | OB_PUTC ('['); | |
1538 | dump_expr (TREE_OPERAND (t, 1), 0); | |
1539 | OB_PUTC (']'); | |
1540 | break; | |
1541 | ||
8d08fdba MS |
1542 | case CONVERT_EXPR: |
1543 | dump_unary_op ("+", t, nop); | |
1544 | break; | |
1545 | ||
1546 | case ADDR_EXPR: | |
1547 | if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL | |
1548 | || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST) | |
1549 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1550 | else | |
1551 | dump_unary_op ("&", t, nop); | |
1552 | break; | |
1553 | ||
1554 | case INDIRECT_REF: | |
1555 | if (TREE_HAS_CONSTRUCTOR (t)) | |
1556 | { | |
1557 | t = TREE_OPERAND (t, 0); | |
1558 | my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237); | |
1559 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1560 | OB_PUTC ('('); | |
1561 | dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1))); | |
1562 | OB_PUTC (')'); | |
1563 | } | |
1564 | else | |
1565 | { | |
6467930b | 1566 | if (TREE_OPERAND (t,0) != NULL_TREE |
5082a355 | 1567 | && TREE_TYPE (TREE_OPERAND (t, 0)) |
6467930b | 1568 | && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE) |
8d08fdba MS |
1569 | dump_expr (TREE_OPERAND (t, 0), nop); |
1570 | else | |
1571 | dump_unary_op ("*", t, nop); | |
1572 | } | |
1573 | break; | |
1574 | ||
1575 | case NEGATE_EXPR: | |
1576 | case BIT_NOT_EXPR: | |
1577 | case TRUTH_NOT_EXPR: | |
1578 | case PREDECREMENT_EXPR: | |
1579 | case PREINCREMENT_EXPR: | |
1580 | dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop); | |
1581 | break; | |
1582 | ||
1583 | case POSTDECREMENT_EXPR: | |
1584 | case POSTINCREMENT_EXPR: | |
1585 | OB_PUTC ('('); | |
1586 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1587 | OB_PUTCP (opname_tab[(int)TREE_CODE (t)]); | |
1588 | OB_PUTC (')'); | |
1589 | break; | |
1590 | ||
1591 | case NON_LVALUE_EXPR: | |
1592 | /* FIXME: This is a KLUDGE workaround for a parsing problem. There | |
1593 | should be another level of INDIRECT_REF so that I don't have to do | |
1594 | this. */ | |
6467930b | 1595 | if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE) |
8d08fdba MS |
1596 | { |
1597 | tree next = TREE_TYPE (TREE_TYPE (t)); | |
1598 | ||
1599 | while (TREE_CODE (next) == POINTER_TYPE) | |
1600 | next = TREE_TYPE (next); | |
1601 | ||
1602 | if (TREE_CODE (next) == FUNCTION_TYPE) | |
1603 | { | |
1604 | if (!nop) OB_PUTC ('('); | |
1605 | OB_PUTC ('*'); | |
1606 | dump_expr (TREE_OPERAND (t, 0), 1); | |
1607 | if (!nop) OB_PUTC (')'); | |
1608 | break; | |
1609 | } | |
1610 | /* else FALLTHRU */ | |
1611 | } | |
1612 | dump_expr (TREE_OPERAND (t, 0), 0); | |
1613 | break; | |
1614 | ||
1615 | case NOP_EXPR: | |
1616 | dump_expr (TREE_OPERAND (t, 0), nop); | |
1617 | break; | |
1618 | ||
1619 | case CONSTRUCTOR: | |
9a3b49ac MS |
1620 | if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) |
1621 | { | |
1622 | tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0); | |
1623 | ||
1624 | if (integer_all_onesp (idx)) | |
1625 | { | |
1626 | tree pfn = PFN_FROM_PTRMEMFUNC (t); | |
bbcec105 | 1627 | dump_unary_op ("&", pfn, 0); |
9a3b49ac MS |
1628 | break; |
1629 | } | |
e08a8f45 MM |
1630 | else if (TREE_CODE (idx) == INTEGER_CST |
1631 | && tree_int_cst_equal (idx, integer_zero_node)) | |
1632 | { | |
1633 | /* A NULL pointer-to-member constant. */ | |
1634 | OB_PUTS ("(("); | |
1635 | dump_type (TREE_TYPE (t), 0); | |
1636 | OB_PUTS (") 0)"); | |
1637 | break; | |
1638 | } | |
1639 | else if (TREE_CODE (idx) == INTEGER_CST | |
1640 | && TREE_INT_CST_HIGH (idx) == 0) | |
9a3b49ac MS |
1641 | { |
1642 | tree virtuals; | |
1643 | unsigned HOST_WIDE_INT n; | |
1644 | ||
1645 | t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t))); | |
1646 | t = TYPE_METHOD_BASETYPE (t); | |
1647 | virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t))); | |
1648 | ||
1649 | n = TREE_INT_CST_LOW (idx); | |
1650 | ||
1651 | /* Map vtable index back one, to allow for the null pointer to | |
1652 | member. */ | |
1653 | --n; | |
1654 | ||
1655 | while (n > 0 && virtuals) | |
1656 | { | |
1657 | --n; | |
1658 | virtuals = TREE_CHAIN (virtuals); | |
1659 | } | |
1660 | if (virtuals) | |
1661 | { | |
49c249e1 | 1662 | dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0); |
9a3b49ac MS |
1663 | break; |
1664 | } | |
1665 | } | |
1666 | } | |
8d08fdba | 1667 | OB_PUTC ('{'); |
6467930b | 1668 | dump_expr_list (CONSTRUCTOR_ELTS (t)); |
8d08fdba MS |
1669 | OB_PUTC ('}'); |
1670 | break; | |
1671 | ||
51c184be MS |
1672 | case OFFSET_REF: |
1673 | { | |
1674 | tree ob = TREE_OPERAND (t, 0); | |
51924768 | 1675 | if (is_dummy_object (ob)) |
61a127b3 MM |
1676 | { |
1677 | if (TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL) | |
1678 | /* A::f */ | |
1679 | dump_expr (TREE_OPERAND (t, 1), 0); | |
1680 | else | |
1681 | dump_decl (TREE_OPERAND (t, 1), 0); | |
1682 | } | |
51c184be MS |
1683 | else |
1684 | { | |
bbcec105 JM |
1685 | if (TREE_CODE (ob) == INDIRECT_REF) |
1686 | { | |
1687 | dump_expr (TREE_OPERAND (ob, 0), 0); | |
1688 | OB_PUTS (" ->* "); | |
1689 | } | |
1690 | else | |
1691 | { | |
1692 | dump_expr (ob, 0); | |
1693 | OB_PUTS (" .* "); | |
1694 | } | |
4ac14744 | 1695 | dump_expr (TREE_OPERAND (t, 1), 0); |
51c184be MS |
1696 | } |
1697 | break; | |
1698 | } | |
1699 | ||
f84b4be9 | 1700 | case TEMPLATE_PARM_INDEX: |
050367a3 | 1701 | dump_decl (TEMPLATE_PARM_DECL (t), -1); |
de22184b | 1702 | break; |
5566b478 MS |
1703 | |
1704 | case IDENTIFIER_NODE: | |
1705 | OB_PUTID (t); | |
1706 | break; | |
1707 | ||
1708 | case SCOPE_REF: | |
1709 | dump_type (TREE_OPERAND (t, 0), 0); | |
1710 | OB_PUTS ("::"); | |
1711 | dump_expr (TREE_OPERAND (t, 1), 0); | |
1712 | break; | |
1713 | ||
1714 | case CAST_EXPR: | |
e349ee73 MS |
1715 | if (TREE_OPERAND (t, 0) == NULL_TREE |
1716 | || TREE_CHAIN (TREE_OPERAND (t, 0))) | |
e76a2646 MS |
1717 | { |
1718 | dump_type (TREE_TYPE (t), 0); | |
1719 | OB_PUTC ('('); | |
6467930b | 1720 | dump_expr_list (TREE_OPERAND (t, 0)); |
e76a2646 MS |
1721 | OB_PUTC (')'); |
1722 | } | |
1723 | else | |
1724 | { | |
1725 | OB_PUTC ('('); | |
1726 | dump_type (TREE_TYPE (t), 0); | |
1727 | OB_PUTC (')'); | |
1728 | OB_PUTC ('('); | |
1729 | dump_expr_list (TREE_OPERAND (t, 0)); | |
1730 | OB_PUTC (')'); | |
1731 | } | |
1732 | break; | |
1733 | ||
1734 | case LOOKUP_EXPR: | |
1735 | OB_PUTID (TREE_OPERAND (t, 0)); | |
1736 | break; | |
1737 | ||
5a11e05b BK |
1738 | case ARROW_EXPR: |
1739 | dump_expr (TREE_OPERAND (t, 0), nop); | |
1740 | OB_PUTS ("->"); | |
1741 | break; | |
1742 | ||
e76a2646 | 1743 | case SIZEOF_EXPR: |
abff8e06 JM |
1744 | case ALIGNOF_EXPR: |
1745 | if (TREE_CODE (t) == SIZEOF_EXPR) | |
1746 | OB_PUTS ("sizeof ("); | |
1747 | else | |
1748 | { | |
1749 | my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0); | |
1750 | OB_PUTS ("__alignof__ ("); | |
1751 | } | |
e76a2646 MS |
1752 | if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't') |
1753 | dump_type (TREE_OPERAND (t, 0), 0); | |
1754 | else | |
1755 | dump_unary_op ("*", t, 0); | |
1756 | OB_PUTC (')'); | |
1757 | break; | |
5566b478 | 1758 | |
da20811c JM |
1759 | case DEFAULT_ARG: |
1760 | OB_PUTS ("{unparsed}"); | |
1761 | break; | |
1762 | ||
6748b643 JM |
1763 | case TRY_CATCH_EXPR: |
1764 | case WITH_CLEANUP_EXPR: | |
1765 | case CLEANUP_POINT_EXPR: | |
1766 | dump_expr (TREE_OPERAND (t, 0), nop); | |
1767 | break; | |
1768 | ||
7ac7b28f MM |
1769 | case TEMPLATE_ID_EXPR: |
1770 | dump_decl (t, 0); | |
1771 | break; | |
1772 | ||
00595019 MS |
1773 | case TREE_LIST: |
1774 | if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL) | |
1775 | { | |
1776 | OB_PUTID (DECL_NAME (TREE_VALUE (t))); | |
1777 | break; | |
1778 | } | |
1779 | /* else fall through */ | |
1780 | ||
8d08fdba MS |
1781 | /* This list is incomplete, but should suffice for now. |
1782 | It is very important that `sorry' does not call | |
1783 | `report_error_function'. That could cause an infinite loop. */ | |
1784 | default: | |
1785 | sorry ("`%s' not supported by dump_expr", | |
1786 | tree_code_name[(int) TREE_CODE (t)]); | |
1787 | ||
1788 | /* fall through to ERROR_MARK... */ | |
1789 | case ERROR_MARK: | |
51c184be | 1790 | OB_PUTCP ("{error}"); |
8d08fdba MS |
1791 | break; |
1792 | } | |
1793 | } | |
1794 | ||
1795 | static void | |
1796 | dump_binary_op (opstring, t) | |
1797 | char *opstring; | |
1798 | tree t; | |
1799 | { | |
1800 | OB_PUTC ('('); | |
1801 | dump_expr (TREE_OPERAND (t, 0), 1); | |
1802 | OB_PUTC (' '); | |
1803 | OB_PUTCP (opstring); | |
1804 | OB_PUTC (' '); | |
1805 | dump_expr (TREE_OPERAND (t, 1), 1); | |
1806 | OB_PUTC (')'); | |
1807 | } | |
1808 | ||
1809 | static void | |
1810 | dump_unary_op (opstring, t, nop) | |
1811 | char *opstring; | |
1812 | tree t; | |
1813 | int nop; | |
1814 | { | |
1815 | if (!nop) OB_PUTC ('('); | |
1816 | OB_PUTCP (opstring); | |
1817 | dump_expr (TREE_OPERAND (t, 0), 1); | |
1818 | if (!nop) OB_PUTC (')'); | |
1819 | } | |
1820 | ||
4995028c NS |
1821 | /* Print a function decl with exception specification included. */ |
1822 | ||
8d08fdba | 1823 | char * |
4995028c | 1824 | fndecl_as_string (fndecl, print_default_args_p) |
5566b478 | 1825 | tree fndecl; |
4995028c | 1826 | int print_default_args_p; |
8d08fdba | 1827 | { |
4995028c NS |
1828 | OB_INIT (); |
1829 | ||
1830 | dump_function_decl (fndecl, 2 + print_default_args_p); | |
1831 | ||
1832 | OB_FINISH (); | |
1833 | ||
1834 | return (char *)obstack_base (&scratch_obstack); | |
8d08fdba MS |
1835 | } |
1836 | ||
e1467ff2 | 1837 | /* Same, but handle a _TYPE. |
8d08fdba | 1838 | Called from convert_to_reference, mangle_class_name_for_template, |
294471c3 MM |
1839 | build_unary_op, and GNU_xref_decl. If CANONICAL_NAME is non-zero, |
1840 | when describing a typedef, we use the name of the type described, | |
1841 | rather than the name of the typedef. */ | |
e92cc029 | 1842 | |
8d08fdba | 1843 | char * |
294471c3 | 1844 | type_as_string_real (typ, v, canonical_name) |
8d08fdba MS |
1845 | tree typ; |
1846 | int v; | |
294471c3 | 1847 | int canonical_name; |
8d08fdba MS |
1848 | { |
1849 | OB_INIT (); | |
1850 | ||
294471c3 | 1851 | dump_type_real (typ, v, canonical_name); |
8d08fdba MS |
1852 | |
1853 | OB_FINISH (); | |
1854 | ||
1855 | return (char *)obstack_base (&scratch_obstack); | |
1856 | } | |
1857 | ||
294471c3 MM |
1858 | |
1859 | char * | |
1860 | type_as_string (typ, v) | |
1861 | tree typ; | |
1862 | int v; | |
1863 | { | |
1864 | return type_as_string_real (typ, v, 0); | |
1865 | } | |
1866 | ||
8d08fdba MS |
1867 | char * |
1868 | expr_as_string (decl, v) | |
1869 | tree decl; | |
7dee3f36 | 1870 | int v ATTRIBUTE_UNUSED; |
8d08fdba MS |
1871 | { |
1872 | OB_INIT (); | |
1873 | ||
1874 | dump_expr (decl, 1); | |
1875 | ||
1876 | OB_FINISH (); | |
1877 | ||
1878 | return (char *)obstack_base (&scratch_obstack); | |
1879 | } | |
1880 | ||
1881 | /* A cross between type_as_string and fndecl_as_string. | |
1882 | Only called from substitute_nice_name. */ | |
e92cc029 | 1883 | |
8d08fdba MS |
1884 | char * |
1885 | decl_as_string (decl, v) | |
1886 | tree decl; | |
1887 | int v; | |
1888 | { | |
1889 | OB_INIT (); | |
1890 | ||
1891 | dump_decl (decl, v); | |
1892 | ||
1893 | OB_FINISH (); | |
1894 | ||
1895 | return (char *)obstack_base (&scratch_obstack); | |
1896 | } | |
1897 | ||
2ba25f50 MS |
1898 | /* Generate the three forms of printable names for lang_printable_name. */ |
1899 | ||
1900 | char * | |
1901 | lang_decl_name (decl, v) | |
1902 | tree decl; | |
1903 | int v; | |
1904 | { | |
1905 | if (v >= 2) | |
1906 | return decl_as_string (decl, 1); | |
1907 | ||
1908 | OB_INIT (); | |
1909 | ||
6eb3bb27 | 1910 | if (v == 1 && DECL_CLASS_SCOPE_P (decl)) |
2ba25f50 MS |
1911 | { |
1912 | tree cname; | |
1913 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1914 | cname = DECL_CLASS_CONTEXT (decl); | |
1915 | else | |
1916 | cname = DECL_CONTEXT (decl); | |
1917 | dump_type (cname, 0); | |
1918 | OB_PUTC2 (':', ':'); | |
1919 | } | |
1920 | ||
1921 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1922 | dump_function_name (decl); | |
1923 | else | |
1924 | dump_decl (DECL_NAME (decl), 0); | |
1925 | ||
1926 | OB_FINISH (); | |
1927 | ||
1928 | return (char *)obstack_base (&scratch_obstack); | |
1929 | } | |
1930 | ||
1931 | ||
8d08fdba MS |
1932 | char * |
1933 | cp_file_of (t) | |
1934 | tree t; | |
1935 | { | |
741f2839 | 1936 | if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t)) |
8d08fdba MS |
1937 | return DECL_SOURCE_FILE (DECL_CONTEXT (t)); |
1938 | else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') | |
d2e5ee5c | 1939 | return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t)); |
8f032717 MM |
1940 | else if (TREE_CODE (t) == OVERLOAD) |
1941 | return DECL_SOURCE_FILE (OVL_FUNCTION (t)); | |
8d08fdba MS |
1942 | else |
1943 | return DECL_SOURCE_FILE (t); | |
1944 | } | |
1945 | ||
1946 | int | |
1947 | cp_line_of (t) | |
1948 | tree t; | |
1949 | { | |
f376e137 | 1950 | int line = 0; |
741f2839 | 1951 | if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t)) |
f376e137 | 1952 | line = DECL_SOURCE_LINE (DECL_CONTEXT (t)); |
f3400fe2 JM |
1953 | if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t) |
1954 | && TYPE_MAIN_DECL (TREE_TYPE (t))) | |
f376e137 MS |
1955 | t = TREE_TYPE (t); |
1956 | ||
1957 | if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') | |
d2e5ee5c | 1958 | line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t)); |
8f032717 MM |
1959 | else if (TREE_CODE (t) == OVERLOAD) |
1960 | line = DECL_SOURCE_LINE (OVL_FUNCTION (t)); | |
8d08fdba | 1961 | else |
f376e137 MS |
1962 | line = DECL_SOURCE_LINE (t); |
1963 | ||
1964 | if (line == 0) | |
1965 | return lineno; | |
1966 | ||
1967 | return line; | |
8d08fdba MS |
1968 | } |
1969 | ||
1970 | char * | |
1971 | code_as_string (c, v) | |
1972 | enum tree_code c; | |
7dee3f36 | 1973 | int v ATTRIBUTE_UNUSED; |
8d08fdba MS |
1974 | { |
1975 | return tree_code_name [c]; | |
1976 | } | |
1977 | ||
1978 | char * | |
1979 | language_as_string (c, v) | |
1980 | enum languages c; | |
7dee3f36 | 1981 | int v ATTRIBUTE_UNUSED; |
8d08fdba MS |
1982 | { |
1983 | switch (c) | |
1984 | { | |
1985 | case lang_c: | |
1986 | return "C"; | |
1987 | ||
1988 | case lang_cplusplus: | |
1989 | return "C++"; | |
1990 | ||
31b72b87 PB |
1991 | case lang_java: |
1992 | return "Java"; | |
1993 | ||
8d08fdba MS |
1994 | default: |
1995 | my_friendly_abort (355); | |
8926095f | 1996 | return 0; |
8d08fdba MS |
1997 | } |
1998 | } | |
1999 | ||
2000 | /* Return the proper printed version of a parameter to a C++ function. */ | |
e92cc029 | 2001 | |
8d08fdba MS |
2002 | char * |
2003 | parm_as_string (p, v) | |
7dee3f36 KG |
2004 | int p; |
2005 | int v ATTRIBUTE_UNUSED; | |
8d08fdba MS |
2006 | { |
2007 | if (p < 0) | |
2008 | return "`this'"; | |
2009 | ||
2010 | sprintf (digit_buffer, "%d", p+1); | |
2011 | return digit_buffer; | |
2012 | } | |
2013 | ||
2014 | char * | |
2015 | op_as_string (p, v) | |
2016 | enum tree_code p; | |
7dee3f36 | 2017 | int v ATTRIBUTE_UNUSED; |
8d08fdba MS |
2018 | { |
2019 | static char buf[] = "operator "; | |
2020 | ||
2021 | if (p == 0) | |
51c184be | 2022 | return "{unknown}"; |
8d08fdba MS |
2023 | |
2024 | strcpy (buf + 9, opname_tab [p]); | |
2025 | return buf; | |
2026 | } | |
2027 | ||
c91a56d2 MS |
2028 | char * |
2029 | assop_as_string (p, v) | |
2030 | enum tree_code p; | |
7dee3f36 | 2031 | int v ATTRIBUTE_UNUSED; |
c91a56d2 MS |
2032 | { |
2033 | static char buf[] = "operator "; | |
2034 | ||
2035 | if (p == 0) | |
2036 | return "{unknown}"; | |
2037 | ||
2038 | strcpy (buf + 9, assignop_tab [p]); | |
2039 | return buf; | |
2040 | } | |
2041 | ||
8d08fdba MS |
2042 | char * |
2043 | args_as_string (p, v) | |
2044 | tree p; | |
2045 | int v; | |
2046 | { | |
2047 | if (p == NULL_TREE) | |
c73964b2 | 2048 | return ""; |
8d08fdba | 2049 | |
c73964b2 MS |
2050 | if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't') |
2051 | return type_as_string (p, v); | |
2052 | ||
2053 | OB_INIT (); | |
2054 | for (; p; p = TREE_CHAIN (p)) | |
2055 | { | |
a6967cc0 JM |
2056 | if (TREE_VALUE (p) == null_node) |
2057 | OB_PUTS ("NULL"); | |
2058 | else | |
2059 | dump_type (error_type (TREE_VALUE (p)), v); | |
c73964b2 MS |
2060 | if (TREE_CHAIN (p)) |
2061 | OB_PUTS (", "); | |
2062 | } | |
2063 | OB_FINISH (); | |
2064 | return (char *)obstack_base (&scratch_obstack); | |
8d08fdba | 2065 | } |
f30432d7 MS |
2066 | |
2067 | char * | |
2068 | cv_as_string (p, v) | |
2069 | tree p; | |
7dee3f36 | 2070 | int v ATTRIBUTE_UNUSED; |
f30432d7 MS |
2071 | { |
2072 | OB_INIT (); | |
2073 | ||
91063b51 | 2074 | dump_qualifiers (p, before); |
f30432d7 MS |
2075 | |
2076 | OB_FINISH (); | |
2077 | ||
2078 | return (char *)obstack_base (&scratch_obstack); | |
2079 | } |