]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Call-backs for C++ error reporting. |
2 | This code is non-reentrant. | |
7adcbafe | 3 | Copyright (C) 1993-2022 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" | |
7e2de6df | 21 | /* For use with name_hint. */ |
b8f7ff76 | 22 | #define INCLUDE_MEMORY |
8d052bc7 | 23 | #include "system.h" |
4977bab6 | 24 | #include "coretypes.h" |
8d08fdba | 25 | #include "cp-tree.h" |
2adfab87 | 26 | #include "stringpool.h" |
cf835838 | 27 | #include "tree-diagnostic.h" |
7cb32822 | 28 | #include "langhooks-def.h" |
b02cec6e | 29 | #include "intl.h" |
e1a4dd13 | 30 | #include "cxx-pretty-print.h" |
cf835838 | 31 | #include "tree-pretty-print.h" |
da67acb9 | 32 | #include "gimple-pretty-print.h" |
61d3ce20 | 33 | #include "c-family/c-objc.h" |
de5a5fa1 | 34 | #include "ubsan.h" |
0b274c17 | 35 | #include "internal-fn.h" |
96e6ae57 | 36 | #include "gcc-rich-location.h" |
7e2de6df | 37 | #include "cp-name-hint.h" |
8d08fdba | 38 | |
73bbafe5 | 39 | #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') |
ca17c07b | 40 | #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') |
a1066c99 | 41 | |
d723bb7c MLI |
42 | /* cxx_pp is a C++ front-end-specific pretty printer: this is where we |
43 | dump C++ ASTs as strings. It is mostly used only by the various | |
44 | tree -> string functions that are occasionally called from the | |
45 | debugger or by the front-end for things like | |
46 | __PRETTY_FUNCTION__. */ | |
5d58db82 PP |
47 | static cxx_pretty_printer actual_pretty_printer; |
48 | static cxx_pretty_printer * const cxx_pp = &actual_pretty_printer; | |
0aafb128 | 49 | |
f41c4af3 JM |
50 | /* Translate if being used for diagnostics, but not for dump files or |
51 | __PRETTY_FUNCTION. */ | |
52 | #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid)) | |
53 | ||
b34c06e3 | 54 | # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T))) |
8d08fdba | 55 | |
3f8548e7 | 56 | static const char *args_to_string (tree, int); |
4e3f84b7 | 57 | static const char *code_to_string (enum tree_code); |
3f8548e7 GDR |
58 | static const char *cv_to_string (tree, int); |
59 | static const char *decl_to_string (tree, int); | |
3f8548e7 | 60 | static const char *fndecl_to_string (tree, int); |
88a819be | 61 | static const char *op_to_string (bool, enum tree_code); |
4e3f84b7 | 62 | static const char *parm_to_string (int); |
ce95abc4 | 63 | static const char *type_to_string (tree, int, bool, bool *, bool); |
3f8548e7 | 64 | |
3c1ab1ab GDR |
65 | static void dump_alias_template_specialization (cxx_pretty_printer *, tree, int); |
66 | static void dump_type (cxx_pretty_printer *, tree, int); | |
67 | static void dump_typename (cxx_pretty_printer *, tree, int); | |
68 | static void dump_simple_decl (cxx_pretty_printer *, tree, tree, int); | |
69 | static void dump_decl (cxx_pretty_printer *, tree, int); | |
70 | static void dump_template_decl (cxx_pretty_printer *, tree, int); | |
71 | static void dump_function_decl (cxx_pretty_printer *, tree, int); | |
72 | static void dump_expr (cxx_pretty_printer *, tree, int); | |
73 | static void dump_unary_op (cxx_pretty_printer *, const char *, tree, int); | |
74 | static void dump_binary_op (cxx_pretty_printer *, const char *, tree, int); | |
75 | static void dump_aggr_type (cxx_pretty_printer *, tree, int); | |
76 | static void dump_type_prefix (cxx_pretty_printer *, tree, int); | |
77 | static void dump_type_suffix (cxx_pretty_printer *, tree, int); | |
78 | static void dump_function_name (cxx_pretty_printer *, tree, int); | |
79 | static void dump_call_expr_args (cxx_pretty_printer *, tree, int, bool); | |
80 | static void dump_aggr_init_expr_args (cxx_pretty_printer *, tree, int, bool); | |
81 | static void dump_expr_list (cxx_pretty_printer *, tree, int); | |
82 | static void dump_global_iord (cxx_pretty_printer *, tree); | |
83 | static void dump_parameters (cxx_pretty_printer *, tree, int); | |
84 | static void dump_ref_qualifier (cxx_pretty_printer *, tree, int); | |
85 | static void dump_exception_spec (cxx_pretty_printer *, tree, int); | |
86 | static void dump_template_argument (cxx_pretty_printer *, tree, int); | |
87 | static void dump_template_argument_list (cxx_pretty_printer *, tree, int); | |
88 | static void dump_template_parameter (cxx_pretty_printer *, tree, int); | |
89 | static void dump_template_bindings (cxx_pretty_printer *, tree, tree, | |
90 | vec<tree, va_gc> *); | |
91 | static void dump_scope (cxx_pretty_printer *, tree, int); | |
92 | static void dump_template_parms (cxx_pretty_printer *, tree, int, int); | |
1a048f82 | 93 | static int get_non_default_template_args_count (tree, int); |
3f8548e7 | 94 | static const char *function_category (tree); |
2bfe0527 | 95 | static void maybe_print_constexpr_context (diagnostic_context *); |
3f8548e7 GDR |
96 | static void maybe_print_instantiation_context (diagnostic_context *); |
97 | static void print_instantiation_full_context (diagnostic_context *); | |
98 | static void print_instantiation_partial_context (diagnostic_context *, | |
e2c3721c PB |
99 | struct tinst_level *, |
100 | location_t); | |
cb57504a | 101 | static void maybe_print_constraint_context (diagnostic_context *); |
3f8548e7 | 102 | static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *); |
3f8548e7 GDR |
103 | static void cp_print_error_function (diagnostic_context *, diagnostic_info *); |
104 | ||
39ce81c9 | 105 | static bool cp_printer (pretty_printer *, text_info *, const char *, |
ce95abc4 | 106 | int, bool, bool, bool, bool *, const char **); |
f012c8ef DM |
107 | |
108 | /* Struct for handling %H or %I, which require delaying printing the | |
109 | type until a postprocessing stage. */ | |
110 | ||
6c1dae73 | 111 | class deferred_printed_type |
f012c8ef | 112 | { |
6c1dae73 | 113 | public: |
f012c8ef DM |
114 | deferred_printed_type () |
115 | : m_tree (NULL_TREE), m_buffer_ptr (NULL), m_verbose (false), m_quote (false) | |
116 | {} | |
117 | ||
118 | deferred_printed_type (tree type, const char **buffer_ptr, bool verbose, | |
119 | bool quote) | |
120 | : m_tree (type), m_buffer_ptr (buffer_ptr), m_verbose (verbose), | |
121 | m_quote (quote) | |
122 | { | |
123 | gcc_assert (type); | |
124 | gcc_assert (buffer_ptr); | |
125 | } | |
126 | ||
127 | /* The tree is not GTY-marked: they are only non-NULL within a | |
128 | call to pp_format. */ | |
129 | tree m_tree; | |
130 | const char **m_buffer_ptr; | |
131 | bool m_verbose; | |
132 | bool m_quote; | |
133 | }; | |
134 | ||
135 | /* Subclass of format_postprocessor for the C++ frontend. | |
136 | This handles the %H and %I formatting codes, printing them | |
137 | in a postprocessing phase (since they affect each other). */ | |
138 | ||
139 | class cxx_format_postprocessor : public format_postprocessor | |
140 | { | |
141 | public: | |
142 | cxx_format_postprocessor () | |
143 | : m_type_a (), m_type_b () | |
144 | {} | |
145 | ||
368877a1 DM |
146 | format_postprocessor *clone() const FINAL OVERRIDE |
147 | { | |
148 | return new cxx_format_postprocessor (); | |
149 | } | |
150 | ||
f012c8ef DM |
151 | void handle (pretty_printer *pp) FINAL OVERRIDE; |
152 | ||
153 | deferred_printed_type m_type_a; | |
154 | deferred_printed_type m_type_b; | |
155 | }; | |
8d08fdba | 156 | |
d723bb7c MLI |
157 | /* CONTEXT->printer is a basic pretty printer that was constructed |
158 | presumably by diagnostic_initialize(), called early in the | |
159 | compiler's initialization process (in general_init) Before the FE | |
160 | is initialized. This (C++) FE-specific diagnostic initializer is | |
161 | thus replacing the basic pretty printer with one that has C++-aware | |
162 | capacities. */ | |
163 | ||
8d08fdba | 164 | void |
d723bb7c | 165 | cxx_initialize_diagnostics (diagnostic_context *context) |
8d08fdba | 166 | { |
d723bb7c MLI |
167 | pretty_printer *base = context->printer; |
168 | cxx_pretty_printer *pp = XNEW (cxx_pretty_printer); | |
169 | context->printer = new (pp) cxx_pretty_printer (); | |
170 | ||
171 | /* It is safe to free this object because it was previously XNEW()'d. */ | |
172 | base->~pretty_printer (); | |
173 | XDELETE (base); | |
174 | ||
175 | c_common_diagnostics_set_defaults (context); | |
176 | diagnostic_starter (context) = cp_diagnostic_starter; | |
18767f65 | 177 | /* diagnostic_finalizer is already c_diagnostic_finalizer. */ |
d723bb7c | 178 | diagnostic_format_decoder (context) = cp_printer; |
f012c8ef | 179 | pp->m_format_postprocessor = new cxx_format_postprocessor (); |
d723bb7c | 180 | } |
749ced52 | 181 | |
8c60696b NS |
182 | /* Dump an '@module' name suffix for DECL, if any. */ |
183 | ||
184 | static void | |
185 | dump_module_suffix (cxx_pretty_printer *pp, tree decl) | |
186 | { | |
187 | if (!modules_p ()) | |
188 | return; | |
189 | ||
190 | if (!DECL_CONTEXT (decl)) | |
191 | return; | |
192 | ||
193 | if (TREE_CODE (decl) != CONST_DECL | |
194 | || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl))) | |
195 | { | |
196 | if (!DECL_NAMESPACE_SCOPE_P (decl)) | |
197 | return; | |
198 | ||
199 | if (TREE_CODE (decl) == NAMESPACE_DECL | |
200 | && !DECL_NAMESPACE_ALIAS (decl) | |
201 | && (TREE_PUBLIC (decl) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl)))) | |
202 | return; | |
203 | } | |
204 | ||
205 | if (unsigned m = get_originating_module (decl)) | |
206 | if (const char *n = module_name (m, false)) | |
207 | { | |
208 | pp_character (pp, '@'); | |
209 | pp->padding = pp_none; | |
210 | pp_string (pp, n); | |
211 | } | |
212 | } | |
213 | ||
f78eaffd JM |
214 | /* The scope of the declaration we're currently printing, to avoid redundantly |
215 | dumping the same scope on parameter types. */ | |
216 | static tree current_dump_scope; | |
217 | ||
9e93bc9d | 218 | /* Dump a scope, if deemed necessary. */ |
bbcec105 | 219 | |
9e93bc9d | 220 | static void |
3c1ab1ab | 221 | dump_scope (cxx_pretty_printer *pp, tree scope, int flags) |
bbcec105 | 222 | { |
af88c58f | 223 | int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF); |
761f0855 | 224 | |
f78eaffd | 225 | if (scope == NULL_TREE || scope == current_dump_scope) |
9e93bc9d | 226 | return; |
bb20cc46 | 227 | |
3ded6ffd DM |
228 | /* Enum values within an unscoped enum will be CONST_DECL with an |
229 | ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the | |
230 | ENUMERAL_TYPE, so as to print any enclosing namespace. */ | |
231 | if (UNSCOPED_ENUM_P (scope)) | |
232 | scope = CP_TYPE_CONTEXT (scope); | |
233 | ||
9e93bc9d NS |
234 | if (TREE_CODE (scope) == NAMESPACE_DECL) |
235 | { | |
236 | if (scope != global_namespace) | |
0cbd7506 | 237 | { |
3c1ab1ab GDR |
238 | dump_decl (pp, scope, f); |
239 | pp_cxx_colon_colon (pp); | |
0cbd7506 | 240 | } |
9e93bc9d | 241 | } |
3ded6ffd DM |
242 | else if (AGGREGATE_TYPE_P (scope) |
243 | || SCOPED_ENUM_P (scope)) | |
9e93bc9d | 244 | { |
3c1ab1ab GDR |
245 | dump_type (pp, scope, f); |
246 | pp_cxx_colon_colon (pp); | |
9e93bc9d | 247 | } |
761f0855 | 248 | else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL) |
9e93bc9d | 249 | { |
7fb9a1e9 | 250 | dump_function_decl (pp, scope, f | TFF_NO_TEMPLATE_BINDINGS); |
3c1ab1ab | 251 | pp_cxx_colon_colon (pp); |
9e93bc9d | 252 | } |
bbcec105 JM |
253 | } |
254 | ||
612c671a | 255 | /* Dump the template ARGument under control of FLAGS. */ |
5f77d6cc GDR |
256 | |
257 | static void | |
3c1ab1ab | 258 | dump_template_argument (cxx_pretty_printer *pp, tree arg, int flags) |
5f77d6cc | 259 | { |
5d80a306 | 260 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 261 | dump_template_argument_list (pp, ARGUMENT_PACK_ARGS (arg), |
89a27d8f JM |
262 | /* No default args in argument packs. */ |
263 | flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
5d80a306 | 264 | else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL) |
3c1ab1ab | 265 | dump_type (pp, arg, flags & ~TFF_CLASS_KEY_OR_ENUM); |
5f77d6cc | 266 | else |
a9fe2f76 PC |
267 | { |
268 | if (TREE_CODE (arg) == TREE_LIST) | |
269 | arg = TREE_VALUE (arg); | |
270 | ||
16b61424 JM |
271 | /* Strip implicit conversions. */ |
272 | while (CONVERT_EXPR_P (arg)) | |
273 | arg = TREE_OPERAND (arg, 0); | |
274 | ||
3c1ab1ab | 275 | dump_expr (pp, arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM); |
a9fe2f76 | 276 | } |
5f77d6cc GDR |
277 | } |
278 | ||
53b39fe5 JM |
279 | /* Count the number of template arguments ARGS whose value does not |
280 | match the (optional) default template parameter in PARAMS */ | |
281 | ||
282 | static int | |
1a048f82 | 283 | get_non_default_template_args_count (tree args, int flags) |
53b39fe5 | 284 | { |
1a048f82 | 285 | int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 | 286 | |
1a048f82 | 287 | if (/* We use this flag when generating debug information. We don't |
b5b8b0ac AO |
288 | want to expand templates at this point, for this may generate |
289 | new decls, which gets decl counts out of sync, which may in | |
290 | turn cause codegen differences between compilations with and | |
291 | without -g. */ | |
1a048f82 | 292 | (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0 |
b5b8b0ac | 293 | || !flag_pretty_templates) |
53b39fe5 JM |
294 | return n; |
295 | ||
1a048f82 | 296 | return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 JM |
297 | } |
298 | ||
612c671a GDR |
299 | /* Dump a template-argument-list ARGS (always a TREE_VEC) under control |
300 | of FLAGS. */ | |
301 | ||
302 | static void | |
3c1ab1ab | 303 | dump_template_argument_list (cxx_pretty_printer *pp, tree args, int flags) |
612c671a | 304 | { |
1a048f82 | 305 | int n = get_non_default_template_args_count (args, flags); |
612c671a GDR |
306 | int need_comma = 0; |
307 | int i; | |
308 | ||
53b39fe5 | 309 | for (i = 0; i < n; ++i) |
612c671a | 310 | { |
5d80a306 DG |
311 | tree arg = TREE_VEC_ELT (args, i); |
312 | ||
313 | /* Only print a comma if we know there is an argument coming. In | |
314 | the case of an empty template argument pack, no actual | |
315 | argument will be printed. */ | |
316 | if (need_comma | |
317 | && (!ARGUMENT_PACK_P (arg) | |
318 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 319 | pp_separate_with_comma (pp); |
5d80a306 | 320 | |
3c1ab1ab | 321 | dump_template_argument (pp, arg, flags); |
612c671a GDR |
322 | need_comma = 1; |
323 | } | |
324 | } | |
325 | ||
326 | /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */ | |
327 | ||
328 | static void | |
3c1ab1ab | 329 | dump_template_parameter (cxx_pretty_printer *pp, tree parm, int flags) |
612c671a | 330 | { |
42b304f1 LM |
331 | tree p; |
332 | tree a; | |
333 | ||
334 | if (parm == error_mark_node) | |
335 | return; | |
336 | ||
337 | p = TREE_VALUE (parm); | |
338 | a = TREE_PURPOSE (parm); | |
612c671a GDR |
339 | |
340 | if (TREE_CODE (p) == TYPE_DECL) | |
341 | { | |
761f0855 | 342 | if (flags & TFF_DECL_SPECIFIERS) |
0cbd7506 | 343 | { |
3c1ab1ab | 344 | pp_cxx_ws_string (pp, "class"); |
5d80a306 | 345 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p))) |
3c1ab1ab | 346 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 | 347 | if (DECL_NAME (p)) |
3c1ab1ab | 348 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
0cbd7506 | 349 | } |
612c671a | 350 | else if (DECL_NAME (p)) |
3c1ab1ab | 351 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
612c671a | 352 | else |
3c1ab1ab | 353 | pp_cxx_canonical_template_parameter (pp, TREE_TYPE (p)); |
612c671a GDR |
354 | } |
355 | else | |
3c1ab1ab | 356 | dump_decl (pp, p, flags | TFF_DECL_SPECIFIERS); |
612c671a | 357 | |
761f0855 | 358 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE) |
612c671a | 359 | { |
3c1ab1ab GDR |
360 | pp_cxx_whitespace (pp); |
361 | pp_equal (pp); | |
362 | pp_cxx_whitespace (pp); | |
31bb3027 | 363 | if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL) |
3c1ab1ab | 364 | dump_type (pp, a, flags & ~TFF_CHASE_TYPEDEF); |
612c671a | 365 | else |
3c1ab1ab | 366 | dump_expr (pp, a, flags | TFF_EXPR_IN_PARENS); |
612c671a GDR |
367 | } |
368 | } | |
369 | ||
370 | /* Dump, under control of FLAGS, a template-parameter-list binding. | |
371 | PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a | |
372 | TREE_VEC. */ | |
373 | ||
374 | static void | |
3c1ab1ab GDR |
375 | dump_template_bindings (cxx_pretty_printer *pp, tree parms, tree args, |
376 | vec<tree, va_gc> *typenames) | |
612c671a | 377 | { |
c33ec196 MK |
378 | /* Print "[with" and ']', conditional on whether anything is printed at all. |
379 | This is tied to whether a semicolon is needed to separate multiple template | |
380 | parameters. */ | |
381 | struct prepost_semicolon | |
382 | { | |
383 | cxx_pretty_printer *pp; | |
384 | bool need_semicolon; | |
385 | ||
386 | void operator() () | |
387 | { | |
388 | if (need_semicolon) | |
389 | pp_separate_with_semicolon (pp); | |
390 | else | |
391 | { | |
392 | pp_cxx_whitespace (pp); | |
393 | pp_cxx_left_bracket (pp); | |
394 | pp->translate_string ("with"); | |
395 | pp_cxx_whitespace (pp); | |
396 | need_semicolon = true; | |
397 | } | |
398 | } | |
399 | ||
400 | ~prepost_semicolon () | |
401 | { | |
402 | if (need_semicolon) | |
403 | pp_cxx_right_bracket (pp); | |
404 | } | |
405 | } semicolon_or_introducer = {pp, false}; | |
406 | ||
d5c8be27 JM |
407 | int i; |
408 | tree t; | |
612c671a GDR |
409 | |
410 | while (parms) | |
411 | { | |
412 | tree p = TREE_VALUE (parms); | |
b5ac18ea MM |
413 | int lvl = TMPL_PARMS_DEPTH (parms); |
414 | int arg_idx = 0; | |
612c671a | 415 | int i; |
53b39fe5 JM |
416 | tree lvl_args = NULL_TREE; |
417 | ||
418 | /* Don't crash if we had an invalid argument list. */ | |
419 | if (TMPL_ARGS_DEPTH (args) >= lvl) | |
420 | lvl_args = TMPL_ARGS_LEVEL (args, lvl); | |
612c671a GDR |
421 | |
422 | for (i = 0; i < TREE_VEC_LENGTH (p); ++i) | |
b5ac18ea | 423 | { |
2bb5d995 JM |
424 | tree arg = NULL_TREE; |
425 | ||
426 | /* Don't crash if we had an invalid argument list. */ | |
53b39fe5 JM |
427 | if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx) |
428 | arg = TREE_VEC_ELT (lvl_args, arg_idx); | |
b5ac18ea | 429 | |
c33ec196 MK |
430 | tree parm_i = TREE_VEC_ELT (p, i); |
431 | /* If the template argument repeats the template parameter (T = T), | |
432 | skip the parameter.*/ | |
433 | if (arg && TREE_CODE (arg) == TEMPLATE_TYPE_PARM | |
434 | && TREE_CODE (parm_i) == TREE_LIST | |
435 | && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL | |
436 | && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i))) | |
437 | == TEMPLATE_TYPE_PARM | |
438 | && DECL_NAME (TREE_VALUE (parm_i)) | |
439 | == DECL_NAME (TREE_CHAIN (arg))) | |
440 | continue; | |
441 | ||
442 | semicolon_or_introducer (); | |
443 | dump_template_parameter (pp, parm_i, TFF_PLAIN_IDENTIFIER); | |
3c1ab1ab GDR |
444 | pp_cxx_whitespace (pp); |
445 | pp_equal (pp); | |
446 | pp_cxx_whitespace (pp); | |
b5ac18ea | 447 | if (arg) |
af16209f JM |
448 | { |
449 | if (ARGUMENT_PACK_P (arg)) | |
3c1ab1ab GDR |
450 | pp_cxx_left_brace (pp); |
451 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
af16209f | 452 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 453 | pp_cxx_right_brace (pp); |
af16209f | 454 | } |
b5ac18ea | 455 | else |
3c1ab1ab | 456 | pp_string (pp, M_("<missing>")); |
bb20cc46 | 457 | |
b5ac18ea | 458 | ++arg_idx; |
b5ac18ea | 459 | } |
612c671a GDR |
460 | |
461 | parms = TREE_CHAIN (parms); | |
462 | } | |
d5c8be27 | 463 | |
21d69a5b | 464 | /* Don't bother with typenames for a partial instantiation. */ |
9771b263 | 465 | if (vec_safe_is_empty (typenames) || uses_template_parms (args)) |
21d69a5b JM |
466 | return; |
467 | ||
1ed5f1d3 JM |
468 | /* Don't try to print typenames when we're processing a clone. */ |
469 | if (current_function_decl | |
470 | && !DECL_LANG_SPECIFIC (current_function_decl)) | |
471 | return; | |
472 | ||
e5e58dbe JM |
473 | /* Don't try to do this once cgraph starts throwing away front-end |
474 | information. */ | |
475 | if (at_eof >= 2) | |
476 | return; | |
477 | ||
9771b263 | 478 | FOR_EACH_VEC_SAFE_ELT (typenames, i, t) |
d5c8be27 | 479 | { |
c33ec196 | 480 | semicolon_or_introducer (); |
3c1ab1ab GDR |
481 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); |
482 | pp_cxx_whitespace (pp); | |
483 | pp_equal (pp); | |
484 | pp_cxx_whitespace (pp); | |
42d1e31d | 485 | push_deferring_access_checks (dk_no_check); |
a4d674fc | 486 | t = tsubst (t, args, tf_none, NULL_TREE); |
42d1e31d | 487 | pop_deferring_access_checks (); |
a4d674fc JM |
488 | /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because |
489 | pp_simple_type_specifier doesn't know about it. */ | |
10bce48f | 490 | t = strip_typedefs (t, NULL, STF_USER_VISIBLE); |
3c1ab1ab | 491 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); |
d5c8be27 | 492 | } |
612c671a GDR |
493 | } |
494 | ||
28704289 DS |
495 | /* Dump a human-readable equivalent of the alias template |
496 | specialization of T. */ | |
497 | ||
498 | static void | |
3c1ab1ab | 499 | dump_alias_template_specialization (cxx_pretty_printer *pp, tree t, int flags) |
28704289 | 500 | { |
96cbfa7f | 501 | gcc_assert (alias_template_specialization_p (t, nt_opaque)); |
28704289 | 502 | |
5bfd81e7 | 503 | tree decl = TYPE_NAME (t); |
7d29c953 | 504 | if (!(flags & TFF_UNQUALIFIED_NAME)) |
5bfd81e7 NS |
505 | dump_scope (pp, CP_DECL_CONTEXT (decl), flags); |
506 | pp_cxx_tree_identifier (pp, DECL_NAME (decl)); | |
507 | dump_template_parms (pp, DECL_TEMPLATE_INFO (decl), | |
28704289 DS |
508 | /*primary=*/false, |
509 | flags & ~TFF_TEMPLATE_HEADER); | |
510 | } | |
511 | ||
b3426eb9 GK |
512 | /* Dump a human-readable equivalent of TYPE. FLAGS controls the |
513 | format. */ | |
e92cc029 | 514 | |
8d08fdba | 515 | static void |
3c1ab1ab | 516 | dump_type (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
517 | { |
518 | if (t == NULL_TREE) | |
519 | return; | |
bb20cc46 | 520 | |
3333a2dd JM |
521 | /* Don't print e.g. "struct mytypedef". */ |
522 | if (TYPE_P (t) && typedef_variant_p (t)) | |
523 | { | |
524 | tree decl = TYPE_NAME (t); | |
525 | if ((flags & TFF_CHASE_TYPEDEF) | |
28704289 DS |
526 | || DECL_SELF_REFERENCE_P (decl) |
527 | || (!flag_pretty_templates | |
528 | && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))) | |
10bce48f RS |
529 | { |
530 | unsigned int stf_flags = (!(pp->flags & pp_c_flag_gnu_v3) | |
531 | ? STF_USER_VISIBLE : 0); | |
532 | t = strip_typedefs (t, NULL, stf_flags); | |
533 | } | |
96cbfa7f | 534 | else if (alias_template_specialization_p (t, nt_opaque)) |
28704289 | 535 | { |
3c1ab1ab | 536 | dump_alias_template_specialization (pp, t, flags); |
28704289 DS |
537 | return; |
538 | } | |
3333a2dd JM |
539 | else if (same_type_p (t, TREE_TYPE (decl))) |
540 | t = decl; | |
541 | else | |
542 | { | |
3c1ab1ab | 543 | pp_cxx_cv_qualifier_seq (pp, t); |
27e906d5 MK |
544 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
545 | dump_scope (pp, CP_DECL_CONTEXT (decl), flags); | |
3c1ab1ab | 546 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
3333a2dd JM |
547 | return; |
548 | } | |
549 | } | |
550 | ||
8d08fdba MS |
551 | if (TYPE_PTRMEMFUNC_P (t)) |
552 | goto offset_type; | |
553 | ||
554 | switch (TREE_CODE (t)) | |
555 | { | |
fbfc8363 | 556 | case LANG_TYPE: |
09357846 | 557 | if (t == init_list_type_node) |
3c1ab1ab | 558 | pp_string (pp, M_("<brace-enclosed initializer list>")); |
fbfc8363 | 559 | else if (t == unknown_type_node) |
3c1ab1ab | 560 | pp_string (pp, M_("<unresolved overloaded function type>")); |
fbfc8363 | 561 | else |
5116acc6 | 562 | { |
3c1ab1ab GDR |
563 | pp_cxx_cv_qualifier_seq (pp, t); |
564 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
5116acc6 | 565 | } |
8d08fdba MS |
566 | break; |
567 | ||
dcd08efc JM |
568 | case TREE_LIST: |
569 | /* A list of function parms. */ | |
3c1ab1ab | 570 | dump_parameters (pp, t, flags); |
dcd08efc JM |
571 | break; |
572 | ||
8d08fdba | 573 | case IDENTIFIER_NODE: |
3c1ab1ab | 574 | pp_cxx_tree_identifier (pp, t); |
8d08fdba MS |
575 | break; |
576 | ||
c81f61b2 | 577 | case TREE_BINFO: |
3c1ab1ab | 578 | dump_type (pp, BINFO_TYPE (t), flags); |
8d08fdba MS |
579 | break; |
580 | ||
581 | case RECORD_TYPE: | |
582 | case UNION_TYPE: | |
583 | case ENUMERAL_TYPE: | |
3c1ab1ab | 584 | dump_aggr_type (pp, t, flags); |
8d08fdba MS |
585 | break; |
586 | ||
587 | case TYPE_DECL: | |
761f0855 | 588 | if (flags & TFF_CHASE_TYPEDEF) |
0cbd7506 | 589 | { |
3c1ab1ab | 590 | dump_type (pp, DECL_ORIGINAL_TYPE (t) |
0cbd7506 MS |
591 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags); |
592 | break; | |
593 | } | |
191816a3 | 594 | /* Fall through. */ |
bb20cc46 | 595 | |
67c2a928 | 596 | case TEMPLATE_DECL: |
009425e1 | 597 | case NAMESPACE_DECL: |
3c1ab1ab | 598 | dump_decl (pp, t, flags & ~TFF_DECL_SPECIFIERS); |
8d08fdba | 599 | break; |
bb20cc46 | 600 | |
8d08fdba | 601 | case INTEGER_TYPE: |
8d08fdba MS |
602 | case REAL_TYPE: |
603 | case VOID_TYPE: | |
1e2d8575 | 604 | case OPAQUE_TYPE: |
2986ae00 | 605 | case BOOLEAN_TYPE: |
53de5204 GDR |
606 | case COMPLEX_TYPE: |
607 | case VECTOR_TYPE: | |
998ceda2 | 608 | case FIXED_POINT_TYPE: |
3c1ab1ab | 609 | pp_type_specifier_seq (pp, t); |
8d08fdba MS |
610 | break; |
611 | ||
73b0fce8 | 612 | case TEMPLATE_TEMPLATE_PARM: |
c6002625 | 613 | /* For parameters inside template signature. */ |
a1281f45 | 614 | if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 615 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
73b0fce8 | 616 | else |
3c1ab1ab | 617 | pp_cxx_canonical_template_parameter (pp, t); |
a1281f45 KL |
618 | break; |
619 | ||
620 | case BOUND_TEMPLATE_TEMPLATE_PARM: | |
621 | { | |
622 | tree args = TYPE_TI_ARGS (t); | |
3c1ab1ab GDR |
623 | pp_cxx_cv_qualifier_seq (pp, t); |
624 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
625 | pp_cxx_begin_template_argument_list (pp); | |
626 | dump_template_argument_list (pp, args, flags); | |
627 | pp_cxx_end_template_argument_list (pp); | |
a1281f45 | 628 | } |
73b0fce8 KL |
629 | break; |
630 | ||
8d08fdba | 631 | case TEMPLATE_TYPE_PARM: |
3c1ab1ab | 632 | pp_cxx_cv_qualifier_seq (pp, t); |
cb57504a | 633 | if (template_placeholder_p (t)) |
33f746e5 AO |
634 | { |
635 | t = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t)); | |
636 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
637 | pp_string (pp, "<...auto...>"); | |
638 | } | |
4fea442d | 639 | else if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 640 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
ec255269 | 641 | else |
0cbd7506 | 642 | pp_cxx_canonical_template_parameter |
3c1ab1ab | 643 | (pp, TEMPLATE_TYPE_PARM_INDEX (t)); |
cb57504a JM |
644 | /* If this is a constrained placeholder, add the requirements. */ |
645 | if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t)) | |
646 | pp_cxx_constrained_type_spec (pp, c); | |
8d08fdba MS |
647 | break; |
648 | ||
8d08fdba MS |
649 | /* This is not always necessary for pointers and such, but doing this |
650 | reduces code size. */ | |
651 | case ARRAY_TYPE: | |
652 | case POINTER_TYPE: | |
653 | case REFERENCE_TYPE: | |
654 | case OFFSET_TYPE: | |
655 | offset_type: | |
656 | case FUNCTION_TYPE: | |
657 | case METHOD_TYPE: | |
9e93bc9d | 658 | { |
3c1ab1ab GDR |
659 | dump_type_prefix (pp, t, flags); |
660 | dump_type_suffix (pp, t, flags); | |
8d08fdba | 661 | break; |
9e93bc9d | 662 | } |
5566b478 | 663 | case TYPENAME_TYPE: |
a4d674fc JM |
664 | if (! (flags & TFF_CHASE_TYPEDEF) |
665 | && DECL_ORIGINAL_TYPE (TYPE_NAME (t))) | |
666 | { | |
3c1ab1ab | 667 | dump_decl (pp, TYPE_NAME (t), TFF_PLAIN_IDENTIFIER); |
a4d674fc JM |
668 | break; |
669 | } | |
3c1ab1ab GDR |
670 | pp_cxx_cv_qualifier_seq (pp, t); |
671 | pp_cxx_ws_string (pp, | |
c8094d83 | 672 | TYPENAME_IS_ENUM_P (t) ? "enum" |
fc6a28d7 MM |
673 | : TYPENAME_IS_CLASS_P (t) ? "class" |
674 | : "typename"); | |
3c1ab1ab | 675 | dump_typename (pp, t, flags); |
5566b478 MS |
676 | break; |
677 | ||
b8c6534b | 678 | case UNBOUND_CLASS_TEMPLATE: |
e1faa105 JM |
679 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
680 | { | |
3c1ab1ab GDR |
681 | dump_type (pp, TYPE_CONTEXT (t), flags); |
682 | pp_cxx_colon_colon (pp); | |
e1faa105 | 683 | } |
3c1ab1ab | 684 | pp_cxx_ws_string (pp, "template"); |
cc27b5cd | 685 | dump_type (pp, TYPE_IDENTIFIER (t), flags); |
b8c6534b KL |
686 | break; |
687 | ||
b894fc05 | 688 | case TYPEOF_TYPE: |
3c1ab1ab GDR |
689 | pp_cxx_ws_string (pp, "__typeof__"); |
690 | pp_cxx_whitespace (pp); | |
691 | pp_cxx_left_paren (pp); | |
692 | dump_expr (pp, TYPEOF_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
693 | pp_cxx_right_paren (pp); | |
b894fc05 JM |
694 | break; |
695 | ||
a0d260fc | 696 | case UNDERLYING_TYPE: |
3c1ab1ab GDR |
697 | pp_cxx_ws_string (pp, "__underlying_type"); |
698 | pp_cxx_whitespace (pp); | |
699 | pp_cxx_left_paren (pp); | |
700 | dump_expr (pp, UNDERLYING_TYPE_TYPE (t), flags & ~TFF_EXPR_IN_PARENS); | |
701 | pp_cxx_right_paren (pp); | |
a0d260fc PC |
702 | break; |
703 | ||
5d80a306 | 704 | case TYPE_PACK_EXPANSION: |
3c1ab1ab GDR |
705 | dump_type (pp, PACK_EXPANSION_PATTERN (t), flags); |
706 | pp_cxx_ws_string (pp, "..."); | |
5d80a306 DG |
707 | break; |
708 | ||
b1d7b1c0 | 709 | case TYPE_ARGUMENT_PACK: |
3c1ab1ab | 710 | dump_template_argument (pp, t, flags); |
b1d7b1c0 DG |
711 | break; |
712 | ||
3ad6a8e1 | 713 | case DECLTYPE_TYPE: |
3c1ab1ab GDR |
714 | pp_cxx_ws_string (pp, "decltype"); |
715 | pp_cxx_whitespace (pp); | |
716 | pp_cxx_left_paren (pp); | |
717 | dump_expr (pp, DECLTYPE_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
718 | pp_cxx_right_paren (pp); | |
3ad6a8e1 DG |
719 | break; |
720 | ||
1e85e720 | 721 | case NULLPTR_TYPE: |
3c1ab1ab | 722 | pp_string (pp, "std::nullptr_t"); |
1e85e720 RG |
723 | break; |
724 | ||
8d08fdba | 725 | default: |
3c1ab1ab | 726 | pp_unsupported_tree (pp, t); |
295844f6 | 727 | /* Fall through. */ |
9e93bc9d NS |
728 | |
729 | case ERROR_MARK: | |
3c1ab1ab | 730 | pp_string (pp, M_("<type error>")); |
9e93bc9d | 731 | break; |
8d08fdba MS |
732 | } |
733 | } | |
734 | ||
46e2747c NS |
735 | /* Dump a TYPENAME_TYPE. We need to notice when the context is itself |
736 | a TYPENAME_TYPE. */ | |
737 | ||
738 | static void | |
3c1ab1ab | 739 | dump_typename (cxx_pretty_printer *pp, tree t, int flags) |
46e2747c NS |
740 | { |
741 | tree ctx = TYPE_CONTEXT (t); | |
bb20cc46 | 742 | |
46e2747c | 743 | if (TREE_CODE (ctx) == TYPENAME_TYPE) |
3c1ab1ab | 744 | dump_typename (pp, ctx, flags); |
46e2747c | 745 | else |
3c1ab1ab GDR |
746 | dump_type (pp, ctx, flags & ~TFF_CLASS_KEY_OR_ENUM); |
747 | pp_cxx_colon_colon (pp); | |
748 | dump_decl (pp, TYPENAME_TYPE_FULLNAME (t), flags); | |
46e2747c NS |
749 | } |
750 | ||
9e93bc9d NS |
751 | /* Return the name of the supplied aggregate, or enumeral type. */ |
752 | ||
3cabd8f9 MA |
753 | const char * |
754 | class_key_or_enum_as_string (tree t) | |
8d08fdba | 755 | { |
adf2edec DG |
756 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
757 | { | |
758 | if (SCOPED_ENUM_P (t)) | |
759 | return "enum class"; | |
760 | else | |
761 | return "enum"; | |
762 | } | |
8d08fdba | 763 | else if (TREE_CODE (t) == UNION_TYPE) |
51c184be | 764 | return "union"; |
8d08fdba | 765 | else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t)) |
51c184be | 766 | return "class"; |
8d08fdba | 767 | else |
51c184be MS |
768 | return "struct"; |
769 | } | |
770 | ||
9e93bc9d NS |
771 | /* Print out a class declaration T under the control of FLAGS, |
772 | in the form `class foo'. */ | |
e92cc029 | 773 | |
51c184be | 774 | static void |
3c1ab1ab | 775 | dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags) |
51c184be | 776 | { |
3cabd8f9 | 777 | const char *variety = class_key_or_enum_as_string (t); |
9e93bc9d NS |
778 | int typdef = 0; |
779 | int tmplate = 0; | |
8d08fdba | 780 | |
3c1ab1ab | 781 | pp_cxx_cv_qualifier_seq (pp, t); |
8d08fdba | 782 | |
761f0855 | 783 | if (flags & TFF_CLASS_KEY_OR_ENUM) |
3c1ab1ab | 784 | pp_cxx_ws_string (pp, variety); |
bb20cc46 | 785 | |
0f32c94f | 786 | tree decl = TYPE_NAME (t); |
9e93bc9d | 787 | |
0f32c94f | 788 | if (decl) |
8d08fdba | 789 | { |
0f32c94f | 790 | typdef = (!DECL_ARTIFICIAL (decl) |
28704289 DS |
791 | /* An alias specialization is not considered to be a |
792 | typedef. */ | |
96cbfa7f | 793 | && !alias_template_specialization_p (t, nt_opaque)); |
f6f5e3a1 | 794 | |
abd5730b JM |
795 | if ((typdef |
796 | && ((flags & TFF_CHASE_TYPEDEF) | |
0f32c94f NS |
797 | || (!flag_pretty_templates && DECL_LANG_SPECIFIC (decl) |
798 | && DECL_TEMPLATE_INFO (decl)))) | |
799 | || DECL_SELF_REFERENCE_P (decl)) | |
f6f5e3a1 JM |
800 | { |
801 | t = TYPE_MAIN_VARIANT (t); | |
0f32c94f | 802 | decl = TYPE_NAME (t); |
f6f5e3a1 JM |
803 | typdef = 0; |
804 | } | |
805 | ||
9e93bc9d | 806 | tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE |
0cbd7506 | 807 | && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t) |
f0d60e22 | 808 | && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL |
0cbd7506 | 809 | || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t))); |
a0ad3539 MM |
810 | |
811 | if (! (flags & TFF_UNQUALIFIED_NAME)) | |
0f32c94f | 812 | dump_scope (pp, CP_DECL_CONTEXT (decl), flags | TFF_SCOPE); |
a0ad3539 | 813 | flags &= ~TFF_UNQUALIFIED_NAME; |
9e93bc9d | 814 | if (tmplate) |
0cbd7506 MS |
815 | { |
816 | /* Because the template names are mangled, we have to locate | |
817 | the most general template, and use that name. */ | |
28704289 | 818 | tree tpl = TYPE_TI_TEMPLATE (t); |
0cbd7506 MS |
819 | |
820 | while (DECL_TEMPLATE_INFO (tpl)) | |
821 | tpl = DECL_TI_TEMPLATE (tpl); | |
0f32c94f | 822 | decl = tpl; |
0cbd7506 | 823 | } |
8d08fdba MS |
824 | } |
825 | ||
ca3edeae | 826 | if (LAMBDA_TYPE_P (t)) |
d5f4eddd JM |
827 | { |
828 | /* A lambda's "type" is essentially its signature. */ | |
3c1ab1ab | 829 | pp_string (pp, M_("<lambda")); |
d5f4eddd | 830 | if (lambda_function (t)) |
3c1ab1ab GDR |
831 | dump_parameters (pp, |
832 | FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t)), | |
d5f4eddd | 833 | flags); |
3c1ab1ab | 834 | pp_greater (pp); |
d5f4eddd | 835 | } |
0f32c94f | 836 | else if (!decl || IDENTIFIER_ANON_P (DECL_NAME (decl))) |
ca3edeae NS |
837 | { |
838 | if (flags & TFF_CLASS_KEY_OR_ENUM) | |
839 | pp_string (pp, M_("<unnamed>")); | |
840 | else | |
841 | pp_printf (pp, M_("<unnamed %s>"), variety); | |
842 | } | |
8d08fdba | 843 | else |
0f32c94f | 844 | pp_cxx_tree_identifier (pp, DECL_NAME (decl)); |
ca3edeae | 845 | |
8c60696b NS |
846 | dump_module_suffix (pp, decl); |
847 | ||
9e93bc9d | 848 | if (tmplate) |
3c1ab1ab | 849 | dump_template_parms (pp, TYPE_TEMPLATE_INFO (t), |
0cbd7506 MS |
850 | !CLASSTYPE_USE_TEMPLATE (t), |
851 | flags & ~TFF_TEMPLATE_HEADER); | |
8d08fdba MS |
852 | } |
853 | ||
854 | /* Dump into the obstack the initial part of the output for a given type. | |
855 | This is necessary when dealing with things like functions returning | |
856 | functions. Examples: | |
857 | ||
858 | return type of `int (* fee ())()': pointer -> function -> int. Both | |
859 | pointer (and reference and offset) and function (and member) types must | |
860 | deal with prefix and suffix. | |
861 | ||
862 | Arrays must also do this for DECL nodes, like int a[], and for things like | |
b9b44fb9 | 863 | int *[]&. */ |
8d08fdba | 864 | |
c8094d83 | 865 | static void |
3c1ab1ab | 866 | dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
867 | { |
868 | if (TYPE_PTRMEMFUNC_P (t)) | |
869 | { | |
870 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
871 | goto offset_type; | |
872 | } | |
bb20cc46 | 873 | |
8d08fdba MS |
874 | switch (TREE_CODE (t)) |
875 | { | |
876 | case POINTER_TYPE: | |
91063b51 | 877 | case REFERENCE_TYPE: |
8d08fdba MS |
878 | { |
879 | tree sub = TREE_TYPE (t); | |
bb20cc46 | 880 | |
3c1ab1ab | 881 | dump_type_prefix (pp, sub, flags); |
0d9c0892 JM |
882 | if (TREE_CODE (sub) == ARRAY_TYPE |
883 | || TREE_CODE (sub) == FUNCTION_TYPE) | |
8d08fdba | 884 | { |
3c1ab1ab GDR |
885 | pp_cxx_whitespace (pp); |
886 | pp_cxx_left_paren (pp); | |
887 | pp_c_attributes_display (pp, TYPE_ATTRIBUTES (sub)); | |
8d08fdba | 888 | } |
50e10fa8 | 889 | if (TYPE_PTR_P (t)) |
3c1ab1ab | 890 | pp_star (pp); |
9f613f06 PC |
891 | else if (TYPE_REF_P (t)) |
892 | { | |
893 | if (TYPE_REF_IS_RVALUE (t)) | |
894 | pp_ampersand_ampersand (pp); | |
895 | else | |
896 | pp_ampersand (pp); | |
897 | } | |
3c1ab1ab GDR |
898 | pp->padding = pp_before; |
899 | pp_cxx_cv_qualifier_seq (pp, t); | |
8d08fdba | 900 | } |
8d08fdba MS |
901 | break; |
902 | ||
903 | case OFFSET_TYPE: | |
904 | offset_type: | |
3c1ab1ab | 905 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
51c184be MS |
906 | if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */ |
907 | { | |
3c1ab1ab | 908 | pp_maybe_space (pp); |
0cbd7506 | 909 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) |
3c1ab1ab GDR |
910 | pp_cxx_left_paren (pp); |
911 | dump_type (pp, TYPE_OFFSET_BASETYPE (t), flags); | |
912 | pp_cxx_colon_colon (pp); | |
51c184be | 913 | } |
3c1ab1ab GDR |
914 | pp_cxx_star (pp); |
915 | pp_cxx_cv_qualifier_seq (pp, t); | |
916 | pp->padding = pp_before; | |
8d08fdba MS |
917 | break; |
918 | ||
0d9c0892 JM |
919 | /* This can be reached without a pointer when dealing with |
920 | templates, e.g. std::is_function. */ | |
8d08fdba | 921 | case FUNCTION_TYPE: |
3c1ab1ab | 922 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
923 | break; |
924 | ||
925 | case METHOD_TYPE: | |
3c1ab1ab GDR |
926 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
927 | pp_maybe_space (pp); | |
928 | pp_cxx_left_paren (pp); | |
929 | dump_aggr_type (pp, TYPE_METHOD_BASETYPE (t), flags); | |
930 | pp_cxx_colon_colon (pp); | |
8d08fdba MS |
931 | break; |
932 | ||
933 | case ARRAY_TYPE: | |
3c1ab1ab | 934 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
935 | break; |
936 | ||
937 | case ENUMERAL_TYPE: | |
8d08fdba MS |
938 | case IDENTIFIER_NODE: |
939 | case INTEGER_TYPE: | |
2986ae00 | 940 | case BOOLEAN_TYPE: |
8d08fdba MS |
941 | case REAL_TYPE: |
942 | case RECORD_TYPE: | |
943 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 944 | case TEMPLATE_TEMPLATE_PARM: |
a1281f45 | 945 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
946 | case TREE_LIST: |
947 | case TYPE_DECL: | |
948 | case TREE_VEC: | |
8d08fdba | 949 | case UNION_TYPE: |
fbfc8363 | 950 | case LANG_TYPE: |
8d08fdba | 951 | case VOID_TYPE: |
1e2d8575 | 952 | case OPAQUE_TYPE: |
5566b478 | 953 | case TYPENAME_TYPE: |
37c46b43 | 954 | case COMPLEX_TYPE: |
c00996a3 | 955 | case VECTOR_TYPE: |
0df4ae96 | 956 | case TYPEOF_TYPE: |
a0d260fc | 957 | case UNDERLYING_TYPE: |
3ad6a8e1 | 958 | case DECLTYPE_TYPE: |
e7de2d6f | 959 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 960 | case FIXED_POINT_TYPE: |
1e85e720 | 961 | case NULLPTR_TYPE: |
3c1ab1ab GDR |
962 | dump_type (pp, t, flags); |
963 | pp->padding = pp_before; | |
8d08fdba | 964 | break; |
bb20cc46 | 965 | |
8d08fdba | 966 | default: |
3c1ab1ab | 967 | pp_unsupported_tree (pp, t); |
99885b3f | 968 | /* fall through. */ |
9e93bc9d | 969 | case ERROR_MARK: |
3c1ab1ab | 970 | pp_string (pp, M_("<typeprefixerror>")); |
9e93bc9d | 971 | break; |
8d08fdba MS |
972 | } |
973 | } | |
974 | ||
9e93bc9d NS |
975 | /* Dump the suffix of type T, under control of FLAGS. This is the part |
976 | which appears after the identifier (or function parms). */ | |
977 | ||
8d08fdba | 978 | static void |
3c1ab1ab | 979 | dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
980 | { |
981 | if (TYPE_PTRMEMFUNC_P (t)) | |
982 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
983 | ||
984 | switch (TREE_CODE (t)) | |
985 | { | |
986 | case POINTER_TYPE: | |
987 | case REFERENCE_TYPE: | |
988 | case OFFSET_TYPE: | |
0d9c0892 JM |
989 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE |
990 | || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) | |
3c1ab1ab | 991 | pp_cxx_right_paren (pp); |
985acf5a PC |
992 | if (TREE_CODE (t) == POINTER_TYPE) |
993 | flags |= TFF_POINTER; | |
3c1ab1ab | 994 | dump_type_suffix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
995 | break; |
996 | ||
8d08fdba MS |
997 | case FUNCTION_TYPE: |
998 | case METHOD_TYPE: | |
999 | { | |
1000 | tree arg; | |
0d9c0892 JM |
1001 | if (TREE_CODE (t) == METHOD_TYPE) |
1002 | /* Can only be reached through a pointer. */ | |
3c1ab1ab | 1003 | pp_cxx_right_paren (pp); |
8d08fdba MS |
1004 | arg = TYPE_ARG_TYPES (t); |
1005 | if (TREE_CODE (t) == METHOD_TYPE) | |
1006 | arg = TREE_CHAIN (arg); | |
1007 | ||
4995028c NS |
1008 | /* Function pointers don't have default args. Not in standard C++, |
1009 | anyway; they may in g++, but we'll just pretend otherwise. */ | |
3c1ab1ab | 1010 | dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS); |
4995028c | 1011 | |
3c1ab1ab | 1012 | pp->padding = pp_before; |
985acf5a PC |
1013 | pp_cxx_cv_qualifiers (pp, type_memfn_quals (t), |
1014 | TREE_CODE (t) == FUNCTION_TYPE | |
1015 | && (flags & TFF_POINTER)); | |
3c1ab1ab | 1016 | dump_ref_qualifier (pp, t, flags); |
b8fd7909 JM |
1017 | if (tx_safe_fn_type_p (t)) |
1018 | pp_cxx_ws_string (pp, "transaction_safe"); | |
3c1ab1ab GDR |
1019 | dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags); |
1020 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba MS |
1021 | break; |
1022 | } | |
1023 | ||
1024 | case ARRAY_TYPE: | |
3c1ab1ab GDR |
1025 | pp_maybe_space (pp); |
1026 | pp_cxx_left_bracket (pp); | |
05dd97db | 1027 | if (tree dtype = TYPE_DOMAIN (t)) |
5156628f | 1028 | { |
5e203bf8 | 1029 | tree max = TYPE_MAX_VALUE (dtype); |
1be51a3a MS |
1030 | /* Zero-length arrays have a null upper bound in C and SIZE_MAX |
1031 | in C++. Handle both since the type might be constructed by | |
1032 | the middle end and end up here as a result of a warning (see | |
1033 | PR c++/97201). */ | |
1034 | if (!max || integer_all_onesp (max)) | |
3c1ab1ab | 1035 | pp_character (pp, '0'); |
9541ffee | 1036 | else if (tree_fits_shwi_p (max)) |
9439e9a1 | 1037 | pp_wide_integer (pp, tree_to_shwi (max) + 1); |
5156628f | 1038 | else |
785b887e JM |
1039 | { |
1040 | STRIP_NOPS (max); | |
1041 | if (TREE_CODE (max) == SAVE_EXPR) | |
1042 | max = TREE_OPERAND (max, 0); | |
1043 | if (TREE_CODE (max) == MINUS_EXPR | |
1044 | || TREE_CODE (max) == PLUS_EXPR) | |
1045 | { | |
1046 | max = TREE_OPERAND (max, 0); | |
1047 | while (CONVERT_EXPR_P (max)) | |
1048 | max = TREE_OPERAND (max, 0); | |
1049 | } | |
1050 | else | |
1051 | max = fold_build2_loc (input_location, | |
1052 | PLUS_EXPR, dtype, max, | |
1053 | build_int_cst (dtype, 1)); | |
3c1ab1ab | 1054 | dump_expr (pp, max, flags & ~TFF_EXPR_IN_PARENS); |
785b887e | 1055 | } |
5156628f | 1056 | } |
3c1ab1ab GDR |
1057 | pp_cxx_right_bracket (pp); |
1058 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba | 1059 | break; |
bb20cc46 | 1060 | |
8d08fdba | 1061 | case ENUMERAL_TYPE: |
8d08fdba MS |
1062 | case IDENTIFIER_NODE: |
1063 | case INTEGER_TYPE: | |
2986ae00 | 1064 | case BOOLEAN_TYPE: |
8d08fdba MS |
1065 | case REAL_TYPE: |
1066 | case RECORD_TYPE: | |
1067 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 1068 | case TEMPLATE_TEMPLATE_PARM: |
a97d0689 | 1069 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
1070 | case TREE_LIST: |
1071 | case TYPE_DECL: | |
1072 | case TREE_VEC: | |
8d08fdba | 1073 | case UNION_TYPE: |
fbfc8363 | 1074 | case LANG_TYPE: |
8d08fdba | 1075 | case VOID_TYPE: |
1e2d8575 | 1076 | case OPAQUE_TYPE: |
5566b478 | 1077 | case TYPENAME_TYPE: |
37c46b43 | 1078 | case COMPLEX_TYPE: |
c00996a3 | 1079 | case VECTOR_TYPE: |
0df4ae96 | 1080 | case TYPEOF_TYPE: |
a0d260fc | 1081 | case UNDERLYING_TYPE: |
3ad6a8e1 | 1082 | case DECLTYPE_TYPE: |
e7de2d6f | 1083 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 1084 | case FIXED_POINT_TYPE: |
1e85e720 | 1085 | case NULLPTR_TYPE: |
8d08fdba MS |
1086 | break; |
1087 | ||
1088 | default: | |
3c1ab1ab | 1089 | pp_unsupported_tree (pp, t); |
9e93bc9d NS |
1090 | case ERROR_MARK: |
1091 | /* Don't mark it here, we should have already done in | |
0cbd7506 | 1092 | dump_type_prefix. */ |
9e93bc9d | 1093 | break; |
8d08fdba MS |
1094 | } |
1095 | } | |
1096 | ||
49c249e1 | 1097 | static void |
3c1ab1ab | 1098 | dump_global_iord (cxx_pretty_printer *pp, tree t) |
8d08fdba | 1099 | { |
99885b3f | 1100 | const char *p = NULL; |
8d08fdba | 1101 | |
92643fea | 1102 | if (DECL_GLOBAL_CTOR_P (t)) |
f41c4af3 | 1103 | p = M_("(static initializers for %s)"); |
92643fea | 1104 | else if (DECL_GLOBAL_DTOR_P (t)) |
f41c4af3 | 1105 | p = M_("(static destructors for %s)"); |
8d08fdba | 1106 | else |
8dc2b103 | 1107 | gcc_unreachable (); |
bb20cc46 | 1108 | |
7c010e27 | 1109 | pp_printf (pp, p, DECL_SOURCE_FILE (t)); |
8d08fdba MS |
1110 | } |
1111 | ||
07389efe | 1112 | static void |
3c1ab1ab | 1113 | dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) |
07389efe | 1114 | { |
4be5c72c JM |
1115 | if (template_parm_object_p (t)) |
1116 | return dump_expr (pp, DECL_INITIAL (t), flags); | |
1117 | ||
761f0855 | 1118 | if (flags & TFF_DECL_SPECIFIERS) |
07389efe | 1119 | { |
91f4fc40 PP |
1120 | if (concept_definition_p (t)) |
1121 | pp_cxx_ws_string (pp, "concept"); | |
1122 | else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t)) | |
1123 | pp_cxx_ws_string (pp, "constexpr"); | |
1124 | ||
1125 | if (!standard_concept_p (t)) | |
1126 | dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME); | |
3c1ab1ab | 1127 | pp_maybe_space (pp); |
07389efe | 1128 | } |
a0ad3539 | 1129 | if (! (flags & TFF_UNQUALIFIED_NAME) |
af88c58f | 1130 | && TREE_CODE (t) != PARM_DECL |
a0ad3539 MM |
1131 | && (!DECL_INITIAL (t) |
1132 | || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)) | |
3c1ab1ab | 1133 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 1134 | flags &= ~TFF_UNQUALIFIED_NAME; |
a022041e DG |
1135 | if ((flags & TFF_DECL_SPECIFIERS) |
1136 | && DECL_TEMPLATE_PARM_P (t) | |
1137 | && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t))) | |
3c1ab1ab | 1138 | pp_string (pp, "..."); |
07389efe | 1139 | if (DECL_NAME (t)) |
af580858 | 1140 | { |
76089b28 | 1141 | if (TREE_CODE (t) == FIELD_DECL && DECL_NORMAL_CAPTURE_P (t)) |
af580858 | 1142 | { |
3c1ab1ab GDR |
1143 | pp_less (pp); |
1144 | pp_string (pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2); | |
1145 | pp_string (pp, " capture>"); | |
af580858 JM |
1146 | } |
1147 | else | |
3c1ab1ab | 1148 | dump_decl (pp, DECL_NAME (t), flags); |
af580858 | 1149 | } |
5726acd7 JM |
1150 | else if (DECL_DECOMPOSITION_P (t)) |
1151 | pp_string (pp, M_("<structured bindings>")); | |
07389efe | 1152 | else |
3c1ab1ab | 1153 | pp_string (pp, M_("<anonymous>")); |
8c60696b NS |
1154 | |
1155 | dump_module_suffix (pp, t); | |
1156 | ||
761f0855 | 1157 | if (flags & TFF_DECL_SPECIFIERS) |
3c1ab1ab | 1158 | dump_type_suffix (pp, type, flags); |
07389efe MM |
1159 | } |
1160 | ||
fd338b13 JM |
1161 | /* Print an IDENTIFIER_NODE that is the name of a declaration. */ |
1162 | ||
1163 | static void | |
1164 | dump_decl_name (cxx_pretty_printer *pp, tree t, int flags) | |
1165 | { | |
1166 | /* These special cases are duplicated here so that other functions | |
1167 | can feed identifiers to error and get them demangled properly. */ | |
84c0088f | 1168 | if (IDENTIFIER_CONV_OP_P (t)) |
fd338b13 JM |
1169 | { |
1170 | pp_cxx_ws_string (pp, "operator"); | |
1171 | /* Not exactly IDENTIFIER_TYPE_VALUE. */ | |
1172 | dump_type (pp, TREE_TYPE (t), flags); | |
1173 | return; | |
1174 | } | |
1175 | if (dguide_name_p (t)) | |
1176 | { | |
1177 | dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)), | |
a56c0ac0 | 1178 | TFF_UNQUALIFIED_NAME); |
fd338b13 JM |
1179 | return; |
1180 | } | |
1181 | ||
1182 | const char *str = IDENTIFIER_POINTER (t); | |
6ba3079d | 1183 | if (startswith (str, "_ZGR")) |
fd338b13 JM |
1184 | { |
1185 | pp_cxx_ws_string (pp, "<temporary>"); | |
1186 | return; | |
1187 | } | |
1188 | ||
1189 | pp_cxx_tree_identifier (pp, t); | |
1190 | } | |
1191 | ||
9e93bc9d NS |
1192 | /* Dump a human readable string for the decl T under control of FLAGS. */ |
1193 | ||
8d08fdba | 1194 | static void |
3c1ab1ab | 1195 | dump_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1196 | { |
1197 | if (t == NULL_TREE) | |
1198 | return; | |
1199 | ||
be8cf3b5 NP |
1200 | /* If doing Objective-C++, give Objective-C a chance to demangle |
1201 | Objective-C method names. */ | |
1202 | if (c_dialect_objc ()) | |
1203 | { | |
1204 | const char *demangled = objc_maybe_printable_name (t, flags); | |
1205 | if (demangled) | |
1206 | { | |
3c1ab1ab | 1207 | pp_string (pp, demangled); |
be8cf3b5 NP |
1208 | return; |
1209 | } | |
1210 | } | |
1211 | ||
8d08fdba MS |
1212 | switch (TREE_CODE (t)) |
1213 | { | |
7177d104 | 1214 | case TYPE_DECL: |
b54a07e8 | 1215 | /* Don't say 'typedef class A' */ |
7c8b00f9 | 1216 | if (DECL_ARTIFICIAL (t) && !DECL_SELF_REFERENCE_P (t)) |
b54a07e8 NS |
1217 | { |
1218 | if ((flags & TFF_DECL_SPECIFIERS) | |
1219 | && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM) | |
a022041e DG |
1220 | { |
1221 | /* Say `class T' not just `T'. */ | |
3c1ab1ab | 1222 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1223 | |
1224 | /* Emit the `...' for a parameter pack. */ | |
1225 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1226 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1227 | } |
c8094d83 | 1228 | |
3c1ab1ab | 1229 | dump_type (pp, TREE_TYPE (t), flags); |
b54a07e8 NS |
1230 | break; |
1231 | } | |
28704289 DS |
1232 | if (TYPE_DECL_ALIAS_P (t) |
1233 | && (flags & TFF_DECL_SPECIFIERS | |
1234 | || flags & TFF_CLASS_KEY_OR_ENUM)) | |
1235 | { | |
3c1ab1ab GDR |
1236 | pp_cxx_ws_string (pp, "using"); |
1237 | dump_decl (pp, DECL_NAME (t), flags); | |
1238 | pp_cxx_whitespace (pp); | |
1239 | pp_cxx_ws_string (pp, "="); | |
1240 | pp_cxx_whitespace (pp); | |
e7555e42 JM |
1241 | dump_type (pp, (DECL_ORIGINAL_TYPE (t) |
1242 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t)), | |
1243 | flags); | |
28704289 DS |
1244 | break; |
1245 | } | |
5a080ad7 JM |
1246 | if ((flags & TFF_DECL_SPECIFIERS) |
1247 | && !DECL_SELF_REFERENCE_P (t)) | |
3c1ab1ab GDR |
1248 | pp_cxx_ws_string (pp, "typedef"); |
1249 | dump_simple_decl (pp, t, DECL_ORIGINAL_TYPE (t) | |
9e93bc9d | 1250 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), |
0cbd7506 | 1251 | flags); |
7177d104 | 1252 | break; |
bb20cc46 | 1253 | |
8d08fdba | 1254 | case VAR_DECL: |
b7484fbe | 1255 | if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) |
8d08fdba | 1256 | { |
3c1ab1ab | 1257 | pp_string (pp, M_("vtable for ")); |
50bc768d | 1258 | gcc_assert (TYPE_P (DECL_CONTEXT (t))); |
3c1ab1ab | 1259 | dump_type (pp, DECL_CONTEXT (t), flags); |
8d08fdba MS |
1260 | break; |
1261 | } | |
191816a3 | 1262 | /* Fall through. */ |
8d08fdba MS |
1263 | case FIELD_DECL: |
1264 | case PARM_DECL: | |
3c1ab1ab | 1265 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
aed67566 JM |
1266 | |
1267 | /* Handle variable template specializations. */ | |
56a6f1d3 | 1268 | if (VAR_P (t) |
aed67566 JM |
1269 | && DECL_LANG_SPECIFIC (t) |
1270 | && DECL_TEMPLATE_INFO (t) | |
1271 | && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))) | |
1272 | { | |
1273 | pp_cxx_begin_template_argument_list (pp); | |
1274 | tree args = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t)); | |
1275 | dump_template_argument_list (pp, args, flags); | |
1276 | pp_cxx_end_template_argument_list (pp); | |
1277 | } | |
8d08fdba MS |
1278 | break; |
1279 | ||
f6a898ba | 1280 | case RESULT_DECL: |
3c1ab1ab GDR |
1281 | pp_string (pp, M_("<return value> ")); |
1282 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); | |
f6a898ba AO |
1283 | break; |
1284 | ||
a9aedbc2 | 1285 | case NAMESPACE_DECL: |
a2a9e21c | 1286 | if (flags & TFF_DECL_SPECIFIERS) |
8f0e4d72 | 1287 | pp->declaration (t); |
0c8feefe | 1288 | else |
0cbd7506 | 1289 | { |
a0ad3539 | 1290 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
3c1ab1ab | 1291 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 1292 | flags &= ~TFF_UNQUALIFIED_NAME; |
0cbd7506 | 1293 | if (DECL_NAME (t) == NULL_TREE) |
7496cd5b | 1294 | { |
3c1ab1ab GDR |
1295 | if (!(pp->flags & pp_c_flag_gnu_v3)) |
1296 | pp_cxx_ws_string (pp, M_("{anonymous}")); | |
7496cd5b | 1297 | else |
3c1ab1ab | 1298 | pp_cxx_ws_string (pp, M_("(anonymous namespace)")); |
7496cd5b | 1299 | } |
0cbd7506 | 1300 | else |
3c1ab1ab | 1301 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); |
0cbd7506 | 1302 | } |
a9aedbc2 MS |
1303 | break; |
1304 | ||
3e3f722c | 1305 | case SCOPE_REF: |
3c1ab1ab | 1306 | dump_type (pp, TREE_OPERAND (t, 0), flags); |
5256a7f5 | 1307 | pp_cxx_colon_colon (pp); |
3c1ab1ab | 1308 | dump_decl (pp, TREE_OPERAND (t, 1), TFF_UNQUALIFIED_NAME); |
bb20cc46 | 1309 | break; |
3e3f722c | 1310 | |
8d08fdba | 1311 | case ARRAY_REF: |
3c1ab1ab GDR |
1312 | dump_decl (pp, TREE_OPERAND (t, 0), flags); |
1313 | pp_cxx_left_bracket (pp); | |
1314 | dump_decl (pp, TREE_OPERAND (t, 1), flags); | |
1315 | pp_cxx_right_bracket (pp); | |
8d08fdba MS |
1316 | break; |
1317 | ||
9e93bc9d | 1318 | /* So that we can do dump_decl on an aggr type. */ |
8d08fdba MS |
1319 | case RECORD_TYPE: |
1320 | case UNION_TYPE: | |
1321 | case ENUMERAL_TYPE: | |
3c1ab1ab | 1322 | dump_type (pp, t, flags); |
8d08fdba MS |
1323 | break; |
1324 | ||
814ae570 | 1325 | case BIT_NOT_EXPR: |
82911f36 | 1326 | /* This is a pseudo destructor call which has not been folded into |
0cbd7506 | 1327 | a PSEUDO_DTOR_EXPR yet. */ |
3c1ab1ab GDR |
1328 | pp_cxx_complement (pp); |
1329 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
814ae570 GB |
1330 | break; |
1331 | ||
8d08fdba | 1332 | case TYPE_EXPR: |
8dc2b103 | 1333 | gcc_unreachable (); |
8d08fdba MS |
1334 | break; |
1335 | ||
8d08fdba | 1336 | case IDENTIFIER_NODE: |
fd338b13 | 1337 | dump_decl_name (pp, t, flags); |
8d08fdba MS |
1338 | break; |
1339 | ||
8f032717 | 1340 | case OVERLOAD: |
6f2f4050 | 1341 | if (!OVL_SINGLE_P (t)) |
65a5559b | 1342 | { |
5256a7f5 | 1343 | tree ctx = ovl_scope (t); |
6f2f4050 | 1344 | if (ctx != global_namespace) |
65a5559b | 1345 | { |
6f2f4050 NS |
1346 | if (TYPE_P (ctx)) |
1347 | dump_type (pp, ctx, flags); | |
1348 | else | |
1349 | dump_decl (pp, ctx, flags); | |
3c1ab1ab | 1350 | pp_cxx_colon_colon (pp); |
65a5559b | 1351 | } |
5256a7f5 | 1352 | dump_decl (pp, OVL_NAME (t), flags); |
65a5559b MM |
1353 | break; |
1354 | } | |
c8094d83 | 1355 | |
65a5559b MM |
1356 | /* If there's only one function, just treat it like an ordinary |
1357 | FUNCTION_DECL. */ | |
848bf88d | 1358 | t = OVL_FIRST (t); |
8f032717 MM |
1359 | /* Fall through. */ |
1360 | ||
8d08fdba | 1361 | case FUNCTION_DECL: |
2d0db225 | 1362 | if (! DECL_LANG_SPECIFIC (t)) |
8aa1cce6 | 1363 | { |
716c5ace MJ |
1364 | if (DECL_ABSTRACT_ORIGIN (t) |
1365 | && DECL_ABSTRACT_ORIGIN (t) != t) | |
8aa1cce6 RB |
1366 | dump_decl (pp, DECL_ABSTRACT_ORIGIN (t), flags); |
1367 | else | |
716c5ace | 1368 | dump_function_name (pp, t, flags); |
8aa1cce6 | 1369 | } |
2d0db225 | 1370 | else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) |
3c1ab1ab | 1371 | dump_global_iord (pp, t); |
8d08fdba | 1372 | else |
3c1ab1ab | 1373 | dump_function_decl (pp, t, flags); |
8d08fdba MS |
1374 | break; |
1375 | ||
1376 | case TEMPLATE_DECL: | |
3c1ab1ab | 1377 | dump_template_decl (pp, t, flags); |
8d08fdba MS |
1378 | break; |
1379 | ||
cb57504a | 1380 | case CONCEPT_DECL: |
91f4fc40 | 1381 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
cb57504a JM |
1382 | break; |
1383 | ||
1384 | case WILDCARD_DECL: | |
1385 | pp_string (pp, "<wildcard>"); | |
1386 | break; | |
1387 | ||
74cd8397 JM |
1388 | case TEMPLATE_ID_EXPR: |
1389 | { | |
aa36c081 | 1390 | tree name = TREE_OPERAND (t, 0); |
6c1e7aa9 | 1391 | tree args = TREE_OPERAND (t, 1); |
c8094d83 | 1392 | |
848bf88d NS |
1393 | if (!identifier_p (name)) |
1394 | name = OVL_NAME (name); | |
3c1ab1ab GDR |
1395 | dump_decl (pp, name, flags); |
1396 | pp_cxx_begin_template_argument_list (pp); | |
6c1e7aa9 | 1397 | if (args == error_mark_node) |
3c1ab1ab | 1398 | pp_string (pp, M_("<template arguments error>")); |
6c1e7aa9 | 1399 | else if (args) |
4757fa7f JM |
1400 | dump_template_argument_list |
1401 | (pp, args, flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
3c1ab1ab | 1402 | pp_cxx_end_template_argument_list (pp); |
74cd8397 JM |
1403 | } |
1404 | break; | |
1405 | ||
8d08fdba | 1406 | case LABEL_DECL: |
df0581a4 ML |
1407 | if (DECL_NAME (t)) |
1408 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); | |
1409 | else | |
d2218b04 | 1410 | dump_generic_node (pp, t, 0, TDF_SLIM, false); |
8d08fdba MS |
1411 | break; |
1412 | ||
1413 | case CONST_DECL: | |
6467930b | 1414 | if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) |
03555413 | 1415 | || (DECL_INITIAL (t) && |
f84b4be9 | 1416 | TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX)) |
3c1ab1ab | 1417 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
224c649b | 1418 | else if (DECL_NAME (t)) |
3c1ab1ab | 1419 | dump_decl (pp, DECL_NAME (t), flags); |
03555413 | 1420 | else if (DECL_INITIAL (t)) |
3c1ab1ab | 1421 | dump_expr (pp, DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS); |
03555413 | 1422 | else |
3c1ab1ab | 1423 | pp_string (pp, M_("<enumerator>")); |
8d08fdba MS |
1424 | break; |
1425 | ||
cffa8729 | 1426 | case USING_DECL: |
f4da28a0 JM |
1427 | { |
1428 | pp_cxx_ws_string (pp, "using"); | |
1429 | tree scope = USING_DECL_SCOPE (t); | |
1430 | bool variadic = false; | |
1431 | if (PACK_EXPANSION_P (scope)) | |
1432 | { | |
1433 | scope = PACK_EXPANSION_PATTERN (scope); | |
1434 | variadic = true; | |
1435 | } | |
1436 | dump_type (pp, scope, flags); | |
1437 | pp_cxx_colon_colon (pp); | |
1438 | dump_decl (pp, DECL_NAME (t), flags); | |
1439 | if (variadic) | |
1440 | pp_cxx_ws_string (pp, "..."); | |
1441 | } | |
cffa8729 MS |
1442 | break; |
1443 | ||
55a3debe | 1444 | case STATIC_ASSERT: |
8f0e4d72 | 1445 | pp->declaration (t); |
55a3debe DG |
1446 | break; |
1447 | ||
50ad9642 | 1448 | case BASELINK: |
3c1ab1ab | 1449 | dump_decl (pp, BASELINK_FUNCTIONS (t), flags); |
50ad9642 MM |
1450 | break; |
1451 | ||
d17811fd | 1452 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 1453 | dump_expr (pp, t, flags); |
d17811fd MM |
1454 | break; |
1455 | ||
bf3e8283 GDR |
1456 | case TEMPLATE_TYPE_PARM: |
1457 | if (flags & TFF_DECL_SPECIFIERS) | |
8f0e4d72 | 1458 | pp->declaration (t); |
bf3e8283 | 1459 | else |
20059c8b | 1460 | pp->type_id (t); |
bf3e8283 GDR |
1461 | break; |
1462 | ||
2658bdae | 1463 | case UNBOUND_CLASS_TEMPLATE: |
930a1e63 | 1464 | case TYPE_PACK_EXPANSION: |
06be4f56 | 1465 | case TREE_BINFO: |
3c1ab1ab | 1466 | dump_type (pp, t, flags); |
2658bdae PC |
1467 | break; |
1468 | ||
8d08fdba | 1469 | default: |
3c1ab1ab | 1470 | pp_unsupported_tree (pp, t); |
295844f6 | 1471 | /* Fall through. */ |
9e93bc9d NS |
1472 | |
1473 | case ERROR_MARK: | |
3c1ab1ab | 1474 | pp_string (pp, M_("<declaration error>")); |
9e93bc9d NS |
1475 | break; |
1476 | } | |
1477 | } | |
1478 | ||
1479 | /* Dump a template declaration T under control of FLAGS. This means the | |
1480 | 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */ | |
1481 | ||
1482 | static void | |
3c1ab1ab | 1483 | dump_template_decl (cxx_pretty_printer *pp, tree t, int flags) |
9e93bc9d | 1484 | { |
b5ac18ea MM |
1485 | tree orig_parms = DECL_TEMPLATE_PARMS (t); |
1486 | tree parms; | |
bb20cc46 AJ |
1487 | int i; |
1488 | ||
761f0855 | 1489 | if (flags & TFF_TEMPLATE_HEADER) |
9e93bc9d | 1490 | { |
bb20cc46 | 1491 | for (parms = orig_parms = nreverse (orig_parms); |
0cbd7506 MS |
1492 | parms; |
1493 | parms = TREE_CHAIN (parms)) | |
1494 | { | |
b5ac18ea | 1495 | tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms); |
0cbd7506 | 1496 | int len = TREE_VEC_LENGTH (inner_parms); |
bb20cc46 | 1497 | |
c5540945 PP |
1498 | if (len == 0) |
1499 | { | |
1500 | /* Skip over the dummy template levels of a template template | |
1501 | parm. */ | |
1502 | gcc_assert (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TEMPLATE_PARM); | |
1503 | continue; | |
1504 | } | |
1505 | ||
3c1ab1ab GDR |
1506 | pp_cxx_ws_string (pp, "template"); |
1507 | pp_cxx_begin_template_argument_list (pp); | |
38066e83 KL |
1508 | |
1509 | /* If we've shown the template prefix, we'd better show the | |
1510 | parameters' and decl's type too. */ | |
1511 | flags |= TFF_DECL_SPECIFIERS; | |
1512 | ||
0cbd7506 MS |
1513 | for (i = 0; i < len; i++) |
1514 | { | |
1515 | if (i) | |
3c1ab1ab GDR |
1516 | pp_separate_with_comma (pp); |
1517 | dump_template_parameter (pp, TREE_VEC_ELT (inner_parms, i), | |
1518 | flags); | |
0cbd7506 | 1519 | } |
3c1ab1ab GDR |
1520 | pp_cxx_end_template_argument_list (pp); |
1521 | pp_cxx_whitespace (pp); | |
0cbd7506 | 1522 | } |
b5ac18ea | 1523 | nreverse(orig_parms); |
38066e83 KL |
1524 | |
1525 | if (DECL_TEMPLATE_TEMPLATE_PARM_P (t)) | |
a022041e DG |
1526 | { |
1527 | /* Say `template<arg> class TT' not just `template<arg> TT'. */ | |
3c1ab1ab | 1528 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1529 | |
1530 | /* If this is a parameter pack, print the ellipsis. */ | |
1531 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1532 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1533 | } |
f078dc7d AS |
1534 | |
1535 | /* Only print the requirements if we're also printing | |
1536 | the template header. */ | |
1537 | if (flag_concepts) | |
1538 | if (tree ci = get_constraints (t)) | |
1539 | if (check_constraint_info (ci)) | |
1540 | if (tree reqs = CI_TEMPLATE_REQS (ci)) | |
1541 | { | |
1542 | pp_cxx_requires_clause (pp, reqs); | |
1543 | pp_cxx_whitespace (pp); | |
1544 | } | |
9e93bc9d | 1545 | } |
38066e83 | 1546 | |
971e17ff | 1547 | |
28704289 | 1548 | if (DECL_CLASS_TEMPLATE_P (t)) |
3c1ab1ab | 1549 | dump_type (pp, TREE_TYPE (t), |
0cbd7506 MS |
1550 | ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1551 | | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0))); | |
b55276c8 | 1552 | else if (DECL_TEMPLATE_RESULT (t) |
5a6ccc94 | 1553 | && (VAR_P (DECL_TEMPLATE_RESULT (t)) |
28704289 | 1554 | /* Alias template. */ |
cb57504a JM |
1555 | || DECL_TYPE_TEMPLATE_P (t) |
1556 | /* Concept definition. &*/ | |
1557 | || TREE_CODE (DECL_TEMPLATE_RESULT (t)) == CONCEPT_DECL)) | |
3c1ab1ab | 1558 | dump_decl (pp, DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME); |
9e93bc9d | 1559 | else |
9e93bc9d | 1560 | { |
8dc2b103 NS |
1561 | gcc_assert (TREE_TYPE (t)); |
1562 | switch (NEXT_CODE (t)) | |
1563 | { | |
1564 | case METHOD_TYPE: | |
1565 | case FUNCTION_TYPE: | |
3c1ab1ab | 1566 | dump_function_decl (pp, t, flags | TFF_TEMPLATE_NAME); |
8dc2b103 NS |
1567 | break; |
1568 | default: | |
1569 | /* This case can occur with some invalid code. */ | |
3c1ab1ab | 1570 | dump_type (pp, TREE_TYPE (t), |
8dc2b103 NS |
1571 | (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1572 | | (flags & TFF_DECL_SPECIFIERS | |
1573 | ? TFF_CLASS_KEY_OR_ENUM : 0)); | |
1574 | } | |
8d08fdba MS |
1575 | } |
1576 | } | |
1577 | ||
d5c8be27 | 1578 | /* find_typenames looks through the type of the function template T |
9771b263 | 1579 | and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs |
7cb4dfec | 1580 | it finds. */ |
d5c8be27 JM |
1581 | |
1582 | struct find_typenames_t | |
1583 | { | |
6e2830c3 | 1584 | hash_set<tree> *p_set; |
9771b263 | 1585 | vec<tree, va_gc> *typenames; |
d5c8be27 JM |
1586 | }; |
1587 | ||
1588 | static tree | |
ff9b4073 | 1589 | find_typenames_r (tree *tp, int *walk_subtrees, void *data) |
d5c8be27 JM |
1590 | { |
1591 | struct find_typenames_t *d = (struct find_typenames_t *)data; | |
a4d674fc JM |
1592 | tree mv = NULL_TREE; |
1593 | ||
1594 | if (TYPE_P (*tp) && is_typedef_decl (TYPE_NAME (*tp))) | |
1595 | /* Add the type of the typedef without any additional cv-quals. */ | |
1596 | mv = TREE_TYPE (TYPE_NAME (*tp)); | |
7cb4dfec JM |
1597 | else if (TREE_CODE (*tp) == TYPENAME_TYPE |
1598 | || TREE_CODE (*tp) == DECLTYPE_TYPE) | |
a4d674fc JM |
1599 | /* Add the typename without any cv-qualifiers. */ |
1600 | mv = TYPE_MAIN_VARIANT (*tp); | |
1601 | ||
e6875743 | 1602 | if (PACK_EXPANSION_P (*tp)) |
ff9b4073 JM |
1603 | { |
1604 | /* Don't mess with parameter packs since we don't remember | |
1605 | the pack expansion context for a particular typename. */ | |
1606 | *walk_subtrees = false; | |
1607 | return NULL_TREE; | |
1608 | } | |
1609 | ||
6e2830c3 | 1610 | if (mv && (mv == *tp || !d->p_set->add (mv))) |
9771b263 | 1611 | vec_safe_push (d->typenames, mv); |
d5c8be27 | 1612 | |
d5c8be27 JM |
1613 | return NULL_TREE; |
1614 | } | |
1615 | ||
9771b263 | 1616 | static vec<tree, va_gc> * |
d5c8be27 JM |
1617 | find_typenames (tree t) |
1618 | { | |
1619 | struct find_typenames_t ft; | |
6e2830c3 | 1620 | ft.p_set = new hash_set<tree>; |
d5c8be27 JM |
1621 | ft.typenames = NULL; |
1622 | cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)), | |
1623 | find_typenames_r, &ft, ft.p_set); | |
6e2830c3 | 1624 | delete ft.p_set; |
d5c8be27 JM |
1625 | return ft.typenames; |
1626 | } | |
1627 | ||
753c4989 AB |
1628 | /* Output the "[with ...]" clause for a template instantiation T iff |
1629 | TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if | |
1630 | formatting a deduction/substitution diagnostic rather than an | |
1631 | instantiation. */ | |
1632 | ||
1633 | static void | |
1634 | dump_substitution (cxx_pretty_printer *pp, | |
1635 | tree t, tree template_parms, tree template_args, | |
1636 | int flags) | |
1637 | { | |
1638 | if (template_parms != NULL_TREE && template_args != NULL_TREE | |
1639 | && !(flags & TFF_NO_TEMPLATE_BINDINGS)) | |
1640 | { | |
1641 | vec<tree, va_gc> *typenames = t ? find_typenames (t) : NULL; | |
753c4989 | 1642 | dump_template_bindings (pp, template_parms, template_args, typenames); |
753c4989 AB |
1643 | } |
1644 | } | |
1645 | ||
1646 | /* Dump the lambda function FN including its 'mutable' qualifier and any | |
1647 | template bindings. */ | |
1648 | ||
1649 | static void | |
1650 | dump_lambda_function (cxx_pretty_printer *pp, | |
1651 | tree fn, tree template_parms, tree template_args, | |
1652 | int flags) | |
1653 | { | |
1654 | /* A lambda's signature is essentially its "type". */ | |
1655 | dump_type (pp, DECL_CONTEXT (fn), flags); | |
1656 | if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST)) | |
1657 | { | |
1658 | pp->padding = pp_before; | |
1659 | pp_c_ws_string (pp, "mutable"); | |
1660 | } | |
1661 | dump_substitution (pp, fn, template_parms, template_args, flags); | |
1662 | } | |
1663 | ||
4995028c | 1664 | /* Pretty print a function decl. There are several ways we want to print a |
761f0855 | 1665 | function declaration. The TFF_ bits in FLAGS tells us how to behave. |
33bd39a2 | 1666 | As error can only apply the '#' flag once to give 0 and 1 for V, there |
c6002625 | 1667 | is %D which doesn't print the throw specs, and %F which does. */ |
8d08fdba MS |
1668 | |
1669 | static void | |
3c1ab1ab | 1670 | dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 1671 | { |
98c1c668 JM |
1672 | tree fntype; |
1673 | tree parmtypes; | |
8d08fdba | 1674 | tree cname = NULL_TREE; |
612c671a GDR |
1675 | tree template_args = NULL_TREE; |
1676 | tree template_parms = NULL_TREE; | |
761f0855 | 1677 | int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS; |
a0ad3539 | 1678 | int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME); |
4d4e036d | 1679 | tree exceptions; |
c561b091 | 1680 | bool constexpr_p; |
420db574 | 1681 | tree ret = NULL_TREE; |
d5f4eddd | 1682 | |
c33ec196 MK |
1683 | int dump_function_name_flags = flags & ~TFF_UNQUALIFIED_NAME; |
1684 | flags = dump_function_name_flags & ~TFF_TEMPLATE_NAME; | |
98c1c668 JM |
1685 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1686 | t = DECL_TEMPLATE_RESULT (t); | |
1687 | ||
4d4e036d PC |
1688 | /* Save the exceptions, in case t is a specialization and we are |
1689 | emitting an error about incompatible specifications. */ | |
1690 | exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t)); | |
1691 | ||
c561b091 | 1692 | /* Likewise for the constexpr specifier, in case t is a specialization. */ |
87c2080b JM |
1693 | constexpr_p = (DECL_DECLARED_CONSTEXPR_P (t) |
1694 | && !decl_implicit_constexpr_p (t)); | |
c561b091 | 1695 | |
612c671a | 1696 | /* Pretty print template instantiations only. */ |
6ea2bd47 | 1697 | if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t) |
98e5a19a | 1698 | && !(flags & TFF_NO_TEMPLATE_BINDINGS) |
6ea2bd47 | 1699 | && flag_pretty_templates) |
612c671a | 1700 | { |
f9a7ae04 MM |
1701 | tree tmpl; |
1702 | ||
612c671a | 1703 | template_args = DECL_TI_ARGS (t); |
f9a7ae04 MM |
1704 | tmpl = most_general_template (t); |
1705 | if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL) | |
1706 | { | |
1707 | template_parms = DECL_TEMPLATE_PARMS (tmpl); | |
1708 | t = tmpl; | |
1709 | } | |
612c671a GDR |
1710 | } |
1711 | ||
753c4989 AB |
1712 | if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) |
1713 | return dump_lambda_function (pp, t, template_parms, template_args, flags); | |
1714 | ||
98c1c668 | 1715 | fntype = TREE_TYPE (t); |
e0fff4b3 | 1716 | parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t); |
98c1c668 | 1717 | |
2642b9bf | 1718 | if (DECL_CLASS_SCOPE_P (t)) |
4f1c5b7d | 1719 | cname = DECL_CONTEXT (t); |
f4f206f4 | 1720 | /* This is for partially instantiated template methods. */ |
8d08fdba MS |
1721 | else if (TREE_CODE (fntype) == METHOD_TYPE) |
1722 | cname = TREE_TYPE (TREE_VALUE (parmtypes)); | |
1723 | ||
2842beb6 JM |
1724 | if (flags & TFF_DECL_SPECIFIERS) |
1725 | { | |
1726 | if (DECL_STATIC_FUNCTION_P (t)) | |
3c1ab1ab | 1727 | pp_cxx_ws_string (pp, "static"); |
2842beb6 | 1728 | else if (DECL_VIRTUAL_P (t)) |
3c1ab1ab | 1729 | pp_cxx_ws_string (pp, "virtual"); |
2842beb6 | 1730 | |
c561b091 | 1731 | if (constexpr_p) |
f078dc7d AS |
1732 | { |
1733 | if (DECL_DECLARED_CONCEPT_P (t)) | |
1734 | pp_cxx_ws_string (pp, "concept"); | |
f968ef9b JJ |
1735 | else if (DECL_IMMEDIATE_FUNCTION_P (t)) |
1736 | pp_cxx_ws_string (pp, "consteval"); | |
1737 | else | |
f078dc7d AS |
1738 | pp_cxx_ws_string (pp, "constexpr"); |
1739 | } | |
2842beb6 | 1740 | } |
bb20cc46 | 1741 | |
9e93bc9d NS |
1742 | /* Print the return type? */ |
1743 | if (show_return) | |
76b294d4 JM |
1744 | show_return = (!DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t) |
1745 | && !DECL_DESTRUCTOR_P (t) && !deduction_guide_p (t)); | |
9e93bc9d | 1746 | if (show_return) |
79d8a272 | 1747 | { |
420db574 | 1748 | ret = fndecl_declared_return_type (t); |
3c1ab1ab | 1749 | dump_type_prefix (pp, ret, flags); |
79d8a272 | 1750 | } |
8d08fdba | 1751 | |
61cd552e | 1752 | /* Print the function name. */ |
a0ad3539 MM |
1753 | if (!do_outer_scope) |
1754 | /* Nothing. */; | |
1755 | else if (cname) | |
8d08fdba | 1756 | { |
3c1ab1ab GDR |
1757 | dump_type (pp, cname, flags); |
1758 | pp_cxx_colon_colon (pp); | |
2642b9bf | 1759 | } |
9e93bc9d | 1760 | else |
3c1ab1ab | 1761 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
8d08fdba | 1762 | |
f78eaffd JM |
1763 | /* Name lookup for the rest of the function declarator is implicitly in the |
1764 | scope of the function, so avoid printing redundant scope qualifiers. */ | |
1765 | auto cds = make_temp_override (current_dump_scope, CP_DECL_CONTEXT (t)); | |
1766 | ||
c33ec196 | 1767 | dump_function_name (pp, t, dump_function_name_flags); |
bb20cc46 | 1768 | |
303357a7 | 1769 | if (!(flags & TFF_NO_FUNCTION_ARGUMENTS)) |
ad50e811 | 1770 | { |
3c1ab1ab | 1771 | dump_parameters (pp, parmtypes, flags); |
bb20cc46 | 1772 | |
ad50e811 | 1773 | if (TREE_CODE (fntype) == METHOD_TYPE) |
0cbd7506 | 1774 | { |
3c1ab1ab GDR |
1775 | pp->padding = pp_before; |
1776 | pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (fntype)); | |
1777 | dump_ref_qualifier (pp, fntype, flags); | |
0cbd7506 | 1778 | } |
bb20cc46 | 1779 | |
b8fd7909 JM |
1780 | if (tx_safe_fn_type_p (fntype)) |
1781 | { | |
1782 | pp->padding = pp_before; | |
1783 | pp_cxx_ws_string (pp, "transaction_safe"); | |
1784 | } | |
1785 | ||
761f0855 | 1786 | if (flags & TFF_EXCEPTION_SPECIFICATION) |
0cbd7506 | 1787 | { |
3c1ab1ab GDR |
1788 | pp->padding = pp_before; |
1789 | dump_exception_spec (pp, exceptions, flags); | |
0cbd7506 | 1790 | } |
ad6b1795 JM |
1791 | |
1792 | if (show_return) | |
420db574 | 1793 | dump_type_suffix (pp, ret, flags); |
76b294d4 JM |
1794 | else if (deduction_guide_p (t)) |
1795 | { | |
1796 | pp_cxx_ws_string (pp, "->"); | |
1797 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
1798 | } | |
612c671a | 1799 | |
971e17ff AS |
1800 | if (flag_concepts) |
1801 | if (tree ci = get_constraints (t)) | |
1802 | if (tree reqs = CI_DECLARATOR_REQS (ci)) | |
1803 | pp_cxx_requires_clause (pp, reqs); | |
1804 | ||
753c4989 | 1805 | dump_substitution (pp, t, template_parms, template_args, flags); |
31f7f784 JM |
1806 | |
1807 | if (tree base = DECL_INHERITED_CTOR_BASE (t)) | |
1808 | { | |
1809 | pp_cxx_ws_string (pp, "[inherited from"); | |
1810 | dump_type (pp, base, TFF_PLAIN_IDENTIFIER); | |
1811 | pp_character (pp, ']'); | |
1812 | } | |
21d69a5b JM |
1813 | } |
1814 | else if (template_args) | |
612c671a | 1815 | { |
21d69a5b JM |
1816 | bool need_comma = false; |
1817 | int i; | |
3c1ab1ab | 1818 | pp_cxx_begin_template_argument_list (pp); |
21d69a5b JM |
1819 | template_args = INNERMOST_TEMPLATE_ARGS (template_args); |
1820 | for (i = 0; i < TREE_VEC_LENGTH (template_args); ++i) | |
1821 | { | |
1822 | tree arg = TREE_VEC_ELT (template_args, i); | |
1823 | if (need_comma) | |
3c1ab1ab | 1824 | pp_separate_with_comma (pp); |
21d69a5b | 1825 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab GDR |
1826 | pp_cxx_left_brace (pp); |
1827 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
21d69a5b | 1828 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 1829 | pp_cxx_right_brace (pp); |
21d69a5b JM |
1830 | need_comma = true; |
1831 | } | |
3c1ab1ab | 1832 | pp_cxx_end_template_argument_list (pp); |
612c671a | 1833 | } |
4995028c NS |
1834 | } |
1835 | ||
9e93bc9d NS |
1836 | /* Print a parameter list. If this is for a member function, the |
1837 | member object ptr (and any other hidden args) should have | |
c6002625 | 1838 | already been removed. */ |
4995028c NS |
1839 | |
1840 | static void | |
3c1ab1ab | 1841 | dump_parameters (cxx_pretty_printer *pp, tree parmtypes, int flags) |
4995028c | 1842 | { |
5d80a306 | 1843 | int first = 1; |
af88c58f | 1844 | flags &= ~TFF_SCOPE; |
3c1ab1ab | 1845 | pp_cxx_left_paren (pp); |
4995028c NS |
1846 | |
1847 | for (first = 1; parmtypes != void_list_node; | |
1848 | parmtypes = TREE_CHAIN (parmtypes)) | |
1849 | { | |
1850 | if (!first) | |
3c1ab1ab | 1851 | pp_separate_with_comma (pp); |
4995028c NS |
1852 | first = 0; |
1853 | if (!parmtypes) | |
0cbd7506 | 1854 | { |
3c1ab1ab | 1855 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 MS |
1856 | break; |
1857 | } | |
31d40008 | 1858 | |
3c1ab1ab | 1859 | dump_type (pp, TREE_VALUE (parmtypes), flags); |
bb20cc46 | 1860 | |
761f0855 | 1861 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes)) |
0cbd7506 | 1862 | { |
3c1ab1ab GDR |
1863 | pp_cxx_whitespace (pp); |
1864 | pp_equal (pp); | |
1865 | pp_cxx_whitespace (pp); | |
1866 | dump_expr (pp, TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS); | |
0cbd7506 | 1867 | } |
4995028c NS |
1868 | } |
1869 | ||
3c1ab1ab | 1870 | pp_cxx_right_paren (pp); |
4995028c NS |
1871 | } |
1872 | ||
2eed8e37 BK |
1873 | /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */ |
1874 | ||
1875 | static void | |
3c1ab1ab | 1876 | dump_ref_qualifier (cxx_pretty_printer *pp, tree t, int flags ATTRIBUTE_UNUSED) |
2eed8e37 BK |
1877 | { |
1878 | if (FUNCTION_REF_QUALIFIED (t)) | |
1879 | { | |
3c1ab1ab | 1880 | pp->padding = pp_before; |
2eed8e37 | 1881 | if (FUNCTION_RVALUE_QUALIFIED (t)) |
3c1ab1ab | 1882 | pp_cxx_ws_string (pp, "&&"); |
2eed8e37 | 1883 | else |
3c1ab1ab | 1884 | pp_cxx_ws_string (pp, "&"); |
2eed8e37 BK |
1885 | } |
1886 | } | |
1887 | ||
c6002625 | 1888 | /* Print an exception specification. T is the exception specification. */ |
4995028c NS |
1889 | |
1890 | static void | |
3c1ab1ab | 1891 | dump_exception_spec (cxx_pretty_printer *pp, tree t, int flags) |
4995028c | 1892 | { |
3a55fb4c JM |
1893 | if (t && TREE_PURPOSE (t)) |
1894 | { | |
3c1ab1ab | 1895 | pp_cxx_ws_string (pp, "noexcept"); |
1a1f2bc5 JM |
1896 | if (!integer_onep (TREE_PURPOSE (t))) |
1897 | { | |
1898 | pp_cxx_whitespace (pp); | |
1899 | pp_cxx_left_paren (pp); | |
1900 | if (DEFERRED_NOEXCEPT_SPEC_P (t)) | |
1901 | pp_cxx_ws_string (pp, "<uninstantiated>"); | |
1902 | else | |
1903 | dump_expr (pp, TREE_PURPOSE (t), flags); | |
1904 | pp_cxx_right_paren (pp); | |
1905 | } | |
3a55fb4c JM |
1906 | } |
1907 | else if (t) | |
4995028c | 1908 | { |
3c1ab1ab GDR |
1909 | pp_cxx_ws_string (pp, "throw"); |
1910 | pp_cxx_whitespace (pp); | |
1911 | pp_cxx_left_paren (pp); | |
4995028c | 1912 | if (TREE_VALUE (t) != NULL_TREE) |
0cbd7506 MS |
1913 | while (1) |
1914 | { | |
3c1ab1ab | 1915 | dump_type (pp, TREE_VALUE (t), flags); |
0cbd7506 MS |
1916 | t = TREE_CHAIN (t); |
1917 | if (!t) | |
1918 | break; | |
3c1ab1ab | 1919 | pp_separate_with_comma (pp); |
0cbd7506 | 1920 | } |
3c1ab1ab | 1921 | pp_cxx_right_paren (pp); |
4995028c | 1922 | } |
8d08fdba MS |
1923 | } |
1924 | ||
1925 | /* Handle the function name for a FUNCTION_DECL node, grokking operators | |
1926 | and destructors properly. */ | |
e92cc029 | 1927 | |
8d08fdba | 1928 | static void |
3c1ab1ab | 1929 | dump_function_name (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1930 | { |
1931 | tree name = DECL_NAME (t); | |
1932 | ||
93604b1a ZW |
1933 | /* We can get here with a decl that was synthesized by language- |
1934 | independent machinery (e.g. coverage.c) in which case it won't | |
1935 | have a lang_specific structure attached and DECL_CONSTRUCTOR_P | |
1936 | will crash. In this case it is safe just to print out the | |
1937 | literal name. */ | |
1938 | if (!DECL_LANG_SPECIFIC (t)) | |
1939 | { | |
3c1ab1ab | 1940 | pp_cxx_tree_identifier (pp, name); |
93604b1a ZW |
1941 | return; |
1942 | } | |
1943 | ||
78abea27 RS |
1944 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1945 | t = DECL_TEMPLATE_RESULT (t); | |
1946 | ||
5e818b93 JM |
1947 | /* Don't let the user see __comp_ctor et al. */ |
1948 | if (DECL_CONSTRUCTOR_P (t) | |
1949 | || DECL_DESTRUCTOR_P (t)) | |
d5f4eddd JM |
1950 | { |
1951 | if (LAMBDA_TYPE_P (DECL_CONTEXT (t))) | |
1952 | name = get_identifier ("<lambda>"); | |
6a7b9203 | 1953 | else if (TYPE_UNNAMED_P (DECL_CONTEXT (t))) |
7996b727 | 1954 | name = get_identifier ("<constructor>"); |
d5f4eddd JM |
1955 | else |
1956 | name = constructor_name (DECL_CONTEXT (t)); | |
1957 | } | |
5e818b93 | 1958 | |
aa45967f | 1959 | if (DECL_DESTRUCTOR_P (t)) |
8d08fdba | 1960 | { |
3c1ab1ab GDR |
1961 | pp_cxx_complement (pp); |
1962 | dump_decl (pp, name, TFF_PLAIN_IDENTIFIER); | |
8d08fdba | 1963 | } |
aa45967f | 1964 | else if (DECL_CONV_FN_P (t)) |
8d08fdba MS |
1965 | { |
1966 | /* This cannot use the hack that the operator's return | |
1967 | type is stashed off of its name because it may be | |
1968 | used for error reporting. In the case of conflicting | |
1969 | declarations, both will have the same name, yet | |
1970 | the types will be different, hence the TREE_TYPE field | |
1971 | of the first name will be clobbered by the second. */ | |
3c1ab1ab GDR |
1972 | pp_cxx_ws_string (pp, "operator"); |
1973 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba | 1974 | } |
8d08fdba | 1975 | else |
3c1ab1ab | 1976 | dump_decl (pp, name, flags); |
386b8a85 | 1977 | |
8c60696b NS |
1978 | dump_module_suffix (pp, t); |
1979 | ||
93604b1a | 1980 | if (DECL_TEMPLATE_INFO (t) |
c33ec196 | 1981 | && !(flags & TFF_TEMPLATE_NAME) |
05fd666b | 1982 | && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t) |
f0d60e22 | 1983 | && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL |
36a117a5 | 1984 | || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))) |
3c1ab1ab GDR |
1985 | dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), |
1986 | flags); | |
9e93bc9d | 1987 | } |
75650646 | 1988 | |
9e93bc9d NS |
1989 | /* Dump the template parameters from the template info INFO under control of |
1990 | FLAGS. PRIMARY indicates whether this is a primary template decl, or | |
1991 | specialization (partial or complete). For partial specializations we show | |
1992 | the specialized parameter values. For a primary template we show no | |
1993 | decoration. */ | |
1994 | ||
1995 | static void | |
3c1ab1ab GDR |
1996 | dump_template_parms (cxx_pretty_printer *pp, tree info, |
1997 | int primary, int flags) | |
9e93bc9d NS |
1998 | { |
1999 | tree args = info ? TI_ARGS (info) : NULL_TREE; | |
bb20cc46 | 2000 | |
761f0855 | 2001 | if (primary && flags & TFF_TEMPLATE_NAME) |
9e93bc9d | 2002 | return; |
761f0855 | 2003 | flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME); |
3c1ab1ab | 2004 | pp_cxx_begin_template_argument_list (pp); |
9e93bc9d NS |
2005 | |
2006 | /* Be careful only to print things when we have them, so as not | |
8cc77ebe | 2007 | to crash producing error messages. */ |
9e93bc9d NS |
2008 | if (args && !primary) |
2009 | { | |
bf12d54d | 2010 | int len, ix; |
1a048f82 | 2011 | len = get_non_default_template_args_count (args, flags); |
bb20cc46 | 2012 | |
11d7788d | 2013 | args = INNERMOST_TEMPLATE_ARGS (args); |
bf12d54d | 2014 | for (ix = 0; ix != len; ix++) |
0cbd7506 MS |
2015 | { |
2016 | tree arg = TREE_VEC_ELT (args, ix); | |
bf12d54d | 2017 | |
5d80a306 DG |
2018 | /* Only print a comma if we know there is an argument coming. In |
2019 | the case of an empty template argument pack, no actual | |
2020 | argument will be printed. */ | |
2021 | if (ix | |
2022 | && (!ARGUMENT_PACK_P (arg) | |
2023 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 2024 | pp_separate_with_comma (pp); |
5d80a306 DG |
2025 | |
2026 | if (!arg) | |
3c1ab1ab | 2027 | pp_string (pp, M_("<template parameter error>")); |
5d80a306 | 2028 | else |
3c1ab1ab | 2029 | dump_template_argument (pp, arg, flags); |
5d80a306 | 2030 | } |
9e93bc9d | 2031 | } |
9e93bc9d NS |
2032 | else if (primary) |
2033 | { | |
2034 | tree tpl = TI_TEMPLATE (info); | |
2035 | tree parms = DECL_TEMPLATE_PARMS (tpl); | |
2036 | int len, ix; | |
bb20cc46 | 2037 | |
9e93bc9d NS |
2038 | parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE; |
2039 | len = parms ? TREE_VEC_LENGTH (parms) : 0; | |
bb20cc46 | 2040 | |
9e93bc9d | 2041 | for (ix = 0; ix != len; ix++) |
0cbd7506 | 2042 | { |
2d8ba2c7 LM |
2043 | tree parm; |
2044 | ||
2045 | if (TREE_VEC_ELT (parms, ix) == error_mark_node) | |
2046 | { | |
3c1ab1ab | 2047 | pp_string (pp, M_("<template parameter error>")); |
2d8ba2c7 LM |
2048 | continue; |
2049 | } | |
2050 | ||
2051 | parm = TREE_VALUE (TREE_VEC_ELT (parms, ix)); | |
9e93bc9d | 2052 | |
0cbd7506 | 2053 | if (ix) |
3c1ab1ab | 2054 | pp_separate_with_comma (pp); |
bb20cc46 | 2055 | |
3c1ab1ab | 2056 | dump_decl (pp, parm, flags & ~TFF_DECL_SPECIFIERS); |
0cbd7506 | 2057 | } |
386b8a85 | 2058 | } |
3c1ab1ab | 2059 | pp_cxx_end_template_argument_list (pp); |
8d08fdba MS |
2060 | } |
2061 | ||
5039610b SL |
2062 | /* Print out the arguments of CALL_EXPR T as a parenthesized list using |
2063 | flags FLAGS. Skip over the first argument if SKIPFIRST is true. */ | |
2064 | ||
2065 | static void | |
3c1ab1ab | 2066 | dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst) |
5039610b SL |
2067 | { |
2068 | tree arg; | |
2069 | call_expr_arg_iterator iter; | |
2070 | ||
3c1ab1ab | 2071 | pp_cxx_left_paren (pp); |
5039610b SL |
2072 | FOR_EACH_CALL_EXPR_ARG (arg, iter, t) |
2073 | { | |
2074 | if (skipfirst) | |
2075 | skipfirst = false; | |
2076 | else | |
2077 | { | |
3c1ab1ab | 2078 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 2079 | if (more_call_expr_args_p (&iter)) |
3c1ab1ab | 2080 | pp_separate_with_comma (pp); |
5039610b SL |
2081 | } |
2082 | } | |
3c1ab1ab | 2083 | pp_cxx_right_paren (pp); |
5039610b SL |
2084 | } |
2085 | ||
2086 | /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list | |
2087 | using flags FLAGS. Skip over the first argument if SKIPFIRST is | |
2088 | true. */ | |
2089 | ||
2090 | static void | |
3c1ab1ab GDR |
2091 | dump_aggr_init_expr_args (cxx_pretty_printer *pp, tree t, int flags, |
2092 | bool skipfirst) | |
5039610b SL |
2093 | { |
2094 | tree arg; | |
2095 | aggr_init_expr_arg_iterator iter; | |
2096 | ||
3c1ab1ab | 2097 | pp_cxx_left_paren (pp); |
5039610b SL |
2098 | FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t) |
2099 | { | |
2100 | if (skipfirst) | |
2101 | skipfirst = false; | |
2102 | else | |
2103 | { | |
3c1ab1ab | 2104 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 2105 | if (more_aggr_init_expr_args_p (&iter)) |
3c1ab1ab | 2106 | pp_separate_with_comma (pp); |
5039610b SL |
2107 | } |
2108 | } | |
3c1ab1ab | 2109 | pp_cxx_right_paren (pp); |
5039610b SL |
2110 | } |
2111 | ||
f4f206f4 | 2112 | /* Print out a list of initializers (subr of dump_expr). */ |
e92cc029 | 2113 | |
8d08fdba | 2114 | static void |
3c1ab1ab | 2115 | dump_expr_list (cxx_pretty_printer *pp, tree l, int flags) |
8d08fdba MS |
2116 | { |
2117 | while (l) | |
2118 | { | |
3c1ab1ab | 2119 | dump_expr (pp, TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS); |
8d08fdba | 2120 | l = TREE_CHAIN (l); |
9e93bc9d | 2121 | if (l) |
3c1ab1ab | 2122 | pp_separate_with_comma (pp); |
8d08fdba MS |
2123 | } |
2124 | } | |
2125 | ||
4038c495 GB |
2126 | /* Print out a vector of initializers (subr of dump_expr). */ |
2127 | ||
2128 | static void | |
3c1ab1ab GDR |
2129 | dump_expr_init_vec (cxx_pretty_printer *pp, vec<constructor_elt, va_gc> *v, |
2130 | int flags) | |
4038c495 GB |
2131 | { |
2132 | unsigned HOST_WIDE_INT idx; | |
2133 | tree value; | |
2134 | ||
2135 | FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
2136 | { | |
3c1ab1ab | 2137 | dump_expr (pp, value, flags | TFF_EXPR_IN_PARENS); |
9771b263 | 2138 | if (idx != v->length () - 1) |
3c1ab1ab | 2139 | pp_separate_with_comma (pp); |
4038c495 GB |
2140 | } |
2141 | } | |
2142 | ||
2143 | ||
7f58e7ac GDR |
2144 | /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual |
2145 | function. Resolve it to a close relative -- in the sense of static | |
2146 | type -- variant being overridden. That is close to what was written in | |
2147 | the source code. Subroutine of dump_expr. */ | |
2148 | ||
2149 | static tree | |
2150 | resolve_virtual_fun_from_obj_type_ref (tree ref) | |
2151 | { | |
2152 | tree obj_type = TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref)); | |
ae7e9ddd | 2153 | HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref)); |
7f58e7ac | 2154 | tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type))); |
c6f3d2f4 JJ |
2155 | while (index) |
2156 | { | |
7f58e7ac | 2157 | fun = TREE_CHAIN (fun); |
c6f3d2f4 JJ |
2158 | index -= (TARGET_VTABLE_USES_DESCRIPTORS |
2159 | ? TARGET_VTABLE_USES_DESCRIPTORS : 1); | |
2160 | } | |
7f58e7ac GDR |
2161 | |
2162 | return BV_FN (fun); | |
2163 | } | |
2164 | ||
c6002625 | 2165 | /* Print out an expression E under control of FLAGS. */ |
e92cc029 | 2166 | |
8d08fdba | 2167 | static void |
3c1ab1ab | 2168 | dump_expr (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 2169 | { |
a1e03bc5 JM |
2170 | tree op; |
2171 | ||
8c048a52 GDR |
2172 | if (t == 0) |
2173 | return; | |
c8094d83 | 2174 | |
10a6624a PC |
2175 | if (STATEMENT_CLASS_P (t)) |
2176 | { | |
3c1ab1ab | 2177 | pp_cxx_ws_string (pp, M_("<statement>")); |
10a6624a PC |
2178 | return; |
2179 | } | |
2180 | ||
8d08fdba MS |
2181 | switch (TREE_CODE (t)) |
2182 | { | |
2183 | case VAR_DECL: | |
2184 | case PARM_DECL: | |
2185 | case FIELD_DECL: | |
2186 | case CONST_DECL: | |
2187 | case FUNCTION_DECL: | |
ec255269 | 2188 | case TEMPLATE_DECL: |
6b57ac29 | 2189 | case NAMESPACE_DECL: |
39e837db | 2190 | case LABEL_DECL: |
cb57504a | 2191 | case WILDCARD_DECL: |
5d73aa63 | 2192 | case OVERLOAD: |
501c95ff | 2193 | case TYPE_DECL: |
a723baf1 | 2194 | case IDENTIFIER_NODE: |
3c1ab1ab GDR |
2195 | dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE |
2196 | |TFF_TEMPLATE_HEADER)) | |
98e5a19a | 2197 | | TFF_NO_TEMPLATE_BINDINGS |
3c1ab1ab | 2198 | | TFF_NO_FUNCTION_ARGUMENTS)); |
8d08fdba MS |
2199 | break; |
2200 | ||
a5952633 | 2201 | case SSA_NAME: |
70b5e7dc RG |
2202 | if (SSA_NAME_VAR (t) |
2203 | && !DECL_ARTIFICIAL (SSA_NAME_VAR (t))) | |
3c1ab1ab | 2204 | dump_expr (pp, SSA_NAME_VAR (t), flags); |
a5952633 | 2205 | else |
3c1ab1ab | 2206 | pp_cxx_ws_string (pp, M_("<unknown>")); |
a5952633 RG |
2207 | break; |
2208 | ||
632f2871 | 2209 | case VOID_CST: |
7a8380ae | 2210 | case INTEGER_CST: |
8d08fdba | 2211 | case REAL_CST: |
a176426f | 2212 | case STRING_CST: |
7368348c | 2213 | case COMPLEX_CST: |
20059c8b | 2214 | pp->constant (t); |
8d08fdba MS |
2215 | break; |
2216 | ||
3ce4f9e4 | 2217 | case USERDEF_LITERAL: |
3c1ab1ab | 2218 | pp_cxx_userdef_literal (pp, t); |
3ce4f9e4 ESR |
2219 | break; |
2220 | ||
1c09c5e5 | 2221 | case THROW_EXPR: |
d8b4270d PC |
2222 | /* While waiting for caret diagnostics, avoid printing |
2223 | __cxa_allocate_exception, __cxa_throw, and the like. */ | |
3c1ab1ab | 2224 | pp_cxx_ws_string (pp, M_("<throw-expression>")); |
1c09c5e5 GDR |
2225 | break; |
2226 | ||
61a127b3 | 2227 | case PTRMEM_CST: |
3c1ab1ab GDR |
2228 | pp_ampersand (pp); |
2229 | dump_type (pp, PTRMEM_CST_CLASS (t), flags); | |
2230 | pp_cxx_colon_colon (pp); | |
2231 | pp_cxx_tree_identifier (pp, DECL_NAME (PTRMEM_CST_MEMBER (t))); | |
61a127b3 MM |
2232 | break; |
2233 | ||
8d08fdba | 2234 | case COMPOUND_EXPR: |
3c1ab1ab GDR |
2235 | pp_cxx_left_paren (pp); |
2236 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2237 | pp_separate_with_comma (pp); | |
2238 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2239 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2240 | break; |
2241 | ||
2242 | case COND_EXPR: | |
82665822 | 2243 | case VEC_COND_EXPR: |
3c1ab1ab GDR |
2244 | pp_cxx_left_paren (pp); |
2245 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2246 | pp_string (pp, " ? "); | |
2247 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2248 | pp_string (pp, " : "); | |
2249 | dump_expr (pp, TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS); | |
2250 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2251 | break; |
2252 | ||
2253 | case SAVE_EXPR: | |
2254 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2255 | { | |
3c1ab1ab GDR |
2256 | pp_cxx_ws_string (pp, "new"); |
2257 | pp_cxx_whitespace (pp); | |
2258 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba MS |
2259 | } |
2260 | else | |
3c1ab1ab | 2261 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2262 | break; |
2263 | ||
02531345 | 2264 | case AGGR_INIT_EXPR: |
27b8d0cd MM |
2265 | { |
2266 | tree fn = NULL_TREE; | |
bb20cc46 | 2267 | |
5039610b SL |
2268 | if (TREE_CODE (AGGR_INIT_EXPR_FN (t)) == ADDR_EXPR) |
2269 | fn = TREE_OPERAND (AGGR_INIT_EXPR_FN (t), 0); | |
27b8d0cd MM |
2270 | |
2271 | if (fn && TREE_CODE (fn) == FUNCTION_DECL) | |
2272 | { | |
2273 | if (DECL_CONSTRUCTOR_P (fn)) | |
3c1ab1ab | 2274 | dump_type (pp, DECL_CONTEXT (fn), flags); |
27b8d0cd | 2275 | else |
3c1ab1ab | 2276 | dump_decl (pp, fn, 0); |
27b8d0cd MM |
2277 | } |
2278 | else | |
3c1ab1ab | 2279 | dump_expr (pp, AGGR_INIT_EXPR_FN (t), 0); |
27b8d0cd | 2280 | } |
3c1ab1ab | 2281 | dump_aggr_init_expr_args (pp, t, flags, true); |
8d08fdba MS |
2282 | break; |
2283 | ||
2284 | case CALL_EXPR: | |
2285 | { | |
5039610b SL |
2286 | tree fn = CALL_EXPR_FN (t); |
2287 | bool skipfirst = false; | |
bb20cc46 | 2288 | |
0b274c17 MP |
2289 | /* Deal with internal functions. */ |
2290 | if (fn == NULL_TREE) | |
2291 | { | |
2292 | pp_string (pp, internal_fn_name (CALL_EXPR_IFN (t))); | |
2293 | dump_call_expr_args (pp, t, flags, skipfirst); | |
2294 | break; | |
2295 | } | |
2296 | ||
8d08fdba MS |
2297 | if (TREE_CODE (fn) == ADDR_EXPR) |
2298 | fn = TREE_OPERAND (fn, 0); | |
2299 | ||
3db45ab5 MS |
2300 | /* Nobody is interested in seeing the guts of vcalls. */ |
2301 | if (TREE_CODE (fn) == OBJ_TYPE_REF) | |
2302 | fn = resolve_virtual_fun_from_obj_type_ref (fn); | |
7f58e7ac | 2303 | |
dd6f4f89 JJ |
2304 | if (TREE_TYPE (fn) != NULL_TREE |
2305 | && NEXT_CODE (fn) == METHOD_TYPE | |
2306 | && call_expr_nargs (t)) | |
8d08fdba | 2307 | { |
5039610b | 2308 | tree ob = CALL_EXPR_ARG (t, 0); |
8d08fdba MS |
2309 | if (TREE_CODE (ob) == ADDR_EXPR) |
2310 | { | |
3c1ab1ab GDR |
2311 | dump_expr (pp, TREE_OPERAND (ob, 0), |
2312 | flags | TFF_EXPR_IN_PARENS); | |
2313 | pp_cxx_dot (pp); | |
8d08fdba | 2314 | } |
c3b0f4c6 | 2315 | else if (!is_this_parameter (ob)) |
8d08fdba | 2316 | { |
3c1ab1ab GDR |
2317 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2318 | pp_cxx_arrow (pp); | |
8d08fdba | 2319 | } |
5039610b | 2320 | skipfirst = true; |
8d08fdba | 2321 | } |
de5a5fa1 MP |
2322 | if (flag_sanitize & SANITIZE_UNDEFINED |
2323 | && is_ubsan_builtin_p (fn)) | |
2324 | { | |
2325 | pp_string (cxx_pp, M_("<ubsan routine call>")); | |
2326 | break; | |
2327 | } | |
3c1ab1ab GDR |
2328 | dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS); |
2329 | dump_call_expr_args (pp, t, flags, skipfirst); | |
8d08fdba MS |
2330 | } |
2331 | break; | |
2332 | ||
8d08fdba MS |
2333 | case TARGET_EXPR: |
2334 | /* Note that this only works for G++ target exprs. If somebody | |
2335 | builds a general TARGET_EXPR, there's no way to represent that | |
2336 | it initializes anything other that the parameter slot for the | |
2337 | default argument. Note we may have cleared out the first | |
2338 | operand in expand_expr, so don't go killing ourselves. */ | |
2339 | if (TREE_OPERAND (t, 1)) | |
3c1ab1ab | 2340 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2341 | break; |
2342 | ||
d7705934 | 2343 | case POINTER_PLUS_EXPR: |
3c1ab1ab | 2344 | dump_binary_op (pp, "+", t, flags); |
d7705934 DB |
2345 | break; |
2346 | ||
1af4ebf5 MG |
2347 | case POINTER_DIFF_EXPR: |
2348 | dump_binary_op (pp, "-", t, flags); | |
2349 | break; | |
2350 | ||
b3ab27f3 | 2351 | case INIT_EXPR: |
8d08fdba | 2352 | case MODIFY_EXPR: |
88a819be | 2353 | dump_binary_op (pp, OVL_OP_INFO (true, NOP_EXPR)->name, t, flags); |
a11e05f4 JM |
2354 | break; |
2355 | ||
8d08fdba MS |
2356 | case PLUS_EXPR: |
2357 | case MINUS_EXPR: | |
2358 | case MULT_EXPR: | |
2359 | case TRUNC_DIV_EXPR: | |
2360 | case TRUNC_MOD_EXPR: | |
2361 | case MIN_EXPR: | |
2362 | case MAX_EXPR: | |
2363 | case LSHIFT_EXPR: | |
2364 | case RSHIFT_EXPR: | |
2365 | case BIT_IOR_EXPR: | |
2366 | case BIT_XOR_EXPR: | |
2367 | case BIT_AND_EXPR: | |
8d08fdba MS |
2368 | case TRUTH_ANDIF_EXPR: |
2369 | case TRUTH_ORIF_EXPR: | |
2370 | case LT_EXPR: | |
2371 | case LE_EXPR: | |
2372 | case GT_EXPR: | |
2373 | case GE_EXPR: | |
2374 | case EQ_EXPR: | |
2375 | case NE_EXPR: | |
b7689b96 | 2376 | case SPACESHIP_EXPR: |
2adeacc9 | 2377 | case EXACT_DIV_EXPR: |
88a819be | 2378 | dump_binary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags); |
8d08fdba MS |
2379 | break; |
2380 | ||
2381 | case CEIL_DIV_EXPR: | |
2382 | case FLOOR_DIV_EXPR: | |
2383 | case ROUND_DIV_EXPR: | |
ba52691c | 2384 | case RDIV_EXPR: |
3c1ab1ab | 2385 | dump_binary_op (pp, "/", t, flags); |
8d08fdba MS |
2386 | break; |
2387 | ||
2388 | case CEIL_MOD_EXPR: | |
2389 | case FLOOR_MOD_EXPR: | |
2390 | case ROUND_MOD_EXPR: | |
3c1ab1ab | 2391 | dump_binary_op (pp, "%", t, flags); |
8d08fdba MS |
2392 | break; |
2393 | ||
2394 | case COMPONENT_REF: | |
2395 | { | |
2396 | tree ob = TREE_OPERAND (t, 0); | |
591cb3cf | 2397 | if (INDIRECT_REF_P (ob)) |
8d08fdba MS |
2398 | { |
2399 | ob = TREE_OPERAND (ob, 0); | |
709718d4 JM |
2400 | if (!is_this_parameter (ob) |
2401 | && !is_dummy_object (ob)) | |
8d08fdba | 2402 | { |
3c1ab1ab | 2403 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
9f613f06 | 2404 | if (TYPE_REF_P (TREE_TYPE (ob))) |
3c1ab1ab | 2405 | pp_cxx_dot (pp); |
87fd3cf1 | 2406 | else |
3c1ab1ab | 2407 | pp_cxx_arrow (pp); |
8d08fdba MS |
2408 | } |
2409 | } | |
2410 | else | |
2411 | { | |
3c1ab1ab | 2412 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
19bdccb4 JJ |
2413 | if (TREE_CODE (ob) != ARROW_EXPR) |
2414 | pp_cxx_dot (pp); | |
8d08fdba | 2415 | } |
3c1ab1ab | 2416 | dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2417 | } |
2418 | break; | |
2419 | ||
28cbf42c | 2420 | case ARRAY_REF: |
3c1ab1ab GDR |
2421 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
2422 | pp_cxx_left_bracket (pp); | |
2423 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2424 | pp_cxx_right_bracket (pp); | |
28cbf42c MS |
2425 | break; |
2426 | ||
392e3d51 | 2427 | case UNARY_PLUS_EXPR: |
3c1ab1ab | 2428 | dump_unary_op (pp, "+", t, flags); |
8d08fdba MS |
2429 | break; |
2430 | ||
2431 | case ADDR_EXPR: | |
2432 | if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL | |
fd74ca0b MM |
2433 | || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST |
2434 | /* An ADDR_EXPR can have reference type. In that case, we | |
2435 | shouldn't print the `&' doing so indicates to the user | |
2436 | that the expression has pointer type. */ | |
bb20cc46 | 2437 | || (TREE_TYPE (t) |
9f613f06 | 2438 | && TYPE_REF_P (TREE_TYPE (t)))) |
3c1ab1ab | 2439 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
39e837db | 2440 | else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL) |
3c1ab1ab | 2441 | dump_unary_op (pp, "&&", t, flags); |
8d08fdba | 2442 | else |
3c1ab1ab | 2443 | dump_unary_op (pp, "&", t, flags); |
8d08fdba MS |
2444 | break; |
2445 | ||
2446 | case INDIRECT_REF: | |
2447 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2448 | { | |
2449 | t = TREE_OPERAND (t, 0); | |
50bc768d | 2450 | gcc_assert (TREE_CODE (t) == CALL_EXPR); |
3c1ab1ab GDR |
2451 | dump_expr (pp, CALL_EXPR_FN (t), flags | TFF_EXPR_IN_PARENS); |
2452 | dump_call_expr_args (pp, t, flags, true); | |
8d08fdba MS |
2453 | } |
2454 | else | |
2455 | { | |
6467930b | 2456 | if (TREE_OPERAND (t,0) != NULL_TREE |
5082a355 | 2457 | && TREE_TYPE (TREE_OPERAND (t, 0)) |
6467930b | 2458 | && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE) |
3c1ab1ab | 2459 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
8d08fdba | 2460 | else |
3c1ab1ab | 2461 | dump_unary_op (pp, "*", t, flags); |
8d08fdba MS |
2462 | } |
2463 | break; | |
2464 | ||
892f6119 | 2465 | case MEM_REF: |
abb1b605 MS |
2466 | /* Delegate to the base "C" pretty printer. */ |
2467 | pp->c_pretty_printer::unary_expression (t); | |
892f6119 RG |
2468 | break; |
2469 | ||
ac1c65ad JJ |
2470 | case TARGET_MEM_REF: |
2471 | /* TARGET_MEM_REF can't appear directly from source, but can appear | |
2472 | during late GIMPLE optimizations and through late diagnostic we might | |
2473 | need to support it. Print it as dereferencing of a pointer after | |
2474 | cast to the TARGET_MEM_REF type, with pointer arithmetics on some | |
2475 | pointer to single byte types, so | |
2476 | *(type *)((char *) ptr + step * index + index2) if all the operands | |
2477 | are present and the casts are needed. */ | |
2478 | pp_cxx_star (pp); | |
2479 | pp_cxx_left_paren (pp); | |
2480 | if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t)))) == NULL_TREE | |
2481 | || !integer_onep (TYPE_SIZE_UNIT | |
2482 | (TREE_TYPE (TREE_TYPE (TMR_BASE (t)))))) | |
2483 | { | |
2484 | if (TYPE_SIZE_UNIT (TREE_TYPE (t)) | |
2485 | && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t)))) | |
2486 | { | |
2487 | pp_cxx_left_paren (pp); | |
2488 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2489 | } | |
2490 | else | |
2491 | { | |
2492 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2493 | pp_cxx_right_paren (pp); | |
2494 | pp_cxx_left_paren (pp); | |
2495 | pp_cxx_left_paren (pp); | |
2496 | dump_type (pp, build_pointer_type (char_type_node), flags); | |
2497 | } | |
2498 | pp_cxx_right_paren (pp); | |
2499 | } | |
2500 | else if (!same_type_p (TREE_TYPE (t), | |
2501 | TREE_TYPE (TREE_TYPE (TMR_BASE (t))))) | |
2502 | { | |
2503 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2504 | pp_cxx_right_paren (pp); | |
2505 | pp_cxx_left_paren (pp); | |
2506 | } | |
2507 | dump_expr (pp, TMR_BASE (t), flags); | |
2508 | if (TMR_STEP (t) && TMR_INDEX (t)) | |
2509 | { | |
2510 | pp_cxx_ws_string (pp, "+"); | |
2511 | dump_expr (pp, TMR_INDEX (t), flags); | |
2512 | pp_cxx_ws_string (pp, "*"); | |
2513 | dump_expr (pp, TMR_STEP (t), flags); | |
2514 | } | |
2515 | if (TMR_INDEX2 (t)) | |
2516 | { | |
2517 | pp_cxx_ws_string (pp, "+"); | |
2518 | dump_expr (pp, TMR_INDEX2 (t), flags); | |
2519 | } | |
2520 | if (!integer_zerop (TMR_OFFSET (t))) | |
2521 | { | |
2522 | pp_cxx_ws_string (pp, "+"); | |
2523 | dump_expr (pp, fold_convert (ssizetype, TMR_OFFSET (t)), flags); | |
2524 | } | |
2525 | pp_cxx_right_paren (pp); | |
2526 | break; | |
2527 | ||
8d08fdba MS |
2528 | case NEGATE_EXPR: |
2529 | case BIT_NOT_EXPR: | |
2530 | case TRUTH_NOT_EXPR: | |
2531 | case PREDECREMENT_EXPR: | |
2532 | case PREINCREMENT_EXPR: | |
88a819be | 2533 | dump_unary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags); |
8d08fdba MS |
2534 | break; |
2535 | ||
2536 | case POSTDECREMENT_EXPR: | |
2537 | case POSTINCREMENT_EXPR: | |
3c1ab1ab GDR |
2538 | pp_cxx_left_paren (pp); |
2539 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
88a819be | 2540 | pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name); |
3c1ab1ab | 2541 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2542 | break; |
2543 | ||
2544 | case NON_LVALUE_EXPR: | |
2545 | /* FIXME: This is a KLUDGE workaround for a parsing problem. There | |
2546 | should be another level of INDIRECT_REF so that I don't have to do | |
2547 | this. */ | |
6467930b | 2548 | if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE) |
8d08fdba MS |
2549 | { |
2550 | tree next = TREE_TYPE (TREE_TYPE (t)); | |
2551 | ||
50e10fa8 | 2552 | while (TYPE_PTR_P (next)) |
8d08fdba | 2553 | next = TREE_TYPE (next); |
bb20cc46 | 2554 | |
8d08fdba MS |
2555 | if (TREE_CODE (next) == FUNCTION_TYPE) |
2556 | { | |
761f0855 | 2557 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
2558 | pp_cxx_left_paren (pp); |
2559 | pp_cxx_star (pp); | |
2560 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 2561 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2562 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2563 | break; |
2564 | } | |
f4f206f4 | 2565 | /* Else fall through. */ |
8d08fdba | 2566 | } |
3c1ab1ab | 2567 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2568 | break; |
2569 | ||
63a906f0 | 2570 | CASE_CONVERT: |
a4474a38 | 2571 | case IMPLICIT_CONV_EXPR: |
b8ce93da | 2572 | case VIEW_CONVERT_EXPR: |
ffc76561 NS |
2573 | { |
2574 | tree op = TREE_OPERAND (t, 0); | |
75d980ab JM |
2575 | tree ttype = TREE_TYPE (t); |
2576 | tree optype = TREE_TYPE (op); | |
2577 | ||
2578 | if (TREE_CODE (ttype) != TREE_CODE (optype) | |
71a93b08 PC |
2579 | && INDIRECT_TYPE_P (ttype) |
2580 | && INDIRECT_TYPE_P (optype) | |
75d980ab JM |
2581 | && same_type_p (TREE_TYPE (optype), |
2582 | TREE_TYPE (ttype))) | |
2583 | { | |
9f613f06 | 2584 | if (TYPE_REF_P (ttype)) |
e4c4792d JM |
2585 | { |
2586 | STRIP_NOPS (op); | |
2587 | if (TREE_CODE (op) == ADDR_EXPR) | |
2588 | dump_expr (pp, TREE_OPERAND (op, 0), flags); | |
2589 | else | |
2590 | dump_unary_op (pp, "*", t, flags); | |
2591 | } | |
75d980ab | 2592 | else |
3c1ab1ab | 2593 | dump_unary_op (pp, "&", t, flags); |
75d980ab JM |
2594 | } |
2595 | else if (!same_type_p (TREE_TYPE (op), TREE_TYPE (t))) | |
ffc76561 NS |
2596 | { |
2597 | /* It is a cast, but we cannot tell whether it is a | |
2598 | reinterpret or static cast. Use the C style notation. */ | |
2599 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab GDR |
2600 | pp_cxx_left_paren (pp); |
2601 | pp_cxx_left_paren (pp); | |
2602 | dump_type (pp, TREE_TYPE (t), flags); | |
2603 | pp_cxx_right_paren (pp); | |
2604 | dump_expr (pp, op, flags | TFF_EXPR_IN_PARENS); | |
ffc76561 | 2605 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2606 | pp_cxx_right_paren (pp); |
ffc76561 NS |
2607 | } |
2608 | else | |
3c1ab1ab | 2609 | dump_expr (pp, op, flags); |
ffc76561 NS |
2610 | break; |
2611 | } | |
c8094d83 | 2612 | |
8d08fdba | 2613 | case CONSTRUCTOR: |
9a3b49ac MS |
2614 | if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) |
2615 | { | |
50ad9642 | 2616 | tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier); |
9a3b49ac | 2617 | |
c4372ef4 | 2618 | if (integer_zerop (idx)) |
e08a8f45 MM |
2619 | { |
2620 | /* A NULL pointer-to-member constant. */ | |
3c1ab1ab GDR |
2621 | pp_cxx_left_paren (pp); |
2622 | pp_cxx_left_paren (pp); | |
2623 | dump_type (pp, TREE_TYPE (t), flags); | |
2624 | pp_cxx_right_paren (pp); | |
2625 | pp_character (pp, '0'); | |
2626 | pp_cxx_right_paren (pp); | |
e08a8f45 MM |
2627 | break; |
2628 | } | |
9541ffee | 2629 | else if (tree_fits_shwi_p (idx)) |
9a3b49ac MS |
2630 | { |
2631 | tree virtuals; | |
2632 | unsigned HOST_WIDE_INT n; | |
2633 | ||
2634 | t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t))); | |
2635 | t = TYPE_METHOD_BASETYPE (t); | |
604a3205 | 2636 | virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t))); |
bb20cc46 | 2637 | |
9439e9a1 | 2638 | n = tree_to_shwi (idx); |
9a3b49ac MS |
2639 | |
2640 | /* Map vtable index back one, to allow for the null pointer to | |
2641 | member. */ | |
2642 | --n; | |
2643 | ||
2644 | while (n > 0 && virtuals) | |
2645 | { | |
2646 | --n; | |
2647 | virtuals = TREE_CHAIN (virtuals); | |
2648 | } | |
2649 | if (virtuals) | |
2650 | { | |
3c1ab1ab | 2651 | dump_expr (pp, BV_FN (virtuals), |
0cbd7506 | 2652 | flags | TFF_EXPR_IN_PARENS); |
9a3b49ac MS |
2653 | break; |
2654 | } | |
2655 | } | |
2656 | } | |
539b471b | 2657 | if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t))) |
3c1ab1ab | 2658 | pp_string (pp, "<lambda closure object>"); |
4038c495 | 2659 | if (TREE_TYPE (t) && EMPTY_CONSTRUCTOR_P (t)) |
f3146d75 | 2660 | { |
3c1ab1ab GDR |
2661 | dump_type (pp, TREE_TYPE (t), 0); |
2662 | pp_cxx_left_paren (pp); | |
2663 | pp_cxx_right_paren (pp); | |
f3146d75 NS |
2664 | } |
2665 | else | |
2666 | { | |
11a36a27 | 2667 | if (!BRACE_ENCLOSED_INITIALIZER_P (t)) |
3c1ab1ab GDR |
2668 | dump_type (pp, TREE_TYPE (t), 0); |
2669 | pp_cxx_left_brace (pp); | |
2670 | dump_expr_init_vec (pp, CONSTRUCTOR_ELTS (t), flags); | |
2671 | pp_cxx_right_brace (pp); | |
f3146d75 | 2672 | } |
c8094d83 | 2673 | |
8d08fdba MS |
2674 | break; |
2675 | ||
51c184be MS |
2676 | case OFFSET_REF: |
2677 | { | |
2678 | tree ob = TREE_OPERAND (t, 0); | |
51924768 | 2679 | if (is_dummy_object (ob)) |
61a127b3 | 2680 | { |
05e0b2f4 JM |
2681 | t = TREE_OPERAND (t, 1); |
2682 | if (TREE_CODE (t) == FUNCTION_DECL) | |
61a127b3 | 2683 | /* A::f */ |
3c1ab1ab | 2684 | dump_expr (pp, t, flags | TFF_EXPR_IN_PARENS); |
05e0b2f4 | 2685 | else if (BASELINK_P (t)) |
848bf88d | 2686 | dump_expr (pp, OVL_FIRST (BASELINK_FUNCTIONS (t)), |
da15dae6 | 2687 | flags | TFF_EXPR_IN_PARENS); |
61a127b3 | 2688 | else |
3c1ab1ab | 2689 | dump_decl (pp, t, flags); |
61a127b3 | 2690 | } |
51c184be MS |
2691 | else |
2692 | { | |
591cb3cf | 2693 | if (INDIRECT_REF_P (ob)) |
bbcec105 | 2694 | { |
3c1ab1ab GDR |
2695 | dump_expr (pp, TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS); |
2696 | pp_cxx_arrow (pp); | |
2697 | pp_cxx_star (pp); | |
bbcec105 JM |
2698 | } |
2699 | else | |
2700 | { | |
3c1ab1ab GDR |
2701 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2702 | pp_cxx_dot (pp); | |
2703 | pp_cxx_star (pp); | |
bbcec105 | 2704 | } |
3c1ab1ab | 2705 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
51c184be MS |
2706 | } |
2707 | break; | |
2708 | } | |
2709 | ||
f84b4be9 | 2710 | case TEMPLATE_PARM_INDEX: |
3c1ab1ab | 2711 | dump_decl (pp, TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS); |
de22184b | 2712 | break; |
5566b478 | 2713 | |
5566b478 | 2714 | case CAST_EXPR: |
e349ee73 MS |
2715 | if (TREE_OPERAND (t, 0) == NULL_TREE |
2716 | || TREE_CHAIN (TREE_OPERAND (t, 0))) | |
e76a2646 | 2717 | { |
3c1ab1ab GDR |
2718 | dump_type (pp, TREE_TYPE (t), flags); |
2719 | pp_cxx_left_paren (pp); | |
2720 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2721 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2722 | } |
2723 | else | |
2724 | { | |
3c1ab1ab GDR |
2725 | pp_cxx_left_paren (pp); |
2726 | dump_type (pp, TREE_TYPE (t), flags); | |
2727 | pp_cxx_right_paren (pp); | |
2728 | pp_cxx_left_paren (pp); | |
2729 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2730 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2731 | } |
2732 | break; | |
2733 | ||
477f6664 | 2734 | case STATIC_CAST_EXPR: |
3c1ab1ab | 2735 | pp_cxx_ws_string (pp, "static_cast"); |
477f6664 JM |
2736 | goto cast; |
2737 | case REINTERPRET_CAST_EXPR: | |
3c1ab1ab | 2738 | pp_cxx_ws_string (pp, "reinterpret_cast"); |
477f6664 JM |
2739 | goto cast; |
2740 | case CONST_CAST_EXPR: | |
3c1ab1ab | 2741 | pp_cxx_ws_string (pp, "const_cast"); |
477f6664 JM |
2742 | goto cast; |
2743 | case DYNAMIC_CAST_EXPR: | |
3c1ab1ab | 2744 | pp_cxx_ws_string (pp, "dynamic_cast"); |
477f6664 | 2745 | cast: |
3c1ab1ab GDR |
2746 | pp_cxx_begin_template_argument_list (pp); |
2747 | dump_type (pp, TREE_TYPE (t), flags); | |
2748 | pp_cxx_end_template_argument_list (pp); | |
2749 | pp_cxx_left_paren (pp); | |
2750 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2751 | pp_cxx_right_paren (pp); | |
477f6664 JM |
2752 | break; |
2753 | ||
5a11e05b | 2754 | case ARROW_EXPR: |
3c1ab1ab GDR |
2755 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
2756 | pp_cxx_arrow (pp); | |
5a11e05b BK |
2757 | break; |
2758 | ||
e76a2646 | 2759 | case SIZEOF_EXPR: |
abff8e06 JM |
2760 | case ALIGNOF_EXPR: |
2761 | if (TREE_CODE (t) == SIZEOF_EXPR) | |
3c1ab1ab | 2762 | pp_cxx_ws_string (pp, "sizeof"); |
bb20cc46 | 2763 | else |
abff8e06 | 2764 | { |
50bc768d | 2765 | gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR); |
3c1ab1ab | 2766 | pp_cxx_ws_string (pp, "__alignof__"); |
abff8e06 | 2767 | } |
a1e03bc5 JM |
2768 | op = TREE_OPERAND (t, 0); |
2769 | if (PACK_EXPANSION_P (op)) | |
2770 | { | |
3c1ab1ab | 2771 | pp_string (pp, "..."); |
a1e03bc5 JM |
2772 | op = PACK_EXPANSION_PATTERN (op); |
2773 | } | |
3c1ab1ab GDR |
2774 | pp_cxx_whitespace (pp); |
2775 | pp_cxx_left_paren (pp); | |
0d23cf7a | 2776 | if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t)) |
3c1ab1ab | 2777 | dump_type (pp, TREE_TYPE (op), flags); |
0d23cf7a | 2778 | else if (TYPE_P (TREE_OPERAND (t, 0))) |
3c1ab1ab | 2779 | dump_type (pp, op, flags); |
e76a2646 | 2780 | else |
3c1ab1ab GDR |
2781 | dump_expr (pp, op, flags); |
2782 | pp_cxx_right_paren (pp); | |
e76a2646 | 2783 | break; |
5566b478 | 2784 | |
c154b3d8 | 2785 | case AT_ENCODE_EXPR: |
3c1ab1ab GDR |
2786 | pp_cxx_ws_string (pp, "@encode"); |
2787 | pp_cxx_whitespace (pp); | |
2788 | pp_cxx_left_paren (pp); | |
2789 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
2790 | pp_cxx_right_paren (pp); | |
c154b3d8 NP |
2791 | break; |
2792 | ||
3a55fb4c | 2793 | case NOEXCEPT_EXPR: |
3c1ab1ab GDR |
2794 | pp_cxx_ws_string (pp, "noexcept"); |
2795 | pp_cxx_whitespace (pp); | |
2796 | pp_cxx_left_paren (pp); | |
2797 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2798 | pp_cxx_right_paren (pp); | |
3a55fb4c JM |
2799 | break; |
2800 | ||
19948e32 GDR |
2801 | case REALPART_EXPR: |
2802 | case IMAGPART_EXPR: | |
88a819be | 2803 | pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name); |
3c1ab1ab GDR |
2804 | pp_cxx_whitespace (pp); |
2805 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
19948e32 GDR |
2806 | break; |
2807 | ||
7b49e3da | 2808 | case DEFERRED_PARSE: |
3c1ab1ab | 2809 | pp_string (pp, M_("<unparsed>")); |
da20811c JM |
2810 | break; |
2811 | ||
6748b643 | 2812 | case TRY_CATCH_EXPR: |
6748b643 | 2813 | case CLEANUP_POINT_EXPR: |
3c1ab1ab | 2814 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
6748b643 JM |
2815 | break; |
2816 | ||
40242ccf | 2817 | case PSEUDO_DTOR_EXPR: |
c0c66032 | 2818 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
3c1ab1ab | 2819 | pp_cxx_dot (pp); |
c0c66032 PC |
2820 | if (TREE_OPERAND (t, 1)) |
2821 | { | |
2822 | dump_type (pp, TREE_OPERAND (t, 1), flags); | |
2823 | pp_cxx_colon_colon (pp); | |
2824 | } | |
3c1ab1ab | 2825 | pp_cxx_complement (pp); |
c0c66032 | 2826 | dump_type (pp, TREE_OPERAND (t, 2), flags); |
40242ccf MM |
2827 | break; |
2828 | ||
7ac7b28f | 2829 | case TEMPLATE_ID_EXPR: |
3c1ab1ab | 2830 | dump_decl (pp, t, flags); |
7ac7b28f MM |
2831 | break; |
2832 | ||
744b12b6 | 2833 | case BIND_EXPR: |
558475f0 | 2834 | case STMT_EXPR: |
aee5c3ed | 2835 | case EXPR_STMT: |
744b12b6 | 2836 | case STATEMENT_LIST: |
558475f0 MM |
2837 | /* We don't yet have a way of dumping statements in a |
2838 | human-readable format. */ | |
3c1ab1ab | 2839 | pp_string (pp, "({...})"); |
558475f0 MM |
2840 | break; |
2841 | ||
0045e0bc | 2842 | case LOOP_EXPR: |
3c1ab1ab GDR |
2843 | pp_string (pp, "while (1) { "); |
2844 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2845 | pp_cxx_right_brace (pp); | |
0045e0bc MM |
2846 | break; |
2847 | ||
2848 | case EXIT_EXPR: | |
3c1ab1ab GDR |
2849 | pp_string (pp, "if ("); |
2850 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2851 | pp_string (pp, ") break; "); | |
0045e0bc MM |
2852 | break; |
2853 | ||
a723baf1 | 2854 | case BASELINK: |
3c1ab1ab | 2855 | dump_expr (pp, BASELINK_FUNCTIONS (t), flags & ~TFF_EXPR_IN_PARENS); |
a723baf1 MM |
2856 | break; |
2857 | ||
98ed3906 | 2858 | case EMPTY_CLASS_EXPR: |
3c1ab1ab GDR |
2859 | dump_type (pp, TREE_TYPE (t), flags); |
2860 | pp_cxx_left_paren (pp); | |
2861 | pp_cxx_right_paren (pp); | |
98ed3906 GDR |
2862 | break; |
2863 | ||
d17811fd | 2864 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 2865 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
d17811fd | 2866 | break; |
00595019 | 2867 | |
31d40008 | 2868 | case ARGUMENT_PACK_SELECT: |
3c1ab1ab | 2869 | dump_template_argument (pp, ARGUMENT_PACK_SELECT_FROM_PACK (t), flags); |
31d40008 PC |
2870 | break; |
2871 | ||
5a023baa GDR |
2872 | case RECORD_TYPE: |
2873 | case UNION_TYPE: | |
2874 | case ENUMERAL_TYPE: | |
2875 | case REAL_TYPE: | |
2876 | case VOID_TYPE: | |
1e2d8575 | 2877 | case OPAQUE_TYPE: |
5a023baa GDR |
2878 | case BOOLEAN_TYPE: |
2879 | case INTEGER_TYPE: | |
2880 | case COMPLEX_TYPE: | |
2881 | case VECTOR_TYPE: | |
06756ed9 | 2882 | case DECLTYPE_TYPE: |
3c1ab1ab | 2883 | pp_type_specifier_seq (pp, t); |
5a023baa GDR |
2884 | break; |
2885 | ||
2886 | case TYPENAME_TYPE: | |
2887 | /* We get here when we want to print a dependent type as an | |
2888 | id-expression, without any disambiguator decoration. */ | |
20059c8b | 2889 | pp->id_expression (t); |
5a023baa GDR |
2890 | break; |
2891 | ||
0a8fc247 | 2892 | case TEMPLATE_TYPE_PARM: |
fcb13a10 | 2893 | case TEMPLATE_TEMPLATE_PARM: |
0a8fc247 | 2894 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
3c1ab1ab | 2895 | dump_type (pp, t, flags); |
0a8fc247 PC |
2896 | break; |
2897 | ||
e74392f0 | 2898 | case TRAIT_EXPR: |
3c1ab1ab | 2899 | pp_cxx_trait_expression (pp, t); |
e74392f0 PC |
2900 | break; |
2901 | ||
fdb8f418 | 2902 | case VA_ARG_EXPR: |
3c1ab1ab | 2903 | pp_cxx_va_arg_expression (pp, t); |
fdb8f418 PC |
2904 | break; |
2905 | ||
094a5fe2 | 2906 | case OFFSETOF_EXPR: |
3c1ab1ab | 2907 | pp_cxx_offsetof_expression (pp, t); |
094a5fe2 JJ |
2908 | break; |
2909 | ||
be845b04 JJ |
2910 | case ADDRESSOF_EXPR: |
2911 | pp_cxx_addressof_expression (pp, t); | |
2912 | break; | |
2913 | ||
066f956c | 2914 | case SCOPE_REF: |
3c1ab1ab | 2915 | dump_decl (pp, t, flags); |
e1faa105 JM |
2916 | break; |
2917 | ||
066f956c | 2918 | case EXPR_PACK_EXPANSION: |
f078dc7d AS |
2919 | case UNARY_LEFT_FOLD_EXPR: |
2920 | case UNARY_RIGHT_FOLD_EXPR: | |
2921 | case BINARY_LEFT_FOLD_EXPR: | |
2922 | case BINARY_RIGHT_FOLD_EXPR: | |
066f956c | 2923 | case TYPEID_EXPR: |
1e3eacc7 JJ |
2924 | case MEMBER_REF: |
2925 | case DOTSTAR_EXPR: | |
a84a98ca PC |
2926 | case NEW_EXPR: |
2927 | case VEC_NEW_EXPR: | |
62081704 PC |
2928 | case DELETE_EXPR: |
2929 | case VEC_DELETE_EXPR: | |
066f956c | 2930 | case MODOP_EXPR: |
214452b9 | 2931 | case ABS_EXPR: |
e28fadbc | 2932 | case ABSU_EXPR: |
998ceda2 | 2933 | case CONJ_EXPR: |
e94384db | 2934 | case VECTOR_CST: |
998ceda2 | 2935 | case FIXED_CST: |
07874f1f JJ |
2936 | case UNORDERED_EXPR: |
2937 | case ORDERED_EXPR: | |
2938 | case UNLT_EXPR: | |
2939 | case UNLE_EXPR: | |
2940 | case UNGT_EXPR: | |
2941 | case UNGE_EXPR: | |
2942 | case UNEQ_EXPR: | |
2943 | case LTGT_EXPR: | |
66e68191 | 2944 | case COMPLEX_EXPR: |
5eddced5 | 2945 | case BIT_FIELD_REF: |
1fae3e66 PC |
2946 | case FIX_TRUNC_EXPR: |
2947 | case FLOAT_EXPR: | |
20059c8b | 2948 | pp->expression (t); |
62081704 PC |
2949 | break; |
2950 | ||
6f536f74 JJ |
2951 | case TRUTH_AND_EXPR: |
2952 | case TRUTH_OR_EXPR: | |
2953 | case TRUTH_XOR_EXPR: | |
2954 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab | 2955 | pp_cxx_left_paren (pp); |
20059c8b | 2956 | pp->expression (t); |
6f536f74 | 2957 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2958 | pp_cxx_right_paren (pp); |
6f536f74 JJ |
2959 | break; |
2960 | ||
89ab8ba0 | 2961 | case OBJ_TYPE_REF: |
3c1ab1ab | 2962 | dump_expr (pp, resolve_virtual_fun_from_obj_type_ref (t), flags); |
89ab8ba0 JJ |
2963 | break; |
2964 | ||
f030a1dc | 2965 | case LAMBDA_EXPR: |
3c1ab1ab | 2966 | pp_string (pp, M_("<lambda>")); |
f030a1dc PC |
2967 | break; |
2968 | ||
10c6dc8e | 2969 | case PAREN_EXPR: |
3c1ab1ab GDR |
2970 | pp_cxx_left_paren (pp); |
2971 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2972 | pp_cxx_right_paren (pp); | |
10c6dc8e JM |
2973 | break; |
2974 | ||
971e17ff AS |
2975 | case REQUIRES_EXPR: |
2976 | pp_cxx_requires_expr (cxx_pp, t); | |
2977 | break; | |
2978 | ||
2979 | case SIMPLE_REQ: | |
2980 | pp_cxx_simple_requirement (cxx_pp, t); | |
2981 | break; | |
2982 | ||
2983 | case TYPE_REQ: | |
2984 | pp_cxx_type_requirement (cxx_pp, t); | |
2985 | break; | |
2986 | ||
2987 | case COMPOUND_REQ: | |
2988 | pp_cxx_compound_requirement (cxx_pp, t); | |
2989 | break; | |
2990 | ||
2991 | case NESTED_REQ: | |
2992 | pp_cxx_nested_requirement (cxx_pp, t); | |
2993 | break; | |
2994 | ||
cb57504a | 2995 | case ATOMIC_CONSTR: |
f078dc7d | 2996 | case CHECK_CONSTR: |
971e17ff AS |
2997 | case CONJ_CONSTR: |
2998 | case DISJ_CONSTR: | |
cb57504a JM |
2999 | { |
3000 | pp_cxx_constraint (cxx_pp, t); | |
3001 | break; | |
3002 | } | |
971e17ff | 3003 | |
3e605b20 JM |
3004 | case PLACEHOLDER_EXPR: |
3005 | pp_string (pp, M_("*this")); | |
3006 | break; | |
3007 | ||
d6e3e8a5 MP |
3008 | case TREE_LIST: |
3009 | dump_expr_list (pp, t, flags); | |
3010 | break; | |
3011 | ||
8d08fdba MS |
3012 | /* This list is incomplete, but should suffice for now. |
3013 | It is very important that `sorry' does not call | |
3014 | `report_error_function'. That could cause an infinite loop. */ | |
3015 | default: | |
3c1ab1ab | 3016 | pp_unsupported_tree (pp, t); |
295844f6 | 3017 | /* Fall through. */ |
8d08fdba | 3018 | case ERROR_MARK: |
3c1ab1ab | 3019 | pp_string (pp, M_("<expression error>")); |
8d08fdba MS |
3020 | break; |
3021 | } | |
3022 | } | |
3023 | ||
3024 | static void | |
3c1ab1ab GDR |
3025 | dump_binary_op (cxx_pretty_printer *pp, const char *opstring, tree t, |
3026 | int flags) | |
8d08fdba | 3027 | { |
3c1ab1ab GDR |
3028 | pp_cxx_left_paren (pp); |
3029 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
3030 | pp_cxx_whitespace (pp); | |
2adeacc9 | 3031 | if (opstring) |
3c1ab1ab | 3032 | pp_cxx_ws_string (pp, opstring); |
2adeacc9 | 3033 | else |
3c1ab1ab GDR |
3034 | pp_string (pp, M_("<unknown operator>")); |
3035 | pp_cxx_whitespace (pp); | |
5094c440 JM |
3036 | tree op1 = TREE_OPERAND (t, 1); |
3037 | if (TREE_CODE (t) == POINTER_PLUS_EXPR | |
3038 | && TREE_CODE (op1) == INTEGER_CST | |
3039 | && tree_int_cst_sign_bit (op1)) | |
3040 | /* A pointer minus an integer is represented internally as plus a very | |
3041 | large number, don't expose that to users. */ | |
3042 | op1 = convert (ssizetype, op1); | |
3043 | dump_expr (pp, op1, flags | TFF_EXPR_IN_PARENS); | |
3c1ab1ab | 3044 | pp_cxx_right_paren (pp); |
8d08fdba MS |
3045 | } |
3046 | ||
3047 | static void | |
3c1ab1ab | 3048 | dump_unary_op (cxx_pretty_printer *pp, const char *opstring, tree t, int flags) |
8d08fdba | 3049 | { |
761f0855 | 3050 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
3051 | pp_cxx_left_paren (pp); |
3052 | pp_cxx_ws_string (pp, opstring); | |
3053 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 3054 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 3055 | pp_cxx_right_paren (pp); |
8d08fdba MS |
3056 | } |
3057 | ||
73bbafe5 GDR |
3058 | static void |
3059 | reinit_cxx_pp (void) | |
3060 | { | |
3061 | pp_clear_output_area (cxx_pp); | |
b066401f | 3062 | cxx_pp->padding = pp_none; |
73bbafe5 GDR |
3063 | pp_indentation (cxx_pp) = 0; |
3064 | pp_needs_newline (cxx_pp) = false; | |
d5aa2cf0 | 3065 | cxx_pp->enclosing_scope = current_function_decl; |
73bbafe5 GDR |
3066 | } |
3067 | ||
8ccb81bd GDR |
3068 | /* Same as pp_formatted_text, except the return string is a separate |
3069 | copy and has a GGC storage duration, e.g. an indefinite lifetime. */ | |
3070 | ||
3071 | inline const char * | |
3072 | pp_ggc_formatted_text (pretty_printer *pp) | |
3073 | { | |
3074 | return ggc_strdup (pp_formatted_text (pp)); | |
3075 | } | |
73bbafe5 | 3076 | |
761f0855 | 3077 | /* Exported interface to stringifying types, exprs and decls under TFF_* |
9e93bc9d | 3078 | control. */ |
4995028c | 3079 | |
e1def31b | 3080 | const char * |
3f8548e7 | 3081 | type_as_string (tree typ, int flags) |
f41c4af3 JM |
3082 | { |
3083 | reinit_cxx_pp (); | |
3084 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 3085 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 3086 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
3087 | } |
3088 | ||
3089 | const char * | |
3090 | type_as_string_translate (tree typ, int flags) | |
8d08fdba | 3091 | { |
73bbafe5 | 3092 | reinit_cxx_pp (); |
3c1ab1ab | 3093 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 3094 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3095 | } |
3096 | ||
e1def31b | 3097 | const char * |
3f8548e7 | 3098 | expr_as_string (tree decl, int flags) |
8d08fdba | 3099 | { |
73bbafe5 | 3100 | reinit_cxx_pp (); |
f41c4af3 | 3101 | pp_translate_identifiers (cxx_pp) = false; |
3c1ab1ab | 3102 | dump_expr (cxx_pp, decl, flags); |
8ccb81bd | 3103 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3104 | } |
3105 | ||
7496cd5b SA |
3106 | /* Wrap decl_as_string with options appropriate for dwarf. */ |
3107 | ||
3108 | const char * | |
3109 | decl_as_dwarf_string (tree decl, int flags) | |
3110 | { | |
3111 | const char *name; | |
3112 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
9c582551 | 3113 | here will be adequate to get the desired behavior. */ |
b066401f | 3114 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
3115 | name = decl_as_string (decl, flags); |
3116 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 3117 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
3118 | return name; |
3119 | } | |
3120 | ||
e1def31b | 3121 | const char * |
3f8548e7 | 3122 | decl_as_string (tree decl, int flags) |
f41c4af3 JM |
3123 | { |
3124 | reinit_cxx_pp (); | |
3125 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 3126 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3127 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
3128 | } |
3129 | ||
3130 | const char * | |
3131 | decl_as_string_translate (tree decl, int flags) | |
8d08fdba | 3132 | { |
73bbafe5 | 3133 | reinit_cxx_pp (); |
3c1ab1ab | 3134 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3135 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3136 | } |
3137 | ||
7496cd5b SA |
3138 | /* Wrap lang_decl_name with options appropriate for dwarf. */ |
3139 | ||
3140 | const char * | |
3141 | lang_decl_dwarf_name (tree decl, int v, bool translate) | |
3142 | { | |
3143 | const char *name; | |
3144 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
9c582551 | 3145 | here will be adequate to get the desired behavior. */ |
b066401f | 3146 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
3147 | name = lang_decl_name (decl, v, translate); |
3148 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 3149 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
3150 | return name; |
3151 | } | |
3152 | ||
7afff7cf | 3153 | /* Generate the three forms of printable names for cxx_printable_name. */ |
2ba25f50 | 3154 | |
e1def31b | 3155 | const char * |
f41c4af3 | 3156 | lang_decl_name (tree decl, int v, bool translate) |
2ba25f50 MS |
3157 | { |
3158 | if (v >= 2) | |
f41c4af3 JM |
3159 | return (translate |
3160 | ? decl_as_string_translate (decl, TFF_DECL_SPECIFIERS) | |
3161 | : decl_as_string (decl, TFF_DECL_SPECIFIERS)); | |
2ba25f50 | 3162 | |
73bbafe5 | 3163 | reinit_cxx_pp (); |
f41c4af3 | 3164 | pp_translate_identifiers (cxx_pp) = translate; |
b96fe38e DS |
3165 | if (v == 1 |
3166 | && (DECL_CLASS_SCOPE_P (decl) | |
3167 | || (DECL_NAMESPACE_SCOPE_P (decl) | |
3168 | && CP_DECL_CONTEXT (decl) != global_namespace))) | |
2ba25f50 | 3169 | { |
3c1ab1ab | 3170 | dump_type (cxx_pp, CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER); |
73bbafe5 | 3171 | pp_cxx_colon_colon (cxx_pp); |
2ba25f50 MS |
3172 | } |
3173 | ||
3174 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3c1ab1ab | 3175 | dump_function_name (cxx_pp, decl, TFF_PLAIN_IDENTIFIER); |
7496cd5b SA |
3176 | else if ((DECL_NAME (decl) == NULL_TREE) |
3177 | && TREE_CODE (decl) == NAMESPACE_DECL) | |
3c1ab1ab | 3178 | dump_decl (cxx_pp, decl, TFF_PLAIN_IDENTIFIER | TFF_UNQUALIFIED_NAME); |
2ba25f50 | 3179 | else |
3c1ab1ab | 3180 | dump_decl (cxx_pp, DECL_NAME (decl), TFF_PLAIN_IDENTIFIER); |
2ba25f50 | 3181 | |
8ccb81bd | 3182 | return pp_ggc_formatted_text (cxx_pp); |
2ba25f50 | 3183 | } |
2ba25f50 | 3184 | |
dee15844 JM |
3185 | /* Return the location of a tree passed to %+ formats. */ |
3186 | ||
501c95ff | 3187 | location_t |
9a472a42 | 3188 | location_of (tree t) |
8d08fdba | 3189 | { |
aeda100f | 3190 | if (TYPE_P (t)) |
06be4922 JM |
3191 | { |
3192 | t = TYPE_MAIN_DECL (t); | |
3193 | if (t == NULL_TREE) | |
3194 | return input_location; | |
3195 | } | |
8f032717 | 3196 | else if (TREE_CODE (t) == OVERLOAD) |
848bf88d | 3197 | t = OVL_FIRST (t); |
c8094d83 | 3198 | |
9e115cec JM |
3199 | if (DECL_P (t)) |
3200 | return DECL_SOURCE_LOCATION (t); | |
7b49e3da MP |
3201 | if (TREE_CODE (t) == DEFERRED_PARSE) |
3202 | return defparse_location (t); | |
f9d0ca40 | 3203 | return cp_expr_loc_or_input_loc (t); |
8d08fdba MS |
3204 | } |
3205 | ||
33bd39a2 | 3206 | /* Now the interfaces from error et al to dump_type et al. Each takes an |
761f0855 | 3207 | on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_ |
9e93bc9d NS |
3208 | function. */ |
3209 | ||
3210 | static const char * | |
3f8548e7 | 3211 | decl_to_string (tree decl, int verbose) |
9e93bc9d | 3212 | { |
761f0855 | 3213 | int flags = 0; |
d67cdbc3 | 3214 | |
9e93bc9d NS |
3215 | if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE |
3216 | || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE) | |
761f0855 | 3217 | flags = TFF_CLASS_KEY_OR_ENUM; |
9e93bc9d | 3218 | if (verbose) |
4a386498 | 3219 | flags |= TFF_DECL_SPECIFIERS; |
9e93bc9d | 3220 | else if (TREE_CODE (decl) == FUNCTION_DECL) |
761f0855 GDR |
3221 | flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE; |
3222 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 3223 | |
73bbafe5 | 3224 | reinit_cxx_pp (); |
3c1ab1ab | 3225 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3226 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3227 | } |
3228 | ||
7e2de6df | 3229 | const char * |
4e3f84b7 | 3230 | expr_to_string (tree decl) |
9e93bc9d | 3231 | { |
73bbafe5 | 3232 | reinit_cxx_pp (); |
3c1ab1ab | 3233 | dump_expr (cxx_pp, decl, 0); |
8ccb81bd | 3234 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3235 | } |
3236 | ||
3237 | static const char * | |
3f8548e7 | 3238 | fndecl_to_string (tree fndecl, int verbose) |
9e93bc9d | 3239 | { |
761f0855 | 3240 | int flags; |
bb20cc46 | 3241 | |
e1f0e7a6 MM |
3242 | flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS |
3243 | | TFF_TEMPLATE_HEADER; | |
9e93bc9d | 3244 | if (verbose) |
761f0855 | 3245 | flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS; |
73bbafe5 | 3246 | reinit_cxx_pp (); |
3c1ab1ab | 3247 | dump_decl (cxx_pp, fndecl, flags); |
8ccb81bd | 3248 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3249 | } |
3250 | ||
3251 | ||
3252 | static const char * | |
4e3f84b7 | 3253 | code_to_string (enum tree_code c) |
8d08fdba | 3254 | { |
5806f481 | 3255 | return get_tree_code_name (c); |
8d08fdba MS |
3256 | } |
3257 | ||
421844e7 | 3258 | const char * |
4e3f84b7 | 3259 | language_to_string (enum languages c) |
8d08fdba MS |
3260 | { |
3261 | switch (c) | |
3262 | { | |
3263 | case lang_c: | |
3264 | return "C"; | |
3265 | ||
3266 | case lang_cplusplus: | |
3267 | return "C++"; | |
3268 | ||
3269 | default: | |
8dc2b103 | 3270 | gcc_unreachable (); |
8d08fdba | 3271 | } |
6aed477a | 3272 | return NULL; |
8d08fdba MS |
3273 | } |
3274 | ||
3275 | /* Return the proper printed version of a parameter to a C++ function. */ | |
e92cc029 | 3276 | |
9e93bc9d | 3277 | static const char * |
4e3f84b7 | 3278 | parm_to_string (int p) |
8d08fdba | 3279 | { |
73bbafe5 | 3280 | reinit_cxx_pp (); |
8d08fdba | 3281 | if (p < 0) |
b6fe0bb8 | 3282 | pp_string (cxx_pp, "'this'"); |
4e3f84b7 | 3283 | else |
b6fe0bb8 | 3284 | pp_decimal_int (cxx_pp, p + 1); |
8ccb81bd | 3285 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3286 | } |
3287 | ||
9e93bc9d | 3288 | static const char * |
88a819be | 3289 | op_to_string (bool assop, enum tree_code p) |
8d08fdba | 3290 | { |
88a819be | 3291 | tree id = ovl_op_identifier (assop, p); |
f41c4af3 | 3292 | return id ? IDENTIFIER_POINTER (id) : M_("<unknown>"); |
8d08fdba MS |
3293 | } |
3294 | ||
ce95abc4 DM |
3295 | /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE. |
3296 | ||
3297 | If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the | |
3298 | string in appropriate places, and *QUOTE is written to with false | |
3299 | to suppress pp_format's trailing close quote so that e.g. | |
3300 | foo_typedef {aka underlying_foo} {enum} | |
3301 | can be printed by "%qT" as: | |
3302 | `foo_typedef' {aka `underlying_foo'} {enum} | |
3303 | rather than: | |
3304 | `foo_typedef {aka underlying_foo} {enum}' | |
3305 | When adding such quotes, if POSTPROCESSED is true (for handling %H and %I) | |
3306 | then a leading open quote will be added, whereas if POSTPROCESSED is false | |
3307 | (for handling %T) then any leading quote has already been added by | |
3308 | pp_format, or is not needed due to QUOTE being NULL (for template arguments | |
3309 | within %H and %I). | |
3310 | ||
3311 | SHOW_COLOR is used to determine the colorization of any quotes that | |
3312 | are added. */ | |
3313 | ||
9e93bc9d | 3314 | static const char * |
ce95abc4 DM |
3315 | type_to_string (tree typ, int verbose, bool postprocessed, bool *quote, |
3316 | bool show_color) | |
9e93bc9d | 3317 | { |
b6fe0bb8 | 3318 | int flags = 0; |
9e93bc9d | 3319 | if (verbose) |
761f0855 GDR |
3320 | flags |= TFF_CLASS_KEY_OR_ENUM; |
3321 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 3322 | |
73bbafe5 | 3323 | reinit_cxx_pp (); |
ce95abc4 DM |
3324 | |
3325 | if (postprocessed && quote && *quote) | |
3326 | pp_begin_quote (cxx_pp, show_color); | |
3327 | ||
3328 | struct obstack *ob = pp_buffer (cxx_pp)->obstack; | |
3329 | int type_start, type_len; | |
3330 | type_start = obstack_object_size (ob); | |
3331 | ||
3c1ab1ab | 3332 | dump_type (cxx_pp, typ, flags); |
ce95abc4 DM |
3333 | |
3334 | /* Remember the end of the initial dump. */ | |
3335 | type_len = obstack_object_size (ob) - type_start; | |
3336 | ||
0d3128d6 JM |
3337 | /* If we're printing a type that involves typedefs, also print the |
3338 | stripped version. But sometimes the stripped version looks | |
3339 | exactly the same, so we don't want it after all. To avoid printing | |
3340 | it in that case, we play ugly obstack games. */ | |
8722cdee JM |
3341 | if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ) |
3342 | && !uses_template_parms (typ)) | |
3343 | { | |
045af2d7 | 3344 | int aka_start, aka_len; char *p; |
10bce48f | 3345 | tree aka = strip_typedefs (typ, NULL, STF_USER_VISIBLE); |
ce95abc4 DM |
3346 | if (quote && *quote) |
3347 | pp_end_quote (cxx_pp, show_color); | |
8722cdee JM |
3348 | pp_string (cxx_pp, " {aka"); |
3349 | pp_cxx_whitespace (cxx_pp); | |
ce95abc4 DM |
3350 | if (quote && *quote) |
3351 | pp_begin_quote (cxx_pp, show_color); | |
0d3128d6 JM |
3352 | /* And remember the start of the aka dump. */ |
3353 | aka_start = obstack_object_size (ob); | |
3c1ab1ab | 3354 | dump_type (cxx_pp, aka, flags); |
045af2d7 | 3355 | aka_len = obstack_object_size (ob) - aka_start; |
ce95abc4 DM |
3356 | if (quote && *quote) |
3357 | pp_end_quote (cxx_pp, show_color); | |
07838b13 | 3358 | pp_right_brace (cxx_pp); |
0d3128d6 | 3359 | p = (char*)obstack_base (ob); |
ce95abc4 DM |
3360 | /* If they are identical, cut off the aka by unwinding the obstack. */ |
3361 | if (type_len == aka_len | |
3362 | && memcmp (p + type_start, p+aka_start, type_len) == 0) | |
3363 | { | |
3364 | /* We can't add a '\0' here, since we may be adding a closing quote | |
3365 | below, and it would be hidden by the '\0'. | |
3366 | Instead, manually unwind the current object within the obstack | |
3367 | so that the insertion point is at the end of the type, before | |
3368 | the "' {aka". */ | |
3369 | int delta = type_start + type_len - obstack_object_size (ob); | |
3370 | gcc_assert (delta <= 0); | |
3371 | obstack_blank_fast (ob, delta); | |
3372 | } | |
3373 | else | |
3374 | if (quote) | |
3375 | /* No further closing quotes are needed. */ | |
3376 | *quote = false; | |
3377 | } | |
3378 | ||
3379 | if (quote && *quote) | |
3380 | { | |
3381 | pp_end_quote (cxx_pp, show_color); | |
3382 | *quote = false; | |
8722cdee | 3383 | } |
8ccb81bd | 3384 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3385 | } |
3386 | ||
9e93bc9d | 3387 | static const char * |
3f8548e7 | 3388 | args_to_string (tree p, int verbose) |
8d08fdba | 3389 | { |
761f0855 | 3390 | int flags = 0; |
9e93bc9d | 3391 | if (verbose) |
761f0855 | 3392 | flags |= TFF_CLASS_KEY_OR_ENUM; |
bb20cc46 | 3393 | |
8d08fdba | 3394 | if (p == NULL_TREE) |
c73964b2 | 3395 | return ""; |
8d08fdba | 3396 | |
2f939d94 | 3397 | if (TYPE_P (TREE_VALUE (p))) |
f41c4af3 | 3398 | return type_as_string_translate (p, flags); |
c73964b2 | 3399 | |
73bbafe5 | 3400 | reinit_cxx_pp (); |
c73964b2 MS |
3401 | for (; p; p = TREE_CHAIN (p)) |
3402 | { | |
9a004410 | 3403 | if (null_node_p (TREE_VALUE (p))) |
b02cec6e | 3404 | pp_cxx_ws_string (cxx_pp, "NULL"); |
a6967cc0 | 3405 | else |
3c1ab1ab | 3406 | dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags); |
c73964b2 | 3407 | if (TREE_CHAIN (p)) |
b6fe0bb8 | 3408 | pp_separate_with_comma (cxx_pp); |
c73964b2 | 3409 | } |
8ccb81bd | 3410 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba | 3411 | } |
f30432d7 | 3412 | |
3ff60975 JM |
3413 | /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P |
3414 | is a TREE_LIST with purpose the TEMPLATE_DECL, value the template | |
3415 | arguments. */ | |
3416 | ||
3417 | static const char * | |
3418 | subst_to_string (tree p) | |
3419 | { | |
3420 | tree decl = TREE_PURPOSE (p); | |
3421 | tree targs = TREE_VALUE (p); | |
3422 | tree tparms = DECL_TEMPLATE_PARMS (decl); | |
3579964b JM |
3423 | int flags = (TFF_DECL_SPECIFIERS|TFF_TEMPLATE_HEADER |
3424 | |TFF_NO_TEMPLATE_BINDINGS); | |
3ff60975 JM |
3425 | |
3426 | if (p == NULL_TREE) | |
3427 | return ""; | |
3428 | ||
3429 | reinit_cxx_pp (); | |
3c1ab1ab | 3430 | dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags); |
753c4989 | 3431 | dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0); |
8ccb81bd | 3432 | return pp_ggc_formatted_text (cxx_pp); |
3ff60975 JM |
3433 | } |
3434 | ||
9e93bc9d | 3435 | static const char * |
3f8548e7 | 3436 | cv_to_string (tree p, int v) |
f30432d7 | 3437 | { |
73bbafe5 | 3438 | reinit_cxx_pp (); |
b066401f | 3439 | cxx_pp->padding = v ? pp_before : pp_none; |
b9b44fb9 | 3440 | pp_cxx_cv_qualifier_seq (cxx_pp, p); |
8ccb81bd | 3441 | return pp_ggc_formatted_text (cxx_pp); |
f30432d7 | 3442 | } |
cb753e49 | 3443 | |
3f04b1bb JM |
3444 | static const char * |
3445 | eh_spec_to_string (tree p, int /*v*/) | |
3446 | { | |
3447 | int flags = 0; | |
3448 | reinit_cxx_pp (); | |
3449 | dump_exception_spec (cxx_pp, p, flags); | |
3450 | return pp_ggc_formatted_text (cxx_pp); | |
3451 | } | |
3452 | ||
7cb32822 NB |
3453 | /* Langhook for print_error_function. */ |
3454 | void | |
c94ed7a1 JJ |
3455 | cxx_print_error_function (diagnostic_context *context, const char *file, |
3456 | diagnostic_info *diagnostic) | |
a72462a4 | 3457 | { |
653fee19 DM |
3458 | char *prefix; |
3459 | if (file) | |
3460 | prefix = xstrdup (file); | |
3461 | else | |
3462 | prefix = NULL; | |
c94ed7a1 | 3463 | lhd_print_error_function (context, file, diagnostic); |
653fee19 | 3464 | pp_set_prefix (context->printer, prefix); |
47b69537 | 3465 | maybe_print_instantiation_context (context); |
a72462a4 GDR |
3466 | } |
3467 | ||
cb753e49 | 3468 | static void |
3f8548e7 | 3469 | cp_diagnostic_starter (diagnostic_context *context, |
0cbd7506 | 3470 | diagnostic_info *diagnostic) |
cb753e49 | 3471 | { |
2a2703a2 | 3472 | diagnostic_report_current_module (context, diagnostic_location (diagnostic)); |
47b69537 GDR |
3473 | cp_print_error_function (context, diagnostic); |
3474 | maybe_print_instantiation_context (context); | |
2bfe0527 | 3475 | maybe_print_constexpr_context (context); |
cb57504a | 3476 | maybe_print_constraint_context (context); |
b066401f | 3477 | pp_set_prefix (context->printer, diagnostic_build_prefix (context, |
243fbddd | 3478 | diagnostic)); |
cb753e49 GDR |
3479 | } |
3480 | ||
cb753e49 GDR |
3481 | /* Print current function onto BUFFER, in the process of reporting |
3482 | a diagnostic message. Called from cp_diagnostic_starter. */ | |
3483 | static void | |
3f8548e7 | 3484 | cp_print_error_function (diagnostic_context *context, |
0cbd7506 | 3485 | diagnostic_info *diagnostic) |
cb753e49 | 3486 | { |
6573e8a0 JM |
3487 | /* If we are in an instantiation context, current_function_decl is likely |
3488 | to be wrong, so just rely on print_instantiation_full_context. */ | |
3489 | if (current_instantiation ()) | |
3490 | return; | |
1906392b AS |
3491 | /* The above is true for constraint satisfaction also. */ |
3492 | if (current_failed_constraint) | |
3493 | return; | |
c94ed7a1 | 3494 | if (diagnostic_last_function_changed (context, diagnostic)) |
cb753e49 | 3495 | { |
653fee19 | 3496 | char *old_prefix = pp_take_prefix (context->printer); |
2a2703a2 | 3497 | const char *file = LOCATION_FILE (diagnostic_location (diagnostic)); |
cf835838 | 3498 | tree abstract_origin = diagnostic_abstract_origin (diagnostic); |
c94ed7a1 | 3499 | char *new_prefix = (file && abstract_origin == NULL) |
e78e8a0b | 3500 | ? file_name_as_prefix (context, file) : NULL; |
cb753e49 | 3501 | |
b066401f | 3502 | pp_set_prefix (context->printer, new_prefix); |
bb20cc46 | 3503 | |
cb753e49 | 3504 | if (current_function_decl == NULL) |
b066401f | 3505 | pp_string (context->printer, _("At global scope:")); |
cb753e49 | 3506 | else |
c94ed7a1 JJ |
3507 | { |
3508 | tree fndecl, ao; | |
3509 | ||
3510 | if (abstract_origin) | |
3511 | { | |
3512 | ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin); | |
c94ed7a1 JJ |
3513 | gcc_assert (TREE_CODE (ao) == FUNCTION_DECL); |
3514 | fndecl = ao; | |
3515 | } | |
3516 | else | |
3517 | fndecl = current_function_decl; | |
3518 | ||
b02cec6e | 3519 | pp_printf (context->printer, function_category (fndecl), |
f41c4af3 | 3520 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3521 | |
3522 | while (abstract_origin) | |
3523 | { | |
3524 | location_t *locus; | |
3525 | tree block = abstract_origin; | |
3526 | ||
3527 | locus = &BLOCK_SOURCE_LOCATION (block); | |
3528 | fndecl = NULL; | |
3529 | block = BLOCK_SUPERCONTEXT (block); | |
3530 | while (block && TREE_CODE (block) == BLOCK | |
3531 | && BLOCK_ABSTRACT_ORIGIN (block)) | |
3532 | { | |
3533 | ao = BLOCK_ABSTRACT_ORIGIN (block); | |
c94ed7a1 JJ |
3534 | if (TREE_CODE (ao) == FUNCTION_DECL) |
3535 | { | |
3536 | fndecl = ao; | |
3537 | break; | |
3538 | } | |
3539 | else if (TREE_CODE (ao) != BLOCK) | |
3540 | break; | |
3541 | ||
3542 | block = BLOCK_SUPERCONTEXT (block); | |
3543 | } | |
3544 | if (fndecl) | |
3545 | abstract_origin = block; | |
3546 | else | |
3547 | { | |
3548 | while (block && TREE_CODE (block) == BLOCK) | |
3549 | block = BLOCK_SUPERCONTEXT (block); | |
3550 | ||
9304142e | 3551 | if (block && TREE_CODE (block) == FUNCTION_DECL) |
c94ed7a1 JJ |
3552 | fndecl = block; |
3553 | abstract_origin = NULL; | |
3554 | } | |
3555 | if (fndecl) | |
3556 | { | |
3557 | expanded_location s = expand_location (*locus); | |
b066401f GDR |
3558 | pp_character (context->printer, ','); |
3559 | pp_newline (context->printer); | |
c94ed7a1 JJ |
3560 | if (s.file != NULL) |
3561 | { | |
243fbddd | 3562 | if (context->show_column && s.column != 0) |
c94ed7a1 | 3563 | pp_printf (context->printer, |
4b84d650 | 3564 | _(" inlined from %qs at %r%s:%d:%d%R"), |
f41c4af3 | 3565 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3566 | "locus", s.file, s.line, s.column); |
c94ed7a1 | 3567 | else |
c94ed7a1 | 3568 | pp_printf (context->printer, |
4b84d650 | 3569 | _(" inlined from %qs at %r%s:%d%R"), |
f41c4af3 | 3570 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3571 | "locus", s.file, s.line); |
c94ed7a1 JJ |
3572 | |
3573 | } | |
3574 | else | |
b02cec6e | 3575 | pp_printf (context->printer, _(" inlined from %qs"), |
f41c4af3 | 3576 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3577 | } |
3578 | } | |
b066401f | 3579 | pp_character (context->printer, ':'); |
c94ed7a1 | 3580 | } |
b066401f | 3581 | pp_newline (context->printer); |
47b69537 | 3582 | |
c94ed7a1 | 3583 | diagnostic_set_last_function (context, diagnostic); |
b066401f | 3584 | pp_destroy_prefix (context->printer); |
b6fe0bb8 | 3585 | context->printer->prefix = old_prefix; |
cb753e49 GDR |
3586 | } |
3587 | } | |
3588 | ||
b02cec6e JM |
3589 | /* Returns a description of FUNCTION using standard terminology. The |
3590 | result is a format string of the form "In CATEGORY %qs". */ | |
cb753e49 | 3591 | static const char * |
3f8548e7 | 3592 | function_category (tree fn) |
cb753e49 | 3593 | { |
a406865a RG |
3594 | /* We can get called from the middle-end for diagnostics of function |
3595 | clones. Make sure we have language specific information before | |
3596 | dereferencing it. */ | |
3597 | if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn)) | |
3598 | && DECL_FUNCTION_MEMBER_P (fn)) | |
cb753e49 GDR |
3599 | { |
3600 | if (DECL_STATIC_FUNCTION_P (fn)) | |
b02cec6e | 3601 | return _("In static member function %qs"); |
cb753e49 | 3602 | else if (DECL_COPY_CONSTRUCTOR_P (fn)) |
b02cec6e | 3603 | return _("In copy constructor %qs"); |
cb753e49 | 3604 | else if (DECL_CONSTRUCTOR_P (fn)) |
b02cec6e | 3605 | return _("In constructor %qs"); |
cb753e49 | 3606 | else if (DECL_DESTRUCTOR_P (fn)) |
b02cec6e | 3607 | return _("In destructor %qs"); |
d5f4eddd JM |
3608 | else if (LAMBDA_FUNCTION_P (fn)) |
3609 | return _("In lambda function"); | |
cb753e49 | 3610 | else |
b02cec6e | 3611 | return _("In member function %qs"); |
cb753e49 GDR |
3612 | } |
3613 | else | |
b02cec6e | 3614 | return _("In function %qs"); |
cb753e49 GDR |
3615 | } |
3616 | ||
ca23341b MS |
3617 | /* Disable warnings about missing quoting in GCC diagnostics for |
3618 | the pp_verbatim calls. Their format strings deliberately don't | |
3619 | follow GCC diagnostic conventions. */ | |
3620 | #if __GNUC__ >= 10 | |
3621 | # pragma GCC diagnostic push | |
3622 | # pragma GCC diagnostic ignored "-Wformat-diag" | |
3623 | #endif | |
3624 | ||
cb753e49 GDR |
3625 | /* Report the full context of a current template instantiation, |
3626 | onto BUFFER. */ | |
3627 | static void | |
3f8548e7 | 3628 | print_instantiation_full_context (diagnostic_context *context) |
cb753e49 | 3629 | { |
e2c3721c | 3630 | struct tinst_level *p = current_instantiation (); |
82a98427 | 3631 | location_t location = input_location; |
c8094d83 | 3632 | |
cb753e49 GDR |
3633 | if (p) |
3634 | { | |
6573e8a0 | 3635 | pp_verbatim (context->printer, |
a56e2f69 | 3636 | p->list_p () |
6573e8a0 JM |
3637 | ? _("%s: In substitution of %qS:\n") |
3638 | : _("%s: In instantiation of %q#D:\n"), | |
3639 | LOCATION_FILE (location), | |
a56e2f69 | 3640 | p->get_node ()); |
6573e8a0 JM |
3641 | |
3642 | location = p->locus; | |
3643 | p = p->next; | |
cb753e49 | 3644 | } |
bb20cc46 | 3645 | |
35773471 | 3646 | print_instantiation_partial_context (context, p, location); |
cb753e49 GDR |
3647 | } |
3648 | ||
f89b94d9 MLI |
3649 | /* Helper function of print_instantiation_partial_context() that |
3650 | prints a single line of instantiation context. */ | |
3651 | ||
cb753e49 | 3652 | static void |
f89b94d9 | 3653 | print_instantiation_partial_context_line (diagnostic_context *context, |
a56e2f69 | 3654 | struct tinst_level *t, |
4b414c93 | 3655 | location_t loc, bool recursive_p) |
cb753e49 | 3656 | { |
4f90d3e0 JH |
3657 | if (loc == UNKNOWN_LOCATION) |
3658 | return; | |
3659 | ||
3660 | expanded_location xloc = expand_location (loc); | |
f89b94d9 | 3661 | |
3ff60975 | 3662 | if (context->show_column) |
4b84d650 JJ |
3663 | pp_verbatim (context->printer, _("%r%s:%d:%d:%R "), |
3664 | "locus", xloc.file, xloc.line, xloc.column); | |
3ff60975 | 3665 | else |
4b84d650 JJ |
3666 | pp_verbatim (context->printer, _("%r%s:%d:%R "), |
3667 | "locus", xloc.file, xloc.line); | |
3ff60975 JM |
3668 | |
3669 | if (t != NULL) | |
4b414c93 | 3670 | { |
a56e2f69 | 3671 | if (t->list_p ()) |
4b414c93 MLI |
3672 | pp_verbatim (context->printer, |
3673 | recursive_p | |
3ff60975 JM |
3674 | ? _("recursively required by substitution of %qS\n") |
3675 | : _("required by substitution of %qS\n"), | |
a56e2f69 | 3676 | t->get_node ()); |
4b414c93 MLI |
3677 | else |
3678 | pp_verbatim (context->printer, | |
3679 | recursive_p | |
3ff60975 JM |
3680 | ? _("recursively required from %q#D\n") |
3681 | : _("required from %q#D\n"), | |
a56e2f69 | 3682 | t->get_node ()); |
4b414c93 MLI |
3683 | } |
3684 | else | |
3685 | { | |
3ff60975 JM |
3686 | pp_verbatim (context->printer, |
3687 | recursive_p | |
01e1dea3 DM |
3688 | ? _("recursively required from here\n") |
3689 | : _("required from here\n")); | |
4b414c93 | 3690 | } |
f89b94d9 MLI |
3691 | } |
3692 | ||
3693 | /* Same as print_instantiation_full_context but less verbose. */ | |
3694 | ||
3695 | static void | |
3696 | print_instantiation_partial_context (diagnostic_context *context, | |
3697 | struct tinst_level *t0, location_t loc) | |
3698 | { | |
3699 | struct tinst_level *t; | |
3700 | int n_total = 0; | |
3701 | int n; | |
4b414c93 | 3702 | location_t prev_loc = loc; |
f89b94d9 MLI |
3703 | |
3704 | for (t = t0; t != NULL; t = t->next) | |
4b414c93 MLI |
3705 | if (prev_loc != t->locus) |
3706 | { | |
3707 | prev_loc = t->locus; | |
3708 | n_total++; | |
3709 | } | |
f89b94d9 MLI |
3710 | |
3711 | t = t0; | |
3712 | ||
a12bf402 MLI |
3713 | if (template_backtrace_limit |
3714 | && n_total > template_backtrace_limit) | |
cb753e49 | 3715 | { |
a12bf402 MLI |
3716 | int skip = n_total - template_backtrace_limit; |
3717 | int head = template_backtrace_limit / 2; | |
3718 | ||
3719 | /* Avoid skipping just 1. If so, skip 2. */ | |
3720 | if (skip == 1) | |
3721 | { | |
3722 | skip = 2; | |
3723 | head = (template_backtrace_limit - 1) / 2; | |
3724 | } | |
3725 | ||
3726 | for (n = 0; n < head; n++) | |
f89b94d9 MLI |
3727 | { |
3728 | gcc_assert (t != NULL); | |
4b414c93 MLI |
3729 | if (loc != t->locus) |
3730 | print_instantiation_partial_context_line (context, t, loc, | |
3731 | /*recursive_p=*/false); | |
f89b94d9 MLI |
3732 | loc = t->locus; |
3733 | t = t->next; | |
3734 | } | |
a12bf402 | 3735 | if (t != NULL && skip > 0) |
f89b94d9 MLI |
3736 | { |
3737 | expanded_location xloc; | |
3738 | xloc = expand_location (loc); | |
243fbddd | 3739 | if (context->show_column) |
f89b94d9 | 3740 | pp_verbatim (context->printer, |
4b84d650 JJ |
3741 | _("%r%s:%d:%d:%R [ skipping %d instantiation " |
3742 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3743 | "disable ]\n"), | |
3744 | "locus", xloc.file, xloc.line, xloc.column, skip); | |
f89b94d9 MLI |
3745 | else |
3746 | pp_verbatim (context->printer, | |
4b84d650 JJ |
3747 | _("%r%s:%d:%R [ skipping %d instantiation " |
3748 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3749 | "disable ]\n"), | |
3750 | "locus", xloc.file, xloc.line, skip); | |
f89b94d9 MLI |
3751 | |
3752 | do { | |
4b414c93 MLI |
3753 | loc = t->locus; |
3754 | t = t->next; | |
3755 | } while (t != NULL && --skip > 0); | |
f89b94d9 MLI |
3756 | } |
3757 | } | |
3758 | ||
4b414c93 | 3759 | while (t != NULL) |
f89b94d9 | 3760 | { |
4b414c93 MLI |
3761 | while (t->next != NULL && t->locus == t->next->locus) |
3762 | { | |
3763 | loc = t->locus; | |
3764 | t = t->next; | |
3765 | } | |
3766 | print_instantiation_partial_context_line (context, t, loc, | |
3767 | t->locus == loc); | |
e2c3721c | 3768 | loc = t->locus; |
4b414c93 | 3769 | t = t->next; |
cb753e49 | 3770 | } |
4b414c93 MLI |
3771 | print_instantiation_partial_context_line (context, NULL, loc, |
3772 | /*recursive_p=*/false); | |
cb753e49 GDR |
3773 | } |
3774 | ||
3775 | /* Called from cp_thing to print the template context for an error. */ | |
3776 | static void | |
3f8548e7 | 3777 | maybe_print_instantiation_context (diagnostic_context *context) |
cb753e49 GDR |
3778 | { |
3779 | if (!problematic_instantiation_changed () || current_instantiation () == 0) | |
3780 | return; | |
3781 | ||
3782 | record_last_problematic_instantiation (); | |
47b69537 | 3783 | print_instantiation_full_context (context); |
cb753e49 | 3784 | } |
a1066c99 | 3785 | \f |
2bfe0527 JM |
3786 | /* Report what constexpr call(s) we're trying to expand, if any. */ |
3787 | ||
3788 | void | |
3789 | maybe_print_constexpr_context (diagnostic_context *context) | |
3790 | { | |
9771b263 | 3791 | vec<tree> call_stack = cx_error_context (); |
2bfe0527 JM |
3792 | unsigned ix; |
3793 | tree t; | |
3794 | ||
9771b263 | 3795 | FOR_EACH_VEC_ELT (call_stack, ix, t) |
2bfe0527 JM |
3796 | { |
3797 | expanded_location xloc = expand_location (EXPR_LOCATION (t)); | |
3798 | const char *s = expr_as_string (t, 0); | |
3799 | if (context->show_column) | |
3800 | pp_verbatim (context->printer, | |
84fa214d | 3801 | _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"), |
4b84d650 | 3802 | "locus", xloc.file, xloc.line, xloc.column, s); |
2bfe0527 JM |
3803 | else |
3804 | pp_verbatim (context->printer, | |
84fa214d | 3805 | _("%r%s:%d:%R in %<constexpr%> expansion of %qs"), |
4b84d650 | 3806 | "locus", xloc.file, xloc.line, s); |
b066401f | 3807 | pp_newline (context->printer); |
2bfe0527 JM |
3808 | } |
3809 | } | |
3810 | \f | |
f012c8ef | 3811 | |
cb57504a JM |
3812 | static void |
3813 | print_location (diagnostic_context *context, location_t loc) | |
3814 | { | |
3815 | expanded_location xloc = expand_location (loc); | |
3816 | if (context->show_column) | |
3817 | pp_verbatim (context->printer, _("%r%s:%d:%d:%R "), | |
3818 | "locus", xloc.file, xloc.line, xloc.column); | |
3819 | else | |
3820 | pp_verbatim (context->printer, _("%r%s:%d:%R "), | |
3821 | "locus", xloc.file, xloc.line); | |
3822 | } | |
3823 | ||
cb57504a JM |
3824 | static void |
3825 | print_constrained_decl_info (diagnostic_context *context, tree decl) | |
3826 | { | |
3827 | print_location (context, DECL_SOURCE_LOCATION (decl)); | |
3828 | pp_verbatim (context->printer, "required by the constraints of %q#D\n", decl); | |
3829 | } | |
3830 | ||
3831 | static void | |
3832 | print_concept_check_info (diagnostic_context *context, tree expr, tree map, tree args) | |
3833 | { | |
3834 | gcc_assert (concept_check_p (expr)); | |
3835 | ||
3836 | tree id = unpack_concept_check (expr); | |
3837 | tree tmpl = TREE_OPERAND (id, 0); | |
3838 | if (OVL_P (tmpl)) | |
3839 | tmpl = OVL_FIRST (tmpl); | |
cb57504a JM |
3840 | |
3841 | print_location (context, DECL_SOURCE_LOCATION (tmpl)); | |
828878c3 PP |
3842 | |
3843 | cxx_pretty_printer *pp = (cxx_pretty_printer *)context->printer; | |
3844 | pp_verbatim (pp, "required for the satisfaction of %qE", expr); | |
3845 | if (map && map != error_mark_node) | |
3846 | { | |
3847 | tree subst_map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE); | |
3848 | pp_cxx_parameter_mapping (pp, (subst_map != error_mark_node | |
3849 | ? subst_map : map)); | |
3850 | } | |
3851 | pp_newline (pp); | |
cb57504a JM |
3852 | } |
3853 | ||
3854 | /* Diagnose the entry point into the satisfaction error. Returns the next | |
3855 | context, if any. */ | |
3856 | ||
3857 | static tree | |
3858 | print_constraint_context_head (diagnostic_context *context, tree cxt, tree args) | |
3859 | { | |
3860 | tree src = TREE_VALUE (cxt); | |
3861 | if (!src) | |
3862 | { | |
3863 | print_location (context, input_location); | |
3864 | pp_verbatim (context->printer, "required for constraint satisfaction\n"); | |
3865 | return NULL_TREE; | |
3866 | } | |
3867 | if (DECL_P (src)) | |
3868 | { | |
3869 | print_constrained_decl_info (context, src); | |
3870 | return NULL_TREE; | |
3871 | } | |
3872 | else | |
3873 | { | |
3874 | print_concept_check_info (context, src, TREE_PURPOSE (cxt), args); | |
3875 | return TREE_CHAIN (cxt); | |
3876 | } | |
3877 | } | |
3878 | ||
3879 | static void | |
3880 | print_requires_expression_info (diagnostic_context *context, tree constr, tree args) | |
3881 | { | |
3882 | ||
3883 | tree expr = ATOMIC_CONSTR_EXPR (constr); | |
3884 | tree map = ATOMIC_CONSTR_MAP (constr); | |
3885 | map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE); | |
3886 | if (map == error_mark_node) | |
3887 | return; | |
cb57504a JM |
3888 | |
3889 | print_location (context, cp_expr_loc_or_input_loc (expr)); | |
3890 | pp_verbatim (context->printer, "in requirements "); | |
3891 | ||
3892 | tree parms = TREE_OPERAND (expr, 0); | |
3893 | if (parms) | |
3894 | pp_verbatim (context->printer, "with "); | |
3895 | while (parms) | |
3896 | { | |
43439d5e PP |
3897 | pp_verbatim (context->printer, "%q#D", parms); |
3898 | if (TREE_CHAIN (parms)) | |
cb57504a | 3899 | pp_separate_with_comma ((cxx_pretty_printer *)context->printer); |
43439d5e | 3900 | parms = TREE_CHAIN (parms); |
cb57504a | 3901 | } |
43439d5e | 3902 | pp_cxx_parameter_mapping ((cxx_pretty_printer *)context->printer, map); |
cb57504a JM |
3903 | |
3904 | pp_verbatim (context->printer, "\n"); | |
3905 | } | |
3906 | ||
3907 | void | |
3908 | maybe_print_single_constraint_context (diagnostic_context *context, tree failed) | |
3909 | { | |
3910 | if (!failed) | |
3911 | return; | |
3912 | ||
3913 | tree constr = TREE_VALUE (failed); | |
3914 | if (!constr || constr == error_mark_node) | |
3915 | return; | |
3916 | tree cxt = CONSTR_CONTEXT (constr); | |
3917 | if (!cxt) | |
3918 | return; | |
3919 | tree args = TREE_PURPOSE (failed); | |
3920 | ||
3921 | /* Print the stack of requirements. */ | |
3922 | cxt = print_constraint_context_head (context, cxt, args); | |
3923 | while (cxt && !DECL_P (TREE_VALUE (cxt))) | |
3924 | { | |
3925 | tree expr = TREE_VALUE (cxt); | |
3926 | tree map = TREE_PURPOSE (cxt); | |
3927 | print_concept_check_info (context, expr, map, args); | |
3928 | cxt = TREE_CHAIN (cxt); | |
3929 | } | |
3930 | ||
3931 | /* For certain constraints, we can provide additional context. */ | |
3932 | if (TREE_CODE (constr) == ATOMIC_CONSTR | |
3933 | && TREE_CODE (ATOMIC_CONSTR_EXPR (constr)) == REQUIRES_EXPR) | |
3934 | print_requires_expression_info (context, constr, args); | |
3935 | } | |
3936 | ||
3937 | void | |
3938 | maybe_print_constraint_context (diagnostic_context *context) | |
3939 | { | |
3940 | if (!current_failed_constraint) | |
3941 | return; | |
3942 | ||
3943 | tree cur = current_failed_constraint; | |
3944 | ||
3945 | /* Recursively print nested contexts. */ | |
3946 | current_failed_constraint = TREE_CHAIN (current_failed_constraint); | |
3947 | if (current_failed_constraint) | |
3948 | maybe_print_constraint_context (context); | |
3949 | ||
3950 | /* Print this context. */ | |
3951 | maybe_print_single_constraint_context (context, cur); | |
3952 | } | |
3953 | ||
f012c8ef DM |
3954 | /* Return true iff TYPE_A and TYPE_B are template types that are |
3955 | meaningful to compare. */ | |
3956 | ||
3957 | static bool | |
3958 | comparable_template_types_p (tree type_a, tree type_b) | |
3959 | { | |
3960 | if (!CLASS_TYPE_P (type_a)) | |
3961 | return false; | |
3962 | if (!CLASS_TYPE_P (type_b)) | |
3963 | return false; | |
3964 | ||
3965 | tree tinfo_a = TYPE_TEMPLATE_INFO (type_a); | |
3966 | tree tinfo_b = TYPE_TEMPLATE_INFO (type_b); | |
3967 | if (!tinfo_a || !tinfo_b) | |
3968 | return false; | |
3969 | ||
3970 | return TI_TEMPLATE (tinfo_a) == TI_TEMPLATE (tinfo_b); | |
3971 | } | |
3972 | ||
3973 | /* Start a new line indented by SPC spaces on PP. */ | |
3974 | ||
3975 | static void | |
3976 | newline_and_indent (pretty_printer *pp, int spc) | |
3977 | { | |
3978 | pp_newline (pp); | |
3979 | for (int i = 0; i < spc; i++) | |
3980 | pp_space (pp); | |
3981 | } | |
3982 | ||
3983 | /* Generate a GC-allocated string for ARG, an expression or type. */ | |
3984 | ||
3985 | static const char * | |
3986 | arg_to_string (tree arg, bool verbose) | |
3987 | { | |
3988 | if (TYPE_P (arg)) | |
ce95abc4 | 3989 | return type_to_string (arg, verbose, true, NULL, false); |
f012c8ef DM |
3990 | else |
3991 | return expr_to_string (arg); | |
3992 | } | |
3993 | ||
3994 | /* Subroutine to type_to_string_with_compare and | |
3995 | print_template_tree_comparison. | |
3996 | ||
3997 | Print a representation of ARG (an expression or type) to PP, | |
3998 | colorizing it as "type-diff" if PP->show_color. */ | |
3999 | ||
4000 | static void | |
4001 | print_nonequal_arg (pretty_printer *pp, tree arg, bool verbose) | |
4002 | { | |
4003 | pp_printf (pp, "%r%s%R", | |
4004 | "type-diff", | |
4005 | (arg | |
4006 | ? arg_to_string (arg, verbose) | |
4007 | : G_("(no argument)"))); | |
4008 | } | |
4009 | ||
4010 | /* Recursively print template TYPE_A to PP, as compared to template TYPE_B. | |
4011 | ||
4012 | The types must satisfy comparable_template_types_p. | |
4013 | ||
4014 | If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but | |
4015 | potentially colorizing/eliding in comparison with TYPE_B. | |
4016 | ||
4017 | For example given types: | |
4018 | vector<map<int,double>> | |
4019 | and | |
4020 | vector<map<int,float>> | |
4021 | then the result on PP would be: | |
4022 | vector<map<[...],double>> | |
4023 | with type elision, and: | |
4024 | vector<map<int,double>> | |
4025 | without type elision. | |
4026 | ||
4027 | In both cases the parts of TYPE that differ from PEER will be colorized | |
4028 | if pp_show_color (pp) is true. In the above example, this would be | |
4029 | "double". | |
4030 | ||
4031 | If INDENT is non-zero, then the types are printed in a tree-like form | |
4032 | which shows both types. In the above example, the result on PP would be: | |
4033 | ||
4034 | vector< | |
4035 | map< | |
4036 | [...], | |
4037 | [double != float]>> | |
4038 | ||
4039 | and without type-elision would be: | |
4040 | ||
4041 | vector< | |
4042 | map< | |
4043 | int, | |
4044 | [double != float]>> | |
4045 | ||
4046 | As before, the differing parts of the types are colorized if | |
4047 | pp_show_color (pp) is true ("double" and "float" in this example). | |
4048 | ||
4049 | Template arguments in which both types are using the default arguments | |
4050 | are not printed; if at least one of the two types is using a non-default | |
4051 | argument, then that argument is printed (or both arguments for the | |
4052 | tree-like print format). */ | |
4053 | ||
4054 | static void | |
4055 | print_template_differences (pretty_printer *pp, tree type_a, tree type_b, | |
4056 | bool verbose, int indent) | |
4057 | { | |
4058 | if (indent) | |
4059 | newline_and_indent (pp, indent); | |
4060 | ||
4061 | tree tinfo_a = TYPE_TEMPLATE_INFO (type_a); | |
4062 | tree tinfo_b = TYPE_TEMPLATE_INFO (type_b); | |
4063 | ||
4064 | pp_printf (pp, "%s<", | |
4065 | IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a)))); | |
4066 | ||
4067 | tree args_a = TI_ARGS (tinfo_a); | |
4068 | tree args_b = TI_ARGS (tinfo_b); | |
4069 | gcc_assert (TREE_CODE (args_a) == TREE_VEC); | |
4070 | gcc_assert (TREE_CODE (args_b) == TREE_VEC); | |
4071 | int flags = 0; | |
4072 | int len_a = get_non_default_template_args_count (args_a, flags); | |
4073 | args_a = INNERMOST_TEMPLATE_ARGS (args_a); | |
4074 | int len_b = get_non_default_template_args_count (args_b, flags); | |
4075 | args_b = INNERMOST_TEMPLATE_ARGS (args_b); | |
4076 | /* Determine the maximum range of args for which non-default template args | |
4077 | were used; beyond this, only default args (if any) were used, and so | |
4078 | they will be equal from this point onwards. | |
4079 | One of the two peers might have used default arguments within this | |
4080 | range, but the other will be using non-default arguments, and so | |
4081 | it's more readable to print both within this range, to highlight | |
4082 | the differences. */ | |
4083 | int len_max = MAX (len_a, len_b); | |
4084 | gcc_assert (TREE_CODE (args_a) == TREE_VEC); | |
4085 | gcc_assert (TREE_CODE (args_b) == TREE_VEC); | |
4086 | for (int idx = 0; idx < len_max; idx++) | |
4087 | { | |
4088 | if (idx) | |
4089 | pp_character (pp, ','); | |
4090 | ||
4091 | tree arg_a = TREE_VEC_ELT (args_a, idx); | |
4092 | tree arg_b = TREE_VEC_ELT (args_b, idx); | |
4093 | if (arg_a == arg_b) | |
4094 | { | |
4095 | if (indent) | |
4096 | newline_and_indent (pp, indent + 2); | |
4097 | /* Can do elision here, printing "[...]". */ | |
4098 | if (flag_elide_type) | |
4099 | pp_string (pp, G_("[...]")); | |
4100 | else | |
4101 | pp_string (pp, arg_to_string (arg_a, verbose)); | |
4102 | } | |
4103 | else | |
4104 | { | |
4105 | int new_indent = indent ? indent + 2 : 0; | |
4106 | if (comparable_template_types_p (arg_a, arg_b)) | |
4107 | print_template_differences (pp, arg_a, arg_b, verbose, new_indent); | |
4108 | else | |
4109 | if (indent) | |
4110 | { | |
4111 | newline_and_indent (pp, indent + 2); | |
4112 | pp_character (pp, '['); | |
4113 | print_nonequal_arg (pp, arg_a, verbose); | |
4114 | pp_string (pp, " != "); | |
4115 | print_nonequal_arg (pp, arg_b, verbose); | |
4116 | pp_character (pp, ']'); | |
4117 | } | |
4118 | else | |
4119 | print_nonequal_arg (pp, arg_a, verbose); | |
4120 | } | |
4121 | } | |
4122 | pp_printf (pp, ">"); | |
4123 | } | |
4124 | ||
4125 | /* As type_to_string, but for a template, potentially colorizing/eliding | |
4126 | in comparison with PEER. | |
4127 | For example, if TYPE is map<int,double> and PEER is map<int,int>, | |
4128 | then the resulting string would be: | |
4129 | map<[...],double> | |
4130 | with type elision, and: | |
4131 | map<int,double> | |
4132 | without type elision. | |
4133 | ||
4134 | In both cases the parts of TYPE that differ from PEER will be colorized | |
4135 | if SHOW_COLOR is true. In the above example, this would be "double". | |
4136 | ||
4137 | Template arguments in which both types are using the default arguments | |
4138 | are not printed; if at least one of the two types is using a non-default | |
4139 | argument, then both arguments are printed. | |
4140 | ||
4141 | The resulting string is in a GC-allocated buffer. */ | |
4142 | ||
4143 | static const char * | |
4144 | type_to_string_with_compare (tree type, tree peer, bool verbose, | |
4145 | bool show_color) | |
4146 | { | |
4147 | pretty_printer inner_pp; | |
4148 | pretty_printer *pp = &inner_pp; | |
4149 | pp_show_color (pp) = show_color; | |
4150 | ||
4151 | print_template_differences (pp, type, peer, verbose, 0); | |
4152 | return pp_ggc_formatted_text (pp); | |
4153 | } | |
4154 | ||
4155 | /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP, | |
4156 | indented by INDENT spaces. | |
4157 | ||
4158 | For example given types: | |
4159 | ||
4160 | vector<map<int,double>> | |
4161 | ||
4162 | and | |
4163 | ||
4164 | vector<map<double,float>> | |
4165 | ||
4166 | the output with type elision would be: | |
4167 | ||
4168 | vector< | |
4169 | map< | |
4170 | [...], | |
4171 | [double != float]>> | |
4172 | ||
4173 | and without type-elision would be: | |
4174 | ||
4175 | vector< | |
4176 | map< | |
4177 | int, | |
4178 | [double != float]>> | |
4179 | ||
4180 | TYPE_A and TYPE_B must both be comparable template types | |
4181 | (as per comparable_template_types_p). | |
4182 | ||
4183 | Template arguments in which both types are using the default arguments | |
4184 | are not printed; if at least one of the two types is using a non-default | |
4185 | argument, then both arguments are printed. */ | |
4186 | ||
4187 | static void | |
4188 | print_template_tree_comparison (pretty_printer *pp, tree type_a, tree type_b, | |
4189 | bool verbose, int indent) | |
4190 | { | |
4191 | print_template_differences (pp, type_a, type_b, verbose, indent); | |
4192 | } | |
4193 | ||
4194 | /* Subroutine for use in a format_postprocessor::handle | |
4195 | implementation. Adds a chunk to the end of | |
4196 | formatted output, so that it will be printed | |
4197 | by pp_output_formatted_text. */ | |
4198 | ||
4199 | static void | |
4200 | append_formatted_chunk (pretty_printer *pp, const char *content) | |
4201 | { | |
4202 | output_buffer *buffer = pp_buffer (pp); | |
4203 | struct chunk_info *chunk_array = buffer->cur_chunk_array; | |
4204 | const char **args = chunk_array->args; | |
4205 | ||
4206 | unsigned int chunk_idx; | |
4207 | for (chunk_idx = 0; args[chunk_idx]; chunk_idx++) | |
4208 | ; | |
4209 | args[chunk_idx++] = content; | |
4210 | args[chunk_idx] = NULL; | |
4211 | } | |
4212 | ||
4213 | /* Create a copy of CONTENT, with quotes added, and, | |
4214 | potentially, with colorization. | |
4215 | No escaped is performed on CONTENT. | |
4216 | The result is in a GC-allocated buffer. */ | |
4217 | ||
4218 | static const char * | |
4219 | add_quotes (const char *content, bool show_color) | |
4220 | { | |
4221 | pretty_printer tmp_pp; | |
4222 | pp_show_color (&tmp_pp) = show_color; | |
4223 | ||
fb6b29c8 MS |
4224 | /* We have to use "%<%s%>" rather than "%qs" here in order to avoid |
4225 | quoting colorization bytes within the results and using either | |
4226 | pp_quote or pp_begin_quote doesn't work the same. */ | |
4227 | pp_printf (&tmp_pp, "%<%s%>", content); | |
f012c8ef DM |
4228 | |
4229 | return pp_ggc_formatted_text (&tmp_pp); | |
4230 | } | |
4231 | ||
fb6b29c8 MS |
4232 | #if __GNUC__ >= 10 |
4233 | # pragma GCC diagnostic pop | |
4234 | #endif | |
4235 | ||
f012c8ef DM |
4236 | /* If we had %H and %I, and hence deferred printing them, |
4237 | print them now, storing the result into the chunk_info | |
4238 | for pp_format. Quote them if 'q' was provided. | |
4239 | Also print the difference in tree form, adding it as | |
4240 | an additional chunk. */ | |
4241 | ||
4242 | void | |
4243 | cxx_format_postprocessor::handle (pretty_printer *pp) | |
4244 | { | |
4245 | /* If we have one of %H and %I, the other should have | |
4246 | been present. */ | |
4247 | if (m_type_a.m_tree || m_type_b.m_tree) | |
4248 | { | |
4249 | /* Avoid reentrancy issues by working with a copy of | |
4250 | m_type_a and m_type_b, resetting them now. */ | |
4251 | deferred_printed_type type_a = m_type_a; | |
4252 | deferred_printed_type type_b = m_type_b; | |
4253 | m_type_a = deferred_printed_type (); | |
4254 | m_type_b = deferred_printed_type (); | |
4255 | ||
4256 | gcc_assert (type_a.m_buffer_ptr); | |
4257 | gcc_assert (type_b.m_buffer_ptr); | |
4258 | ||
4259 | bool show_color = pp_show_color (pp); | |
4260 | ||
4261 | const char *type_a_text; | |
4262 | const char *type_b_text; | |
4263 | ||
4264 | if (comparable_template_types_p (type_a.m_tree, type_b.m_tree)) | |
4265 | { | |
4266 | type_a_text | |
4267 | = type_to_string_with_compare (type_a.m_tree, type_b.m_tree, | |
4268 | type_a.m_verbose, show_color); | |
4269 | type_b_text | |
4270 | = type_to_string_with_compare (type_b.m_tree, type_a.m_tree, | |
4271 | type_b.m_verbose, show_color); | |
4272 | ||
4273 | if (flag_diagnostics_show_template_tree) | |
4274 | { | |
4275 | pretty_printer inner_pp; | |
4276 | pp_show_color (&inner_pp) = pp_show_color (pp); | |
4277 | print_template_tree_comparison | |
4278 | (&inner_pp, type_a.m_tree, type_b.m_tree, type_a.m_verbose, 2); | |
4279 | append_formatted_chunk (pp, pp_ggc_formatted_text (&inner_pp)); | |
4280 | } | |
4281 | } | |
4282 | else | |
4283 | { | |
ce95abc4 DM |
4284 | /* If the types were not comparable (or if only one of %H/%I was |
4285 | provided), they are printed normally, and no difference tree | |
4286 | is printed. */ | |
4287 | type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose, | |
4288 | true, &type_a.m_quote, show_color); | |
4289 | type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose, | |
4290 | true, &type_b.m_quote, show_color); | |
f012c8ef DM |
4291 | } |
4292 | ||
4293 | if (type_a.m_quote) | |
4294 | type_a_text = add_quotes (type_a_text, show_color); | |
4295 | *type_a.m_buffer_ptr = type_a_text; | |
4296 | ||
4297 | if (type_b.m_quote) | |
4298 | type_b_text = add_quotes (type_b_text, show_color); | |
4299 | *type_b.m_buffer_ptr = type_b_text; | |
4300 | } | |
4301 | } | |
4302 | ||
4303 | /* Subroutine for handling %H and %I, to support i18n of messages like: | |
4304 | ||
4305 | error_at (loc, "could not convert %qE from %qH to %qI", | |
4306 | expr, type_a, type_b); | |
4307 | ||
4308 | so that we can print things like: | |
4309 | ||
4310 | could not convert 'foo' from 'map<int,double>' to 'map<int,int>' | |
4311 | ||
4312 | and, with type-elision: | |
4313 | ||
4314 | could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>' | |
4315 | ||
4316 | (with color-coding of the differences between the types). | |
4317 | ||
4318 | The %H and %I format codes are peers: both must be present, | |
4319 | and they affect each other. Hence to handle them, we must | |
4320 | delay printing until we have both, deferring the printing to | |
4321 | pretty_printer's m_format_postprocessor hook. | |
4322 | ||
4323 | This is called in phase 2 of pp_format, when it is accumulating | |
4324 | a series of formatted chunks. We stash the location of the chunk | |
4325 | we're meant to have written to, so that we can write to it in the | |
4326 | m_format_postprocessor hook. | |
4327 | ||
4328 | We also need to stash whether a 'q' prefix was provided (the QUOTE | |
4329 | param) so that we can add the quotes when writing out the delayed | |
4330 | chunk. */ | |
4331 | ||
4332 | static void | |
4333 | defer_phase_2_of_type_diff (deferred_printed_type *deferred, | |
4334 | tree type, const char **buffer_ptr, | |
4335 | bool verbose, bool quote) | |
4336 | { | |
4337 | gcc_assert (deferred->m_tree == NULL_TREE); | |
4338 | gcc_assert (deferred->m_buffer_ptr == NULL); | |
4339 | *deferred = deferred_printed_type (type, buffer_ptr, verbose, quote); | |
4340 | } | |
4341 | ||
4342 | ||
a1066c99 GDR |
4343 | /* Called from output_format -- during diagnostic message processing -- |
4344 | to handle C++ specific format specifier with the following meanings: | |
4345 | %A function argument-list. | |
749ced52 | 4346 | %C tree code. |
a1066c99 GDR |
4347 | %D declaration. |
4348 | %E expression. | |
4349 | %F function declaration. | |
081b70a9 DM |
4350 | %H type difference (from). |
4351 | %I type difference (to). | |
749ced52 ZW |
4352 | %L language as used in extern "lang". |
4353 | %O binary operator. | |
a1066c99 | 4354 | %P function parameter whose position is indicated by an integer. |
749ced52 | 4355 | %Q assignment operator. |
3f04b1bb | 4356 | %S substitution (template + args) |
a1066c99 | 4357 | %T type. |
3f04b1bb | 4358 | %V cv-qualifier. |
081b70a9 | 4359 | %X exception-specification. */ |
47b69537 | 4360 | static bool |
39ce81c9 | 4361 | cp_printer (pretty_printer *pp, text_info *text, const char *spec, |
f012c8ef | 4362 | int precision, bool wide, bool set_locus, bool verbose, |
ce95abc4 | 4363 | bool *quoted, const char **buffer_ptr) |
a1066c99 | 4364 | { |
f012c8ef DM |
4365 | gcc_assert (pp->m_format_postprocessor); |
4366 | cxx_format_postprocessor *postprocessor | |
4367 | = static_cast <cxx_format_postprocessor *> (pp->m_format_postprocessor); | |
4368 | ||
749ced52 | 4369 | const char *result; |
39ce81c9 ZW |
4370 | tree t = NULL; |
4371 | #define next_tree (t = va_arg (*text->args_ptr, tree)) | |
72b5577d ILT |
4372 | #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int)) |
4373 | #define next_lang ((enum languages) va_arg (*text->args_ptr, int)) | |
47b69537 GDR |
4374 | #define next_int va_arg (*text->args_ptr, int) |
4375 | ||
39ce81c9 ZW |
4376 | if (precision != 0 || wide) |
4377 | return false; | |
4378 | ||
39ce81c9 | 4379 | switch (*spec) |
22a4158c | 4380 | { |
749ced52 | 4381 | case 'A': result = args_to_string (next_tree, verbose); break; |
0cbd7506 | 4382 | case 'C': result = code_to_string (next_tcode); break; |
dd90d2b2 RH |
4383 | case 'D': |
4384 | { | |
4385 | tree temp = next_tree; | |
5a6ccc94 | 4386 | if (VAR_P (temp) |
839b422f | 4387 | && DECL_HAS_DEBUG_EXPR_P (temp)) |
dd90d2b2 RH |
4388 | { |
4389 | temp = DECL_DEBUG_EXPR (temp); | |
4390 | if (!DECL_P (temp)) | |
4391 | { | |
4392 | result = expr_to_string (temp); | |
4393 | break; | |
4394 | } | |
4395 | } | |
4396 | result = decl_to_string (temp, verbose); | |
4397 | } | |
4398 | break; | |
0cbd7506 | 4399 | case 'E': result = expr_to_string (next_tree); break; |
749ced52 | 4400 | case 'F': result = fndecl_to_string (next_tree, verbose); break; |
081b70a9 DM |
4401 | case 'H': |
4402 | defer_phase_2_of_type_diff (&postprocessor->m_type_a, next_tree, | |
4403 | buffer_ptr, verbose, *quoted); | |
4404 | return true; | |
4405 | case 'I': | |
4406 | defer_phase_2_of_type_diff (&postprocessor->m_type_b, next_tree, | |
4407 | buffer_ptr, verbose, *quoted); | |
4408 | return true; | |
0cbd7506 | 4409 | case 'L': result = language_to_string (next_lang); break; |
88a819be | 4410 | case 'O': result = op_to_string (false, next_tcode); break; |
0cbd7506 | 4411 | case 'P': result = parm_to_string (next_int); break; |
88a819be | 4412 | case 'Q': result = op_to_string (true, next_tcode); break; |
3ff60975 | 4413 | case 'S': result = subst_to_string (next_tree); break; |
ce95abc4 DM |
4414 | case 'T': |
4415 | { | |
4416 | result = type_to_string (next_tree, verbose, false, quoted, | |
4417 | pp_show_color (pp)); | |
4418 | } | |
4419 | break; | |
749ced52 | 4420 | case 'V': result = cv_to_string (next_tree, verbose); break; |
3f04b1bb | 4421 | case 'X': result = eh_spec_to_string (next_tree, verbose); break; |
c8094d83 | 4422 | |
22a4158c | 4423 | default: |
47b69537 | 4424 | return false; |
a1066c99 | 4425 | } |
bb20cc46 | 4426 | |
b066401f | 4427 | pp_string (pp, result); |
39ce81c9 | 4428 | if (set_locus && t != NULL) |
85204e23 | 4429 | text->set_location (0, location_of (t), SHOW_RANGE_WITH_CARET); |
47b69537 | 4430 | return true; |
749ced52 ZW |
4431 | #undef next_tree |
4432 | #undef next_tcode | |
4433 | #undef next_lang | |
4434 | #undef next_int | |
a1066c99 | 4435 | } |
178b58b5 | 4436 | \f |
09357846 | 4437 | /* Warn about the use of C++0x features when appropriate. */ |
5d80a306 | 4438 | void |
d71d019f | 4439 | maybe_warn_cpp0x (cpp0x_warn_str str, location_t loc/*=input_location*/) |
5d80a306 | 4440 | { |
ac4c7868 | 4441 | if (cxx_dialect == cxx98) |
848f237b SZ |
4442 | switch (str) |
4443 | { | |
4444 | case CPP0X_INITIALIZER_LISTS: | |
d71d019f | 4445 | pedwarn (loc, OPT_Wc__11_extensions, |
848f237b | 4446 | "extended initializer lists " |
a3f9f006 | 4447 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4448 | break; |
4449 | case CPP0X_EXPLICIT_CONVERSION: | |
d71d019f | 4450 | pedwarn (loc, OPT_Wc__11_extensions, |
848f237b | 4451 | "explicit conversion operators " |
a3f9f006 | 4452 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4453 | break; |
4454 | case CPP0X_VARIADIC_TEMPLATES: | |
d71d019f | 4455 | pedwarn (loc, OPT_Wc__11_extensions, |
848f237b | 4456 | "variadic templates " |
a3f9f006 | 4457 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4458 | break; |
4459 | case CPP0X_LAMBDA_EXPR: | |
d71d019f | 4460 | pedwarn (loc, OPT_Wc__11_extensions, |
848f237b | 4461 | "lambda expressions " |
a3f9f006 | 4462 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4463 | break; |
4464 | case CPP0X_AUTO: | |
d71d019f | 4465 | pedwarn (loc, OPT_Wc__11_extensions, |
a3f9f006 ML |
4466 | "C++11 auto only available with %<-std=c++11%> or " |
4467 | "%<-std=gnu++11%>"); | |
848f237b SZ |
4468 | break; |
4469 | case CPP0X_SCOPED_ENUMS: | |
d71d019f | 4470 | pedwarn (loc, OPT_Wc__11_extensions, |
a3f9f006 ML |
4471 | "scoped enums only available with %<-std=c++11%> or " |
4472 | "%<-std=gnu++11%>"); | |
848f237b SZ |
4473 | break; |
4474 | case CPP0X_DEFAULTED_DELETED: | |
d71d019f | 4475 | pedwarn (loc, OPT_Wc__11_extensions, |
848f237b | 4476 | "defaulted and deleted functions " |
a3f9f006 | 4477 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
bc2c4cb4 RRC |
4478 | break; |
4479 | case CPP0X_INLINE_NAMESPACES: | |
ee336ecb | 4480 | if (pedantic) |
d71d019f | 4481 | pedwarn (loc, OPT_Wc__11_extensions, |
ee336ecb JW |
4482 | "inline namespaces " |
4483 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); | |
3ce4f9e4 | 4484 | break; |
eda42c4f | 4485 | case CPP0X_OVERRIDE_CONTROLS: |
d71d019f | 4486 | pedwarn (loc, OPT_Wc__11_extensions, |
eda42c4f | 4487 | "override controls (override/final) " |
a3f9f006 | 4488 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
eda42c4f | 4489 | break; |
0e5f8a59 | 4490 | case CPP0X_NSDMI: |
d71d019f | 4491 | pedwarn (loc, OPT_Wc__11_extensions, |
0e5f8a59 | 4492 | "non-static data member initializers " |
a3f9f006 | 4493 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
0e5f8a59 | 4494 | break; |
3ce4f9e4 | 4495 | case CPP0X_USER_DEFINED_LITERALS: |
d71d019f | 4496 | pedwarn (loc, OPT_Wc__11_extensions, |
3ce4f9e4 | 4497 | "user-defined literals " |
a3f9f006 | 4498 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
3ce4f9e4 | 4499 | break; |
238e471c | 4500 | case CPP0X_DELEGATING_CTORS: |
d71d019f | 4501 | pedwarn (loc, OPT_Wc__11_extensions, |
238e471c | 4502 | "delegating constructors " |
a3f9f006 | 4503 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
85b5d65a JM |
4504 | break; |
4505 | case CPP0X_INHERITING_CTORS: | |
d71d019f | 4506 | pedwarn (loc, OPT_Wc__11_extensions, |
85b5d65a | 4507 | "inheriting constructors " |
a3f9f006 | 4508 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
238e471c | 4509 | break; |
e28d52cf | 4510 | case CPP0X_ATTRIBUTES: |
d71d019f | 4511 | pedwarn (loc, OPT_Wc__11_extensions, |
ee336ecb | 4512 | "C++11 attributes " |
a3f9f006 | 4513 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
e28d52cf | 4514 | break; |
2eed8e37 | 4515 | case CPP0X_REF_QUALIFIER: |
d71d019f | 4516 | pedwarn (loc, OPT_Wc__11_extensions, |
2eed8e37 | 4517 | "ref-qualifiers " |
a3f9f006 | 4518 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
2eed8e37 | 4519 | break; |
848f237b | 4520 | default: |
3ce4f9e4 | 4521 | gcc_unreachable (); |
848f237b | 4522 | } |
09357846 JM |
4523 | } |
4524 | ||
4525 | /* Warn about the use of variadic templates when appropriate. */ | |
4526 | void | |
4527 | maybe_warn_variadic_templates (void) | |
4528 | { | |
848f237b | 4529 | maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES); |
5d80a306 | 4530 | } |
9c650d90 MLI |
4531 | |
4532 | ||
4533 | /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on | |
4534 | option OPT with text GMSGID. Use this function to report | |
4535 | diagnostics for constructs that are invalid C++98, but valid | |
4536 | C++0x. */ | |
4537 | bool | |
4538 | pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...) | |
4539 | { | |
4540 | diagnostic_info diagnostic; | |
4541 | va_list ap; | |
c522573e | 4542 | bool ret; |
ebedc9a3 | 4543 | rich_location richloc (line_table, location); |
9c650d90 MLI |
4544 | |
4545 | va_start (ap, gmsgid); | |
8a645150 | 4546 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, |
9c650d90 MLI |
4547 | (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING); |
4548 | diagnostic.option_index = opt; | |
56d35585 | 4549 | ret = diagnostic_report_diagnostic (global_dc, &diagnostic); |
9c650d90 | 4550 | va_end (ap); |
c522573e | 4551 | return ret; |
9c650d90 | 4552 | } |
993acb36 NF |
4553 | |
4554 | /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what | |
4555 | we found when we tried to do the lookup. LOCATION is the location of | |
4556 | the NAME identifier. */ | |
4557 | ||
4558 | void | |
4559 | qualified_name_lookup_error (tree scope, tree name, | |
4560 | tree decl, location_t location) | |
4561 | { | |
4562 | if (scope == error_mark_node) | |
4563 | ; /* We already complained. */ | |
4564 | else if (TYPE_P (scope)) | |
4565 | { | |
4566 | if (!COMPLETE_TYPE_P (scope)) | |
4567 | error_at (location, "incomplete type %qT used in nested name specifier", | |
4568 | scope); | |
4569 | else if (TREE_CODE (decl) == TREE_LIST) | |
4570 | { | |
4571 | error_at (location, "reference to %<%T::%D%> is ambiguous", | |
4572 | scope, name); | |
4573 | print_candidates (decl); | |
4574 | } | |
4575 | else | |
3ded6ffd DM |
4576 | { |
4577 | name_hint hint; | |
883c0796 | 4578 | if (SCOPED_ENUM_P (scope) && TREE_CODE (name) == IDENTIFIER_NODE) |
3ded6ffd DM |
4579 | hint = suggest_alternative_in_scoped_enum (name, scope); |
4580 | if (const char *suggestion = hint.suggestion ()) | |
4581 | { | |
4582 | gcc_rich_location richloc (location); | |
4583 | richloc.add_fixit_replace (suggestion); | |
4584 | error_at (&richloc, | |
4585 | "%qD is not a member of %qT; did you mean %qs?", | |
4586 | name, scope, suggestion); | |
4587 | } | |
4588 | else | |
4589 | error_at (location, "%qD is not a member of %qT", name, scope); | |
4590 | } | |
993acb36 NF |
4591 | } |
4592 | else if (scope != global_namespace) | |
4593 | { | |
097f82ec | 4594 | auto_diagnostic_group d; |
7e2de6df DM |
4595 | bool emit_fixit = true; |
4596 | name_hint hint | |
4597 | = suggest_alternative_in_explicit_scope (location, name, scope); | |
4598 | if (!hint) | |
4599 | { | |
4600 | hint = suggest_alternatives_in_other_namespaces (location, name); | |
4601 | /* "location" is just the location of the name, not of the explicit | |
4602 | scope, and it's not easy to get at the latter, so we can't issue | |
4603 | fix-it hints for the suggestion. */ | |
4604 | emit_fixit = false; | |
4605 | } | |
4606 | if (const char *suggestion = hint.suggestion ()) | |
4607 | { | |
4608 | gcc_rich_location richloc (location); | |
4609 | if (emit_fixit) | |
4610 | richloc.add_fixit_replace (suggestion); | |
4611 | error_at (&richloc, "%qD is not a member of %qD; did you mean %qs?", | |
4612 | name, scope, suggestion); | |
4613 | } | |
4614 | else | |
4615 | error_at (location, "%qD is not a member of %qD", name, scope); | |
993acb36 NF |
4616 | } |
4617 | else | |
4618 | { | |
097f82ec | 4619 | auto_diagnostic_group d; |
7e2de6df DM |
4620 | name_hint hint = suggest_alternatives_for (location, name, true); |
4621 | if (const char *suggestion = hint.suggestion ()) | |
4622 | { | |
4623 | gcc_rich_location richloc (location); | |
4624 | richloc.add_fixit_replace (suggestion); | |
4625 | error_at (&richloc, | |
4626 | "%<::%D%> has not been declared; did you mean %qs?", | |
4627 | name, suggestion); | |
4628 | } | |
4629 | else | |
4630 | error_at (location, "%<::%D%> has not been declared", name); | |
993acb36 NF |
4631 | } |
4632 | } | |
96e6ae57 DM |
4633 | |
4634 | /* C++-specific implementation of range_label::get_text () vfunc for | |
4635 | range_label_for_type_mismatch. | |
4636 | ||
4637 | Compare with print_template_differences above. */ | |
4638 | ||
4639 | label_text | |
9c4a4b3c | 4640 | range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const |
96e6ae57 DM |
4641 | { |
4642 | if (m_labelled_type == NULL_TREE) | |
d68f5d45 | 4643 | return label_text::borrow (NULL); |
96e6ae57 DM |
4644 | |
4645 | const bool verbose = false; | |
4646 | const bool show_color = false; | |
4647 | ||
4648 | const char *result; | |
4649 | if (m_other_type | |
4650 | && comparable_template_types_p (m_labelled_type, m_other_type)) | |
4651 | result = type_to_string_with_compare (m_labelled_type, m_other_type, | |
4652 | verbose, show_color); | |
4653 | else | |
4654 | result = type_to_string (m_labelled_type, verbose, true, NULL, show_color); | |
4655 | ||
4656 | /* Both of the above return GC-allocated buffers, so the caller mustn't | |
4657 | free them. */ | |
d68f5d45 | 4658 | return label_text::borrow (result); |
96e6ae57 | 4659 | } |