]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Call-backs for C++ error reporting. |
2 | This code is non-reentrant. | |
5624e564 | 3 | Copyright (C) 1993-2015 Free Software Foundation, Inc. |
f5adbb8d | 4 | This file is part of GCC. |
8d08fdba | 5 | |
f5adbb8d | 6 | GCC is free software; you can redistribute it and/or modify |
8d08fdba | 7 | it under the terms of the GNU General Public License as published by |
e77f031d | 8 | the Free Software Foundation; either version 3, or (at your option) |
8d08fdba MS |
9 | any later version. |
10 | ||
f5adbb8d | 11 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
e77f031d NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
8d08fdba MS |
19 | |
20 | #include "config.h" | |
8d052bc7 | 21 | #include "system.h" |
4977bab6 ZW |
22 | #include "coretypes.h" |
23 | #include "tm.h" | |
40e23961 MC |
24 | #include "hash-set.h" |
25 | #include "machmode.h" | |
26 | #include "vec.h" | |
27 | #include "double-int.h" | |
28 | #include "input.h" | |
29 | #include "alias.h" | |
30 | #include "symtab.h" | |
31 | #include "wide-int.h" | |
32 | #include "inchash.h" | |
8d08fdba | 33 | #include "tree.h" |
d8a2d370 | 34 | #include "stringpool.h" |
8d08fdba | 35 | #include "cp-tree.h" |
749ced52 | 36 | #include "flags.h" |
cb753e49 | 37 | #include "diagnostic.h" |
cf835838 | 38 | #include "tree-diagnostic.h" |
7cb32822 | 39 | #include "langhooks-def.h" |
b02cec6e | 40 | #include "intl.h" |
e1a4dd13 | 41 | #include "cxx-pretty-print.h" |
cf835838 | 42 | #include "tree-pretty-print.h" |
61d3ce20 | 43 | #include "c-family/c-objc.h" |
de5a5fa1 | 44 | #include "ubsan.h" |
0b274c17 | 45 | #include "internal-fn.h" |
8d08fdba | 46 | |
da6ca2b5 GDR |
47 | #include <new> // For placement-new. |
48 | ||
73bbafe5 | 49 | #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') |
ca17c07b | 50 | #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') |
a1066c99 | 51 | |
d723bb7c MLI |
52 | /* cxx_pp is a C++ front-end-specific pretty printer: this is where we |
53 | dump C++ ASTs as strings. It is mostly used only by the various | |
54 | tree -> string functions that are occasionally called from the | |
55 | debugger or by the front-end for things like | |
56 | __PRETTY_FUNCTION__. */ | |
e1a4dd13 | 57 | static cxx_pretty_printer scratch_pretty_printer; |
d723bb7c | 58 | static cxx_pretty_printer * cxx_pp = &scratch_pretty_printer; |
0aafb128 | 59 | |
f41c4af3 JM |
60 | /* Translate if being used for diagnostics, but not for dump files or |
61 | __PRETTY_FUNCTION. */ | |
62 | #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid)) | |
63 | ||
b34c06e3 | 64 | # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T))) |
8d08fdba | 65 | |
3f8548e7 | 66 | static const char *args_to_string (tree, int); |
4e3f84b7 GDR |
67 | static const char *assop_to_string (enum tree_code); |
68 | static const char *code_to_string (enum tree_code); | |
3f8548e7 GDR |
69 | static const char *cv_to_string (tree, int); |
70 | static const char *decl_to_string (tree, int); | |
4e3f84b7 | 71 | static const char *expr_to_string (tree); |
3f8548e7 | 72 | static const char *fndecl_to_string (tree, int); |
4e3f84b7 GDR |
73 | static const char *op_to_string (enum tree_code); |
74 | static const char *parm_to_string (int); | |
3f8548e7 GDR |
75 | static const char *type_to_string (tree, int); |
76 | ||
3c1ab1ab GDR |
77 | static void dump_alias_template_specialization (cxx_pretty_printer *, tree, int); |
78 | static void dump_type (cxx_pretty_printer *, tree, int); | |
79 | static void dump_typename (cxx_pretty_printer *, tree, int); | |
80 | static void dump_simple_decl (cxx_pretty_printer *, tree, tree, int); | |
81 | static void dump_decl (cxx_pretty_printer *, tree, int); | |
82 | static void dump_template_decl (cxx_pretty_printer *, tree, int); | |
83 | static void dump_function_decl (cxx_pretty_printer *, tree, int); | |
84 | static void dump_expr (cxx_pretty_printer *, tree, int); | |
85 | static void dump_unary_op (cxx_pretty_printer *, const char *, tree, int); | |
86 | static void dump_binary_op (cxx_pretty_printer *, const char *, tree, int); | |
87 | static void dump_aggr_type (cxx_pretty_printer *, tree, int); | |
88 | static void dump_type_prefix (cxx_pretty_printer *, tree, int); | |
89 | static void dump_type_suffix (cxx_pretty_printer *, tree, int); | |
90 | static void dump_function_name (cxx_pretty_printer *, tree, int); | |
91 | static void dump_call_expr_args (cxx_pretty_printer *, tree, int, bool); | |
92 | static void dump_aggr_init_expr_args (cxx_pretty_printer *, tree, int, bool); | |
93 | static void dump_expr_list (cxx_pretty_printer *, tree, int); | |
94 | static void dump_global_iord (cxx_pretty_printer *, tree); | |
95 | static void dump_parameters (cxx_pretty_printer *, tree, int); | |
96 | static void dump_ref_qualifier (cxx_pretty_printer *, tree, int); | |
97 | static void dump_exception_spec (cxx_pretty_printer *, tree, int); | |
98 | static void dump_template_argument (cxx_pretty_printer *, tree, int); | |
99 | static void dump_template_argument_list (cxx_pretty_printer *, tree, int); | |
100 | static void dump_template_parameter (cxx_pretty_printer *, tree, int); | |
101 | static void dump_template_bindings (cxx_pretty_printer *, tree, tree, | |
102 | vec<tree, va_gc> *); | |
103 | static void dump_scope (cxx_pretty_printer *, tree, int); | |
104 | static void dump_template_parms (cxx_pretty_printer *, tree, int, int); | |
1a048f82 | 105 | static int get_non_default_template_args_count (tree, int); |
3f8548e7 | 106 | static const char *function_category (tree); |
2bfe0527 | 107 | static void maybe_print_constexpr_context (diagnostic_context *); |
3f8548e7 GDR |
108 | static void maybe_print_instantiation_context (diagnostic_context *); |
109 | static void print_instantiation_full_context (diagnostic_context *); | |
110 | static void print_instantiation_partial_context (diagnostic_context *, | |
e2c3721c PB |
111 | struct tinst_level *, |
112 | location_t); | |
3f8548e7 | 113 | static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *); |
3f8548e7 GDR |
114 | static void cp_print_error_function (diagnostic_context *, diagnostic_info *); |
115 | ||
39ce81c9 ZW |
116 | static bool cp_printer (pretty_printer *, text_info *, const char *, |
117 | int, bool, bool, bool); | |
8d08fdba | 118 | |
d723bb7c MLI |
119 | /* CONTEXT->printer is a basic pretty printer that was constructed |
120 | presumably by diagnostic_initialize(), called early in the | |
121 | compiler's initialization process (in general_init) Before the FE | |
122 | is initialized. This (C++) FE-specific diagnostic initializer is | |
123 | thus replacing the basic pretty printer with one that has C++-aware | |
124 | capacities. */ | |
125 | ||
8d08fdba | 126 | void |
d723bb7c | 127 | cxx_initialize_diagnostics (diagnostic_context *context) |
8d08fdba | 128 | { |
d723bb7c MLI |
129 | pretty_printer *base = context->printer; |
130 | cxx_pretty_printer *pp = XNEW (cxx_pretty_printer); | |
131 | context->printer = new (pp) cxx_pretty_printer (); | |
132 | ||
133 | /* It is safe to free this object because it was previously XNEW()'d. */ | |
134 | base->~pretty_printer (); | |
135 | XDELETE (base); | |
136 | ||
137 | c_common_diagnostics_set_defaults (context); | |
138 | diagnostic_starter (context) = cp_diagnostic_starter; | |
18767f65 | 139 | /* diagnostic_finalizer is already c_diagnostic_finalizer. */ |
d723bb7c MLI |
140 | diagnostic_format_decoder (context) = cp_printer; |
141 | } | |
749ced52 | 142 | |
d723bb7c MLI |
143 | /* Initialize the global cxx_pp that is used as the memory store for |
144 | the string representation of C++ AST. See the description of | |
145 | cxx_pp above. */ | |
146 | ||
147 | void | |
148 | init_error (void) | |
149 | { | |
da6ca2b5 | 150 | new (cxx_pp) cxx_pretty_printer (); |
8d08fdba MS |
151 | } |
152 | ||
9e93bc9d | 153 | /* Dump a scope, if deemed necessary. */ |
bbcec105 | 154 | |
9e93bc9d | 155 | static void |
3c1ab1ab | 156 | dump_scope (cxx_pretty_printer *pp, tree scope, int flags) |
bbcec105 | 157 | { |
af88c58f | 158 | int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF); |
761f0855 | 159 | |
9e93bc9d NS |
160 | if (scope == NULL_TREE) |
161 | return; | |
bb20cc46 | 162 | |
9e93bc9d NS |
163 | if (TREE_CODE (scope) == NAMESPACE_DECL) |
164 | { | |
165 | if (scope != global_namespace) | |
0cbd7506 | 166 | { |
3c1ab1ab GDR |
167 | dump_decl (pp, scope, f); |
168 | pp_cxx_colon_colon (pp); | |
0cbd7506 | 169 | } |
9e93bc9d NS |
170 | } |
171 | else if (AGGREGATE_TYPE_P (scope)) | |
172 | { | |
3c1ab1ab GDR |
173 | dump_type (pp, scope, f); |
174 | pp_cxx_colon_colon (pp); | |
9e93bc9d | 175 | } |
761f0855 | 176 | else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL) |
9e93bc9d | 177 | { |
3c1ab1ab GDR |
178 | dump_function_decl (pp, scope, f); |
179 | pp_cxx_colon_colon (pp); | |
9e93bc9d | 180 | } |
bbcec105 JM |
181 | } |
182 | ||
612c671a | 183 | /* Dump the template ARGument under control of FLAGS. */ |
5f77d6cc GDR |
184 | |
185 | static void | |
3c1ab1ab | 186 | dump_template_argument (cxx_pretty_printer *pp, tree arg, int flags) |
5f77d6cc | 187 | { |
5d80a306 | 188 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 189 | dump_template_argument_list (pp, ARGUMENT_PACK_ARGS (arg), |
89a27d8f JM |
190 | /* No default args in argument packs. */ |
191 | flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
5d80a306 | 192 | else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL) |
3c1ab1ab | 193 | dump_type (pp, arg, flags & ~TFF_CLASS_KEY_OR_ENUM); |
5f77d6cc | 194 | else |
a9fe2f76 PC |
195 | { |
196 | if (TREE_CODE (arg) == TREE_LIST) | |
197 | arg = TREE_VALUE (arg); | |
198 | ||
3c1ab1ab | 199 | dump_expr (pp, arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM); |
a9fe2f76 | 200 | } |
5f77d6cc GDR |
201 | } |
202 | ||
53b39fe5 JM |
203 | /* Count the number of template arguments ARGS whose value does not |
204 | match the (optional) default template parameter in PARAMS */ | |
205 | ||
206 | static int | |
1a048f82 | 207 | get_non_default_template_args_count (tree args, int flags) |
53b39fe5 | 208 | { |
1a048f82 | 209 | int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 | 210 | |
1a048f82 | 211 | if (/* We use this flag when generating debug information. We don't |
b5b8b0ac AO |
212 | want to expand templates at this point, for this may generate |
213 | new decls, which gets decl counts out of sync, which may in | |
214 | turn cause codegen differences between compilations with and | |
215 | without -g. */ | |
1a048f82 | 216 | (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0 |
b5b8b0ac | 217 | || !flag_pretty_templates) |
53b39fe5 JM |
218 | return n; |
219 | ||
1a048f82 | 220 | return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 JM |
221 | } |
222 | ||
612c671a GDR |
223 | /* Dump a template-argument-list ARGS (always a TREE_VEC) under control |
224 | of FLAGS. */ | |
225 | ||
226 | static void | |
3c1ab1ab | 227 | dump_template_argument_list (cxx_pretty_printer *pp, tree args, int flags) |
612c671a | 228 | { |
1a048f82 | 229 | int n = get_non_default_template_args_count (args, flags); |
612c671a GDR |
230 | int need_comma = 0; |
231 | int i; | |
232 | ||
53b39fe5 | 233 | for (i = 0; i < n; ++i) |
612c671a | 234 | { |
5d80a306 DG |
235 | tree arg = TREE_VEC_ELT (args, i); |
236 | ||
237 | /* Only print a comma if we know there is an argument coming. In | |
238 | the case of an empty template argument pack, no actual | |
239 | argument will be printed. */ | |
240 | if (need_comma | |
241 | && (!ARGUMENT_PACK_P (arg) | |
242 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 243 | pp_separate_with_comma (pp); |
5d80a306 | 244 | |
3c1ab1ab | 245 | dump_template_argument (pp, arg, flags); |
612c671a GDR |
246 | need_comma = 1; |
247 | } | |
248 | } | |
249 | ||
250 | /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */ | |
251 | ||
252 | static void | |
3c1ab1ab | 253 | dump_template_parameter (cxx_pretty_printer *pp, tree parm, int flags) |
612c671a | 254 | { |
42b304f1 LM |
255 | tree p; |
256 | tree a; | |
257 | ||
258 | if (parm == error_mark_node) | |
259 | return; | |
260 | ||
261 | p = TREE_VALUE (parm); | |
262 | a = TREE_PURPOSE (parm); | |
612c671a GDR |
263 | |
264 | if (TREE_CODE (p) == TYPE_DECL) | |
265 | { | |
761f0855 | 266 | if (flags & TFF_DECL_SPECIFIERS) |
0cbd7506 | 267 | { |
3c1ab1ab | 268 | pp_cxx_ws_string (pp, "class"); |
5d80a306 | 269 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p))) |
3c1ab1ab | 270 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 | 271 | if (DECL_NAME (p)) |
3c1ab1ab | 272 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
0cbd7506 | 273 | } |
612c671a | 274 | else if (DECL_NAME (p)) |
3c1ab1ab | 275 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
612c671a | 276 | else |
3c1ab1ab | 277 | pp_cxx_canonical_template_parameter (pp, TREE_TYPE (p)); |
612c671a GDR |
278 | } |
279 | else | |
3c1ab1ab | 280 | dump_decl (pp, p, flags | TFF_DECL_SPECIFIERS); |
612c671a | 281 | |
761f0855 | 282 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE) |
612c671a | 283 | { |
3c1ab1ab GDR |
284 | pp_cxx_whitespace (pp); |
285 | pp_equal (pp); | |
286 | pp_cxx_whitespace (pp); | |
31bb3027 | 287 | if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL) |
3c1ab1ab | 288 | dump_type (pp, a, flags & ~TFF_CHASE_TYPEDEF); |
612c671a | 289 | else |
3c1ab1ab | 290 | dump_expr (pp, a, flags | TFF_EXPR_IN_PARENS); |
612c671a GDR |
291 | } |
292 | } | |
293 | ||
294 | /* Dump, under control of FLAGS, a template-parameter-list binding. | |
295 | PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a | |
296 | TREE_VEC. */ | |
297 | ||
298 | static void | |
3c1ab1ab GDR |
299 | dump_template_bindings (cxx_pretty_printer *pp, tree parms, tree args, |
300 | vec<tree, va_gc> *typenames) | |
612c671a | 301 | { |
ca17c07b | 302 | bool need_semicolon = false; |
d5c8be27 JM |
303 | int i; |
304 | tree t; | |
612c671a GDR |
305 | |
306 | while (parms) | |
307 | { | |
308 | tree p = TREE_VALUE (parms); | |
b5ac18ea MM |
309 | int lvl = TMPL_PARMS_DEPTH (parms); |
310 | int arg_idx = 0; | |
612c671a | 311 | int i; |
53b39fe5 JM |
312 | tree lvl_args = NULL_TREE; |
313 | ||
314 | /* Don't crash if we had an invalid argument list. */ | |
315 | if (TMPL_ARGS_DEPTH (args) >= lvl) | |
316 | lvl_args = TMPL_ARGS_LEVEL (args, lvl); | |
612c671a GDR |
317 | |
318 | for (i = 0; i < TREE_VEC_LENGTH (p); ++i) | |
b5ac18ea | 319 | { |
2bb5d995 JM |
320 | tree arg = NULL_TREE; |
321 | ||
322 | /* Don't crash if we had an invalid argument list. */ | |
53b39fe5 JM |
323 | if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx) |
324 | arg = TREE_VEC_ELT (lvl_args, arg_idx); | |
b5ac18ea | 325 | |
ca17c07b | 326 | if (need_semicolon) |
3c1ab1ab GDR |
327 | pp_separate_with_semicolon (pp); |
328 | dump_template_parameter (pp, TREE_VEC_ELT (p, i), | |
329 | TFF_PLAIN_IDENTIFIER); | |
330 | pp_cxx_whitespace (pp); | |
331 | pp_equal (pp); | |
332 | pp_cxx_whitespace (pp); | |
b5ac18ea | 333 | if (arg) |
af16209f JM |
334 | { |
335 | if (ARGUMENT_PACK_P (arg)) | |
3c1ab1ab GDR |
336 | pp_cxx_left_brace (pp); |
337 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
af16209f | 338 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 339 | pp_cxx_right_brace (pp); |
af16209f | 340 | } |
b5ac18ea | 341 | else |
3c1ab1ab | 342 | pp_string (pp, M_("<missing>")); |
bb20cc46 | 343 | |
b5ac18ea | 344 | ++arg_idx; |
ca17c07b | 345 | need_semicolon = true; |
b5ac18ea | 346 | } |
612c671a GDR |
347 | |
348 | parms = TREE_CHAIN (parms); | |
349 | } | |
d5c8be27 | 350 | |
21d69a5b | 351 | /* Don't bother with typenames for a partial instantiation. */ |
9771b263 | 352 | if (vec_safe_is_empty (typenames) || uses_template_parms (args)) |
21d69a5b JM |
353 | return; |
354 | ||
1ed5f1d3 JM |
355 | /* Don't try to print typenames when we're processing a clone. */ |
356 | if (current_function_decl | |
357 | && !DECL_LANG_SPECIFIC (current_function_decl)) | |
358 | return; | |
359 | ||
9771b263 | 360 | FOR_EACH_VEC_SAFE_ELT (typenames, i, t) |
d5c8be27 | 361 | { |
ca17c07b | 362 | if (need_semicolon) |
3c1ab1ab GDR |
363 | pp_separate_with_semicolon (pp); |
364 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); | |
365 | pp_cxx_whitespace (pp); | |
366 | pp_equal (pp); | |
367 | pp_cxx_whitespace (pp); | |
42d1e31d | 368 | push_deferring_access_checks (dk_no_check); |
a4d674fc | 369 | t = tsubst (t, args, tf_none, NULL_TREE); |
42d1e31d | 370 | pop_deferring_access_checks (); |
a4d674fc JM |
371 | /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because |
372 | pp_simple_type_specifier doesn't know about it. */ | |
cd41d410 | 373 | t = strip_typedefs (t); |
3c1ab1ab | 374 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); |
d5c8be27 | 375 | } |
612c671a GDR |
376 | } |
377 | ||
28704289 DS |
378 | /* Dump a human-readable equivalent of the alias template |
379 | specialization of T. */ | |
380 | ||
381 | static void | |
3c1ab1ab | 382 | dump_alias_template_specialization (cxx_pretty_printer *pp, tree t, int flags) |
28704289 DS |
383 | { |
384 | tree name; | |
385 | ||
386 | gcc_assert (alias_template_specialization_p (t)); | |
387 | ||
7d29c953 | 388 | if (!(flags & TFF_UNQUALIFIED_NAME)) |
3c1ab1ab | 389 | dump_scope (pp, CP_DECL_CONTEXT (TYPE_NAME (t)), flags); |
28704289 | 390 | name = TYPE_IDENTIFIER (t); |
3c1ab1ab GDR |
391 | pp_cxx_tree_identifier (pp, name); |
392 | dump_template_parms (pp, TYPE_TEMPLATE_INFO (t), | |
28704289 DS |
393 | /*primary=*/false, |
394 | flags & ~TFF_TEMPLATE_HEADER); | |
395 | } | |
396 | ||
b3426eb9 GK |
397 | /* Dump a human-readable equivalent of TYPE. FLAGS controls the |
398 | format. */ | |
e92cc029 | 399 | |
8d08fdba | 400 | static void |
3c1ab1ab | 401 | dump_type (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
402 | { |
403 | if (t == NULL_TREE) | |
404 | return; | |
bb20cc46 | 405 | |
3333a2dd JM |
406 | /* Don't print e.g. "struct mytypedef". */ |
407 | if (TYPE_P (t) && typedef_variant_p (t)) | |
408 | { | |
409 | tree decl = TYPE_NAME (t); | |
410 | if ((flags & TFF_CHASE_TYPEDEF) | |
28704289 DS |
411 | || DECL_SELF_REFERENCE_P (decl) |
412 | || (!flag_pretty_templates | |
413 | && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))) | |
3333a2dd | 414 | t = strip_typedefs (t); |
28704289 DS |
415 | else if (alias_template_specialization_p (t)) |
416 | { | |
3c1ab1ab | 417 | dump_alias_template_specialization (pp, t, flags); |
28704289 DS |
418 | return; |
419 | } | |
3333a2dd JM |
420 | else if (same_type_p (t, TREE_TYPE (decl))) |
421 | t = decl; | |
422 | else | |
423 | { | |
3c1ab1ab GDR |
424 | pp_cxx_cv_qualifier_seq (pp, t); |
425 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
3333a2dd JM |
426 | return; |
427 | } | |
428 | } | |
429 | ||
8d08fdba MS |
430 | if (TYPE_PTRMEMFUNC_P (t)) |
431 | goto offset_type; | |
432 | ||
433 | switch (TREE_CODE (t)) | |
434 | { | |
fbfc8363 | 435 | case LANG_TYPE: |
09357846 | 436 | if (t == init_list_type_node) |
3c1ab1ab | 437 | pp_string (pp, M_("<brace-enclosed initializer list>")); |
fbfc8363 | 438 | else if (t == unknown_type_node) |
3c1ab1ab | 439 | pp_string (pp, M_("<unresolved overloaded function type>")); |
fbfc8363 | 440 | else |
5116acc6 | 441 | { |
3c1ab1ab GDR |
442 | pp_cxx_cv_qualifier_seq (pp, t); |
443 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
5116acc6 | 444 | } |
8d08fdba MS |
445 | break; |
446 | ||
dcd08efc JM |
447 | case TREE_LIST: |
448 | /* A list of function parms. */ | |
3c1ab1ab | 449 | dump_parameters (pp, t, flags); |
dcd08efc JM |
450 | break; |
451 | ||
8d08fdba | 452 | case IDENTIFIER_NODE: |
3c1ab1ab | 453 | pp_cxx_tree_identifier (pp, t); |
8d08fdba MS |
454 | break; |
455 | ||
c81f61b2 | 456 | case TREE_BINFO: |
3c1ab1ab | 457 | dump_type (pp, BINFO_TYPE (t), flags); |
8d08fdba MS |
458 | break; |
459 | ||
460 | case RECORD_TYPE: | |
461 | case UNION_TYPE: | |
462 | case ENUMERAL_TYPE: | |
3c1ab1ab | 463 | dump_aggr_type (pp, t, flags); |
8d08fdba MS |
464 | break; |
465 | ||
466 | case TYPE_DECL: | |
761f0855 | 467 | if (flags & TFF_CHASE_TYPEDEF) |
0cbd7506 | 468 | { |
3c1ab1ab | 469 | dump_type (pp, DECL_ORIGINAL_TYPE (t) |
0cbd7506 MS |
470 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags); |
471 | break; | |
472 | } | |
f4f206f4 | 473 | /* Else fall through. */ |
bb20cc46 | 474 | |
67c2a928 | 475 | case TEMPLATE_DECL: |
009425e1 | 476 | case NAMESPACE_DECL: |
3c1ab1ab | 477 | dump_decl (pp, t, flags & ~TFF_DECL_SPECIFIERS); |
8d08fdba | 478 | break; |
bb20cc46 | 479 | |
8d08fdba | 480 | case INTEGER_TYPE: |
8d08fdba MS |
481 | case REAL_TYPE: |
482 | case VOID_TYPE: | |
2986ae00 | 483 | case BOOLEAN_TYPE: |
53de5204 GDR |
484 | case COMPLEX_TYPE: |
485 | case VECTOR_TYPE: | |
998ceda2 | 486 | case FIXED_POINT_TYPE: |
3c1ab1ab | 487 | pp_type_specifier_seq (pp, t); |
8d08fdba MS |
488 | break; |
489 | ||
73b0fce8 | 490 | case TEMPLATE_TEMPLATE_PARM: |
c6002625 | 491 | /* For parameters inside template signature. */ |
a1281f45 | 492 | if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 493 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
73b0fce8 | 494 | else |
3c1ab1ab | 495 | pp_cxx_canonical_template_parameter (pp, t); |
a1281f45 KL |
496 | break; |
497 | ||
498 | case BOUND_TEMPLATE_TEMPLATE_PARM: | |
499 | { | |
500 | tree args = TYPE_TI_ARGS (t); | |
3c1ab1ab GDR |
501 | pp_cxx_cv_qualifier_seq (pp, t); |
502 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
503 | pp_cxx_begin_template_argument_list (pp); | |
504 | dump_template_argument_list (pp, args, flags); | |
505 | pp_cxx_end_template_argument_list (pp); | |
a1281f45 | 506 | } |
73b0fce8 KL |
507 | break; |
508 | ||
8d08fdba | 509 | case TEMPLATE_TYPE_PARM: |
3c1ab1ab | 510 | pp_cxx_cv_qualifier_seq (pp, t); |
ec255269 | 511 | if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 512 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
ec255269 | 513 | else |
0cbd7506 | 514 | pp_cxx_canonical_template_parameter |
3c1ab1ab | 515 | (pp, TEMPLATE_TYPE_PARM_INDEX (t)); |
8d08fdba MS |
516 | break; |
517 | ||
8d08fdba MS |
518 | /* This is not always necessary for pointers and such, but doing this |
519 | reduces code size. */ | |
520 | case ARRAY_TYPE: | |
521 | case POINTER_TYPE: | |
522 | case REFERENCE_TYPE: | |
523 | case OFFSET_TYPE: | |
524 | offset_type: | |
525 | case FUNCTION_TYPE: | |
526 | case METHOD_TYPE: | |
9e93bc9d | 527 | { |
3c1ab1ab GDR |
528 | dump_type_prefix (pp, t, flags); |
529 | dump_type_suffix (pp, t, flags); | |
8d08fdba | 530 | break; |
9e93bc9d | 531 | } |
5566b478 | 532 | case TYPENAME_TYPE: |
a4d674fc JM |
533 | if (! (flags & TFF_CHASE_TYPEDEF) |
534 | && DECL_ORIGINAL_TYPE (TYPE_NAME (t))) | |
535 | { | |
3c1ab1ab | 536 | dump_decl (pp, TYPE_NAME (t), TFF_PLAIN_IDENTIFIER); |
a4d674fc JM |
537 | break; |
538 | } | |
3c1ab1ab GDR |
539 | pp_cxx_cv_qualifier_seq (pp, t); |
540 | pp_cxx_ws_string (pp, | |
c8094d83 | 541 | TYPENAME_IS_ENUM_P (t) ? "enum" |
fc6a28d7 MM |
542 | : TYPENAME_IS_CLASS_P (t) ? "class" |
543 | : "typename"); | |
3c1ab1ab | 544 | dump_typename (pp, t, flags); |
5566b478 MS |
545 | break; |
546 | ||
b8c6534b | 547 | case UNBOUND_CLASS_TEMPLATE: |
e1faa105 JM |
548 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
549 | { | |
3c1ab1ab GDR |
550 | dump_type (pp, TYPE_CONTEXT (t), flags); |
551 | pp_cxx_colon_colon (pp); | |
e1faa105 | 552 | } |
3c1ab1ab | 553 | pp_cxx_ws_string (pp, "template"); |
cc27b5cd | 554 | dump_type (pp, TYPE_IDENTIFIER (t), flags); |
b8c6534b KL |
555 | break; |
556 | ||
b894fc05 | 557 | case TYPEOF_TYPE: |
3c1ab1ab GDR |
558 | pp_cxx_ws_string (pp, "__typeof__"); |
559 | pp_cxx_whitespace (pp); | |
560 | pp_cxx_left_paren (pp); | |
561 | dump_expr (pp, TYPEOF_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
562 | pp_cxx_right_paren (pp); | |
b894fc05 JM |
563 | break; |
564 | ||
a0d260fc | 565 | case UNDERLYING_TYPE: |
3c1ab1ab GDR |
566 | pp_cxx_ws_string (pp, "__underlying_type"); |
567 | pp_cxx_whitespace (pp); | |
568 | pp_cxx_left_paren (pp); | |
569 | dump_expr (pp, UNDERLYING_TYPE_TYPE (t), flags & ~TFF_EXPR_IN_PARENS); | |
570 | pp_cxx_right_paren (pp); | |
a0d260fc PC |
571 | break; |
572 | ||
5d80a306 | 573 | case TYPE_PACK_EXPANSION: |
3c1ab1ab GDR |
574 | dump_type (pp, PACK_EXPANSION_PATTERN (t), flags); |
575 | pp_cxx_ws_string (pp, "..."); | |
5d80a306 DG |
576 | break; |
577 | ||
b1d7b1c0 | 578 | case TYPE_ARGUMENT_PACK: |
3c1ab1ab | 579 | dump_template_argument (pp, t, flags); |
b1d7b1c0 DG |
580 | break; |
581 | ||
3ad6a8e1 | 582 | case DECLTYPE_TYPE: |
3c1ab1ab GDR |
583 | pp_cxx_ws_string (pp, "decltype"); |
584 | pp_cxx_whitespace (pp); | |
585 | pp_cxx_left_paren (pp); | |
586 | dump_expr (pp, DECLTYPE_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
587 | pp_cxx_right_paren (pp); | |
3ad6a8e1 DG |
588 | break; |
589 | ||
1e85e720 | 590 | case NULLPTR_TYPE: |
3c1ab1ab | 591 | pp_string (pp, "std::nullptr_t"); |
1e85e720 RG |
592 | break; |
593 | ||
8d08fdba | 594 | default: |
3c1ab1ab | 595 | pp_unsupported_tree (pp, t); |
c6002625 | 596 | /* Fall through to error. */ |
9e93bc9d NS |
597 | |
598 | case ERROR_MARK: | |
3c1ab1ab | 599 | pp_string (pp, M_("<type error>")); |
9e93bc9d | 600 | break; |
8d08fdba MS |
601 | } |
602 | } | |
603 | ||
46e2747c NS |
604 | /* Dump a TYPENAME_TYPE. We need to notice when the context is itself |
605 | a TYPENAME_TYPE. */ | |
606 | ||
607 | static void | |
3c1ab1ab | 608 | dump_typename (cxx_pretty_printer *pp, tree t, int flags) |
46e2747c NS |
609 | { |
610 | tree ctx = TYPE_CONTEXT (t); | |
bb20cc46 | 611 | |
46e2747c | 612 | if (TREE_CODE (ctx) == TYPENAME_TYPE) |
3c1ab1ab | 613 | dump_typename (pp, ctx, flags); |
46e2747c | 614 | else |
3c1ab1ab GDR |
615 | dump_type (pp, ctx, flags & ~TFF_CLASS_KEY_OR_ENUM); |
616 | pp_cxx_colon_colon (pp); | |
617 | dump_decl (pp, TYPENAME_TYPE_FULLNAME (t), flags); | |
46e2747c NS |
618 | } |
619 | ||
9e93bc9d NS |
620 | /* Return the name of the supplied aggregate, or enumeral type. */ |
621 | ||
3cabd8f9 MA |
622 | const char * |
623 | class_key_or_enum_as_string (tree t) | |
8d08fdba | 624 | { |
adf2edec DG |
625 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
626 | { | |
627 | if (SCOPED_ENUM_P (t)) | |
628 | return "enum class"; | |
629 | else | |
630 | return "enum"; | |
631 | } | |
8d08fdba | 632 | else if (TREE_CODE (t) == UNION_TYPE) |
51c184be | 633 | return "union"; |
8d08fdba | 634 | else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t)) |
51c184be | 635 | return "class"; |
8d08fdba | 636 | else |
51c184be MS |
637 | return "struct"; |
638 | } | |
639 | ||
9e93bc9d NS |
640 | /* Print out a class declaration T under the control of FLAGS, |
641 | in the form `class foo'. */ | |
e92cc029 | 642 | |
51c184be | 643 | static void |
3c1ab1ab | 644 | dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags) |
51c184be MS |
645 | { |
646 | tree name; | |
3cabd8f9 | 647 | const char *variety = class_key_or_enum_as_string (t); |
9e93bc9d NS |
648 | int typdef = 0; |
649 | int tmplate = 0; | |
8d08fdba | 650 | |
3c1ab1ab | 651 | pp_cxx_cv_qualifier_seq (pp, t); |
8d08fdba | 652 | |
761f0855 | 653 | if (flags & TFF_CLASS_KEY_OR_ENUM) |
3c1ab1ab | 654 | pp_cxx_ws_string (pp, variety); |
bb20cc46 | 655 | |
9e93bc9d NS |
656 | name = TYPE_NAME (t); |
657 | ||
658 | if (name) | |
8d08fdba | 659 | { |
28704289 DS |
660 | typdef = (!DECL_ARTIFICIAL (name) |
661 | /* An alias specialization is not considered to be a | |
662 | typedef. */ | |
663 | && !alias_template_specialization_p (t)); | |
f6f5e3a1 | 664 | |
abd5730b JM |
665 | if ((typdef |
666 | && ((flags & TFF_CHASE_TYPEDEF) | |
667 | || (!flag_pretty_templates && DECL_LANG_SPECIFIC (name) | |
668 | && DECL_TEMPLATE_INFO (name)))) | |
669 | || DECL_SELF_REFERENCE_P (name)) | |
f6f5e3a1 JM |
670 | { |
671 | t = TYPE_MAIN_VARIANT (t); | |
672 | name = TYPE_NAME (t); | |
673 | typdef = 0; | |
674 | } | |
675 | ||
9e93bc9d | 676 | tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE |
0cbd7506 | 677 | && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t) |
f0d60e22 | 678 | && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL |
0cbd7506 | 679 | || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t))); |
a0ad3539 MM |
680 | |
681 | if (! (flags & TFF_UNQUALIFIED_NAME)) | |
3c1ab1ab | 682 | dump_scope (pp, CP_DECL_CONTEXT (name), flags | TFF_SCOPE); |
a0ad3539 | 683 | flags &= ~TFF_UNQUALIFIED_NAME; |
9e93bc9d | 684 | if (tmplate) |
0cbd7506 MS |
685 | { |
686 | /* Because the template names are mangled, we have to locate | |
687 | the most general template, and use that name. */ | |
28704289 | 688 | tree tpl = TYPE_TI_TEMPLATE (t); |
0cbd7506 MS |
689 | |
690 | while (DECL_TEMPLATE_INFO (tpl)) | |
691 | tpl = DECL_TI_TEMPLATE (tpl); | |
692 | name = tpl; | |
693 | } | |
9e93bc9d | 694 | name = DECL_NAME (name); |
8d08fdba MS |
695 | } |
696 | ||
f30432d7 | 697 | if (name == 0 || ANON_AGGRNAME_P (name)) |
8d08fdba | 698 | { |
761f0855 | 699 | if (flags & TFF_CLASS_KEY_OR_ENUM) |
3c1ab1ab | 700 | pp_string (pp, M_("<anonymous>")); |
99885b3f | 701 | else |
3c1ab1ab | 702 | pp_printf (pp, M_("<anonymous %s>"), variety); |
8d08fdba | 703 | } |
af580858 | 704 | else if (LAMBDA_TYPE_P (t)) |
d5f4eddd JM |
705 | { |
706 | /* A lambda's "type" is essentially its signature. */ | |
3c1ab1ab | 707 | pp_string (pp, M_("<lambda")); |
d5f4eddd | 708 | if (lambda_function (t)) |
3c1ab1ab GDR |
709 | dump_parameters (pp, |
710 | FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t)), | |
d5f4eddd | 711 | flags); |
3c1ab1ab | 712 | pp_greater (pp); |
d5f4eddd | 713 | } |
8d08fdba | 714 | else |
3c1ab1ab | 715 | pp_cxx_tree_identifier (pp, name); |
9e93bc9d | 716 | if (tmplate) |
3c1ab1ab | 717 | dump_template_parms (pp, TYPE_TEMPLATE_INFO (t), |
0cbd7506 MS |
718 | !CLASSTYPE_USE_TEMPLATE (t), |
719 | flags & ~TFF_TEMPLATE_HEADER); | |
8d08fdba MS |
720 | } |
721 | ||
722 | /* Dump into the obstack the initial part of the output for a given type. | |
723 | This is necessary when dealing with things like functions returning | |
724 | functions. Examples: | |
725 | ||
726 | return type of `int (* fee ())()': pointer -> function -> int. Both | |
727 | pointer (and reference and offset) and function (and member) types must | |
728 | deal with prefix and suffix. | |
729 | ||
730 | Arrays must also do this for DECL nodes, like int a[], and for things like | |
b9b44fb9 | 731 | int *[]&. */ |
8d08fdba | 732 | |
c8094d83 | 733 | static void |
3c1ab1ab | 734 | dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
735 | { |
736 | if (TYPE_PTRMEMFUNC_P (t)) | |
737 | { | |
738 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
739 | goto offset_type; | |
740 | } | |
bb20cc46 | 741 | |
8d08fdba MS |
742 | switch (TREE_CODE (t)) |
743 | { | |
744 | case POINTER_TYPE: | |
91063b51 | 745 | case REFERENCE_TYPE: |
8d08fdba MS |
746 | { |
747 | tree sub = TREE_TYPE (t); | |
bb20cc46 | 748 | |
3c1ab1ab | 749 | dump_type_prefix (pp, sub, flags); |
0d9c0892 JM |
750 | if (TREE_CODE (sub) == ARRAY_TYPE |
751 | || TREE_CODE (sub) == FUNCTION_TYPE) | |
8d08fdba | 752 | { |
3c1ab1ab GDR |
753 | pp_cxx_whitespace (pp); |
754 | pp_cxx_left_paren (pp); | |
755 | pp_c_attributes_display (pp, TYPE_ATTRIBUTES (sub)); | |
8d08fdba | 756 | } |
50e10fa8 | 757 | if (TYPE_PTR_P (t)) |
3c1ab1ab | 758 | pp_star (pp); |
8af2fec4 RY |
759 | else if (TREE_CODE (t) == REFERENCE_TYPE) |
760 | { | |
761 | if (TYPE_REF_IS_RVALUE (t)) | |
3c1ab1ab | 762 | pp_ampersand_ampersand (pp); |
8af2fec4 | 763 | else |
3c1ab1ab | 764 | pp_ampersand (pp); |
8af2fec4 | 765 | } |
3c1ab1ab GDR |
766 | pp->padding = pp_before; |
767 | pp_cxx_cv_qualifier_seq (pp, t); | |
8d08fdba | 768 | } |
8d08fdba MS |
769 | break; |
770 | ||
771 | case OFFSET_TYPE: | |
772 | offset_type: | |
3c1ab1ab | 773 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
51c184be MS |
774 | if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */ |
775 | { | |
3c1ab1ab | 776 | pp_maybe_space (pp); |
0cbd7506 | 777 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) |
3c1ab1ab GDR |
778 | pp_cxx_left_paren (pp); |
779 | dump_type (pp, TYPE_OFFSET_BASETYPE (t), flags); | |
780 | pp_cxx_colon_colon (pp); | |
51c184be | 781 | } |
3c1ab1ab GDR |
782 | pp_cxx_star (pp); |
783 | pp_cxx_cv_qualifier_seq (pp, t); | |
784 | pp->padding = pp_before; | |
8d08fdba MS |
785 | break; |
786 | ||
0d9c0892 JM |
787 | /* This can be reached without a pointer when dealing with |
788 | templates, e.g. std::is_function. */ | |
8d08fdba | 789 | case FUNCTION_TYPE: |
3c1ab1ab | 790 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
791 | break; |
792 | ||
793 | case METHOD_TYPE: | |
3c1ab1ab GDR |
794 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
795 | pp_maybe_space (pp); | |
796 | pp_cxx_left_paren (pp); | |
797 | dump_aggr_type (pp, TYPE_METHOD_BASETYPE (t), flags); | |
798 | pp_cxx_colon_colon (pp); | |
8d08fdba MS |
799 | break; |
800 | ||
801 | case ARRAY_TYPE: | |
3c1ab1ab | 802 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
803 | break; |
804 | ||
805 | case ENUMERAL_TYPE: | |
8d08fdba MS |
806 | case IDENTIFIER_NODE: |
807 | case INTEGER_TYPE: | |
2986ae00 | 808 | case BOOLEAN_TYPE: |
8d08fdba MS |
809 | case REAL_TYPE: |
810 | case RECORD_TYPE: | |
811 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 812 | case TEMPLATE_TEMPLATE_PARM: |
a1281f45 | 813 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
814 | case TREE_LIST: |
815 | case TYPE_DECL: | |
816 | case TREE_VEC: | |
8d08fdba | 817 | case UNION_TYPE: |
fbfc8363 | 818 | case LANG_TYPE: |
8d08fdba | 819 | case VOID_TYPE: |
5566b478 | 820 | case TYPENAME_TYPE: |
37c46b43 | 821 | case COMPLEX_TYPE: |
c00996a3 | 822 | case VECTOR_TYPE: |
0df4ae96 | 823 | case TYPEOF_TYPE: |
a0d260fc | 824 | case UNDERLYING_TYPE: |
3ad6a8e1 | 825 | case DECLTYPE_TYPE: |
e7de2d6f | 826 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 827 | case FIXED_POINT_TYPE: |
1e85e720 | 828 | case NULLPTR_TYPE: |
3c1ab1ab GDR |
829 | dump_type (pp, t, flags); |
830 | pp->padding = pp_before; | |
8d08fdba | 831 | break; |
bb20cc46 | 832 | |
8d08fdba | 833 | default: |
3c1ab1ab | 834 | pp_unsupported_tree (pp, t); |
99885b3f | 835 | /* fall through. */ |
9e93bc9d | 836 | case ERROR_MARK: |
3c1ab1ab | 837 | pp_string (pp, M_("<typeprefixerror>")); |
9e93bc9d | 838 | break; |
8d08fdba MS |
839 | } |
840 | } | |
841 | ||
9e93bc9d NS |
842 | /* Dump the suffix of type T, under control of FLAGS. This is the part |
843 | which appears after the identifier (or function parms). */ | |
844 | ||
8d08fdba | 845 | static void |
3c1ab1ab | 846 | dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
847 | { |
848 | if (TYPE_PTRMEMFUNC_P (t)) | |
849 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
850 | ||
851 | switch (TREE_CODE (t)) | |
852 | { | |
853 | case POINTER_TYPE: | |
854 | case REFERENCE_TYPE: | |
855 | case OFFSET_TYPE: | |
0d9c0892 JM |
856 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE |
857 | || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) | |
3c1ab1ab | 858 | pp_cxx_right_paren (pp); |
985acf5a PC |
859 | if (TREE_CODE (t) == POINTER_TYPE) |
860 | flags |= TFF_POINTER; | |
3c1ab1ab | 861 | dump_type_suffix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
862 | break; |
863 | ||
8d08fdba MS |
864 | case FUNCTION_TYPE: |
865 | case METHOD_TYPE: | |
866 | { | |
867 | tree arg; | |
0d9c0892 JM |
868 | if (TREE_CODE (t) == METHOD_TYPE) |
869 | /* Can only be reached through a pointer. */ | |
3c1ab1ab | 870 | pp_cxx_right_paren (pp); |
8d08fdba MS |
871 | arg = TYPE_ARG_TYPES (t); |
872 | if (TREE_CODE (t) == METHOD_TYPE) | |
873 | arg = TREE_CHAIN (arg); | |
874 | ||
4995028c NS |
875 | /* Function pointers don't have default args. Not in standard C++, |
876 | anyway; they may in g++, but we'll just pretend otherwise. */ | |
3c1ab1ab | 877 | dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS); |
4995028c | 878 | |
3c1ab1ab | 879 | pp->padding = pp_before; |
985acf5a PC |
880 | pp_cxx_cv_qualifiers (pp, type_memfn_quals (t), |
881 | TREE_CODE (t) == FUNCTION_TYPE | |
882 | && (flags & TFF_POINTER)); | |
3c1ab1ab GDR |
883 | dump_ref_qualifier (pp, t, flags); |
884 | dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags); | |
885 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba MS |
886 | break; |
887 | } | |
888 | ||
889 | case ARRAY_TYPE: | |
3c1ab1ab GDR |
890 | pp_maybe_space (pp); |
891 | pp_cxx_left_bracket (pp); | |
8d08fdba | 892 | if (TYPE_DOMAIN (t)) |
5156628f | 893 | { |
5e203bf8 RS |
894 | tree dtype = TYPE_DOMAIN (t); |
895 | tree max = TYPE_MAX_VALUE (dtype); | |
faddc0d7 | 896 | if (integer_all_onesp (max)) |
3c1ab1ab | 897 | pp_character (pp, '0'); |
9541ffee | 898 | else if (tree_fits_shwi_p (max)) |
9439e9a1 | 899 | pp_wide_integer (pp, tree_to_shwi (max) + 1); |
5156628f | 900 | else |
785b887e JM |
901 | { |
902 | STRIP_NOPS (max); | |
903 | if (TREE_CODE (max) == SAVE_EXPR) | |
904 | max = TREE_OPERAND (max, 0); | |
905 | if (TREE_CODE (max) == MINUS_EXPR | |
906 | || TREE_CODE (max) == PLUS_EXPR) | |
907 | { | |
908 | max = TREE_OPERAND (max, 0); | |
909 | while (CONVERT_EXPR_P (max)) | |
910 | max = TREE_OPERAND (max, 0); | |
911 | } | |
912 | else | |
913 | max = fold_build2_loc (input_location, | |
914 | PLUS_EXPR, dtype, max, | |
915 | build_int_cst (dtype, 1)); | |
3c1ab1ab | 916 | dump_expr (pp, max, flags & ~TFF_EXPR_IN_PARENS); |
785b887e | 917 | } |
5156628f | 918 | } |
3c1ab1ab GDR |
919 | pp_cxx_right_bracket (pp); |
920 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba | 921 | break; |
bb20cc46 | 922 | |
8d08fdba | 923 | case ENUMERAL_TYPE: |
8d08fdba MS |
924 | case IDENTIFIER_NODE: |
925 | case INTEGER_TYPE: | |
2986ae00 | 926 | case BOOLEAN_TYPE: |
8d08fdba MS |
927 | case REAL_TYPE: |
928 | case RECORD_TYPE: | |
929 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 930 | case TEMPLATE_TEMPLATE_PARM: |
a97d0689 | 931 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
932 | case TREE_LIST: |
933 | case TYPE_DECL: | |
934 | case TREE_VEC: | |
8d08fdba | 935 | case UNION_TYPE: |
fbfc8363 | 936 | case LANG_TYPE: |
8d08fdba | 937 | case VOID_TYPE: |
5566b478 | 938 | case TYPENAME_TYPE: |
37c46b43 | 939 | case COMPLEX_TYPE: |
c00996a3 | 940 | case VECTOR_TYPE: |
0df4ae96 | 941 | case TYPEOF_TYPE: |
a0d260fc | 942 | case UNDERLYING_TYPE: |
3ad6a8e1 | 943 | case DECLTYPE_TYPE: |
e7de2d6f | 944 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 945 | case FIXED_POINT_TYPE: |
1e85e720 | 946 | case NULLPTR_TYPE: |
8d08fdba MS |
947 | break; |
948 | ||
949 | default: | |
3c1ab1ab | 950 | pp_unsupported_tree (pp, t); |
9e93bc9d NS |
951 | case ERROR_MARK: |
952 | /* Don't mark it here, we should have already done in | |
0cbd7506 | 953 | dump_type_prefix. */ |
9e93bc9d | 954 | break; |
8d08fdba MS |
955 | } |
956 | } | |
957 | ||
49c249e1 | 958 | static void |
3c1ab1ab | 959 | dump_global_iord (cxx_pretty_printer *pp, tree t) |
8d08fdba | 960 | { |
99885b3f | 961 | const char *p = NULL; |
8d08fdba | 962 | |
92643fea | 963 | if (DECL_GLOBAL_CTOR_P (t)) |
f41c4af3 | 964 | p = M_("(static initializers for %s)"); |
92643fea | 965 | else if (DECL_GLOBAL_DTOR_P (t)) |
f41c4af3 | 966 | p = M_("(static destructors for %s)"); |
8d08fdba | 967 | else |
8dc2b103 | 968 | gcc_unreachable (); |
bb20cc46 | 969 | |
8400e75e | 970 | pp_printf (pp, p, LOCATION_FILE (input_location)); |
8d08fdba MS |
971 | } |
972 | ||
07389efe | 973 | static void |
3c1ab1ab | 974 | dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) |
07389efe | 975 | { |
761f0855 | 976 | if (flags & TFF_DECL_SPECIFIERS) |
07389efe | 977 | { |
5a6ccc94 | 978 | if (VAR_P (t) |
2842beb6 | 979 | && DECL_DECLARED_CONSTEXPR_P (t)) |
3c1ab1ab GDR |
980 | pp_cxx_ws_string (pp, "constexpr"); |
981 | dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME); | |
982 | pp_maybe_space (pp); | |
07389efe | 983 | } |
a0ad3539 | 984 | if (! (flags & TFF_UNQUALIFIED_NAME) |
af88c58f | 985 | && TREE_CODE (t) != PARM_DECL |
a0ad3539 MM |
986 | && (!DECL_INITIAL (t) |
987 | || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)) | |
3c1ab1ab | 988 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 989 | flags &= ~TFF_UNQUALIFIED_NAME; |
a022041e DG |
990 | if ((flags & TFF_DECL_SPECIFIERS) |
991 | && DECL_TEMPLATE_PARM_P (t) | |
992 | && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t))) | |
3c1ab1ab | 993 | pp_string (pp, "..."); |
07389efe | 994 | if (DECL_NAME (t)) |
af580858 | 995 | { |
76089b28 | 996 | if (TREE_CODE (t) == FIELD_DECL && DECL_NORMAL_CAPTURE_P (t)) |
af580858 | 997 | { |
3c1ab1ab GDR |
998 | pp_less (pp); |
999 | pp_string (pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2); | |
1000 | pp_string (pp, " capture>"); | |
af580858 JM |
1001 | } |
1002 | else | |
3c1ab1ab | 1003 | dump_decl (pp, DECL_NAME (t), flags); |
af580858 | 1004 | } |
07389efe | 1005 | else |
3c1ab1ab | 1006 | pp_string (pp, M_("<anonymous>")); |
761f0855 | 1007 | if (flags & TFF_DECL_SPECIFIERS) |
3c1ab1ab | 1008 | dump_type_suffix (pp, type, flags); |
07389efe MM |
1009 | } |
1010 | ||
9e93bc9d NS |
1011 | /* Dump a human readable string for the decl T under control of FLAGS. */ |
1012 | ||
8d08fdba | 1013 | static void |
3c1ab1ab | 1014 | dump_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1015 | { |
1016 | if (t == NULL_TREE) | |
1017 | return; | |
1018 | ||
be8cf3b5 NP |
1019 | /* If doing Objective-C++, give Objective-C a chance to demangle |
1020 | Objective-C method names. */ | |
1021 | if (c_dialect_objc ()) | |
1022 | { | |
1023 | const char *demangled = objc_maybe_printable_name (t, flags); | |
1024 | if (demangled) | |
1025 | { | |
3c1ab1ab | 1026 | pp_string (pp, demangled); |
be8cf3b5 NP |
1027 | return; |
1028 | } | |
1029 | } | |
1030 | ||
8d08fdba MS |
1031 | switch (TREE_CODE (t)) |
1032 | { | |
7177d104 | 1033 | case TYPE_DECL: |
b54a07e8 | 1034 | /* Don't say 'typedef class A' */ |
7c8b00f9 | 1035 | if (DECL_ARTIFICIAL (t) && !DECL_SELF_REFERENCE_P (t)) |
b54a07e8 NS |
1036 | { |
1037 | if ((flags & TFF_DECL_SPECIFIERS) | |
1038 | && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM) | |
a022041e DG |
1039 | { |
1040 | /* Say `class T' not just `T'. */ | |
3c1ab1ab | 1041 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1042 | |
1043 | /* Emit the `...' for a parameter pack. */ | |
1044 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1045 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1046 | } |
c8094d83 | 1047 | |
3c1ab1ab | 1048 | dump_type (pp, TREE_TYPE (t), flags); |
b54a07e8 NS |
1049 | break; |
1050 | } | |
28704289 DS |
1051 | if (TYPE_DECL_ALIAS_P (t) |
1052 | && (flags & TFF_DECL_SPECIFIERS | |
1053 | || flags & TFF_CLASS_KEY_OR_ENUM)) | |
1054 | { | |
3c1ab1ab GDR |
1055 | pp_cxx_ws_string (pp, "using"); |
1056 | dump_decl (pp, DECL_NAME (t), flags); | |
1057 | pp_cxx_whitespace (pp); | |
1058 | pp_cxx_ws_string (pp, "="); | |
1059 | pp_cxx_whitespace (pp); | |
1060 | dump_type (pp, DECL_ORIGINAL_TYPE (t), flags); | |
28704289 DS |
1061 | break; |
1062 | } | |
5a080ad7 JM |
1063 | if ((flags & TFF_DECL_SPECIFIERS) |
1064 | && !DECL_SELF_REFERENCE_P (t)) | |
3c1ab1ab GDR |
1065 | pp_cxx_ws_string (pp, "typedef"); |
1066 | dump_simple_decl (pp, t, DECL_ORIGINAL_TYPE (t) | |
9e93bc9d | 1067 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), |
0cbd7506 | 1068 | flags); |
7177d104 | 1069 | break; |
bb20cc46 | 1070 | |
8d08fdba | 1071 | case VAR_DECL: |
b7484fbe | 1072 | if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) |
8d08fdba | 1073 | { |
3c1ab1ab | 1074 | pp_string (pp, M_("vtable for ")); |
50bc768d | 1075 | gcc_assert (TYPE_P (DECL_CONTEXT (t))); |
3c1ab1ab | 1076 | dump_type (pp, DECL_CONTEXT (t), flags); |
8d08fdba MS |
1077 | break; |
1078 | } | |
f4f206f4 | 1079 | /* Else fall through. */ |
8d08fdba MS |
1080 | case FIELD_DECL: |
1081 | case PARM_DECL: | |
3c1ab1ab | 1082 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
aed67566 JM |
1083 | |
1084 | /* Handle variable template specializations. */ | |
1085 | if (TREE_CODE (t) == VAR_DECL | |
1086 | && DECL_LANG_SPECIFIC (t) | |
1087 | && DECL_TEMPLATE_INFO (t) | |
1088 | && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))) | |
1089 | { | |
1090 | pp_cxx_begin_template_argument_list (pp); | |
1091 | tree args = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t)); | |
1092 | dump_template_argument_list (pp, args, flags); | |
1093 | pp_cxx_end_template_argument_list (pp); | |
1094 | } | |
8d08fdba MS |
1095 | break; |
1096 | ||
f6a898ba | 1097 | case RESULT_DECL: |
3c1ab1ab GDR |
1098 | pp_string (pp, M_("<return value> ")); |
1099 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); | |
f6a898ba AO |
1100 | break; |
1101 | ||
a9aedbc2 | 1102 | case NAMESPACE_DECL: |
a2a9e21c | 1103 | if (flags & TFF_DECL_SPECIFIERS) |
8f0e4d72 | 1104 | pp->declaration (t); |
0c8feefe | 1105 | else |
0cbd7506 | 1106 | { |
a0ad3539 | 1107 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
3c1ab1ab | 1108 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 1109 | flags &= ~TFF_UNQUALIFIED_NAME; |
0cbd7506 | 1110 | if (DECL_NAME (t) == NULL_TREE) |
7496cd5b | 1111 | { |
3c1ab1ab GDR |
1112 | if (!(pp->flags & pp_c_flag_gnu_v3)) |
1113 | pp_cxx_ws_string (pp, M_("{anonymous}")); | |
7496cd5b | 1114 | else |
3c1ab1ab | 1115 | pp_cxx_ws_string (pp, M_("(anonymous namespace)")); |
7496cd5b | 1116 | } |
0cbd7506 | 1117 | else |
3c1ab1ab | 1118 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); |
0cbd7506 | 1119 | } |
a9aedbc2 MS |
1120 | break; |
1121 | ||
3e3f722c | 1122 | case SCOPE_REF: |
3c1ab1ab GDR |
1123 | dump_type (pp, TREE_OPERAND (t, 0), flags); |
1124 | pp_colon_colon (pp); | |
1125 | dump_decl (pp, TREE_OPERAND (t, 1), TFF_UNQUALIFIED_NAME); | |
bb20cc46 | 1126 | break; |
3e3f722c | 1127 | |
8d08fdba | 1128 | case ARRAY_REF: |
3c1ab1ab GDR |
1129 | dump_decl (pp, TREE_OPERAND (t, 0), flags); |
1130 | pp_cxx_left_bracket (pp); | |
1131 | dump_decl (pp, TREE_OPERAND (t, 1), flags); | |
1132 | pp_cxx_right_bracket (pp); | |
8d08fdba MS |
1133 | break; |
1134 | ||
2ce86d2e | 1135 | case ARRAY_NOTATION_REF: |
3c1ab1ab GDR |
1136 | dump_decl (pp, ARRAY_NOTATION_ARRAY (t), flags | TFF_EXPR_IN_PARENS); |
1137 | pp_cxx_left_bracket (pp); | |
1138 | dump_decl (pp, ARRAY_NOTATION_START (t), flags | TFF_EXPR_IN_PARENS); | |
1139 | pp_colon (pp); | |
1140 | dump_decl (pp, ARRAY_NOTATION_LENGTH (t), flags | TFF_EXPR_IN_PARENS); | |
1141 | pp_colon (pp); | |
1142 | dump_decl (pp, ARRAY_NOTATION_STRIDE (t), flags | TFF_EXPR_IN_PARENS); | |
1143 | pp_cxx_right_bracket (pp); | |
2ce86d2e BI |
1144 | break; |
1145 | ||
9e93bc9d | 1146 | /* So that we can do dump_decl on an aggr type. */ |
8d08fdba MS |
1147 | case RECORD_TYPE: |
1148 | case UNION_TYPE: | |
1149 | case ENUMERAL_TYPE: | |
3c1ab1ab | 1150 | dump_type (pp, t, flags); |
8d08fdba MS |
1151 | break; |
1152 | ||
814ae570 | 1153 | case BIT_NOT_EXPR: |
82911f36 | 1154 | /* This is a pseudo destructor call which has not been folded into |
0cbd7506 | 1155 | a PSEUDO_DTOR_EXPR yet. */ |
3c1ab1ab GDR |
1156 | pp_cxx_complement (pp); |
1157 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
814ae570 GB |
1158 | break; |
1159 | ||
8d08fdba | 1160 | case TYPE_EXPR: |
8dc2b103 | 1161 | gcc_unreachable (); |
8d08fdba MS |
1162 | break; |
1163 | ||
1164 | /* These special cases are duplicated here so that other functions | |
33bd39a2 | 1165 | can feed identifiers to error and get them demangled properly. */ |
8d08fdba | 1166 | case IDENTIFIER_NODE: |
dc5c569a JJ |
1167 | if (IDENTIFIER_TYPENAME_P (t)) |
1168 | { | |
3c1ab1ab | 1169 | pp_cxx_ws_string (pp, "operator"); |
dc5c569a | 1170 | /* Not exactly IDENTIFIER_TYPE_VALUE. */ |
3c1ab1ab | 1171 | dump_type (pp, TREE_TYPE (t), flags); |
dc5c569a JJ |
1172 | break; |
1173 | } | |
1174 | else | |
3c1ab1ab | 1175 | pp_cxx_tree_identifier (pp, t); |
8d08fdba MS |
1176 | break; |
1177 | ||
8f032717 | 1178 | case OVERLOAD: |
65a5559b MM |
1179 | if (OVL_CHAIN (t)) |
1180 | { | |
1181 | t = OVL_CURRENT (t); | |
1182 | if (DECL_CLASS_SCOPE_P (t)) | |
1183 | { | |
3c1ab1ab GDR |
1184 | dump_type (pp, DECL_CONTEXT (t), flags); |
1185 | pp_cxx_colon_colon (pp); | |
65a5559b | 1186 | } |
7f701cc1 | 1187 | else if (!DECL_FILE_SCOPE_P (t)) |
65a5559b | 1188 | { |
3c1ab1ab GDR |
1189 | dump_decl (pp, DECL_CONTEXT (t), flags); |
1190 | pp_cxx_colon_colon (pp); | |
65a5559b | 1191 | } |
3c1ab1ab | 1192 | dump_decl (pp, DECL_NAME (t), flags); |
65a5559b MM |
1193 | break; |
1194 | } | |
c8094d83 | 1195 | |
65a5559b MM |
1196 | /* If there's only one function, just treat it like an ordinary |
1197 | FUNCTION_DECL. */ | |
8f032717 MM |
1198 | t = OVL_CURRENT (t); |
1199 | /* Fall through. */ | |
1200 | ||
8d08fdba | 1201 | case FUNCTION_DECL: |
2d0db225 | 1202 | if (! DECL_LANG_SPECIFIC (t)) |
8aa1cce6 RB |
1203 | { |
1204 | if (DECL_ABSTRACT_ORIGIN (t)) | |
1205 | dump_decl (pp, DECL_ABSTRACT_ORIGIN (t), flags); | |
1206 | else | |
1207 | pp_string (pp, M_("<built-in>")); | |
1208 | } | |
2d0db225 | 1209 | else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) |
3c1ab1ab | 1210 | dump_global_iord (pp, t); |
8d08fdba | 1211 | else |
3c1ab1ab | 1212 | dump_function_decl (pp, t, flags); |
8d08fdba MS |
1213 | break; |
1214 | ||
1215 | case TEMPLATE_DECL: | |
3c1ab1ab | 1216 | dump_template_decl (pp, t, flags); |
8d08fdba MS |
1217 | break; |
1218 | ||
74cd8397 JM |
1219 | case TEMPLATE_ID_EXPR: |
1220 | { | |
aa36c081 | 1221 | tree name = TREE_OPERAND (t, 0); |
6c1e7aa9 | 1222 | tree args = TREE_OPERAND (t, 1); |
c8094d83 | 1223 | |
aa36c081 | 1224 | if (is_overloaded_fn (name)) |
a2033ab1 JM |
1225 | name = get_first_fn (name); |
1226 | if (DECL_P (name)) | |
1227 | name = DECL_NAME (name); | |
3c1ab1ab GDR |
1228 | dump_decl (pp, name, flags); |
1229 | pp_cxx_begin_template_argument_list (pp); | |
6c1e7aa9 | 1230 | if (args == error_mark_node) |
3c1ab1ab | 1231 | pp_string (pp, M_("<template arguments error>")); |
6c1e7aa9 | 1232 | else if (args) |
3c1ab1ab GDR |
1233 | dump_template_argument_list (pp, args, flags); |
1234 | pp_cxx_end_template_argument_list (pp); | |
74cd8397 JM |
1235 | } |
1236 | break; | |
1237 | ||
8d08fdba | 1238 | case LABEL_DECL: |
3c1ab1ab | 1239 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); |
8d08fdba MS |
1240 | break; |
1241 | ||
1242 | case CONST_DECL: | |
6467930b | 1243 | if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) |
03555413 | 1244 | || (DECL_INITIAL (t) && |
f84b4be9 | 1245 | TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX)) |
3c1ab1ab | 1246 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
224c649b | 1247 | else if (DECL_NAME (t)) |
3c1ab1ab | 1248 | dump_decl (pp, DECL_NAME (t), flags); |
03555413 | 1249 | else if (DECL_INITIAL (t)) |
3c1ab1ab | 1250 | dump_expr (pp, DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS); |
03555413 | 1251 | else |
3c1ab1ab | 1252 | pp_string (pp, M_("<enumerator>")); |
8d08fdba MS |
1253 | break; |
1254 | ||
cffa8729 | 1255 | case USING_DECL: |
3c1ab1ab GDR |
1256 | pp_cxx_ws_string (pp, "using"); |
1257 | dump_type (pp, USING_DECL_SCOPE (t), flags); | |
1258 | pp_cxx_colon_colon (pp); | |
1259 | dump_decl (pp, DECL_NAME (t), flags); | |
cffa8729 MS |
1260 | break; |
1261 | ||
55a3debe | 1262 | case STATIC_ASSERT: |
8f0e4d72 | 1263 | pp->declaration (t); |
55a3debe DG |
1264 | break; |
1265 | ||
50ad9642 | 1266 | case BASELINK: |
3c1ab1ab | 1267 | dump_decl (pp, BASELINK_FUNCTIONS (t), flags); |
50ad9642 MM |
1268 | break; |
1269 | ||
d17811fd | 1270 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 1271 | dump_expr (pp, t, flags); |
d17811fd MM |
1272 | break; |
1273 | ||
bf3e8283 GDR |
1274 | case TEMPLATE_TYPE_PARM: |
1275 | if (flags & TFF_DECL_SPECIFIERS) | |
8f0e4d72 | 1276 | pp->declaration (t); |
bf3e8283 | 1277 | else |
20059c8b | 1278 | pp->type_id (t); |
bf3e8283 GDR |
1279 | break; |
1280 | ||
2658bdae | 1281 | case UNBOUND_CLASS_TEMPLATE: |
930a1e63 | 1282 | case TYPE_PACK_EXPANSION: |
06be4f56 | 1283 | case TREE_BINFO: |
3c1ab1ab | 1284 | dump_type (pp, t, flags); |
2658bdae PC |
1285 | break; |
1286 | ||
8d08fdba | 1287 | default: |
3c1ab1ab | 1288 | pp_unsupported_tree (pp, t); |
852dcbdd | 1289 | /* Fall through to error. */ |
9e93bc9d NS |
1290 | |
1291 | case ERROR_MARK: | |
3c1ab1ab | 1292 | pp_string (pp, M_("<declaration error>")); |
9e93bc9d NS |
1293 | break; |
1294 | } | |
1295 | } | |
1296 | ||
1297 | /* Dump a template declaration T under control of FLAGS. This means the | |
1298 | 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */ | |
1299 | ||
1300 | static void | |
3c1ab1ab | 1301 | dump_template_decl (cxx_pretty_printer *pp, tree t, int flags) |
9e93bc9d | 1302 | { |
b5ac18ea MM |
1303 | tree orig_parms = DECL_TEMPLATE_PARMS (t); |
1304 | tree parms; | |
bb20cc46 AJ |
1305 | int i; |
1306 | ||
761f0855 | 1307 | if (flags & TFF_TEMPLATE_HEADER) |
9e93bc9d | 1308 | { |
bb20cc46 | 1309 | for (parms = orig_parms = nreverse (orig_parms); |
0cbd7506 MS |
1310 | parms; |
1311 | parms = TREE_CHAIN (parms)) | |
1312 | { | |
b5ac18ea | 1313 | tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms); |
0cbd7506 | 1314 | int len = TREE_VEC_LENGTH (inner_parms); |
bb20cc46 | 1315 | |
3c1ab1ab GDR |
1316 | pp_cxx_ws_string (pp, "template"); |
1317 | pp_cxx_begin_template_argument_list (pp); | |
38066e83 KL |
1318 | |
1319 | /* If we've shown the template prefix, we'd better show the | |
1320 | parameters' and decl's type too. */ | |
1321 | flags |= TFF_DECL_SPECIFIERS; | |
1322 | ||
0cbd7506 MS |
1323 | for (i = 0; i < len; i++) |
1324 | { | |
1325 | if (i) | |
3c1ab1ab GDR |
1326 | pp_separate_with_comma (pp); |
1327 | dump_template_parameter (pp, TREE_VEC_ELT (inner_parms, i), | |
1328 | flags); | |
0cbd7506 | 1329 | } |
3c1ab1ab GDR |
1330 | pp_cxx_end_template_argument_list (pp); |
1331 | pp_cxx_whitespace (pp); | |
0cbd7506 | 1332 | } |
b5ac18ea | 1333 | nreverse(orig_parms); |
38066e83 KL |
1334 | |
1335 | if (DECL_TEMPLATE_TEMPLATE_PARM_P (t)) | |
a022041e DG |
1336 | { |
1337 | /* Say `template<arg> class TT' not just `template<arg> TT'. */ | |
3c1ab1ab | 1338 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1339 | |
1340 | /* If this is a parameter pack, print the ellipsis. */ | |
1341 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1342 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1343 | } |
9e93bc9d | 1344 | } |
38066e83 | 1345 | |
28704289 | 1346 | if (DECL_CLASS_TEMPLATE_P (t)) |
3c1ab1ab | 1347 | dump_type (pp, TREE_TYPE (t), |
0cbd7506 MS |
1348 | ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1349 | | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0))); | |
b55276c8 | 1350 | else if (DECL_TEMPLATE_RESULT (t) |
5a6ccc94 | 1351 | && (VAR_P (DECL_TEMPLATE_RESULT (t)) |
28704289 DS |
1352 | /* Alias template. */ |
1353 | || DECL_TYPE_TEMPLATE_P (t))) | |
3c1ab1ab | 1354 | dump_decl (pp, DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME); |
9e93bc9d | 1355 | else |
9e93bc9d | 1356 | { |
8dc2b103 NS |
1357 | gcc_assert (TREE_TYPE (t)); |
1358 | switch (NEXT_CODE (t)) | |
1359 | { | |
1360 | case METHOD_TYPE: | |
1361 | case FUNCTION_TYPE: | |
3c1ab1ab | 1362 | dump_function_decl (pp, t, flags | TFF_TEMPLATE_NAME); |
8dc2b103 NS |
1363 | break; |
1364 | default: | |
1365 | /* This case can occur with some invalid code. */ | |
3c1ab1ab | 1366 | dump_type (pp, TREE_TYPE (t), |
8dc2b103 NS |
1367 | (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1368 | | (flags & TFF_DECL_SPECIFIERS | |
1369 | ? TFF_CLASS_KEY_OR_ENUM : 0)); | |
1370 | } | |
8d08fdba MS |
1371 | } |
1372 | } | |
1373 | ||
d5c8be27 | 1374 | /* find_typenames looks through the type of the function template T |
9771b263 | 1375 | and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs |
7cb4dfec | 1376 | it finds. */ |
d5c8be27 JM |
1377 | |
1378 | struct find_typenames_t | |
1379 | { | |
6e2830c3 | 1380 | hash_set<tree> *p_set; |
9771b263 | 1381 | vec<tree, va_gc> *typenames; |
d5c8be27 JM |
1382 | }; |
1383 | ||
1384 | static tree | |
ff9b4073 | 1385 | find_typenames_r (tree *tp, int *walk_subtrees, void *data) |
d5c8be27 JM |
1386 | { |
1387 | struct find_typenames_t *d = (struct find_typenames_t *)data; | |
a4d674fc JM |
1388 | tree mv = NULL_TREE; |
1389 | ||
1390 | if (TYPE_P (*tp) && is_typedef_decl (TYPE_NAME (*tp))) | |
1391 | /* Add the type of the typedef without any additional cv-quals. */ | |
1392 | mv = TREE_TYPE (TYPE_NAME (*tp)); | |
7cb4dfec JM |
1393 | else if (TREE_CODE (*tp) == TYPENAME_TYPE |
1394 | || TREE_CODE (*tp) == DECLTYPE_TYPE) | |
a4d674fc JM |
1395 | /* Add the typename without any cv-qualifiers. */ |
1396 | mv = TYPE_MAIN_VARIANT (*tp); | |
1397 | ||
ff9b4073 JM |
1398 | if (TREE_CODE (*tp) == TYPE_PACK_EXPANSION) |
1399 | { | |
1400 | /* Don't mess with parameter packs since we don't remember | |
1401 | the pack expansion context for a particular typename. */ | |
1402 | *walk_subtrees = false; | |
1403 | return NULL_TREE; | |
1404 | } | |
1405 | ||
6e2830c3 | 1406 | if (mv && (mv == *tp || !d->p_set->add (mv))) |
9771b263 | 1407 | vec_safe_push (d->typenames, mv); |
d5c8be27 | 1408 | |
d5c8be27 JM |
1409 | /* Search into class template arguments, which cp_walk_subtrees |
1410 | doesn't do. */ | |
a4d674fc JM |
1411 | if (CLASS_TYPE_P (*tp) && CLASSTYPE_TEMPLATE_INFO (*tp)) |
1412 | cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp), find_typenames_r, | |
1413 | data, d->p_set); | |
1414 | ||
d5c8be27 JM |
1415 | return NULL_TREE; |
1416 | } | |
1417 | ||
9771b263 | 1418 | static vec<tree, va_gc> * |
d5c8be27 JM |
1419 | find_typenames (tree t) |
1420 | { | |
1421 | struct find_typenames_t ft; | |
6e2830c3 | 1422 | ft.p_set = new hash_set<tree>; |
d5c8be27 JM |
1423 | ft.typenames = NULL; |
1424 | cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)), | |
1425 | find_typenames_r, &ft, ft.p_set); | |
6e2830c3 | 1426 | delete ft.p_set; |
d5c8be27 JM |
1427 | return ft.typenames; |
1428 | } | |
1429 | ||
753c4989 AB |
1430 | /* Output the "[with ...]" clause for a template instantiation T iff |
1431 | TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if | |
1432 | formatting a deduction/substitution diagnostic rather than an | |
1433 | instantiation. */ | |
1434 | ||
1435 | static void | |
1436 | dump_substitution (cxx_pretty_printer *pp, | |
1437 | tree t, tree template_parms, tree template_args, | |
1438 | int flags) | |
1439 | { | |
1440 | if (template_parms != NULL_TREE && template_args != NULL_TREE | |
1441 | && !(flags & TFF_NO_TEMPLATE_BINDINGS)) | |
1442 | { | |
1443 | vec<tree, va_gc> *typenames = t ? find_typenames (t) : NULL; | |
1444 | pp_cxx_whitespace (pp); | |
1445 | pp_cxx_left_bracket (pp); | |
1446 | pp->translate_string ("with"); | |
1447 | pp_cxx_whitespace (pp); | |
1448 | dump_template_bindings (pp, template_parms, template_args, typenames); | |
1449 | pp_cxx_right_bracket (pp); | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | /* Dump the lambda function FN including its 'mutable' qualifier and any | |
1454 | template bindings. */ | |
1455 | ||
1456 | static void | |
1457 | dump_lambda_function (cxx_pretty_printer *pp, | |
1458 | tree fn, tree template_parms, tree template_args, | |
1459 | int flags) | |
1460 | { | |
1461 | /* A lambda's signature is essentially its "type". */ | |
1462 | dump_type (pp, DECL_CONTEXT (fn), flags); | |
1463 | if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST)) | |
1464 | { | |
1465 | pp->padding = pp_before; | |
1466 | pp_c_ws_string (pp, "mutable"); | |
1467 | } | |
1468 | dump_substitution (pp, fn, template_parms, template_args, flags); | |
1469 | } | |
1470 | ||
4995028c | 1471 | /* Pretty print a function decl. There are several ways we want to print a |
761f0855 | 1472 | function declaration. The TFF_ bits in FLAGS tells us how to behave. |
33bd39a2 | 1473 | As error can only apply the '#' flag once to give 0 and 1 for V, there |
c6002625 | 1474 | is %D which doesn't print the throw specs, and %F which does. */ |
8d08fdba MS |
1475 | |
1476 | static void | |
3c1ab1ab | 1477 | dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 1478 | { |
98c1c668 JM |
1479 | tree fntype; |
1480 | tree parmtypes; | |
8d08fdba | 1481 | tree cname = NULL_TREE; |
612c671a GDR |
1482 | tree template_args = NULL_TREE; |
1483 | tree template_parms = NULL_TREE; | |
761f0855 | 1484 | int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS; |
a0ad3539 | 1485 | int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME); |
4d4e036d | 1486 | tree exceptions; |
d5f4eddd | 1487 | |
ee38ecd4 | 1488 | flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME); |
98c1c668 JM |
1489 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1490 | t = DECL_TEMPLATE_RESULT (t); | |
1491 | ||
4d4e036d PC |
1492 | /* Save the exceptions, in case t is a specialization and we are |
1493 | emitting an error about incompatible specifications. */ | |
1494 | exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t)); | |
1495 | ||
612c671a | 1496 | /* Pretty print template instantiations only. */ |
6ea2bd47 JM |
1497 | if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t) |
1498 | && flag_pretty_templates) | |
612c671a | 1499 | { |
f9a7ae04 MM |
1500 | tree tmpl; |
1501 | ||
612c671a | 1502 | template_args = DECL_TI_ARGS (t); |
f9a7ae04 MM |
1503 | tmpl = most_general_template (t); |
1504 | if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL) | |
1505 | { | |
1506 | template_parms = DECL_TEMPLATE_PARMS (tmpl); | |
1507 | t = tmpl; | |
1508 | } | |
612c671a GDR |
1509 | } |
1510 | ||
753c4989 AB |
1511 | if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) |
1512 | return dump_lambda_function (pp, t, template_parms, template_args, flags); | |
1513 | ||
98c1c668 | 1514 | fntype = TREE_TYPE (t); |
e0fff4b3 | 1515 | parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t); |
98c1c668 | 1516 | |
2642b9bf | 1517 | if (DECL_CLASS_SCOPE_P (t)) |
4f1c5b7d | 1518 | cname = DECL_CONTEXT (t); |
f4f206f4 | 1519 | /* This is for partially instantiated template methods. */ |
8d08fdba MS |
1520 | else if (TREE_CODE (fntype) == METHOD_TYPE) |
1521 | cname = TREE_TYPE (TREE_VALUE (parmtypes)); | |
1522 | ||
2842beb6 JM |
1523 | if (flags & TFF_DECL_SPECIFIERS) |
1524 | { | |
1525 | if (DECL_STATIC_FUNCTION_P (t)) | |
3c1ab1ab | 1526 | pp_cxx_ws_string (pp, "static"); |
2842beb6 | 1527 | else if (DECL_VIRTUAL_P (t)) |
3c1ab1ab | 1528 | pp_cxx_ws_string (pp, "virtual"); |
2842beb6 | 1529 | |
c582aac9 | 1530 | if (DECL_DECLARED_CONSTEXPR_P (t)) |
3c1ab1ab | 1531 | pp_cxx_ws_string (pp, "constexpr"); |
2842beb6 | 1532 | } |
bb20cc46 | 1533 | |
9e93bc9d NS |
1534 | /* Print the return type? */ |
1535 | if (show_return) | |
1536 | show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t) | |
0cbd7506 | 1537 | && !DECL_DESTRUCTOR_P (t); |
9e93bc9d | 1538 | if (show_return) |
79d8a272 JM |
1539 | { |
1540 | tree ret = fndecl_declared_return_type (t); | |
3c1ab1ab | 1541 | dump_type_prefix (pp, ret, flags); |
79d8a272 | 1542 | } |
8d08fdba | 1543 | |
61cd552e | 1544 | /* Print the function name. */ |
a0ad3539 MM |
1545 | if (!do_outer_scope) |
1546 | /* Nothing. */; | |
1547 | else if (cname) | |
8d08fdba | 1548 | { |
3c1ab1ab GDR |
1549 | dump_type (pp, cname, flags); |
1550 | pp_cxx_colon_colon (pp); | |
2642b9bf | 1551 | } |
9e93bc9d | 1552 | else |
3c1ab1ab | 1553 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
8d08fdba | 1554 | |
3c1ab1ab | 1555 | dump_function_name (pp, t, flags); |
bb20cc46 | 1556 | |
303357a7 | 1557 | if (!(flags & TFF_NO_FUNCTION_ARGUMENTS)) |
ad50e811 | 1558 | { |
3c1ab1ab | 1559 | dump_parameters (pp, parmtypes, flags); |
bb20cc46 | 1560 | |
ad50e811 | 1561 | if (TREE_CODE (fntype) == METHOD_TYPE) |
0cbd7506 | 1562 | { |
3c1ab1ab GDR |
1563 | pp->padding = pp_before; |
1564 | pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (fntype)); | |
1565 | dump_ref_qualifier (pp, fntype, flags); | |
0cbd7506 | 1566 | } |
bb20cc46 | 1567 | |
761f0855 | 1568 | if (flags & TFF_EXCEPTION_SPECIFICATION) |
0cbd7506 | 1569 | { |
3c1ab1ab GDR |
1570 | pp->padding = pp_before; |
1571 | dump_exception_spec (pp, exceptions, flags); | |
0cbd7506 | 1572 | } |
ad6b1795 JM |
1573 | |
1574 | if (show_return) | |
3c1ab1ab | 1575 | dump_type_suffix (pp, TREE_TYPE (fntype), flags); |
612c671a | 1576 | |
753c4989 | 1577 | dump_substitution (pp, t, template_parms, template_args, flags); |
21d69a5b JM |
1578 | } |
1579 | else if (template_args) | |
612c671a | 1580 | { |
21d69a5b JM |
1581 | bool need_comma = false; |
1582 | int i; | |
3c1ab1ab | 1583 | pp_cxx_begin_template_argument_list (pp); |
21d69a5b JM |
1584 | template_args = INNERMOST_TEMPLATE_ARGS (template_args); |
1585 | for (i = 0; i < TREE_VEC_LENGTH (template_args); ++i) | |
1586 | { | |
1587 | tree arg = TREE_VEC_ELT (template_args, i); | |
1588 | if (need_comma) | |
3c1ab1ab | 1589 | pp_separate_with_comma (pp); |
21d69a5b | 1590 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab GDR |
1591 | pp_cxx_left_brace (pp); |
1592 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
21d69a5b | 1593 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 1594 | pp_cxx_right_brace (pp); |
21d69a5b JM |
1595 | need_comma = true; |
1596 | } | |
3c1ab1ab | 1597 | pp_cxx_end_template_argument_list (pp); |
612c671a | 1598 | } |
4995028c NS |
1599 | } |
1600 | ||
9e93bc9d NS |
1601 | /* Print a parameter list. If this is for a member function, the |
1602 | member object ptr (and any other hidden args) should have | |
c6002625 | 1603 | already been removed. */ |
4995028c NS |
1604 | |
1605 | static void | |
3c1ab1ab | 1606 | dump_parameters (cxx_pretty_printer *pp, tree parmtypes, int flags) |
4995028c | 1607 | { |
5d80a306 | 1608 | int first = 1; |
af88c58f | 1609 | flags &= ~TFF_SCOPE; |
3c1ab1ab | 1610 | pp_cxx_left_paren (pp); |
4995028c NS |
1611 | |
1612 | for (first = 1; parmtypes != void_list_node; | |
1613 | parmtypes = TREE_CHAIN (parmtypes)) | |
1614 | { | |
1615 | if (!first) | |
3c1ab1ab | 1616 | pp_separate_with_comma (pp); |
4995028c NS |
1617 | first = 0; |
1618 | if (!parmtypes) | |
0cbd7506 | 1619 | { |
3c1ab1ab | 1620 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 MS |
1621 | break; |
1622 | } | |
31d40008 | 1623 | |
3c1ab1ab | 1624 | dump_type (pp, TREE_VALUE (parmtypes), flags); |
bb20cc46 | 1625 | |
761f0855 | 1626 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes)) |
0cbd7506 | 1627 | { |
3c1ab1ab GDR |
1628 | pp_cxx_whitespace (pp); |
1629 | pp_equal (pp); | |
1630 | pp_cxx_whitespace (pp); | |
1631 | dump_expr (pp, TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS); | |
0cbd7506 | 1632 | } |
4995028c NS |
1633 | } |
1634 | ||
3c1ab1ab | 1635 | pp_cxx_right_paren (pp); |
4995028c NS |
1636 | } |
1637 | ||
2eed8e37 BK |
1638 | /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */ |
1639 | ||
1640 | static void | |
3c1ab1ab | 1641 | dump_ref_qualifier (cxx_pretty_printer *pp, tree t, int flags ATTRIBUTE_UNUSED) |
2eed8e37 BK |
1642 | { |
1643 | if (FUNCTION_REF_QUALIFIED (t)) | |
1644 | { | |
3c1ab1ab | 1645 | pp->padding = pp_before; |
2eed8e37 | 1646 | if (FUNCTION_RVALUE_QUALIFIED (t)) |
3c1ab1ab | 1647 | pp_cxx_ws_string (pp, "&&"); |
2eed8e37 | 1648 | else |
3c1ab1ab | 1649 | pp_cxx_ws_string (pp, "&"); |
2eed8e37 BK |
1650 | } |
1651 | } | |
1652 | ||
c6002625 | 1653 | /* Print an exception specification. T is the exception specification. */ |
4995028c NS |
1654 | |
1655 | static void | |
3c1ab1ab | 1656 | dump_exception_spec (cxx_pretty_printer *pp, tree t, int flags) |
4995028c | 1657 | { |
3a55fb4c JM |
1658 | if (t && TREE_PURPOSE (t)) |
1659 | { | |
3c1ab1ab | 1660 | pp_cxx_ws_string (pp, "noexcept"); |
1a1f2bc5 JM |
1661 | if (!integer_onep (TREE_PURPOSE (t))) |
1662 | { | |
1663 | pp_cxx_whitespace (pp); | |
1664 | pp_cxx_left_paren (pp); | |
1665 | if (DEFERRED_NOEXCEPT_SPEC_P (t)) | |
1666 | pp_cxx_ws_string (pp, "<uninstantiated>"); | |
1667 | else | |
1668 | dump_expr (pp, TREE_PURPOSE (t), flags); | |
1669 | pp_cxx_right_paren (pp); | |
1670 | } | |
3a55fb4c JM |
1671 | } |
1672 | else if (t) | |
4995028c | 1673 | { |
3c1ab1ab GDR |
1674 | pp_cxx_ws_string (pp, "throw"); |
1675 | pp_cxx_whitespace (pp); | |
1676 | pp_cxx_left_paren (pp); | |
4995028c | 1677 | if (TREE_VALUE (t) != NULL_TREE) |
0cbd7506 MS |
1678 | while (1) |
1679 | { | |
3c1ab1ab | 1680 | dump_type (pp, TREE_VALUE (t), flags); |
0cbd7506 MS |
1681 | t = TREE_CHAIN (t); |
1682 | if (!t) | |
1683 | break; | |
3c1ab1ab | 1684 | pp_separate_with_comma (pp); |
0cbd7506 | 1685 | } |
3c1ab1ab | 1686 | pp_cxx_right_paren (pp); |
4995028c | 1687 | } |
8d08fdba MS |
1688 | } |
1689 | ||
1690 | /* Handle the function name for a FUNCTION_DECL node, grokking operators | |
1691 | and destructors properly. */ | |
e92cc029 | 1692 | |
8d08fdba | 1693 | static void |
3c1ab1ab | 1694 | dump_function_name (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1695 | { |
1696 | tree name = DECL_NAME (t); | |
1697 | ||
93604b1a ZW |
1698 | /* We can get here with a decl that was synthesized by language- |
1699 | independent machinery (e.g. coverage.c) in which case it won't | |
1700 | have a lang_specific structure attached and DECL_CONSTRUCTOR_P | |
1701 | will crash. In this case it is safe just to print out the | |
1702 | literal name. */ | |
1703 | if (!DECL_LANG_SPECIFIC (t)) | |
1704 | { | |
3c1ab1ab | 1705 | pp_cxx_tree_identifier (pp, name); |
93604b1a ZW |
1706 | return; |
1707 | } | |
1708 | ||
78abea27 RS |
1709 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1710 | t = DECL_TEMPLATE_RESULT (t); | |
1711 | ||
5e818b93 JM |
1712 | /* Don't let the user see __comp_ctor et al. */ |
1713 | if (DECL_CONSTRUCTOR_P (t) | |
1714 | || DECL_DESTRUCTOR_P (t)) | |
d5f4eddd JM |
1715 | { |
1716 | if (LAMBDA_TYPE_P (DECL_CONTEXT (t))) | |
1717 | name = get_identifier ("<lambda>"); | |
7996b727 JM |
1718 | else if (TYPE_ANONYMOUS_P (DECL_CONTEXT (t))) |
1719 | name = get_identifier ("<constructor>"); | |
d5f4eddd JM |
1720 | else |
1721 | name = constructor_name (DECL_CONTEXT (t)); | |
1722 | } | |
5e818b93 | 1723 | |
aa45967f | 1724 | if (DECL_DESTRUCTOR_P (t)) |
8d08fdba | 1725 | { |
3c1ab1ab GDR |
1726 | pp_cxx_complement (pp); |
1727 | dump_decl (pp, name, TFF_PLAIN_IDENTIFIER); | |
8d08fdba | 1728 | } |
aa45967f | 1729 | else if (DECL_CONV_FN_P (t)) |
8d08fdba MS |
1730 | { |
1731 | /* This cannot use the hack that the operator's return | |
1732 | type is stashed off of its name because it may be | |
1733 | used for error reporting. In the case of conflicting | |
1734 | declarations, both will have the same name, yet | |
1735 | the types will be different, hence the TREE_TYPE field | |
1736 | of the first name will be clobbered by the second. */ | |
3c1ab1ab GDR |
1737 | pp_cxx_ws_string (pp, "operator"); |
1738 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba | 1739 | } |
b97e8a14 | 1740 | else if (name && IDENTIFIER_OPNAME_P (name)) |
3c1ab1ab | 1741 | pp_cxx_tree_identifier (pp, name); |
3ce4f9e4 | 1742 | else if (name && UDLIT_OPER_P (name)) |
3c1ab1ab | 1743 | pp_cxx_tree_identifier (pp, name); |
8d08fdba | 1744 | else |
3c1ab1ab | 1745 | dump_decl (pp, name, flags); |
386b8a85 | 1746 | |
93604b1a | 1747 | if (DECL_TEMPLATE_INFO (t) |
05fd666b | 1748 | && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t) |
f0d60e22 | 1749 | && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL |
36a117a5 | 1750 | || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))) |
3c1ab1ab GDR |
1751 | dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), |
1752 | flags); | |
9e93bc9d | 1753 | } |
75650646 | 1754 | |
9e93bc9d NS |
1755 | /* Dump the template parameters from the template info INFO under control of |
1756 | FLAGS. PRIMARY indicates whether this is a primary template decl, or | |
1757 | specialization (partial or complete). For partial specializations we show | |
1758 | the specialized parameter values. For a primary template we show no | |
1759 | decoration. */ | |
1760 | ||
1761 | static void | |
3c1ab1ab GDR |
1762 | dump_template_parms (cxx_pretty_printer *pp, tree info, |
1763 | int primary, int flags) | |
9e93bc9d NS |
1764 | { |
1765 | tree args = info ? TI_ARGS (info) : NULL_TREE; | |
bb20cc46 | 1766 | |
761f0855 | 1767 | if (primary && flags & TFF_TEMPLATE_NAME) |
9e93bc9d | 1768 | return; |
761f0855 | 1769 | flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME); |
3c1ab1ab | 1770 | pp_cxx_begin_template_argument_list (pp); |
9e93bc9d NS |
1771 | |
1772 | /* Be careful only to print things when we have them, so as not | |
8cc77ebe | 1773 | to crash producing error messages. */ |
9e93bc9d NS |
1774 | if (args && !primary) |
1775 | { | |
bf12d54d | 1776 | int len, ix; |
1a048f82 | 1777 | len = get_non_default_template_args_count (args, flags); |
bb20cc46 | 1778 | |
11d7788d | 1779 | args = INNERMOST_TEMPLATE_ARGS (args); |
bf12d54d | 1780 | for (ix = 0; ix != len; ix++) |
0cbd7506 MS |
1781 | { |
1782 | tree arg = TREE_VEC_ELT (args, ix); | |
bf12d54d | 1783 | |
5d80a306 DG |
1784 | /* Only print a comma if we know there is an argument coming. In |
1785 | the case of an empty template argument pack, no actual | |
1786 | argument will be printed. */ | |
1787 | if (ix | |
1788 | && (!ARGUMENT_PACK_P (arg) | |
1789 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 1790 | pp_separate_with_comma (pp); |
5d80a306 DG |
1791 | |
1792 | if (!arg) | |
3c1ab1ab | 1793 | pp_string (pp, M_("<template parameter error>")); |
5d80a306 | 1794 | else |
3c1ab1ab | 1795 | dump_template_argument (pp, arg, flags); |
5d80a306 | 1796 | } |
9e93bc9d | 1797 | } |
9e93bc9d NS |
1798 | else if (primary) |
1799 | { | |
1800 | tree tpl = TI_TEMPLATE (info); | |
1801 | tree parms = DECL_TEMPLATE_PARMS (tpl); | |
1802 | int len, ix; | |
bb20cc46 | 1803 | |
9e93bc9d NS |
1804 | parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE; |
1805 | len = parms ? TREE_VEC_LENGTH (parms) : 0; | |
bb20cc46 | 1806 | |
9e93bc9d | 1807 | for (ix = 0; ix != len; ix++) |
0cbd7506 | 1808 | { |
2d8ba2c7 LM |
1809 | tree parm; |
1810 | ||
1811 | if (TREE_VEC_ELT (parms, ix) == error_mark_node) | |
1812 | { | |
3c1ab1ab | 1813 | pp_string (pp, M_("<template parameter error>")); |
2d8ba2c7 LM |
1814 | continue; |
1815 | } | |
1816 | ||
1817 | parm = TREE_VALUE (TREE_VEC_ELT (parms, ix)); | |
9e93bc9d | 1818 | |
0cbd7506 | 1819 | if (ix) |
3c1ab1ab | 1820 | pp_separate_with_comma (pp); |
bb20cc46 | 1821 | |
3c1ab1ab | 1822 | dump_decl (pp, parm, flags & ~TFF_DECL_SPECIFIERS); |
0cbd7506 | 1823 | } |
386b8a85 | 1824 | } |
3c1ab1ab | 1825 | pp_cxx_end_template_argument_list (pp); |
8d08fdba MS |
1826 | } |
1827 | ||
5039610b SL |
1828 | /* Print out the arguments of CALL_EXPR T as a parenthesized list using |
1829 | flags FLAGS. Skip over the first argument if SKIPFIRST is true. */ | |
1830 | ||
1831 | static void | |
3c1ab1ab | 1832 | dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst) |
5039610b SL |
1833 | { |
1834 | tree arg; | |
1835 | call_expr_arg_iterator iter; | |
1836 | ||
3c1ab1ab | 1837 | pp_cxx_left_paren (pp); |
5039610b SL |
1838 | FOR_EACH_CALL_EXPR_ARG (arg, iter, t) |
1839 | { | |
1840 | if (skipfirst) | |
1841 | skipfirst = false; | |
1842 | else | |
1843 | { | |
3c1ab1ab | 1844 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 1845 | if (more_call_expr_args_p (&iter)) |
3c1ab1ab | 1846 | pp_separate_with_comma (pp); |
5039610b SL |
1847 | } |
1848 | } | |
3c1ab1ab | 1849 | pp_cxx_right_paren (pp); |
5039610b SL |
1850 | } |
1851 | ||
1852 | /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list | |
1853 | using flags FLAGS. Skip over the first argument if SKIPFIRST is | |
1854 | true. */ | |
1855 | ||
1856 | static void | |
3c1ab1ab GDR |
1857 | dump_aggr_init_expr_args (cxx_pretty_printer *pp, tree t, int flags, |
1858 | bool skipfirst) | |
5039610b SL |
1859 | { |
1860 | tree arg; | |
1861 | aggr_init_expr_arg_iterator iter; | |
1862 | ||
3c1ab1ab | 1863 | pp_cxx_left_paren (pp); |
5039610b SL |
1864 | FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t) |
1865 | { | |
1866 | if (skipfirst) | |
1867 | skipfirst = false; | |
1868 | else | |
1869 | { | |
3c1ab1ab | 1870 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 1871 | if (more_aggr_init_expr_args_p (&iter)) |
3c1ab1ab | 1872 | pp_separate_with_comma (pp); |
5039610b SL |
1873 | } |
1874 | } | |
3c1ab1ab | 1875 | pp_cxx_right_paren (pp); |
5039610b SL |
1876 | } |
1877 | ||
f4f206f4 | 1878 | /* Print out a list of initializers (subr of dump_expr). */ |
e92cc029 | 1879 | |
8d08fdba | 1880 | static void |
3c1ab1ab | 1881 | dump_expr_list (cxx_pretty_printer *pp, tree l, int flags) |
8d08fdba MS |
1882 | { |
1883 | while (l) | |
1884 | { | |
3c1ab1ab | 1885 | dump_expr (pp, TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS); |
8d08fdba | 1886 | l = TREE_CHAIN (l); |
9e93bc9d | 1887 | if (l) |
3c1ab1ab | 1888 | pp_separate_with_comma (pp); |
8d08fdba MS |
1889 | } |
1890 | } | |
1891 | ||
4038c495 GB |
1892 | /* Print out a vector of initializers (subr of dump_expr). */ |
1893 | ||
1894 | static void | |
3c1ab1ab GDR |
1895 | dump_expr_init_vec (cxx_pretty_printer *pp, vec<constructor_elt, va_gc> *v, |
1896 | int flags) | |
4038c495 GB |
1897 | { |
1898 | unsigned HOST_WIDE_INT idx; | |
1899 | tree value; | |
1900 | ||
1901 | FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
1902 | { | |
3c1ab1ab | 1903 | dump_expr (pp, value, flags | TFF_EXPR_IN_PARENS); |
9771b263 | 1904 | if (idx != v->length () - 1) |
3c1ab1ab | 1905 | pp_separate_with_comma (pp); |
4038c495 GB |
1906 | } |
1907 | } | |
1908 | ||
1909 | ||
7f58e7ac GDR |
1910 | /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual |
1911 | function. Resolve it to a close relative -- in the sense of static | |
1912 | type -- variant being overridden. That is close to what was written in | |
1913 | the source code. Subroutine of dump_expr. */ | |
1914 | ||
1915 | static tree | |
1916 | resolve_virtual_fun_from_obj_type_ref (tree ref) | |
1917 | { | |
1918 | tree obj_type = TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref)); | |
ae7e9ddd | 1919 | HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref)); |
7f58e7ac | 1920 | tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type))); |
c6f3d2f4 JJ |
1921 | while (index) |
1922 | { | |
7f58e7ac | 1923 | fun = TREE_CHAIN (fun); |
c6f3d2f4 JJ |
1924 | index -= (TARGET_VTABLE_USES_DESCRIPTORS |
1925 | ? TARGET_VTABLE_USES_DESCRIPTORS : 1); | |
1926 | } | |
7f58e7ac GDR |
1927 | |
1928 | return BV_FN (fun); | |
1929 | } | |
1930 | ||
c6002625 | 1931 | /* Print out an expression E under control of FLAGS. */ |
e92cc029 | 1932 | |
8d08fdba | 1933 | static void |
3c1ab1ab | 1934 | dump_expr (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 1935 | { |
a1e03bc5 JM |
1936 | tree op; |
1937 | ||
8c048a52 GDR |
1938 | if (t == 0) |
1939 | return; | |
c8094d83 | 1940 | |
10a6624a PC |
1941 | if (STATEMENT_CLASS_P (t)) |
1942 | { | |
3c1ab1ab | 1943 | pp_cxx_ws_string (pp, M_("<statement>")); |
10a6624a PC |
1944 | return; |
1945 | } | |
1946 | ||
8d08fdba MS |
1947 | switch (TREE_CODE (t)) |
1948 | { | |
1949 | case VAR_DECL: | |
1950 | case PARM_DECL: | |
1951 | case FIELD_DECL: | |
1952 | case CONST_DECL: | |
1953 | case FUNCTION_DECL: | |
ec255269 | 1954 | case TEMPLATE_DECL: |
6b57ac29 | 1955 | case NAMESPACE_DECL: |
39e837db | 1956 | case LABEL_DECL: |
5d73aa63 | 1957 | case OVERLOAD: |
501c95ff | 1958 | case TYPE_DECL: |
a723baf1 | 1959 | case IDENTIFIER_NODE: |
3c1ab1ab GDR |
1960 | dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE |
1961 | |TFF_TEMPLATE_HEADER)) | |
1962 | | TFF_NO_FUNCTION_ARGUMENTS)); | |
8d08fdba MS |
1963 | break; |
1964 | ||
a5952633 | 1965 | case SSA_NAME: |
70b5e7dc RG |
1966 | if (SSA_NAME_VAR (t) |
1967 | && !DECL_ARTIFICIAL (SSA_NAME_VAR (t))) | |
3c1ab1ab | 1968 | dump_expr (pp, SSA_NAME_VAR (t), flags); |
a5952633 | 1969 | else |
3c1ab1ab | 1970 | pp_cxx_ws_string (pp, M_("<unknown>")); |
a5952633 RG |
1971 | break; |
1972 | ||
632f2871 | 1973 | case VOID_CST: |
7a8380ae | 1974 | case INTEGER_CST: |
8d08fdba | 1975 | case REAL_CST: |
a176426f | 1976 | case STRING_CST: |
7368348c | 1977 | case COMPLEX_CST: |
20059c8b | 1978 | pp->constant (t); |
8d08fdba MS |
1979 | break; |
1980 | ||
3ce4f9e4 | 1981 | case USERDEF_LITERAL: |
3c1ab1ab | 1982 | pp_cxx_userdef_literal (pp, t); |
3ce4f9e4 ESR |
1983 | break; |
1984 | ||
1c09c5e5 | 1985 | case THROW_EXPR: |
d8b4270d PC |
1986 | /* While waiting for caret diagnostics, avoid printing |
1987 | __cxa_allocate_exception, __cxa_throw, and the like. */ | |
3c1ab1ab | 1988 | pp_cxx_ws_string (pp, M_("<throw-expression>")); |
1c09c5e5 GDR |
1989 | break; |
1990 | ||
61a127b3 | 1991 | case PTRMEM_CST: |
3c1ab1ab GDR |
1992 | pp_ampersand (pp); |
1993 | dump_type (pp, PTRMEM_CST_CLASS (t), flags); | |
1994 | pp_cxx_colon_colon (pp); | |
1995 | pp_cxx_tree_identifier (pp, DECL_NAME (PTRMEM_CST_MEMBER (t))); | |
61a127b3 MM |
1996 | break; |
1997 | ||
8d08fdba | 1998 | case COMPOUND_EXPR: |
3c1ab1ab GDR |
1999 | pp_cxx_left_paren (pp); |
2000 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2001 | pp_separate_with_comma (pp); | |
2002 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2003 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2004 | break; |
2005 | ||
2006 | case COND_EXPR: | |
3c1ab1ab GDR |
2007 | pp_cxx_left_paren (pp); |
2008 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2009 | pp_string (pp, " ? "); | |
2010 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2011 | pp_string (pp, " : "); | |
2012 | dump_expr (pp, TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS); | |
2013 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2014 | break; |
2015 | ||
2016 | case SAVE_EXPR: | |
2017 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2018 | { | |
3c1ab1ab GDR |
2019 | pp_cxx_ws_string (pp, "new"); |
2020 | pp_cxx_whitespace (pp); | |
2021 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba MS |
2022 | } |
2023 | else | |
3c1ab1ab | 2024 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2025 | break; |
2026 | ||
02531345 | 2027 | case AGGR_INIT_EXPR: |
27b8d0cd MM |
2028 | { |
2029 | tree fn = NULL_TREE; | |
bb20cc46 | 2030 | |
5039610b SL |
2031 | if (TREE_CODE (AGGR_INIT_EXPR_FN (t)) == ADDR_EXPR) |
2032 | fn = TREE_OPERAND (AGGR_INIT_EXPR_FN (t), 0); | |
27b8d0cd MM |
2033 | |
2034 | if (fn && TREE_CODE (fn) == FUNCTION_DECL) | |
2035 | { | |
2036 | if (DECL_CONSTRUCTOR_P (fn)) | |
3c1ab1ab | 2037 | dump_type (pp, DECL_CONTEXT (fn), flags); |
27b8d0cd | 2038 | else |
3c1ab1ab | 2039 | dump_decl (pp, fn, 0); |
27b8d0cd MM |
2040 | } |
2041 | else | |
3c1ab1ab | 2042 | dump_expr (pp, AGGR_INIT_EXPR_FN (t), 0); |
27b8d0cd | 2043 | } |
3c1ab1ab | 2044 | dump_aggr_init_expr_args (pp, t, flags, true); |
8d08fdba MS |
2045 | break; |
2046 | ||
2047 | case CALL_EXPR: | |
2048 | { | |
5039610b SL |
2049 | tree fn = CALL_EXPR_FN (t); |
2050 | bool skipfirst = false; | |
bb20cc46 | 2051 | |
0b274c17 MP |
2052 | /* Deal with internal functions. */ |
2053 | if (fn == NULL_TREE) | |
2054 | { | |
2055 | pp_string (pp, internal_fn_name (CALL_EXPR_IFN (t))); | |
2056 | dump_call_expr_args (pp, t, flags, skipfirst); | |
2057 | break; | |
2058 | } | |
2059 | ||
8d08fdba MS |
2060 | if (TREE_CODE (fn) == ADDR_EXPR) |
2061 | fn = TREE_OPERAND (fn, 0); | |
2062 | ||
3db45ab5 MS |
2063 | /* Nobody is interested in seeing the guts of vcalls. */ |
2064 | if (TREE_CODE (fn) == OBJ_TYPE_REF) | |
2065 | fn = resolve_virtual_fun_from_obj_type_ref (fn); | |
7f58e7ac | 2066 | |
dd6f4f89 JJ |
2067 | if (TREE_TYPE (fn) != NULL_TREE |
2068 | && NEXT_CODE (fn) == METHOD_TYPE | |
2069 | && call_expr_nargs (t)) | |
8d08fdba | 2070 | { |
5039610b | 2071 | tree ob = CALL_EXPR_ARG (t, 0); |
8d08fdba MS |
2072 | if (TREE_CODE (ob) == ADDR_EXPR) |
2073 | { | |
3c1ab1ab GDR |
2074 | dump_expr (pp, TREE_OPERAND (ob, 0), |
2075 | flags | TFF_EXPR_IN_PARENS); | |
2076 | pp_cxx_dot (pp); | |
8d08fdba MS |
2077 | } |
2078 | else if (TREE_CODE (ob) != PARM_DECL | |
2079 | || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")) | |
2080 | { | |
3c1ab1ab GDR |
2081 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2082 | pp_cxx_arrow (pp); | |
8d08fdba | 2083 | } |
5039610b | 2084 | skipfirst = true; |
8d08fdba | 2085 | } |
de5a5fa1 MP |
2086 | if (flag_sanitize & SANITIZE_UNDEFINED |
2087 | && is_ubsan_builtin_p (fn)) | |
2088 | { | |
2089 | pp_string (cxx_pp, M_("<ubsan routine call>")); | |
2090 | break; | |
2091 | } | |
3c1ab1ab GDR |
2092 | dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS); |
2093 | dump_call_expr_args (pp, t, flags, skipfirst); | |
8d08fdba MS |
2094 | } |
2095 | break; | |
2096 | ||
8d08fdba MS |
2097 | case TARGET_EXPR: |
2098 | /* Note that this only works for G++ target exprs. If somebody | |
2099 | builds a general TARGET_EXPR, there's no way to represent that | |
2100 | it initializes anything other that the parameter slot for the | |
2101 | default argument. Note we may have cleared out the first | |
2102 | operand in expand_expr, so don't go killing ourselves. */ | |
2103 | if (TREE_OPERAND (t, 1)) | |
3c1ab1ab | 2104 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2105 | break; |
2106 | ||
d7705934 | 2107 | case POINTER_PLUS_EXPR: |
3c1ab1ab | 2108 | dump_binary_op (pp, "+", t, flags); |
d7705934 DB |
2109 | break; |
2110 | ||
b3ab27f3 | 2111 | case INIT_EXPR: |
8d08fdba | 2112 | case MODIFY_EXPR: |
3c1ab1ab | 2113 | dump_binary_op (pp, assignment_operator_name_info[NOP_EXPR].name, |
a11e05f4 JM |
2114 | t, flags); |
2115 | break; | |
2116 | ||
8d08fdba MS |
2117 | case PLUS_EXPR: |
2118 | case MINUS_EXPR: | |
2119 | case MULT_EXPR: | |
2120 | case TRUNC_DIV_EXPR: | |
2121 | case TRUNC_MOD_EXPR: | |
2122 | case MIN_EXPR: | |
2123 | case MAX_EXPR: | |
2124 | case LSHIFT_EXPR: | |
2125 | case RSHIFT_EXPR: | |
2126 | case BIT_IOR_EXPR: | |
2127 | case BIT_XOR_EXPR: | |
2128 | case BIT_AND_EXPR: | |
8d08fdba MS |
2129 | case TRUTH_ANDIF_EXPR: |
2130 | case TRUTH_ORIF_EXPR: | |
2131 | case LT_EXPR: | |
2132 | case LE_EXPR: | |
2133 | case GT_EXPR: | |
2134 | case GE_EXPR: | |
2135 | case EQ_EXPR: | |
2136 | case NE_EXPR: | |
2adeacc9 | 2137 | case EXACT_DIV_EXPR: |
3c1ab1ab | 2138 | dump_binary_op (pp, operator_name_info[TREE_CODE (t)].name, t, flags); |
8d08fdba MS |
2139 | break; |
2140 | ||
2141 | case CEIL_DIV_EXPR: | |
2142 | case FLOOR_DIV_EXPR: | |
2143 | case ROUND_DIV_EXPR: | |
ba52691c | 2144 | case RDIV_EXPR: |
3c1ab1ab | 2145 | dump_binary_op (pp, "/", t, flags); |
8d08fdba MS |
2146 | break; |
2147 | ||
2148 | case CEIL_MOD_EXPR: | |
2149 | case FLOOR_MOD_EXPR: | |
2150 | case ROUND_MOD_EXPR: | |
3c1ab1ab | 2151 | dump_binary_op (pp, "%", t, flags); |
8d08fdba MS |
2152 | break; |
2153 | ||
2154 | case COMPONENT_REF: | |
2155 | { | |
2156 | tree ob = TREE_OPERAND (t, 0); | |
591cb3cf | 2157 | if (INDIRECT_REF_P (ob)) |
8d08fdba MS |
2158 | { |
2159 | ob = TREE_OPERAND (ob, 0); | |
2160 | if (TREE_CODE (ob) != PARM_DECL | |
c4eacf99 NS |
2161 | || (DECL_NAME (ob) |
2162 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))) | |
8d08fdba | 2163 | { |
3c1ab1ab | 2164 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
87fd3cf1 | 2165 | if (TREE_CODE (TREE_TYPE (ob)) == REFERENCE_TYPE) |
3c1ab1ab | 2166 | pp_cxx_dot (pp); |
87fd3cf1 | 2167 | else |
3c1ab1ab | 2168 | pp_cxx_arrow (pp); |
8d08fdba MS |
2169 | } |
2170 | } | |
2171 | else | |
2172 | { | |
3c1ab1ab GDR |
2173 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2174 | pp_cxx_dot (pp); | |
8d08fdba | 2175 | } |
3c1ab1ab | 2176 | dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2177 | } |
2178 | break; | |
2179 | ||
28cbf42c | 2180 | case ARRAY_REF: |
3c1ab1ab GDR |
2181 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
2182 | pp_cxx_left_bracket (pp); | |
2183 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2184 | pp_cxx_right_bracket (pp); | |
2ce86d2e BI |
2185 | break; |
2186 | ||
2187 | case ARRAY_NOTATION_REF: | |
3c1ab1ab GDR |
2188 | dump_expr (pp, ARRAY_NOTATION_ARRAY (t), flags | TFF_EXPR_IN_PARENS); |
2189 | pp_cxx_left_bracket (pp); | |
2190 | dump_expr (pp, ARRAY_NOTATION_START (t), flags | TFF_EXPR_IN_PARENS); | |
2191 | pp_colon (pp); | |
2192 | dump_expr (pp, ARRAY_NOTATION_LENGTH (t), flags | TFF_EXPR_IN_PARENS); | |
2193 | pp_colon (pp); | |
2194 | dump_expr (pp, ARRAY_NOTATION_STRIDE (t), flags | TFF_EXPR_IN_PARENS); | |
2195 | pp_cxx_right_bracket (pp); | |
28cbf42c MS |
2196 | break; |
2197 | ||
392e3d51 | 2198 | case UNARY_PLUS_EXPR: |
3c1ab1ab | 2199 | dump_unary_op (pp, "+", t, flags); |
8d08fdba MS |
2200 | break; |
2201 | ||
2202 | case ADDR_EXPR: | |
2203 | if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL | |
fd74ca0b MM |
2204 | || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST |
2205 | /* An ADDR_EXPR can have reference type. In that case, we | |
2206 | shouldn't print the `&' doing so indicates to the user | |
2207 | that the expression has pointer type. */ | |
bb20cc46 | 2208 | || (TREE_TYPE (t) |
fd74ca0b | 2209 | && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)) |
3c1ab1ab | 2210 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
39e837db | 2211 | else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL) |
3c1ab1ab | 2212 | dump_unary_op (pp, "&&", t, flags); |
8d08fdba | 2213 | else |
3c1ab1ab | 2214 | dump_unary_op (pp, "&", t, flags); |
8d08fdba MS |
2215 | break; |
2216 | ||
2217 | case INDIRECT_REF: | |
2218 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2219 | { | |
2220 | t = TREE_OPERAND (t, 0); | |
50bc768d | 2221 | gcc_assert (TREE_CODE (t) == CALL_EXPR); |
3c1ab1ab GDR |
2222 | dump_expr (pp, CALL_EXPR_FN (t), flags | TFF_EXPR_IN_PARENS); |
2223 | dump_call_expr_args (pp, t, flags, true); | |
8d08fdba MS |
2224 | } |
2225 | else | |
2226 | { | |
6467930b | 2227 | if (TREE_OPERAND (t,0) != NULL_TREE |
5082a355 | 2228 | && TREE_TYPE (TREE_OPERAND (t, 0)) |
6467930b | 2229 | && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE) |
3c1ab1ab | 2230 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
8d08fdba | 2231 | else |
3c1ab1ab | 2232 | dump_unary_op (pp, "*", t, flags); |
8d08fdba MS |
2233 | } |
2234 | break; | |
2235 | ||
892f6119 RG |
2236 | case MEM_REF: |
2237 | if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR | |
2238 | && integer_zerop (TREE_OPERAND (t, 1))) | |
3c1ab1ab | 2239 | dump_expr (pp, TREE_OPERAND (TREE_OPERAND (t, 0), 0), flags); |
892f6119 RG |
2240 | else |
2241 | { | |
3c1ab1ab | 2242 | pp_cxx_star (pp); |
892f6119 RG |
2243 | if (!integer_zerop (TREE_OPERAND (t, 1))) |
2244 | { | |
3c1ab1ab | 2245 | pp_cxx_left_paren (pp); |
892f6119 RG |
2246 | if (!integer_onep (TYPE_SIZE_UNIT |
2247 | (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)))))) | |
2248 | { | |
3c1ab1ab GDR |
2249 | pp_cxx_left_paren (pp); |
2250 | dump_type (pp, ptr_type_node, flags); | |
2251 | pp_cxx_right_paren (pp); | |
892f6119 RG |
2252 | } |
2253 | } | |
3c1ab1ab | 2254 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
892f6119 RG |
2255 | if (!integer_zerop (TREE_OPERAND (t, 1))) |
2256 | { | |
3c1ab1ab GDR |
2257 | pp_cxx_ws_string (pp, "+"); |
2258 | dump_expr (pp, fold_convert (ssizetype, TREE_OPERAND (t, 1)), | |
2259 | flags); | |
2260 | pp_cxx_right_paren (pp); | |
892f6119 RG |
2261 | } |
2262 | } | |
2263 | break; | |
2264 | ||
8d08fdba MS |
2265 | case NEGATE_EXPR: |
2266 | case BIT_NOT_EXPR: | |
2267 | case TRUTH_NOT_EXPR: | |
2268 | case PREDECREMENT_EXPR: | |
2269 | case PREINCREMENT_EXPR: | |
3c1ab1ab | 2270 | dump_unary_op (pp, operator_name_info [TREE_CODE (t)].name, t, flags); |
8d08fdba MS |
2271 | break; |
2272 | ||
2273 | case POSTDECREMENT_EXPR: | |
2274 | case POSTINCREMENT_EXPR: | |
3c1ab1ab GDR |
2275 | pp_cxx_left_paren (pp); |
2276 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2277 | pp_cxx_ws_string (pp, operator_name_info[TREE_CODE (t)].name); | |
2278 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2279 | break; |
2280 | ||
2281 | case NON_LVALUE_EXPR: | |
2282 | /* FIXME: This is a KLUDGE workaround for a parsing problem. There | |
2283 | should be another level of INDIRECT_REF so that I don't have to do | |
2284 | this. */ | |
6467930b | 2285 | if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE) |
8d08fdba MS |
2286 | { |
2287 | tree next = TREE_TYPE (TREE_TYPE (t)); | |
2288 | ||
50e10fa8 | 2289 | while (TYPE_PTR_P (next)) |
8d08fdba | 2290 | next = TREE_TYPE (next); |
bb20cc46 | 2291 | |
8d08fdba MS |
2292 | if (TREE_CODE (next) == FUNCTION_TYPE) |
2293 | { | |
761f0855 | 2294 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
2295 | pp_cxx_left_paren (pp); |
2296 | pp_cxx_star (pp); | |
2297 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 2298 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2299 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2300 | break; |
2301 | } | |
f4f206f4 | 2302 | /* Else fall through. */ |
8d08fdba | 2303 | } |
3c1ab1ab | 2304 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2305 | break; |
2306 | ||
63a906f0 | 2307 | CASE_CONVERT: |
a4474a38 | 2308 | case IMPLICIT_CONV_EXPR: |
b8ce93da | 2309 | case VIEW_CONVERT_EXPR: |
ffc76561 NS |
2310 | { |
2311 | tree op = TREE_OPERAND (t, 0); | |
75d980ab JM |
2312 | tree ttype = TREE_TYPE (t); |
2313 | tree optype = TREE_TYPE (op); | |
2314 | ||
2315 | if (TREE_CODE (ttype) != TREE_CODE (optype) | |
2316 | && POINTER_TYPE_P (ttype) | |
2317 | && POINTER_TYPE_P (optype) | |
2318 | && same_type_p (TREE_TYPE (optype), | |
2319 | TREE_TYPE (ttype))) | |
2320 | { | |
2321 | if (TREE_CODE (ttype) == REFERENCE_TYPE) | |
e4c4792d JM |
2322 | { |
2323 | STRIP_NOPS (op); | |
2324 | if (TREE_CODE (op) == ADDR_EXPR) | |
2325 | dump_expr (pp, TREE_OPERAND (op, 0), flags); | |
2326 | else | |
2327 | dump_unary_op (pp, "*", t, flags); | |
2328 | } | |
75d980ab | 2329 | else |
3c1ab1ab | 2330 | dump_unary_op (pp, "&", t, flags); |
75d980ab JM |
2331 | } |
2332 | else if (!same_type_p (TREE_TYPE (op), TREE_TYPE (t))) | |
ffc76561 NS |
2333 | { |
2334 | /* It is a cast, but we cannot tell whether it is a | |
2335 | reinterpret or static cast. Use the C style notation. */ | |
2336 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab GDR |
2337 | pp_cxx_left_paren (pp); |
2338 | pp_cxx_left_paren (pp); | |
2339 | dump_type (pp, TREE_TYPE (t), flags); | |
2340 | pp_cxx_right_paren (pp); | |
2341 | dump_expr (pp, op, flags | TFF_EXPR_IN_PARENS); | |
ffc76561 | 2342 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2343 | pp_cxx_right_paren (pp); |
ffc76561 NS |
2344 | } |
2345 | else | |
3c1ab1ab | 2346 | dump_expr (pp, op, flags); |
ffc76561 NS |
2347 | break; |
2348 | } | |
c8094d83 | 2349 | |
8d08fdba | 2350 | case CONSTRUCTOR: |
9a3b49ac MS |
2351 | if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) |
2352 | { | |
50ad9642 | 2353 | tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier); |
9a3b49ac | 2354 | |
c4372ef4 | 2355 | if (integer_zerop (idx)) |
e08a8f45 MM |
2356 | { |
2357 | /* A NULL pointer-to-member constant. */ | |
3c1ab1ab GDR |
2358 | pp_cxx_left_paren (pp); |
2359 | pp_cxx_left_paren (pp); | |
2360 | dump_type (pp, TREE_TYPE (t), flags); | |
2361 | pp_cxx_right_paren (pp); | |
2362 | pp_character (pp, '0'); | |
2363 | pp_cxx_right_paren (pp); | |
e08a8f45 MM |
2364 | break; |
2365 | } | |
9541ffee | 2366 | else if (tree_fits_shwi_p (idx)) |
9a3b49ac MS |
2367 | { |
2368 | tree virtuals; | |
2369 | unsigned HOST_WIDE_INT n; | |
2370 | ||
2371 | t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t))); | |
2372 | t = TYPE_METHOD_BASETYPE (t); | |
604a3205 | 2373 | virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t))); |
bb20cc46 | 2374 | |
9439e9a1 | 2375 | n = tree_to_shwi (idx); |
9a3b49ac MS |
2376 | |
2377 | /* Map vtable index back one, to allow for the null pointer to | |
2378 | member. */ | |
2379 | --n; | |
2380 | ||
2381 | while (n > 0 && virtuals) | |
2382 | { | |
2383 | --n; | |
2384 | virtuals = TREE_CHAIN (virtuals); | |
2385 | } | |
2386 | if (virtuals) | |
2387 | { | |
3c1ab1ab | 2388 | dump_expr (pp, BV_FN (virtuals), |
0cbd7506 | 2389 | flags | TFF_EXPR_IN_PARENS); |
9a3b49ac MS |
2390 | break; |
2391 | } | |
2392 | } | |
2393 | } | |
539b471b | 2394 | if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t))) |
3c1ab1ab | 2395 | pp_string (pp, "<lambda closure object>"); |
4038c495 | 2396 | if (TREE_TYPE (t) && EMPTY_CONSTRUCTOR_P (t)) |
f3146d75 | 2397 | { |
3c1ab1ab GDR |
2398 | dump_type (pp, TREE_TYPE (t), 0); |
2399 | pp_cxx_left_paren (pp); | |
2400 | pp_cxx_right_paren (pp); | |
f3146d75 NS |
2401 | } |
2402 | else | |
2403 | { | |
11a36a27 | 2404 | if (!BRACE_ENCLOSED_INITIALIZER_P (t)) |
3c1ab1ab GDR |
2405 | dump_type (pp, TREE_TYPE (t), 0); |
2406 | pp_cxx_left_brace (pp); | |
2407 | dump_expr_init_vec (pp, CONSTRUCTOR_ELTS (t), flags); | |
2408 | pp_cxx_right_brace (pp); | |
f3146d75 | 2409 | } |
c8094d83 | 2410 | |
8d08fdba MS |
2411 | break; |
2412 | ||
51c184be MS |
2413 | case OFFSET_REF: |
2414 | { | |
2415 | tree ob = TREE_OPERAND (t, 0); | |
51924768 | 2416 | if (is_dummy_object (ob)) |
61a127b3 | 2417 | { |
05e0b2f4 JM |
2418 | t = TREE_OPERAND (t, 1); |
2419 | if (TREE_CODE (t) == FUNCTION_DECL) | |
61a127b3 | 2420 | /* A::f */ |
3c1ab1ab | 2421 | dump_expr (pp, t, flags | TFF_EXPR_IN_PARENS); |
05e0b2f4 | 2422 | else if (BASELINK_P (t)) |
3c1ab1ab | 2423 | dump_expr (pp, OVL_CURRENT (BASELINK_FUNCTIONS (t)), |
da15dae6 | 2424 | flags | TFF_EXPR_IN_PARENS); |
61a127b3 | 2425 | else |
3c1ab1ab | 2426 | dump_decl (pp, t, flags); |
61a127b3 | 2427 | } |
51c184be MS |
2428 | else |
2429 | { | |
591cb3cf | 2430 | if (INDIRECT_REF_P (ob)) |
bbcec105 | 2431 | { |
3c1ab1ab GDR |
2432 | dump_expr (pp, TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS); |
2433 | pp_cxx_arrow (pp); | |
2434 | pp_cxx_star (pp); | |
bbcec105 JM |
2435 | } |
2436 | else | |
2437 | { | |
3c1ab1ab GDR |
2438 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2439 | pp_cxx_dot (pp); | |
2440 | pp_cxx_star (pp); | |
bbcec105 | 2441 | } |
3c1ab1ab | 2442 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
51c184be MS |
2443 | } |
2444 | break; | |
2445 | } | |
2446 | ||
f84b4be9 | 2447 | case TEMPLATE_PARM_INDEX: |
3c1ab1ab | 2448 | dump_decl (pp, TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS); |
de22184b | 2449 | break; |
5566b478 | 2450 | |
5566b478 | 2451 | case CAST_EXPR: |
e349ee73 MS |
2452 | if (TREE_OPERAND (t, 0) == NULL_TREE |
2453 | || TREE_CHAIN (TREE_OPERAND (t, 0))) | |
e76a2646 | 2454 | { |
3c1ab1ab GDR |
2455 | dump_type (pp, TREE_TYPE (t), flags); |
2456 | pp_cxx_left_paren (pp); | |
2457 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2458 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2459 | } |
2460 | else | |
2461 | { | |
3c1ab1ab GDR |
2462 | pp_cxx_left_paren (pp); |
2463 | dump_type (pp, TREE_TYPE (t), flags); | |
2464 | pp_cxx_right_paren (pp); | |
2465 | pp_cxx_left_paren (pp); | |
2466 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2467 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2468 | } |
2469 | break; | |
2470 | ||
477f6664 | 2471 | case STATIC_CAST_EXPR: |
3c1ab1ab | 2472 | pp_cxx_ws_string (pp, "static_cast"); |
477f6664 JM |
2473 | goto cast; |
2474 | case REINTERPRET_CAST_EXPR: | |
3c1ab1ab | 2475 | pp_cxx_ws_string (pp, "reinterpret_cast"); |
477f6664 JM |
2476 | goto cast; |
2477 | case CONST_CAST_EXPR: | |
3c1ab1ab | 2478 | pp_cxx_ws_string (pp, "const_cast"); |
477f6664 JM |
2479 | goto cast; |
2480 | case DYNAMIC_CAST_EXPR: | |
3c1ab1ab | 2481 | pp_cxx_ws_string (pp, "dynamic_cast"); |
477f6664 | 2482 | cast: |
3c1ab1ab GDR |
2483 | pp_cxx_begin_template_argument_list (pp); |
2484 | dump_type (pp, TREE_TYPE (t), flags); | |
2485 | pp_cxx_end_template_argument_list (pp); | |
2486 | pp_cxx_left_paren (pp); | |
2487 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2488 | pp_cxx_right_paren (pp); | |
477f6664 JM |
2489 | break; |
2490 | ||
5a11e05b | 2491 | case ARROW_EXPR: |
3c1ab1ab GDR |
2492 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
2493 | pp_cxx_arrow (pp); | |
5a11e05b BK |
2494 | break; |
2495 | ||
e76a2646 | 2496 | case SIZEOF_EXPR: |
abff8e06 JM |
2497 | case ALIGNOF_EXPR: |
2498 | if (TREE_CODE (t) == SIZEOF_EXPR) | |
3c1ab1ab | 2499 | pp_cxx_ws_string (pp, "sizeof"); |
bb20cc46 | 2500 | else |
abff8e06 | 2501 | { |
50bc768d | 2502 | gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR); |
3c1ab1ab | 2503 | pp_cxx_ws_string (pp, "__alignof__"); |
abff8e06 | 2504 | } |
a1e03bc5 JM |
2505 | op = TREE_OPERAND (t, 0); |
2506 | if (PACK_EXPANSION_P (op)) | |
2507 | { | |
3c1ab1ab | 2508 | pp_string (pp, "..."); |
a1e03bc5 JM |
2509 | op = PACK_EXPANSION_PATTERN (op); |
2510 | } | |
3c1ab1ab GDR |
2511 | pp_cxx_whitespace (pp); |
2512 | pp_cxx_left_paren (pp); | |
0d23cf7a | 2513 | if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t)) |
3c1ab1ab | 2514 | dump_type (pp, TREE_TYPE (op), flags); |
0d23cf7a | 2515 | else if (TYPE_P (TREE_OPERAND (t, 0))) |
3c1ab1ab | 2516 | dump_type (pp, op, flags); |
e76a2646 | 2517 | else |
3c1ab1ab GDR |
2518 | dump_expr (pp, op, flags); |
2519 | pp_cxx_right_paren (pp); | |
e76a2646 | 2520 | break; |
5566b478 | 2521 | |
c154b3d8 | 2522 | case AT_ENCODE_EXPR: |
3c1ab1ab GDR |
2523 | pp_cxx_ws_string (pp, "@encode"); |
2524 | pp_cxx_whitespace (pp); | |
2525 | pp_cxx_left_paren (pp); | |
2526 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
2527 | pp_cxx_right_paren (pp); | |
c154b3d8 NP |
2528 | break; |
2529 | ||
3a55fb4c | 2530 | case NOEXCEPT_EXPR: |
3c1ab1ab GDR |
2531 | pp_cxx_ws_string (pp, "noexcept"); |
2532 | pp_cxx_whitespace (pp); | |
2533 | pp_cxx_left_paren (pp); | |
2534 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2535 | pp_cxx_right_paren (pp); | |
3a55fb4c JM |
2536 | break; |
2537 | ||
19948e32 GDR |
2538 | case REALPART_EXPR: |
2539 | case IMAGPART_EXPR: | |
3c1ab1ab GDR |
2540 | pp_cxx_ws_string (pp, operator_name_info[TREE_CODE (t)].name); |
2541 | pp_cxx_whitespace (pp); | |
2542 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
19948e32 GDR |
2543 | break; |
2544 | ||
da20811c | 2545 | case DEFAULT_ARG: |
3c1ab1ab | 2546 | pp_string (pp, M_("<unparsed>")); |
da20811c JM |
2547 | break; |
2548 | ||
6748b643 JM |
2549 | case TRY_CATCH_EXPR: |
2550 | case WITH_CLEANUP_EXPR: | |
2551 | case CLEANUP_POINT_EXPR: | |
3c1ab1ab | 2552 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
6748b643 JM |
2553 | break; |
2554 | ||
40242ccf | 2555 | case PSEUDO_DTOR_EXPR: |
c0c66032 | 2556 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
3c1ab1ab | 2557 | pp_cxx_dot (pp); |
c0c66032 PC |
2558 | if (TREE_OPERAND (t, 1)) |
2559 | { | |
2560 | dump_type (pp, TREE_OPERAND (t, 1), flags); | |
2561 | pp_cxx_colon_colon (pp); | |
2562 | } | |
3c1ab1ab | 2563 | pp_cxx_complement (pp); |
c0c66032 | 2564 | dump_type (pp, TREE_OPERAND (t, 2), flags); |
40242ccf MM |
2565 | break; |
2566 | ||
7ac7b28f | 2567 | case TEMPLATE_ID_EXPR: |
3c1ab1ab | 2568 | dump_decl (pp, t, flags); |
7ac7b28f MM |
2569 | break; |
2570 | ||
744b12b6 | 2571 | case BIND_EXPR: |
558475f0 | 2572 | case STMT_EXPR: |
aee5c3ed | 2573 | case EXPR_STMT: |
744b12b6 | 2574 | case STATEMENT_LIST: |
558475f0 MM |
2575 | /* We don't yet have a way of dumping statements in a |
2576 | human-readable format. */ | |
3c1ab1ab | 2577 | pp_string (pp, "({...})"); |
558475f0 MM |
2578 | break; |
2579 | ||
0045e0bc | 2580 | case LOOP_EXPR: |
3c1ab1ab GDR |
2581 | pp_string (pp, "while (1) { "); |
2582 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2583 | pp_cxx_right_brace (pp); | |
0045e0bc MM |
2584 | break; |
2585 | ||
2586 | case EXIT_EXPR: | |
3c1ab1ab GDR |
2587 | pp_string (pp, "if ("); |
2588 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2589 | pp_string (pp, ") break; "); | |
0045e0bc MM |
2590 | break; |
2591 | ||
a723baf1 | 2592 | case BASELINK: |
3c1ab1ab | 2593 | dump_expr (pp, BASELINK_FUNCTIONS (t), flags & ~TFF_EXPR_IN_PARENS); |
a723baf1 MM |
2594 | break; |
2595 | ||
98ed3906 | 2596 | case EMPTY_CLASS_EXPR: |
3c1ab1ab GDR |
2597 | dump_type (pp, TREE_TYPE (t), flags); |
2598 | pp_cxx_left_paren (pp); | |
2599 | pp_cxx_right_paren (pp); | |
98ed3906 GDR |
2600 | break; |
2601 | ||
d17811fd | 2602 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 2603 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
d17811fd | 2604 | break; |
00595019 | 2605 | |
31d40008 | 2606 | case ARGUMENT_PACK_SELECT: |
3c1ab1ab | 2607 | dump_template_argument (pp, ARGUMENT_PACK_SELECT_FROM_PACK (t), flags); |
31d40008 PC |
2608 | break; |
2609 | ||
5a023baa GDR |
2610 | case RECORD_TYPE: |
2611 | case UNION_TYPE: | |
2612 | case ENUMERAL_TYPE: | |
2613 | case REAL_TYPE: | |
2614 | case VOID_TYPE: | |
2615 | case BOOLEAN_TYPE: | |
2616 | case INTEGER_TYPE: | |
2617 | case COMPLEX_TYPE: | |
2618 | case VECTOR_TYPE: | |
3c1ab1ab | 2619 | pp_type_specifier_seq (pp, t); |
5a023baa GDR |
2620 | break; |
2621 | ||
2622 | case TYPENAME_TYPE: | |
2623 | /* We get here when we want to print a dependent type as an | |
2624 | id-expression, without any disambiguator decoration. */ | |
20059c8b | 2625 | pp->id_expression (t); |
5a023baa GDR |
2626 | break; |
2627 | ||
0a8fc247 | 2628 | case TEMPLATE_TYPE_PARM: |
fcb13a10 | 2629 | case TEMPLATE_TEMPLATE_PARM: |
0a8fc247 | 2630 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
3c1ab1ab | 2631 | dump_type (pp, t, flags); |
0a8fc247 PC |
2632 | break; |
2633 | ||
e74392f0 | 2634 | case TRAIT_EXPR: |
3c1ab1ab | 2635 | pp_cxx_trait_expression (pp, t); |
e74392f0 PC |
2636 | break; |
2637 | ||
fdb8f418 | 2638 | case VA_ARG_EXPR: |
3c1ab1ab | 2639 | pp_cxx_va_arg_expression (pp, t); |
fdb8f418 PC |
2640 | break; |
2641 | ||
094a5fe2 | 2642 | case OFFSETOF_EXPR: |
3c1ab1ab | 2643 | pp_cxx_offsetof_expression (pp, t); |
094a5fe2 JJ |
2644 | break; |
2645 | ||
066f956c | 2646 | case SCOPE_REF: |
3c1ab1ab | 2647 | dump_decl (pp, t, flags); |
e1faa105 JM |
2648 | break; |
2649 | ||
066f956c PC |
2650 | case EXPR_PACK_EXPANSION: |
2651 | case TYPEID_EXPR: | |
1e3eacc7 JJ |
2652 | case MEMBER_REF: |
2653 | case DOTSTAR_EXPR: | |
a84a98ca PC |
2654 | case NEW_EXPR: |
2655 | case VEC_NEW_EXPR: | |
62081704 PC |
2656 | case DELETE_EXPR: |
2657 | case VEC_DELETE_EXPR: | |
066f956c | 2658 | case MODOP_EXPR: |
214452b9 | 2659 | case ABS_EXPR: |
998ceda2 | 2660 | case CONJ_EXPR: |
e94384db | 2661 | case VECTOR_CST: |
998ceda2 | 2662 | case FIXED_CST: |
07874f1f JJ |
2663 | case UNORDERED_EXPR: |
2664 | case ORDERED_EXPR: | |
2665 | case UNLT_EXPR: | |
2666 | case UNLE_EXPR: | |
2667 | case UNGT_EXPR: | |
2668 | case UNGE_EXPR: | |
2669 | case UNEQ_EXPR: | |
2670 | case LTGT_EXPR: | |
66e68191 | 2671 | case COMPLEX_EXPR: |
5eddced5 | 2672 | case BIT_FIELD_REF: |
1fae3e66 PC |
2673 | case FIX_TRUNC_EXPR: |
2674 | case FLOAT_EXPR: | |
20059c8b | 2675 | pp->expression (t); |
62081704 PC |
2676 | break; |
2677 | ||
6f536f74 JJ |
2678 | case TRUTH_AND_EXPR: |
2679 | case TRUTH_OR_EXPR: | |
2680 | case TRUTH_XOR_EXPR: | |
2681 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab | 2682 | pp_cxx_left_paren (pp); |
20059c8b | 2683 | pp->expression (t); |
6f536f74 | 2684 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2685 | pp_cxx_right_paren (pp); |
6f536f74 JJ |
2686 | break; |
2687 | ||
89ab8ba0 | 2688 | case OBJ_TYPE_REF: |
3c1ab1ab | 2689 | dump_expr (pp, resolve_virtual_fun_from_obj_type_ref (t), flags); |
89ab8ba0 JJ |
2690 | break; |
2691 | ||
f030a1dc | 2692 | case LAMBDA_EXPR: |
3c1ab1ab | 2693 | pp_string (pp, M_("<lambda>")); |
f030a1dc PC |
2694 | break; |
2695 | ||
10c6dc8e | 2696 | case PAREN_EXPR: |
3c1ab1ab GDR |
2697 | pp_cxx_left_paren (pp); |
2698 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2699 | pp_cxx_right_paren (pp); | |
10c6dc8e JM |
2700 | break; |
2701 | ||
3e605b20 JM |
2702 | case PLACEHOLDER_EXPR: |
2703 | pp_string (pp, M_("*this")); | |
2704 | break; | |
2705 | ||
8d08fdba MS |
2706 | /* This list is incomplete, but should suffice for now. |
2707 | It is very important that `sorry' does not call | |
2708 | `report_error_function'. That could cause an infinite loop. */ | |
2709 | default: | |
3c1ab1ab | 2710 | pp_unsupported_tree (pp, t); |
8d08fdba MS |
2711 | /* fall through to ERROR_MARK... */ |
2712 | case ERROR_MARK: | |
3c1ab1ab | 2713 | pp_string (pp, M_("<expression error>")); |
8d08fdba MS |
2714 | break; |
2715 | } | |
2716 | } | |
2717 | ||
2718 | static void | |
3c1ab1ab GDR |
2719 | dump_binary_op (cxx_pretty_printer *pp, const char *opstring, tree t, |
2720 | int flags) | |
8d08fdba | 2721 | { |
3c1ab1ab GDR |
2722 | pp_cxx_left_paren (pp); |
2723 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2724 | pp_cxx_whitespace (pp); | |
2adeacc9 | 2725 | if (opstring) |
3c1ab1ab | 2726 | pp_cxx_ws_string (pp, opstring); |
2adeacc9 | 2727 | else |
3c1ab1ab GDR |
2728 | pp_string (pp, M_("<unknown operator>")); |
2729 | pp_cxx_whitespace (pp); | |
2730 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2731 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2732 | } |
2733 | ||
2734 | static void | |
3c1ab1ab | 2735 | dump_unary_op (cxx_pretty_printer *pp, const char *opstring, tree t, int flags) |
8d08fdba | 2736 | { |
761f0855 | 2737 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
2738 | pp_cxx_left_paren (pp); |
2739 | pp_cxx_ws_string (pp, opstring); | |
2740 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 2741 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2742 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2743 | } |
2744 | ||
73bbafe5 GDR |
2745 | static void |
2746 | reinit_cxx_pp (void) | |
2747 | { | |
2748 | pp_clear_output_area (cxx_pp); | |
b066401f | 2749 | cxx_pp->padding = pp_none; |
73bbafe5 GDR |
2750 | pp_indentation (cxx_pp) = 0; |
2751 | pp_needs_newline (cxx_pp) = false; | |
d5aa2cf0 | 2752 | cxx_pp->enclosing_scope = current_function_decl; |
73bbafe5 GDR |
2753 | } |
2754 | ||
8ccb81bd GDR |
2755 | /* Same as pp_formatted_text, except the return string is a separate |
2756 | copy and has a GGC storage duration, e.g. an indefinite lifetime. */ | |
2757 | ||
2758 | inline const char * | |
2759 | pp_ggc_formatted_text (pretty_printer *pp) | |
2760 | { | |
2761 | return ggc_strdup (pp_formatted_text (pp)); | |
2762 | } | |
73bbafe5 | 2763 | |
761f0855 | 2764 | /* Exported interface to stringifying types, exprs and decls under TFF_* |
9e93bc9d | 2765 | control. */ |
4995028c | 2766 | |
e1def31b | 2767 | const char * |
3f8548e7 | 2768 | type_as_string (tree typ, int flags) |
f41c4af3 JM |
2769 | { |
2770 | reinit_cxx_pp (); | |
2771 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 2772 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 2773 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
2774 | } |
2775 | ||
2776 | const char * | |
2777 | type_as_string_translate (tree typ, int flags) | |
8d08fdba | 2778 | { |
73bbafe5 | 2779 | reinit_cxx_pp (); |
3c1ab1ab | 2780 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 2781 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
2782 | } |
2783 | ||
e1def31b | 2784 | const char * |
3f8548e7 | 2785 | expr_as_string (tree decl, int flags) |
8d08fdba | 2786 | { |
73bbafe5 | 2787 | reinit_cxx_pp (); |
f41c4af3 | 2788 | pp_translate_identifiers (cxx_pp) = false; |
3c1ab1ab | 2789 | dump_expr (cxx_pp, decl, flags); |
8ccb81bd | 2790 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
2791 | } |
2792 | ||
7496cd5b SA |
2793 | /* Wrap decl_as_string with options appropriate for dwarf. */ |
2794 | ||
2795 | const char * | |
2796 | decl_as_dwarf_string (tree decl, int flags) | |
2797 | { | |
2798 | const char *name; | |
2799 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
2800 | here will be adequate to get the desired behaviour. */ | |
b066401f | 2801 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
2802 | name = decl_as_string (decl, flags); |
2803 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 2804 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
2805 | return name; |
2806 | } | |
2807 | ||
e1def31b | 2808 | const char * |
3f8548e7 | 2809 | decl_as_string (tree decl, int flags) |
f41c4af3 JM |
2810 | { |
2811 | reinit_cxx_pp (); | |
2812 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 2813 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 2814 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
2815 | } |
2816 | ||
2817 | const char * | |
2818 | decl_as_string_translate (tree decl, int flags) | |
8d08fdba | 2819 | { |
73bbafe5 | 2820 | reinit_cxx_pp (); |
3c1ab1ab | 2821 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 2822 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
2823 | } |
2824 | ||
7496cd5b SA |
2825 | /* Wrap lang_decl_name with options appropriate for dwarf. */ |
2826 | ||
2827 | const char * | |
2828 | lang_decl_dwarf_name (tree decl, int v, bool translate) | |
2829 | { | |
2830 | const char *name; | |
2831 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
2832 | here will be adequate to get the desired behaviour. */ | |
b066401f | 2833 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
2834 | name = lang_decl_name (decl, v, translate); |
2835 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 2836 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
2837 | return name; |
2838 | } | |
2839 | ||
7afff7cf | 2840 | /* Generate the three forms of printable names for cxx_printable_name. */ |
2ba25f50 | 2841 | |
e1def31b | 2842 | const char * |
f41c4af3 | 2843 | lang_decl_name (tree decl, int v, bool translate) |
2ba25f50 MS |
2844 | { |
2845 | if (v >= 2) | |
f41c4af3 JM |
2846 | return (translate |
2847 | ? decl_as_string_translate (decl, TFF_DECL_SPECIFIERS) | |
2848 | : decl_as_string (decl, TFF_DECL_SPECIFIERS)); | |
2ba25f50 | 2849 | |
73bbafe5 | 2850 | reinit_cxx_pp (); |
f41c4af3 | 2851 | pp_translate_identifiers (cxx_pp) = translate; |
b96fe38e DS |
2852 | if (v == 1 |
2853 | && (DECL_CLASS_SCOPE_P (decl) | |
2854 | || (DECL_NAMESPACE_SCOPE_P (decl) | |
2855 | && CP_DECL_CONTEXT (decl) != global_namespace))) | |
2ba25f50 | 2856 | { |
3c1ab1ab | 2857 | dump_type (cxx_pp, CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER); |
73bbafe5 | 2858 | pp_cxx_colon_colon (cxx_pp); |
2ba25f50 MS |
2859 | } |
2860 | ||
2861 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3c1ab1ab | 2862 | dump_function_name (cxx_pp, decl, TFF_PLAIN_IDENTIFIER); |
7496cd5b SA |
2863 | else if ((DECL_NAME (decl) == NULL_TREE) |
2864 | && TREE_CODE (decl) == NAMESPACE_DECL) | |
3c1ab1ab | 2865 | dump_decl (cxx_pp, decl, TFF_PLAIN_IDENTIFIER | TFF_UNQUALIFIED_NAME); |
2ba25f50 | 2866 | else |
3c1ab1ab | 2867 | dump_decl (cxx_pp, DECL_NAME (decl), TFF_PLAIN_IDENTIFIER); |
2ba25f50 | 2868 | |
8ccb81bd | 2869 | return pp_ggc_formatted_text (cxx_pp); |
2ba25f50 | 2870 | } |
2ba25f50 | 2871 | |
dee15844 JM |
2872 | /* Return the location of a tree passed to %+ formats. */ |
2873 | ||
501c95ff | 2874 | location_t |
9a472a42 | 2875 | location_of (tree t) |
8d08fdba | 2876 | { |
aeda100f | 2877 | if (TYPE_P (t)) |
06be4922 JM |
2878 | { |
2879 | t = TYPE_MAIN_DECL (t); | |
2880 | if (t == NULL_TREE) | |
2881 | return input_location; | |
2882 | } | |
8f032717 | 2883 | else if (TREE_CODE (t) == OVERLOAD) |
9a472a42 | 2884 | t = OVL_FUNCTION (t); |
c8094d83 | 2885 | |
9e115cec JM |
2886 | if (DECL_P (t)) |
2887 | return DECL_SOURCE_LOCATION (t); | |
8400e75e | 2888 | return EXPR_LOC_OR_LOC (t, input_location); |
8d08fdba MS |
2889 | } |
2890 | ||
33bd39a2 | 2891 | /* Now the interfaces from error et al to dump_type et al. Each takes an |
761f0855 | 2892 | on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_ |
9e93bc9d NS |
2893 | function. */ |
2894 | ||
2895 | static const char * | |
3f8548e7 | 2896 | decl_to_string (tree decl, int verbose) |
9e93bc9d | 2897 | { |
761f0855 | 2898 | int flags = 0; |
d67cdbc3 | 2899 | |
9e93bc9d NS |
2900 | if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE |
2901 | || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE) | |
761f0855 | 2902 | flags = TFF_CLASS_KEY_OR_ENUM; |
9e93bc9d | 2903 | if (verbose) |
4a386498 | 2904 | flags |= TFF_DECL_SPECIFIERS; |
9e93bc9d | 2905 | else if (TREE_CODE (decl) == FUNCTION_DECL) |
761f0855 GDR |
2906 | flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE; |
2907 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 2908 | |
73bbafe5 | 2909 | reinit_cxx_pp (); |
3c1ab1ab | 2910 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 2911 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
2912 | } |
2913 | ||
2914 | static const char * | |
4e3f84b7 | 2915 | expr_to_string (tree decl) |
9e93bc9d | 2916 | { |
73bbafe5 | 2917 | reinit_cxx_pp (); |
3c1ab1ab | 2918 | dump_expr (cxx_pp, decl, 0); |
8ccb81bd | 2919 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
2920 | } |
2921 | ||
2922 | static const char * | |
3f8548e7 | 2923 | fndecl_to_string (tree fndecl, int verbose) |
9e93bc9d | 2924 | { |
761f0855 | 2925 | int flags; |
bb20cc46 | 2926 | |
e1f0e7a6 MM |
2927 | flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS |
2928 | | TFF_TEMPLATE_HEADER; | |
9e93bc9d | 2929 | if (verbose) |
761f0855 | 2930 | flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS; |
73bbafe5 | 2931 | reinit_cxx_pp (); |
3c1ab1ab | 2932 | dump_decl (cxx_pp, fndecl, flags); |
8ccb81bd | 2933 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
2934 | } |
2935 | ||
2936 | ||
2937 | static const char * | |
4e3f84b7 | 2938 | code_to_string (enum tree_code c) |
8d08fdba | 2939 | { |
5806f481 | 2940 | return get_tree_code_name (c); |
8d08fdba MS |
2941 | } |
2942 | ||
421844e7 | 2943 | const char * |
4e3f84b7 | 2944 | language_to_string (enum languages c) |
8d08fdba MS |
2945 | { |
2946 | switch (c) | |
2947 | { | |
2948 | case lang_c: | |
2949 | return "C"; | |
2950 | ||
2951 | case lang_cplusplus: | |
2952 | return "C++"; | |
2953 | ||
31b72b87 PB |
2954 | case lang_java: |
2955 | return "Java"; | |
2956 | ||
8d08fdba | 2957 | default: |
8dc2b103 | 2958 | gcc_unreachable (); |
8d08fdba | 2959 | } |
6aed477a | 2960 | return NULL; |
8d08fdba MS |
2961 | } |
2962 | ||
2963 | /* Return the proper printed version of a parameter to a C++ function. */ | |
e92cc029 | 2964 | |
9e93bc9d | 2965 | static const char * |
4e3f84b7 | 2966 | parm_to_string (int p) |
8d08fdba | 2967 | { |
73bbafe5 | 2968 | reinit_cxx_pp (); |
8d08fdba | 2969 | if (p < 0) |
b6fe0bb8 | 2970 | pp_string (cxx_pp, "'this'"); |
4e3f84b7 | 2971 | else |
b6fe0bb8 | 2972 | pp_decimal_int (cxx_pp, p + 1); |
8ccb81bd | 2973 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
2974 | } |
2975 | ||
9e93bc9d | 2976 | static const char * |
4e3f84b7 | 2977 | op_to_string (enum tree_code p) |
8d08fdba | 2978 | { |
3c1ab1ab | 2979 | tree id = operator_name_info[p].identifier; |
f41c4af3 | 2980 | return id ? IDENTIFIER_POINTER (id) : M_("<unknown>"); |
8d08fdba MS |
2981 | } |
2982 | ||
9e93bc9d | 2983 | static const char * |
3f8548e7 | 2984 | type_to_string (tree typ, int verbose) |
9e93bc9d | 2985 | { |
b6fe0bb8 | 2986 | int flags = 0; |
9e93bc9d | 2987 | if (verbose) |
761f0855 GDR |
2988 | flags |= TFF_CLASS_KEY_OR_ENUM; |
2989 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 2990 | |
73bbafe5 | 2991 | reinit_cxx_pp (); |
3c1ab1ab | 2992 | dump_type (cxx_pp, typ, flags); |
0d3128d6 JM |
2993 | /* If we're printing a type that involves typedefs, also print the |
2994 | stripped version. But sometimes the stripped version looks | |
2995 | exactly the same, so we don't want it after all. To avoid printing | |
2996 | it in that case, we play ugly obstack games. */ | |
8722cdee JM |
2997 | if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ) |
2998 | && !uses_template_parms (typ)) | |
2999 | { | |
045af2d7 | 3000 | int aka_start, aka_len; char *p; |
025311c4 | 3001 | struct obstack *ob = pp_buffer (cxx_pp)->obstack; |
0d3128d6 JM |
3002 | /* Remember the end of the initial dump. */ |
3003 | int len = obstack_object_size (ob); | |
8722cdee JM |
3004 | tree aka = strip_typedefs (typ); |
3005 | pp_string (cxx_pp, " {aka"); | |
3006 | pp_cxx_whitespace (cxx_pp); | |
0d3128d6 JM |
3007 | /* And remember the start of the aka dump. */ |
3008 | aka_start = obstack_object_size (ob); | |
3c1ab1ab | 3009 | dump_type (cxx_pp, aka, flags); |
045af2d7 | 3010 | aka_len = obstack_object_size (ob) - aka_start; |
07838b13 | 3011 | pp_right_brace (cxx_pp); |
0d3128d6 JM |
3012 | p = (char*)obstack_base (ob); |
3013 | /* If they are identical, cut off the aka with a NUL. */ | |
045af2d7 | 3014 | if (len == aka_len && memcmp (p, p+aka_start, len) == 0) |
0d3128d6 | 3015 | p[len] = '\0'; |
8722cdee | 3016 | } |
8ccb81bd | 3017 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3018 | } |
3019 | ||
3020 | static const char * | |
4e3f84b7 | 3021 | assop_to_string (enum tree_code p) |
c91a56d2 | 3022 | { |
b6fe0bb8 | 3023 | tree id = assignment_operator_name_info[(int) p].identifier; |
f41c4af3 | 3024 | return id ? IDENTIFIER_POINTER (id) : M_("{unknown}"); |
c91a56d2 MS |
3025 | } |
3026 | ||
9e93bc9d | 3027 | static const char * |
3f8548e7 | 3028 | args_to_string (tree p, int verbose) |
8d08fdba | 3029 | { |
761f0855 | 3030 | int flags = 0; |
9e93bc9d | 3031 | if (verbose) |
761f0855 | 3032 | flags |= TFF_CLASS_KEY_OR_ENUM; |
bb20cc46 | 3033 | |
8d08fdba | 3034 | if (p == NULL_TREE) |
c73964b2 | 3035 | return ""; |
8d08fdba | 3036 | |
2f939d94 | 3037 | if (TYPE_P (TREE_VALUE (p))) |
f41c4af3 | 3038 | return type_as_string_translate (p, flags); |
c73964b2 | 3039 | |
73bbafe5 | 3040 | reinit_cxx_pp (); |
c73964b2 MS |
3041 | for (; p; p = TREE_CHAIN (p)) |
3042 | { | |
a6967cc0 | 3043 | if (TREE_VALUE (p) == null_node) |
b02cec6e | 3044 | pp_cxx_ws_string (cxx_pp, "NULL"); |
a6967cc0 | 3045 | else |
3c1ab1ab | 3046 | dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags); |
c73964b2 | 3047 | if (TREE_CHAIN (p)) |
b6fe0bb8 | 3048 | pp_separate_with_comma (cxx_pp); |
c73964b2 | 3049 | } |
8ccb81bd | 3050 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba | 3051 | } |
f30432d7 | 3052 | |
3ff60975 JM |
3053 | /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P |
3054 | is a TREE_LIST with purpose the TEMPLATE_DECL, value the template | |
3055 | arguments. */ | |
3056 | ||
3057 | static const char * | |
3058 | subst_to_string (tree p) | |
3059 | { | |
3060 | tree decl = TREE_PURPOSE (p); | |
3061 | tree targs = TREE_VALUE (p); | |
3062 | tree tparms = DECL_TEMPLATE_PARMS (decl); | |
3579964b JM |
3063 | int flags = (TFF_DECL_SPECIFIERS|TFF_TEMPLATE_HEADER |
3064 | |TFF_NO_TEMPLATE_BINDINGS); | |
3ff60975 JM |
3065 | |
3066 | if (p == NULL_TREE) | |
3067 | return ""; | |
3068 | ||
3069 | reinit_cxx_pp (); | |
3c1ab1ab | 3070 | dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags); |
753c4989 | 3071 | dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0); |
8ccb81bd | 3072 | return pp_ggc_formatted_text (cxx_pp); |
3ff60975 JM |
3073 | } |
3074 | ||
9e93bc9d | 3075 | static const char * |
3f8548e7 | 3076 | cv_to_string (tree p, int v) |
f30432d7 | 3077 | { |
73bbafe5 | 3078 | reinit_cxx_pp (); |
b066401f | 3079 | cxx_pp->padding = v ? pp_before : pp_none; |
b9b44fb9 | 3080 | pp_cxx_cv_qualifier_seq (cxx_pp, p); |
8ccb81bd | 3081 | return pp_ggc_formatted_text (cxx_pp); |
f30432d7 | 3082 | } |
cb753e49 | 3083 | |
3f04b1bb JM |
3084 | static const char * |
3085 | eh_spec_to_string (tree p, int /*v*/) | |
3086 | { | |
3087 | int flags = 0; | |
3088 | reinit_cxx_pp (); | |
3089 | dump_exception_spec (cxx_pp, p, flags); | |
3090 | return pp_ggc_formatted_text (cxx_pp); | |
3091 | } | |
3092 | ||
7cb32822 NB |
3093 | /* Langhook for print_error_function. */ |
3094 | void | |
c94ed7a1 JJ |
3095 | cxx_print_error_function (diagnostic_context *context, const char *file, |
3096 | diagnostic_info *diagnostic) | |
a72462a4 | 3097 | { |
c94ed7a1 | 3098 | lhd_print_error_function (context, file, diagnostic); |
b066401f | 3099 | pp_set_prefix (context->printer, file); |
47b69537 | 3100 | maybe_print_instantiation_context (context); |
a72462a4 GDR |
3101 | } |
3102 | ||
cb753e49 | 3103 | static void |
3f8548e7 | 3104 | cp_diagnostic_starter (diagnostic_context *context, |
0cbd7506 | 3105 | diagnostic_info *diagnostic) |
cb753e49 | 3106 | { |
07a0b324 | 3107 | diagnostic_report_current_module (context, diagnostic->location); |
47b69537 GDR |
3108 | cp_print_error_function (context, diagnostic); |
3109 | maybe_print_instantiation_context (context); | |
2bfe0527 | 3110 | maybe_print_constexpr_context (context); |
b066401f | 3111 | pp_set_prefix (context->printer, diagnostic_build_prefix (context, |
243fbddd | 3112 | diagnostic)); |
cb753e49 GDR |
3113 | } |
3114 | ||
cb753e49 GDR |
3115 | /* Print current function onto BUFFER, in the process of reporting |
3116 | a diagnostic message. Called from cp_diagnostic_starter. */ | |
3117 | static void | |
3f8548e7 | 3118 | cp_print_error_function (diagnostic_context *context, |
0cbd7506 | 3119 | diagnostic_info *diagnostic) |
cb753e49 | 3120 | { |
6573e8a0 JM |
3121 | /* If we are in an instantiation context, current_function_decl is likely |
3122 | to be wrong, so just rely on print_instantiation_full_context. */ | |
3123 | if (current_instantiation ()) | |
3124 | return; | |
c94ed7a1 | 3125 | if (diagnostic_last_function_changed (context, diagnostic)) |
cb753e49 | 3126 | { |
b6fe0bb8 | 3127 | const char *old_prefix = context->printer->prefix; |
93409b8c | 3128 | const char *file = LOCATION_FILE (diagnostic->location); |
cf835838 | 3129 | tree abstract_origin = diagnostic_abstract_origin (diagnostic); |
c94ed7a1 | 3130 | char *new_prefix = (file && abstract_origin == NULL) |
e78e8a0b | 3131 | ? file_name_as_prefix (context, file) : NULL; |
cb753e49 | 3132 | |
b066401f | 3133 | pp_set_prefix (context->printer, new_prefix); |
bb20cc46 | 3134 | |
cb753e49 | 3135 | if (current_function_decl == NULL) |
b066401f | 3136 | pp_string (context->printer, _("At global scope:")); |
cb753e49 | 3137 | else |
c94ed7a1 JJ |
3138 | { |
3139 | tree fndecl, ao; | |
3140 | ||
3141 | if (abstract_origin) | |
3142 | { | |
3143 | ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin); | |
e92cbe3a JJ |
3144 | while (TREE_CODE (ao) == BLOCK |
3145 | && BLOCK_ABSTRACT_ORIGIN (ao) | |
3146 | && BLOCK_ABSTRACT_ORIGIN (ao) != ao) | |
c94ed7a1 JJ |
3147 | ao = BLOCK_ABSTRACT_ORIGIN (ao); |
3148 | gcc_assert (TREE_CODE (ao) == FUNCTION_DECL); | |
3149 | fndecl = ao; | |
3150 | } | |
3151 | else | |
3152 | fndecl = current_function_decl; | |
3153 | ||
b02cec6e | 3154 | pp_printf (context->printer, function_category (fndecl), |
f41c4af3 | 3155 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3156 | |
3157 | while (abstract_origin) | |
3158 | { | |
3159 | location_t *locus; | |
3160 | tree block = abstract_origin; | |
3161 | ||
3162 | locus = &BLOCK_SOURCE_LOCATION (block); | |
3163 | fndecl = NULL; | |
3164 | block = BLOCK_SUPERCONTEXT (block); | |
3165 | while (block && TREE_CODE (block) == BLOCK | |
3166 | && BLOCK_ABSTRACT_ORIGIN (block)) | |
3167 | { | |
3168 | ao = BLOCK_ABSTRACT_ORIGIN (block); | |
3169 | ||
02dcf7ba RG |
3170 | while (TREE_CODE (ao) == BLOCK |
3171 | && BLOCK_ABSTRACT_ORIGIN (ao) | |
3172 | && BLOCK_ABSTRACT_ORIGIN (ao) != ao) | |
c94ed7a1 JJ |
3173 | ao = BLOCK_ABSTRACT_ORIGIN (ao); |
3174 | ||
3175 | if (TREE_CODE (ao) == FUNCTION_DECL) | |
3176 | { | |
3177 | fndecl = ao; | |
3178 | break; | |
3179 | } | |
3180 | else if (TREE_CODE (ao) != BLOCK) | |
3181 | break; | |
3182 | ||
3183 | block = BLOCK_SUPERCONTEXT (block); | |
3184 | } | |
3185 | if (fndecl) | |
3186 | abstract_origin = block; | |
3187 | else | |
3188 | { | |
3189 | while (block && TREE_CODE (block) == BLOCK) | |
3190 | block = BLOCK_SUPERCONTEXT (block); | |
3191 | ||
9304142e | 3192 | if (block && TREE_CODE (block) == FUNCTION_DECL) |
c94ed7a1 JJ |
3193 | fndecl = block; |
3194 | abstract_origin = NULL; | |
3195 | } | |
3196 | if (fndecl) | |
3197 | { | |
3198 | expanded_location s = expand_location (*locus); | |
b066401f GDR |
3199 | pp_character (context->printer, ','); |
3200 | pp_newline (context->printer); | |
c94ed7a1 JJ |
3201 | if (s.file != NULL) |
3202 | { | |
243fbddd | 3203 | if (context->show_column && s.column != 0) |
c94ed7a1 | 3204 | pp_printf (context->printer, |
4b84d650 | 3205 | _(" inlined from %qs at %r%s:%d:%d%R"), |
f41c4af3 | 3206 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3207 | "locus", s.file, s.line, s.column); |
c94ed7a1 | 3208 | else |
c94ed7a1 | 3209 | pp_printf (context->printer, |
4b84d650 | 3210 | _(" inlined from %qs at %r%s:%d%R"), |
f41c4af3 | 3211 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3212 | "locus", s.file, s.line); |
c94ed7a1 JJ |
3213 | |
3214 | } | |
3215 | else | |
b02cec6e | 3216 | pp_printf (context->printer, _(" inlined from %qs"), |
f41c4af3 | 3217 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3218 | } |
3219 | } | |
b066401f | 3220 | pp_character (context->printer, ':'); |
c94ed7a1 | 3221 | } |
b066401f | 3222 | pp_newline (context->printer); |
47b69537 | 3223 | |
c94ed7a1 | 3224 | diagnostic_set_last_function (context, diagnostic); |
b066401f | 3225 | pp_destroy_prefix (context->printer); |
b6fe0bb8 | 3226 | context->printer->prefix = old_prefix; |
cb753e49 GDR |
3227 | } |
3228 | } | |
3229 | ||
b02cec6e JM |
3230 | /* Returns a description of FUNCTION using standard terminology. The |
3231 | result is a format string of the form "In CATEGORY %qs". */ | |
cb753e49 | 3232 | static const char * |
3f8548e7 | 3233 | function_category (tree fn) |
cb753e49 | 3234 | { |
a406865a RG |
3235 | /* We can get called from the middle-end for diagnostics of function |
3236 | clones. Make sure we have language specific information before | |
3237 | dereferencing it. */ | |
3238 | if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn)) | |
3239 | && DECL_FUNCTION_MEMBER_P (fn)) | |
cb753e49 GDR |
3240 | { |
3241 | if (DECL_STATIC_FUNCTION_P (fn)) | |
b02cec6e | 3242 | return _("In static member function %qs"); |
cb753e49 | 3243 | else if (DECL_COPY_CONSTRUCTOR_P (fn)) |
b02cec6e | 3244 | return _("In copy constructor %qs"); |
cb753e49 | 3245 | else if (DECL_CONSTRUCTOR_P (fn)) |
b02cec6e | 3246 | return _("In constructor %qs"); |
cb753e49 | 3247 | else if (DECL_DESTRUCTOR_P (fn)) |
b02cec6e | 3248 | return _("In destructor %qs"); |
d5f4eddd JM |
3249 | else if (LAMBDA_FUNCTION_P (fn)) |
3250 | return _("In lambda function"); | |
cb753e49 | 3251 | else |
b02cec6e | 3252 | return _("In member function %qs"); |
cb753e49 GDR |
3253 | } |
3254 | else | |
b02cec6e | 3255 | return _("In function %qs"); |
cb753e49 GDR |
3256 | } |
3257 | ||
3258 | /* Report the full context of a current template instantiation, | |
3259 | onto BUFFER. */ | |
3260 | static void | |
3f8548e7 | 3261 | print_instantiation_full_context (diagnostic_context *context) |
cb753e49 | 3262 | { |
e2c3721c | 3263 | struct tinst_level *p = current_instantiation (); |
82a98427 | 3264 | location_t location = input_location; |
c8094d83 | 3265 | |
cb753e49 GDR |
3266 | if (p) |
3267 | { | |
6573e8a0 JM |
3268 | pp_verbatim (context->printer, |
3269 | TREE_CODE (p->decl) == TREE_LIST | |
3270 | ? _("%s: In substitution of %qS:\n") | |
3271 | : _("%s: In instantiation of %q#D:\n"), | |
3272 | LOCATION_FILE (location), | |
3273 | p->decl); | |
3274 | ||
3275 | location = p->locus; | |
3276 | p = p->next; | |
cb753e49 | 3277 | } |
bb20cc46 | 3278 | |
35773471 | 3279 | print_instantiation_partial_context (context, p, location); |
cb753e49 GDR |
3280 | } |
3281 | ||
f89b94d9 MLI |
3282 | /* Helper function of print_instantiation_partial_context() that |
3283 | prints a single line of instantiation context. */ | |
3284 | ||
cb753e49 | 3285 | static void |
f89b94d9 | 3286 | print_instantiation_partial_context_line (diagnostic_context *context, |
4b414c93 MLI |
3287 | const struct tinst_level *t, |
3288 | location_t loc, bool recursive_p) | |
cb753e49 | 3289 | { |
4f90d3e0 JH |
3290 | if (loc == UNKNOWN_LOCATION) |
3291 | return; | |
3292 | ||
3293 | expanded_location xloc = expand_location (loc); | |
f89b94d9 | 3294 | |
3ff60975 | 3295 | if (context->show_column) |
4b84d650 JJ |
3296 | pp_verbatim (context->printer, _("%r%s:%d:%d:%R "), |
3297 | "locus", xloc.file, xloc.line, xloc.column); | |
3ff60975 | 3298 | else |
4b84d650 JJ |
3299 | pp_verbatim (context->printer, _("%r%s:%d:%R "), |
3300 | "locus", xloc.file, xloc.line); | |
3ff60975 JM |
3301 | |
3302 | if (t != NULL) | |
4b414c93 | 3303 | { |
3ff60975 | 3304 | if (TREE_CODE (t->decl) == TREE_LIST) |
4b414c93 MLI |
3305 | pp_verbatim (context->printer, |
3306 | recursive_p | |
3ff60975 JM |
3307 | ? _("recursively required by substitution of %qS\n") |
3308 | : _("required by substitution of %qS\n"), | |
3309 | t->decl); | |
4b414c93 MLI |
3310 | else |
3311 | pp_verbatim (context->printer, | |
3312 | recursive_p | |
3ff60975 JM |
3313 | ? _("recursively required from %q#D\n") |
3314 | : _("required from %q#D\n"), | |
3315 | t->decl); | |
4b414c93 MLI |
3316 | } |
3317 | else | |
3318 | { | |
3ff60975 JM |
3319 | pp_verbatim (context->printer, |
3320 | recursive_p | |
3321 | ? _("recursively required from here") | |
3322 | : _("required from here")); | |
4b414c93 | 3323 | } |
f89b94d9 MLI |
3324 | } |
3325 | ||
3326 | /* Same as print_instantiation_full_context but less verbose. */ | |
3327 | ||
3328 | static void | |
3329 | print_instantiation_partial_context (diagnostic_context *context, | |
3330 | struct tinst_level *t0, location_t loc) | |
3331 | { | |
3332 | struct tinst_level *t; | |
3333 | int n_total = 0; | |
3334 | int n; | |
4b414c93 | 3335 | location_t prev_loc = loc; |
f89b94d9 MLI |
3336 | |
3337 | for (t = t0; t != NULL; t = t->next) | |
4b414c93 MLI |
3338 | if (prev_loc != t->locus) |
3339 | { | |
3340 | prev_loc = t->locus; | |
3341 | n_total++; | |
3342 | } | |
f89b94d9 MLI |
3343 | |
3344 | t = t0; | |
3345 | ||
a12bf402 MLI |
3346 | if (template_backtrace_limit |
3347 | && n_total > template_backtrace_limit) | |
cb753e49 | 3348 | { |
a12bf402 MLI |
3349 | int skip = n_total - template_backtrace_limit; |
3350 | int head = template_backtrace_limit / 2; | |
3351 | ||
3352 | /* Avoid skipping just 1. If so, skip 2. */ | |
3353 | if (skip == 1) | |
3354 | { | |
3355 | skip = 2; | |
3356 | head = (template_backtrace_limit - 1) / 2; | |
3357 | } | |
3358 | ||
3359 | for (n = 0; n < head; n++) | |
f89b94d9 MLI |
3360 | { |
3361 | gcc_assert (t != NULL); | |
4b414c93 MLI |
3362 | if (loc != t->locus) |
3363 | print_instantiation_partial_context_line (context, t, loc, | |
3364 | /*recursive_p=*/false); | |
f89b94d9 MLI |
3365 | loc = t->locus; |
3366 | t = t->next; | |
3367 | } | |
a12bf402 | 3368 | if (t != NULL && skip > 0) |
f89b94d9 MLI |
3369 | { |
3370 | expanded_location xloc; | |
3371 | xloc = expand_location (loc); | |
243fbddd | 3372 | if (context->show_column) |
f89b94d9 | 3373 | pp_verbatim (context->printer, |
4b84d650 JJ |
3374 | _("%r%s:%d:%d:%R [ skipping %d instantiation " |
3375 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3376 | "disable ]\n"), | |
3377 | "locus", xloc.file, xloc.line, xloc.column, skip); | |
f89b94d9 MLI |
3378 | else |
3379 | pp_verbatim (context->printer, | |
4b84d650 JJ |
3380 | _("%r%s:%d:%R [ skipping %d instantiation " |
3381 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3382 | "disable ]\n"), | |
3383 | "locus", xloc.file, xloc.line, skip); | |
f89b94d9 MLI |
3384 | |
3385 | do { | |
4b414c93 MLI |
3386 | loc = t->locus; |
3387 | t = t->next; | |
3388 | } while (t != NULL && --skip > 0); | |
f89b94d9 MLI |
3389 | } |
3390 | } | |
3391 | ||
4b414c93 | 3392 | while (t != NULL) |
f89b94d9 | 3393 | { |
4b414c93 MLI |
3394 | while (t->next != NULL && t->locus == t->next->locus) |
3395 | { | |
3396 | loc = t->locus; | |
3397 | t = t->next; | |
3398 | } | |
3399 | print_instantiation_partial_context_line (context, t, loc, | |
3400 | t->locus == loc); | |
e2c3721c | 3401 | loc = t->locus; |
4b414c93 | 3402 | t = t->next; |
cb753e49 | 3403 | } |
4b414c93 MLI |
3404 | print_instantiation_partial_context_line (context, NULL, loc, |
3405 | /*recursive_p=*/false); | |
b066401f | 3406 | pp_newline (context->printer); |
cb753e49 GDR |
3407 | } |
3408 | ||
3409 | /* Called from cp_thing to print the template context for an error. */ | |
3410 | static void | |
3f8548e7 | 3411 | maybe_print_instantiation_context (diagnostic_context *context) |
cb753e49 GDR |
3412 | { |
3413 | if (!problematic_instantiation_changed () || current_instantiation () == 0) | |
3414 | return; | |
3415 | ||
3416 | record_last_problematic_instantiation (); | |
47b69537 | 3417 | print_instantiation_full_context (context); |
cb753e49 | 3418 | } |
a1066c99 | 3419 | \f |
2bfe0527 JM |
3420 | /* Report what constexpr call(s) we're trying to expand, if any. */ |
3421 | ||
3422 | void | |
3423 | maybe_print_constexpr_context (diagnostic_context *context) | |
3424 | { | |
9771b263 | 3425 | vec<tree> call_stack = cx_error_context (); |
2bfe0527 JM |
3426 | unsigned ix; |
3427 | tree t; | |
3428 | ||
9771b263 | 3429 | FOR_EACH_VEC_ELT (call_stack, ix, t) |
2bfe0527 JM |
3430 | { |
3431 | expanded_location xloc = expand_location (EXPR_LOCATION (t)); | |
3432 | const char *s = expr_as_string (t, 0); | |
3433 | if (context->show_column) | |
3434 | pp_verbatim (context->printer, | |
4b84d650 JJ |
3435 | _("%r%s:%d:%d:%R in constexpr expansion of %qs"), |
3436 | "locus", xloc.file, xloc.line, xloc.column, s); | |
2bfe0527 JM |
3437 | else |
3438 | pp_verbatim (context->printer, | |
4b84d650 JJ |
3439 | _("%r%s:%d:%R in constexpr expansion of %qs"), |
3440 | "locus", xloc.file, xloc.line, s); | |
b066401f | 3441 | pp_newline (context->printer); |
2bfe0527 JM |
3442 | } |
3443 | } | |
3444 | \f | |
a1066c99 GDR |
3445 | /* Called from output_format -- during diagnostic message processing -- |
3446 | to handle C++ specific format specifier with the following meanings: | |
3447 | %A function argument-list. | |
749ced52 | 3448 | %C tree code. |
a1066c99 GDR |
3449 | %D declaration. |
3450 | %E expression. | |
3451 | %F function declaration. | |
749ced52 ZW |
3452 | %L language as used in extern "lang". |
3453 | %O binary operator. | |
a1066c99 | 3454 | %P function parameter whose position is indicated by an integer. |
749ced52 | 3455 | %Q assignment operator. |
3f04b1bb | 3456 | %S substitution (template + args) |
a1066c99 | 3457 | %T type. |
3f04b1bb JM |
3458 | %V cv-qualifier. |
3459 | %X exception-specification. */ | |
47b69537 | 3460 | static bool |
39ce81c9 ZW |
3461 | cp_printer (pretty_printer *pp, text_info *text, const char *spec, |
3462 | int precision, bool wide, bool set_locus, bool verbose) | |
a1066c99 | 3463 | { |
749ced52 | 3464 | const char *result; |
39ce81c9 ZW |
3465 | tree t = NULL; |
3466 | #define next_tree (t = va_arg (*text->args_ptr, tree)) | |
72b5577d ILT |
3467 | #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int)) |
3468 | #define next_lang ((enum languages) va_arg (*text->args_ptr, int)) | |
47b69537 GDR |
3469 | #define next_int va_arg (*text->args_ptr, int) |
3470 | ||
39ce81c9 ZW |
3471 | if (precision != 0 || wide) |
3472 | return false; | |
3473 | ||
3474 | if (text->locus == NULL) | |
3475 | set_locus = false; | |
a1066c99 | 3476 | |
39ce81c9 | 3477 | switch (*spec) |
22a4158c | 3478 | { |
749ced52 | 3479 | case 'A': result = args_to_string (next_tree, verbose); break; |
0cbd7506 | 3480 | case 'C': result = code_to_string (next_tcode); break; |
dd90d2b2 RH |
3481 | case 'D': |
3482 | { | |
3483 | tree temp = next_tree; | |
5a6ccc94 | 3484 | if (VAR_P (temp) |
839b422f | 3485 | && DECL_HAS_DEBUG_EXPR_P (temp)) |
dd90d2b2 RH |
3486 | { |
3487 | temp = DECL_DEBUG_EXPR (temp); | |
3488 | if (!DECL_P (temp)) | |
3489 | { | |
3490 | result = expr_to_string (temp); | |
3491 | break; | |
3492 | } | |
3493 | } | |
3494 | result = decl_to_string (temp, verbose); | |
3495 | } | |
3496 | break; | |
0cbd7506 | 3497 | case 'E': result = expr_to_string (next_tree); break; |
749ced52 | 3498 | case 'F': result = fndecl_to_string (next_tree, verbose); break; |
0cbd7506 MS |
3499 | case 'L': result = language_to_string (next_lang); break; |
3500 | case 'O': result = op_to_string (next_tcode); break; | |
3501 | case 'P': result = parm_to_string (next_int); break; | |
3502 | case 'Q': result = assop_to_string (next_tcode); break; | |
3ff60975 | 3503 | case 'S': result = subst_to_string (next_tree); break; |
749ced52 ZW |
3504 | case 'T': result = type_to_string (next_tree, verbose); break; |
3505 | case 'V': result = cv_to_string (next_tree, verbose); break; | |
3f04b1bb | 3506 | case 'X': result = eh_spec_to_string (next_tree, verbose); break; |
c8094d83 | 3507 | |
cf835838 JM |
3508 | case 'K': |
3509 | percent_K_format (text); | |
3510 | return true; | |
3511 | ||
22a4158c | 3512 | default: |
47b69537 | 3513 | return false; |
a1066c99 | 3514 | } |
bb20cc46 | 3515 | |
b066401f | 3516 | pp_string (pp, result); |
39ce81c9 ZW |
3517 | if (set_locus && t != NULL) |
3518 | *text->locus = location_of (t); | |
47b69537 | 3519 | return true; |
749ced52 ZW |
3520 | #undef next_tree |
3521 | #undef next_tcode | |
3522 | #undef next_lang | |
3523 | #undef next_int | |
a1066c99 | 3524 | } |
178b58b5 | 3525 | \f |
09357846 | 3526 | /* Warn about the use of C++0x features when appropriate. */ |
5d80a306 | 3527 | void |
848f237b | 3528 | maybe_warn_cpp0x (cpp0x_warn_str str) |
5d80a306 | 3529 | { |
8400e75e | 3530 | if ((cxx_dialect == cxx98) && !in_system_header_at (input_location)) |
a57a55de | 3531 | /* We really want to suppress this warning in system headers, |
5d80a306 DG |
3532 | because libstdc++ uses variadic templates even when we aren't |
3533 | in C++0x mode. */ | |
848f237b SZ |
3534 | switch (str) |
3535 | { | |
3536 | case CPP0X_INITIALIZER_LISTS: | |
3537 | pedwarn (input_location, 0, | |
3538 | "extended initializer lists " | |
97e3ad20 | 3539 | "only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3540 | break; |
3541 | case CPP0X_EXPLICIT_CONVERSION: | |
3542 | pedwarn (input_location, 0, | |
3543 | "explicit conversion operators " | |
97e3ad20 | 3544 | "only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3545 | break; |
3546 | case CPP0X_VARIADIC_TEMPLATES: | |
3547 | pedwarn (input_location, 0, | |
3548 | "variadic templates " | |
97e3ad20 | 3549 | "only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3550 | break; |
3551 | case CPP0X_LAMBDA_EXPR: | |
3552 | pedwarn (input_location, 0, | |
3553 | "lambda expressions " | |
97e3ad20 | 3554 | "only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3555 | break; |
3556 | case CPP0X_AUTO: | |
3557 | pedwarn (input_location, 0, | |
b0f36e5e | 3558 | "C++11 auto only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3559 | break; |
3560 | case CPP0X_SCOPED_ENUMS: | |
3561 | pedwarn (input_location, 0, | |
97e3ad20 | 3562 | "scoped enums only available with -std=c++11 or -std=gnu++11"); |
848f237b SZ |
3563 | break; |
3564 | case CPP0X_DEFAULTED_DELETED: | |
3565 | pedwarn (input_location, 0, | |
3566 | "defaulted and deleted functions " | |
97e3ad20 | 3567 | "only available with -std=c++11 or -std=gnu++11"); |
bc2c4cb4 RRC |
3568 | break; |
3569 | case CPP0X_INLINE_NAMESPACES: | |
c1771a20 | 3570 | pedwarn (input_location, OPT_Wpedantic, |
bc2c4cb4 | 3571 | "inline namespaces " |
97e3ad20 | 3572 | "only available with -std=c++11 or -std=gnu++11"); |
3ce4f9e4 | 3573 | break; |
eda42c4f VV |
3574 | case CPP0X_OVERRIDE_CONTROLS: |
3575 | pedwarn (input_location, 0, | |
3576 | "override controls (override/final) " | |
97e3ad20 | 3577 | "only available with -std=c++11 or -std=gnu++11"); |
eda42c4f | 3578 | break; |
0e5f8a59 JM |
3579 | case CPP0X_NSDMI: |
3580 | pedwarn (input_location, 0, | |
3581 | "non-static data member initializers " | |
97e3ad20 | 3582 | "only available with -std=c++11 or -std=gnu++11"); |
0e5f8a59 | 3583 | break; |
3ce4f9e4 ESR |
3584 | case CPP0X_USER_DEFINED_LITERALS: |
3585 | pedwarn (input_location, 0, | |
3586 | "user-defined literals " | |
97e3ad20 | 3587 | "only available with -std=c++11 or -std=gnu++11"); |
3ce4f9e4 | 3588 | break; |
238e471c VV |
3589 | case CPP0X_DELEGATING_CTORS: |
3590 | pedwarn (input_location, 0, | |
3591 | "delegating constructors " | |
3592 | "only available with -std=c++11 or -std=gnu++11"); | |
85b5d65a JM |
3593 | break; |
3594 | case CPP0X_INHERITING_CTORS: | |
3595 | pedwarn (input_location, 0, | |
3596 | "inheriting constructors " | |
3597 | "only available with -std=c++11 or -std=gnu++11"); | |
238e471c | 3598 | break; |
e28d52cf DS |
3599 | case CPP0X_ATTRIBUTES: |
3600 | pedwarn (input_location, 0, | |
3601 | "c++11 attributes " | |
3602 | "only available with -std=c++11 or -std=gnu++11"); | |
3603 | break; | |
2eed8e37 BK |
3604 | case CPP0X_REF_QUALIFIER: |
3605 | pedwarn (input_location, 0, | |
3606 | "ref-qualifiers " | |
b0f36e5e | 3607 | "only available with -std=c++11 or -std=gnu++11"); |
2eed8e37 | 3608 | break; |
848f237b | 3609 | default: |
3ce4f9e4 | 3610 | gcc_unreachable (); |
848f237b | 3611 | } |
09357846 JM |
3612 | } |
3613 | ||
3614 | /* Warn about the use of variadic templates when appropriate. */ | |
3615 | void | |
3616 | maybe_warn_variadic_templates (void) | |
3617 | { | |
848f237b | 3618 | maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES); |
5d80a306 | 3619 | } |
9c650d90 MLI |
3620 | |
3621 | ||
3622 | /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on | |
3623 | option OPT with text GMSGID. Use this function to report | |
3624 | diagnostics for constructs that are invalid C++98, but valid | |
3625 | C++0x. */ | |
3626 | bool | |
3627 | pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...) | |
3628 | { | |
3629 | diagnostic_info diagnostic; | |
3630 | va_list ap; | |
c522573e | 3631 | bool ret; |
9c650d90 MLI |
3632 | |
3633 | va_start (ap, gmsgid); | |
3634 | diagnostic_set_info (&diagnostic, gmsgid, &ap, location, | |
3635 | (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING); | |
3636 | diagnostic.option_index = opt; | |
c522573e | 3637 | ret = report_diagnostic (&diagnostic); |
9c650d90 | 3638 | va_end (ap); |
c522573e | 3639 | return ret; |
9c650d90 | 3640 | } |
993acb36 NF |
3641 | |
3642 | /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what | |
3643 | we found when we tried to do the lookup. LOCATION is the location of | |
3644 | the NAME identifier. */ | |
3645 | ||
3646 | void | |
3647 | qualified_name_lookup_error (tree scope, tree name, | |
3648 | tree decl, location_t location) | |
3649 | { | |
3650 | if (scope == error_mark_node) | |
3651 | ; /* We already complained. */ | |
3652 | else if (TYPE_P (scope)) | |
3653 | { | |
3654 | if (!COMPLETE_TYPE_P (scope)) | |
3655 | error_at (location, "incomplete type %qT used in nested name specifier", | |
3656 | scope); | |
3657 | else if (TREE_CODE (decl) == TREE_LIST) | |
3658 | { | |
3659 | error_at (location, "reference to %<%T::%D%> is ambiguous", | |
3660 | scope, name); | |
3661 | print_candidates (decl); | |
3662 | } | |
3663 | else | |
3664 | error_at (location, "%qD is not a member of %qT", name, scope); | |
3665 | } | |
3666 | else if (scope != global_namespace) | |
3667 | { | |
3668 | error_at (location, "%qD is not a member of %qD", name, scope); | |
3669 | suggest_alternatives_for (location, name); | |
3670 | } | |
3671 | else | |
3672 | { | |
3673 | error_at (location, "%<::%D%> has not been declared", name); | |
3674 | suggest_alternatives_for (location, name); | |
3675 | } | |
3676 | } |