Line data Source code
1 : /* Call-backs for C++ error reporting.
2 : This code is non-reentrant.
3 : Copyright (C) 1993-2026 Free Software Foundation, Inc.
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3, or (at your option)
9 : any later version.
10 :
11 : GCC is distributed in the hope that it will be useful,
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
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : #define INCLUDE_VECTOR
21 : #include "config.h"
22 : /* For use with name_hint. */
23 : #include "system.h"
24 : #include "coretypes.h"
25 : #include "cp-tree.h"
26 : #include "stringpool.h"
27 : #include "tree-diagnostic.h"
28 : #include "diagnostics/color.h"
29 : #include "langhooks-def.h"
30 : #include "intl.h"
31 : #include "cxx-pretty-print.h"
32 : #include "tree-pretty-print.h"
33 : #include "tree-pretty-print-markup.h"
34 : #include "gimple-pretty-print.h"
35 : #include "c-family/c-objc.h"
36 : #include "ubsan.h"
37 : #include "internal-fn.h"
38 : #include "c-family/c-type-mismatch.h"
39 : #include "cp-name-hint.h"
40 : #include "attribs.h"
41 : #include "pretty-print-format-impl.h"
42 : #include "diagnostics/text-sink.h"
43 :
44 : #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
45 : #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
46 :
47 : /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
48 : dump C++ ASTs as strings. It is mostly used only by the various
49 : tree -> string functions that are occasionally called from the
50 : debugger or by the front-end for things like
51 : __PRETTY_FUNCTION__. */
52 : static cxx_pretty_printer actual_pretty_printer;
53 : static cxx_pretty_printer * const cxx_pp = &actual_pretty_printer;
54 :
55 : /* Translate if being used for diagnostics, but not for dump files or
56 : __PRETTY_FUNCTION. */
57 : #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
58 :
59 : # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
60 :
61 : static const char *args_to_string (tree, int);
62 : static const char *code_to_string (enum tree_code);
63 : static const char *cv_to_string (tree, int);
64 : static const char *decl_to_string (tree, int, bool);
65 : static const char *fndecl_to_string (tree, int);
66 : static const char *op_to_string (bool, enum tree_code);
67 : static const char *parm_to_string (int);
68 : static const char *type_to_string (tree, int, bool, bool *, bool,
69 : const char * = nullptr);
70 :
71 : static void dump_alias_template_specialization (cxx_pretty_printer *, tree, int);
72 : static void dump_type (cxx_pretty_printer *, tree, int);
73 : static void dump_typename (cxx_pretty_printer *, tree, int);
74 : static void dump_simple_decl (cxx_pretty_printer *, tree, tree, int);
75 : static void dump_decl (cxx_pretty_printer *, tree, int);
76 : static void dump_template_decl (cxx_pretty_printer *, tree, int);
77 : static void dump_function_decl (cxx_pretty_printer *, tree, int);
78 : static void dump_expr (cxx_pretty_printer *, tree, int);
79 : static void dump_unary_op (cxx_pretty_printer *, const char *, tree, int);
80 : static void dump_binary_op (cxx_pretty_printer *, const char *, tree, int);
81 : static void dump_aggr_type (cxx_pretty_printer *, tree, int);
82 : static void dump_type_prefix (cxx_pretty_printer *, tree, int);
83 : static void dump_type_suffix (cxx_pretty_printer *, tree, int);
84 : static void dump_function_name (cxx_pretty_printer *, tree, int);
85 : static void dump_call_expr_args (cxx_pretty_printer *, tree, int, bool);
86 : static void dump_expr_list (cxx_pretty_printer *, tree, int);
87 : static void dump_global_iord (cxx_pretty_printer *, tree);
88 : static void dump_parameters (cxx_pretty_printer *, tree, int);
89 : static void dump_ref_qualifier (cxx_pretty_printer *, tree, int);
90 : static void dump_exception_spec (cxx_pretty_printer *, tree, int);
91 : static void dump_template_argument (cxx_pretty_printer *, tree, int);
92 : static void dump_template_argument_list (cxx_pretty_printer *, tree, int);
93 : static void dump_template_parameter (cxx_pretty_printer *, tree, int);
94 : static void dump_template_bindings (cxx_pretty_printer *, tree, tree,
95 : vec<tree, va_gc> *);
96 : static void dump_scope (cxx_pretty_printer *, tree, int);
97 : static void dump_template_parms (cxx_pretty_printer *, tree, int, int);
98 : static int get_non_default_template_args_count (tree, int);
99 : static const char *function_category (tree);
100 : static void maybe_print_constexpr_context (diagnostics::text_sink &);
101 : static void maybe_print_instantiation_context (diagnostics::text_sink &);
102 : static void print_instantiation_full_context (diagnostics::text_sink &);
103 : static void print_instantiation_partial_context (diagnostics::text_sink &,
104 : struct tinst_level *,
105 : location_t);
106 : static void maybe_print_constraint_context (diagnostics::text_sink &);
107 : static void cp_diagnostic_text_starter (diagnostics::text_sink &,
108 : const diagnostics::diagnostic_info *);
109 : static void cp_print_error_function (diagnostics::text_sink &,
110 : const diagnostics::diagnostic_info *);
111 :
112 : static bool cp_printer (pretty_printer *, text_info *, const char *,
113 : int, bool, bool, bool, bool *, pp_token_list &);
114 :
115 : /* Color names for highlighting "%qH" vs "%qI" values,
116 : and ranges corresponding to them. */
117 : const char *const highlight_colors::percent_h = "highlight-a";
118 : const char *const highlight_colors::percent_i = "highlight-b";
119 :
120 : /* Struct for handling %H or %I, which require delaying printing the
121 : type until a postprocessing stage. */
122 :
123 125856 : class deferred_printed_type
124 : {
125 : public:
126 340653 : deferred_printed_type ()
127 340653 : : m_tree (NULL_TREE),
128 340653 : m_printed_text (),
129 340653 : m_token_list (nullptr),
130 20976 : m_verbose (false), m_quote (false)
131 : {}
132 :
133 20976 : deferred_printed_type (tree type,
134 : pp_token_list &token_list,
135 : bool verbose,
136 : bool quote)
137 20976 : : m_tree (type),
138 20976 : m_printed_text (),
139 20976 : m_token_list (&token_list),
140 20976 : m_verbose (verbose),
141 20976 : m_quote (quote)
142 : {
143 20976 : gcc_assert (type);
144 : }
145 :
146 20976 : void set_text_for_token_list (const char *text, bool quote)
147 : {
148 : /* Replace the contents of m_token_list with a text token for TEXT,
149 : possibly wrapped by BEGIN_QUOTE/END_QUOTE (if QUOTE is true).
150 : This allows us to ignore any {BEGIN,END}_QUOTE tokens added
151 : by %qH and %qI, and instead use the quoting from type_to_string,
152 : and its logic for "aka". */
153 62928 : while (m_token_list->m_first)
154 41952 : m_token_list->pop_front ();
155 :
156 20976 : if (quote)
157 334 : m_token_list->push_back<pp_token_begin_quote> ();
158 :
159 : // TEXT is gc-allocated, so we can borrow it
160 20976 : m_token_list->push_back_text (label_text::borrow (text));
161 :
162 20976 : if (quote)
163 334 : m_token_list->push_back<pp_token_end_quote> ();
164 20976 : }
165 :
166 : /* The tree is not GTY-marked: they are only non-NULL within a
167 : call to pp_format. */
168 : tree m_tree;
169 : label_text m_printed_text;
170 : pp_token_list *m_token_list;
171 : bool m_verbose;
172 : bool m_quote;
173 : };
174 :
175 : /* Subclass of format_postprocessor for the C++ frontend.
176 : This handles the %H and %I formatting codes, printing them
177 : in a postprocessing phase (since they affect each other). */
178 :
179 : class cxx_format_postprocessor : public format_postprocessor
180 : {
181 : public:
182 319677 : cxx_format_postprocessor ()
183 319677 : : m_type_a (), m_type_b ()
184 : {}
185 :
186 : std::unique_ptr<format_postprocessor>
187 221138 : clone() const final override
188 : {
189 221138 : return std::make_unique<cxx_format_postprocessor> ();
190 : }
191 :
192 : void handle (pretty_printer *pp) final override;
193 :
194 : deferred_printed_type m_type_a;
195 : deferred_printed_type m_type_b;
196 : };
197 :
198 : /* Constructor and destructor for cxx_dump_pretty_printer, defined here to
199 : avoid needing to move cxx_format_postprocessor into the header as well. */
200 :
201 841025916 : cxx_dump_pretty_printer::
202 841025916 : cxx_dump_pretty_printer (int phase)
203 841025916 : : phase (phase)
204 : {
205 841025916 : outf = dump_begin (phase, &flags);
206 841025916 : if (outf)
207 : {
208 0 : pp_format_decoder (this) = cp_printer;
209 0 : set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ());
210 0 : set_output_stream (outf);
211 : }
212 841025916 : }
213 :
214 841025916 : cxx_dump_pretty_printer::
215 841025916 : ~cxx_dump_pretty_printer ()
216 : {
217 841025916 : if (outf)
218 : {
219 0 : pp_flush (this);
220 0 : dump_end (phase, outf);
221 : }
222 841025916 : }
223 :
224 : /* Return the in-scope template that's currently being parsed, or
225 : NULL_TREE otherwise. */
226 :
227 : static tree
228 86814 : get_current_template ()
229 : {
230 86814 : if (scope_chain && in_template_context && !current_instantiation ())
231 10801 : if (tree ti = get_template_info (current_scope ()))
232 : {
233 4830 : if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)) && TI_PARTIAL_INFO (ti))
234 24 : ti = TI_PARTIAL_INFO (ti);
235 4830 : return TI_TEMPLATE (ti);
236 : }
237 :
238 : return NULL_TREE;
239 : }
240 :
241 : /* A map from TEMPLATE_DECLs that we've determined to be erroneous
242 : at parse time to the location of the first error within. */
243 :
244 : erroneous_templates_t *erroneous_templates;
245 :
246 : /* Callback function diagnostics::context::m_adjust_diagnostic_info.
247 :
248 : Errors issued when parsing a template are automatically treated like
249 : permerrors associated with the -Wtemplate-body flag and can be
250 : downgraded into warnings accordingly, in which case we'll still
251 : issue an error if we later need to instantiate the template. */
252 :
253 : static void
254 98288870 : cp_adjust_diagnostic_info (const diagnostics::context &context,
255 : diagnostics::diagnostic_info *diagnostic)
256 : {
257 98288870 : if (diagnostic->m_kind == diagnostics::kind::error)
258 86796 : if (tree tmpl = get_current_template ())
259 : {
260 4812 : diagnostic->m_option_id = OPT_Wtemplate_body;
261 :
262 4812 : if (context.m_permissive)
263 48 : diagnostic->m_kind = diagnostics::kind::warning;
264 :
265 4812 : bool existed;
266 4812 : location_t &error_loc
267 4812 : = hash_map_safe_get_or_insert<true> (erroneous_templates,
268 : tmpl, &existed);
269 4812 : if (!existed)
270 : /* Remember that this template had a parse-time error so
271 : that we'll ensure a hard error has been issued upon
272 : its instantiation. */
273 2316 : error_loc = diagnostic->m_richloc->get_loc ();
274 : }
275 98288870 : }
276 :
277 : /* A generalization of seen_error which also returns true if we've
278 : permissively downgraded an error to a warning inside a template. */
279 :
280 : bool
281 8789622 : cp_seen_error ()
282 : {
283 8789622 : if ((seen_error) ())
284 : return true;
285 :
286 8767741 : if (erroneous_templates)
287 18 : if (tree tmpl = get_current_template ())
288 18 : if (erroneous_templates->get (tmpl))
289 18 : return true;
290 :
291 : return false;
292 : }
293 :
294 : /* CONTEXT->printer is a basic pretty printer that was constructed
295 : presumably by diagnostic_initialize(), called early in the
296 : compiler's initialization process (in general_init) Before the FE
297 : is initialized. This (C++) FE-specific diagnostic initializer is
298 : thus replacing the basic pretty printer with one that has C++-aware
299 : capacities. */
300 :
301 : void
302 98539 : cxx_initialize_diagnostics (diagnostics::context *context)
303 : {
304 98539 : cxx_pretty_printer *pp = new cxx_pretty_printer ();
305 98539 : pp->set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ());
306 98539 : context->set_pretty_printer (std::unique_ptr<pretty_printer> (pp));
307 :
308 98539 : c_common_diagnostics_set_defaults (context);
309 98539 : diagnostics::text_starter (context) = cp_diagnostic_text_starter;
310 : /* diagnostic_finalizer is already c_diagnostic_text_finalizer. */
311 98539 : context->set_format_decoder (cp_printer);
312 98539 : context->set_adjust_diagnostic_info_callback (cp_adjust_diagnostic_info);
313 98539 : }
314 :
315 : /* Dump an '@module' name suffix for DECL, if it's attached to an import. */
316 :
317 : static void
318 223997654 : dump_module_suffix (cxx_pretty_printer *pp, tree decl)
319 : {
320 223997654 : if (!modules_p ())
321 : return;
322 :
323 176817 : if (!DECL_CONTEXT (decl))
324 : return;
325 :
326 176126 : if (TREE_CODE (decl) != CONST_DECL
327 176126 : || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl)))
328 : {
329 176098 : if (!DECL_NAMESPACE_SCOPE_P (decl))
330 : return;
331 :
332 84491 : if (TREE_CODE (decl) == NAMESPACE_DECL
333 0 : && !DECL_NAMESPACE_ALIAS (decl)
334 84491 : && (TREE_PUBLIC (decl) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl))))
335 : return;
336 : }
337 :
338 84519 : int m = get_originating_module (decl, /*global=-1*/true);
339 84519 : if (m > 0)
340 402 : if (const char *n = module_name (m, false))
341 : {
342 402 : pp_character (pp, '@');
343 402 : pp->set_padding (pp_none);
344 402 : pp_string (pp, n);
345 : }
346 : }
347 :
348 : /* The scope of the declaration we're currently printing, to avoid redundantly
349 : dumping the same scope on parameter types. */
350 : static tree current_dump_scope;
351 :
352 : /* Dump a scope, if deemed necessary. */
353 :
354 : static void
355 166193693 : dump_scope (cxx_pretty_printer *pp, tree scope, int flags)
356 : {
357 166193693 : int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF);
358 :
359 166193693 : if (scope == NULL_TREE || scope == current_dump_scope)
360 : return;
361 :
362 : /* Enum values within an unscoped enum will be CONST_DECL with an
363 : ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
364 : ENUMERAL_TYPE, so as to print any enclosing namespace. */
365 165969300 : if (UNSCOPED_ENUM_P (scope))
366 202 : scope = CP_TYPE_CONTEXT (scope);
367 :
368 165969300 : if (TREE_CODE (scope) == NAMESPACE_DECL)
369 : {
370 147753099 : if (scope != global_namespace)
371 : {
372 82010886 : dump_decl (pp, scope, f);
373 82010886 : pp_cxx_colon_colon (pp);
374 : }
375 : }
376 18216201 : else if (AGGREGATE_TYPE_P (scope)
377 18216201 : || SCOPED_ENUM_P (scope))
378 : {
379 17804887 : dump_type (pp, scope, f);
380 17804887 : pp_cxx_colon_colon (pp);
381 : }
382 411314 : else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL)
383 : {
384 396603 : dump_function_decl (pp, scope, f | TFF_NO_TEMPLATE_BINDINGS);
385 396603 : pp_cxx_colon_colon (pp);
386 : }
387 : }
388 :
389 : /* Dump the template ARGument under control of FLAGS. */
390 :
391 : static void
392 146076317 : dump_template_argument (cxx_pretty_printer *pp, tree arg, int flags)
393 : {
394 146076317 : if (ARGUMENT_PACK_P (arg))
395 7090461 : dump_template_argument_list (pp, ARGUMENT_PACK_ARGS (arg),
396 : /* No default args in argument packs. */
397 : flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
398 138985856 : else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
399 118417709 : dump_type (pp, arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
400 : else
401 : {
402 20568147 : if (TREE_CODE (arg) == TREE_LIST)
403 0 : arg = TREE_VALUE (arg);
404 :
405 : /* Strip implicit conversions. */
406 20568207 : while (CONVERT_EXPR_P (arg))
407 60 : arg = TREE_OPERAND (arg, 0);
408 :
409 20568147 : dump_expr (pp, arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM);
410 : }
411 146076317 : }
412 :
413 : /* Count the number of template arguments ARGS whose value does not
414 : match the (optional) default template parameter in PARAMS */
415 :
416 : static int
417 93487192 : get_non_default_template_args_count (tree args, int flags)
418 : {
419 93487192 : int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args));
420 :
421 93487192 : if (/* We use this flag when generating debug information. We don't
422 : want to expand templates at this point, for this may generate
423 : new decls, which gets decl counts out of sync, which may in
424 : turn cause codegen differences between compilations with and
425 : without -g. */
426 93487192 : (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0
427 4197923 : || !flag_pretty_templates)
428 : return n;
429 :
430 4197866 : return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args));
431 : }
432 :
433 : /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
434 : of FLAGS. */
435 :
436 : static void
437 7094166 : dump_template_argument_list (cxx_pretty_printer *pp, tree args, int flags)
438 : {
439 7094166 : int n = get_non_default_template_args_count (args, flags);
440 7094166 : int need_comma = 0;
441 7094166 : int i;
442 :
443 21187770 : for (i = 0; i < n; ++i)
444 : {
445 14093604 : tree arg = TREE_VEC_ELT (args, i);
446 :
447 : /* Only print a comma if we know there is an argument coming. In
448 : the case of an empty template argument pack, no actual
449 : argument will be printed. */
450 14093604 : if (need_comma
451 14093604 : && (!ARGUMENT_PACK_P (arg)
452 188 : || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
453 7554706 : pp_separate_with_comma (pp);
454 :
455 14093604 : dump_template_argument (pp, arg, flags);
456 14093604 : need_comma = 1;
457 : }
458 7094166 : }
459 :
460 : /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
461 :
462 : static void
463 75489 : dump_template_parameter (cxx_pretty_printer *pp, tree parm, int flags)
464 : {
465 75489 : tree p;
466 75489 : tree a;
467 :
468 75489 : if (parm == error_mark_node)
469 : return;
470 :
471 75489 : p = TREE_VALUE (parm);
472 75489 : a = TREE_PURPOSE (parm);
473 :
474 75489 : if (TREE_CODE (p) == TYPE_DECL)
475 : {
476 68071 : if (flags & TFF_DECL_SPECIFIERS)
477 : {
478 10616 : pp_cxx_ws_string (pp, "class");
479 10616 : if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p)))
480 854 : pp_cxx_ws_string (pp, "...");
481 10616 : if (DECL_NAME (p))
482 9873 : pp_cxx_tree_identifier (pp, DECL_NAME (p));
483 : }
484 57455 : else if (DECL_NAME (p))
485 56625 : pp_cxx_tree_identifier (pp, DECL_NAME (p));
486 : else
487 830 : pp_cxx_canonical_template_parameter (pp, TREE_TYPE (p));
488 : }
489 : else
490 7418 : dump_decl (pp, p, flags | TFF_DECL_SPECIFIERS);
491 :
492 75489 : if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE)
493 : {
494 0 : pp_cxx_whitespace (pp);
495 0 : pp_equal (pp);
496 0 : pp_cxx_whitespace (pp);
497 0 : if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL)
498 0 : dump_type (pp, a, flags & ~TFF_CHASE_TYPEDEF);
499 : else
500 0 : dump_expr (pp, a, flags | TFF_EXPR_IN_PARENS);
501 : }
502 : }
503 :
504 : /* Dump, under control of FLAGS, a template-parameter-list binding.
505 : PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
506 : TREE_VEC. */
507 :
508 : static void
509 40142 : dump_template_bindings (cxx_pretty_printer *pp, tree parms, tree args,
510 : vec<tree, va_gc> *typenames)
511 : {
512 : /* Print "[with" and ']', conditional on whether anything is printed at all.
513 : This is tied to whether a semicolon is needed to separate multiple template
514 : parameters. */
515 40142 : struct prepost_semicolon
516 : {
517 : cxx_pretty_printer *pp;
518 : bool need_semicolon;
519 :
520 73917 : void operator() ()
521 : {
522 73917 : if (need_semicolon)
523 33775 : pp_separate_with_semicolon (pp);
524 : else
525 : {
526 40142 : pp_cxx_whitespace (pp);
527 40142 : pp_string (pp, colorize_start (pp_show_color (pp), "targs"));
528 40142 : pp_cxx_left_bracket (pp);
529 40142 : pp->translate_string ("with");
530 40142 : pp_cxx_whitespace (pp);
531 40142 : need_semicolon = true;
532 : }
533 73917 : }
534 :
535 40142 : ~prepost_semicolon ()
536 : {
537 40142 : if (need_semicolon)
538 : {
539 40142 : pp_cxx_right_bracket (pp);
540 40142 : pp_string (pp, colorize_stop (pp_show_color (pp)));
541 : }
542 40142 : }
543 40142 : } semicolon_or_introducer = {pp, false};
544 :
545 40142 : int i;
546 40142 : tree t;
547 :
548 81794 : while (parms)
549 : {
550 41652 : tree p = TREE_VALUE (parms);
551 41652 : int lvl = TMPL_PARMS_DEPTH (parms);
552 41652 : int arg_idx = 0;
553 41652 : int i;
554 41652 : tree lvl_args = NULL_TREE;
555 :
556 : /* Don't crash if we had an invalid argument list. */
557 121951 : if (TMPL_ARGS_DEPTH (args) >= lvl)
558 83292 : lvl_args = TMPL_ARGS_LEVEL (args, lvl);
559 :
560 105419 : for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
561 : {
562 63767 : tree arg = NULL_TREE;
563 :
564 : /* Don't crash if we had an invalid argument list. */
565 127528 : if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx)
566 63761 : arg = TREE_VEC_ELT (lvl_args, arg_idx);
567 :
568 63767 : tree parm_i = TREE_VEC_ELT (p, i);
569 : /* If the template argument repeats the template parameter (T = T),
570 : skip the parameter.*/
571 63732 : if (arg && TREE_CODE (arg) == TEMPLATE_TYPE_PARM
572 1032 : && arg == TYPE_MAIN_VARIANT (arg)
573 1032 : && TREE_CODE (parm_i) == TREE_LIST
574 1032 : && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL
575 1013 : && (TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i)))
576 : == TEMPLATE_TYPE_PARM)
577 64780 : && (DECL_NAME (TREE_VALUE (parm_i))
578 1013 : == DECL_NAME (TYPE_STUB_DECL (arg))))
579 559 : continue;
580 :
581 63208 : semicolon_or_introducer ();
582 63208 : dump_template_parameter (pp, parm_i, TFF_PLAIN_IDENTIFIER);
583 63208 : pp_cxx_whitespace (pp);
584 63208 : pp_equal (pp);
585 63208 : pp_cxx_whitespace (pp);
586 63208 : if (arg)
587 : {
588 63173 : if (ARGUMENT_PACK_P (arg))
589 2242 : pp_cxx_left_brace (pp);
590 63173 : dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER);
591 63173 : if (ARGUMENT_PACK_P (arg))
592 2242 : pp_cxx_right_brace (pp);
593 : }
594 : else
595 35 : pp_string (pp, M_("<missing>"));
596 :
597 63208 : ++arg_idx;
598 : }
599 :
600 41652 : parms = TREE_CHAIN (parms);
601 : }
602 :
603 : /* Don't bother with typenames for a partial instantiation. */
604 48514 : if (vec_safe_is_empty (typenames) || uses_template_parms (args))
605 31980 : return;
606 :
607 : /* Don't try to print typenames when we're processing a clone. */
608 8162 : if (current_function_decl
609 8162 : && !DECL_LANG_SPECIFIC (current_function_decl))
610 : return;
611 :
612 : /* Don't try to do this once cgraph starts throwing away front-end
613 : information. */
614 8162 : if (at_eof >= 3)
615 : return;
616 :
617 18602 : FOR_EACH_VEC_SAFE_ELT (typenames, i, t)
618 : {
619 10709 : semicolon_or_introducer ();
620 10709 : dump_type (pp, t, TFF_PLAIN_IDENTIFIER);
621 10709 : pp_cxx_whitespace (pp);
622 10709 : pp_equal (pp);
623 10709 : pp_cxx_whitespace (pp);
624 10709 : push_deferring_access_checks (dk_no_check);
625 10709 : t = tsubst (t, args, tf_none, NULL_TREE);
626 10709 : pop_deferring_access_checks ();
627 : /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
628 : pp_simple_type_specifier doesn't know about it. */
629 10709 : t = strip_typedefs (t, NULL, STF_USER_VISIBLE);
630 10709 : dump_type (pp, t, TFF_PLAIN_IDENTIFIER);
631 : }
632 40142 : }
633 :
634 : /* Dump a human-readable equivalent of the alias template
635 : specialization of T. */
636 :
637 : static void
638 7163 : dump_alias_template_specialization (cxx_pretty_printer *pp, tree t, int flags)
639 : {
640 7163 : gcc_assert (alias_template_specialization_p (t, nt_opaque));
641 :
642 7163 : tree decl = TYPE_NAME (t);
643 7163 : if (!(flags & TFF_UNQUALIFIED_NAME))
644 7163 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags);
645 7163 : pp_cxx_tree_identifier (pp, DECL_NAME (decl));
646 7163 : dump_template_parms (pp, DECL_TEMPLATE_INFO (decl),
647 : /*primary=*/false,
648 : flags & ~TFF_TEMPLATE_HEADER);
649 7163 : }
650 :
651 : /* Dump a human-readable equivalent of TYPE. FLAGS controls the
652 : format. */
653 :
654 : static void
655 214625177 : dump_type (cxx_pretty_printer *pp, tree t, int flags)
656 : {
657 214625207 : if (t == NULL_TREE)
658 : return;
659 :
660 : /* Don't print e.g. "struct mytypedef". */
661 214625193 : if (TYPE_P (t) && typedef_variant_p (t))
662 : {
663 1125113 : tree decl = TYPE_NAME (t);
664 1125113 : if ((flags & TFF_CHASE_TYPEDEF)
665 1125113 : || DECL_SELF_REFERENCE_P (decl)
666 2249631 : || (!flag_pretty_templates
667 6 : && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
668 : {
669 0 : unsigned int stf_flags = (!(pp->flags & pp_c_flag_gnu_v3)
670 601 : ? STF_USER_VISIBLE : 0);
671 601 : t = strip_typedefs (t, NULL, stf_flags);
672 : }
673 1124512 : else if (alias_template_specialization_p (t, nt_opaque))
674 : {
675 7163 : dump_alias_template_specialization (pp, t, flags);
676 7163 : return;
677 : }
678 1117349 : else if (same_type_p (t, TREE_TYPE (decl)))
679 : t = decl;
680 : else
681 : {
682 3231 : pp_cxx_cv_qualifier_seq (pp, t);
683 3231 : if (! (flags & TFF_UNQUALIFIED_NAME))
684 3231 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags);
685 3231 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
686 3231 : return;
687 : }
688 : }
689 :
690 214614799 : if (TYPE_PTRMEMFUNC_P (t))
691 169245 : goto offset_type;
692 :
693 214445554 : switch (TREE_CODE (t))
694 : {
695 441 : case LANG_TYPE:
696 441 : if (t == init_list_type_node)
697 282 : pp_string (pp, M_("<brace-enclosed initializer list>"));
698 159 : else if (t == unknown_type_node)
699 159 : pp_string (pp, M_("<unresolved overloaded function type>"));
700 : else
701 : {
702 0 : pp_cxx_cv_qualifier_seq (pp, t);
703 0 : if (tree id = TYPE_IDENTIFIER (t))
704 0 : pp_cxx_tree_identifier (pp, id);
705 : }
706 : break;
707 :
708 91 : case TREE_VEC:
709 91 : {
710 : /* A list of types used for a trait. */
711 91 : bool need_comma = false;
712 213 : for (tree arg : tree_vec_range (t))
713 : {
714 122 : if (need_comma)
715 31 : pp_separate_with_comma (pp);
716 122 : dump_type (pp, arg, flags);
717 122 : need_comma = true;
718 : }
719 : }
720 91 : break;
721 :
722 0 : case TREE_LIST:
723 : /* A list of function parms. */
724 0 : dump_parameters (pp, t, flags);
725 0 : break;
726 :
727 304 : case IDENTIFIER_NODE:
728 304 : pp_cxx_tree_identifier (pp, t);
729 304 : break;
730 :
731 24 : case TREE_BINFO:
732 24 : dump_type (pp, BINFO_TYPE (t), flags);
733 24 : break;
734 :
735 129859123 : case RECORD_TYPE:
736 129859123 : case UNION_TYPE:
737 129859123 : case ENUMERAL_TYPE:
738 129859123 : dump_aggr_type (pp, t, flags);
739 129859123 : break;
740 :
741 1114676 : case TYPE_DECL:
742 1114676 : if (flags & TFF_CHASE_TYPEDEF)
743 : {
744 0 : dump_type (pp, DECL_ORIGINAL_TYPE (t)
745 0 : ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
746 0 : break;
747 : }
748 : /* Fall through. */
749 :
750 1591619 : case TEMPLATE_DECL:
751 1591619 : case NAMESPACE_DECL:
752 1591619 : case CONST_DECL:
753 1591619 : dump_decl (pp, t, flags & ~TFF_DECL_SPECIFIERS);
754 1591619 : break;
755 :
756 56135417 : case INTEGER_TYPE:
757 56135417 : case REAL_TYPE:
758 56135417 : case VOID_TYPE:
759 56135417 : case OPAQUE_TYPE:
760 56135417 : case BOOLEAN_TYPE:
761 56135417 : case COMPLEX_TYPE:
762 56135417 : case VECTOR_TYPE:
763 56135417 : case FIXED_POINT_TYPE:
764 56135417 : pp_type_specifier_seq (pp, t);
765 56135417 : break;
766 :
767 1627 : case TEMPLATE_TEMPLATE_PARM:
768 : /* For parameters inside template signature. */
769 1627 : if (TYPE_IDENTIFIER (t))
770 3164 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
771 : else
772 45 : pp_cxx_canonical_template_parameter (pp, t);
773 : break;
774 :
775 432 : case BOUND_TEMPLATE_TEMPLATE_PARM:
776 432 : {
777 432 : tree args = TYPE_TI_ARGS (t);
778 432 : pp_cxx_cv_qualifier_seq (pp, t);
779 864 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
780 432 : pp_cxx_begin_template_argument_list (pp);
781 432 : dump_template_argument_list (pp, args, flags);
782 432 : pp_cxx_end_template_argument_list (pp);
783 : }
784 432 : break;
785 :
786 244532 : case TEMPLATE_TYPE_PARM:
787 244532 : pp_cxx_cv_qualifier_seq (pp, t);
788 244532 : if (template_placeholder_p (t))
789 : {
790 57 : tree tmpl = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t));
791 114 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (tmpl));
792 57 : pp_string (pp, "<...auto...>");
793 : }
794 244475 : else if (TYPE_IDENTIFIER (t))
795 487210 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
796 : else
797 870 : pp_cxx_canonical_template_parameter
798 870 : (pp, TEMPLATE_TYPE_PARM_INDEX (t));
799 : /* If this is a constrained placeholder, add the requirements. */
800 244532 : if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t))
801 180 : pp_cxx_constrained_type_spec (pp, c);
802 : break;
803 :
804 : /* This is not always necessary for pointers and such, but doing this
805 : reduces code size. */
806 26614620 : case ARRAY_TYPE:
807 26614620 : case POINTER_TYPE:
808 26614620 : case REFERENCE_TYPE:
809 26614620 : case OFFSET_TYPE:
810 26614620 : offset_type:
811 26614620 : case FUNCTION_TYPE:
812 26614620 : case METHOD_TYPE:
813 26614620 : {
814 26614620 : dump_type_prefix (pp, t, flags);
815 26614620 : dump_type_suffix (pp, t, flags);
816 26614620 : break;
817 : }
818 3285 : case TYPENAME_TYPE:
819 3285 : if (! (flags & TFF_CHASE_TYPEDEF)
820 3285 : && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
821 : {
822 0 : dump_decl (pp, TYPE_NAME (t), TFF_PLAIN_IDENTIFIER);
823 0 : break;
824 : }
825 3285 : pp_cxx_cv_qualifier_seq (pp, t);
826 3285 : if (const char *tag = tag_name (get_typename_tag (t)))
827 3256 : pp_cxx_ws_string (pp, tag);
828 3285 : dump_typename (pp, t, flags);
829 3285 : break;
830 :
831 6 : case UNBOUND_CLASS_TEMPLATE:
832 6 : if (! (flags & TFF_UNQUALIFIED_NAME))
833 : {
834 6 : dump_type (pp, TYPE_CONTEXT (t), flags);
835 6 : pp_cxx_colon_colon (pp);
836 : }
837 6 : pp_cxx_ws_string (pp, "template");
838 6 : dump_type (pp, TYPE_IDENTIFIER (t), flags);
839 6 : break;
840 :
841 3 : case TYPEOF_TYPE:
842 3 : pp_cxx_ws_string (pp, "__typeof__");
843 3 : pp_cxx_whitespace (pp);
844 3 : pp_cxx_left_paren (pp);
845 3 : dump_expr (pp, TYPEOF_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS);
846 3 : pp_cxx_right_paren (pp);
847 3 : break;
848 :
849 42 : case TRAIT_TYPE:
850 42 : pp_cxx_trait (pp, t);
851 42 : break;
852 :
853 35928 : case TYPE_PACK_EXPANSION:
854 35928 : dump_type (pp, PACK_EXPANSION_PATTERN (t), flags);
855 35928 : pp_cxx_ws_string (pp, "...");
856 35928 : break;
857 :
858 2 : case PACK_INDEX_TYPE:
859 2 : dump_type (pp, PACK_INDEX_PACK (t), flags);
860 2 : pp_cxx_left_bracket (pp);
861 2 : dump_expr (pp, PACK_INDEX_INDEX (t), flags & ~TFF_EXPR_IN_PARENS);
862 2 : pp_cxx_right_bracket (pp);
863 2 : break;
864 :
865 74 : case TYPE_ARGUMENT_PACK:
866 74 : dump_template_argument (pp, t, flags);
867 74 : break;
868 :
869 755 : case DECLTYPE_TYPE:
870 755 : pp_cxx_ws_string (pp, "decltype");
871 755 : pp_cxx_whitespace (pp);
872 755 : pp_cxx_left_paren (pp);
873 755 : dump_expr (pp, DECLTYPE_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS);
874 755 : pp_cxx_right_paren (pp);
875 755 : break;
876 :
877 125317 : case NULLPTR_TYPE:
878 125317 : pp_cxx_ws_string (pp, "std::nullptr_t");
879 125317 : break;
880 :
881 1116 : case META_TYPE:
882 1116 : pp_cxx_ws_string (pp, "std::meta::info");
883 1116 : break;
884 :
885 12 : case SPLICE_SCOPE:
886 12 : dump_expr (pp, SPLICE_SCOPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS);
887 12 : break;
888 :
889 0 : default:
890 0 : pp_unsupported_tree (pp, t);
891 : /* Fall through. */
892 :
893 29 : case ERROR_MARK:
894 29 : pp_string (pp, M_("<type error>"));
895 29 : break;
896 : }
897 : }
898 :
899 : /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
900 : a TYPENAME_TYPE. */
901 :
902 : static void
903 3783 : dump_typename (cxx_pretty_printer *pp, tree t, int flags)
904 : {
905 3783 : tree ctx = TYPE_CONTEXT (t);
906 :
907 3783 : if (TREE_CODE (ctx) == TYPENAME_TYPE)
908 498 : dump_typename (pp, ctx, flags);
909 : else
910 3285 : dump_type (pp, ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
911 3783 : pp_cxx_colon_colon (pp);
912 3783 : dump_decl (pp, TYPENAME_TYPE_FULLNAME (t), flags);
913 3783 : }
914 :
915 : /* Return the name of the supplied aggregate, or enumeral type. */
916 :
917 : const char *
918 130032484 : class_key_or_enum_as_string (tree t)
919 : {
920 130032484 : if (TREE_CODE (t) == ENUMERAL_TYPE)
921 : {
922 2453347 : if (SCOPED_ENUM_P (t))
923 : return "enum class";
924 : else
925 1164460 : return "enum";
926 : }
927 127579137 : else if (TREE_CODE (t) == UNION_TYPE)
928 : return "union";
929 126895869 : else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
930 34152739 : return "class";
931 : else
932 : return "struct";
933 : }
934 :
935 : /* Disable warnings about missing quoting in GCC diagnostics for
936 : the pp_verbatim call. Their format strings deliberately don't
937 : follow GCC diagnostic conventions. */
938 : #if __GNUC__ >= 10
939 : #pragma GCC diagnostic push
940 : #pragma GCC diagnostic ignored "-Wformat-diag"
941 : #endif
942 :
943 : /* Print out a class declaration T under the control of FLAGS,
944 : in the form `class foo'. */
945 :
946 : static void
947 130032375 : dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags)
948 : {
949 130032375 : const char *variety = class_key_or_enum_as_string (t);
950 130032375 : int typdef = 0;
951 130032375 : int tmplate = 0;
952 :
953 130032375 : pp_cxx_cv_qualifier_seq (pp, t);
954 :
955 130032375 : if (flags & TFF_CLASS_KEY_OR_ENUM)
956 11840 : pp_cxx_ws_string (pp, variety);
957 :
958 130032375 : tree decl = TYPE_NAME (t);
959 :
960 130032375 : if (decl)
961 : {
962 130032375 : typdef = (!DECL_ARTIFICIAL (decl)
963 : /* An alias specialization is not considered to be a
964 : typedef. */
965 130032375 : && !alias_template_specialization_p (t, nt_opaque));
966 :
967 330961 : if ((typdef
968 330961 : && ((flags & TFF_CHASE_TYPEDEF)
969 330961 : || (!flag_pretty_templates && DECL_LANG_SPECIFIC (decl)
970 0 : && DECL_TEMPLATE_INFO (decl))))
971 130032375 : || DECL_SELF_REFERENCE_P (decl))
972 : {
973 0 : t = TYPE_MAIN_VARIANT (t);
974 0 : decl = TYPE_NAME (t);
975 0 : typdef = 0;
976 : }
977 :
978 129701414 : tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
979 127248174 : && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
980 218099739 : && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
981 88067364 : || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
982 :
983 130032375 : if (! (flags & TFF_UNQUALIFIED_NAME))
984 82486072 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags | TFF_SCOPE);
985 130032375 : flags &= ~TFF_UNQUALIFIED_NAME;
986 130032375 : if (tmplate)
987 : {
988 : /* Because the template names are mangled, we have to locate
989 : the most general template, and use that name. */
990 86212869 : tree tpl = TYPE_TI_TEMPLATE (t);
991 :
992 86861063 : while (DECL_TEMPLATE_INFO (tpl))
993 648194 : tpl = DECL_TI_TEMPLATE (tpl);
994 : decl = tpl;
995 : }
996 : }
997 :
998 256928061 : if (LAMBDA_TYPE_P (t))
999 : {
1000 : /* A lambda's "type" is essentially its signature. */
1001 307708 : pp_string (pp, M_("<lambda"));
1002 307708 : tree const fn = lambda_function (t);
1003 307708 : if (fn)
1004 : {
1005 307687 : int const parm_flags
1006 307687 : = DECL_XOBJ_MEMBER_FUNCTION_P (fn) ? TFF_XOBJ_FUNC | flags
1007 120 : : flags;
1008 307687 : dump_parameters (pp, FUNCTION_FIRST_USER_PARMTYPE (fn), parm_flags);
1009 : }
1010 307708 : pp_greater (pp);
1011 : }
1012 129724667 : else if (!decl || IDENTIFIER_ANON_P (DECL_NAME (decl)))
1013 : {
1014 1811 : if (flags & TFF_CLASS_KEY_OR_ENUM)
1015 214 : pp_string (pp, M_("<unnamed>"));
1016 : else
1017 1597 : pp_printf (pp, M_("<unnamed %s>"), variety);
1018 : }
1019 : else
1020 129722856 : pp_cxx_tree_identifier (pp, DECL_NAME (decl));
1021 :
1022 130032375 : dump_module_suffix (pp, decl);
1023 :
1024 130032375 : if (tmplate)
1025 86212869 : dump_template_parms (pp, TYPE_TEMPLATE_INFO (t),
1026 86212869 : !CLASSTYPE_USE_TEMPLATE (t),
1027 : flags & ~TFF_TEMPLATE_HEADER);
1028 130032375 : }
1029 :
1030 : #if __GNUC__ >= 10
1031 : #pragma GCC diagnostic pop
1032 : #endif
1033 :
1034 : /* Dump into the obstack the initial part of the output for a given type.
1035 : This is necessary when dealing with things like functions returning
1036 : functions. Examples:
1037 :
1038 : return type of `int (* fee ())()': pointer -> function -> int. Both
1039 : pointer (and reference and offset) and function (and member) types must
1040 : deal with prefix and suffix.
1041 :
1042 : Arrays must also do this for DECL nodes, like int a[], and for things like
1043 : int *[]&. */
1044 :
1045 : static void
1046 55588487 : dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags)
1047 : {
1048 56827568 : if (TYPE_PTRMEMFUNC_P (t))
1049 : {
1050 173090 : t = TYPE_PTRMEMFUNC_FN_TYPE (t);
1051 173090 : goto offset_type;
1052 : }
1053 :
1054 56654478 : switch (TREE_CODE (t))
1055 : {
1056 28474509 : case POINTER_TYPE:
1057 28474509 : case REFERENCE_TYPE:
1058 28474509 : {
1059 28474509 : tree sub = TREE_TYPE (t);
1060 :
1061 28474509 : dump_type_prefix (pp, sub, flags);
1062 28474509 : if (TREE_CODE (sub) == ARRAY_TYPE
1063 28305773 : || TREE_CODE (sub) == FUNCTION_TYPE)
1064 : {
1065 430122 : pp_cxx_whitespace (pp);
1066 430122 : pp_cxx_left_paren (pp);
1067 : /* If we're dealing with the GNU form of attributes, print this:
1068 : void (__attribute__((noreturn)) *f) ();
1069 : If it is the standard [[]] attribute, we'll print the attribute
1070 : in dump_type_suffix. */
1071 430122 : if (!cxx11_attribute_p (TYPE_ATTRIBUTES (sub)))
1072 430117 : pp_c_attributes_display (pp, TYPE_ATTRIBUTES (sub));
1073 : }
1074 28474509 : if (TYPE_PTR_P (t))
1075 15660101 : pp_star (pp);
1076 12814408 : else if (TYPE_REF_P (t))
1077 : {
1078 12814408 : if (TYPE_REF_IS_RVALUE (t))
1079 1910429 : pp_ampersand_ampersand (pp);
1080 : else
1081 10903979 : pp_ampersand (pp);
1082 : }
1083 28474509 : pp->set_padding (pp_before);
1084 28474509 : pp_cxx_cv_qualifier_seq (pp, t);
1085 : }
1086 28474509 : break;
1087 :
1088 182252 : case OFFSET_TYPE:
1089 182252 : offset_type:
1090 182252 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1091 182252 : if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
1092 : {
1093 9162 : pp_maybe_space (pp);
1094 9162 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1095 436 : pp_cxx_left_paren (pp);
1096 9162 : dump_type (pp, TYPE_OFFSET_BASETYPE (t), flags);
1097 9162 : pp_cxx_colon_colon (pp);
1098 : }
1099 182252 : pp_cxx_star (pp);
1100 182252 : pp_cxx_cv_qualifier_seq (pp, t);
1101 182252 : pp->set_padding (pp_before);
1102 182252 : break;
1103 :
1104 : /* This can be reached without a pointer when dealing with
1105 : templates, e.g. std::is_function. */
1106 494345 : case FUNCTION_TYPE:
1107 494345 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1108 494345 : break;
1109 :
1110 173252 : case METHOD_TYPE:
1111 173252 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1112 173252 : pp_maybe_space (pp);
1113 173252 : pp_cxx_left_paren (pp);
1114 173252 : dump_aggr_type (pp, TYPE_METHOD_BASETYPE (t), flags);
1115 173252 : pp_cxx_colon_colon (pp);
1116 173252 : break;
1117 :
1118 744736 : case ARRAY_TYPE:
1119 744736 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1120 744736 : break;
1121 :
1122 26758443 : case ENUMERAL_TYPE:
1123 26758443 : case IDENTIFIER_NODE:
1124 26758443 : case INTEGER_TYPE:
1125 26758443 : case BOOLEAN_TYPE:
1126 26758443 : case REAL_TYPE:
1127 26758443 : case RECORD_TYPE:
1128 26758443 : case TEMPLATE_TYPE_PARM:
1129 26758443 : case TEMPLATE_TEMPLATE_PARM:
1130 26758443 : case BOUND_TEMPLATE_TEMPLATE_PARM:
1131 26758443 : case TREE_LIST:
1132 26758443 : case TYPE_DECL:
1133 26758443 : case TREE_VEC:
1134 26758443 : case UNION_TYPE:
1135 26758443 : case LANG_TYPE:
1136 26758443 : case VOID_TYPE:
1137 26758443 : case OPAQUE_TYPE:
1138 26758443 : case TYPENAME_TYPE:
1139 26758443 : case COMPLEX_TYPE:
1140 26758443 : case VECTOR_TYPE:
1141 26758443 : case TYPEOF_TYPE:
1142 26758443 : case TRAIT_TYPE:
1143 26758443 : case DECLTYPE_TYPE:
1144 26758443 : case TYPE_PACK_EXPANSION:
1145 26758443 : case FIXED_POINT_TYPE:
1146 26758443 : case NULLPTR_TYPE:
1147 26758443 : case PACK_INDEX_TYPE:
1148 26758443 : case META_TYPE:
1149 26758443 : case SPLICE_SCOPE:
1150 26758443 : dump_type (pp, t, flags);
1151 26758443 : pp->set_padding (pp_before);
1152 26758443 : break;
1153 :
1154 0 : default:
1155 0 : pp_unsupported_tree (pp, t);
1156 : /* fall through. */
1157 31 : case ERROR_MARK:
1158 31 : pp_string (pp, M_("<typeprefixerror>"));
1159 31 : break;
1160 : }
1161 55588487 : }
1162 :
1163 : /* Dump the suffix of type T, under control of FLAGS. This is the part
1164 : which appears after the identifier (or function parms). */
1165 :
1166 : static void
1167 26758811 : dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags)
1168 : {
1169 56827905 : if (TYPE_PTRMEMFUNC_P (t))
1170 173090 : t = TYPE_PTRMEMFUNC_FN_TYPE (t);
1171 :
1172 56827905 : switch (TREE_CODE (t))
1173 : {
1174 28656761 : case POINTER_TYPE:
1175 28656761 : case REFERENCE_TYPE:
1176 28656761 : case OFFSET_TYPE:
1177 28656761 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1178 28656761 : || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1179 430558 : pp_cxx_right_paren (pp);
1180 28656761 : if (TREE_CODE (t) == POINTER_TYPE)
1181 15833191 : flags |= TFF_POINTER;
1182 28656761 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1183 28656761 : break;
1184 :
1185 667597 : case FUNCTION_TYPE:
1186 667597 : case METHOD_TYPE:
1187 667597 : {
1188 667597 : tree arg;
1189 667597 : if (TREE_CODE (t) == METHOD_TYPE)
1190 : /* Can only be reached through a pointer. */
1191 173252 : pp_cxx_right_paren (pp);
1192 667597 : arg = TYPE_ARG_TYPES (t);
1193 667597 : if (TREE_CODE (t) == METHOD_TYPE)
1194 173252 : arg = TREE_CHAIN (arg);
1195 :
1196 : /* Function pointers don't have default args. Not in standard C++,
1197 : anyway; they may in g++, but we'll just pretend otherwise. */
1198 667597 : dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
1199 :
1200 667597 : pp->set_padding (pp_before);
1201 998365 : pp_cxx_cv_qualifiers (pp, type_memfn_quals (t),
1202 : TREE_CODE (t) == FUNCTION_TYPE
1203 : && (flags & TFF_POINTER));
1204 667597 : dump_ref_qualifier (pp, t, flags);
1205 667597 : if (tx_safe_fn_type_p (t))
1206 19 : pp_cxx_ws_string (pp, "transaction_safe");
1207 667597 : dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags);
1208 : /* If this is the standard [[]] attribute, print
1209 : void (*)() [[noreturn]]; */
1210 667597 : if (cxx11_attribute_p (TYPE_ATTRIBUTES (t)))
1211 : {
1212 2 : pp_space (pp);
1213 2 : pp_c_attributes_display (pp, TYPE_ATTRIBUTES (t));
1214 2 : pp->set_padding (pp_before);
1215 : }
1216 667597 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1217 667597 : break;
1218 : }
1219 :
1220 744736 : case ARRAY_TYPE:
1221 744736 : pp_maybe_space (pp);
1222 744736 : pp_cxx_left_bracket (pp);
1223 744736 : if (tree dtype = TYPE_DOMAIN (t))
1224 : {
1225 122987 : tree max = TYPE_MAX_VALUE (dtype);
1226 : /* Zero-length arrays have a null upper bound in C and SIZE_MAX
1227 : in C++. Handle both since the type might be constructed by
1228 : the middle end and end up here as a result of a warning (see
1229 : PR c++/97201). */
1230 122987 : if (!max || integer_all_onesp (max))
1231 651 : pp_character (pp, '0');
1232 122336 : else if (tree_fits_shwi_p (max))
1233 121778 : pp_wide_integer (pp, tree_to_shwi (max) + 1);
1234 : else
1235 : {
1236 558 : STRIP_NOPS (max);
1237 558 : if (TREE_CODE (max) == SAVE_EXPR)
1238 0 : max = TREE_OPERAND (max, 0);
1239 558 : if (TREE_CODE (max) == MINUS_EXPR
1240 558 : || TREE_CODE (max) == PLUS_EXPR)
1241 : {
1242 486 : max = TREE_OPERAND (max, 0);
1243 874 : while (CONVERT_EXPR_P (max))
1244 388 : max = TREE_OPERAND (max, 0);
1245 : }
1246 : else
1247 72 : max = fold_build2_loc (input_location,
1248 : PLUS_EXPR, dtype, max,
1249 : build_int_cst (dtype, 1));
1250 558 : dump_expr (pp, max, flags & ~TFF_EXPR_IN_PARENS);
1251 : }
1252 : }
1253 744736 : pp_cxx_right_bracket (pp);
1254 744736 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1255 744736 : break;
1256 :
1257 : case ENUMERAL_TYPE:
1258 : case IDENTIFIER_NODE:
1259 : case INTEGER_TYPE:
1260 : case BOOLEAN_TYPE:
1261 : case REAL_TYPE:
1262 : case RECORD_TYPE:
1263 : case TEMPLATE_TYPE_PARM:
1264 : case TEMPLATE_TEMPLATE_PARM:
1265 : case BOUND_TEMPLATE_TEMPLATE_PARM:
1266 : case TREE_LIST:
1267 : case TYPE_DECL:
1268 : case TREE_VEC:
1269 : case UNION_TYPE:
1270 : case LANG_TYPE:
1271 : case VOID_TYPE:
1272 : case OPAQUE_TYPE:
1273 : case TYPENAME_TYPE:
1274 : case COMPLEX_TYPE:
1275 : case VECTOR_TYPE:
1276 : case TYPEOF_TYPE:
1277 : case TRAIT_TYPE:
1278 : case DECLTYPE_TYPE:
1279 : case TYPE_PACK_EXPANSION:
1280 : case FIXED_POINT_TYPE:
1281 : case NULLPTR_TYPE:
1282 : case PACK_INDEX_TYPE:
1283 : case META_TYPE:
1284 : case SPLICE_SCOPE:
1285 : break;
1286 :
1287 0 : default:
1288 0 : pp_unsupported_tree (pp, t);
1289 : case ERROR_MARK:
1290 : /* Don't mark it here, we should have already done in
1291 : dump_type_prefix. */
1292 : break;
1293 : }
1294 26758811 : }
1295 :
1296 : static void
1297 72 : dump_global_iord (cxx_pretty_printer *pp, tree t)
1298 : {
1299 72 : const char *p = NULL;
1300 :
1301 72 : if (DECL_GLOBAL_CTOR_P (t))
1302 72 : p = M_("(static initializers for %s)");
1303 0 : else if (DECL_GLOBAL_DTOR_P (t))
1304 0 : p = M_("(static destructors for %s)");
1305 : else
1306 0 : gcc_unreachable ();
1307 :
1308 72 : pp_printf (pp, p, DECL_SOURCE_FILE (t));
1309 72 : }
1310 :
1311 : /* Write a representation of OpenMP "declare mapper" T to PP in a manner
1312 : suitable for error messages. */
1313 :
1314 : static void
1315 40 : dump_omp_declare_mapper (cxx_pretty_printer *pp, tree t, int flags)
1316 : {
1317 40 : pp_string (pp, "#pragma omp declare mapper");
1318 40 : if (t == NULL_TREE || t == error_mark_node)
1319 : return;
1320 40 : pp_space (pp);
1321 40 : pp_cxx_left_paren (pp);
1322 40 : if (OMP_DECLARE_MAPPER_ID (t))
1323 : {
1324 8 : pp_cxx_tree_identifier (pp, OMP_DECLARE_MAPPER_ID (t));
1325 8 : pp_colon (pp);
1326 : }
1327 40 : dump_type (pp, TREE_TYPE (t), flags);
1328 40 : pp_cxx_right_paren (pp);
1329 : }
1330 :
1331 : static void
1332 1332086 : dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
1333 : {
1334 1332086 : if (VAR_P (t) && DECL_NTTP_OBJECT_P (t))
1335 22620 : return dump_expr (pp, DECL_INITIAL (t), flags);
1336 :
1337 1309466 : if (TREE_CODE (t) == VAR_DECL
1338 26417 : && DECL_LANG_SPECIFIC (t)
1339 1315183 : && DECL_OMP_DECLARE_MAPPER_P (t))
1340 40 : return dump_omp_declare_mapper (pp, DECL_INITIAL (t), flags);
1341 :
1342 1309426 : if (flags & TFF_DECL_SPECIFIERS)
1343 : {
1344 26558 : if (concept_definition_p (t))
1345 337 : pp_cxx_ws_string (pp, "concept");
1346 26221 : else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t))
1347 510 : pp_cxx_ws_string (pp, "constexpr");
1348 :
1349 26558 : if (!concept_definition_p (t))
1350 26221 : dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME);
1351 26558 : pp_maybe_space (pp);
1352 : }
1353 1309426 : if (! (flags & TFF_UNQUALIFIED_NAME)
1354 1298037 : && TREE_CODE (t) != PARM_DECL
1355 2586928 : && (!DECL_INITIAL (t)
1356 9405 : || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX))
1357 1275964 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
1358 1309426 : flags &= ~TFF_UNQUALIFIED_NAME;
1359 1309426 : if ((flags & TFF_DECL_SPECIFIERS)
1360 26558 : && DECL_TEMPLATE_PARM_P (t)
1361 1315877 : && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t)))
1362 503 : pp_string (pp, "...");
1363 1309426 : if (DECL_NAME (t))
1364 : {
1365 1307507 : if (TREE_CODE (t) == FIELD_DECL && DECL_NORMAL_CAPTURE_P (t))
1366 : {
1367 12 : pp_less (pp);
1368 12 : pp_string (pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2);
1369 12 : pp_string (pp, " capture>");
1370 : }
1371 : else
1372 1307495 : dump_decl (pp, DECL_NAME (t), flags);
1373 : }
1374 1919 : else if (DECL_DECOMPOSITION_P (t))
1375 53 : pp_string (pp, M_("<structured bindings>"));
1376 1866 : else if (TREE_CODE (t) == FIELD_DECL && DECL_FIELD_IS_BASE (t))
1377 512 : dump_type (pp, TREE_TYPE (t), flags);
1378 : else
1379 1354 : pp_string (pp, M_("<anonymous>"));
1380 :
1381 1309426 : dump_module_suffix (pp, t);
1382 :
1383 1309426 : if (flags & TFF_DECL_SPECIFIERS)
1384 26558 : dump_type_suffix (pp, type, flags);
1385 : }
1386 :
1387 : class colorize_guard
1388 : {
1389 : bool colorize;
1390 : cxx_pretty_printer *pp;
1391 : public:
1392 92661897 : colorize_guard (bool _colorize, cxx_pretty_printer *pp, const char *name)
1393 92661897 : : colorize (_colorize && pp_show_color (pp)), pp (pp)
1394 : {
1395 92661897 : pp_string (pp, colorize_start (colorize, name));
1396 92661897 : }
1397 92661897 : ~colorize_guard ()
1398 : {
1399 92661897 : pp_string (pp, colorize_stop (colorize));
1400 92661897 : }
1401 : };
1402 :
1403 : /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1404 :
1405 : static void
1406 186688917 : dump_decl_name (cxx_pretty_printer *pp, tree t, int flags)
1407 : {
1408 : /* These special cases are duplicated here so that other functions
1409 : can feed identifiers to error and get them demangled properly. */
1410 186688917 : if (IDENTIFIER_CONV_OP_P (t))
1411 : {
1412 27 : pp_cxx_ws_string (pp, "operator");
1413 : /* Not exactly IDENTIFIER_TYPE_VALUE. */
1414 27 : dump_type (pp, TREE_TYPE (t), flags);
1415 27 : return;
1416 : }
1417 186688890 : if (dguide_name_p (t))
1418 : {
1419 863 : dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)),
1420 : TFF_UNQUALIFIED_NAME);
1421 863 : return;
1422 : }
1423 :
1424 186688027 : const char *str = IDENTIFIER_POINTER (t);
1425 186688027 : if (startswith (str, "_ZGR"))
1426 : {
1427 15 : pp_cxx_ws_string (pp, "<temporary>");
1428 15 : return;
1429 : }
1430 :
1431 186688012 : pp_cxx_tree_identifier (pp, t);
1432 : }
1433 :
1434 : /* Dump a human readable string for the decl T under control of FLAGS. */
1435 :
1436 : static void
1437 318248633 : dump_decl (cxx_pretty_printer *pp, tree t, int flags)
1438 : {
1439 318250121 : if (t == NULL_TREE)
1440 : return;
1441 :
1442 : /* If doing Objective-C++, give Objective-C a chance to demangle
1443 : Objective-C method names. */
1444 318250121 : if (c_dialect_objc ())
1445 : {
1446 0 : const char *demangled = objc_maybe_printable_name (t, flags);
1447 0 : if (demangled)
1448 : {
1449 0 : pp_string (pp, demangled);
1450 0 : return;
1451 : }
1452 : }
1453 :
1454 318250121 : switch (TREE_CODE (t))
1455 : {
1456 48836626 : case TYPE_DECL:
1457 : /* Don't say 'typedef class A' */
1458 48836626 : if (DECL_ARTIFICIAL (t) && !DECL_SELF_REFERENCE_P (t))
1459 : {
1460 47583869 : if ((flags & TFF_DECL_SPECIFIERS)
1461 47583869 : && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
1462 : {
1463 : /* Say `class T' not just `T'. */
1464 60 : pp_cxx_ws_string (pp, "class");
1465 :
1466 : /* Emit the `...' for a parameter pack. */
1467 60 : if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
1468 3 : pp_cxx_ws_string (pp, "...");
1469 : }
1470 :
1471 47583869 : dump_type (pp, TREE_TYPE (t), flags);
1472 47583869 : break;
1473 : }
1474 1252757 : if (TYPE_DECL_ALIAS_P (t)
1475 1252757 : && (flags & TFF_DECL_SPECIFIERS
1476 749241 : || flags & TFF_CLASS_KEY_OR_ENUM))
1477 : {
1478 482 : pp_cxx_ws_string (pp, "using");
1479 482 : if (! (flags & TFF_UNQUALIFIED_NAME))
1480 482 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
1481 482 : dump_decl (pp, DECL_NAME (t), flags);
1482 482 : pp_cxx_whitespace (pp);
1483 482 : pp_cxx_ws_string (pp, "=");
1484 482 : pp_cxx_whitespace (pp);
1485 505 : dump_type (pp, (DECL_ORIGINAL_TYPE (t)
1486 23 : ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t)),
1487 : flags);
1488 482 : break;
1489 : }
1490 1252275 : if ((flags & TFF_DECL_SPECIFIERS)
1491 1252275 : && !DECL_SELF_REFERENCE_P (t))
1492 11586 : pp_cxx_ws_string (pp, "typedef");
1493 1263763 : dump_simple_decl (pp, t, DECL_ORIGINAL_TYPE (t)
1494 11488 : ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
1495 : flags);
1496 1252275 : break;
1497 :
1498 49037 : case VAR_DECL:
1499 49037 : if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
1500 : {
1501 0 : pp_string (pp, M_("vtable for "));
1502 0 : gcc_assert (TYPE_P (DECL_CONTEXT (t)));
1503 0 : dump_type (pp, DECL_CONTEXT (t), flags);
1504 0 : break;
1505 : }
1506 : /* Fall through. */
1507 77460 : case FIELD_DECL:
1508 77460 : case PARM_DECL:
1509 77460 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1510 :
1511 : /* Handle variable template specializations. */
1512 77460 : if (VAR_P (t)
1513 49037 : && DECL_LANG_SPECIFIC (t)
1514 5717 : && DECL_TEMPLATE_INFO (t)
1515 79359 : && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
1516 : {
1517 1135 : pp_cxx_begin_template_argument_list (pp);
1518 1135 : tree args = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
1519 1135 : dump_template_argument_list (pp, args, flags);
1520 1135 : pp_cxx_end_template_argument_list (pp);
1521 : }
1522 : break;
1523 :
1524 0 : case RESULT_DECL:
1525 0 : pp_string (pp, M_("<return value> "));
1526 0 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1527 0 : break;
1528 :
1529 82038437 : case NAMESPACE_DECL:
1530 82038437 : if (flags & TFF_DECL_SPECIFIERS)
1531 81 : pp->declaration (t);
1532 : else
1533 : {
1534 82038356 : if (! (flags & TFF_UNQUALIFIED_NAME))
1535 82038335 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
1536 82038356 : flags &= ~TFF_UNQUALIFIED_NAME;
1537 82038356 : if (DECL_NAME (t) == NULL_TREE)
1538 : {
1539 7361 : if (!(pp->flags & pp_c_flag_gnu_v3))
1540 1654 : pp_cxx_ws_string (pp, M_("{anonymous}"));
1541 : else
1542 5707 : pp_cxx_ws_string (pp, M_("(anonymous namespace)"));
1543 : }
1544 : else
1545 82030995 : pp_cxx_tree_identifier (pp, DECL_NAME (t));
1546 : }
1547 : break;
1548 :
1549 926 : case SCOPE_REF:
1550 926 : dump_type (pp, TREE_OPERAND (t, 0), flags);
1551 926 : pp_cxx_colon_colon (pp);
1552 926 : dump_decl (pp, TREE_OPERAND (t, 1), TFF_UNQUALIFIED_NAME);
1553 926 : break;
1554 :
1555 0 : case ARRAY_REF:
1556 0 : dump_decl (pp, TREE_OPERAND (t, 0), flags);
1557 0 : pp_cxx_left_bracket (pp);
1558 0 : dump_decl (pp, TREE_OPERAND (t, 1), flags);
1559 0 : pp_cxx_right_bracket (pp);
1560 0 : break;
1561 :
1562 : /* So that we can do dump_decl on an aggr type. */
1563 1665 : case RECORD_TYPE:
1564 1665 : case UNION_TYPE:
1565 1665 : case ENUMERAL_TYPE:
1566 1665 : dump_type (pp, t, flags);
1567 1665 : break;
1568 :
1569 48 : case BIT_NOT_EXPR:
1570 : /* This is a pseudo destructor call which has not been folded into
1571 : a PSEUDO_DTOR_EXPR yet. */
1572 48 : pp_cxx_complement (pp);
1573 48 : dump_type (pp, TREE_OPERAND (t, 0), flags);
1574 48 : break;
1575 :
1576 0 : case TYPE_EXPR:
1577 0 : gcc_unreachable ();
1578 186688917 : break;
1579 :
1580 186688917 : case IDENTIFIER_NODE:
1581 186688917 : dump_decl_name (pp, t, flags);
1582 186688917 : break;
1583 :
1584 302 : case OVERLOAD:
1585 302 : if (!OVL_SINGLE_P (t))
1586 : {
1587 126 : tree ctx = ovl_scope (t);
1588 126 : if (ctx != global_namespace)
1589 : {
1590 73 : if (TYPE_P (ctx))
1591 59 : dump_type (pp, ctx, flags);
1592 : else
1593 14 : dump_decl (pp, ctx, flags);
1594 73 : pp_cxx_colon_colon (pp);
1595 : }
1596 252 : dump_decl (pp, OVL_NAME (t), flags);
1597 126 : break;
1598 : }
1599 :
1600 : /* If there's only one function, dump that. */
1601 318250121 : return dump_decl (pp, OVL_FIRST (t), flags);
1602 :
1603 141365 : case FUNCTION_DECL:
1604 141365 : if (! DECL_LANG_SPECIFIC (t))
1605 : {
1606 1467 : if (DECL_ABSTRACT_ORIGIN (t)
1607 1467 : && DECL_ABSTRACT_ORIGIN (t) != t)
1608 160 : dump_decl (pp, DECL_ABSTRACT_ORIGIN (t), flags);
1609 : else
1610 1307 : dump_function_name (pp, t, flags);
1611 : }
1612 139898 : else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
1613 72 : dump_global_iord (pp, t);
1614 : else
1615 139826 : dump_function_decl (pp, t, flags);
1616 : break;
1617 :
1618 459111 : case TEMPLATE_DECL:
1619 459111 : dump_template_decl (pp, t, flags);
1620 459111 : break;
1621 :
1622 362 : case CONCEPT_DECL:
1623 362 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1624 362 : break;
1625 :
1626 2234 : case TEMPLATE_ID_EXPR:
1627 2234 : {
1628 2234 : tree name = TREE_OPERAND (t, 0);
1629 2234 : tree args = TREE_OPERAND (t, 1);
1630 :
1631 2234 : if (TREE_CODE (name) == SPLICE_EXPR)
1632 7 : dump_expr (pp, name, flags);
1633 : else
1634 : {
1635 2761 : if (!identifier_p (name))
1636 1590 : name = OVL_NAME (name);
1637 2227 : dump_decl (pp, name, flags);
1638 : }
1639 2234 : pp_cxx_begin_template_argument_list (pp);
1640 2234 : if (args == error_mark_node)
1641 0 : pp_string (pp, M_("<template arguments error>"));
1642 2234 : else if (args)
1643 2138 : dump_template_argument_list
1644 2138 : (pp, args, flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
1645 2234 : pp_cxx_end_template_argument_list (pp);
1646 : }
1647 2234 : break;
1648 :
1649 382 : case LABEL_DECL:
1650 382 : if (DECL_NAME (t))
1651 376 : pp_cxx_tree_identifier (pp, DECL_NAME (t));
1652 : else
1653 6 : dump_generic_node (pp, t, 0, TDF_SLIM, false);
1654 : break;
1655 :
1656 2031 : case CONST_DECL:
1657 4056 : if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
1658 3529 : || (DECL_INITIAL (t) &&
1659 1498 : TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
1660 1989 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1661 42 : else if (DECL_NAME (t))
1662 42 : dump_decl (pp, DECL_NAME (t), flags);
1663 0 : else if (DECL_INITIAL (t))
1664 0 : dump_expr (pp, DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
1665 : else
1666 0 : pp_string (pp, M_("<enumerator>"));
1667 : break;
1668 :
1669 137 : case USING_DECL:
1670 137 : {
1671 137 : if (flags & TFF_DECL_SPECIFIERS)
1672 131 : pp_cxx_ws_string (pp, "using");
1673 137 : bool variadic = false;
1674 137 : if (!(flags & TFF_UNQUALIFIED_NAME))
1675 : {
1676 137 : tree scope = USING_DECL_SCOPE (t);
1677 137 : tree name = DECL_NAME (t);
1678 137 : if (PACK_EXPANSION_P (scope))
1679 : {
1680 0 : scope = PACK_EXPANSION_PATTERN (scope);
1681 : variadic = true;
1682 : }
1683 137 : if (identifier_p (name)
1684 137 : && IDENTIFIER_CONV_OP_P (name)
1685 0 : && PACK_EXPANSION_P (TREE_TYPE (name)))
1686 : {
1687 0 : name = make_conv_op_name (PACK_EXPANSION_PATTERN
1688 : (TREE_TYPE (name)));
1689 0 : variadic = true;
1690 : }
1691 137 : dump_type (pp, scope, flags);
1692 137 : pp_cxx_colon_colon (pp);
1693 : }
1694 137 : dump_decl (pp, DECL_NAME (t), flags);
1695 137 : if (variadic)
1696 0 : pp_cxx_ws_string (pp, "...");
1697 : }
1698 : break;
1699 :
1700 0 : case STATIC_ASSERT:
1701 0 : pp->declaration (t);
1702 0 : break;
1703 :
1704 58 : case BASELINK:
1705 58 : dump_decl (pp, BASELINK_FUNCTIONS (t), flags);
1706 58 : break;
1707 :
1708 0 : case TEMPLATE_TYPE_PARM:
1709 0 : if (flags & TFF_DECL_SPECIFIERS)
1710 0 : pp->declaration (t);
1711 : else
1712 0 : pp->type_id (t);
1713 : break;
1714 :
1715 9 : case UNBOUND_CLASS_TEMPLATE:
1716 9 : case TYPE_PACK_EXPANSION:
1717 9 : case TREE_BINFO:
1718 9 : dump_type (pp, t, flags);
1719 9 : break;
1720 :
1721 30 : default:
1722 30 : pp_unsupported_tree (pp, t);
1723 : /* Fall through. */
1724 :
1725 51 : case ERROR_MARK:
1726 51 : pp_string (pp, M_("<declaration error>"));
1727 51 : break;
1728 : }
1729 : }
1730 :
1731 : /* Dump a template declaration T under control of FLAGS. This means the
1732 : 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1733 :
1734 : static void
1735 460675 : dump_template_decl (cxx_pretty_printer *pp, tree t, int flags)
1736 : {
1737 460675 : tree orig_parms = DECL_TEMPLATE_PARMS (t);
1738 460675 : tree parms;
1739 460675 : int i;
1740 :
1741 460675 : if (flags & TFF_TEMPLATE_HEADER)
1742 : {
1743 8104 : for (parms = orig_parms = nreverse (orig_parms);
1744 16748 : parms;
1745 8644 : parms = TREE_CHAIN (parms))
1746 : {
1747 8644 : tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1748 8644 : int len = TREE_VEC_LENGTH (inner_parms);
1749 :
1750 8644 : if (len == 0)
1751 : {
1752 : /* Skip over the dummy template levels of a template template
1753 : parm. */
1754 298 : gcc_assert (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TEMPLATE_PARM);
1755 298 : continue;
1756 : }
1757 :
1758 8346 : pp_cxx_ws_string (pp, "template");
1759 8346 : pp_cxx_begin_template_argument_list (pp);
1760 :
1761 : /* If we've shown the template prefix, we'd better show the
1762 : parameters' and decl's type too. */
1763 8346 : flags |= TFF_DECL_SPECIFIERS;
1764 :
1765 20627 : for (i = 0; i < len; i++)
1766 : {
1767 12281 : if (i)
1768 3935 : pp_separate_with_comma (pp);
1769 12281 : dump_template_parameter (pp, TREE_VEC_ELT (inner_parms, i),
1770 : flags);
1771 : }
1772 8346 : pp_cxx_end_template_argument_list (pp);
1773 8346 : pp_cxx_whitespace (pp);
1774 : }
1775 8104 : nreverse(orig_parms);
1776 :
1777 8104 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
1778 : {
1779 : /* Say `template<arg> class TT' not just `template<arg> TT'. */
1780 304 : pp_cxx_ws_string (pp, "class");
1781 :
1782 : /* If this is a parameter pack, print the ellipsis. */
1783 304 : if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
1784 54 : pp_cxx_ws_string (pp, "...");
1785 : }
1786 :
1787 : /* Only print the requirements if we're also printing
1788 : the template header. */
1789 8104 : if (flag_concepts)
1790 7142 : if (tree ci = get_constraints (t))
1791 2481 : if (check_constraint_info (ci))
1792 2481 : if (tree reqs = CI_TEMPLATE_REQS (ci))
1793 : {
1794 2014 : pp_cxx_requires_clause (pp, reqs);
1795 2014 : pp_cxx_whitespace (pp);
1796 : }
1797 : }
1798 :
1799 :
1800 460675 : if (DECL_CLASS_TEMPLATE_P (t))
1801 325863 : dump_type (pp, TREE_TYPE (t),
1802 325863 : ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1803 325863 : | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)));
1804 134812 : else if (DECL_TEMPLATE_RESULT (t)
1805 134812 : && (VAR_P (DECL_TEMPLATE_RESULT (t))
1806 : /* Alias template. */
1807 134650 : || DECL_TYPE_TEMPLATE_P (t)
1808 : /* Concept definition. &*/
1809 6591 : || TREE_CODE (DECL_TEMPLATE_RESULT (t)) == CONCEPT_DECL))
1810 128568 : dump_decl (pp, DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME);
1811 : else
1812 : {
1813 6244 : gcc_assert (TREE_TYPE (t));
1814 6244 : switch (NEXT_CODE (t))
1815 : {
1816 6244 : case METHOD_TYPE:
1817 6244 : case FUNCTION_TYPE:
1818 6244 : dump_function_decl (pp, t, flags | TFF_TEMPLATE_NAME);
1819 6244 : break;
1820 0 : default:
1821 : /* This case can occur with some invalid code. */
1822 0 : dump_type (pp, TREE_TYPE (t),
1823 0 : (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1824 : | (flags & TFF_DECL_SPECIFIERS
1825 0 : ? TFF_CLASS_KEY_OR_ENUM : 0));
1826 : }
1827 : }
1828 460675 : }
1829 :
1830 : /* find_typenames looks through the type of the function template T
1831 : and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1832 : it finds. */
1833 :
1834 : struct find_typenames_t
1835 : {
1836 : hash_set<tree> *p_set;
1837 : vec<tree, va_gc> *typenames;
1838 : };
1839 :
1840 : static tree
1841 319237 : find_typenames_r (tree *tp, int *walk_subtrees, void *data)
1842 : {
1843 319237 : struct find_typenames_t *d = (struct find_typenames_t *)data;
1844 319237 : tree mv = NULL_TREE;
1845 :
1846 319237 : if (TYPE_P (*tp) && is_typedef_decl (TYPE_NAME (*tp)))
1847 : /* Add the type of the typedef without any additional cv-quals. */
1848 10582 : mv = TREE_TYPE (TYPE_NAME (*tp));
1849 308655 : else if (TREE_CODE (*tp) == TYPENAME_TYPE
1850 308114 : || TREE_CODE (*tp) == DECLTYPE_TYPE)
1851 : /* Add the typename without any cv-qualifiers. */
1852 710 : mv = TYPE_MAIN_VARIANT (*tp);
1853 :
1854 319237 : if (PACK_EXPANSION_P (*tp))
1855 : {
1856 : /* Don't mess with parameter packs since we don't remember
1857 : the pack expansion context for a particular typename. */
1858 1932 : *walk_subtrees = false;
1859 1932 : return NULL_TREE;
1860 : }
1861 :
1862 317305 : if (mv && (mv == *tp || !d->p_set->add (mv)))
1863 11276 : vec_safe_push (d->typenames, mv);
1864 :
1865 : return NULL_TREE;
1866 : }
1867 :
1868 : static vec<tree, va_gc> *
1869 38578 : find_typenames (tree t)
1870 : {
1871 38578 : struct find_typenames_t ft;
1872 38578 : ft.p_set = new hash_set<tree>;
1873 38578 : ft.typenames = NULL;
1874 38578 : cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)),
1875 : find_typenames_r, &ft, ft.p_set);
1876 77156 : delete ft.p_set;
1877 38578 : return ft.typenames;
1878 : }
1879 :
1880 : /* Output the "[with ...]" clause for a template instantiation T iff
1881 : TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1882 : formatting a deduction/substitution diagnostic rather than an
1883 : instantiation. */
1884 :
1885 : static void
1886 529756 : dump_substitution (cxx_pretty_printer *pp,
1887 : tree t, tree template_parms, tree template_args,
1888 : int flags)
1889 : {
1890 529756 : if (template_parms != NULL_TREE && template_args != NULL_TREE
1891 40142 : && !(flags & TFF_NO_TEMPLATE_BINDINGS))
1892 : {
1893 40142 : vec<tree, va_gc> *typenames = t ? find_typenames (t) : NULL;
1894 40142 : dump_template_bindings (pp, template_parms, template_args, typenames);
1895 : }
1896 529756 : }
1897 :
1898 : /* Dump the lambda function FN including its 'mutable' qualifier and any
1899 : template bindings. */
1900 :
1901 : static void
1902 8769 : dump_lambda_function (cxx_pretty_printer *pp,
1903 : tree fn, tree template_parms, tree template_args,
1904 : int flags)
1905 : {
1906 : /* A lambda's signature is essentially its "type". */
1907 8769 : dump_type (pp, DECL_CONTEXT (fn), flags);
1908 8769 : if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
1909 : /* Early escape. */;
1910 8743 : else if (TREE_CODE (TREE_TYPE (fn)) == FUNCTION_TYPE)
1911 : {
1912 177 : pp->set_padding (pp_before);
1913 177 : pp_c_ws_string (pp, "static");
1914 : }
1915 8566 : else if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn)))
1916 8566 : & TYPE_QUAL_CONST))
1917 : {
1918 87 : pp->set_padding (pp_before);
1919 87 : pp_c_ws_string (pp, "mutable");
1920 : }
1921 8769 : dump_substitution (pp, fn, template_parms, template_args, flags);
1922 8769 : }
1923 :
1924 : /* Pretty print a function decl. There are several ways we want to print a
1925 : function declaration. The TFF_ bits in FLAGS tells us how to behave.
1926 : As error can only apply the '#' flag once to give 0 and 1 for V, there
1927 : is %D which doesn't print the throw specs, and %F which does. */
1928 :
1929 : static void
1930 542673 : dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
1931 : {
1932 542673 : tree fntype;
1933 542673 : tree parmtypes;
1934 542673 : tree cname = NULL_TREE;
1935 542673 : tree template_args = NULL_TREE;
1936 542673 : tree template_parms = NULL_TREE;
1937 542673 : int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
1938 542673 : int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
1939 542673 : tree exceptions;
1940 542673 : bool constexpr_p;
1941 542673 : tree ret = NULL_TREE;
1942 :
1943 542673 : int dump_function_name_flags = flags & ~TFF_UNQUALIFIED_NAME;
1944 542673 : flags = dump_function_name_flags & ~TFF_TEMPLATE_NAME;
1945 542673 : if (TREE_CODE (t) == TEMPLATE_DECL)
1946 6244 : t = DECL_TEMPLATE_RESULT (t);
1947 :
1948 : /* Save the exceptions, in case t is a specialization and we are
1949 : emitting an error about incompatible specifications. */
1950 542673 : exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t));
1951 :
1952 : /* Likewise for the constexpr specifier, in case t is a specialization. */
1953 542673 : constexpr_p = (DECL_DECLARED_CONSTEXPR_P (t)
1954 542673 : && !decl_implicit_constexpr_p (t));
1955 :
1956 : /* Pretty print template instantiations only. */
1957 760284 : if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t)
1958 217557 : && !(flags & TFF_NO_TEMPLATE_BINDINGS)
1959 581303 : && flag_pretty_templates)
1960 : {
1961 38603 : tree tmpl;
1962 :
1963 38603 : template_args = DECL_TI_ARGS (t);
1964 38603 : tmpl = most_general_template (t);
1965 38603 : if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1966 : {
1967 38578 : template_parms = DECL_TEMPLATE_PARMS (tmpl);
1968 38578 : t = tmpl;
1969 : }
1970 : }
1971 :
1972 554862 : if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
1973 8769 : return dump_lambda_function (pp, t, template_parms, template_args, flags);
1974 :
1975 533904 : fntype = TREE_TYPE (t);
1976 533904 : parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
1977 :
1978 533904 : if (DECL_CLASS_SCOPE_P (t))
1979 151458 : cname = DECL_CONTEXT (t);
1980 : /* This is for partially instantiated template methods. */
1981 382446 : else if (TREE_CODE (fntype) == METHOD_TYPE)
1982 3 : cname = TREE_TYPE (TREE_VALUE (parmtypes));
1983 :
1984 533904 : if (flags & TFF_DECL_SPECIFIERS)
1985 : {
1986 129520 : if (DECL_STATIC_FUNCTION_P (t))
1987 3611 : pp_cxx_ws_string (pp, "static");
1988 125909 : else if (DECL_VIRTUAL_P (t))
1989 2714 : pp_cxx_ws_string (pp, "virtual");
1990 :
1991 129520 : if (constexpr_p)
1992 : {
1993 83850 : if (DECL_IMMEDIATE_FUNCTION_P (t))
1994 330 : pp_cxx_ws_string (pp, "consteval");
1995 : else
1996 41595 : pp_cxx_ws_string (pp, "constexpr");
1997 : }
1998 : }
1999 :
2000 : /* Print the return type? */
2001 533904 : if (show_return)
2002 387678 : show_return = (!DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
2003 248924 : && !DECL_DESTRUCTOR_P (t) && !deduction_guide_p (t));
2004 117633 : if (show_return)
2005 : {
2006 117633 : ret = fndecl_declared_return_type (t);
2007 117633 : dump_type_prefix (pp, ret, flags);
2008 : }
2009 :
2010 : /* Print the function name. */
2011 533904 : if (!do_outer_scope)
2012 : /* Nothing. */;
2013 533904 : else if (cname)
2014 : {
2015 151458 : dump_type (pp, cname, flags);
2016 151458 : pp_cxx_colon_colon (pp);
2017 : }
2018 : else
2019 382446 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
2020 :
2021 : /* Name lookup for the rest of the function declarator is implicitly in the
2022 : scope of the function, so avoid printing redundant scope qualifiers. */
2023 533904 : auto cds = make_temp_override (current_dump_scope, CP_DECL_CONTEXT (t));
2024 :
2025 533904 : dump_function_name (pp, t, dump_function_name_flags);
2026 :
2027 : /* By default we need no padding here, but if we emit target_version or
2028 : target_clones then we need some. */
2029 533904 : pp->set_padding (pp_none);
2030 533904 : pp_cxx_function_target_version (pp, t);
2031 533904 : pp_cxx_maybe_whitespace (pp);
2032 533904 : pp_cxx_function_target_clones (pp, t);
2033 533904 : pp_cxx_maybe_whitespace (pp);
2034 :
2035 533904 : if (!(flags & TFF_NO_FUNCTION_ARGUMENTS))
2036 : {
2037 519423 : int const parm_flags
2038 519423 : = DECL_XOBJ_MEMBER_FUNCTION_P (t) ? TFF_XOBJ_FUNC | flags : flags;
2039 519423 : dump_parameters (pp, parmtypes, parm_flags);
2040 :
2041 519423 : if (TREE_CODE (fntype) == METHOD_TYPE)
2042 : {
2043 144244 : pp->set_padding (pp_before);
2044 144244 : pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (fntype));
2045 144244 : dump_ref_qualifier (pp, fntype, flags);
2046 : }
2047 :
2048 519423 : if (tx_safe_fn_type_p (fntype))
2049 : {
2050 18 : pp->set_padding (pp_before);
2051 18 : pp_cxx_ws_string (pp, "transaction_safe");
2052 : }
2053 :
2054 519423 : if (flags & TFF_EXCEPTION_SPECIFICATION)
2055 : {
2056 350 : pp->set_padding (pp_before);
2057 350 : dump_exception_spec (pp, exceptions, flags);
2058 : }
2059 :
2060 519423 : if (show_return)
2061 117633 : dump_type_suffix (pp, ret, flags);
2062 401790 : else if (deduction_guide_p (t))
2063 : {
2064 670 : pp->set_padding (pp_before);
2065 670 : pp_cxx_ws_string (pp, "->");
2066 670 : dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
2067 : }
2068 :
2069 519423 : if (flag_concepts)
2070 492470 : if (tree ci = get_constraints (t))
2071 58132 : if (tree reqs = CI_DECLARATOR_REQS (ci))
2072 16671 : pp_cxx_requires_clause (pp, reqs);
2073 :
2074 519423 : dump_substitution (pp, t, template_parms, template_args, flags);
2075 :
2076 1038846 : if (tree base = DECL_INHERITED_CTOR_BASE (t))
2077 : {
2078 71 : pp_cxx_ws_string (pp, "[inherited from");
2079 71 : dump_type (pp, base, TFF_PLAIN_IDENTIFIER);
2080 71 : pp_character (pp, ']');
2081 : }
2082 : }
2083 14481 : else if (template_args)
2084 : {
2085 0 : bool need_comma = false;
2086 0 : int i;
2087 0 : pp_cxx_begin_template_argument_list (pp);
2088 0 : template_args = INNERMOST_TEMPLATE_ARGS (template_args);
2089 0 : for (i = 0; i < TREE_VEC_LENGTH (template_args); ++i)
2090 : {
2091 0 : tree arg = TREE_VEC_ELT (template_args, i);
2092 0 : if (need_comma)
2093 0 : pp_separate_with_comma (pp);
2094 0 : if (ARGUMENT_PACK_P (arg))
2095 0 : pp_cxx_left_brace (pp);
2096 0 : dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER);
2097 0 : if (ARGUMENT_PACK_P (arg))
2098 0 : pp_cxx_right_brace (pp);
2099 0 : need_comma = true;
2100 : }
2101 0 : pp_cxx_end_template_argument_list (pp);
2102 : }
2103 533904 : }
2104 :
2105 : /* Print a parameter list. If this is for a member function, the
2106 : member object ptr (and any other hidden args) should have
2107 : already been removed. */
2108 :
2109 : static void
2110 1494707 : dump_parameters (cxx_pretty_printer *pp, tree parmtypes, int flags)
2111 : {
2112 1494707 : int first = 1;
2113 1494707 : flags &= ~TFF_SCOPE;
2114 1494707 : pp_cxx_left_paren (pp);
2115 :
2116 4733669 : for (first = 1; parmtypes != void_list_node;
2117 1744255 : parmtypes = TREE_CHAIN (parmtypes))
2118 : {
2119 1746442 : if (first && flags & TFF_XOBJ_FUNC)
2120 1057 : pp_string (pp, "this ");
2121 855760 : if (!first)
2122 855760 : pp_separate_with_comma (pp);
2123 1746442 : first = 0;
2124 1746442 : if (!parmtypes)
2125 : {
2126 2187 : pp_cxx_ws_string (pp, "...");
2127 2187 : break;
2128 : }
2129 :
2130 1744255 : dump_type (pp, TREE_VALUE (parmtypes), flags);
2131 :
2132 1744270 : if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes))
2133 : {
2134 6 : pp_cxx_whitespace (pp);
2135 6 : pp_equal (pp);
2136 6 : pp_cxx_whitespace (pp);
2137 6 : dump_expr (pp, TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS);
2138 : }
2139 : }
2140 :
2141 1494707 : pp_cxx_right_paren (pp);
2142 1494707 : }
2143 :
2144 : /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
2145 :
2146 : static void
2147 811841 : dump_ref_qualifier (cxx_pretty_printer *pp, tree t, int flags ATTRIBUTE_UNUSED)
2148 : {
2149 811841 : if (FUNCTION_REF_QUALIFIED (t))
2150 : {
2151 1293 : pp->set_padding (pp_before);
2152 1293 : if (FUNCTION_RVALUE_QUALIFIED (t))
2153 389 : pp_cxx_ws_string (pp, "&&");
2154 : else
2155 904 : pp_cxx_ws_string (pp, "&");
2156 : }
2157 811841 : }
2158 :
2159 : /* Print an exception specification. T is the exception specification. */
2160 :
2161 : static void
2162 667950 : dump_exception_spec (cxx_pretty_printer *pp, tree t, int flags)
2163 : {
2164 673200 : if (t && TREE_PURPOSE (t))
2165 : {
2166 5152 : pp_cxx_ws_string (pp, "noexcept");
2167 5152 : if (!integer_onep (TREE_PURPOSE (t)))
2168 : {
2169 98 : pp_cxx_whitespace (pp);
2170 98 : pp_cxx_left_paren (pp);
2171 98 : if (DEFERRED_NOEXCEPT_SPEC_P (t))
2172 3 : pp_cxx_ws_string (pp, "<uninstantiated>");
2173 : else
2174 95 : dump_expr (pp, TREE_PURPOSE (t), flags);
2175 98 : pp_cxx_right_paren (pp);
2176 : }
2177 : }
2178 662798 : else if (t)
2179 : {
2180 98 : pp_cxx_ws_string (pp, "throw");
2181 98 : pp_cxx_whitespace (pp);
2182 98 : pp_cxx_left_paren (pp);
2183 98 : if (TREE_VALUE (t) != NULL_TREE)
2184 73 : while (1)
2185 : {
2186 61 : dump_type (pp, TREE_VALUE (t), flags);
2187 61 : t = TREE_CHAIN (t);
2188 61 : if (!t)
2189 : break;
2190 12 : pp_separate_with_comma (pp);
2191 : }
2192 98 : pp_cxx_right_paren (pp);
2193 : }
2194 667950 : }
2195 :
2196 : /* Handle the function name for a FUNCTION_DECL node, grokking operators
2197 : and destructors properly. */
2198 :
2199 : static void
2200 92661897 : dump_function_name (cxx_pretty_printer *pp, tree t, int flags)
2201 : {
2202 : /* Only colorize when we're printing something before the name; in
2203 : particular, not when printing a CALL_EXPR. */
2204 92661897 : bool colorize = flags & (TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE
2205 : | TFF_TEMPLATE_HEADER);
2206 :
2207 92661897 : colorize_guard g (colorize, pp, "fnname");
2208 :
2209 92661897 : tree name = DECL_NAME (t);
2210 :
2211 : /* We can get here with a decl that was synthesized by language-
2212 : independent machinery (e.g. coverage.cc) in which case it won't
2213 : have a lang_specific structure attached and DECL_CONSTRUCTOR_P
2214 : will crash. In this case it is safe just to print out the
2215 : literal name. */
2216 92661897 : if (!DECL_LANG_SPECIFIC (t))
2217 : {
2218 6044 : pp_cxx_tree_identifier (pp, name);
2219 6044 : return;
2220 : }
2221 :
2222 92655853 : if (TREE_CODE (t) == TEMPLATE_DECL)
2223 37512 : t = DECL_TEMPLATE_RESULT (t);
2224 :
2225 : /* Don't let the user see __comp_ctor et al. */
2226 92655853 : if (DECL_CONSTRUCTOR_P (t)
2227 92655853 : || DECL_DESTRUCTOR_P (t))
2228 : {
2229 35868668 : if (LAMBDA_TYPE_P (DECL_CONTEXT (t)))
2230 198576 : name = get_identifier ("<lambda>");
2231 35500960 : else if (TYPE_UNNAMED_P (DECL_CONTEXT (t)))
2232 118 : name = get_identifier ("<constructor>");
2233 : else
2234 17750303 : name = constructor_name (DECL_CONTEXT (t));
2235 : }
2236 :
2237 185311706 : if (DECL_DESTRUCTOR_P (t))
2238 : {
2239 2257835 : pp_cxx_complement (pp);
2240 2257835 : dump_decl (pp, name, TFF_PLAIN_IDENTIFIER);
2241 : }
2242 90398018 : else if (DECL_CONV_FN_P (t))
2243 : {
2244 : /* This cannot use the hack that the operator's return
2245 : type is stashed off of its name because it may be
2246 : used for error reporting. In the case of conflicting
2247 : declarations, both will have the same name, yet
2248 : the types will be different, hence the TREE_TYPE field
2249 : of the first name will be clobbered by the second. */
2250 1500713 : pp_cxx_ws_string (pp, "operator");
2251 1500713 : dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
2252 : }
2253 : else
2254 88897305 : dump_decl (pp, name, flags);
2255 :
2256 92655853 : dump_module_suffix (pp, t);
2257 :
2258 92655853 : if (DECL_TEMPLATE_INFO (t)
2259 71505206 : && !(flags & TFF_TEMPLATE_NAME)
2260 71499280 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
2261 164099565 : && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
2262 71443687 : || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
2263 521191 : dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t),
2264 : flags);
2265 92661897 : }
2266 :
2267 : /* Dump the template parameters from the template info INFO under control of
2268 : FLAGS. PRIMARY indicates whether this is a primary template decl, or
2269 : specialization (partial or complete). For partial specializations we show
2270 : the specialized parameter values. For a primary template we show no
2271 : decoration. */
2272 :
2273 : static void
2274 86741223 : dump_template_parms (cxx_pretty_printer *pp, tree info,
2275 : int primary, int flags)
2276 : {
2277 173482446 : tree args = info ? TI_ARGS (info) : NULL_TREE;
2278 :
2279 86741223 : if (primary && flags & TFF_TEMPLATE_NAME)
2280 : return;
2281 86415320 : flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME);
2282 86415320 : pp_cxx_begin_template_argument_list (pp);
2283 :
2284 : /* Be careful only to print things when we have them, so as not
2285 : to crash producing error messages. */
2286 86415320 : if (args && !primary)
2287 : {
2288 86392140 : int len, ix;
2289 86392140 : len = get_non_default_template_args_count (args, flags);
2290 :
2291 86392140 : args = INNERMOST_TEMPLATE_ARGS (args);
2292 218311606 : for (ix = 0; ix != len; ix++)
2293 : {
2294 131919466 : tree arg = TREE_VEC_ELT (args, ix);
2295 :
2296 : /* Only print a comma if we know there is an argument coming. In
2297 : the case of an empty template argument pack, no actual
2298 : argument will be printed. */
2299 131919466 : if (ix
2300 131919466 : && (!ARGUMENT_PACK_P (arg)
2301 3148136 : || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
2302 45140103 : pp_separate_with_comma (pp);
2303 :
2304 131919466 : if (!arg)
2305 0 : pp_string (pp, M_("<template parameter error>"));
2306 : else
2307 131919466 : dump_template_argument (pp, arg, flags);
2308 : }
2309 : }
2310 23180 : else if (primary)
2311 : {
2312 23174 : tree tpl = TI_TEMPLATE (info);
2313 23174 : tree parms = DECL_TEMPLATE_PARMS (tpl);
2314 23174 : int len, ix;
2315 :
2316 23174 : parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
2317 46348 : len = parms ? TREE_VEC_LENGTH (parms) : 0;
2318 :
2319 62340 : for (ix = 0; ix != len; ix++)
2320 : {
2321 39166 : tree parm;
2322 :
2323 39166 : if (TREE_VEC_ELT (parms, ix) == error_mark_node)
2324 : {
2325 0 : pp_string (pp, M_("<template parameter error>"));
2326 0 : continue;
2327 : }
2328 :
2329 39166 : parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
2330 :
2331 39166 : if (ix)
2332 15992 : pp_separate_with_comma (pp);
2333 :
2334 39166 : dump_decl (pp, parm, flags & ~TFF_DECL_SPECIFIERS);
2335 : }
2336 : }
2337 86415320 : pp_cxx_end_template_argument_list (pp);
2338 : }
2339 :
2340 : /* Print out the arguments of CALL_EXPR T as a parenthesized list using
2341 : flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
2342 :
2343 : static void
2344 5792 : dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst)
2345 : {
2346 5792 : const int len = call_expr_nargs (t);
2347 :
2348 5792 : pp_cxx_left_paren (pp);
2349 11396 : for (int i = skipfirst; i < len; ++i)
2350 : {
2351 5604 : tree arg = get_nth_callarg (t, i);
2352 5604 : dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS);
2353 5604 : if (i + 1 < len)
2354 1688 : pp_separate_with_comma (pp);
2355 : }
2356 5792 : pp_cxx_right_paren (pp);
2357 5792 : }
2358 :
2359 : /* Print out a list of initializers (subr of dump_expr). */
2360 :
2361 : static void
2362 209 : dump_expr_list (cxx_pretty_printer *pp, tree l, int flags)
2363 : {
2364 237 : while (l)
2365 : {
2366 127 : dump_expr (pp, TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS);
2367 127 : l = TREE_CHAIN (l);
2368 127 : if (l)
2369 28 : pp_separate_with_comma (pp);
2370 : }
2371 209 : }
2372 :
2373 : /* Print out a vector of initializers (subr of dump_expr). */
2374 :
2375 : static void
2376 20538 : dump_expr_init_vec (cxx_pretty_printer *pp, vec<constructor_elt, va_gc> *v,
2377 : int flags)
2378 : {
2379 20538 : unsigned HOST_WIDE_INT idx;
2380 20538 : tree value;
2381 :
2382 43854 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2383 : {
2384 23316 : if (TREE_CODE (value) == RAW_DATA_CST)
2385 0 : for (unsigned i = 0; i < (unsigned) RAW_DATA_LENGTH (value); ++i)
2386 : {
2387 0 : if (TYPE_UNSIGNED (TREE_TYPE (value))
2388 0 : || TYPE_PRECISION (TREE_TYPE (value)) > CHAR_BIT)
2389 0 : pp_decimal_int (pp, RAW_DATA_UCHAR_ELT (value, i));
2390 : else
2391 0 : pp_decimal_int (pp, RAW_DATA_SCHAR_ELT (value, i));
2392 0 : if (i == RAW_DATA_LENGTH (value) - 1U)
2393 : break;
2394 0 : else if (i == 9 && RAW_DATA_LENGTH (value) > 20)
2395 : {
2396 0 : pp_string (pp, ", ..., ");
2397 0 : i = RAW_DATA_LENGTH (value) - 11;
2398 : }
2399 : else
2400 0 : pp_separate_with_comma (pp);
2401 : }
2402 : else
2403 23316 : dump_expr (pp, value, flags | TFF_EXPR_IN_PARENS);
2404 23316 : if (idx != v->length () - 1)
2405 2832 : pp_separate_with_comma (pp);
2406 : }
2407 20538 : }
2408 :
2409 :
2410 : /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2411 : function. Resolve it to a close relative -- in the sense of static
2412 : type -- variant being overridden. That is close to what was written in
2413 : the source code. Subroutine of dump_expr. */
2414 :
2415 : static tree
2416 143 : resolve_virtual_fun_from_obj_type_ref (tree ref)
2417 : {
2418 143 : tree obj_type = TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref));
2419 143 : HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref));
2420 143 : tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type)));
2421 280 : while (index)
2422 : {
2423 137 : fun = TREE_CHAIN (fun);
2424 137 : index -= (TARGET_VTABLE_USES_DESCRIPTORS
2425 : ? TARGET_VTABLE_USES_DESCRIPTORS : 1);
2426 : }
2427 :
2428 143 : return BV_FN (fun);
2429 : }
2430 :
2431 : /* Print out an expression E under control of FLAGS. */
2432 :
2433 : static void
2434 20696638 : dump_expr (cxx_pretty_printer *pp, tree t, int flags)
2435 : {
2436 20715491 : tree op;
2437 :
2438 20715491 : if (t == 0)
2439 : return;
2440 :
2441 20715463 : if (STATEMENT_CLASS_P (t))
2442 : {
2443 15 : pp_cxx_ws_string (pp, M_("<statement>"));
2444 15 : return;
2445 : }
2446 :
2447 20715448 : switch (TREE_CODE (t))
2448 : {
2449 70768 : case VAR_DECL:
2450 70768 : case PARM_DECL:
2451 70768 : case FIELD_DECL:
2452 70768 : case CONST_DECL:
2453 70768 : case FUNCTION_DECL:
2454 70768 : case TEMPLATE_DECL:
2455 70768 : case NAMESPACE_DECL:
2456 70768 : case LABEL_DECL:
2457 70768 : case OVERLOAD:
2458 70768 : case TYPE_DECL:
2459 70768 : case USING_DECL:
2460 70768 : case IDENTIFIER_NODE:
2461 70768 : dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
2462 : |TFF_TEMPLATE_HEADER))
2463 : | TFF_NO_TEMPLATE_BINDINGS
2464 70768 : | TFF_NO_FUNCTION_ARGUMENTS));
2465 70768 : break;
2466 :
2467 6478 : case SSA_NAME:
2468 6478 : if (SSA_NAME_VAR (t)
2469 6406 : && !DECL_ARTIFICIAL (SSA_NAME_VAR (t)))
2470 : dump_expr (pp, SSA_NAME_VAR (t), flags);
2471 : else
2472 75 : pp_cxx_ws_string (pp, M_("<unknown>"));
2473 : break;
2474 :
2475 20574754 : case VOID_CST:
2476 20574754 : case INTEGER_CST:
2477 20574754 : case REAL_CST:
2478 20574754 : case STRING_CST:
2479 20574754 : case COMPLEX_CST:
2480 20574754 : pp->constant (t);
2481 20574754 : break;
2482 :
2483 0 : case USERDEF_LITERAL:
2484 0 : pp_cxx_userdef_literal (pp, t);
2485 0 : break;
2486 :
2487 115 : case THROW_EXPR:
2488 : /* While waiting for caret diagnostics, avoid printing
2489 : __cxa_allocate_exception, __cxa_throw, and the like. */
2490 115 : pp_cxx_ws_string (pp, M_("<throw-expression>"));
2491 115 : break;
2492 :
2493 478 : case PTRMEM_CST:
2494 478 : pp_ampersand (pp);
2495 478 : dump_type (pp, PTRMEM_CST_CLASS (t), flags);
2496 478 : pp_cxx_colon_colon (pp);
2497 478 : pp_cxx_tree_identifier (pp, DECL_NAME (PTRMEM_CST_MEMBER (t)));
2498 478 : break;
2499 :
2500 447 : case COMPOUND_EXPR:
2501 447 : pp_cxx_left_paren (pp);
2502 447 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2503 447 : pp_separate_with_comma (pp);
2504 447 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2505 447 : pp_cxx_right_paren (pp);
2506 447 : break;
2507 :
2508 53 : case COND_EXPR:
2509 53 : case VEC_COND_EXPR:
2510 53 : pp_cxx_left_paren (pp);
2511 53 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2512 53 : pp_string (pp, " ? ");
2513 53 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2514 53 : pp_string (pp, " : ");
2515 53 : dump_expr (pp, TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS);
2516 53 : pp_cxx_right_paren (pp);
2517 53 : break;
2518 :
2519 248 : case SAVE_EXPR:
2520 248 : if (TREE_HAS_CONSTRUCTOR (t))
2521 : {
2522 0 : pp_cxx_ws_string (pp, "new");
2523 0 : pp_cxx_whitespace (pp);
2524 0 : dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
2525 : }
2526 : else
2527 248 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2528 : break;
2529 :
2530 5792 : case AGGR_INIT_EXPR:
2531 5792 : case CALL_EXPR:
2532 5792 : {
2533 5792 : tree fn = cp_get_callee (t);
2534 5792 : bool skipfirst = false;
2535 :
2536 : /* Deal with internal functions. */
2537 5792 : if (fn == NULL_TREE)
2538 : {
2539 3 : pp_string (pp, internal_fn_name (CALL_EXPR_IFN (t)));
2540 3 : dump_call_expr_args (pp, t, flags, skipfirst);
2541 3 : break;
2542 : }
2543 :
2544 5789 : if (TREE_CODE (fn) == ADDR_EXPR)
2545 4966 : fn = TREE_OPERAND (fn, 0);
2546 :
2547 : /* Nobody is interested in seeing the guts of vcalls. */
2548 5789 : if (TREE_CODE (fn) == OBJ_TYPE_REF)
2549 137 : fn = resolve_virtual_fun_from_obj_type_ref (fn);
2550 :
2551 5789 : if (TREE_TYPE (fn) != NULL_TREE
2552 5577 : && NEXT_CODE (fn) == METHOD_TYPE
2553 7875 : && call_expr_nargs (t))
2554 : {
2555 2083 : tree ob = get_nth_callarg (t, 0);
2556 2083 : if (is_dummy_object (ob))
2557 : /* Don't print dummy object. */;
2558 1604 : else if (TREE_CODE (ob) == ADDR_EXPR)
2559 : {
2560 1036 : dump_expr (pp, TREE_OPERAND (ob, 0),
2561 : flags | TFF_EXPR_IN_PARENS);
2562 1036 : pp_cxx_dot (pp);
2563 : }
2564 568 : else if (!is_this_parameter (ob))
2565 : {
2566 568 : dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
2567 568 : pp_cxx_arrow (pp);
2568 : }
2569 : skipfirst = true;
2570 : }
2571 5789 : if (flag_sanitize & SANITIZE_UNDEFINED
2572 5789 : && is_ubsan_builtin_p (fn))
2573 : {
2574 0 : pp_string (cxx_pp, M_("<ubsan routine call>"));
2575 0 : break;
2576 : }
2577 :
2578 5789 : if (TREE_CODE (fn) == FUNCTION_DECL
2579 5136 : && DECL_CONSTRUCTOR_P (fn)
2580 6466 : && is_dummy_object (get_nth_callarg (t, 0)))
2581 479 : dump_type (pp, DECL_CONTEXT (fn), flags);
2582 : else
2583 5310 : dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS);
2584 5789 : dump_call_expr_args (pp, t, flags, skipfirst);
2585 : }
2586 5789 : break;
2587 :
2588 1430 : case TARGET_EXPR:
2589 : /* Note that this only works for G++ target exprs. If somebody
2590 : builds a general TARGET_EXPR, there's no way to represent that
2591 : it initializes anything other that the parameter slot for the
2592 : default argument. Note we may have cleared out the first
2593 : operand in expand_expr, so don't go killing ourselves. */
2594 1430 : if (TARGET_EXPR_INITIAL (t))
2595 1430 : dump_expr (pp, TARGET_EXPR_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
2596 : break;
2597 :
2598 302 : case POINTER_PLUS_EXPR:
2599 302 : dump_binary_op (pp, "+", t, flags);
2600 302 : break;
2601 :
2602 2 : case POINTER_DIFF_EXPR:
2603 2 : dump_binary_op (pp, "-", t, flags);
2604 2 : break;
2605 :
2606 24 : case INIT_EXPR:
2607 24 : case MODIFY_EXPR:
2608 24 : dump_binary_op (pp, OVL_OP_INFO (true, NOP_EXPR)->name, t, flags);
2609 24 : break;
2610 :
2611 1649 : case PLUS_EXPR:
2612 1649 : case MINUS_EXPR:
2613 1649 : case MULT_EXPR:
2614 1649 : case TRUNC_DIV_EXPR:
2615 1649 : case TRUNC_MOD_EXPR:
2616 1649 : case MIN_EXPR:
2617 1649 : case MAX_EXPR:
2618 1649 : case LSHIFT_EXPR:
2619 1649 : case RSHIFT_EXPR:
2620 1649 : case BIT_IOR_EXPR:
2621 1649 : case BIT_XOR_EXPR:
2622 1649 : case BIT_AND_EXPR:
2623 1649 : case TRUTH_ANDIF_EXPR:
2624 1649 : case TRUTH_ORIF_EXPR:
2625 1649 : case LT_EXPR:
2626 1649 : case LE_EXPR:
2627 1649 : case GT_EXPR:
2628 1649 : case GE_EXPR:
2629 1649 : case EQ_EXPR:
2630 1649 : case NE_EXPR:
2631 1649 : case SPACESHIP_EXPR:
2632 1649 : dump_binary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags);
2633 1649 : break;
2634 :
2635 9 : case CEIL_DIV_EXPR:
2636 9 : case FLOOR_DIV_EXPR:
2637 9 : case ROUND_DIV_EXPR:
2638 9 : case RDIV_EXPR:
2639 9 : case EXACT_DIV_EXPR:
2640 9 : dump_binary_op (pp, "/", t, flags);
2641 9 : break;
2642 :
2643 0 : case CEIL_MOD_EXPR:
2644 0 : case FLOOR_MOD_EXPR:
2645 0 : case ROUND_MOD_EXPR:
2646 0 : dump_binary_op (pp, "%", t, flags);
2647 0 : break;
2648 :
2649 1793 : case COMPONENT_REF:
2650 1793 : {
2651 1793 : tree ob = TREE_OPERAND (t, 0);
2652 1793 : if (INDIRECT_REF_P (ob))
2653 : {
2654 796 : ob = TREE_OPERAND (ob, 0);
2655 796 : if (!is_this_parameter (ob)
2656 796 : && !is_dummy_object (ob))
2657 : {
2658 772 : dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
2659 772 : if (TYPE_REF_P (TREE_TYPE (ob)))
2660 201 : pp_cxx_dot (pp);
2661 : else
2662 571 : pp_cxx_arrow (pp);
2663 : }
2664 : }
2665 : else
2666 : {
2667 997 : dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
2668 997 : if (TREE_CODE (ob) != ARROW_EXPR)
2669 994 : pp_cxx_dot (pp);
2670 : }
2671 1793 : dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
2672 : }
2673 1793 : break;
2674 :
2675 271 : case ARRAY_REF:
2676 271 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2677 271 : pp_cxx_left_bracket (pp);
2678 271 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2679 271 : pp_cxx_right_bracket (pp);
2680 271 : break;
2681 :
2682 33 : case OMP_ARRAY_SECTION:
2683 33 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
2684 33 : pp_cxx_left_bracket (pp);
2685 33 : dump_expr (pp, TREE_OPERAND (t, 1), flags);
2686 33 : pp_colon (pp);
2687 33 : dump_expr (pp, TREE_OPERAND (t, 2), flags);
2688 33 : pp_cxx_right_bracket (pp);
2689 33 : break;
2690 :
2691 0 : case UNARY_PLUS_EXPR:
2692 0 : dump_unary_op (pp, "+", t, flags);
2693 0 : break;
2694 :
2695 2427 : case ADDR_EXPR:
2696 2427 : if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
2697 1681 : || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
2698 : /* An ADDR_EXPR can have reference type. In that case, we
2699 : shouldn't print the `&' doing so indicates to the user
2700 : that the expression has pointer type. */
2701 4038 : || (TREE_TYPE (t)
2702 1611 : && TYPE_REF_P (TREE_TYPE (t))))
2703 841 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2704 1586 : else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL)
2705 3 : dump_unary_op (pp, "&&", t, flags);
2706 : else
2707 1583 : dump_unary_op (pp, "&", t, flags);
2708 : break;
2709 :
2710 701 : case INDIRECT_REF:
2711 701 : if (TREE_HAS_CONSTRUCTOR (t))
2712 : {
2713 0 : t = TREE_OPERAND (t, 0);
2714 0 : gcc_assert (TREE_CODE (t) == CALL_EXPR);
2715 0 : dump_expr (pp, CALL_EXPR_FN (t), flags | TFF_EXPR_IN_PARENS);
2716 0 : dump_call_expr_args (pp, t, flags, true);
2717 : }
2718 701 : else if (is_stub_object (t))
2719 : {
2720 18 : pp_string (pp, "std::declval<");
2721 18 : if (lvalue_p (t)) /* T& */
2722 0 : dump_type (pp, TREE_TYPE (STRIP_REFERENCE_REF (t)), flags);
2723 : else /* T */
2724 18 : dump_type (pp, TREE_TYPE (t), flags);
2725 18 : pp_string (pp, ">()");
2726 : }
2727 : else
2728 : {
2729 683 : if (TREE_OPERAND (t,0) != NULL_TREE
2730 683 : && TREE_TYPE (TREE_OPERAND (t, 0))
2731 1358 : && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
2732 417 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
2733 : else
2734 266 : dump_unary_op (pp, "*", t, flags);
2735 : }
2736 : break;
2737 :
2738 575 : case MEM_REF:
2739 : /* Delegate to the base "C" pretty printer. */
2740 575 : pp->c_pretty_printer::unary_expression (t);
2741 575 : break;
2742 :
2743 0 : case TARGET_MEM_REF:
2744 : /* TARGET_MEM_REF can't appear directly from source, but can appear
2745 : during late GIMPLE optimizations and through late diagnostic we might
2746 : need to support it. Print it as dereferencing of a pointer after
2747 : cast to the TARGET_MEM_REF type, with pointer arithmetics on some
2748 : pointer to single byte types, so
2749 : *(type *)((char *) ptr + step * index + index2) if all the operands
2750 : are present and the casts are needed. */
2751 0 : pp_cxx_star (pp);
2752 0 : pp_cxx_left_paren (pp);
2753 0 : if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t)))) == NULL_TREE
2754 0 : || !integer_onep (TYPE_SIZE_UNIT
2755 : (TREE_TYPE (TREE_TYPE (TMR_BASE (t))))))
2756 : {
2757 0 : if (TYPE_SIZE_UNIT (TREE_TYPE (t))
2758 0 : && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t))))
2759 : {
2760 0 : pp_cxx_left_paren (pp);
2761 0 : dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags);
2762 : }
2763 : else
2764 : {
2765 0 : dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags);
2766 0 : pp_cxx_right_paren (pp);
2767 0 : pp_cxx_left_paren (pp);
2768 0 : pp_cxx_left_paren (pp);
2769 0 : dump_type (pp, build_pointer_type (char_type_node), flags);
2770 : }
2771 0 : pp_cxx_right_paren (pp);
2772 : }
2773 0 : else if (!same_type_p (TREE_TYPE (t),
2774 : TREE_TYPE (TREE_TYPE (TMR_BASE (t)))))
2775 : {
2776 0 : dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags);
2777 0 : pp_cxx_right_paren (pp);
2778 0 : pp_cxx_left_paren (pp);
2779 : }
2780 0 : dump_expr (pp, TMR_BASE (t), flags);
2781 0 : if (TMR_STEP (t) && TMR_INDEX (t))
2782 : {
2783 0 : pp_cxx_ws_string (pp, "+");
2784 0 : dump_expr (pp, TMR_INDEX (t), flags);
2785 0 : pp_cxx_ws_string (pp, "*");
2786 0 : dump_expr (pp, TMR_STEP (t), flags);
2787 : }
2788 0 : if (TMR_INDEX2 (t))
2789 : {
2790 0 : pp_cxx_ws_string (pp, "+");
2791 0 : dump_expr (pp, TMR_INDEX2 (t), flags);
2792 : }
2793 0 : if (!integer_zerop (TMR_OFFSET (t)))
2794 : {
2795 0 : pp_cxx_ws_string (pp, "+");
2796 0 : dump_expr (pp, fold_convert (ssizetype, TMR_OFFSET (t)), flags);
2797 : }
2798 0 : pp_cxx_right_paren (pp);
2799 0 : break;
2800 :
2801 221 : case NEGATE_EXPR:
2802 221 : case BIT_NOT_EXPR:
2803 221 : case TRUTH_NOT_EXPR:
2804 221 : case PREDECREMENT_EXPR:
2805 221 : case PREINCREMENT_EXPR:
2806 221 : dump_unary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags);
2807 221 : break;
2808 :
2809 0 : case POSTDECREMENT_EXPR:
2810 0 : case POSTINCREMENT_EXPR:
2811 0 : pp_cxx_left_paren (pp);
2812 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2813 0 : pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name);
2814 0 : pp_cxx_right_paren (pp);
2815 0 : break;
2816 :
2817 1607 : case NON_LVALUE_EXPR:
2818 : /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2819 : should be another level of INDIRECT_REF so that I don't have to do
2820 : this. */
2821 1607 : if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
2822 : {
2823 21 : tree next = TREE_TYPE (TREE_TYPE (t));
2824 :
2825 21 : while (TYPE_PTR_P (next))
2826 0 : next = TREE_TYPE (next);
2827 :
2828 21 : if (TREE_CODE (next) == FUNCTION_TYPE)
2829 : {
2830 0 : if (flags & TFF_EXPR_IN_PARENS)
2831 0 : pp_cxx_left_paren (pp);
2832 0 : pp_cxx_star (pp);
2833 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2834 0 : if (flags & TFF_EXPR_IN_PARENS)
2835 0 : pp_cxx_right_paren (pp);
2836 : break;
2837 : }
2838 : /* Else fall through. */
2839 : }
2840 1607 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2841 1607 : break;
2842 :
2843 9914 : CASE_CONVERT:
2844 9914 : case IMPLICIT_CONV_EXPR:
2845 9914 : case VIEW_CONVERT_EXPR:
2846 9914 : case EXCESS_PRECISION_EXPR:
2847 9914 : {
2848 9914 : tree op = TREE_OPERAND (t, 0);
2849 :
2850 9914 : if (location_wrapper_p (t))
2851 : {
2852 : dump_expr (pp, op, flags);
2853 : break;
2854 : }
2855 :
2856 5815 : tree ttype = TREE_TYPE (t);
2857 5815 : tree optype = TREE_TYPE (op);
2858 5815 : if (!optype)
2859 150 : optype = unknown_type_node;
2860 :
2861 5815 : if (TREE_CODE (ttype) != TREE_CODE (optype)
2862 3541 : && INDIRECT_TYPE_P (ttype)
2863 3245 : && INDIRECT_TYPE_P (optype)
2864 8982 : && same_type_p (TREE_TYPE (optype),
2865 : TREE_TYPE (ttype)))
2866 : {
2867 3119 : if (TYPE_REF_P (ttype))
2868 : {
2869 2303 : STRIP_NOPS (op);
2870 2303 : if (TREE_CODE (op) == ADDR_EXPR)
2871 1546 : dump_expr (pp, TREE_OPERAND (op, 0), flags);
2872 : else
2873 757 : dump_unary_op (pp, "*", t, flags);
2874 : }
2875 : else
2876 816 : dump_unary_op (pp, "&", t, flags);
2877 : }
2878 2696 : else if (!same_type_p (optype, ttype))
2879 : {
2880 : /* It is a cast, but we cannot tell whether it is a
2881 : reinterpret or static cast. Use the C style notation. */
2882 2399 : if (flags & TFF_EXPR_IN_PARENS)
2883 1818 : pp_cxx_left_paren (pp);
2884 2399 : pp_cxx_left_paren (pp);
2885 2399 : dump_type (pp, TREE_TYPE (t), flags);
2886 2399 : pp_cxx_right_paren (pp);
2887 2399 : dump_expr (pp, op, flags | TFF_EXPR_IN_PARENS);
2888 2399 : if (flags & TFF_EXPR_IN_PARENS)
2889 1818 : pp_cxx_right_paren (pp);
2890 : }
2891 : else
2892 : dump_expr (pp, op, flags);
2893 : break;
2894 : }
2895 :
2896 26289 : case CONSTRUCTOR:
2897 26289 : if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
2898 : {
2899 21 : tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier);
2900 :
2901 21 : if (integer_zerop (idx))
2902 : {
2903 : /* A NULL pointer-to-member constant. */
2904 8 : pp_cxx_left_paren (pp);
2905 8 : pp_cxx_left_paren (pp);
2906 8 : dump_type (pp, TREE_TYPE (t), flags);
2907 8 : pp_cxx_right_paren (pp);
2908 8 : pp_character (pp, '0');
2909 8 : pp_cxx_right_paren (pp);
2910 8 : break;
2911 : }
2912 13 : else if (tree_fits_shwi_p (idx))
2913 : {
2914 4 : tree virtuals;
2915 4 : unsigned HOST_WIDE_INT n;
2916 :
2917 4 : t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
2918 4 : t = TYPE_METHOD_BASETYPE (t);
2919 4 : virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
2920 :
2921 4 : n = tree_to_shwi (idx);
2922 :
2923 : /* Map vtable index back one, to allow for the null pointer to
2924 : member. */
2925 4 : --n;
2926 :
2927 4 : while (n > 0 && virtuals)
2928 : {
2929 0 : --n;
2930 0 : virtuals = TREE_CHAIN (virtuals);
2931 : }
2932 4 : if (virtuals)
2933 : {
2934 4 : dump_expr (pp, BV_FN (virtuals),
2935 : flags | TFF_EXPR_IN_PARENS);
2936 4 : break;
2937 : }
2938 : }
2939 : }
2940 50643 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
2941 423 : pp_string (pp, "<lambda closure object>");
2942 26277 : if (TREE_TYPE (t) && EMPTY_CONSTRUCTOR_P (t))
2943 : {
2944 5739 : dump_type (pp, TREE_TYPE (t), 0);
2945 5739 : pp_cxx_left_paren (pp);
2946 5739 : pp_cxx_right_paren (pp);
2947 : }
2948 : else
2949 : {
2950 20538 : if (!BRACE_ENCLOSED_INITIALIZER_P (t))
2951 20479 : dump_type (pp, TREE_TYPE (t), 0);
2952 20538 : pp_cxx_left_brace (pp);
2953 20538 : dump_expr_init_vec (pp, CONSTRUCTOR_ELTS (t), flags);
2954 20538 : pp_cxx_right_brace (pp);
2955 : }
2956 :
2957 : break;
2958 :
2959 25 : case OFFSET_REF:
2960 25 : {
2961 25 : tree ob = TREE_OPERAND (t, 0);
2962 25 : if (is_dummy_object (ob))
2963 : {
2964 22 : t = TREE_OPERAND (t, 1);
2965 22 : if (TREE_CODE (t) == FUNCTION_DECL)
2966 : /* A::f */
2967 0 : dump_expr (pp, t, flags | TFF_EXPR_IN_PARENS);
2968 22 : else if (BASELINK_P (t))
2969 20715510 : dump_expr (pp, OVL_FIRST (BASELINK_FUNCTIONS (t)),
2970 : flags | TFF_EXPR_IN_PARENS);
2971 : else
2972 3 : dump_decl (pp, t, flags);
2973 : }
2974 : else
2975 : {
2976 3 : if (INDIRECT_REF_P (ob))
2977 : {
2978 3 : dump_expr (pp, TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
2979 3 : pp_cxx_arrow (pp);
2980 3 : pp_cxx_star (pp);
2981 : }
2982 : else
2983 : {
2984 0 : dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
2985 0 : pp_cxx_dot (pp);
2986 0 : pp_cxx_star (pp);
2987 : }
2988 3 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2989 : }
2990 : break;
2991 : }
2992 :
2993 1469 : case TEMPLATE_PARM_INDEX:
2994 1469 : dump_decl (pp, TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS);
2995 1469 : break;
2996 :
2997 162 : case CAST_EXPR:
2998 162 : if (TREE_OPERAND (t, 0) == NULL_TREE
2999 162 : || TREE_CHAIN (TREE_OPERAND (t, 0)))
3000 : {
3001 111 : dump_type (pp, TREE_TYPE (t), flags);
3002 111 : pp_cxx_left_paren (pp);
3003 111 : dump_expr_list (pp, TREE_OPERAND (t, 0), flags);
3004 111 : pp_cxx_right_paren (pp);
3005 : }
3006 : else
3007 : {
3008 51 : pp_cxx_left_paren (pp);
3009 51 : dump_type (pp, TREE_TYPE (t), flags);
3010 51 : pp_cxx_right_paren (pp);
3011 51 : pp_cxx_left_paren (pp);
3012 51 : dump_expr_list (pp, TREE_OPERAND (t, 0), flags);
3013 51 : pp_cxx_right_paren (pp);
3014 : }
3015 : break;
3016 :
3017 31 : case STATIC_CAST_EXPR:
3018 31 : pp_cxx_ws_string (pp, "static_cast");
3019 31 : goto cast;
3020 0 : case REINTERPRET_CAST_EXPR:
3021 0 : pp_cxx_ws_string (pp, "reinterpret_cast");
3022 0 : goto cast;
3023 3 : case CONST_CAST_EXPR:
3024 3 : pp_cxx_ws_string (pp, "const_cast");
3025 3 : goto cast;
3026 0 : case DYNAMIC_CAST_EXPR:
3027 0 : pp_cxx_ws_string (pp, "dynamic_cast");
3028 34 : cast:
3029 34 : pp_cxx_begin_template_argument_list (pp);
3030 34 : dump_type (pp, TREE_TYPE (t), flags);
3031 34 : pp_cxx_end_template_argument_list (pp);
3032 34 : pp_cxx_left_paren (pp);
3033 34 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3034 34 : pp_cxx_right_paren (pp);
3035 34 : break;
3036 :
3037 3 : case ARROW_EXPR:
3038 3 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3039 3 : pp_cxx_arrow (pp);
3040 3 : break;
3041 :
3042 190 : case SIZEOF_EXPR:
3043 190 : case ALIGNOF_EXPR:
3044 190 : if (TREE_CODE (t) == SIZEOF_EXPR)
3045 172 : pp_cxx_ws_string (pp, "sizeof");
3046 18 : else if (ALIGNOF_EXPR_STD_P (t))
3047 12 : pp_cxx_ws_string (pp, "alignof");
3048 : else
3049 6 : pp_cxx_ws_string (pp, "__alignof__");
3050 190 : op = TREE_OPERAND (t, 0);
3051 190 : if (PACK_EXPANSION_P (op))
3052 : {
3053 84 : pp_string (pp, "...");
3054 84 : op = PACK_EXPANSION_PATTERN (op);
3055 : }
3056 190 : pp_cxx_whitespace (pp);
3057 190 : pp_cxx_left_paren (pp);
3058 190 : if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
3059 29 : dump_type (pp, TREE_TYPE (op), flags);
3060 161 : else if (TYPE_P (TREE_OPERAND (t, 0)))
3061 98 : dump_type (pp, op, flags);
3062 : else
3063 63 : dump_expr (pp, op, flags);
3064 190 : pp_cxx_right_paren (pp);
3065 190 : break;
3066 :
3067 0 : case AT_ENCODE_EXPR:
3068 0 : pp_cxx_ws_string (pp, "@encode");
3069 0 : pp_cxx_whitespace (pp);
3070 0 : pp_cxx_left_paren (pp);
3071 0 : dump_type (pp, TREE_OPERAND (t, 0), flags);
3072 0 : pp_cxx_right_paren (pp);
3073 0 : break;
3074 :
3075 12 : case NOEXCEPT_EXPR:
3076 12 : pp_cxx_ws_string (pp, "noexcept");
3077 12 : pp_cxx_whitespace (pp);
3078 12 : pp_cxx_left_paren (pp);
3079 12 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3080 12 : pp_cxx_right_paren (pp);
3081 12 : break;
3082 :
3083 0 : case REALPART_EXPR:
3084 0 : case IMAGPART_EXPR:
3085 0 : pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name);
3086 0 : pp_cxx_whitespace (pp);
3087 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3088 0 : break;
3089 :
3090 0 : case DEFERRED_PARSE:
3091 0 : pp_string (pp, M_("<unparsed>"));
3092 0 : break;
3093 :
3094 0 : case TRY_CATCH_EXPR:
3095 0 : case CLEANUP_POINT_EXPR:
3096 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3097 0 : break;
3098 :
3099 0 : case PSEUDO_DTOR_EXPR:
3100 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3101 0 : pp_cxx_dot (pp);
3102 0 : if (TREE_OPERAND (t, 1))
3103 : {
3104 0 : dump_type (pp, TREE_OPERAND (t, 1), flags);
3105 0 : pp_cxx_colon_colon (pp);
3106 : }
3107 0 : pp_cxx_complement (pp);
3108 0 : dump_type (pp, TREE_OPERAND (t, 2), flags);
3109 0 : break;
3110 :
3111 1380 : case TEMPLATE_ID_EXPR:
3112 1380 : dump_decl (pp, t, flags);
3113 1380 : break;
3114 :
3115 28 : case BIND_EXPR:
3116 28 : case STMT_EXPR:
3117 28 : case EXPR_STMT:
3118 28 : case STATEMENT_LIST:
3119 : /* We don't yet have a way of dumping statements in a
3120 : human-readable format. */
3121 28 : pp_string (pp, "({...})");
3122 28 : break;
3123 :
3124 0 : case LOOP_EXPR:
3125 0 : pp_string (pp, "while (1) { ");
3126 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
3127 0 : pp_cxx_right_brace (pp);
3128 0 : break;
3129 :
3130 0 : case EXIT_EXPR:
3131 0 : pp_string (pp, "if (");
3132 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
3133 0 : pp_string (pp, ") break; ");
3134 0 : break;
3135 :
3136 133 : case BASELINK:
3137 133 : dump_expr (pp, BASELINK_FUNCTIONS (t), flags & ~TFF_EXPR_IN_PARENS);
3138 133 : break;
3139 :
3140 356 : case EMPTY_CLASS_EXPR:
3141 356 : dump_type (pp, TREE_TYPE (t), flags);
3142 356 : pp_cxx_left_paren (pp);
3143 356 : pp_cxx_right_paren (pp);
3144 356 : break;
3145 :
3146 0 : case ARGUMENT_PACK_SELECT:
3147 0 : dump_template_argument (pp, ARGUMENT_PACK_SELECT_FROM_PACK (t), flags);
3148 0 : break;
3149 :
3150 91 : case RECORD_TYPE:
3151 91 : case UNION_TYPE:
3152 91 : case ENUMERAL_TYPE:
3153 91 : case REAL_TYPE:
3154 91 : case VOID_TYPE:
3155 91 : case OPAQUE_TYPE:
3156 91 : case BOOLEAN_TYPE:
3157 91 : case INTEGER_TYPE:
3158 91 : case COMPLEX_TYPE:
3159 91 : case VECTOR_TYPE:
3160 91 : case DECLTYPE_TYPE:
3161 91 : pp_type_specifier_seq (pp, t);
3162 91 : break;
3163 :
3164 0 : case TYPENAME_TYPE:
3165 : /* We get here when we want to print a dependent type as an
3166 : id-expression, without any disambiguator decoration. */
3167 0 : pp->id_expression (t);
3168 0 : break;
3169 :
3170 33 : case TEMPLATE_TYPE_PARM:
3171 33 : case TEMPLATE_TEMPLATE_PARM:
3172 33 : case BOUND_TEMPLATE_TEMPLATE_PARM:
3173 33 : dump_type (pp, t, flags);
3174 33 : break;
3175 :
3176 56 : case TRAIT_EXPR:
3177 56 : pp_cxx_trait (pp, t);
3178 56 : break;
3179 :
3180 3 : case VA_ARG_EXPR:
3181 3 : pp_cxx_va_arg_expression (pp, t);
3182 3 : break;
3183 :
3184 15 : case OFFSETOF_EXPR:
3185 15 : pp_cxx_offsetof_expression (pp, t);
3186 15 : break;
3187 :
3188 0 : case ADDRESSOF_EXPR:
3189 0 : pp_cxx_addressof_expression (pp, t);
3190 0 : break;
3191 :
3192 923 : case SCOPE_REF:
3193 923 : dump_decl (pp, t, flags);
3194 923 : break;
3195 :
3196 2828 : case EXPR_PACK_EXPANSION:
3197 2828 : case UNARY_LEFT_FOLD_EXPR:
3198 2828 : case UNARY_RIGHT_FOLD_EXPR:
3199 2828 : case BINARY_LEFT_FOLD_EXPR:
3200 2828 : case BINARY_RIGHT_FOLD_EXPR:
3201 2828 : case TYPEID_EXPR:
3202 2828 : case MEMBER_REF:
3203 2828 : case DOTSTAR_EXPR:
3204 2828 : case NEW_EXPR:
3205 2828 : case VEC_NEW_EXPR:
3206 2828 : case DELETE_EXPR:
3207 2828 : case VEC_DELETE_EXPR:
3208 2828 : case MODOP_EXPR:
3209 2828 : case ABS_EXPR:
3210 2828 : case ABSU_EXPR:
3211 2828 : case CONJ_EXPR:
3212 2828 : case VECTOR_CST:
3213 2828 : case FIXED_CST:
3214 2828 : case UNORDERED_EXPR:
3215 2828 : case ORDERED_EXPR:
3216 2828 : case UNLT_EXPR:
3217 2828 : case UNLE_EXPR:
3218 2828 : case UNGT_EXPR:
3219 2828 : case UNGE_EXPR:
3220 2828 : case UNEQ_EXPR:
3221 2828 : case LTGT_EXPR:
3222 2828 : case COMPLEX_EXPR:
3223 2828 : case BIT_FIELD_REF:
3224 2828 : case FIX_TRUNC_EXPR:
3225 2828 : case FLOAT_EXPR:
3226 2828 : pp->expression (t);
3227 2828 : break;
3228 :
3229 0 : case PACK_INDEX_EXPR:
3230 0 : pp->expression (PACK_INDEX_PACK (t));
3231 0 : pp_cxx_left_bracket (pp);
3232 0 : pp->expression (PACK_INDEX_INDEX (t));
3233 0 : pp_cxx_right_bracket (pp);
3234 0 : break;
3235 :
3236 0 : case TRUTH_AND_EXPR:
3237 0 : case TRUTH_OR_EXPR:
3238 0 : case TRUTH_XOR_EXPR:
3239 0 : if (flags & TFF_EXPR_IN_PARENS)
3240 0 : pp_cxx_left_paren (pp);
3241 0 : pp->expression (t);
3242 0 : if (flags & TFF_EXPR_IN_PARENS)
3243 0 : pp_cxx_right_paren (pp);
3244 : break;
3245 :
3246 6 : case OBJ_TYPE_REF:
3247 6 : dump_expr (pp, resolve_virtual_fun_from_obj_type_ref (t), flags);
3248 6 : break;
3249 :
3250 111 : case LAMBDA_EXPR:
3251 111 : pp_string (pp, M_("<lambda>"));
3252 111 : break;
3253 :
3254 10 : case PAREN_EXPR:
3255 10 : pp_cxx_left_paren (pp);
3256 10 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
3257 10 : pp_cxx_right_paren (pp);
3258 10 : break;
3259 :
3260 3 : case REQUIRES_EXPR:
3261 3 : pp_cxx_requires_expr (cxx_pp, t);
3262 3 : break;
3263 :
3264 0 : case SIMPLE_REQ:
3265 0 : pp_cxx_simple_requirement (cxx_pp, t);
3266 0 : break;
3267 :
3268 0 : case TYPE_REQ:
3269 0 : pp_cxx_type_requirement (cxx_pp, t);
3270 0 : break;
3271 :
3272 0 : case COMPOUND_REQ:
3273 0 : pp_cxx_compound_requirement (cxx_pp, t);
3274 0 : break;
3275 :
3276 0 : case NESTED_REQ:
3277 0 : pp_cxx_nested_requirement (cxx_pp, t);
3278 0 : break;
3279 :
3280 945 : case ATOMIC_CONSTR:
3281 945 : case CONJ_CONSTR:
3282 945 : case DISJ_CONSTR:
3283 945 : {
3284 945 : pp_cxx_constraint (cxx_pp, t);
3285 945 : break;
3286 : }
3287 :
3288 13 : case PLACEHOLDER_EXPR:
3289 13 : pp_string (pp, M_("*this"));
3290 13 : break;
3291 :
3292 47 : case TREE_LIST:
3293 47 : dump_expr_list (pp, t, flags);
3294 47 : break;
3295 :
3296 6 : case NONTYPE_ARGUMENT_PACK:
3297 6 : {
3298 6 : tree args = ARGUMENT_PACK_ARGS (t);
3299 6 : int len = TREE_VEC_LENGTH (args);
3300 6 : pp_cxx_left_brace (pp);
3301 12 : for (int i = 0; i < len; ++i)
3302 : {
3303 6 : if (i > 0)
3304 0 : pp_separate_with_comma (pp);
3305 6 : dump_expr (pp, TREE_VEC_ELT (args, i), flags);
3306 : }
3307 6 : pp_cxx_right_brace (pp);
3308 6 : break;
3309 : }
3310 :
3311 3 : case CO_AWAIT_EXPR:
3312 3 : pp_cxx_ws_string (pp, "co_await");
3313 3 : pp_cxx_whitespace (pp);
3314 3 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3315 3 : break;
3316 :
3317 0 : case CO_YIELD_EXPR:
3318 0 : pp_cxx_ws_string (pp, "co_yield");
3319 0 : pp_cxx_whitespace (pp);
3320 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3321 0 : break;
3322 :
3323 0 : case CO_RETURN_EXPR:
3324 0 : pp_cxx_ws_string (pp, "co_return");
3325 0 : if (TREE_OPERAND (t, 0))
3326 : {
3327 0 : pp_cxx_whitespace (pp);
3328 0 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3329 : }
3330 : break;
3331 :
3332 123 : case REFLECT_EXPR:
3333 123 : {
3334 123 : tree h = REFLECT_EXPR_HANDLE (t);
3335 123 : bool any;
3336 123 : switch (REFLECT_EXPR_KIND (t))
3337 : {
3338 2 : case REFLECT_ANNOTATION:
3339 2 : pp_string (pp, "^^[[=");
3340 2 : pp->set_padding (pp_none);
3341 2 : dump_expr (pp, TREE_VALUE (TREE_VALUE (h)), flags);
3342 2 : pp_string (pp, "]]");
3343 2 : break;
3344 3 : case REFLECT_DATA_MEMBER_SPEC:
3345 3 : pp_cxx_ws_string (pp, "data_member_spec");
3346 3 : pp_string (pp, "(^^");
3347 3 : pp->set_padding (pp_none);
3348 3 : dump_type (pp, TREE_VEC_ELT (h, 0), flags);
3349 3 : pp_string (pp, ",{");
3350 3 : any = false;
3351 3 : if (TREE_VEC_ELT (h, 1))
3352 : {
3353 2 : pp_string (pp, ".name=");
3354 2 : pp_doublequote (pp);
3355 2 : pp->set_padding (pp_none);
3356 2 : dump_decl (pp, TREE_VEC_ELT (h, 1), flags);
3357 2 : pp_doublequote (pp);
3358 2 : any = true;
3359 : }
3360 3 : if (TREE_VEC_ELT (h, 2))
3361 : {
3362 1 : if (any)
3363 1 : pp_comma (pp);
3364 1 : pp_string (pp, ".alignment=");
3365 1 : pp->set_padding (pp_none);
3366 1 : dump_expr (pp, TREE_VEC_ELT (h, 2), flags);
3367 1 : any = true;
3368 : }
3369 3 : if (TREE_VEC_ELT (h, 3))
3370 : {
3371 1 : if (any)
3372 0 : pp_comma (pp);
3373 1 : pp_string (pp, ".bit_width=");
3374 1 : pp->set_padding (pp_none);
3375 1 : dump_expr (pp, TREE_VEC_ELT (h, 3), flags);
3376 1 : any = true;
3377 : }
3378 3 : if (TREE_VEC_ELT (h, 4) && !integer_zerop (TREE_VEC_ELT (h, 4)))
3379 : {
3380 1 : if (any)
3381 1 : pp_comma (pp);
3382 1 : pp_string (pp, ".no_unique_address=");
3383 1 : pp->set_padding (pp_none);
3384 1 : dump_expr (pp, TREE_VEC_ELT (h, 4), flags);
3385 1 : any = true;
3386 : }
3387 3 : if (TREE_VEC_LENGTH (h) > 5)
3388 : {
3389 1 : if (any)
3390 1 : pp_comma (pp);
3391 1 : pp_string (pp, ".annotations={");
3392 1 : pp->set_padding (pp_none);
3393 4 : for (int i = 5; i < TREE_VEC_LENGTH (h); ++i)
3394 : {
3395 3 : dump_expr (pp, TREE_VEC_ELT (h, i), flags);
3396 3 : if (i != TREE_VEC_LENGTH (h) - 1)
3397 2 : pp_comma (pp);
3398 3 : pp->set_padding (pp_none);
3399 : }
3400 1 : pp_right_brace (pp);
3401 : }
3402 3 : pp_string (pp, "})");
3403 3 : break;
3404 4 : case REFLECT_BASE:
3405 4 : {
3406 4 : pp_cxx_ws_string (pp, "bases_of");
3407 4 : pp_string (pp, "(^^");
3408 4 : pp->set_padding (pp_none);
3409 4 : tree d = direct_base_derived (h);
3410 4 : dump_type (pp, d, flags);
3411 4 : pp_string (pp, ",std::meta::access_context::unchecked())[");
3412 4 : pp->set_padding (pp_none);
3413 4 : tree binfo = TYPE_BINFO (d), base_binfo;
3414 7 : for (unsigned i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo);
3415 : i++)
3416 7 : if (base_binfo == h)
3417 : {
3418 4 : pp_wide_integer (pp, i);
3419 4 : break;
3420 : }
3421 4 : pp_string (pp, "] {aka ");
3422 4 : pp->set_padding (pp_none);
3423 4 : dump_type (pp, BINFO_TYPE (h), flags);
3424 4 : pp_right_brace (pp);
3425 4 : break;
3426 : }
3427 4 : case REFLECT_PARM:
3428 4 : {
3429 4 : pp_cxx_ws_string (pp, "parameters_of");
3430 4 : pp_string (pp, "(^^");
3431 4 : pp->set_padding (pp_none);
3432 4 : h = maybe_update_function_parm (h);
3433 4 : dump_decl (pp, DECL_CONTEXT (h), flags);
3434 4 : pp_string (pp, ")[");
3435 4 : pp->set_padding (pp_none);
3436 4 : unsigned int i = 0;
3437 4 : for (tree arg = FUNCTION_FIRST_USER_PARM (DECL_CONTEXT (h));
3438 6 : arg; arg = DECL_CHAIN (arg), ++i)
3439 6 : if (arg == h)
3440 : {
3441 4 : pp_wide_integer (pp, i);
3442 4 : break;
3443 : }
3444 4 : pp_right_bracket (pp);
3445 4 : if (MULTIPLE_NAMES_PARM_P (h))
3446 : break;
3447 3 : if (DECL_NAME (h))
3448 1 : h = DECL_NAME (h);
3449 2 : else if (tree opn = lookup_attribute ("old parm name",
3450 2 : DECL_ATTRIBUTES (h)))
3451 2 : h = TREE_VALUE (TREE_VALUE (opn));
3452 : else
3453 : break;
3454 3 : pp_string (pp, " {aka ");
3455 3 : dump_decl (pp, h, flags);
3456 3 : pp_right_brace (pp);
3457 3 : break;
3458 : }
3459 3 : case REFLECT_OBJECT:
3460 3 : pp_cxx_ws_string (pp, "std::meta::reflect_object");
3461 3 : pp_left_paren (pp);
3462 3 : pp->set_padding (pp_none);
3463 3 : dump_expr (pp, h, flags);
3464 3 : pp_right_paren (pp);
3465 3 : break;
3466 4 : case REFLECT_VALUE:
3467 4 : pp_cxx_ws_string (pp, "std::meta::reflect_constant");
3468 4 : pp_left_paren (pp);
3469 4 : pp->set_padding (pp_none);
3470 4 : dump_expr (pp, h, flags);
3471 4 : pp_right_paren (pp);
3472 4 : break;
3473 103 : default:
3474 103 : if (null_reflection_p (t))
3475 : {
3476 2 : pp_cxx_ws_string (pp, "std::meta::info{}");
3477 2 : break;
3478 : }
3479 101 : pp_string (pp, "^^");
3480 101 : pp->set_padding (pp_none);
3481 101 : if (DECL_P (h))
3482 76 : dump_decl (pp, h, flags);
3483 25 : else if (TYPE_P (h))
3484 21 : dump_type (pp, h, flags);
3485 : else
3486 : dump_expr (pp, h, flags);
3487 : break;
3488 : }
3489 : break;
3490 : }
3491 :
3492 12 : case SPLICE_EXPR:
3493 12 : pp_cxx_ws_string (pp, "[:");
3494 12 : pp_cxx_whitespace (pp);
3495 12 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3496 12 : pp_cxx_whitespace (pp);
3497 12 : pp_cxx_ws_string (pp, ":]");
3498 12 : break;
3499 :
3500 : /* This list is incomplete, but should suffice for now.
3501 : It is very important that `sorry' does not call
3502 : `report_error_function'. That could cause an infinite loop. */
3503 12 : default:
3504 12 : pp_unsupported_tree (pp, t);
3505 : /* Fall through. */
3506 48 : case ERROR_MARK:
3507 48 : pp_string (pp, M_("<expression error>"));
3508 48 : break;
3509 : }
3510 : }
3511 :
3512 : static void
3513 1986 : dump_binary_op (cxx_pretty_printer *pp, const char *opstring, tree t,
3514 : int flags)
3515 : {
3516 1986 : pp_cxx_left_paren (pp);
3517 1986 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
3518 1986 : pp_cxx_whitespace (pp);
3519 1986 : if (opstring)
3520 1986 : pp_cxx_ws_string (pp, opstring);
3521 : else
3522 0 : pp_string (pp, M_("<unknown operator>"));
3523 1986 : pp_cxx_whitespace (pp);
3524 1986 : tree op1 = TREE_OPERAND (t, 1);
3525 1986 : if (TREE_CODE (t) == POINTER_PLUS_EXPR
3526 302 : && TREE_CODE (op1) == INTEGER_CST
3527 2162 : && tree_int_cst_sign_bit (op1))
3528 : /* A pointer minus an integer is represented internally as plus a very
3529 : large number, don't expose that to users. */
3530 25 : op1 = convert (ssizetype, op1);
3531 1986 : dump_expr (pp, op1, flags | TFF_EXPR_IN_PARENS);
3532 1986 : pp_cxx_right_paren (pp);
3533 1986 : }
3534 :
3535 : static void
3536 3646 : dump_unary_op (cxx_pretty_printer *pp, const char *opstring, tree t, int flags)
3537 : {
3538 3646 : if (flags & TFF_EXPR_IN_PARENS)
3539 2231 : pp_cxx_left_paren (pp);
3540 3646 : pp_cxx_ws_string (pp, opstring);
3541 3646 : dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
3542 3646 : if (flags & TFF_EXPR_IN_PARENS)
3543 2231 : pp_cxx_right_paren (pp);
3544 3646 : }
3545 :
3546 : static void
3547 234178094 : reinit_cxx_pp (void)
3548 : {
3549 234178094 : pp_clear_output_area (cxx_pp);
3550 234178094 : cxx_pp->set_padding (pp_none);
3551 234178094 : pp_indentation (cxx_pp) = 0;
3552 234178094 : pp_needs_newline (cxx_pp) = false;
3553 234178094 : pp_show_color (cxx_pp) = false;
3554 234178094 : cxx_pp->enclosing_scope = current_function_decl;
3555 234178094 : }
3556 :
3557 : /* Same as pp_formatted_text, except the return string is a separate
3558 : copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3559 :
3560 : inline const char *
3561 234178504 : pp_ggc_formatted_text (pretty_printer *pp)
3562 : {
3563 234178504 : return ggc_strdup (pp_formatted_text (pp));
3564 : }
3565 :
3566 : /* Exported interface to stringifying types, exprs and decls under TFF_*
3567 : control. */
3568 :
3569 : const char *
3570 213 : type_as_string (tree typ, int flags)
3571 : {
3572 213 : reinit_cxx_pp ();
3573 213 : pp_translate_identifiers (cxx_pp) = false;
3574 213 : dump_type (cxx_pp, typ, flags);
3575 213 : return pp_ggc_formatted_text (cxx_pp);
3576 : }
3577 :
3578 : const char *
3579 0 : type_as_string_translate (tree typ, int flags)
3580 : {
3581 0 : reinit_cxx_pp ();
3582 0 : dump_type (cxx_pp, typ, flags);
3583 0 : return pp_ggc_formatted_text (cxx_pp);
3584 : }
3585 :
3586 : const char *
3587 3973 : expr_as_string (tree decl, int flags)
3588 : {
3589 3973 : reinit_cxx_pp ();
3590 3973 : pp_translate_identifiers (cxx_pp) = false;
3591 3973 : dump_expr (cxx_pp, decl, flags);
3592 3973 : return pp_ggc_formatted_text (cxx_pp);
3593 : }
3594 :
3595 : /* Wrap decl_as_string with options appropriate for dwarf. */
3596 :
3597 : const char *
3598 47556838 : decl_as_dwarf_string (tree decl, int flags)
3599 : {
3600 47556838 : const char *name;
3601 : /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3602 : here will be adequate to get the desired behavior. */
3603 47556838 : cxx_pp->flags |= pp_c_flag_gnu_v3;
3604 47556838 : name = decl_as_string (decl, flags);
3605 : /* Subsequent calls to the pretty printer shouldn't use this style. */
3606 47556838 : cxx_pp->flags &= ~pp_c_flag_gnu_v3;
3607 47556838 : return name;
3608 : }
3609 :
3610 : const char *
3611 47623994 : decl_as_string (tree decl, int flags)
3612 : {
3613 47623994 : reinit_cxx_pp ();
3614 47623994 : pp_translate_identifiers (cxx_pp) = false;
3615 47623994 : dump_decl (cxx_pp, decl, flags);
3616 47623994 : return pp_ggc_formatted_text (cxx_pp);
3617 : }
3618 :
3619 : const char *
3620 0 : decl_as_string_translate (tree decl, int flags)
3621 : {
3622 0 : reinit_cxx_pp ();
3623 0 : dump_decl (cxx_pp, decl, flags);
3624 0 : return pp_ggc_formatted_text (cxx_pp);
3625 : }
3626 :
3627 : /* Wrap lang_decl_name with options appropriate for dwarf. */
3628 :
3629 : const char *
3630 186247896 : lang_decl_dwarf_name (tree decl, int v, bool translate)
3631 : {
3632 186247896 : const char *name;
3633 : /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3634 : here will be adequate to get the desired behavior. */
3635 186247896 : cxx_pp->flags |= pp_c_flag_gnu_v3;
3636 186247896 : name = lang_decl_name (decl, v, translate);
3637 : /* Subsequent calls to the pretty printer shouldn't use this style. */
3638 186247896 : cxx_pp->flags &= ~pp_c_flag_gnu_v3;
3639 186247896 : return name;
3640 : }
3641 :
3642 : /* Generate the three forms of printable names for cxx_printable_name. */
3643 :
3644 : const char *
3645 186395591 : lang_decl_name (tree decl, int v, bool translate)
3646 : {
3647 186395591 : if (v >= 2)
3648 66899 : return (translate
3649 66899 : ? decl_as_string_translate (decl, TFF_DECL_SPECIFIERS)
3650 66899 : : decl_as_string (decl, TFF_DECL_SPECIFIERS));
3651 :
3652 186328692 : reinit_cxx_pp ();
3653 186328692 : pp_translate_identifiers (cxx_pp) = translate;
3654 186328692 : if (v == 1
3655 186328692 : && (DECL_CLASS_SCOPE_P (decl)
3656 85167 : || (DECL_NAMESPACE_SCOPE_P (decl)
3657 83888 : && CP_DECL_CONTEXT (decl) != global_namespace)))
3658 : {
3659 152585 : dump_type (cxx_pp, CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER);
3660 152585 : pp_cxx_colon_colon (cxx_pp);
3661 : }
3662 :
3663 186328692 : if (TREE_CODE (decl) == FUNCTION_DECL)
3664 92126686 : dump_function_name (cxx_pp, decl, TFF_PLAIN_IDENTIFIER);
3665 94202006 : else if ((DECL_NAME (decl) == NULL_TREE)
3666 94202006 : && TREE_CODE (decl) == NAMESPACE_DECL)
3667 21 : dump_decl (cxx_pp, decl, TFF_PLAIN_IDENTIFIER | TFF_UNQUALIFIED_NAME);
3668 : else
3669 94201985 : dump_decl (cxx_pp, DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
3670 :
3671 186328692 : return pp_ggc_formatted_text (cxx_pp);
3672 : }
3673 :
3674 : /* Return the location of a tree passed to %+ formats. */
3675 :
3676 : location_t
3677 2005043 : location_of (tree t)
3678 : {
3679 2005043 : if (TYPE_P (t))
3680 : {
3681 3904 : t = TYPE_MAIN_DECL (t);
3682 3904 : if (t == NULL_TREE)
3683 699 : return input_location;
3684 : }
3685 2001139 : else if (TREE_CODE (t) == OVERLOAD)
3686 39 : t = (OVL_FIRST (t) != conv_op_marker ? OVL_FIRST (t)
3687 0 : : OVL_FIRST (OVL_CHAIN (t)));
3688 :
3689 2004344 : if (DECL_P (t))
3690 1507816 : return DECL_SOURCE_LOCATION (t);
3691 496528 : if (TREE_CODE (t) == DEFERRED_PARSE)
3692 22 : return defparse_location (t);
3693 496506 : return cp_expr_loc_or_input_loc (t);
3694 : }
3695 :
3696 : /* Now the interfaces from error et al to dump_type et al. Each takes an
3697 : on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3698 : function. */
3699 :
3700 : static const char *
3701 99857 : decl_to_string (tree decl, int verbose, bool show_color)
3702 : {
3703 99857 : int flags = 0;
3704 :
3705 99857 : if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
3706 : || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
3707 3783 : flags = TFF_CLASS_KEY_OR_ENUM;
3708 99857 : if (verbose)
3709 30516 : flags |= TFF_DECL_SPECIFIERS;
3710 69341 : else if (TREE_CODE (decl) == FUNCTION_DECL)
3711 44444 : flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
3712 99857 : flags |= TFF_TEMPLATE_HEADER;
3713 :
3714 99857 : reinit_cxx_pp ();
3715 99857 : pp_show_color (cxx_pp) = show_color;
3716 99857 : dump_decl (cxx_pp, decl, flags);
3717 99857 : return pp_ggc_formatted_text (cxx_pp);
3718 : }
3719 :
3720 : const char *
3721 50861 : expr_to_string (tree decl)
3722 : {
3723 50861 : reinit_cxx_pp ();
3724 50861 : dump_expr (cxx_pp, decl, 0);
3725 50861 : return pp_ggc_formatted_text (cxx_pp);
3726 : }
3727 :
3728 : static const char *
3729 350 : fndecl_to_string (tree fndecl, int verbose)
3730 : {
3731 350 : int flags;
3732 :
3733 350 : flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS
3734 : | TFF_TEMPLATE_HEADER;
3735 350 : if (verbose)
3736 91 : flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS;
3737 350 : reinit_cxx_pp ();
3738 350 : dump_decl (cxx_pp, fndecl, flags);
3739 350 : return pp_ggc_formatted_text (cxx_pp);
3740 : }
3741 :
3742 :
3743 : static const char *
3744 0 : code_to_string (enum tree_code c)
3745 : {
3746 0 : return get_tree_code_name (c);
3747 : }
3748 :
3749 : const char *
3750 14432 : language_to_string (enum languages c)
3751 : {
3752 14432 : switch (c)
3753 : {
3754 : case lang_c:
3755 : return "C";
3756 :
3757 12 : case lang_cplusplus:
3758 12 : return "C++";
3759 :
3760 0 : default:
3761 0 : gcc_unreachable ();
3762 : }
3763 : return NULL;
3764 : }
3765 :
3766 : /* Return the proper printed version of a parameter to a C++ function. */
3767 :
3768 : static const char *
3769 1538 : parm_to_string (int p)
3770 : {
3771 1538 : reinit_cxx_pp ();
3772 1538 : if (p < 0)
3773 28 : pp_string (cxx_pp, "'this'");
3774 : else
3775 1510 : pp_decimal_int (cxx_pp, p + 1);
3776 1538 : return pp_ggc_formatted_text (cxx_pp);
3777 : }
3778 :
3779 : static const char *
3780 321 : op_to_string (bool assop, enum tree_code p)
3781 : {
3782 321 : tree id = ovl_op_identifier (assop, p);
3783 639 : return id ? IDENTIFIER_POINTER (id) : M_("<unknown>");
3784 : }
3785 :
3786 : /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3787 :
3788 : If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3789 : string in appropriate places, and *QUOTE is written to with false
3790 : to suppress pp_format's trailing close quote so that e.g.
3791 : foo_typedef {aka underlying_foo} {enum}
3792 : can be printed by "%qT" as:
3793 : `foo_typedef' {aka `underlying_foo'} {enum}
3794 : rather than:
3795 : `foo_typedef {aka underlying_foo} {enum}'
3796 : When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3797 : then a leading open quote will be added, whereas if POSTPROCESSED is false
3798 : (for handling %T) then any leading quote has already been added by
3799 : pp_format, or is not needed due to QUOTE being NULL (for template arguments
3800 : within %H and %I).
3801 :
3802 : SHOW_COLOR and HIGHLIGHT_COLOR are used to determine the colorization of
3803 : any quotes that are added. */
3804 :
3805 : static const char *
3806 63351 : type_to_string (tree typ, int verbose, bool postprocessed, bool *quote,
3807 : bool show_color, const char *highlight_color)
3808 : {
3809 63351 : int flags = 0;
3810 63351 : if (verbose)
3811 9536 : flags |= TFF_CLASS_KEY_OR_ENUM;
3812 63351 : flags |= TFF_TEMPLATE_HEADER;
3813 :
3814 63351 : reinit_cxx_pp ();
3815 63351 : pp_show_color (cxx_pp) = show_color;
3816 :
3817 63351 : if (postprocessed && quote && *quote)
3818 : {
3819 20642 : pp_begin_quote (cxx_pp, show_color);
3820 20642 : if (show_color && highlight_color)
3821 0 : pp_string (cxx_pp, colorize_start (show_color, highlight_color));
3822 : }
3823 :
3824 63351 : struct obstack *ob = pp_buffer (cxx_pp)->m_obstack;
3825 63351 : int type_start, type_len;
3826 63351 : type_start = obstack_object_size (ob);
3827 :
3828 63351 : dump_type (cxx_pp, typ, flags);
3829 :
3830 : /* Remember the end of the initial dump. */
3831 63351 : type_len = obstack_object_size (ob) - type_start;
3832 :
3833 : /* If we're printing a type that involves typedefs, also print the
3834 : stripped version. But sometimes the stripped version looks
3835 : exactly the same, so we don't want it after all. To avoid printing
3836 : it in that case, we play ugly obstack games. */
3837 63337 : if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
3838 69441 : && !uses_template_parms (typ))
3839 : {
3840 4360 : int aka_start, aka_len; char *p;
3841 4360 : tree aka = strip_typedefs (typ, NULL, STF_USER_VISIBLE);
3842 4360 : if (quote && *quote)
3843 3907 : pp_end_quote (cxx_pp, show_color);
3844 4360 : pp_string (cxx_pp, " {aka");
3845 4360 : pp_cxx_whitespace (cxx_pp);
3846 4360 : if (quote && *quote)
3847 3907 : pp_begin_quote (cxx_pp, show_color);
3848 4360 : if (highlight_color)
3849 1197 : pp_string (cxx_pp, colorize_start (show_color, highlight_color));
3850 : /* And remember the start of the aka dump. */
3851 4360 : aka_start = obstack_object_size (ob);
3852 4360 : dump_type (cxx_pp, aka, flags);
3853 4360 : aka_len = obstack_object_size (ob) - aka_start;
3854 4360 : if (quote && *quote)
3855 3907 : pp_end_quote (cxx_pp, show_color);
3856 4360 : pp_right_brace (cxx_pp);
3857 4360 : p = (char*)obstack_base (ob);
3858 : /* If they are identical, cut off the aka by unwinding the obstack. */
3859 4360 : if (type_len == aka_len
3860 939 : && memcmp (p + type_start, p+aka_start, type_len) == 0)
3861 : {
3862 : /* We can't add a '\0' here, since we may be adding a closing quote
3863 : below, and it would be hidden by the '\0'.
3864 : Instead, manually unwind the current object within the obstack
3865 : so that the insertion point is at the end of the type, before
3866 : the "' {aka". */
3867 761 : int delta = type_start + type_len - obstack_object_size (ob);
3868 761 : gcc_assert (delta <= 0);
3869 761 : obstack_blank_fast (ob, delta);
3870 761 : }
3871 : else
3872 3599 : if (quote)
3873 : /* No further closing quotes are needed. */
3874 3572 : *quote = false;
3875 : }
3876 :
3877 63324 : if (quote && *quote)
3878 : {
3879 56113 : if (show_color && highlight_color)
3880 0 : pp_string (cxx_pp, colorize_stop (show_color));
3881 56113 : pp_end_quote (cxx_pp, show_color);
3882 56113 : *quote = false;
3883 : }
3884 63351 : return pp_ggc_formatted_text (cxx_pp);
3885 : }
3886 :
3887 : static const char *
3888 3920 : args_to_string (tree p, int verbose)
3889 : {
3890 3920 : int flags = 0;
3891 3920 : if (verbose)
3892 0 : flags |= TFF_CLASS_KEY_OR_ENUM;
3893 :
3894 3920 : if (p == NULL_TREE)
3895 : return "";
3896 :
3897 3059 : if (TYPE_P (TREE_VALUE (p)))
3898 0 : return type_as_string_translate (p, flags);
3899 :
3900 3059 : reinit_cxx_pp ();
3901 9849 : for (; p; p = TREE_CHAIN (p))
3902 : {
3903 3731 : if (null_node_p (TREE_VALUE (p)))
3904 3 : pp_cxx_ws_string (cxx_pp, "NULL");
3905 : else
3906 3728 : dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags);
3907 3731 : if (TREE_CHAIN (p))
3908 672 : pp_separate_with_comma (cxx_pp);
3909 : }
3910 3059 : return pp_ggc_formatted_text (cxx_pp);
3911 : }
3912 :
3913 : /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3914 : is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3915 : arguments. */
3916 :
3917 : static const char *
3918 1564 : subst_to_string (tree p, bool show_color)
3919 : {
3920 1564 : tree decl = TREE_PURPOSE (p);
3921 1564 : tree targs = TREE_VALUE (p);
3922 1564 : tree tparms = DECL_TEMPLATE_PARMS (decl);
3923 1564 : int flags = (TFF_DECL_SPECIFIERS|TFF_TEMPLATE_HEADER
3924 : |TFF_NO_TEMPLATE_BINDINGS);
3925 :
3926 1564 : if (p == NULL_TREE)
3927 : return "";
3928 :
3929 1564 : reinit_cxx_pp ();
3930 1564 : pp_show_color (cxx_pp) = show_color;
3931 1564 : dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags);
3932 1564 : dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0);
3933 1564 : return pp_ggc_formatted_text (cxx_pp);
3934 : }
3935 :
3936 : static const char *
3937 639 : cv_to_string (tree p, int v)
3938 : {
3939 639 : reinit_cxx_pp ();
3940 639 : cxx_pp->set_padding (v ? pp_before : pp_none);
3941 639 : pp_cxx_cv_qualifier_seq (cxx_pp, p);
3942 639 : return pp_ggc_formatted_text (cxx_pp);
3943 : }
3944 :
3945 : static const char *
3946 3 : eh_spec_to_string (tree p, int /*v*/)
3947 : {
3948 3 : int flags = 0;
3949 3 : reinit_cxx_pp ();
3950 3 : dump_exception_spec (cxx_pp, p, flags);
3951 3 : return pp_ggc_formatted_text (cxx_pp);
3952 : }
3953 :
3954 : /* Langhook for print_error_function. */
3955 : void
3956 152 : cxx_print_error_function (diagnostics::text_sink &text_output,
3957 : const char *file,
3958 : const diagnostics::diagnostic_info *diagnostic)
3959 : {
3960 152 : char *prefix;
3961 152 : if (file)
3962 152 : prefix = xstrdup (file);
3963 : else
3964 : prefix = NULL;
3965 152 : lhd_print_error_function (text_output, file, diagnostic);
3966 :
3967 152 : pp_set_prefix (text_output.get_printer (), prefix);
3968 152 : maybe_print_instantiation_context (text_output);
3969 152 : }
3970 :
3971 : static void
3972 244521 : cp_diagnostic_text_starter (diagnostics::text_sink &text_output,
3973 : const diagnostics::diagnostic_info *diagnostic)
3974 : {
3975 244521 : pp_set_prefix (text_output.get_printer (),
3976 : text_output.build_indent_prefix (true));
3977 244521 : text_output.report_current_module (diagnostic_location (diagnostic));
3978 244521 : cp_print_error_function (text_output, diagnostic);
3979 244521 : maybe_print_instantiation_context (text_output);
3980 244521 : maybe_print_constexpr_context (text_output);
3981 244521 : maybe_print_constraint_context (text_output);
3982 244521 : pp_set_prefix (text_output.get_printer (),
3983 : text_output.build_prefix (*diagnostic));
3984 244521 : }
3985 :
3986 : /* Print current function onto BUFFER, in the process of reporting
3987 : a diagnostic message. Called from cp_diagnostic_starter. */
3988 : static void
3989 244521 : cp_print_error_function (diagnostics::text_sink &text_output,
3990 : const diagnostics::diagnostic_info *diagnostic)
3991 : {
3992 : /* If we are in an instantiation context, current_function_decl is likely
3993 : to be wrong, so just rely on print_instantiation_full_context. */
3994 244521 : if (current_instantiation ())
3995 : return;
3996 : /* The above is true for constraint satisfaction also. */
3997 229835 : if (current_failed_constraint)
3998 : return;
3999 229567 : diagnostics::context *const context = &text_output.get_context ();
4000 229567 : if (diagnostic_last_function_changed (context, diagnostic))
4001 : {
4002 25639 : pretty_printer *const pp = text_output.get_printer ();
4003 25639 : char *old_prefix = pp_take_prefix (pp);
4004 25639 : const char *file = LOCATION_FILE (diagnostic_location (diagnostic));
4005 25639 : tree abstract_origin = diagnostic_abstract_origin (diagnostic);
4006 25639 : char *new_prefix = (file && abstract_origin == NULL)
4007 25639 : ? text_output.file_name_as_prefix (file) : NULL;
4008 :
4009 25639 : pp_set_prefix (pp, new_prefix);
4010 :
4011 25639 : if (current_function_decl == NULL)
4012 920 : pp_string (pp, _("At global scope:"));
4013 : else
4014 : {
4015 24719 : tree fndecl, ao;
4016 :
4017 24719 : if (abstract_origin)
4018 : {
4019 404 : ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
4020 404 : gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
4021 : fndecl = ao;
4022 : }
4023 : else
4024 : fndecl = current_function_decl;
4025 :
4026 24719 : pp_printf (pp, function_category (fndecl),
4027 : fndecl);
4028 :
4029 50076 : while (abstract_origin)
4030 : {
4031 638 : location_t *locus;
4032 638 : tree block = abstract_origin;
4033 :
4034 638 : locus = &BLOCK_SOURCE_LOCATION (block);
4035 638 : fndecl = NULL;
4036 638 : block = BLOCK_SUPERCONTEXT (block);
4037 1404 : while (block && TREE_CODE (block) == BLOCK
4038 1523 : && BLOCK_ABSTRACT_ORIGIN (block))
4039 : {
4040 362 : ao = BLOCK_ABSTRACT_ORIGIN (block);
4041 362 : if (TREE_CODE (ao) == FUNCTION_DECL)
4042 : {
4043 : fndecl = ao;
4044 : break;
4045 : }
4046 128 : else if (TREE_CODE (ao) != BLOCK)
4047 : break;
4048 :
4049 128 : block = BLOCK_SUPERCONTEXT (block);
4050 : }
4051 638 : if (fndecl)
4052 : abstract_origin = block;
4053 : else
4054 : {
4055 866 : while (block && TREE_CODE (block) == BLOCK)
4056 462 : block = BLOCK_SUPERCONTEXT (block);
4057 :
4058 404 : if (block && TREE_CODE (block) == FUNCTION_DECL)
4059 : fndecl = block;
4060 : abstract_origin = NULL;
4061 : }
4062 : if (fndecl)
4063 : {
4064 638 : expanded_location s = expand_location (*locus);
4065 638 : pp_character (pp, ',');
4066 638 : pp_newline (pp);
4067 638 : if (s.file != NULL)
4068 : {
4069 638 : if (text_output.show_column_p () && s.column != 0)
4070 584 : pp_printf (pp,
4071 : G_(" inlined from %qD at %r%s:%d:%d%R"),
4072 : fndecl,
4073 : "locus", s.file, s.line, s.column);
4074 : else
4075 54 : pp_printf (pp,
4076 : G_(" inlined from %qD at %r%s:%d%R"),
4077 : fndecl,
4078 : "locus", s.file, s.line);
4079 :
4080 : }
4081 : else
4082 0 : pp_printf (pp, G_(" inlined from %qD"),
4083 : fndecl);
4084 : }
4085 : }
4086 24719 : pp_character (pp, ':');
4087 : }
4088 25639 : pp_newline (pp);
4089 :
4090 25639 : diagnostic_set_last_function (context, diagnostic);
4091 25639 : pp->set_prefix (old_prefix);
4092 : }
4093 : }
4094 :
4095 : /* Returns a description of FUNCTION using standard terminology. The
4096 : result is a format string of the form "In CATEGORY %qD". */
4097 :
4098 : static const char *
4099 24719 : function_category (tree fn)
4100 : {
4101 : /* We can get called from the middle-end for diagnostics of function
4102 : clones. Make sure we have language specific information before
4103 : dereferencing it. */
4104 24719 : if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn))
4105 24719 : && DECL_FUNCTION_MEMBER_P (fn))
4106 : {
4107 3174 : if (DECL_STATIC_FUNCTION_P (fn))
4108 : return G_("In static member function %qD");
4109 3036 : else if (DECL_COPY_CONSTRUCTOR_P (fn))
4110 : return G_("In copy constructor %qD");
4111 5990 : else if (DECL_CONSTRUCTOR_P (fn))
4112 : return G_("In constructor %qD");
4113 2015 : else if (DECL_DESTRUCTOR_P (fn))
4114 : return G_("In destructor %qD");
4115 2472 : else if (LAMBDA_FUNCTION_P (fn))
4116 : return G_("In lambda function");
4117 1320 : else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
4118 14 : return G_("In explicit object member function %qD");
4119 : else
4120 : return G_("In member function %qD");
4121 : }
4122 : else
4123 : return G_("In function %qD");
4124 : }
4125 :
4126 : /* We expected some kind of tree but instead got T and emitted a diagnostic.
4127 : Print the category of T (type, expression, ...) if possible. */
4128 :
4129 : void
4130 117 : inform_tree_category (tree t)
4131 : {
4132 117 : const location_t loc = location_of (t);
4133 :
4134 117 : t = maybe_get_first_fn (t);
4135 117 : if (TREE_CODE (t) == TYPE_DECL)
4136 5 : t = TREE_TYPE (t);
4137 :
4138 117 : if (TYPE_P (t))
4139 50 : inform (loc, "but %qE is a type", t);
4140 67 : else if (EXPR_P (t))
4141 0 : inform (loc, "but %qE is an expression", t);
4142 67 : else if (DECL_DECOMPOSITION_P (t) && !DECL_DECOMP_IS_BASE (t))
4143 1 : inform (loc, "but %qE is a structured binding", t);
4144 66 : else if (VAR_P (t))
4145 23 : inform (loc, "but %qE is a variable", t);
4146 43 : else if (TREE_CODE (t) == PARM_DECL)
4147 2 : inform (loc, "but %qE is a parameter", t);
4148 41 : else if (TREE_CODE (t) == FUNCTION_DECL)
4149 11 : inform (loc, "but %qE is a function", t);
4150 30 : else if (TREE_CODE (t) == FIELD_DECL)
4151 1 : inform (loc, "but %qE is a data member", t);
4152 29 : else if (DECL_FUNCTION_TEMPLATE_P (t))
4153 5 : inform (loc, "but %qE is a function template", t);
4154 24 : else if (DECL_CLASS_TEMPLATE_P (t))
4155 3 : inform (loc, "but %qE is a class template", t);
4156 21 : else if (DECL_ALIAS_TEMPLATE_P (t))
4157 1 : inform (loc, "but %qE is an alias template", t);
4158 20 : else if (variable_template_p (t))
4159 3 : inform (loc, "but %qE is a variable template", t);
4160 17 : else if (TREE_CODE (t) == NAMESPACE_DECL)
4161 10 : inform (loc, "but %qE is a namespace", t);
4162 7 : else if (TREE_CODE (t) == CONST_DECL && !DECL_TEMPLATE_PARM_P (t))
4163 4 : inform (loc, "but %qE is an enumerator", t);
4164 5 : else if (concept_definition_p (t))
4165 2 : inform (loc, "but %qE is a concept", t);
4166 117 : }
4167 :
4168 : /* Disable warnings about missing quoting in GCC diagnostics for
4169 : the pp_verbatim calls. Their format strings deliberately don't
4170 : follow GCC diagnostic conventions. */
4171 : #if __GNUC__ >= 10
4172 : #pragma GCC diagnostic push
4173 : #pragma GCC diagnostic ignored "-Wformat-diag"
4174 : #endif
4175 :
4176 : /* Report the full context of a current template instantiation,
4177 : onto BUFFER. */
4178 : static void
4179 5414 : print_instantiation_full_context (diagnostics::text_sink &text_output)
4180 : {
4181 5414 : struct tinst_level *p = current_instantiation ();
4182 5414 : location_t location = input_location;
4183 :
4184 5414 : if (p)
4185 : {
4186 5414 : bool show_file
4187 5414 : = ((!text_output.show_nesting_p ())
4188 5414 : || text_output.show_locations_in_nesting_p ());
4189 5414 : char *indent = text_output.build_indent_prefix (true);
4190 5414 : bool expansion_stmt_p = TREE_CODE (p->tldcl) == TEMPLATE_FOR_STMT;
4191 10909 : pp_verbatim (text_output.get_printer (),
4192 : expansion_stmt_p
4193 : ? G_("%s%s%sIn instantiation of %<template for%> "
4194 : "iteration %E:\n")
4195 5414 : : p->list_p ()
4196 : ? G_("%s%s%sIn substitution of %qS:\n")
4197 : : G_("%s%s%sIn instantiation of %q#D:\n"),
4198 : indent,
4199 5405 : show_file ? LOCATION_FILE (location) : "",
4200 : show_file ? ": " : "",
4201 : expansion_stmt_p
4202 81 : ? TREE_VEC_ELT (p->targs, 0)
4203 5414 : : p->get_node ());
4204 5414 : free (indent);
4205 5414 : location = p->locus;
4206 5414 : p = p->next;
4207 : }
4208 :
4209 5414 : print_instantiation_partial_context (text_output, p, location);
4210 5414 : }
4211 :
4212 : static void
4213 12331 : print_location (diagnostics::text_sink &text_output,
4214 : location_t loc)
4215 : {
4216 12331 : expanded_location xloc = expand_location (loc);
4217 12331 : pretty_printer *const pp = text_output.get_printer ();
4218 12331 : if (text_output.show_column_p ())
4219 7337 : pp_verbatim (pp, G_("%r%s:%d:%d:%R "),
4220 : "locus", xloc.file, xloc.line, xloc.column);
4221 : else
4222 4994 : pp_verbatim (pp, G_("%r%s:%d:%R "),
4223 : "locus", xloc.file, xloc.line);
4224 12331 : }
4225 :
4226 : /* A RAII class for use when emitting a line of contextual information
4227 : via pp_verbatim to a diagnostics::text_sink to add before/after
4228 : behaviors to the pp_verbatim calls.
4229 :
4230 : If the text output has show_nesting_p (), then the ctor prints
4231 : leading indentation and a bullet point, and the dtor prints
4232 : the location on a new line, and calls diagnostic_show_locus, both
4233 : with indentation (and no bullet point).
4234 :
4235 : Otherwise (when the text output has !show_nesting_p), the ctor prints
4236 : the location as leading information on the same line, and the
4237 : dtor optionally calls diagnostic_show_locus. */
4238 :
4239 : class auto_context_line
4240 : {
4241 : public:
4242 12367 : auto_context_line (diagnostics::text_sink &text_output,
4243 : location_t loc,
4244 : bool show_locus = false)
4245 12367 : : m_text_output (text_output),
4246 12367 : m_loc (loc),
4247 12367 : m_show_locus (show_locus),
4248 12367 : m_nesting_level (text_output.get_context ().get_diagnostic_nesting_level ()),
4249 12367 : m_location_printed (false)
4250 : {
4251 12367 : char *indent = m_text_output.build_indent_prefix (true);
4252 12367 : pp_verbatim (m_text_output.get_printer (), indent);
4253 12367 : free (indent);
4254 12367 : if (m_nesting_level == 0 || !m_text_output.show_nesting_p ())
4255 : {
4256 12331 : print_location (m_text_output, m_loc);
4257 12331 : m_location_printed = true;
4258 : }
4259 12367 : }
4260 12367 : ~auto_context_line ()
4261 : {
4262 12367 : pretty_printer *const pp = m_text_output.get_printer ();
4263 12367 : if (m_text_output.show_nesting_p ())
4264 : {
4265 47 : if (m_text_output.show_locations_in_nesting_p ())
4266 : {
4267 11 : char *indent = m_text_output.build_indent_prefix (false);
4268 11 : if (!m_location_printed)
4269 : {
4270 0 : pp_verbatim (pp, indent);
4271 0 : print_location (m_text_output, m_loc);
4272 0 : pp_newline (pp);
4273 0 : m_location_printed = true;
4274 : }
4275 :
4276 11 : char *saved_prefix = pp_take_prefix (pp);
4277 11 : pp_set_prefix (pp, indent);
4278 11 : gcc_rich_location rich_loc (m_loc);
4279 11 : diagnostic_show_locus (&m_text_output.get_context (),
4280 11 : m_text_output.get_source_printing_options (),
4281 : &rich_loc,
4282 : diagnostics::kind::note, pp);
4283 11 : pp_set_prefix (pp, saved_prefix);
4284 11 : }
4285 : }
4286 12320 : else if (m_show_locus)
4287 : {
4288 7237 : char *saved_prefix = pp_take_prefix (pp);
4289 7237 : pp_set_prefix (pp, nullptr);
4290 7237 : gcc_rich_location rich_loc (m_loc);
4291 7237 : diagnostic_show_locus (&m_text_output.get_context (),
4292 7237 : m_text_output.get_source_printing_options (),
4293 : &rich_loc,
4294 : diagnostics::kind::note, pp);
4295 7237 : pp_set_prefix (pp, saved_prefix);
4296 7237 : }
4297 12367 : }
4298 : private:
4299 : diagnostics::text_sink &m_text_output;
4300 : location_t m_loc;
4301 : bool m_show_locus;
4302 : int m_nesting_level;
4303 : bool m_location_printed;
4304 : };
4305 :
4306 : /* Helper function of print_instantiation_partial_context() that
4307 : prints a single line of instantiation context. */
4308 :
4309 : static void
4310 7257 : print_instantiation_partial_context_line (diagnostics::text_sink &text_output,
4311 : struct tinst_level *t,
4312 : location_t loc, bool recursive_p)
4313 : {
4314 7257 : if (loc == UNKNOWN_LOCATION)
4315 0 : return;
4316 :
4317 7257 : auto_context_line sentinel (text_output, loc, true);
4318 :
4319 7257 : pretty_printer *const pp = text_output.get_printer ();
4320 :
4321 7257 : if (t != NULL)
4322 : {
4323 1843 : if (TREE_CODE (t->tldcl) == TEMPLATE_FOR_STMT)
4324 0 : pp_verbatim (pp,
4325 : recursive_p
4326 : ? G_("recursively required from %<template for%> "
4327 : "iteration %E\n")
4328 : : G_("required from %<template for%> iteration %E\n"),
4329 0 : TREE_VEC_ELT (t->targs, 0));
4330 1843 : else if (t->list_p ())
4331 768 : pp_verbatim (pp,
4332 : recursive_p
4333 : ? G_("recursively required by substitution of %qS\n")
4334 : : G_("required by substitution of %qS\n"),
4335 : t->get_node ());
4336 : else
4337 3014 : pp_verbatim (pp,
4338 : recursive_p
4339 : ? G_("recursively required from %q#D\n")
4340 : : G_("required from %q#D\n"),
4341 : t->get_node ());
4342 : }
4343 : else
4344 : {
4345 10828 : pp_verbatim (pp,
4346 : recursive_p
4347 : ? G_("recursively required from here\n")
4348 : : G_("required from here\n"));
4349 : }
4350 7257 : }
4351 :
4352 : /* Same as print_instantiation_full_context but less verbose. */
4353 :
4354 : static void
4355 5414 : print_instantiation_partial_context (diagnostics::text_sink &text_output,
4356 : struct tinst_level *t0, location_t loc)
4357 : {
4358 5414 : struct tinst_level *t;
4359 5414 : int n_total = 0;
4360 5414 : int n;
4361 5414 : location_t prev_loc = loc;
4362 :
4363 40179 : for (t = t0; t != NULL; t = t->next)
4364 34765 : if (prev_loc != t->locus)
4365 : {
4366 1777 : prev_loc = t->locus;
4367 1777 : n_total++;
4368 : }
4369 :
4370 5414 : t = t0;
4371 :
4372 5414 : if (template_backtrace_limit
4373 5414 : && n_total > template_backtrace_limit)
4374 : {
4375 0 : int skip = n_total - template_backtrace_limit;
4376 0 : int head = template_backtrace_limit / 2;
4377 :
4378 : /* Avoid skipping just 1. If so, skip 2. */
4379 0 : if (skip == 1)
4380 : {
4381 0 : skip = 2;
4382 0 : head = (template_backtrace_limit - 1) / 2;
4383 : }
4384 :
4385 0 : for (n = 0; n < head; n++)
4386 : {
4387 0 : gcc_assert (t != NULL);
4388 0 : if (loc != t->locus)
4389 0 : print_instantiation_partial_context_line (text_output, t, loc,
4390 : /*recursive_p=*/false);
4391 0 : loc = t->locus;
4392 0 : t = t->next;
4393 : }
4394 0 : if (t != NULL && skip > 0)
4395 : {
4396 0 : auto_context_line sentinel (text_output, loc);
4397 0 : pp_verbatim (text_output.get_printer (),
4398 : G_("[ skipping %d instantiation contexts,"
4399 : " use -ftemplate-backtrace-limit=0 to disable ]\n"),
4400 : skip);
4401 0 : do {
4402 0 : loc = t->locus;
4403 0 : t = t->next;
4404 0 : } while (t != NULL && --skip > 0);
4405 0 : }
4406 : }
4407 :
4408 7257 : while (t != NULL)
4409 : {
4410 34765 : while (t->next != NULL && t->locus == t->next->locus)
4411 : {
4412 : loc = t->locus;
4413 : t = t->next;
4414 : }
4415 1843 : print_instantiation_partial_context_line (text_output, t, loc,
4416 1843 : t->locus == loc);
4417 1843 : loc = t->locus;
4418 1843 : t = t->next;
4419 : }
4420 5414 : print_instantiation_partial_context_line (text_output, NULL, loc,
4421 : /*recursive_p=*/false);
4422 5414 : }
4423 :
4424 : /* Called from cp_thing to print the template context for an error. */
4425 : static void
4426 244673 : maybe_print_instantiation_context (diagnostics::text_sink &text_output)
4427 : {
4428 244673 : if (!problematic_instantiation_changed () || current_instantiation () == 0)
4429 239259 : return;
4430 :
4431 5414 : record_last_problematic_instantiation ();
4432 5414 : print_instantiation_full_context (text_output);
4433 : }
4434 :
4435 : /* Report what constexpr call(s) we're trying to expand, if any. */
4436 :
4437 : void
4438 244521 : maybe_print_constexpr_context (diagnostics::text_sink &text_output)
4439 : {
4440 244521 : vec<tree> call_stack = cx_error_context ();
4441 244521 : unsigned ix;
4442 244521 : tree t;
4443 :
4444 247921 : FOR_EACH_VEC_ELT (call_stack, ix, t)
4445 : {
4446 3400 : const char *s = expr_as_string (t, 0);
4447 3400 : pretty_printer *const pp = text_output.get_printer ();
4448 3400 : auto_context_line sentinel (text_output, EXPR_LOCATION (t));
4449 3400 : pp_verbatim (pp,
4450 : G_("in %<constexpr%> expansion of %qs"),
4451 : s);
4452 3400 : pp_newline (pp);
4453 3400 : }
4454 244521 : }
4455 :
4456 :
4457 : static void
4458 603 : print_constrained_decl_info (diagnostics::text_sink &text_output,
4459 : tree decl)
4460 : {
4461 603 : auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (decl));
4462 603 : pretty_printer *const pp = text_output.get_printer ();
4463 603 : pp_verbatim (pp, G_("required by the constraints of %q#D\n"), decl);
4464 603 : }
4465 :
4466 : static void
4467 789 : print_concept_check_info (diagnostics::text_sink &text_output,
4468 : tree expr, tree map, tree args)
4469 : {
4470 789 : gcc_assert (concept_check_p (expr));
4471 :
4472 789 : tree tmpl = TREE_OPERAND (expr, 0);
4473 :
4474 789 : auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (tmpl));
4475 :
4476 789 : cxx_pretty_printer *const pp
4477 789 : = (cxx_pretty_printer *)text_output.get_printer ();
4478 789 : pp_verbatim (pp, G_("required for the satisfaction of %qE"), expr);
4479 789 : if (map && map != error_mark_node)
4480 : {
4481 771 : tree subst_map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE);
4482 773 : pp_cxx_parameter_mapping (pp, (subst_map != error_mark_node
4483 : ? subst_map : map));
4484 : }
4485 789 : pp_newline (pp);
4486 789 : }
4487 :
4488 : /* Diagnose the entry point into the satisfaction error. Returns the next
4489 : context, if any. */
4490 :
4491 : static tree
4492 1324 : print_constraint_context_head (diagnostics::text_sink &text_output,
4493 : tree cxt, tree args)
4494 : {
4495 1324 : tree src = TREE_VALUE (cxt);
4496 1324 : if (!src)
4497 : {
4498 0 : auto_context_line sentinel (text_output, input_location);
4499 0 : pretty_printer *const pp = text_output.get_printer ();
4500 0 : pp_verbatim (pp, G_("required for constraint satisfaction\n"));
4501 0 : return NULL_TREE;
4502 0 : }
4503 1324 : if (DECL_P (src))
4504 : {
4505 603 : print_constrained_decl_info (text_output, src);
4506 603 : return NULL_TREE;
4507 : }
4508 : else
4509 : {
4510 721 : print_concept_check_info (text_output, src, TREE_PURPOSE (cxt), args);
4511 721 : return TREE_CHAIN (cxt);
4512 : }
4513 : }
4514 :
4515 : static void
4516 320 : print_requires_expression_info (diagnostics::text_sink &text_output,
4517 : tree constr, tree args)
4518 : {
4519 :
4520 320 : tree expr = ATOMIC_CONSTR_EXPR (constr);
4521 320 : tree map = ATOMIC_CONSTR_MAP (constr);
4522 320 : map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE);
4523 320 : if (map == error_mark_node)
4524 2 : return;
4525 :
4526 318 : auto_context_line sentinel (text_output, cp_expr_loc_or_input_loc (expr));
4527 318 : cxx_pretty_printer *const pp
4528 318 : = static_cast <cxx_pretty_printer *> (text_output.get_printer ());
4529 :
4530 318 : tree parms = TREE_OPERAND (expr, 0);
4531 318 : pp_verbatim (pp, parms ? G_("in requirements with ")
4532 : : G_("in requirements "));
4533 923 : while (parms)
4534 : {
4535 287 : pp_verbatim (pp, "%q#D", parms);
4536 287 : if (TREE_CHAIN (parms))
4537 97 : pp_separate_with_comma (pp);
4538 287 : parms = TREE_CHAIN (parms);
4539 : }
4540 318 : pp_cxx_parameter_mapping (pp, map);
4541 :
4542 318 : pp_verbatim (pp, "\n");
4543 318 : }
4544 :
4545 : void
4546 1351 : maybe_print_single_constraint_context (diagnostics::text_sink &text_output,
4547 : tree failed)
4548 : {
4549 1351 : if (!failed)
4550 : return;
4551 :
4552 1351 : tree constr = TREE_VALUE (failed);
4553 1351 : if (!constr || constr == error_mark_node)
4554 : return;
4555 1351 : tree cxt = CONSTR_CONTEXT (constr);
4556 1351 : if (!cxt)
4557 : return;
4558 1324 : tree args = TREE_PURPOSE (failed);
4559 :
4560 : /* Print the stack of requirements. */
4561 1324 : cxt = print_constraint_context_head (text_output, cxt, args);
4562 3374 : while (cxt && !DECL_P (TREE_VALUE (cxt)))
4563 : {
4564 68 : tree expr = TREE_VALUE (cxt);
4565 68 : tree map = TREE_PURPOSE (cxt);
4566 68 : print_concept_check_info (text_output, expr, map, args);
4567 68 : cxt = TREE_CHAIN (cxt);
4568 : }
4569 :
4570 : /* For certain constraints, we can provide additional context. */
4571 1324 : if (TREE_CODE (constr) == ATOMIC_CONSTR
4572 1324 : && TREE_CODE (ATOMIC_CONSTR_EXPR (constr)) == REQUIRES_EXPR)
4573 320 : print_requires_expression_info (text_output, constr, args);
4574 : }
4575 :
4576 : void
4577 244524 : maybe_print_constraint_context (diagnostics::text_sink &text_output)
4578 : {
4579 244524 : if (!current_failed_constraint)
4580 : return;
4581 :
4582 1351 : tree cur = current_failed_constraint;
4583 :
4584 : /* Recursively print nested contexts. */
4585 1351 : current_failed_constraint = TREE_CHAIN (current_failed_constraint);
4586 1351 : if (current_failed_constraint)
4587 3 : maybe_print_constraint_context (text_output);
4588 :
4589 : /* Print this context. */
4590 1351 : maybe_print_single_constraint_context (text_output, cur);
4591 : }
4592 :
4593 : /* Return true iff TYPE_A and TYPE_B are template types that are
4594 : meaningful to compare. */
4595 :
4596 : static bool
4597 11467 : comparable_template_types_p (tree type_a, tree type_b)
4598 : {
4599 11467 : if (!CLASS_TYPE_P (type_a))
4600 : return false;
4601 1331 : if (!CLASS_TYPE_P (type_b))
4602 : return false;
4603 :
4604 412 : tree tinfo_a = TYPE_TEMPLATE_INFO (type_a);
4605 412 : tree tinfo_b = TYPE_TEMPLATE_INFO (type_b);
4606 412 : if (!tinfo_a || !tinfo_b)
4607 : return false;
4608 :
4609 251 : return TI_TEMPLATE (tinfo_a) == TI_TEMPLATE (tinfo_b);
4610 : }
4611 :
4612 : /* Start a new line indented by SPC spaces on PP. */
4613 :
4614 : static void
4615 228 : newline_and_indent (pretty_printer *pp, int spc)
4616 : {
4617 228 : pp_newline (pp);
4618 1020 : for (int i = 0; i < spc; i++)
4619 792 : pp_space (pp);
4620 228 : }
4621 :
4622 : /* Generate a GC-allocated string for ARG, an expression or type. */
4623 :
4624 : static const char *
4625 628 : arg_to_string (tree arg, bool verbose)
4626 : {
4627 628 : if (TYPE_P (arg))
4628 366 : return type_to_string (arg, verbose, true, NULL, false);
4629 : else
4630 262 : return expr_to_string (arg);
4631 : }
4632 :
4633 : /* Subroutine to type_to_string_with_compare and
4634 : print_template_tree_comparison.
4635 :
4636 : Print a representation of ARG (an expression or type) to PP,
4637 : colorizing it if PP->show_color, using HIGHLIGHT_COLOR,
4638 : or "type-diff" if the latter is NULL. */
4639 :
4640 : static void
4641 616 : print_nonequal_arg (pretty_printer *pp, tree arg, bool verbose,
4642 : const char *highlight_color)
4643 : {
4644 616 : if (!highlight_color)
4645 10 : highlight_color = "type-diff";
4646 1232 : pp_printf (pp, "%r%s%R",
4647 : highlight_color,
4648 : (arg
4649 616 : ? arg_to_string (arg, verbose)
4650 : : G_("(no argument)")));
4651 616 : }
4652 :
4653 : /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
4654 :
4655 : The types must satisfy comparable_template_types_p.
4656 :
4657 : If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
4658 : potentially colorizing/eliding in comparison with TYPE_B.
4659 :
4660 : For example given types:
4661 : vector<map<int,double>>
4662 : and
4663 : vector<map<int,float>>
4664 : then the result on PP would be:
4665 : vector<map<[...],double>>
4666 : with type elision, and:
4667 : vector<map<int,double>>
4668 : without type elision.
4669 :
4670 : In both cases the parts of TYPE that differ from PEER will be colorized
4671 : if pp_show_color (pp) is true. In the above example, this would be
4672 : "double".
4673 :
4674 : If INDENT is non-zero, then the types are printed in a tree-like form
4675 : which shows both types. In the above example, the result on PP would be:
4676 :
4677 : vector<
4678 : map<
4679 : [...],
4680 : [double != float]>>
4681 :
4682 : and without type-elision would be:
4683 :
4684 : vector<
4685 : map<
4686 : int,
4687 : [double != float]>>
4688 :
4689 : As before, the differing parts of the types are colorized if
4690 : pp_show_color (pp) is true ("double" and "float" in this example).
4691 :
4692 : Template arguments in which both types are using the default arguments
4693 : are not printed; if at least one of the two types is using a non-default
4694 : argument, then that argument is printed (or both arguments for the
4695 : tree-like print format). */
4696 :
4697 : static void
4698 443 : print_template_differences (pretty_printer *pp, tree type_a, tree type_b,
4699 : bool verbose, int indent,
4700 : const char *highlight_color_a,
4701 : const char *highlight_color_b)
4702 : {
4703 443 : if (indent)
4704 85 : newline_and_indent (pp, indent);
4705 :
4706 443 : tree tinfo_a = TYPE_TEMPLATE_INFO (type_a);
4707 443 : tree tinfo_b = TYPE_TEMPLATE_INFO (type_b);
4708 :
4709 443 : pp_printf (pp, "%s<",
4710 443 : IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a))));
4711 :
4712 443 : tree args_a = TI_ARGS (tinfo_a);
4713 443 : tree args_b = TI_ARGS (tinfo_b);
4714 443 : gcc_assert (TREE_CODE (args_a) == TREE_VEC);
4715 443 : gcc_assert (TREE_CODE (args_b) == TREE_VEC);
4716 443 : int flags = 0;
4717 443 : int len_a = get_non_default_template_args_count (args_a, flags);
4718 443 : args_a = INNERMOST_TEMPLATE_ARGS (args_a);
4719 443 : int len_b = get_non_default_template_args_count (args_b, flags);
4720 443 : args_b = INNERMOST_TEMPLATE_ARGS (args_b);
4721 : /* Determine the maximum range of args for which non-default template args
4722 : were used; beyond this, only default args (if any) were used, and so
4723 : they will be equal from this point onwards.
4724 : One of the two peers might have used default arguments within this
4725 : range, but the other will be using non-default arguments, and so
4726 : it's more readable to print both within this range, to highlight
4727 : the differences. */
4728 443 : int len_max = MAX (len_a, len_b);
4729 443 : gcc_assert (TREE_CODE (args_a) == TREE_VEC);
4730 443 : gcc_assert (TREE_CODE (args_b) == TREE_VEC);
4731 1116 : for (int idx = 0; idx < len_max; idx++)
4732 : {
4733 673 : if (idx)
4734 230 : pp_character (pp, ',');
4735 :
4736 673 : tree arg_a = TREE_VEC_ELT (args_a, idx);
4737 673 : tree arg_b = TREE_VEC_ELT (args_b, idx);
4738 673 : if (arg_a == arg_b)
4739 : {
4740 128 : if (indent)
4741 39 : newline_and_indent (pp, indent + 2);
4742 : /* Can do elision here, printing "[...]". */
4743 128 : if (flag_elide_type)
4744 116 : pp_string (pp, G_("[...]"));
4745 : else
4746 12 : pp_string (pp, arg_to_string (arg_a, verbose));
4747 : }
4748 : else
4749 : {
4750 545 : int new_indent = indent ? indent + 2 : 0;
4751 545 : if (comparable_template_types_p (arg_a, arg_b))
4752 33 : print_template_differences (pp, arg_a, arg_b, verbose, new_indent,
4753 : highlight_color_a, highlight_color_b);
4754 : else
4755 512 : if (indent)
4756 : {
4757 104 : newline_and_indent (pp, indent + 2);
4758 104 : pp_character (pp, '[');
4759 104 : print_nonequal_arg (pp, arg_a, verbose, highlight_color_a);
4760 104 : pp_string (pp, " != ");
4761 104 : print_nonequal_arg (pp, arg_b, verbose, highlight_color_b);
4762 104 : pp_character (pp, ']');
4763 : }
4764 : else
4765 408 : print_nonequal_arg (pp, arg_a, verbose, highlight_color_a);
4766 : }
4767 : }
4768 443 : pp_printf (pp, ">");
4769 443 : }
4770 :
4771 : /* As type_to_string, but for a template, potentially colorizing/eliding
4772 : in comparison with PEER.
4773 : For example, if TYPE is map<int,double> and PEER is map<int,int>,
4774 : then the resulting string would be:
4775 : map<[...],double>
4776 : with type elision, and:
4777 : map<int,double>
4778 : without type elision.
4779 :
4780 : In both cases the parts of TYPE that differ from PEER will be colorized
4781 : if SHOW_COLOR is true. In the above example, this would be "double".
4782 :
4783 : Template arguments in which both types are using the default arguments
4784 : are not printed; if at least one of the two types is using a non-default
4785 : argument, then both arguments are printed.
4786 :
4787 : The resulting string is in a GC-allocated buffer. */
4788 :
4789 : static const char *
4790 336 : type_to_string_with_compare (tree type, tree peer, bool verbose,
4791 : bool show_color,
4792 : const char *this_highlight_color,
4793 : const char *peer_highlight_color)
4794 : {
4795 336 : pretty_printer inner_pp;
4796 336 : pretty_printer *pp = &inner_pp;
4797 336 : pp_show_color (pp) = show_color;
4798 :
4799 336 : print_template_differences (pp, type, peer, verbose, 0,
4800 : this_highlight_color, peer_highlight_color);
4801 336 : return pp_ggc_formatted_text (pp);
4802 336 : }
4803 :
4804 : /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4805 : indented by INDENT spaces.
4806 :
4807 : For example given types:
4808 :
4809 : vector<map<int,double>>
4810 :
4811 : and
4812 :
4813 : vector<map<double,float>>
4814 :
4815 : the output with type elision would be:
4816 :
4817 : vector<
4818 : map<
4819 : [...],
4820 : [double != float]>>
4821 :
4822 : and without type-elision would be:
4823 :
4824 : vector<
4825 : map<
4826 : int,
4827 : [double != float]>>
4828 :
4829 : TYPE_A and TYPE_B must both be comparable template types
4830 : (as per comparable_template_types_p).
4831 :
4832 : Template arguments in which both types are using the default arguments
4833 : are not printed; if at least one of the two types is using a non-default
4834 : argument, then both arguments are printed. */
4835 :
4836 : static void
4837 74 : print_template_tree_comparison (pretty_printer *pp, tree type_a, tree type_b,
4838 : bool verbose, int indent,
4839 : const char *highlight_color_a,
4840 : const char *highlight_color_b)
4841 : {
4842 0 : print_template_differences (pp, type_a, type_b, verbose, indent,
4843 : highlight_color_a,
4844 : highlight_color_b);
4845 0 : }
4846 :
4847 : /* Subroutine for use in a format_postprocessor::handle
4848 : implementation. Adds a chunk to the end of
4849 : formatted output, so that it will be printed
4850 : by pp_output_formatted_text. */
4851 :
4852 : static void
4853 74 : append_formatted_chunk (pretty_printer *pp, const char *content)
4854 : {
4855 74 : output_buffer *buffer = pp_buffer (pp);
4856 74 : pp_formatted_chunks *chunk_array = buffer->m_cur_formatted_chunks;
4857 0 : chunk_array->append_formatted_chunk (buffer->m_chunk_obstack, content);
4858 0 : }
4859 :
4860 : #if __GNUC__ >= 10
4861 : #pragma GCC diagnostic pop
4862 : #endif
4863 :
4864 : /* If we had %H and %I, and hence deferred printing them,
4865 : print them now, storing the result into custom_token_value
4866 : for the custom pp_token. Quote them if 'q' was provided.
4867 : Also print the difference in tree form, adding it as
4868 : an additional chunk. */
4869 :
4870 : void
4871 368539 : cxx_format_postprocessor::handle (pretty_printer *pp)
4872 : {
4873 : /* If we have one of %H and %I, the other should have
4874 : been present. */
4875 368539 : if (m_type_a.m_tree || m_type_b.m_tree)
4876 : {
4877 10488 : const bool show_highlight_colors = pp_show_highlight_colors (pp);
4878 10488 : const char *percent_h
4879 10488 : = show_highlight_colors ? highlight_colors::percent_h : nullptr;
4880 2 : const char *percent_i
4881 : = show_highlight_colors ? highlight_colors::percent_i : nullptr;
4882 : /* Avoid reentrancy issues by working with a copy of
4883 : m_type_a and m_type_b, resetting them now. */
4884 10488 : deferred_printed_type type_a = std::move (m_type_a);
4885 10488 : deferred_printed_type type_b = std::move (m_type_b);
4886 10488 : m_type_a = deferred_printed_type ();
4887 10488 : m_type_b = deferred_printed_type ();
4888 :
4889 10488 : gcc_assert (type_a.m_token_list);
4890 10488 : gcc_assert (type_b.m_token_list);
4891 :
4892 10488 : bool show_color = pp_show_color (pp);
4893 :
4894 10488 : const char *type_a_text;
4895 10488 : const char *type_b_text;
4896 :
4897 10488 : if (comparable_template_types_p (type_a.m_tree, type_b.m_tree))
4898 : {
4899 167 : type_a_text = type_to_string_with_compare
4900 167 : (type_a.m_tree, type_b.m_tree,
4901 : type_a.m_verbose, show_color,
4902 : percent_h, percent_i);
4903 167 : type_b_text = type_to_string_with_compare
4904 167 : (type_b.m_tree, type_a.m_tree,
4905 : type_b.m_verbose, show_color,
4906 : percent_i, percent_h);
4907 :
4908 167 : if (flag_diagnostics_show_template_tree)
4909 : {
4910 74 : pretty_printer inner_pp;
4911 74 : pp_show_color (&inner_pp) = pp_show_color (pp);
4912 74 : print_template_tree_comparison
4913 74 : (&inner_pp, type_a.m_tree, type_b.m_tree, type_a.m_verbose, 2,
4914 : percent_h, percent_i);
4915 74 : append_formatted_chunk (pp, pp_ggc_formatted_text (&inner_pp));
4916 74 : }
4917 : }
4918 : else
4919 : {
4920 : /* If the types were not comparable (or if only one of %H/%I was
4921 : provided), they are printed normally, and no difference tree
4922 : is printed. */
4923 10321 : type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose,
4924 : true, &type_a.m_quote, show_color,
4925 : percent_h);
4926 10321 : type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose,
4927 : true, &type_b.m_quote, show_color,
4928 : percent_i);
4929 : }
4930 :
4931 10488 : type_a.set_text_for_token_list (type_a_text, type_a.m_quote);
4932 10488 : type_b.set_text_for_token_list (type_b_text, type_b.m_quote);
4933 10488 : }
4934 368539 : }
4935 :
4936 : /* Subroutine for handling %H and %I, to support i18n of messages like:
4937 :
4938 : error_at (loc, "could not convert %qE from %qH to %qI",
4939 : expr, type_a, type_b);
4940 :
4941 : so that we can print things like:
4942 :
4943 : could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4944 :
4945 : and, with type-elision:
4946 :
4947 : could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4948 :
4949 : (with color-coding of the differences between the types).
4950 :
4951 : The %H and %I format codes are peers: both must be present,
4952 : and they affect each other. Hence to handle them, we must
4953 : delay printing until we have both, deferring the printing to
4954 : pretty_printer's m_format_postprocessor hook.
4955 :
4956 : This is called in phase 2 of pp_format, when it is accumulating
4957 : a series of pp_token lists. Since we have to interact with the
4958 : fiddly quoting logic for "aka", we store the pp_token_list *
4959 : and in the m_format_postprocessor hook we generate text for the type
4960 : (possibly with quotes and colors), then replace all tokens in that token list
4961 : (such as [BEGIN_QUOTE, END_QUOTE]) with a text token containing the
4962 : freshly generated text.
4963 :
4964 : We also need to stash whether a 'q' prefix was provided (the QUOTE
4965 : param) so that we can add the quotes when writing out the delayed
4966 : chunk. */
4967 :
4968 : static void
4969 20976 : defer_phase_2_of_type_diff (deferred_printed_type *deferred,
4970 : tree type,
4971 : pp_token_list &formatted_token_list,
4972 : bool verbose, bool quote)
4973 : {
4974 20976 : gcc_assert (deferred->m_tree == NULL_TREE);
4975 41952 : *deferred = deferred_printed_type (type, formatted_token_list,
4976 20976 : verbose, quote);
4977 20976 : }
4978 :
4979 : /* Implementation of pp_markup::element_quoted_type::print_type
4980 : for C++/ObjC++. */
4981 :
4982 : void
4983 752 : pp_markup::element_quoted_type::print_type (pp_markup::context &ctxt)
4984 : {
4985 752 : const char *highlight_color
4986 752 : = pp_show_highlight_colors (&ctxt.m_pp) ? m_highlight_color : nullptr;
4987 752 : const char *result
4988 1504 : = type_to_string (m_type, false, false, &ctxt.m_quoted,
4989 752 : pp_show_color (&ctxt.m_pp), highlight_color);
4990 752 : pp_string (&ctxt.m_pp, result);
4991 752 : }
4992 :
4993 : /* Called from output_format -- during diagnostic message processing --
4994 : to handle C++ specific format specifier with the following meanings:
4995 : %A function argument-list.
4996 : %C tree code.
4997 : %D declaration.
4998 : %E expression.
4999 : %F function declaration.
5000 : %H type difference (from).
5001 : %I type difference (to).
5002 : %L language as used in extern "lang".
5003 : %O binary operator.
5004 : %P function parameter whose position is indicated by an integer.
5005 : %Q assignment operator.
5006 : %S substitution (template + args)
5007 : %T type.
5008 : %V cv-qualifier.
5009 : %X exception-specification. */
5010 : static bool
5011 220836 : cp_printer (pretty_printer *pp, text_info *text, const char *spec,
5012 : int precision, bool wide, bool set_locus, bool verbose,
5013 : bool *quoted, pp_token_list &formatted_token_list)
5014 : {
5015 220836 : gcc_assert (pp_format_postprocessor (pp));
5016 220836 : cxx_format_postprocessor *postprocessor
5017 220836 : = static_cast <cxx_format_postprocessor *> (pp_format_postprocessor (pp));
5018 :
5019 220836 : const char *result;
5020 220836 : tree t = NULL;
5021 : #define next_tree (t = va_arg (*text->m_args_ptr, tree))
5022 : #define next_tcode ((enum tree_code) va_arg (*text->m_args_ptr, int))
5023 : #define next_lang ((enum languages) va_arg (*text->m_args_ptr, int))
5024 : #define next_int va_arg (*text->m_args_ptr, int)
5025 :
5026 220836 : if (precision != 0 || wide)
5027 : return false;
5028 :
5029 220836 : switch (*spec)
5030 : {
5031 3920 : case 'A': result = args_to_string (next_tree, verbose); break;
5032 0 : case 'C': result = code_to_string (next_tcode); break;
5033 99875 : case 'D':
5034 99875 : {
5035 99875 : tree temp = next_tree;
5036 99875 : if (VAR_P (temp)
5037 99875 : && DECL_HAS_DEBUG_EXPR_P (temp))
5038 : {
5039 18 : temp = DECL_DEBUG_EXPR (temp);
5040 18 : if (!DECL_P (temp))
5041 : {
5042 18 : result = expr_to_string (temp);
5043 18 : break;
5044 : }
5045 : }
5046 99857 : result = decl_to_string (temp, verbose, pp_show_color (pp));
5047 : }
5048 99857 : break;
5049 50470 : case 'E': result = expr_to_string (next_tree); break;
5050 350 : case 'F': result = fndecl_to_string (next_tree, verbose); break;
5051 10488 : case 'H':
5052 20976 : defer_phase_2_of_type_diff (&postprocessor->m_type_a, next_tree,
5053 10488 : formatted_token_list, verbose, *quoted);
5054 10488 : return true;
5055 10488 : case 'I':
5056 20976 : defer_phase_2_of_type_diff (&postprocessor->m_type_b, next_tree,
5057 10488 : formatted_token_list, verbose, *quoted);
5058 10488 : return true;
5059 24 : case 'L': result = language_to_string (next_lang); break;
5060 297 : case 'O': result = op_to_string (false, next_tcode); break;
5061 1538 : case 'P': result = parm_to_string (next_int); break;
5062 24 : case 'Q': result = op_to_string (true, next_tcode); break;
5063 1564 : case 'S': result = subst_to_string (next_tree, pp_show_color (pp)); break;
5064 41156 : case 'T':
5065 41156 : {
5066 82312 : result = type_to_string (next_tree, verbose, false, quoted,
5067 41156 : pp_show_color (pp));
5068 : }
5069 41156 : break;
5070 639 : case 'V': result = cv_to_string (next_tree, verbose); break;
5071 3 : case 'X': result = eh_spec_to_string (next_tree, verbose); break;
5072 :
5073 : default:
5074 : return false;
5075 : }
5076 :
5077 199860 : pp_string (pp, result);
5078 199860 : if (set_locus && t != NULL)
5079 1774 : text->set_location (0, location_of (t), SHOW_RANGE_WITH_CARET);
5080 : return true;
5081 : #undef next_tree
5082 : #undef next_tcode
5083 : #undef next_lang
5084 : #undef next_int
5085 : }
5086 :
5087 : /* Warn about the use of C++0x features when appropriate. */
5088 : void
5089 84808363 : maybe_warn_cpp0x (cpp0x_warn_str str, location_t loc/*=input_location*/)
5090 : {
5091 84808363 : if (cxx_dialect == cxx98)
5092 4319 : switch (str)
5093 : {
5094 186 : case CPP0X_INITIALIZER_LISTS:
5095 186 : pedwarn (loc, OPT_Wc__11_extensions,
5096 : "extended initializer lists "
5097 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5098 186 : break;
5099 0 : case CPP0X_EXPLICIT_CONVERSION:
5100 0 : pedwarn (loc, OPT_Wc__11_extensions,
5101 : "explicit conversion operators "
5102 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5103 0 : break;
5104 1390 : case CPP0X_VARIADIC_TEMPLATES:
5105 1390 : pedwarn (loc, OPT_Wc__11_extensions,
5106 : "variadic templates "
5107 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5108 1390 : break;
5109 6 : case CPP0X_LAMBDA_EXPR:
5110 6 : pedwarn (loc, OPT_Wc__11_extensions,
5111 : "lambda expressions "
5112 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5113 6 : break;
5114 0 : case CPP0X_AUTO:
5115 0 : pedwarn (loc, OPT_Wc__11_extensions,
5116 : "C++11 auto only available with %<-std=c++11%> or "
5117 : "%<-std=gnu++11%>");
5118 0 : break;
5119 16 : case CPP0X_SCOPED_ENUMS:
5120 16 : pedwarn (loc, OPT_Wc__11_extensions,
5121 : "scoped enums only available with %<-std=c++11%> or "
5122 : "%<-std=gnu++11%>");
5123 16 : break;
5124 517 : case CPP0X_DEFAULTED_DELETED:
5125 517 : pedwarn (loc, OPT_Wc__11_extensions,
5126 : "defaulted and deleted functions "
5127 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5128 517 : break;
5129 1913 : case CPP0X_INLINE_NAMESPACES:
5130 1913 : if (pedantic)
5131 581 : pedwarn (loc, OPT_Wc__11_extensions,
5132 : "inline namespaces "
5133 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5134 : break;
5135 3 : case CPP0X_OVERRIDE_CONTROLS:
5136 3 : pedwarn (loc, OPT_Wc__11_extensions,
5137 : "override controls (override/final) "
5138 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5139 3 : break;
5140 132 : case CPP0X_NSDMI:
5141 132 : pedwarn (loc, OPT_Wc__11_extensions,
5142 : "non-static data member initializers "
5143 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5144 132 : break;
5145 4 : case CPP0X_USER_DEFINED_LITERALS:
5146 4 : pedwarn (loc, OPT_Wc__11_extensions,
5147 : "user-defined literals "
5148 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5149 4 : break;
5150 3 : case CPP0X_DELEGATING_CTORS:
5151 3 : pedwarn (loc, OPT_Wc__11_extensions,
5152 : "delegating constructors "
5153 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5154 3 : break;
5155 3 : case CPP0X_INHERITING_CTORS:
5156 3 : pedwarn (loc, OPT_Wc__11_extensions,
5157 : "inheriting constructors "
5158 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5159 3 : break;
5160 146 : case CPP0X_ATTRIBUTES:
5161 146 : if (pedantic)
5162 24 : pedwarn (loc, OPT_Wc__11_extensions,
5163 : "C++11 attributes "
5164 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5165 : break;
5166 0 : case CPP0X_REF_QUALIFIER:
5167 0 : pedwarn (loc, OPT_Wc__11_extensions,
5168 : "ref-qualifiers "
5169 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5170 0 : break;
5171 0 : default:
5172 0 : gcc_unreachable ();
5173 : }
5174 84808363 : }
5175 :
5176 : /* Warn about the use of variadic templates when appropriate. */
5177 : void
5178 14021469 : maybe_warn_variadic_templates (void)
5179 : {
5180 14021469 : maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES);
5181 14021469 : }
5182 :
5183 :
5184 : /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
5185 : option OPTION_ID with text GMSGID. Use this function to report
5186 : diagnostics for constructs that are invalid C++98, but valid
5187 : C++0x. */
5188 : bool
5189 3680049 : pedwarn_cxx98 (location_t location,
5190 : diagnostics::option_id option_id,
5191 : const char *gmsgid, ...)
5192 : {
5193 3680049 : diagnostics::diagnostic_info diagnostic;
5194 3680049 : va_list ap;
5195 3680049 : bool ret;
5196 3680049 : rich_location richloc (line_table, location);
5197 :
5198 3680049 : va_start (ap, gmsgid);
5199 3680049 : diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
5200 3680049 : (cxx_dialect == cxx98
5201 : ? diagnostics::kind::pedwarn
5202 : : diagnostics::kind::warning));
5203 3680049 : diagnostic.m_option_id = option_id;
5204 3680049 : ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
5205 3680049 : va_end (ap);
5206 7360098 : return ret;
5207 3680049 : }
5208 :
5209 : /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
5210 : we found when we tried to do the lookup. LOCATION is the location of
5211 : the NAME identifier. */
5212 :
5213 : void
5214 563 : qualified_name_lookup_error (tree scope, tree name,
5215 : tree decl, location_t location)
5216 : {
5217 563 : if (scope == error_mark_node)
5218 : ; /* We already complained. */
5219 448 : else if (TYPE_P (scope))
5220 : {
5221 255 : if (!COMPLETE_TYPE_P (scope)
5222 255 : && !currently_open_class (scope))
5223 44 : error_at (location, "incomplete type %qT used in nested name specifier",
5224 : scope);
5225 211 : else if (TREE_CODE (decl) == TREE_LIST)
5226 : {
5227 0 : auto_diagnostic_group d;
5228 0 : error_at (location, "reference to %<%T::%D%> is ambiguous",
5229 : scope, name);
5230 0 : print_candidates (location, decl);
5231 0 : }
5232 : else
5233 : {
5234 211 : auto_diagnostic_group d;
5235 211 : name_hint hint;
5236 211 : if (SCOPED_ENUM_P (scope) && TREE_CODE (name) == IDENTIFIER_NODE)
5237 15 : hint = suggest_alternative_in_scoped_enum (name, scope);
5238 211 : if (const char *suggestion = hint.suggestion ())
5239 : {
5240 9 : gcc_rich_location richloc (location);
5241 9 : richloc.add_fixit_replace (suggestion);
5242 9 : error_at (&richloc,
5243 : "%qD is not a member of %qT; did you mean %qs?",
5244 : name, scope, suggestion);
5245 9 : }
5246 : else
5247 202 : error_at (location, "%qD is not a member of %qT", name, scope);
5248 211 : }
5249 : }
5250 193 : else if (scope != global_namespace)
5251 : {
5252 175 : auto_diagnostic_group d;
5253 175 : bool emit_fixit = true;
5254 175 : name_hint hint
5255 175 : = suggest_alternative_in_explicit_scope (location, name, scope);
5256 175 : if (!hint)
5257 : {
5258 59 : hint = suggest_alternatives_in_other_namespaces (location, name);
5259 : /* "location" is just the location of the name, not of the explicit
5260 : scope, and it's not easy to get at the latter, so we can't issue
5261 : fix-it hints for the suggestion. */
5262 59 : emit_fixit = false;
5263 : }
5264 175 : if (const char *suggestion = hint.suggestion ())
5265 : {
5266 54 : gcc_rich_location richloc (location);
5267 54 : if (emit_fixit)
5268 33 : richloc.add_fixit_replace (suggestion);
5269 54 : error_at (&richloc, "%qD is not a member of %qD; did you mean %qs?",
5270 : name, scope, suggestion);
5271 54 : }
5272 : else
5273 121 : error_at (location, "%qD is not a member of %qD", name, scope);
5274 175 : }
5275 : else
5276 : {
5277 18 : auto_diagnostic_group d;
5278 18 : name_hint hint = suggest_alternatives_for (location, name, true);
5279 18 : if (const char *suggestion = hint.suggestion ())
5280 : {
5281 9 : gcc_rich_location richloc (location);
5282 9 : richloc.add_fixit_replace (suggestion);
5283 9 : error_at (&richloc,
5284 : "%<::%D%> has not been declared; did you mean %qs?",
5285 : name, suggestion);
5286 9 : }
5287 : else
5288 9 : error_at (location, "%<::%D%> has not been declared", name);
5289 18 : }
5290 563 : }
5291 :
5292 : /* C++-specific implementation of range_label::get_text () vfunc for
5293 : range_label_for_type_mismatch.
5294 :
5295 : Compare with print_template_differences above. */
5296 :
5297 : label_text
5298 437 : range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
5299 : {
5300 437 : if (m_labelled_type == NULL_TREE)
5301 0 : return label_text::borrow (NULL);
5302 :
5303 437 : const bool verbose = false;
5304 437 : const bool show_color = false;
5305 :
5306 437 : const char *result;
5307 437 : if (m_other_type
5308 437 : && comparable_template_types_p (m_labelled_type, m_other_type))
5309 2 : result = type_to_string_with_compare (m_labelled_type, m_other_type,
5310 : verbose, show_color,
5311 : nullptr, nullptr);
5312 : else
5313 435 : result = type_to_string (m_labelled_type, verbose, true, NULL, show_color);
5314 :
5315 : /* Both of the above return GC-allocated buffers, so the caller mustn't
5316 : free them. */
5317 437 : return label_text::borrow (result);
5318 : }
|