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