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