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