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 125928 : class deferred_printed_type
124 : {
125 : public:
126 339624 : deferred_printed_type ()
127 339624 : : m_tree (NULL_TREE),
128 339624 : m_printed_text (),
129 339624 : m_token_list (nullptr),
130 20988 : m_verbose (false), m_quote (false)
131 : {}
132 :
133 20988 : deferred_printed_type (tree type,
134 : pp_token_list &token_list,
135 : bool verbose,
136 : bool quote)
137 20988 : : m_tree (type),
138 20988 : m_printed_text (),
139 20988 : m_token_list (&token_list),
140 20988 : m_verbose (verbose),
141 20988 : m_quote (quote)
142 : {
143 20988 : gcc_assert (type);
144 : }
145 :
146 20988 : 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 62964 : while (m_token_list->m_first)
154 41976 : m_token_list->pop_front ();
155 :
156 20988 : 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 20988 : m_token_list->push_back_text (label_text::borrow (text));
161 :
162 20988 : if (quote)
163 334 : m_token_list->push_back<pp_token_end_quote> ();
164 20988 : }
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 318636 : cxx_format_postprocessor ()
183 318636 : : m_type_a (), m_type_b ()
184 : {}
185 :
186 : std::unique_ptr<format_postprocessor>
187 220216 : clone() const final override
188 : {
189 220216 : 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 887919995 : cxx_dump_pretty_printer::
202 887919995 : cxx_dump_pretty_printer (int phase)
203 887919995 : : phase (phase)
204 : {
205 887919995 : outf = dump_begin (phase, &flags);
206 887919995 : 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 887919995 : }
213 :
214 887919995 : cxx_dump_pretty_printer::
215 887919995 : ~cxx_dump_pretty_printer ()
216 : {
217 887919995 : if (outf)
218 : {
219 0 : pp_flush (this);
220 0 : dump_end (phase, outf);
221 : }
222 887919995 : }
223 :
224 : /* Return the in-scope template that's currently being parsed, or
225 : NULL_TREE otherwise. */
226 :
227 : static tree
228 86679 : get_current_template ()
229 : {
230 86679 : if (scope_chain && in_template_context && !current_instantiation ())
231 10793 : if (tree ti = get_template_info (current_scope ()))
232 : {
233 4824 : if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)) && TI_PARTIAL_INFO (ti))
234 24 : ti = TI_PARTIAL_INFO (ti);
235 4824 : 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 97851050 : cp_adjust_diagnostic_info (const diagnostics::context &context,
255 : diagnostics::diagnostic_info *diagnostic)
256 : {
257 97851050 : if (diagnostic->m_kind == diagnostics::kind::error)
258 86661 : if (tree tmpl = get_current_template ())
259 : {
260 4806 : diagnostic->m_option_id = OPT_Wtemplate_body;
261 :
262 4806 : if (context.m_permissive)
263 48 : diagnostic->m_kind = diagnostics::kind::warning;
264 :
265 4806 : bool existed;
266 4806 : location_t &error_loc
267 4806 : = hash_map_safe_get_or_insert<true> (erroneous_templates,
268 : tmpl, &existed);
269 4806 : 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 2315 : error_loc = diagnostic->m_richloc->get_loc ();
274 : }
275 97851050 : }
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 8692923 : cp_seen_error ()
282 : {
283 8692923 : if ((seen_error) ())
284 : return true;
285 :
286 8671143 : 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 98419 : cxx_initialize_diagnostics (diagnostics::context *context)
303 : {
304 98419 : cxx_pretty_printer *pp = new cxx_pretty_printer ();
305 98419 : pp->set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ());
306 98419 : context->set_pretty_printer (std::unique_ptr<pretty_printer> (pp));
307 :
308 98419 : c_common_diagnostics_set_defaults (context);
309 98419 : diagnostics::text_starter (context) = cp_diagnostic_text_starter;
310 : /* diagnostic_finalizer is already c_diagnostic_text_finalizer. */
311 98419 : context->set_format_decoder (cp_printer);
312 98419 : context->set_adjust_diagnostic_info_callback (cp_adjust_diagnostic_info);
313 98419 : }
314 :
315 : /* Dump an '@module' name suffix for DECL, if it's attached to an import. */
316 :
317 : static void
318 227952978 : dump_module_suffix (cxx_pretty_printer *pp, tree decl)
319 : {
320 227952978 : if (!modules_p ())
321 : return;
322 :
323 175251 : if (!DECL_CONTEXT (decl))
324 : return;
325 :
326 174731 : if (TREE_CODE (decl) != CONST_DECL
327 174731 : || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl)))
328 : {
329 174703 : if (!DECL_NAMESPACE_SCOPE_P (decl))
330 : return;
331 :
332 85012 : if (TREE_CODE (decl) == NAMESPACE_DECL
333 0 : && !DECL_NAMESPACE_ALIAS (decl)
334 85012 : && (TREE_PUBLIC (decl) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl))))
335 : return;
336 : }
337 :
338 85040 : int m = get_originating_module (decl, /*global=-1*/true);
339 85040 : 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 175420987 : dump_scope (cxx_pretty_printer *pp, tree scope, int flags)
356 : {
357 175420987 : int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF);
358 :
359 175420987 : 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 175203013 : if (UNSCOPED_ENUM_P (scope))
366 202 : scope = CP_TYPE_CONTEXT (scope);
367 :
368 175203013 : if (TREE_CODE (scope) == NAMESPACE_DECL)
369 : {
370 156947468 : if (scope != global_namespace)
371 : {
372 87635394 : dump_decl (pp, scope, f);
373 87635394 : pp_cxx_colon_colon (pp);
374 : }
375 : }
376 18255545 : else if (AGGREGATE_TYPE_P (scope)
377 18255545 : || SCOPED_ENUM_P (scope))
378 : {
379 17853605 : dump_type (pp, scope, f);
380 17853605 : pp_cxx_colon_colon (pp);
381 : }
382 401940 : else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL)
383 : {
384 387276 : dump_function_decl (pp, scope, f | TFF_NO_TEMPLATE_BINDINGS);
385 387276 : pp_cxx_colon_colon (pp);
386 : }
387 : }
388 :
389 : /* Dump the template ARGument under control of FLAGS. */
390 :
391 : static void
392 149889675 : dump_template_argument (cxx_pretty_printer *pp, tree arg, int flags)
393 : {
394 149889675 : if (ARGUMENT_PACK_P (arg))
395 7181721 : 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 142707954 : else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
399 121935483 : dump_type (pp, arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
400 : else
401 : {
402 20772471 : if (TREE_CODE (arg) == TREE_LIST)
403 0 : arg = TREE_VALUE (arg);
404 :
405 : /* Strip implicit conversions. */
406 20772531 : while (CONVERT_EXPR_P (arg))
407 60 : arg = TREE_OPERAND (arg, 0);
408 :
409 20772471 : dump_expr (pp, arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM);
410 : }
411 149889675 : }
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 95875790 : get_non_default_template_args_count (tree args, int flags)
418 : {
419 95875790 : int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args));
420 :
421 95875790 : 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 95875790 : (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0
427 4109638 : || !flag_pretty_templates)
428 : return n;
429 :
430 4109581 : 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 7185411 : dump_template_argument_list (cxx_pretty_printer *pp, tree args, int flags)
438 : {
439 7185411 : int n = get_non_default_template_args_count (args, flags);
440 7185411 : int need_comma = 0;
441 7185411 : int i;
442 :
443 21432747 : for (i = 0; i < n; ++i)
444 : {
445 14247336 : 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 14247336 : if (need_comma
451 14247336 : && (!ARGUMENT_PACK_P (arg)
452 188 : || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
453 7616350 : pp_separate_with_comma (pp);
454 :
455 14247336 : dump_template_argument (pp, arg, flags);
456 14247336 : need_comma = 1;
457 : }
458 7185411 : }
459 :
460 : /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
461 :
462 : static void
463 73510 : dump_template_parameter (cxx_pretty_printer *pp, tree parm, int flags)
464 : {
465 73510 : tree p;
466 73510 : tree a;
467 :
468 73510 : if (parm == error_mark_node)
469 : return;
470 :
471 73510 : p = TREE_VALUE (parm);
472 73510 : a = TREE_PURPOSE (parm);
473 :
474 73510 : if (TREE_CODE (p) == TYPE_DECL)
475 : {
476 66443 : if (flags & TFF_DECL_SPECIFIERS)
477 : {
478 10607 : pp_cxx_ws_string (pp, "class");
479 10607 : if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p)))
480 854 : pp_cxx_ws_string (pp, "...");
481 10607 : if (DECL_NAME (p))
482 9864 : pp_cxx_tree_identifier (pp, DECL_NAME (p));
483 : }
484 55836 : else if (DECL_NAME (p))
485 55006 : 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 7067 : dump_decl (pp, p, flags | TFF_DECL_SPECIFIERS);
491 :
492 73510 : 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 38980 : 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 38980 : struct prepost_semicolon
516 : {
517 : cxx_pretty_printer *pp;
518 : bool need_semicolon;
519 :
520 71369 : void operator() ()
521 : {
522 71369 : if (need_semicolon)
523 32389 : pp_separate_with_semicolon (pp);
524 : else
525 : {
526 38980 : pp_cxx_whitespace (pp);
527 38980 : pp_string (pp, colorize_start (pp_show_color (pp), "targs"));
528 38980 : pp_cxx_left_bracket (pp);
529 38980 : pp->translate_string ("with");
530 38980 : pp_cxx_whitespace (pp);
531 38980 : need_semicolon = true;
532 : }
533 71369 : }
534 :
535 38980 : ~prepost_semicolon ()
536 : {
537 38980 : if (need_semicolon)
538 : {
539 38980 : pp_cxx_right_bracket (pp);
540 38980 : pp_string (pp, colorize_stop (pp_show_color (pp)));
541 : }
542 38980 : }
543 38980 : } semicolon_or_introducer = {pp, false};
544 :
545 38980 : int i;
546 38980 : tree t;
547 :
548 79456 : while (parms)
549 : {
550 40476 : tree p = TREE_VALUE (parms);
551 40476 : int lvl = TMPL_PARMS_DEPTH (parms);
552 40476 : int arg_idx = 0;
553 40476 : int i;
554 40476 : tree lvl_args = NULL_TREE;
555 :
556 : /* Don't crash if we had an invalid argument list. */
557 118451 : if (TMPL_ARGS_DEPTH (args) >= lvl)
558 80940 : lvl_args = TMPL_ARGS_LEVEL (args, lvl);
559 :
560 102277 : for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
561 : {
562 61801 : tree arg = NULL_TREE;
563 :
564 : /* Don't crash if we had an invalid argument list. */
565 123596 : if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx)
566 61795 : arg = TREE_VEC_ELT (lvl_args, arg_idx);
567 :
568 61801 : tree parm_i = TREE_VEC_ELT (p, i);
569 : /* If the template argument repeats the template parameter (T = T),
570 : skip the parameter.*/
571 61766 : 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 62814 : && (DECL_NAME (TREE_VALUE (parm_i))
578 1013 : == DECL_NAME (TYPE_STUB_DECL (arg))))
579 559 : continue;
580 :
581 61242 : semicolon_or_introducer ();
582 61242 : dump_template_parameter (pp, parm_i, TFF_PLAIN_IDENTIFIER);
583 61242 : pp_cxx_whitespace (pp);
584 61242 : pp_equal (pp);
585 61242 : pp_cxx_whitespace (pp);
586 61242 : if (arg)
587 : {
588 61207 : if (ARGUMENT_PACK_P (arg))
589 2235 : pp_cxx_left_brace (pp);
590 61207 : dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER);
591 61207 : if (ARGUMENT_PACK_P (arg))
592 2235 : pp_cxx_right_brace (pp);
593 : }
594 : else
595 35 : pp_string (pp, M_("<missing>"));
596 :
597 61242 : ++arg_idx;
598 : }
599 :
600 40476 : parms = TREE_CHAIN (parms);
601 : }
602 :
603 : /* Don't bother with typenames for a partial instantiation. */
604 46858 : if (vec_safe_is_empty (typenames) || uses_template_parms (args))
605 31312 : return;
606 :
607 : /* Don't try to print typenames when we're processing a clone. */
608 7668 : if (current_function_decl
609 7668 : && !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 7668 : if (at_eof >= 3)
615 : return;
616 :
617 17562 : FOR_EACH_VEC_SAFE_ELT (typenames, i, t)
618 : {
619 10127 : semicolon_or_introducer ();
620 10127 : dump_type (pp, t, TFF_PLAIN_IDENTIFIER);
621 10127 : pp_cxx_whitespace (pp);
622 10127 : pp_equal (pp);
623 10127 : pp_cxx_whitespace (pp);
624 10127 : push_deferring_access_checks (dk_no_check);
625 10127 : t = tsubst (t, args, tf_none, NULL_TREE);
626 10127 : 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 10127 : t = strip_typedefs (t, NULL, STF_USER_VISIBLE);
630 10127 : dump_type (pp, t, TFF_PLAIN_IDENTIFIER);
631 : }
632 38980 : }
633 :
634 : /* Dump a human-readable equivalent of the alias template
635 : specialization of T. */
636 :
637 : static void
638 6596 : dump_alias_template_specialization (cxx_pretty_printer *pp, tree t, int flags)
639 : {
640 6596 : gcc_assert (alias_template_specialization_p (t, nt_opaque));
641 :
642 6596 : tree decl = TYPE_NAME (t);
643 6596 : if (!(flags & TFF_UNQUALIFIED_NAME))
644 6596 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags);
645 6596 : pp_cxx_tree_identifier (pp, DECL_NAME (decl));
646 6596 : dump_template_parms (pp, DECL_TEMPLATE_INFO (decl),
647 : /*primary=*/false,
648 : flags & ~TFF_TEMPLATE_HEADER);
649 6596 : }
650 :
651 : /* Dump a human-readable equivalent of TYPE. FLAGS controls the
652 : format. */
653 :
654 : static void
655 219891999 : dump_type (cxx_pretty_printer *pp, tree t, int flags)
656 : {
657 219892029 : if (t == NULL_TREE)
658 : return;
659 :
660 : /* Don't print e.g. "struct mytypedef". */
661 219892015 : if (TYPE_P (t) && typedef_variant_p (t))
662 : {
663 1110214 : tree decl = TYPE_NAME (t);
664 1110214 : if ((flags & TFF_CHASE_TYPEDEF)
665 1110214 : || DECL_SELF_REFERENCE_P (decl)
666 2219833 : || (!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 1109613 : else if (alias_template_specialization_p (t, nt_opaque))
674 : {
675 6596 : dump_alias_template_specialization (pp, t, flags);
676 6596 : return;
677 : }
678 1103017 : else if (same_type_p (t, TREE_TYPE (decl)))
679 : t = decl;
680 : else
681 : {
682 3169 : pp_cxx_cv_qualifier_seq (pp, t);
683 3169 : if (! (flags & TFF_UNQUALIFIED_NAME))
684 3169 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags);
685 3169 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
686 3169 : return;
687 : }
688 : }
689 :
690 219882250 : if (TYPE_PTRMEMFUNC_P (t))
691 169145 : goto offset_type;
692 :
693 219713105 : switch (TREE_CODE (t))
694 : {
695 438 : case LANG_TYPE:
696 438 : if (t == init_list_type_node)
697 278 : pp_string (pp, M_("<brace-enclosed initializer list>"));
698 160 : else if (t == unknown_type_node)
699 160 : 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 293 : case IDENTIFIER_NODE:
728 293 : pp_cxx_tree_identifier (pp, t);
729 293 : break;
730 :
731 24 : case TREE_BINFO:
732 24 : dump_type (pp, BINFO_TYPE (t), flags);
733 24 : break;
734 :
735 134197725 : case RECORD_TYPE:
736 134197725 : case UNION_TYPE:
737 134197725 : case ENUMERAL_TYPE:
738 134197725 : dump_aggr_type (pp, t, flags);
739 134197725 : break;
740 :
741 1100406 : case TYPE_DECL:
742 1100406 : 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 1575711 : case TEMPLATE_DECL:
751 1575711 : case NAMESPACE_DECL:
752 1575711 : case CONST_DECL:
753 1575711 : dump_decl (pp, t, flags & ~TFF_DECL_SPECIFIERS);
754 1575711 : break;
755 :
756 56057622 : case INTEGER_TYPE:
757 56057622 : case REAL_TYPE:
758 56057622 : case VOID_TYPE:
759 56057622 : case OPAQUE_TYPE:
760 56057622 : case BOOLEAN_TYPE:
761 56057622 : case COMPLEX_TYPE:
762 56057622 : case VECTOR_TYPE:
763 56057622 : case FIXED_POINT_TYPE:
764 56057622 : pp_type_specifier_seq (pp, t);
765 56057622 : break;
766 :
767 1575 : case TEMPLATE_TEMPLATE_PARM:
768 : /* For parameters inside template signature. */
769 1575 : if (TYPE_IDENTIFIER (t))
770 3060 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
771 : else
772 45 : pp_cxx_canonical_template_parameter (pp, t);
773 : break;
774 :
775 420 : case BOUND_TEMPLATE_TEMPLATE_PARM:
776 420 : {
777 420 : tree args = TYPE_TI_ARGS (t);
778 420 : pp_cxx_cv_qualifier_seq (pp, t);
779 840 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
780 420 : pp_cxx_begin_template_argument_list (pp);
781 420 : dump_template_argument_list (pp, args, flags);
782 420 : pp_cxx_end_template_argument_list (pp);
783 : }
784 420 : break;
785 :
786 234896 : case TEMPLATE_TYPE_PARM:
787 234896 : pp_cxx_cv_qualifier_seq (pp, t);
788 234896 : 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 234839 : else if (TYPE_IDENTIFIER (t))
795 467950 : pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
796 : else
797 864 : pp_cxx_canonical_template_parameter
798 864 : (pp, TEMPLATE_TYPE_PARM_INDEX (t));
799 : /* If this is a constrained placeholder, add the requirements. */
800 234896 : 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 27649285 : case ARRAY_TYPE:
807 27649285 : case POINTER_TYPE:
808 27649285 : case REFERENCE_TYPE:
809 27649285 : case OFFSET_TYPE:
810 27649285 : offset_type:
811 27649285 : case FUNCTION_TYPE:
812 27649285 : case METHOD_TYPE:
813 27649285 : {
814 27649285 : dump_type_prefix (pp, t, flags);
815 27649285 : dump_type_suffix (pp, t, flags);
816 27649285 : break;
817 : }
818 3264 : case TYPENAME_TYPE:
819 3264 : if (! (flags & TFF_CHASE_TYPEDEF)
820 3264 : && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
821 : {
822 0 : dump_decl (pp, TYPE_NAME (t), TFF_PLAIN_IDENTIFIER);
823 0 : break;
824 : }
825 3264 : pp_cxx_cv_qualifier_seq (pp, t);
826 3264 : if (const char *tag = tag_name (get_typename_tag (t)))
827 3235 : pp_cxx_ws_string (pp, tag);
828 3264 : dump_typename (pp, t, flags);
829 3264 : 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 33961 : case TYPE_PACK_EXPANSION:
854 33961 : dump_type (pp, PACK_EXPANSION_PATTERN (t), flags);
855 33961 : pp_cxx_ws_string (pp, "...");
856 33961 : 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 724 : case DECLTYPE_TYPE:
870 724 : pp_cxx_ws_string (pp, "decltype");
871 724 : pp_cxx_whitespace (pp);
872 724 : pp_cxx_left_paren (pp);
873 724 : dump_expr (pp, DECLTYPE_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS);
874 724 : pp_cxx_right_paren (pp);
875 724 : break;
876 :
877 125124 : case NULLPTR_TYPE:
878 125124 : pp_cxx_ws_string (pp, "std::nullptr_t");
879 125124 : break;
880 :
881 929 : case META_TYPE:
882 929 : pp_cxx_ws_string (pp, "std::meta::info");
883 929 : 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 3762 : dump_typename (cxx_pretty_printer *pp, tree t, int flags)
904 : {
905 3762 : tree ctx = TYPE_CONTEXT (t);
906 :
907 3762 : if (TREE_CODE (ctx) == TYPENAME_TYPE)
908 498 : dump_typename (pp, ctx, flags);
909 : else
910 3264 : dump_type (pp, ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
911 3762 : pp_cxx_colon_colon (pp);
912 3762 : dump_decl (pp, TYPENAME_TYPE_FULLNAME (t), flags);
913 3762 : }
914 :
915 : /* Return the name of the supplied aggregate, or enumeral type. */
916 :
917 : const char *
918 134370986 : class_key_or_enum_as_string (tree t)
919 : {
920 134370986 : if (TREE_CODE (t) == ENUMERAL_TYPE)
921 : {
922 2449384 : if (SCOPED_ENUM_P (t))
923 : return "enum class";
924 : else
925 1164623 : return "enum";
926 : }
927 131921602 : else if (TREE_CODE (t) == UNION_TYPE)
928 : return "union";
929 131238877 : else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
930 37568697 : 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 134370877 : dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags)
948 : {
949 134370877 : const char *variety = class_key_or_enum_as_string (t);
950 134370877 : int typdef = 0;
951 134370877 : int tmplate = 0;
952 :
953 134370877 : pp_cxx_cv_qualifier_seq (pp, t);
954 :
955 134370877 : if (flags & TFF_CLASS_KEY_OR_ENUM)
956 11809 : pp_cxx_ws_string (pp, variety);
957 :
958 134370877 : tree decl = TYPE_NAME (t);
959 :
960 134370877 : if (decl)
961 : {
962 134370877 : typdef = (!DECL_ARTIFICIAL (decl)
963 : /* An alias specialization is not considered to be a
964 : typedef. */
965 134370877 : && !alias_template_specialization_p (t, nt_opaque));
966 :
967 333354 : if ((typdef
968 333354 : && ((flags & TFF_CHASE_TYPEDEF)
969 333354 : || (!flag_pretty_templates && DECL_LANG_SPECIFIC (decl)
970 0 : && DECL_TEMPLATE_INFO (decl))))
971 134370877 : || 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 134037523 : tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
979 131588246 : && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
980 224609215 : && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
981 90238338 : || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
982 :
983 134370877 : if (! (flags & TFF_UNQUALIFIED_NAME))
984 86108470 : dump_scope (pp, CP_DECL_CONTEXT (decl), flags | TFF_SCOPE);
985 134370877 : flags &= ~TFF_UNQUALIFIED_NAME;
986 134370877 : if (tmplate)
987 : {
988 : /* Because the template names are mangled, we have to locate
989 : the most general template, and use that name. */
990 88515597 : tree tpl = TYPE_TI_TEMPLATE (t);
991 :
992 89162506 : while (DECL_TEMPLATE_INFO (tpl))
993 646909 : tpl = DECL_TI_TEMPLATE (tpl);
994 : decl = tpl;
995 : }
996 : }
997 :
998 265609571 : if (LAMBDA_TYPE_P (t))
999 : {
1000 : /* A lambda's "type" is essentially its signature. */
1001 296842 : pp_string (pp, M_("<lambda"));
1002 296842 : tree const fn = lambda_function (t);
1003 296842 : if (fn)
1004 : {
1005 296821 : int const parm_flags
1006 296821 : = DECL_XOBJ_MEMBER_FUNCTION_P (fn) ? TFF_XOBJ_FUNC | flags
1007 120 : : flags;
1008 296821 : dump_parameters (pp, FUNCTION_FIRST_USER_PARMTYPE (fn), parm_flags);
1009 : }
1010 296842 : pp_greater (pp);
1011 : }
1012 134074035 : else if (!decl || IDENTIFIER_ANON_P (DECL_NAME (decl)))
1013 : {
1014 1817 : if (flags & TFF_CLASS_KEY_OR_ENUM)
1015 214 : pp_string (pp, M_("<unnamed>"));
1016 : else
1017 1603 : pp_printf (pp, M_("<unnamed %s>"), variety);
1018 : }
1019 : else
1020 134072218 : pp_cxx_tree_identifier (pp, DECL_NAME (decl));
1021 :
1022 134370877 : dump_module_suffix (pp, decl);
1023 :
1024 134370877 : if (tmplate)
1025 88515597 : dump_template_parms (pp, TYPE_TEMPLATE_INFO (t),
1026 88515597 : !CLASSTYPE_USE_TEMPLATE (t),
1027 : flags & ~TFF_TEMPLATE_HEADER);
1028 134370877 : }
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 57727193 : dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags)
1047 : {
1048 58974213 : if (TYPE_PTRMEMFUNC_P (t))
1049 : {
1050 172990 : t = TYPE_PTRMEMFUNC_FN_TYPE (t);
1051 172990 : goto offset_type;
1052 : }
1053 :
1054 58801223 : switch (TREE_CODE (t))
1055 : {
1056 29580839 : case POINTER_TYPE:
1057 29580839 : case REFERENCE_TYPE:
1058 29580839 : {
1059 29580839 : tree sub = TREE_TYPE (t);
1060 :
1061 29580839 : dump_type_prefix (pp, sub, flags);
1062 29580839 : if (TREE_CODE (sub) == ARRAY_TYPE
1063 29411704 : || TREE_CODE (sub) == FUNCTION_TYPE)
1064 : {
1065 430106 : pp_cxx_whitespace (pp);
1066 430106 : 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 430106 : if (!cxx11_attribute_p (TYPE_ATTRIBUTES (sub)))
1072 430101 : pp_c_attributes_display (pp, TYPE_ATTRIBUTES (sub));
1073 : }
1074 29580839 : if (TYPE_PTR_P (t))
1075 16320424 : pp_star (pp);
1076 13260415 : else if (TYPE_REF_P (t))
1077 : {
1078 13260415 : if (TYPE_REF_IS_RVALUE (t))
1079 1986152 : pp_ampersand_ampersand (pp);
1080 : else
1081 11274263 : pp_ampersand (pp);
1082 : }
1083 29580839 : pp->set_padding (pp_before);
1084 29580839 : pp_cxx_cv_qualifier_seq (pp, t);
1085 : }
1086 29580839 : break;
1087 :
1088 182136 : case OFFSET_TYPE:
1089 182136 : offset_type:
1090 182136 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1091 182136 : if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
1092 : {
1093 9146 : pp_maybe_space (pp);
1094 9146 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1095 436 : pp_cxx_left_paren (pp);
1096 9146 : dump_type (pp, TYPE_OFFSET_BASETYPE (t), flags);
1097 9146 : pp_cxx_colon_colon (pp);
1098 : }
1099 182136 : pp_cxx_star (pp);
1100 182136 : pp_cxx_cv_qualifier_seq (pp, t);
1101 182136 : pp->set_padding (pp_before);
1102 182136 : break;
1103 :
1104 : /* This can be reached without a pointer when dealing with
1105 : templates, e.g. std::is_function. */
1106 493447 : case FUNCTION_TYPE:
1107 493447 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1108 493447 : break;
1109 :
1110 173152 : case METHOD_TYPE:
1111 173152 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1112 173152 : pp_maybe_space (pp);
1113 173152 : pp_cxx_left_paren (pp);
1114 173152 : dump_aggr_type (pp, TYPE_METHOD_BASETYPE (t), flags);
1115 173152 : pp_cxx_colon_colon (pp);
1116 173152 : break;
1117 :
1118 753573 : case ARRAY_TYPE:
1119 753573 : dump_type_prefix (pp, TREE_TYPE (t), flags);
1120 753573 : break;
1121 :
1122 27791035 : case ENUMERAL_TYPE:
1123 27791035 : case IDENTIFIER_NODE:
1124 27791035 : case INTEGER_TYPE:
1125 27791035 : case BOOLEAN_TYPE:
1126 27791035 : case REAL_TYPE:
1127 27791035 : case RECORD_TYPE:
1128 27791035 : case TEMPLATE_TYPE_PARM:
1129 27791035 : case TEMPLATE_TEMPLATE_PARM:
1130 27791035 : case BOUND_TEMPLATE_TEMPLATE_PARM:
1131 27791035 : case TREE_LIST:
1132 27791035 : case TYPE_DECL:
1133 27791035 : case TREE_VEC:
1134 27791035 : case UNION_TYPE:
1135 27791035 : case LANG_TYPE:
1136 27791035 : case VOID_TYPE:
1137 27791035 : case OPAQUE_TYPE:
1138 27791035 : case TYPENAME_TYPE:
1139 27791035 : case COMPLEX_TYPE:
1140 27791035 : case VECTOR_TYPE:
1141 27791035 : case TYPEOF_TYPE:
1142 27791035 : case TRAIT_TYPE:
1143 27791035 : case DECLTYPE_TYPE:
1144 27791035 : case TYPE_PACK_EXPANSION:
1145 27791035 : case FIXED_POINT_TYPE:
1146 27791035 : case NULLPTR_TYPE:
1147 27791035 : case PACK_INDEX_TYPE:
1148 27791035 : case META_TYPE:
1149 27791035 : case SPLICE_SCOPE:
1150 27791035 : dump_type (pp, t, flags);
1151 27791035 : pp->set_padding (pp_before);
1152 27791035 : 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 57727193 : }
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 27791403 : dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags)
1168 : {
1169 58974550 : if (TYPE_PTRMEMFUNC_P (t))
1170 172990 : t = TYPE_PTRMEMFUNC_FN_TYPE (t);
1171 :
1172 58974550 : switch (TREE_CODE (t))
1173 : {
1174 29762975 : case POINTER_TYPE:
1175 29762975 : case REFERENCE_TYPE:
1176 29762975 : case OFFSET_TYPE:
1177 29762975 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1178 29762975 : || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1179 430542 : pp_cxx_right_paren (pp);
1180 29762975 : if (TREE_CODE (t) == POINTER_TYPE)
1181 16493414 : flags |= TFF_POINTER;
1182 29762975 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1183 29762975 : break;
1184 :
1185 666599 : case FUNCTION_TYPE:
1186 666599 : case METHOD_TYPE:
1187 666599 : {
1188 666599 : tree arg;
1189 666599 : if (TREE_CODE (t) == METHOD_TYPE)
1190 : /* Can only be reached through a pointer. */
1191 173152 : pp_cxx_right_paren (pp);
1192 666599 : arg = TYPE_ARG_TYPES (t);
1193 666599 : if (TREE_CODE (t) == METHOD_TYPE)
1194 173152 : 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 666599 : dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
1199 :
1200 666599 : pp->set_padding (pp_before);
1201 996831 : pp_cxx_cv_qualifiers (pp, type_memfn_quals (t),
1202 : TREE_CODE (t) == FUNCTION_TYPE
1203 : && (flags & TFF_POINTER));
1204 666599 : dump_ref_qualifier (pp, t, flags);
1205 666599 : if (tx_safe_fn_type_p (t))
1206 19 : pp_cxx_ws_string (pp, "transaction_safe");
1207 666599 : dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags);
1208 : /* If this is the standard [[]] attribute, print
1209 : void (*)() [[noreturn]]; */
1210 666599 : 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 666599 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1217 666599 : break;
1218 : }
1219 :
1220 753573 : case ARRAY_TYPE:
1221 753573 : pp_maybe_space (pp);
1222 753573 : pp_cxx_left_bracket (pp);
1223 753573 : if (tree dtype = TYPE_DOMAIN (t))
1224 : {
1225 123592 : 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 123592 : if (!max || integer_all_onesp (max))
1231 651 : pp_character (pp, '0');
1232 122941 : else if (tree_fits_shwi_p (max))
1233 122383 : 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 753573 : pp_cxx_right_bracket (pp);
1254 753573 : dump_type_suffix (pp, TREE_TYPE (t), flags);
1255 753573 : 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 27791403 : }
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 48 : dump_omp_declare_mapper (cxx_pretty_printer *pp, tree t, int flags)
1316 : {
1317 48 : pp_string (pp, "#pragma omp declare mapper");
1318 48 : if (t == NULL_TREE || t == error_mark_node)
1319 : return;
1320 48 : pp_space (pp);
1321 48 : pp_cxx_left_paren (pp);
1322 48 : if (OMP_DECLARE_MAPPER_ID (t))
1323 : {
1324 12 : pp_cxx_tree_identifier (pp, OMP_DECLARE_MAPPER_ID (t));
1325 12 : pp_colon (pp);
1326 : }
1327 48 : dump_type (pp, TREE_TYPE (t), flags);
1328 48 : pp_cxx_right_paren (pp);
1329 : }
1330 :
1331 : static void
1332 1316341 : dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
1333 : {
1334 1316341 : if (VAR_P (t) && DECL_NTTP_OBJECT_P (t))
1335 21980 : return dump_expr (pp, DECL_INITIAL (t), flags);
1336 :
1337 1294361 : if (TREE_CODE (t) == VAR_DECL
1338 26263 : && DECL_LANG_SPECIFIC (t)
1339 1300070 : && DECL_OMP_DECLARE_MAPPER_P (t))
1340 48 : return dump_omp_declare_mapper (pp, DECL_INITIAL (t), flags);
1341 :
1342 1294313 : if (flags & TFF_DECL_SPECIFIERS)
1343 : {
1344 26195 : if (concept_definition_p (t))
1345 337 : pp_cxx_ws_string (pp, "concept");
1346 25858 : else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t))
1347 510 : pp_cxx_ws_string (pp, "constexpr");
1348 :
1349 26195 : if (!concept_definition_p (t))
1350 25858 : dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME);
1351 26195 : pp_maybe_space (pp);
1352 : }
1353 1294313 : if (! (flags & TFF_UNQUALIFIED_NAME)
1354 1282856 : && TREE_CODE (t) != PARM_DECL
1355 2557208 : && (!DECL_INITIAL (t)
1356 9309 : || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX))
1357 1261363 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
1358 1294313 : flags &= ~TFF_UNQUALIFIED_NAME;
1359 1294313 : if ((flags & TFF_DECL_SPECIFIERS)
1360 26195 : && DECL_TEMPLATE_PARM_P (t)
1361 1300453 : && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t)))
1362 503 : pp_string (pp, "...");
1363 1294313 : if (DECL_NAME (t))
1364 : {
1365 1292407 : 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 1292395 : dump_decl (pp, DECL_NAME (t), flags);
1373 : }
1374 1906 : else if (DECL_DECOMPOSITION_P (t))
1375 53 : pp_string (pp, M_("<structured bindings>"));
1376 1853 : else if (TREE_CODE (t) == FIELD_DECL && DECL_FIELD_IS_BASE (t))
1377 512 : dump_type (pp, TREE_TYPE (t), flags);
1378 : else
1379 1341 : pp_string (pp, M_("<anonymous>"));
1380 :
1381 1294313 : dump_module_suffix (pp, t);
1382 :
1383 1294313 : if (flags & TFF_DECL_SPECIFIERS)
1384 26195 : dump_type_suffix (pp, type, flags);
1385 : }
1386 :
1387 : class colorize_guard
1388 : {
1389 : bool colorize;
1390 : cxx_pretty_printer *pp;
1391 : public:
1392 92293899 : colorize_guard (bool _colorize, cxx_pretty_printer *pp, const char *name)
1393 92293899 : : colorize (_colorize && pp_show_color (pp)), pp (pp)
1394 : {
1395 92293899 : pp_string (pp, colorize_start (colorize, name));
1396 92293899 : }
1397 92293899 : ~colorize_guard ()
1398 : {
1399 92293899 : pp_string (pp, colorize_stop (colorize));
1400 92293899 : }
1401 : };
1402 :
1403 : /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1404 :
1405 : static void
1406 187328478 : 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 187328478 : 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 187328451 : if (dguide_name_p (t))
1418 : {
1419 860 : dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)),
1420 : TFF_UNQUALIFIED_NAME);
1421 860 : return;
1422 : }
1423 :
1424 187327591 : const char *str = IDENTIFIER_POINTER (t);
1425 187327591 : if (startswith (str, "_ZGR"))
1426 : {
1427 9 : pp_cxx_ws_string (pp, "<temporary>");
1428 9 : return;
1429 : }
1430 :
1431 187327582 : 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 325207563 : dump_decl (cxx_pretty_printer *pp, tree t, int flags)
1438 : {
1439 325209202 : 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 325209202 : 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 325209202 : switch (TREE_CODE (t))
1455 : {
1456 49536920 : case TYPE_DECL:
1457 : /* Don't say 'typedef class A' */
1458 49536920 : if (DECL_ARTIFICIAL (t) && !DECL_SELF_REFERENCE_P (t))
1459 : {
1460 48298498 : if ((flags & TFF_DECL_SPECIFIERS)
1461 48298498 : && 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 48298498 : dump_type (pp, TREE_TYPE (t), flags);
1472 48298498 : break;
1473 : }
1474 1238422 : if (TYPE_DECL_ALIAS_P (t)
1475 1238422 : && (flags & TFF_DECL_SPECIFIERS
1476 735858 : || 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 1237940 : if ((flags & TFF_DECL_SPECIFIERS)
1491 1237940 : && !DECL_SELF_REFERENCE_P (t))
1492 11654 : pp_cxx_ws_string (pp, "typedef");
1493 1249496 : dump_simple_decl (pp, t, DECL_ORIGINAL_TYPE (t)
1494 11556 : ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
1495 : flags);
1496 1237940 : break;
1497 :
1498 48243 : case VAR_DECL:
1499 48243 : 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 76056 : case FIELD_DECL:
1508 76056 : case PARM_DECL:
1509 76056 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1510 :
1511 : /* Handle variable template specializations. */
1512 76056 : if (VAR_P (t)
1513 48243 : && DECL_LANG_SPECIFIC (t)
1514 5709 : && DECL_TEMPLATE_INFO (t)
1515 77949 : && 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 87662930 : case NAMESPACE_DECL:
1530 87662930 : if (flags & TFF_DECL_SPECIFIERS)
1531 81 : pp->declaration (t);
1532 : else
1533 : {
1534 87662849 : if (! (flags & TFF_UNQUALIFIED_NAME))
1535 87662828 : dump_scope (pp, CP_DECL_CONTEXT (t), flags);
1536 87662849 : flags &= ~TFF_UNQUALIFIED_NAME;
1537 87662849 : if (DECL_NAME (t) == NULL_TREE)
1538 : {
1539 7412 : if (!(pp->flags & pp_c_flag_gnu_v3))
1540 1700 : pp_cxx_ws_string (pp, M_("{anonymous}"));
1541 : else
1542 5712 : pp_cxx_ws_string (pp, M_("(anonymous namespace)"));
1543 : }
1544 : else
1545 87655437 : 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 1651 : case RECORD_TYPE:
1564 1651 : case UNION_TYPE:
1565 1651 : case ENUMERAL_TYPE:
1566 1651 : dump_type (pp, t, flags);
1567 1651 : 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 187328478 : break;
1579 :
1580 187328478 : case IDENTIFIER_NODE:
1581 187328478 : dump_decl_name (pp, t, flags);
1582 187328478 : break;
1583 :
1584 300 : case OVERLOAD:
1585 300 : if (!OVL_SINGLE_P (t))
1586 : {
1587 122 : tree ctx = ovl_scope (t);
1588 122 : if (ctx != global_namespace)
1589 : {
1590 69 : if (TYPE_P (ctx))
1591 59 : dump_type (pp, ctx, flags);
1592 : else
1593 10 : dump_decl (pp, ctx, flags);
1594 69 : pp_cxx_colon_colon (pp);
1595 : }
1596 244 : dump_decl (pp, OVL_NAME (t), flags);
1597 122 : break;
1598 : }
1599 :
1600 : /* If there's only one function, dump that. */
1601 325209202 : return dump_decl (pp, OVL_FIRST (t), flags);
1602 :
1603 139219 : case FUNCTION_DECL:
1604 139219 : if (! DECL_LANG_SPECIFIC (t))
1605 : {
1606 1644 : if (DECL_ABSTRACT_ORIGIN (t)
1607 1644 : && DECL_ABSTRACT_ORIGIN (t) != t)
1608 313 : dump_decl (pp, DECL_ABSTRACT_ORIGIN (t), flags);
1609 : else
1610 1331 : dump_function_name (pp, t, flags);
1611 : }
1612 137575 : else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
1613 72 : dump_global_iord (pp, t);
1614 : else
1615 137503 : dump_function_decl (pp, t, flags);
1616 : break;
1617 :
1618 457419 : case TEMPLATE_DECL:
1619 457419 : dump_template_decl (pp, t, flags);
1620 457419 : break;
1621 :
1622 362 : case CONCEPT_DECL:
1623 362 : dump_simple_decl (pp, t, TREE_TYPE (t), flags);
1624 362 : break;
1625 :
1626 2231 : case TEMPLATE_ID_EXPR:
1627 2231 : {
1628 2231 : tree name = TREE_OPERAND (t, 0);
1629 2231 : tree args = TREE_OPERAND (t, 1);
1630 :
1631 2231 : if (TREE_CODE (name) == SPLICE_EXPR)
1632 7 : dump_expr (pp, name, flags);
1633 : else
1634 : {
1635 2758 : if (!identifier_p (name))
1636 1590 : name = OVL_NAME (name);
1637 2224 : dump_decl (pp, name, flags);
1638 : }
1639 2231 : pp_cxx_begin_template_argument_list (pp);
1640 2231 : if (args == error_mark_node)
1641 0 : pp_string (pp, M_("<template arguments error>"));
1642 2231 : else if (args)
1643 2135 : dump_template_argument_list
1644 2135 : (pp, args, flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
1645 2231 : pp_cxx_end_template_argument_list (pp);
1646 : }
1647 2231 : 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 2025 : case CONST_DECL:
1657 4044 : if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
1658 3517 : || (DECL_INITIAL (t) &&
1659 1492 : TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
1660 1983 : 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 458980 : dump_template_decl (cxx_pretty_printer *pp, tree t, int flags)
1736 : {
1737 458980 : tree orig_parms = DECL_TEMPLATE_PARMS (t);
1738 458980 : tree parms;
1739 458980 : int i;
1740 :
1741 458980 : if (flags & TFF_TEMPLATE_HEADER)
1742 : {
1743 8091 : for (parms = orig_parms = nreverse (orig_parms);
1744 16722 : parms;
1745 8631 : parms = TREE_CHAIN (parms))
1746 : {
1747 8631 : tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1748 8631 : int len = TREE_VEC_LENGTH (inner_parms);
1749 :
1750 8631 : 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 8333 : pp_cxx_ws_string (pp, "template");
1759 8333 : 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 8333 : flags |= TFF_DECL_SPECIFIERS;
1764 :
1765 20601 : for (i = 0; i < len; i++)
1766 : {
1767 12268 : if (i)
1768 3935 : pp_separate_with_comma (pp);
1769 12268 : dump_template_parameter (pp, TREE_VEC_ELT (inner_parms, i),
1770 : flags);
1771 : }
1772 8333 : pp_cxx_end_template_argument_list (pp);
1773 8333 : pp_cxx_whitespace (pp);
1774 : }
1775 8091 : nreverse(orig_parms);
1776 :
1777 8091 : 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 8091 : if (flag_concepts)
1790 7130 : 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 458980 : if (DECL_CLASS_TEMPLATE_P (t))
1801 324365 : dump_type (pp, TREE_TYPE (t),
1802 324365 : ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1803 324365 : | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)));
1804 134615 : else if (DECL_TEMPLATE_RESULT (t)
1805 134615 : && (VAR_P (DECL_TEMPLATE_RESULT (t))
1806 : /* Alias template. */
1807 134453 : || DECL_TYPE_TEMPLATE_P (t)
1808 : /* Concept definition. &*/
1809 6579 : || TREE_CODE (DECL_TEMPLATE_RESULT (t)) == CONCEPT_DECL))
1810 128383 : dump_decl (pp, DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME);
1811 : else
1812 : {
1813 6232 : gcc_assert (TREE_TYPE (t));
1814 6232 : switch (NEXT_CODE (t))
1815 : {
1816 6232 : case METHOD_TYPE:
1817 6232 : case FUNCTION_TYPE:
1818 6232 : dump_function_decl (pp, t, flags | TFF_TEMPLATE_NAME);
1819 6232 : 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 458980 : }
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 308103 : find_typenames_r (tree *tp, int *walk_subtrees, void *data)
1842 : {
1843 308103 : struct find_typenames_t *d = (struct find_typenames_t *)data;
1844 308103 : tree mv = NULL_TREE;
1845 :
1846 308103 : if (TYPE_P (*tp) && is_typedef_decl (TYPE_NAME (*tp)))
1847 : /* Add the type of the typedef without any additional cv-quals. */
1848 9986 : mv = TREE_TYPE (TYPE_NAME (*tp));
1849 298117 : else if (TREE_CODE (*tp) == TYPENAME_TYPE
1850 297586 : || TREE_CODE (*tp) == DECLTYPE_TYPE)
1851 : /* Add the typename without any cv-qualifiers. */
1852 688 : mv = TYPE_MAIN_VARIANT (*tp);
1853 :
1854 308103 : 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 1925 : *walk_subtrees = false;
1859 1925 : return NULL_TREE;
1860 : }
1861 :
1862 306178 : if (mv && (mv == *tp || !d->p_set->add (mv)))
1863 10658 : vec_safe_push (d->typenames, mv);
1864 :
1865 : return NULL_TREE;
1866 : }
1867 :
1868 : static vec<tree, va_gc> *
1869 37419 : find_typenames (tree t)
1870 : {
1871 37419 : struct find_typenames_t ft;
1872 37419 : ft.p_set = new hash_set<tree>;
1873 37419 : ft.typenames = NULL;
1874 37419 : cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)),
1875 : find_typenames_r, &ft, ft.p_set);
1876 74838 : delete ft.p_set;
1877 37419 : 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 518715 : dump_substitution (cxx_pretty_printer *pp,
1887 : tree t, tree template_parms, tree template_args,
1888 : int flags)
1889 : {
1890 518715 : if (template_parms != NULL_TREE && template_args != NULL_TREE
1891 38980 : && !(flags & TFF_NO_TEMPLATE_BINDINGS))
1892 : {
1893 38980 : vec<tree, va_gc> *typenames = t ? find_typenames (t) : NULL;
1894 38980 : dump_template_bindings (pp, template_parms, template_args, typenames);
1895 : }
1896 518715 : }
1897 :
1898 : /* Dump the lambda function FN including its 'mutable' qualifier and any
1899 : template bindings. */
1900 :
1901 : static void
1902 7289 : 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 7289 : dump_type (pp, DECL_CONTEXT (fn), flags);
1908 7289 : if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
1909 : /* Early escape. */;
1910 7263 : else if (TREE_CODE (TREE_TYPE (fn)) == FUNCTION_TYPE)
1911 : {
1912 176 : pp->set_padding (pp_before);
1913 176 : pp_c_ws_string (pp, "static");
1914 : }
1915 7087 : else if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn)))
1916 7087 : & TYPE_QUAL_CONST))
1917 : {
1918 87 : pp->set_padding (pp_before);
1919 87 : pp_c_ws_string (pp, "mutable");
1920 : }
1921 7289 : dump_substitution (pp, fn, template_parms, template_args, flags);
1922 7289 : }
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 531011 : dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
1931 : {
1932 531011 : tree fntype;
1933 531011 : tree parmtypes;
1934 531011 : tree cname = NULL_TREE;
1935 531011 : tree template_args = NULL_TREE;
1936 531011 : tree template_parms = NULL_TREE;
1937 531011 : int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
1938 531011 : int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
1939 531011 : tree exceptions;
1940 531011 : bool constexpr_p;
1941 531011 : tree ret = NULL_TREE;
1942 :
1943 531011 : int dump_function_name_flags = flags & ~TFF_UNQUALIFIED_NAME;
1944 531011 : flags = dump_function_name_flags & ~TFF_TEMPLATE_NAME;
1945 531011 : if (TREE_CODE (t) == TEMPLATE_DECL)
1946 6232 : 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 531011 : exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t));
1951 :
1952 : /* Likewise for the constexpr specifier, in case t is a specialization. */
1953 531011 : constexpr_p = (DECL_DECLARED_CONSTEXPR_P (t)
1954 531011 : && !decl_implicit_constexpr_p (t));
1955 :
1956 : /* Pretty print template instantiations only. */
1957 737648 : if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t)
1958 206583 : && !(flags & TFF_NO_TEMPLATE_BINDINGS)
1959 568482 : && flag_pretty_templates)
1960 : {
1961 37444 : tree tmpl;
1962 :
1963 37444 : template_args = DECL_TI_ARGS (t);
1964 37444 : tmpl = most_general_template (t);
1965 37444 : if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1966 : {
1967 37419 : template_parms = DECL_TEMPLATE_PARMS (tmpl);
1968 37419 : t = tmpl;
1969 : }
1970 : }
1971 :
1972 541685 : if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
1973 7289 : return dump_lambda_function (pp, t, template_parms, template_args, flags);
1974 :
1975 523722 : fntype = TREE_TYPE (t);
1976 523722 : parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
1977 :
1978 523722 : if (DECL_CLASS_SCOPE_P (t))
1979 145643 : cname = DECL_CONTEXT (t);
1980 : /* This is for partially instantiated template methods. */
1981 378079 : else if (TREE_CODE (fntype) == METHOD_TYPE)
1982 3 : cname = TREE_TYPE (TREE_VALUE (parmtypes));
1983 :
1984 523722 : if (flags & TFF_DECL_SPECIFIERS)
1985 : {
1986 127820 : if (DECL_STATIC_FUNCTION_P (t))
1987 3576 : pp_cxx_ws_string (pp, "static");
1988 124244 : else if (DECL_VIRTUAL_P (t))
1989 2729 : pp_cxx_ws_string (pp, "virtual");
1990 :
1991 127820 : if (constexpr_p)
1992 : {
1993 81990 : if (DECL_IMMEDIATE_FUNCTION_P (t))
1994 330 : pp_cxx_ws_string (pp, "consteval");
1995 : else
1996 40665 : pp_cxx_ws_string (pp, "constexpr");
1997 : }
1998 : }
1999 :
2000 : /* Print the return type? */
2001 523722 : if (show_return)
2002 382578 : show_return = (!DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
2003 245497 : && !DECL_DESTRUCTOR_P (t) && !deduction_guide_p (t));
2004 115923 : if (show_return)
2005 : {
2006 115923 : ret = fndecl_declared_return_type (t);
2007 115923 : dump_type_prefix (pp, ret, flags);
2008 : }
2009 :
2010 : /* Print the function name. */
2011 523722 : if (!do_outer_scope)
2012 : /* Nothing. */;
2013 523722 : else if (cname)
2014 : {
2015 145643 : dump_type (pp, cname, flags);
2016 145643 : pp_cxx_colon_colon (pp);
2017 : }
2018 : else
2019 378079 : 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 523722 : auto cds = make_temp_override (current_dump_scope, CP_DECL_CONTEXT (t));
2024 :
2025 523722 : 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 523722 : pp->set_padding (pp_none);
2030 523722 : pp_cxx_function_target_version (pp, t);
2031 523722 : pp_cxx_maybe_whitespace (pp);
2032 523722 : pp_cxx_function_target_clones (pp, t);
2033 523722 : pp_cxx_maybe_whitespace (pp);
2034 :
2035 523722 : if (!(flags & TFF_NO_FUNCTION_ARGUMENTS))
2036 : {
2037 509865 : int const parm_flags
2038 509865 : = DECL_XOBJ_MEMBER_FUNCTION_P (t) ? TFF_XOBJ_FUNC | flags : flags;
2039 509865 : dump_parameters (pp, parmtypes, parm_flags);
2040 :
2041 509865 : if (TREE_CODE (fntype) == METHOD_TYPE)
2042 : {
2043 138718 : pp->set_padding (pp_before);
2044 138718 : pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (fntype));
2045 138718 : dump_ref_qualifier (pp, fntype, flags);
2046 : }
2047 :
2048 509865 : 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 509865 : if (flags & TFF_EXCEPTION_SPECIFICATION)
2055 : {
2056 350 : pp->set_padding (pp_before);
2057 350 : dump_exception_spec (pp, exceptions, flags);
2058 : }
2059 :
2060 509865 : if (show_return)
2061 115923 : dump_type_suffix (pp, ret, flags);
2062 393942 : else if (deduction_guide_p (t))
2063 : {
2064 668 : pp->set_padding (pp_before);
2065 668 : pp_cxx_ws_string (pp, "->");
2066 668 : dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
2067 : }
2068 :
2069 509865 : if (flag_concepts)
2070 482998 : if (tree ci = get_constraints (t))
2071 49966 : if (tree reqs = CI_DECLARATOR_REQS (ci))
2072 13077 : pp_cxx_requires_clause (pp, reqs);
2073 :
2074 509865 : dump_substitution (pp, t, template_parms, template_args, flags);
2075 :
2076 1019730 : 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 13857 : 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 523722 : }
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 1473285 : dump_parameters (cxx_pretty_printer *pp, tree parmtypes, int flags)
2111 : {
2112 1473285 : int first = 1;
2113 1473285 : flags &= ~TFF_SCOPE;
2114 1473285 : pp_cxx_left_paren (pp);
2115 :
2116 4667202 : for (first = 1; parmtypes != void_list_node;
2117 1720632 : parmtypes = TREE_CHAIN (parmtypes))
2118 : {
2119 1722819 : if (first && flags & TFF_XOBJ_FUNC)
2120 1057 : pp_string (pp, "this ");
2121 849923 : if (!first)
2122 849923 : pp_separate_with_comma (pp);
2123 1722819 : first = 0;
2124 1722819 : if (!parmtypes)
2125 : {
2126 2187 : pp_cxx_ws_string (pp, "...");
2127 2187 : break;
2128 : }
2129 :
2130 1720632 : dump_type (pp, TREE_VALUE (parmtypes), flags);
2131 :
2132 1720647 : 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 1473285 : pp_cxx_right_paren (pp);
2142 1473285 : }
2143 :
2144 : /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
2145 :
2146 : static void
2147 805317 : dump_ref_qualifier (cxx_pretty_printer *pp, tree t, int flags ATTRIBUTE_UNUSED)
2148 : {
2149 805317 : if (FUNCTION_REF_QUALIFIED (t))
2150 : {
2151 1272 : pp->set_padding (pp_before);
2152 1272 : if (FUNCTION_RVALUE_QUALIFIED (t))
2153 389 : pp_cxx_ws_string (pp, "&&");
2154 : else
2155 883 : pp_cxx_ws_string (pp, "&");
2156 : }
2157 805317 : }
2158 :
2159 : /* Print an exception specification. T is the exception specification. */
2160 :
2161 : static void
2162 666952 : dump_exception_spec (cxx_pretty_printer *pp, tree t, int flags)
2163 : {
2164 672042 : if (t && TREE_PURPOSE (t))
2165 : {
2166 4992 : pp_cxx_ws_string (pp, "noexcept");
2167 4992 : 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 661960 : 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 666952 : }
2195 :
2196 : /* Handle the function name for a FUNCTION_DECL node, grokking operators
2197 : and destructors properly. */
2198 :
2199 : static void
2200 92293899 : 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 92293899 : bool colorize = flags & (TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE
2205 : | TFF_TEMPLATE_HEADER);
2206 :
2207 92293899 : colorize_guard g (colorize, pp, "fnname");
2208 :
2209 92293899 : 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 92293899 : if (!DECL_LANG_SPECIFIC (t))
2217 : {
2218 6111 : pp_cxx_tree_identifier (pp, name);
2219 6111 : return;
2220 : }
2221 :
2222 92287788 : if (TREE_CODE (t) == TEMPLATE_DECL)
2223 36353 : t = DECL_TEMPLATE_RESULT (t);
2224 :
2225 : /* Don't let the user see __comp_ctor et al. */
2226 92287788 : if (DECL_CONSTRUCTOR_P (t)
2227 92287788 : || DECL_DESTRUCTOR_P (t))
2228 : {
2229 35967726 : if (LAMBDA_TYPE_P (DECL_CONTEXT (t)))
2230 197580 : name = get_identifier ("<lambda>");
2231 35602021 : else if (TYPE_UNNAMED_P (DECL_CONTEXT (t)))
2232 119 : name = get_identifier ("<constructor>");
2233 : else
2234 17800832 : name = constructor_name (DECL_CONTEXT (t));
2235 : }
2236 :
2237 184575576 : if (DECL_DESTRUCTOR_P (t))
2238 : {
2239 2258125 : pp_cxx_complement (pp);
2240 2258125 : dump_decl (pp, name, TFF_PLAIN_IDENTIFIER);
2241 : }
2242 90029663 : 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 1490246 : pp_cxx_ws_string (pp, "operator");
2251 1490246 : dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
2252 : }
2253 : else
2254 88539417 : dump_decl (pp, name, flags);
2255 :
2256 92287788 : dump_module_suffix (pp, t);
2257 :
2258 92287788 : if (DECL_TEMPLATE_INFO (t)
2259 71124699 : && !(flags & TFF_TEMPLATE_NAME)
2260 71118785 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
2261 163352464 : && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
2262 71064651 : || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
2263 514090 : dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t),
2264 : flags);
2265 92293899 : }
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 89036283 : dump_template_parms (cxx_pretty_printer *pp, tree info,
2275 : int primary, int flags)
2276 : {
2277 178072566 : tree args = info ? TI_ARGS (info) : NULL_TREE;
2278 :
2279 89036283 : if (primary && flags & TFF_TEMPLATE_NAME)
2280 : return;
2281 88711878 : flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME);
2282 88711878 : 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 88711878 : if (args && !primary)
2287 : {
2288 88689493 : int len, ix;
2289 88689493 : len = get_non_default_template_args_count (args, flags);
2290 :
2291 88689493 : args = INNERMOST_TEMPLATE_ARGS (args);
2292 224270551 : for (ix = 0; ix != len; ix++)
2293 : {
2294 135581058 : 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 135581058 : if (ix
2300 135581058 : && (!ARGUMENT_PACK_P (arg)
2301 3171758 : || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
2302 46504639 : pp_separate_with_comma (pp);
2303 :
2304 135581058 : if (!arg)
2305 0 : pp_string (pp, M_("<template parameter error>"));
2306 : else
2307 135581058 : dump_template_argument (pp, arg, flags);
2308 : }
2309 : }
2310 22385 : else if (primary)
2311 : {
2312 22379 : tree tpl = TI_TEMPLATE (info);
2313 22379 : tree parms = DECL_TEMPLATE_PARMS (tpl);
2314 22379 : int len, ix;
2315 :
2316 22379 : parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
2317 44758 : len = parms ? TREE_VEC_LENGTH (parms) : 0;
2318 :
2319 59924 : for (ix = 0; ix != len; ix++)
2320 : {
2321 37545 : tree parm;
2322 :
2323 37545 : 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 37545 : parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
2330 :
2331 37545 : if (ix)
2332 15166 : pp_separate_with_comma (pp);
2333 :
2334 37545 : dump_decl (pp, parm, flags & ~TFF_DECL_SPECIFIERS);
2335 : }
2336 : }
2337 88711878 : 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 5637 : dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst)
2345 : {
2346 5637 : const int len = call_expr_nargs (t);
2347 :
2348 5637 : pp_cxx_left_paren (pp);
2349 11113 : for (int i = skipfirst; i < len; ++i)
2350 : {
2351 5476 : tree arg = get_nth_callarg (t, i);
2352 5476 : dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS);
2353 5476 : if (i + 1 < len)
2354 1679 : pp_separate_with_comma (pp);
2355 : }
2356 5637 : pp_cxx_right_paren (pp);
2357 5637 : }
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 19907 : dump_expr_init_vec (cxx_pretty_printer *pp, vec<constructor_elt, va_gc> *v,
2377 : int flags)
2378 : {
2379 19907 : unsigned HOST_WIDE_INT idx;
2380 19907 : tree value;
2381 :
2382 42628 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2383 : {
2384 22721 : 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 22721 : dump_expr (pp, value, flags | TFF_EXPR_IN_PARENS);
2404 22721 : if (idx != v->length () - 1)
2405 2841 : pp_separate_with_comma (pp);
2406 : }
2407 19907 : }
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 20898449 : dump_expr (cxx_pretty_printer *pp, tree t, int flags)
2435 : {
2436 20917146 : tree op;
2437 :
2438 20917146 : if (t == 0)
2439 : return;
2440 :
2441 20917116 : if (STATEMENT_CLASS_P (t))
2442 : {
2443 15 : pp_cxx_ws_string (pp, M_("<statement>"));
2444 15 : return;
2445 : }
2446 :
2447 20917101 : switch (TREE_CODE (t))
2448 : {
2449 69394 : case VAR_DECL:
2450 69394 : case PARM_DECL:
2451 69394 : case FIELD_DECL:
2452 69394 : case CONST_DECL:
2453 69394 : case FUNCTION_DECL:
2454 69394 : case TEMPLATE_DECL:
2455 69394 : case NAMESPACE_DECL:
2456 69394 : case LABEL_DECL:
2457 69394 : case OVERLOAD:
2458 69394 : case TYPE_DECL:
2459 69394 : case USING_DECL:
2460 69394 : case IDENTIFIER_NODE:
2461 69394 : dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
2462 : |TFF_TEMPLATE_HEADER))
2463 : | TFF_NO_TEMPLATE_BINDINGS
2464 69394 : | TFF_NO_FUNCTION_ARGUMENTS));
2465 69394 : break;
2466 :
2467 6409 : case SSA_NAME:
2468 6409 : if (SSA_NAME_VAR (t)
2469 6337 : && !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 20779144 : case VOID_CST:
2476 20779144 : case INTEGER_CST:
2477 20779144 : case REAL_CST:
2478 20779144 : case STRING_CST:
2479 20779144 : case COMPLEX_CST:
2480 20779144 : pp->constant (t);
2481 20779144 : 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 420 : case COMPOUND_EXPR:
2501 420 : pp_cxx_left_paren (pp);
2502 420 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2503 420 : pp_separate_with_comma (pp);
2504 420 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2505 420 : pp_cxx_right_paren (pp);
2506 420 : 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 5637 : case AGGR_INIT_EXPR:
2531 5637 : case CALL_EXPR:
2532 5637 : {
2533 5637 : tree fn = cp_get_callee (t);
2534 5637 : bool skipfirst = false;
2535 :
2536 : /* Deal with internal functions. */
2537 5637 : 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 5634 : if (TREE_CODE (fn) == ADDR_EXPR)
2545 4842 : fn = TREE_OPERAND (fn, 0);
2546 :
2547 : /* Nobody is interested in seeing the guts of vcalls. */
2548 5634 : if (TREE_CODE (fn) == OBJ_TYPE_REF)
2549 137 : fn = resolve_virtual_fun_from_obj_type_ref (fn);
2550 :
2551 5634 : if (TREE_TYPE (fn) != NULL_TREE
2552 5422 : && NEXT_CODE (fn) == METHOD_TYPE
2553 7695 : && call_expr_nargs (t))
2554 : {
2555 2058 : tree ob = get_nth_callarg (t, 0);
2556 2058 : if (is_dummy_object (ob))
2557 : /* Don't print dummy object. */;
2558 1598 : else if (TREE_CODE (ob) == ADDR_EXPR)
2559 : {
2560 1030 : dump_expr (pp, TREE_OPERAND (ob, 0),
2561 : flags | TFF_EXPR_IN_PARENS);
2562 1030 : 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 5634 : if (flag_sanitize & SANITIZE_UNDEFINED
2572 5634 : && is_ubsan_builtin_p (fn))
2573 : {
2574 0 : pp_string (cxx_pp, M_("<ubsan routine call>"));
2575 0 : break;
2576 : }
2577 :
2578 5634 : if (TREE_CODE (fn) == FUNCTION_DECL
2579 5012 : && DECL_CONSTRUCTOR_P (fn)
2580 6292 : && is_dummy_object (get_nth_callarg (t, 0)))
2581 460 : dump_type (pp, DECL_CONTEXT (fn), flags);
2582 : else
2583 5174 : dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS);
2584 5634 : dump_call_expr_args (pp, t, flags, skipfirst);
2585 : }
2586 5634 : break;
2587 :
2588 1408 : 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 1408 : if (TARGET_EXPR_INITIAL (t))
2595 1408 : 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 1617 : case PLUS_EXPR:
2612 1617 : case MINUS_EXPR:
2613 1617 : case MULT_EXPR:
2614 1617 : case TRUNC_DIV_EXPR:
2615 1617 : case TRUNC_MOD_EXPR:
2616 1617 : case MIN_EXPR:
2617 1617 : case MAX_EXPR:
2618 1617 : case LSHIFT_EXPR:
2619 1617 : case RSHIFT_EXPR:
2620 1617 : case BIT_IOR_EXPR:
2621 1617 : case BIT_XOR_EXPR:
2622 1617 : case BIT_AND_EXPR:
2623 1617 : case TRUTH_ANDIF_EXPR:
2624 1617 : case TRUTH_ORIF_EXPR:
2625 1617 : case LT_EXPR:
2626 1617 : case LE_EXPR:
2627 1617 : case GT_EXPR:
2628 1617 : case GE_EXPR:
2629 1617 : case EQ_EXPR:
2630 1617 : case NE_EXPR:
2631 1617 : case SPACESHIP_EXPR:
2632 1617 : case EXACT_DIV_EXPR:
2633 1617 : dump_binary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags);
2634 1617 : break;
2635 :
2636 7 : case CEIL_DIV_EXPR:
2637 7 : case FLOOR_DIV_EXPR:
2638 7 : case ROUND_DIV_EXPR:
2639 7 : case RDIV_EXPR:
2640 7 : dump_binary_op (pp, "/", t, flags);
2641 7 : 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 1787 : case COMPONENT_REF:
2650 1787 : {
2651 1787 : tree ob = TREE_OPERAND (t, 0);
2652 1787 : 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 991 : dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
2668 991 : if (TREE_CODE (ob) != ARROW_EXPR)
2669 988 : pp_cxx_dot (pp);
2670 : }
2671 1787 : dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
2672 : }
2673 1787 : break;
2674 :
2675 269 : case ARRAY_REF:
2676 269 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2677 269 : pp_cxx_left_bracket (pp);
2678 269 : dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2679 269 : pp_cxx_right_bracket (pp);
2680 269 : 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 2423 : case ADDR_EXPR:
2696 2423 : if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
2697 1679 : || 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 4032 : || (TREE_TYPE (t)
2702 1609 : && TYPE_REF_P (TREE_TYPE (t))))
2703 839 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2704 1584 : else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL)
2705 3 : dump_unary_op (pp, "&&", t, flags);
2706 : else
2707 1581 : dump_unary_op (pp, "&", t, flags);
2708 : break;
2709 :
2710 694 : case INDIRECT_REF:
2711 694 : 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 694 : 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 676 : if (TREE_OPERAND (t,0) != NULL_TREE
2730 676 : && TREE_TYPE (TREE_OPERAND (t, 0))
2731 1344 : && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
2732 410 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
2733 : else
2734 266 : dump_unary_op (pp, "*", t, flags);
2735 : }
2736 : break;
2737 :
2738 570 : case MEM_REF:
2739 : /* Delegate to the base "C" pretty printer. */
2740 570 : pp->c_pretty_printer::unary_expression (t);
2741 570 : 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 1585 : 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 1585 : 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 1585 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2841 1585 : break;
2842 :
2843 9873 : CASE_CONVERT:
2844 9873 : case IMPLICIT_CONV_EXPR:
2845 9873 : case VIEW_CONVERT_EXPR:
2846 9873 : case EXCESS_PRECISION_EXPR:
2847 9873 : {
2848 9873 : tree op = TREE_OPERAND (t, 0);
2849 :
2850 9873 : if (location_wrapper_p (t))
2851 : {
2852 : dump_expr (pp, op, flags);
2853 : break;
2854 : }
2855 :
2856 5774 : tree ttype = TREE_TYPE (t);
2857 5774 : tree optype = TREE_TYPE (op);
2858 5774 : if (!optype)
2859 150 : optype = unknown_type_node;
2860 :
2861 5774 : if (TREE_CODE (ttype) != TREE_CODE (optype)
2862 3451 : && INDIRECT_TYPE_P (ttype)
2863 3155 : && INDIRECT_TYPE_P (optype)
2864 8851 : && same_type_p (TREE_TYPE (optype),
2865 : TREE_TYPE (ttype)))
2866 : {
2867 3029 : if (TYPE_REF_P (ttype))
2868 : {
2869 2245 : STRIP_NOPS (op);
2870 2245 : if (TREE_CODE (op) == ADDR_EXPR)
2871 1520 : dump_expr (pp, TREE_OPERAND (op, 0), flags);
2872 : else
2873 725 : dump_unary_op (pp, "*", t, flags);
2874 : }
2875 : else
2876 784 : dump_unary_op (pp, "&", t, flags);
2877 : }
2878 2745 : 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 2450 : if (flags & TFF_EXPR_IN_PARENS)
2883 1820 : pp_cxx_left_paren (pp);
2884 2450 : pp_cxx_left_paren (pp);
2885 2450 : dump_type (pp, TREE_TYPE (t), flags);
2886 2450 : pp_cxx_right_paren (pp);
2887 2450 : dump_expr (pp, op, flags | TFF_EXPR_IN_PARENS);
2888 2450 : if (flags & TFF_EXPR_IN_PARENS)
2889 1820 : pp_cxx_right_paren (pp);
2890 : }
2891 : else
2892 : dump_expr (pp, op, flags);
2893 : break;
2894 : }
2895 :
2896 25664 : case CONSTRUCTOR:
2897 25664 : 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 49395 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
2941 423 : pp_string (pp, "<lambda closure object>");
2942 25652 : if (TREE_TYPE (t) && EMPTY_CONSTRUCTOR_P (t))
2943 : {
2944 5745 : dump_type (pp, TREE_TYPE (t), 0);
2945 5745 : pp_cxx_left_paren (pp);
2946 5745 : pp_cxx_right_paren (pp);
2947 : }
2948 : else
2949 : {
2950 19907 : if (!BRACE_ENCLOSED_INITIALIZER_P (t))
2951 19848 : dump_type (pp, TREE_TYPE (t), 0);
2952 19907 : pp_cxx_left_brace (pp);
2953 19907 : dump_expr_init_vec (pp, CONSTRUCTOR_ELTS (t), flags);
2954 19907 : 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 20917165 : 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 1463 : case TEMPLATE_PARM_INDEX:
2994 1463 : dump_decl (pp, TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS);
2995 1463 : 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 2540 : case EXPR_PACK_EXPANSION:
3197 2540 : case UNARY_LEFT_FOLD_EXPR:
3198 2540 : case UNARY_RIGHT_FOLD_EXPR:
3199 2540 : case BINARY_LEFT_FOLD_EXPR:
3200 2540 : case BINARY_RIGHT_FOLD_EXPR:
3201 2540 : case TYPEID_EXPR:
3202 2540 : case MEMBER_REF:
3203 2540 : case DOTSTAR_EXPR:
3204 2540 : case NEW_EXPR:
3205 2540 : case VEC_NEW_EXPR:
3206 2540 : case DELETE_EXPR:
3207 2540 : case VEC_DELETE_EXPR:
3208 2540 : case MODOP_EXPR:
3209 2540 : case ABS_EXPR:
3210 2540 : case ABSU_EXPR:
3211 2540 : case CONJ_EXPR:
3212 2540 : case VECTOR_CST:
3213 2540 : case FIXED_CST:
3214 2540 : case UNORDERED_EXPR:
3215 2540 : case ORDERED_EXPR:
3216 2540 : case UNLT_EXPR:
3217 2540 : case UNLE_EXPR:
3218 2540 : case UNGT_EXPR:
3219 2540 : case UNGE_EXPR:
3220 2540 : case UNEQ_EXPR:
3221 2540 : case LTGT_EXPR:
3222 2540 : case COMPLEX_EXPR:
3223 2540 : case BIT_FIELD_REF:
3224 2540 : case FIX_TRUNC_EXPR:
3225 2540 : case FLOAT_EXPR:
3226 2540 : pp->expression (t);
3227 2540 : 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 84 : case LAMBDA_EXPR:
3251 84 : pp_string (pp, M_("<lambda>"));
3252 84 : 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 100 : case REFLECT_EXPR:
3333 100 : {
3334 100 : pp_string (pp, "^^");
3335 100 : tree h = REFLECT_EXPR_HANDLE (t);
3336 100 : if (DECL_P (h))
3337 74 : dump_decl (pp, h, flags);
3338 26 : else if (TYPE_P (h))
3339 21 : dump_type (pp, h, flags);
3340 5 : else if (TREE_CODE (h) == TREE_VEC)
3341 : {
3342 1 : pp_format_decoder (pp) = cp_printer;
3343 1 : pp->set_format_postprocessor
3344 1 : (std::make_unique<cxx_format_postprocessor> ());
3345 1 : dump_data_member_spec (pp, h);
3346 : }
3347 : else
3348 : dump_expr (pp, h, flags);
3349 : break;
3350 : }
3351 :
3352 12 : case SPLICE_EXPR:
3353 12 : pp_cxx_ws_string (pp, "[:");
3354 12 : pp_cxx_whitespace (pp);
3355 12 : dump_expr (pp, TREE_OPERAND (t, 0), flags);
3356 12 : pp_cxx_whitespace (pp);
3357 12 : pp_cxx_ws_string (pp, ":]");
3358 12 : break;
3359 :
3360 : /* This list is incomplete, but should suffice for now.
3361 : It is very important that `sorry' does not call
3362 : `report_error_function'. That could cause an infinite loop. */
3363 12 : default:
3364 12 : pp_unsupported_tree (pp, t);
3365 : /* Fall through. */
3366 48 : case ERROR_MARK:
3367 48 : pp_string (pp, M_("<expression error>"));
3368 48 : break;
3369 : }
3370 : }
3371 :
3372 : static void
3373 1952 : dump_binary_op (cxx_pretty_printer *pp, const char *opstring, tree t,
3374 : int flags)
3375 : {
3376 1952 : pp_cxx_left_paren (pp);
3377 1952 : dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
3378 1952 : pp_cxx_whitespace (pp);
3379 1952 : if (opstring)
3380 1950 : pp_cxx_ws_string (pp, opstring);
3381 : else
3382 2 : pp_string (pp, M_("<unknown operator>"));
3383 1952 : pp_cxx_whitespace (pp);
3384 1952 : tree op1 = TREE_OPERAND (t, 1);
3385 1952 : if (TREE_CODE (t) == POINTER_PLUS_EXPR
3386 302 : && TREE_CODE (op1) == INTEGER_CST
3387 2128 : && tree_int_cst_sign_bit (op1))
3388 : /* A pointer minus an integer is represented internally as plus a very
3389 : large number, don't expose that to users. */
3390 25 : op1 = convert (ssizetype, op1);
3391 1952 : dump_expr (pp, op1, flags | TFF_EXPR_IN_PARENS);
3392 1952 : pp_cxx_right_paren (pp);
3393 1952 : }
3394 :
3395 : static void
3396 3580 : dump_unary_op (cxx_pretty_printer *pp, const char *opstring, tree t, int flags)
3397 : {
3398 3580 : if (flags & TFF_EXPR_IN_PARENS)
3399 2197 : pp_cxx_left_paren (pp);
3400 3580 : pp_cxx_ws_string (pp, opstring);
3401 3580 : dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
3402 3580 : if (flags & TFF_EXPR_IN_PARENS)
3403 2197 : pp_cxx_right_paren (pp);
3404 3580 : }
3405 :
3406 : static void
3407 235545945 : reinit_cxx_pp (void)
3408 : {
3409 235545945 : pp_clear_output_area (cxx_pp);
3410 235545945 : cxx_pp->set_padding (pp_none);
3411 235545945 : pp_indentation (cxx_pp) = 0;
3412 235545945 : pp_needs_newline (cxx_pp) = false;
3413 235545945 : pp_show_color (cxx_pp) = false;
3414 235545945 : cxx_pp->enclosing_scope = current_function_decl;
3415 235545945 : }
3416 :
3417 : /* Same as pp_formatted_text, except the return string is a separate
3418 : copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3419 :
3420 : inline const char *
3421 235546355 : pp_ggc_formatted_text (pretty_printer *pp)
3422 : {
3423 235546355 : return ggc_strdup (pp_formatted_text (pp));
3424 : }
3425 :
3426 : /* Exported interface to stringifying types, exprs and decls under TFF_*
3427 : control. */
3428 :
3429 : const char *
3430 213 : type_as_string (tree typ, int flags)
3431 : {
3432 213 : reinit_cxx_pp ();
3433 213 : pp_translate_identifiers (cxx_pp) = false;
3434 213 : dump_type (cxx_pp, typ, flags);
3435 213 : return pp_ggc_formatted_text (cxx_pp);
3436 : }
3437 :
3438 : const char *
3439 0 : type_as_string_translate (tree typ, int flags)
3440 : {
3441 0 : reinit_cxx_pp ();
3442 0 : dump_type (cxx_pp, typ, flags);
3443 0 : return pp_ggc_formatted_text (cxx_pp);
3444 : }
3445 :
3446 : const char *
3447 3972 : expr_as_string (tree decl, int flags)
3448 : {
3449 3972 : reinit_cxx_pp ();
3450 3972 : pp_translate_identifiers (cxx_pp) = false;
3451 3972 : dump_expr (cxx_pp, decl, flags);
3452 3972 : return pp_ggc_formatted_text (cxx_pp);
3453 : }
3454 :
3455 : /* Wrap decl_as_string with options appropriate for dwarf. */
3456 :
3457 : const char *
3458 48273013 : decl_as_dwarf_string (tree decl, int flags)
3459 : {
3460 48273013 : const char *name;
3461 : /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3462 : here will be adequate to get the desired behavior. */
3463 48273013 : cxx_pp->flags |= pp_c_flag_gnu_v3;
3464 48273013 : name = decl_as_string (decl, flags);
3465 : /* Subsequent calls to the pretty printer shouldn't use this style. */
3466 48273013 : cxx_pp->flags &= ~pp_c_flag_gnu_v3;
3467 48273013 : return name;
3468 : }
3469 :
3470 : const char *
3471 48338738 : decl_as_string (tree decl, int flags)
3472 : {
3473 48338738 : reinit_cxx_pp ();
3474 48338738 : pp_translate_identifiers (cxx_pp) = false;
3475 48338738 : dump_decl (cxx_pp, decl, flags);
3476 48338738 : return pp_ggc_formatted_text (cxx_pp);
3477 : }
3478 :
3479 : const char *
3480 0 : decl_as_string_translate (tree decl, int flags)
3481 : {
3482 0 : reinit_cxx_pp ();
3483 0 : dump_decl (cxx_pp, decl, flags);
3484 0 : return pp_ggc_formatted_text (cxx_pp);
3485 : }
3486 :
3487 : /* Wrap lang_decl_name with options appropriate for dwarf. */
3488 :
3489 : const char *
3490 186902668 : lang_decl_dwarf_name (tree decl, int v, bool translate)
3491 : {
3492 186902668 : const char *name;
3493 : /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3494 : here will be adequate to get the desired behavior. */
3495 186902668 : cxx_pp->flags |= pp_c_flag_gnu_v3;
3496 186902668 : name = lang_decl_name (decl, v, translate);
3497 : /* Subsequent calls to the pretty printer shouldn't use this style. */
3498 186902668 : cxx_pp->flags &= ~pp_c_flag_gnu_v3;
3499 186902668 : return name;
3500 : }
3501 :
3502 : /* Generate the three forms of printable names for cxx_printable_name. */
3503 :
3504 : const char *
3505 187048593 : lang_decl_name (tree decl, int v, bool translate)
3506 : {
3507 187048593 : if (v >= 2)
3508 65468 : return (translate
3509 65468 : ? decl_as_string_translate (decl, TFF_DECL_SPECIFIERS)
3510 65468 : : decl_as_string (decl, TFF_DECL_SPECIFIERS));
3511 :
3512 186983125 : reinit_cxx_pp ();
3513 186983125 : pp_translate_identifiers (cxx_pp) = translate;
3514 186983125 : if (v == 1
3515 186983125 : && (DECL_CLASS_SCOPE_P (decl)
3516 84940 : || (DECL_NAMESPACE_SCOPE_P (decl)
3517 83661 : && CP_DECL_CONTEXT (decl) != global_namespace)))
3518 : {
3519 152456 : dump_type (cxx_pp, CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER);
3520 152456 : pp_cxx_colon_colon (cxx_pp);
3521 : }
3522 :
3523 186983125 : if (TREE_CODE (decl) == FUNCTION_DECL)
3524 91768846 : dump_function_name (cxx_pp, decl, TFF_PLAIN_IDENTIFIER);
3525 95214279 : else if ((DECL_NAME (decl) == NULL_TREE)
3526 95214279 : && TREE_CODE (decl) == NAMESPACE_DECL)
3527 21 : dump_decl (cxx_pp, decl, TFF_PLAIN_IDENTIFIER | TFF_UNQUALIFIED_NAME);
3528 : else
3529 95214258 : dump_decl (cxx_pp, DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
3530 :
3531 186983125 : return pp_ggc_formatted_text (cxx_pp);
3532 : }
3533 :
3534 : /* Return the location of a tree passed to %+ formats. */
3535 :
3536 : location_t
3537 1997965 : location_of (tree t)
3538 : {
3539 1997965 : if (TYPE_P (t))
3540 : {
3541 3889 : t = TYPE_MAIN_DECL (t);
3542 3889 : if (t == NULL_TREE)
3543 696 : return input_location;
3544 : }
3545 1994076 : else if (TREE_CODE (t) == OVERLOAD)
3546 37 : t = (OVL_FIRST (t) != conv_op_marker ? OVL_FIRST (t)
3547 0 : : OVL_FIRST (OVL_CHAIN (t)));
3548 :
3549 1997269 : if (DECL_P (t))
3550 1503267 : return DECL_SOURCE_LOCATION (t);
3551 494002 : if (TREE_CODE (t) == DEFERRED_PARSE)
3552 22 : return defparse_location (t);
3553 493980 : return cp_expr_loc_or_input_loc (t);
3554 : }
3555 :
3556 : /* Now the interfaces from error et al to dump_type et al. Each takes an
3557 : on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3558 : function. */
3559 :
3560 : static const char *
3561 99447 : decl_to_string (tree decl, int verbose, bool show_color)
3562 : {
3563 99447 : int flags = 0;
3564 :
3565 99447 : if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
3566 : || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
3567 3765 : flags = TFF_CLASS_KEY_OR_ENUM;
3568 99447 : if (verbose)
3569 30375 : flags |= TFF_DECL_SPECIFIERS;
3570 69072 : else if (TREE_CODE (decl) == FUNCTION_DECL)
3571 44211 : flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
3572 99447 : flags |= TFF_TEMPLATE_HEADER;
3573 :
3574 99447 : reinit_cxx_pp ();
3575 99447 : pp_show_color (cxx_pp) = show_color;
3576 99447 : dump_decl (cxx_pp, decl, flags);
3577 99447 : return pp_ggc_formatted_text (cxx_pp);
3578 : }
3579 :
3580 : const char *
3581 50047 : expr_to_string (tree decl)
3582 : {
3583 50047 : reinit_cxx_pp ();
3584 50047 : dump_expr (cxx_pp, decl, 0);
3585 50047 : return pp_ggc_formatted_text (cxx_pp);
3586 : }
3587 :
3588 : static const char *
3589 350 : fndecl_to_string (tree fndecl, int verbose)
3590 : {
3591 350 : int flags;
3592 :
3593 350 : flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS
3594 : | TFF_TEMPLATE_HEADER;
3595 350 : if (verbose)
3596 91 : flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS;
3597 350 : reinit_cxx_pp ();
3598 350 : dump_decl (cxx_pp, fndecl, flags);
3599 350 : return pp_ggc_formatted_text (cxx_pp);
3600 : }
3601 :
3602 :
3603 : static const char *
3604 0 : code_to_string (enum tree_code c)
3605 : {
3606 0 : return get_tree_code_name (c);
3607 : }
3608 :
3609 : const char *
3610 14402 : language_to_string (enum languages c)
3611 : {
3612 14402 : switch (c)
3613 : {
3614 : case lang_c:
3615 : return "C";
3616 :
3617 12 : case lang_cplusplus:
3618 12 : return "C++";
3619 :
3620 0 : default:
3621 0 : gcc_unreachable ();
3622 : }
3623 : return NULL;
3624 : }
3625 :
3626 : /* Return the proper printed version of a parameter to a C++ function. */
3627 :
3628 : static const char *
3629 1538 : parm_to_string (int p)
3630 : {
3631 1538 : reinit_cxx_pp ();
3632 1538 : if (p < 0)
3633 28 : pp_string (cxx_pp, "'this'");
3634 : else
3635 1510 : pp_decimal_int (cxx_pp, p + 1);
3636 1538 : return pp_ggc_formatted_text (cxx_pp);
3637 : }
3638 :
3639 : static const char *
3640 321 : op_to_string (bool assop, enum tree_code p)
3641 : {
3642 321 : tree id = ovl_op_identifier (assop, p);
3643 639 : return id ? IDENTIFIER_POINTER (id) : M_("<unknown>");
3644 : }
3645 :
3646 : /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3647 :
3648 : If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3649 : string in appropriate places, and *QUOTE is written to with false
3650 : to suppress pp_format's trailing close quote so that e.g.
3651 : foo_typedef {aka underlying_foo} {enum}
3652 : can be printed by "%qT" as:
3653 : `foo_typedef' {aka `underlying_foo'} {enum}
3654 : rather than:
3655 : `foo_typedef {aka underlying_foo} {enum}'
3656 : When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3657 : then a leading open quote will be added, whereas if POSTPROCESSED is false
3658 : (for handling %T) then any leading quote has already been added by
3659 : pp_format, or is not needed due to QUOTE being NULL (for template arguments
3660 : within %H and %I).
3661 :
3662 : SHOW_COLOR and HIGHLIGHT_COLOR are used to determine the colorization of
3663 : any quotes that are added. */
3664 :
3665 : static const char *
3666 63261 : type_to_string (tree typ, int verbose, bool postprocessed, bool *quote,
3667 : bool show_color, const char *highlight_color)
3668 : {
3669 63261 : int flags = 0;
3670 63261 : if (verbose)
3671 9509 : flags |= TFF_CLASS_KEY_OR_ENUM;
3672 63261 : flags |= TFF_TEMPLATE_HEADER;
3673 :
3674 63261 : reinit_cxx_pp ();
3675 63261 : pp_show_color (cxx_pp) = show_color;
3676 :
3677 63261 : if (postprocessed && quote && *quote)
3678 : {
3679 20654 : pp_begin_quote (cxx_pp, show_color);
3680 20654 : if (show_color && highlight_color)
3681 0 : pp_string (cxx_pp, colorize_start (show_color, highlight_color));
3682 : }
3683 :
3684 63261 : struct obstack *ob = pp_buffer (cxx_pp)->m_obstack;
3685 63261 : int type_start, type_len;
3686 63261 : type_start = obstack_object_size (ob);
3687 :
3688 63261 : dump_type (cxx_pp, typ, flags);
3689 :
3690 : /* Remember the end of the initial dump. */
3691 63261 : type_len = obstack_object_size (ob) - type_start;
3692 :
3693 : /* If we're printing a type that involves typedefs, also print the
3694 : stripped version. But sometimes the stripped version looks
3695 : exactly the same, so we don't want it after all. To avoid printing
3696 : it in that case, we play ugly obstack games. */
3697 63247 : if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
3698 69350 : && !uses_template_parms (typ))
3699 : {
3700 4359 : int aka_start, aka_len; char *p;
3701 4359 : tree aka = strip_typedefs (typ, NULL, STF_USER_VISIBLE);
3702 4359 : if (quote && *quote)
3703 3906 : pp_end_quote (cxx_pp, show_color);
3704 4359 : pp_string (cxx_pp, " {aka");
3705 4359 : pp_cxx_whitespace (cxx_pp);
3706 4359 : if (quote && *quote)
3707 3906 : pp_begin_quote (cxx_pp, show_color);
3708 4359 : if (highlight_color)
3709 1197 : pp_string (cxx_pp, colorize_start (show_color, highlight_color));
3710 : /* And remember the start of the aka dump. */
3711 4359 : aka_start = obstack_object_size (ob);
3712 4359 : dump_type (cxx_pp, aka, flags);
3713 4359 : aka_len = obstack_object_size (ob) - aka_start;
3714 4359 : if (quote && *quote)
3715 3906 : pp_end_quote (cxx_pp, show_color);
3716 4359 : pp_right_brace (cxx_pp);
3717 4359 : p = (char*)obstack_base (ob);
3718 : /* If they are identical, cut off the aka by unwinding the obstack. */
3719 4359 : if (type_len == aka_len
3720 939 : && memcmp (p + type_start, p+aka_start, type_len) == 0)
3721 : {
3722 : /* We can't add a '\0' here, since we may be adding a closing quote
3723 : below, and it would be hidden by the '\0'.
3724 : Instead, manually unwind the current object within the obstack
3725 : so that the insertion point is at the end of the type, before
3726 : the "' {aka". */
3727 761 : int delta = type_start + type_len - obstack_object_size (ob);
3728 761 : gcc_assert (delta <= 0);
3729 761 : obstack_blank_fast (ob, delta);
3730 761 : }
3731 : else
3732 3598 : if (quote)
3733 : /* No further closing quotes are needed. */
3734 3571 : *quote = false;
3735 : }
3736 :
3737 63234 : if (quote && *quote)
3738 : {
3739 56026 : if (show_color && highlight_color)
3740 0 : pp_string (cxx_pp, colorize_stop (show_color));
3741 56026 : pp_end_quote (cxx_pp, show_color);
3742 56026 : *quote = false;
3743 : }
3744 63261 : return pp_ggc_formatted_text (cxx_pp);
3745 : }
3746 :
3747 : static const char *
3748 3909 : args_to_string (tree p, int verbose)
3749 : {
3750 3909 : int flags = 0;
3751 3909 : if (verbose)
3752 0 : flags |= TFF_CLASS_KEY_OR_ENUM;
3753 :
3754 3909 : if (p == NULL_TREE)
3755 : return "";
3756 :
3757 3051 : if (TYPE_P (TREE_VALUE (p)))
3758 0 : return type_as_string_translate (p, flags);
3759 :
3760 3051 : reinit_cxx_pp ();
3761 9825 : for (; p; p = TREE_CHAIN (p))
3762 : {
3763 3723 : if (null_node_p (TREE_VALUE (p)))
3764 3 : pp_cxx_ws_string (cxx_pp, "NULL");
3765 : else
3766 3720 : dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags);
3767 3723 : if (TREE_CHAIN (p))
3768 672 : pp_separate_with_comma (cxx_pp);
3769 : }
3770 3051 : return pp_ggc_formatted_text (cxx_pp);
3771 : }
3772 :
3773 : /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3774 : is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3775 : arguments. */
3776 :
3777 : static const char *
3778 1561 : subst_to_string (tree p, bool show_color)
3779 : {
3780 1561 : tree decl = TREE_PURPOSE (p);
3781 1561 : tree targs = TREE_VALUE (p);
3782 1561 : tree tparms = DECL_TEMPLATE_PARMS (decl);
3783 1561 : int flags = (TFF_DECL_SPECIFIERS|TFF_TEMPLATE_HEADER
3784 : |TFF_NO_TEMPLATE_BINDINGS);
3785 :
3786 1561 : if (p == NULL_TREE)
3787 : return "";
3788 :
3789 1561 : reinit_cxx_pp ();
3790 1561 : pp_show_color (cxx_pp) = show_color;
3791 1561 : dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags);
3792 1561 : dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0);
3793 1561 : return pp_ggc_formatted_text (cxx_pp);
3794 : }
3795 :
3796 : static const char *
3797 639 : cv_to_string (tree p, int v)
3798 : {
3799 639 : reinit_cxx_pp ();
3800 639 : cxx_pp->set_padding (v ? pp_before : pp_none);
3801 639 : pp_cxx_cv_qualifier_seq (cxx_pp, p);
3802 639 : return pp_ggc_formatted_text (cxx_pp);
3803 : }
3804 :
3805 : static const char *
3806 3 : eh_spec_to_string (tree p, int /*v*/)
3807 : {
3808 3 : int flags = 0;
3809 3 : reinit_cxx_pp ();
3810 3 : dump_exception_spec (cxx_pp, p, flags);
3811 3 : return pp_ggc_formatted_text (cxx_pp);
3812 : }
3813 :
3814 : /* Langhook for print_error_function. */
3815 : void
3816 119 : cxx_print_error_function (diagnostics::text_sink &text_output,
3817 : const char *file,
3818 : const diagnostics::diagnostic_info *diagnostic)
3819 : {
3820 119 : char *prefix;
3821 119 : if (file)
3822 119 : prefix = xstrdup (file);
3823 : else
3824 : prefix = NULL;
3825 119 : lhd_print_error_function (text_output, file, diagnostic);
3826 :
3827 119 : pp_set_prefix (text_output.get_printer (), prefix);
3828 119 : maybe_print_instantiation_context (text_output);
3829 119 : }
3830 :
3831 : static void
3832 225876 : cp_diagnostic_text_starter (diagnostics::text_sink &text_output,
3833 : const diagnostics::diagnostic_info *diagnostic)
3834 : {
3835 225876 : pp_set_prefix (text_output.get_printer (),
3836 : text_output.build_indent_prefix (true));
3837 225876 : text_output.report_current_module (diagnostic_location (diagnostic));
3838 225876 : cp_print_error_function (text_output, diagnostic);
3839 225876 : maybe_print_instantiation_context (text_output);
3840 225876 : maybe_print_constexpr_context (text_output);
3841 225876 : maybe_print_constraint_context (text_output);
3842 225876 : pp_set_prefix (text_output.get_printer (),
3843 : text_output.build_prefix (*diagnostic));
3844 225876 : }
3845 :
3846 : /* Print current function onto BUFFER, in the process of reporting
3847 : a diagnostic message. Called from cp_diagnostic_starter. */
3848 : static void
3849 225876 : cp_print_error_function (diagnostics::text_sink &text_output,
3850 : const diagnostics::diagnostic_info *diagnostic)
3851 : {
3852 : /* If we are in an instantiation context, current_function_decl is likely
3853 : to be wrong, so just rely on print_instantiation_full_context. */
3854 225876 : if (current_instantiation ())
3855 : return;
3856 : /* The above is true for constraint satisfaction also. */
3857 211350 : if (current_failed_constraint)
3858 : return;
3859 211082 : diagnostics::context *const context = &text_output.get_context ();
3860 211082 : if (diagnostic_last_function_changed (context, diagnostic))
3861 : {
3862 25468 : pretty_printer *const pp = text_output.get_printer ();
3863 25468 : char *old_prefix = pp_take_prefix (pp);
3864 25468 : const char *file = LOCATION_FILE (diagnostic_location (diagnostic));
3865 25468 : tree abstract_origin = diagnostic_abstract_origin (diagnostic);
3866 25468 : char *new_prefix = (file && abstract_origin == NULL)
3867 25468 : ? text_output.file_name_as_prefix (file) : NULL;
3868 :
3869 25468 : pp_set_prefix (pp, new_prefix);
3870 :
3871 25468 : if (current_function_decl == NULL)
3872 929 : pp_string (pp, _("At global scope:"));
3873 : else
3874 : {
3875 24539 : tree fndecl, ao;
3876 :
3877 24539 : if (abstract_origin)
3878 : {
3879 388 : ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
3880 388 : gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
3881 : fndecl = ao;
3882 : }
3883 : else
3884 : fndecl = current_function_decl;
3885 :
3886 24539 : pp_printf (pp, function_category (fndecl),
3887 : fndecl);
3888 :
3889 49673 : while (abstract_origin)
3890 : {
3891 595 : location_t *locus;
3892 595 : tree block = abstract_origin;
3893 :
3894 595 : locus = &BLOCK_SOURCE_LOCATION (block);
3895 595 : fndecl = NULL;
3896 595 : block = BLOCK_SUPERCONTEXT (block);
3897 1317 : while (block && TREE_CODE (block) == BLOCK
3898 1435 : && BLOCK_ABSTRACT_ORIGIN (block))
3899 : {
3900 334 : ao = BLOCK_ABSTRACT_ORIGIN (block);
3901 334 : if (TREE_CODE (ao) == FUNCTION_DECL)
3902 : {
3903 : fndecl = ao;
3904 : break;
3905 : }
3906 127 : else if (TREE_CODE (ao) != BLOCK)
3907 : break;
3908 :
3909 127 : block = BLOCK_SUPERCONTEXT (block);
3910 : }
3911 595 : if (fndecl)
3912 : abstract_origin = block;
3913 : else
3914 : {
3915 834 : while (block && TREE_CODE (block) == BLOCK)
3916 446 : block = BLOCK_SUPERCONTEXT (block);
3917 :
3918 388 : if (block && TREE_CODE (block) == FUNCTION_DECL)
3919 : fndecl = block;
3920 : abstract_origin = NULL;
3921 : }
3922 : if (fndecl)
3923 : {
3924 595 : expanded_location s = expand_location (*locus);
3925 595 : pp_character (pp, ',');
3926 595 : pp_newline (pp);
3927 595 : if (s.file != NULL)
3928 : {
3929 595 : if (text_output.show_column_p () && s.column != 0)
3930 541 : pp_printf (pp,
3931 : G_(" inlined from %qD at %r%s:%d:%d%R"),
3932 : fndecl,
3933 : "locus", s.file, s.line, s.column);
3934 : else
3935 54 : pp_printf (pp,
3936 : G_(" inlined from %qD at %r%s:%d%R"),
3937 : fndecl,
3938 : "locus", s.file, s.line);
3939 :
3940 : }
3941 : else
3942 0 : pp_printf (pp, G_(" inlined from %qD"),
3943 : fndecl);
3944 : }
3945 : }
3946 24539 : pp_character (pp, ':');
3947 : }
3948 25468 : pp_newline (pp);
3949 :
3950 25468 : diagnostic_set_last_function (context, diagnostic);
3951 25468 : pp->set_prefix (old_prefix);
3952 : }
3953 : }
3954 :
3955 : /* Returns a description of FUNCTION using standard terminology. The
3956 : result is a format string of the form "In CATEGORY %qD". */
3957 :
3958 : static const char *
3959 24539 : function_category (tree fn)
3960 : {
3961 : /* We can get called from the middle-end for diagnostics of function
3962 : clones. Make sure we have language specific information before
3963 : dereferencing it. */
3964 24539 : if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn))
3965 24539 : && DECL_FUNCTION_MEMBER_P (fn))
3966 : {
3967 3142 : if (DECL_STATIC_FUNCTION_P (fn))
3968 : return G_("In static member function %qD");
3969 3006 : else if (DECL_COPY_CONSTRUCTOR_P (fn))
3970 : return G_("In copy constructor %qD");
3971 5930 : else if (DECL_CONSTRUCTOR_P (fn))
3972 : return G_("In constructor %qD");
3973 1986 : else if (DECL_DESTRUCTOR_P (fn))
3974 : return G_("In destructor %qD");
3975 2425 : else if (LAMBDA_FUNCTION_P (fn))
3976 : return G_("In lambda function");
3977 1306 : else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3978 14 : return G_("In explicit object member function %qD");
3979 : else
3980 : return G_("In member function %qD");
3981 : }
3982 : else
3983 : return G_("In function %qD");
3984 : }
3985 :
3986 : /* We expected some kind of tree but instead got T and emitted a diagnostic.
3987 : Print the category of T (type, expression, ...) if possible. */
3988 :
3989 : void
3990 95 : inform_tree_category (tree t)
3991 : {
3992 95 : const location_t loc = location_of (t);
3993 :
3994 95 : t = maybe_get_first_fn (t);
3995 95 : if (TREE_CODE (t) == TYPE_DECL)
3996 5 : t = TREE_TYPE (t);
3997 :
3998 95 : if (TYPE_P (t))
3999 50 : inform (loc, "but %qE is a type", t);
4000 45 : else if (EXPR_P (t))
4001 0 : inform (loc, "but %qE is an expression", t);
4002 45 : else if (DECL_DECOMPOSITION_P (t) && !DECL_DECOMP_IS_BASE (t))
4003 1 : inform (loc, "but %qE is a structured binding", t);
4004 44 : else if (VAR_P (t))
4005 15 : inform (loc, "but %qE is a variable", t);
4006 29 : else if (TREE_CODE (t) == PARM_DECL)
4007 2 : inform (loc, "but %qE is a parameter", t);
4008 27 : else if (TREE_CODE (t) == FUNCTION_DECL)
4009 7 : inform (loc, "but %qE is a function", t);
4010 20 : else if (TREE_CODE (t) == FIELD_DECL)
4011 1 : inform (loc, "but %qE is a data member", t);
4012 19 : else if (DECL_FUNCTION_TEMPLATE_P (t))
4013 3 : inform (loc, "but %qE is a function template", t);
4014 16 : else if (DECL_CLASS_TEMPLATE_P (t))
4015 4 : inform (loc, "but %qE is a class template", t);
4016 12 : else if (variable_template_p (t))
4017 1 : inform (loc, "but %qE is a variable template", t);
4018 11 : else if (TREE_CODE (t) == NAMESPACE_DECL)
4019 8 : inform (loc, "but %qE is a namespace", t);
4020 3 : else if (TREE_CODE (t) == CONST_DECL && !DECL_TEMPLATE_PARM_P (t))
4021 2 : inform (loc, "but %qE is an enumerator", t);
4022 95 : }
4023 :
4024 : /* Disable warnings about missing quoting in GCC diagnostics for
4025 : the pp_verbatim calls. Their format strings deliberately don't
4026 : follow GCC diagnostic conventions. */
4027 : #if __GNUC__ >= 10
4028 : #pragma GCC diagnostic push
4029 : #pragma GCC diagnostic ignored "-Wformat-diag"
4030 : #endif
4031 :
4032 : /* Report the full context of a current template instantiation,
4033 : onto BUFFER. */
4034 : static void
4035 5354 : print_instantiation_full_context (diagnostics::text_sink &text_output)
4036 : {
4037 5354 : struct tinst_level *p = current_instantiation ();
4038 5354 : location_t location = input_location;
4039 :
4040 5354 : if (p)
4041 : {
4042 5354 : bool show_file
4043 5354 : = ((!text_output.show_nesting_p ())
4044 5354 : || text_output.show_locations_in_nesting_p ());
4045 5354 : char *indent = text_output.build_indent_prefix (true);
4046 5354 : bool expansion_stmt_p = TREE_CODE (p->tldcl) == TEMPLATE_FOR_STMT;
4047 10789 : pp_verbatim (text_output.get_printer (),
4048 : expansion_stmt_p
4049 : ? G_("%s%s%sIn instantiation of %<template for%> "
4050 : "iteration %E:\n")
4051 5354 : : p->list_p ()
4052 : ? G_("%s%s%sIn substitution of %qS:\n")
4053 : : G_("%s%s%sIn instantiation of %q#D:\n"),
4054 : indent,
4055 5345 : show_file ? LOCATION_FILE (location) : "",
4056 : show_file ? ": " : "",
4057 : expansion_stmt_p
4058 81 : ? TREE_VEC_ELT (p->targs, 0)
4059 5354 : : p->get_node ());
4060 5354 : free (indent);
4061 5354 : location = p->locus;
4062 5354 : p = p->next;
4063 : }
4064 :
4065 5354 : print_instantiation_partial_context (text_output, p, location);
4066 5354 : }
4067 :
4068 : static void
4069 12206 : print_location (diagnostics::text_sink &text_output,
4070 : location_t loc)
4071 : {
4072 12206 : expanded_location xloc = expand_location (loc);
4073 12206 : pretty_printer *const pp = text_output.get_printer ();
4074 12206 : if (text_output.show_column_p ())
4075 7316 : pp_verbatim (pp, G_("%r%s:%d:%d:%R "),
4076 : "locus", xloc.file, xloc.line, xloc.column);
4077 : else
4078 4890 : pp_verbatim (pp, G_("%r%s:%d:%R "),
4079 : "locus", xloc.file, xloc.line);
4080 12206 : }
4081 :
4082 : /* A RAII class for use when emitting a line of contextual information
4083 : via pp_verbatim to a diagnostics::text_sink to add before/after
4084 : behaviors to the pp_verbatim calls.
4085 :
4086 : If the text output has show_nesting_p (), then the ctor prints
4087 : leading indentation and a bullet point, and the dtor prints
4088 : the location on a new line, and calls diagnostic_show_locus, both
4089 : with indentation (and no bullet point).
4090 :
4091 : Otherwise (when the text output has !show_nesting_p), the ctor prints
4092 : the location as leading information on the same line, and the
4093 : dtor optionally calls diagnostic_show_locus. */
4094 :
4095 : class auto_context_line
4096 : {
4097 : public:
4098 12242 : auto_context_line (diagnostics::text_sink &text_output,
4099 : location_t loc,
4100 : bool show_locus = false)
4101 12242 : : m_text_output (text_output),
4102 12242 : m_loc (loc),
4103 12242 : m_show_locus (show_locus),
4104 12242 : m_nesting_level (text_output.get_context ().get_diagnostic_nesting_level ()),
4105 12242 : m_location_printed (false)
4106 : {
4107 12242 : char *indent = m_text_output.build_indent_prefix (true);
4108 12242 : pp_verbatim (m_text_output.get_printer (), indent);
4109 12242 : free (indent);
4110 12242 : if (m_nesting_level == 0 || !m_text_output.show_nesting_p ())
4111 : {
4112 12206 : print_location (m_text_output, m_loc);
4113 12206 : m_location_printed = true;
4114 : }
4115 12242 : }
4116 12242 : ~auto_context_line ()
4117 : {
4118 12242 : pretty_printer *const pp = m_text_output.get_printer ();
4119 12242 : if (m_text_output.show_nesting_p ())
4120 : {
4121 47 : if (m_text_output.show_locations_in_nesting_p ())
4122 : {
4123 11 : char *indent = m_text_output.build_indent_prefix (false);
4124 11 : if (!m_location_printed)
4125 : {
4126 0 : pp_verbatim (pp, indent);
4127 0 : print_location (m_text_output, m_loc);
4128 0 : pp_newline (pp);
4129 0 : m_location_printed = true;
4130 : }
4131 :
4132 11 : char *saved_prefix = pp_take_prefix (pp);
4133 11 : pp_set_prefix (pp, indent);
4134 11 : gcc_rich_location rich_loc (m_loc);
4135 11 : diagnostic_show_locus (&m_text_output.get_context (),
4136 11 : m_text_output.get_source_printing_options (),
4137 : &rich_loc,
4138 : diagnostics::kind::note, pp);
4139 11 : pp_set_prefix (pp, saved_prefix);
4140 11 : }
4141 : }
4142 12195 : else if (m_show_locus)
4143 : {
4144 7113 : char *saved_prefix = pp_take_prefix (pp);
4145 7113 : pp_set_prefix (pp, nullptr);
4146 7113 : gcc_rich_location rich_loc (m_loc);
4147 7113 : diagnostic_show_locus (&m_text_output.get_context (),
4148 7113 : m_text_output.get_source_printing_options (),
4149 : &rich_loc,
4150 : diagnostics::kind::note, pp);
4151 7113 : pp_set_prefix (pp, saved_prefix);
4152 7113 : }
4153 12242 : }
4154 : private:
4155 : diagnostics::text_sink &m_text_output;
4156 : location_t m_loc;
4157 : bool m_show_locus;
4158 : int m_nesting_level;
4159 : bool m_location_printed;
4160 : };
4161 :
4162 : /* Helper function of print_instantiation_partial_context() that
4163 : prints a single line of instantiation context. */
4164 :
4165 : static void
4166 7133 : print_instantiation_partial_context_line (diagnostics::text_sink &text_output,
4167 : struct tinst_level *t,
4168 : location_t loc, bool recursive_p)
4169 : {
4170 7133 : if (loc == UNKNOWN_LOCATION)
4171 0 : return;
4172 :
4173 7133 : auto_context_line sentinel (text_output, loc, true);
4174 :
4175 7133 : pretty_printer *const pp = text_output.get_printer ();
4176 :
4177 7133 : if (t != NULL)
4178 : {
4179 1779 : if (TREE_CODE (t->tldcl) == TEMPLATE_FOR_STMT)
4180 0 : pp_verbatim (pp,
4181 : recursive_p
4182 : ? G_("recursively required from %<template for%> "
4183 : "iteration %E\n")
4184 : : G_("required from %<template for%> iteration %E\n"),
4185 0 : TREE_VEC_ELT (t->targs, 0));
4186 1779 : else if (t->list_p ())
4187 768 : pp_verbatim (pp,
4188 : recursive_p
4189 : ? G_("recursively required by substitution of %qS\n")
4190 : : G_("required by substitution of %qS\n"),
4191 : t->get_node ());
4192 : else
4193 2886 : pp_verbatim (pp,
4194 : recursive_p
4195 : ? G_("recursively required from %q#D\n")
4196 : : G_("required from %q#D\n"),
4197 : t->get_node ());
4198 : }
4199 : else
4200 : {
4201 10708 : pp_verbatim (pp,
4202 : recursive_p
4203 : ? G_("recursively required from here\n")
4204 : : G_("required from here\n"));
4205 : }
4206 7133 : }
4207 :
4208 : /* Same as print_instantiation_full_context but less verbose. */
4209 :
4210 : static void
4211 5354 : print_instantiation_partial_context (diagnostics::text_sink &text_output,
4212 : struct tinst_level *t0, location_t loc)
4213 : {
4214 5354 : struct tinst_level *t;
4215 5354 : int n_total = 0;
4216 5354 : int n;
4217 5354 : location_t prev_loc = loc;
4218 :
4219 40055 : for (t = t0; t != NULL; t = t->next)
4220 34701 : if (prev_loc != t->locus)
4221 : {
4222 1713 : prev_loc = t->locus;
4223 1713 : n_total++;
4224 : }
4225 :
4226 5354 : t = t0;
4227 :
4228 5354 : if (template_backtrace_limit
4229 5354 : && n_total > template_backtrace_limit)
4230 : {
4231 0 : int skip = n_total - template_backtrace_limit;
4232 0 : int head = template_backtrace_limit / 2;
4233 :
4234 : /* Avoid skipping just 1. If so, skip 2. */
4235 0 : if (skip == 1)
4236 : {
4237 0 : skip = 2;
4238 0 : head = (template_backtrace_limit - 1) / 2;
4239 : }
4240 :
4241 0 : for (n = 0; n < head; n++)
4242 : {
4243 0 : gcc_assert (t != NULL);
4244 0 : if (loc != t->locus)
4245 0 : print_instantiation_partial_context_line (text_output, t, loc,
4246 : /*recursive_p=*/false);
4247 0 : loc = t->locus;
4248 0 : t = t->next;
4249 : }
4250 0 : if (t != NULL && skip > 0)
4251 : {
4252 0 : auto_context_line sentinel (text_output, loc);
4253 0 : pp_verbatim (text_output.get_printer (),
4254 : G_("[ skipping %d instantiation contexts,"
4255 : " use -ftemplate-backtrace-limit=0 to disable ]\n"),
4256 : skip);
4257 0 : do {
4258 0 : loc = t->locus;
4259 0 : t = t->next;
4260 0 : } while (t != NULL && --skip > 0);
4261 0 : }
4262 : }
4263 :
4264 7133 : while (t != NULL)
4265 : {
4266 34701 : while (t->next != NULL && t->locus == t->next->locus)
4267 : {
4268 : loc = t->locus;
4269 : t = t->next;
4270 : }
4271 1779 : print_instantiation_partial_context_line (text_output, t, loc,
4272 1779 : t->locus == loc);
4273 1779 : loc = t->locus;
4274 1779 : t = t->next;
4275 : }
4276 5354 : print_instantiation_partial_context_line (text_output, NULL, loc,
4277 : /*recursive_p=*/false);
4278 5354 : }
4279 :
4280 : /* Called from cp_thing to print the template context for an error. */
4281 : static void
4282 225995 : maybe_print_instantiation_context (diagnostics::text_sink &text_output)
4283 : {
4284 225995 : if (!problematic_instantiation_changed () || current_instantiation () == 0)
4285 220641 : return;
4286 :
4287 5354 : record_last_problematic_instantiation ();
4288 5354 : print_instantiation_full_context (text_output);
4289 : }
4290 :
4291 : /* Report what constexpr call(s) we're trying to expand, if any. */
4292 :
4293 : void
4294 225876 : maybe_print_constexpr_context (diagnostics::text_sink &text_output)
4295 : {
4296 225876 : vec<tree> call_stack = cx_error_context ();
4297 225876 : unsigned ix;
4298 225876 : tree t;
4299 :
4300 229275 : FOR_EACH_VEC_ELT (call_stack, ix, t)
4301 : {
4302 3399 : const char *s = expr_as_string (t, 0);
4303 3399 : pretty_printer *const pp = text_output.get_printer ();
4304 3399 : auto_context_line sentinel (text_output, EXPR_LOCATION (t));
4305 3399 : pp_verbatim (pp,
4306 : G_("in %<constexpr%> expansion of %qs"),
4307 : s);
4308 3399 : pp_newline (pp);
4309 3399 : }
4310 225876 : }
4311 :
4312 :
4313 : static void
4314 603 : print_constrained_decl_info (diagnostics::text_sink &text_output,
4315 : tree decl)
4316 : {
4317 603 : auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (decl));
4318 603 : pretty_printer *const pp = text_output.get_printer ();
4319 603 : pp_verbatim (pp, G_("required by the constraints of %q#D\n"), decl);
4320 603 : }
4321 :
4322 : static void
4323 789 : print_concept_check_info (diagnostics::text_sink &text_output,
4324 : tree expr, tree map, tree args)
4325 : {
4326 789 : gcc_assert (concept_check_p (expr));
4327 :
4328 789 : tree tmpl = TREE_OPERAND (expr, 0);
4329 :
4330 789 : auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (tmpl));
4331 :
4332 789 : cxx_pretty_printer *const pp
4333 789 : = (cxx_pretty_printer *)text_output.get_printer ();
4334 789 : pp_verbatim (pp, G_("required for the satisfaction of %qE"), expr);
4335 789 : if (map && map != error_mark_node)
4336 : {
4337 771 : tree subst_map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE);
4338 773 : pp_cxx_parameter_mapping (pp, (subst_map != error_mark_node
4339 : ? subst_map : map));
4340 : }
4341 789 : pp_newline (pp);
4342 789 : }
4343 :
4344 : /* Diagnose the entry point into the satisfaction error. Returns the next
4345 : context, if any. */
4346 :
4347 : static tree
4348 1324 : print_constraint_context_head (diagnostics::text_sink &text_output,
4349 : tree cxt, tree args)
4350 : {
4351 1324 : tree src = TREE_VALUE (cxt);
4352 1324 : if (!src)
4353 : {
4354 0 : auto_context_line sentinel (text_output, input_location);
4355 0 : pretty_printer *const pp = text_output.get_printer ();
4356 0 : pp_verbatim (pp, G_("required for constraint satisfaction\n"));
4357 0 : return NULL_TREE;
4358 0 : }
4359 1324 : if (DECL_P (src))
4360 : {
4361 603 : print_constrained_decl_info (text_output, src);
4362 603 : return NULL_TREE;
4363 : }
4364 : else
4365 : {
4366 721 : print_concept_check_info (text_output, src, TREE_PURPOSE (cxt), args);
4367 721 : return TREE_CHAIN (cxt);
4368 : }
4369 : }
4370 :
4371 : static void
4372 320 : print_requires_expression_info (diagnostics::text_sink &text_output,
4373 : tree constr, tree args)
4374 : {
4375 :
4376 320 : tree expr = ATOMIC_CONSTR_EXPR (constr);
4377 320 : tree map = ATOMIC_CONSTR_MAP (constr);
4378 320 : map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE);
4379 320 : if (map == error_mark_node)
4380 2 : return;
4381 :
4382 318 : auto_context_line sentinel (text_output, cp_expr_loc_or_input_loc (expr));
4383 318 : cxx_pretty_printer *const pp
4384 318 : = static_cast <cxx_pretty_printer *> (text_output.get_printer ());
4385 :
4386 318 : tree parms = TREE_OPERAND (expr, 0);
4387 318 : pp_verbatim (pp, parms ? G_("in requirements with ")
4388 : : G_("in requirements "));
4389 923 : while (parms)
4390 : {
4391 287 : pp_verbatim (pp, "%q#D", parms);
4392 287 : if (TREE_CHAIN (parms))
4393 97 : pp_separate_with_comma (pp);
4394 287 : parms = TREE_CHAIN (parms);
4395 : }
4396 318 : pp_cxx_parameter_mapping (pp, map);
4397 :
4398 318 : pp_verbatim (pp, "\n");
4399 318 : }
4400 :
4401 : void
4402 1351 : maybe_print_single_constraint_context (diagnostics::text_sink &text_output,
4403 : tree failed)
4404 : {
4405 1351 : if (!failed)
4406 : return;
4407 :
4408 1351 : tree constr = TREE_VALUE (failed);
4409 1351 : if (!constr || constr == error_mark_node)
4410 : return;
4411 1351 : tree cxt = CONSTR_CONTEXT (constr);
4412 1351 : if (!cxt)
4413 : return;
4414 1324 : tree args = TREE_PURPOSE (failed);
4415 :
4416 : /* Print the stack of requirements. */
4417 1324 : cxt = print_constraint_context_head (text_output, cxt, args);
4418 3374 : while (cxt && !DECL_P (TREE_VALUE (cxt)))
4419 : {
4420 68 : tree expr = TREE_VALUE (cxt);
4421 68 : tree map = TREE_PURPOSE (cxt);
4422 68 : print_concept_check_info (text_output, expr, map, args);
4423 68 : cxt = TREE_CHAIN (cxt);
4424 : }
4425 :
4426 : /* For certain constraints, we can provide additional context. */
4427 1324 : if (TREE_CODE (constr) == ATOMIC_CONSTR
4428 1324 : && TREE_CODE (ATOMIC_CONSTR_EXPR (constr)) == REQUIRES_EXPR)
4429 320 : print_requires_expression_info (text_output, constr, args);
4430 : }
4431 :
4432 : void
4433 225879 : maybe_print_constraint_context (diagnostics::text_sink &text_output)
4434 : {
4435 225879 : if (!current_failed_constraint)
4436 : return;
4437 :
4438 1351 : tree cur = current_failed_constraint;
4439 :
4440 : /* Recursively print nested contexts. */
4441 1351 : current_failed_constraint = TREE_CHAIN (current_failed_constraint);
4442 1351 : if (current_failed_constraint)
4443 3 : maybe_print_constraint_context (text_output);
4444 :
4445 : /* Print this context. */
4446 1351 : maybe_print_single_constraint_context (text_output, cur);
4447 : }
4448 :
4449 : /* Return true iff TYPE_A and TYPE_B are template types that are
4450 : meaningful to compare. */
4451 :
4452 : static bool
4453 11473 : comparable_template_types_p (tree type_a, tree type_b)
4454 : {
4455 11473 : if (!CLASS_TYPE_P (type_a))
4456 : return false;
4457 1331 : if (!CLASS_TYPE_P (type_b))
4458 : return false;
4459 :
4460 412 : tree tinfo_a = TYPE_TEMPLATE_INFO (type_a);
4461 412 : tree tinfo_b = TYPE_TEMPLATE_INFO (type_b);
4462 412 : if (!tinfo_a || !tinfo_b)
4463 : return false;
4464 :
4465 251 : return TI_TEMPLATE (tinfo_a) == TI_TEMPLATE (tinfo_b);
4466 : }
4467 :
4468 : /* Start a new line indented by SPC spaces on PP. */
4469 :
4470 : static void
4471 228 : newline_and_indent (pretty_printer *pp, int spc)
4472 : {
4473 228 : pp_newline (pp);
4474 1020 : for (int i = 0; i < spc; i++)
4475 792 : pp_space (pp);
4476 228 : }
4477 :
4478 : /* Generate a GC-allocated string for ARG, an expression or type. */
4479 :
4480 : static const char *
4481 628 : arg_to_string (tree arg, bool verbose)
4482 : {
4483 628 : if (TYPE_P (arg))
4484 366 : return type_to_string (arg, verbose, true, NULL, false);
4485 : else
4486 262 : return expr_to_string (arg);
4487 : }
4488 :
4489 : /* Subroutine to type_to_string_with_compare and
4490 : print_template_tree_comparison.
4491 :
4492 : Print a representation of ARG (an expression or type) to PP,
4493 : colorizing it if PP->show_color, using HIGHLIGHT_COLOR,
4494 : or "type-diff" if the latter is NULL. */
4495 :
4496 : static void
4497 616 : print_nonequal_arg (pretty_printer *pp, tree arg, bool verbose,
4498 : const char *highlight_color)
4499 : {
4500 616 : if (!highlight_color)
4501 10 : highlight_color = "type-diff";
4502 1232 : pp_printf (pp, "%r%s%R",
4503 : highlight_color,
4504 : (arg
4505 616 : ? arg_to_string (arg, verbose)
4506 : : G_("(no argument)")));
4507 616 : }
4508 :
4509 : /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
4510 :
4511 : The types must satisfy comparable_template_types_p.
4512 :
4513 : If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
4514 : potentially colorizing/eliding in comparison with TYPE_B.
4515 :
4516 : For example given types:
4517 : vector<map<int,double>>
4518 : and
4519 : vector<map<int,float>>
4520 : then the result on PP would be:
4521 : vector<map<[...],double>>
4522 : with type elision, and:
4523 : vector<map<int,double>>
4524 : without type elision.
4525 :
4526 : In both cases the parts of TYPE that differ from PEER will be colorized
4527 : if pp_show_color (pp) is true. In the above example, this would be
4528 : "double".
4529 :
4530 : If INDENT is non-zero, then the types are printed in a tree-like form
4531 : which shows both types. In the above example, the result on PP would be:
4532 :
4533 : vector<
4534 : map<
4535 : [...],
4536 : [double != float]>>
4537 :
4538 : and without type-elision would be:
4539 :
4540 : vector<
4541 : map<
4542 : int,
4543 : [double != float]>>
4544 :
4545 : As before, the differing parts of the types are colorized if
4546 : pp_show_color (pp) is true ("double" and "float" in this example).
4547 :
4548 : Template arguments in which both types are using the default arguments
4549 : are not printed; if at least one of the two types is using a non-default
4550 : argument, then that argument is printed (or both arguments for the
4551 : tree-like print format). */
4552 :
4553 : static void
4554 443 : print_template_differences (pretty_printer *pp, tree type_a, tree type_b,
4555 : bool verbose, int indent,
4556 : const char *highlight_color_a,
4557 : const char *highlight_color_b)
4558 : {
4559 443 : if (indent)
4560 85 : newline_and_indent (pp, indent);
4561 :
4562 443 : tree tinfo_a = TYPE_TEMPLATE_INFO (type_a);
4563 443 : tree tinfo_b = TYPE_TEMPLATE_INFO (type_b);
4564 :
4565 443 : pp_printf (pp, "%s<",
4566 443 : IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a))));
4567 :
4568 443 : tree args_a = TI_ARGS (tinfo_a);
4569 443 : tree args_b = TI_ARGS (tinfo_b);
4570 443 : gcc_assert (TREE_CODE (args_a) == TREE_VEC);
4571 443 : gcc_assert (TREE_CODE (args_b) == TREE_VEC);
4572 443 : int flags = 0;
4573 443 : int len_a = get_non_default_template_args_count (args_a, flags);
4574 443 : args_a = INNERMOST_TEMPLATE_ARGS (args_a);
4575 443 : int len_b = get_non_default_template_args_count (args_b, flags);
4576 443 : args_b = INNERMOST_TEMPLATE_ARGS (args_b);
4577 : /* Determine the maximum range of args for which non-default template args
4578 : were used; beyond this, only default args (if any) were used, and so
4579 : they will be equal from this point onwards.
4580 : One of the two peers might have used default arguments within this
4581 : range, but the other will be using non-default arguments, and so
4582 : it's more readable to print both within this range, to highlight
4583 : the differences. */
4584 443 : int len_max = MAX (len_a, len_b);
4585 443 : gcc_assert (TREE_CODE (args_a) == TREE_VEC);
4586 443 : gcc_assert (TREE_CODE (args_b) == TREE_VEC);
4587 1116 : for (int idx = 0; idx < len_max; idx++)
4588 : {
4589 673 : if (idx)
4590 230 : pp_character (pp, ',');
4591 :
4592 673 : tree arg_a = TREE_VEC_ELT (args_a, idx);
4593 673 : tree arg_b = TREE_VEC_ELT (args_b, idx);
4594 673 : if (arg_a == arg_b)
4595 : {
4596 128 : if (indent)
4597 39 : newline_and_indent (pp, indent + 2);
4598 : /* Can do elision here, printing "[...]". */
4599 128 : if (flag_elide_type)
4600 116 : pp_string (pp, G_("[...]"));
4601 : else
4602 12 : pp_string (pp, arg_to_string (arg_a, verbose));
4603 : }
4604 : else
4605 : {
4606 545 : int new_indent = indent ? indent + 2 : 0;
4607 545 : if (comparable_template_types_p (arg_a, arg_b))
4608 33 : print_template_differences (pp, arg_a, arg_b, verbose, new_indent,
4609 : highlight_color_a, highlight_color_b);
4610 : else
4611 512 : if (indent)
4612 : {
4613 104 : newline_and_indent (pp, indent + 2);
4614 104 : pp_character (pp, '[');
4615 104 : print_nonequal_arg (pp, arg_a, verbose, highlight_color_a);
4616 104 : pp_string (pp, " != ");
4617 104 : print_nonequal_arg (pp, arg_b, verbose, highlight_color_b);
4618 104 : pp_character (pp, ']');
4619 : }
4620 : else
4621 408 : print_nonequal_arg (pp, arg_a, verbose, highlight_color_a);
4622 : }
4623 : }
4624 443 : pp_printf (pp, ">");
4625 443 : }
4626 :
4627 : /* As type_to_string, but for a template, potentially colorizing/eliding
4628 : in comparison with PEER.
4629 : For example, if TYPE is map<int,double> and PEER is map<int,int>,
4630 : then the resulting string would be:
4631 : map<[...],double>
4632 : with type elision, and:
4633 : map<int,double>
4634 : without type elision.
4635 :
4636 : In both cases the parts of TYPE that differ from PEER will be colorized
4637 : if SHOW_COLOR is true. In the above example, this would be "double".
4638 :
4639 : Template arguments in which both types are using the default arguments
4640 : are not printed; if at least one of the two types is using a non-default
4641 : argument, then both arguments are printed.
4642 :
4643 : The resulting string is in a GC-allocated buffer. */
4644 :
4645 : static const char *
4646 336 : type_to_string_with_compare (tree type, tree peer, bool verbose,
4647 : bool show_color,
4648 : const char *this_highlight_color,
4649 : const char *peer_highlight_color)
4650 : {
4651 336 : pretty_printer inner_pp;
4652 336 : pretty_printer *pp = &inner_pp;
4653 336 : pp_show_color (pp) = show_color;
4654 :
4655 336 : print_template_differences (pp, type, peer, verbose, 0,
4656 : this_highlight_color, peer_highlight_color);
4657 336 : return pp_ggc_formatted_text (pp);
4658 336 : }
4659 :
4660 : /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4661 : indented by INDENT spaces.
4662 :
4663 : For example given types:
4664 :
4665 : vector<map<int,double>>
4666 :
4667 : and
4668 :
4669 : vector<map<double,float>>
4670 :
4671 : the output with type elision would be:
4672 :
4673 : vector<
4674 : map<
4675 : [...],
4676 : [double != float]>>
4677 :
4678 : and without type-elision would be:
4679 :
4680 : vector<
4681 : map<
4682 : int,
4683 : [double != float]>>
4684 :
4685 : TYPE_A and TYPE_B must both be comparable template types
4686 : (as per comparable_template_types_p).
4687 :
4688 : Template arguments in which both types are using the default arguments
4689 : are not printed; if at least one of the two types is using a non-default
4690 : argument, then both arguments are printed. */
4691 :
4692 : static void
4693 74 : print_template_tree_comparison (pretty_printer *pp, tree type_a, tree type_b,
4694 : bool verbose, int indent,
4695 : const char *highlight_color_a,
4696 : const char *highlight_color_b)
4697 : {
4698 0 : print_template_differences (pp, type_a, type_b, verbose, indent,
4699 : highlight_color_a,
4700 : highlight_color_b);
4701 0 : }
4702 :
4703 : /* Subroutine for use in a format_postprocessor::handle
4704 : implementation. Adds a chunk to the end of
4705 : formatted output, so that it will be printed
4706 : by pp_output_formatted_text. */
4707 :
4708 : static void
4709 74 : append_formatted_chunk (pretty_printer *pp, const char *content)
4710 : {
4711 74 : output_buffer *buffer = pp_buffer (pp);
4712 74 : pp_formatted_chunks *chunk_array = buffer->m_cur_formatted_chunks;
4713 0 : chunk_array->append_formatted_chunk (buffer->m_chunk_obstack, content);
4714 0 : }
4715 :
4716 : #if __GNUC__ >= 10
4717 : #pragma GCC diagnostic pop
4718 : #endif
4719 :
4720 : /* If we had %H and %I, and hence deferred printing them,
4721 : print them now, storing the result into custom_token_value
4722 : for the custom pp_token. Quote them if 'q' was provided.
4723 : Also print the difference in tree form, adding it as
4724 : an additional chunk. */
4725 :
4726 : void
4727 347701 : cxx_format_postprocessor::handle (pretty_printer *pp)
4728 : {
4729 : /* If we have one of %H and %I, the other should have
4730 : been present. */
4731 347701 : if (m_type_a.m_tree || m_type_b.m_tree)
4732 : {
4733 10494 : const bool show_highlight_colors = pp_show_highlight_colors (pp);
4734 10494 : const char *percent_h
4735 10494 : = show_highlight_colors ? highlight_colors::percent_h : nullptr;
4736 2 : const char *percent_i
4737 : = show_highlight_colors ? highlight_colors::percent_i : nullptr;
4738 : /* Avoid reentrancy issues by working with a copy of
4739 : m_type_a and m_type_b, resetting them now. */
4740 10494 : deferred_printed_type type_a = std::move (m_type_a);
4741 10494 : deferred_printed_type type_b = std::move (m_type_b);
4742 10494 : m_type_a = deferred_printed_type ();
4743 10494 : m_type_b = deferred_printed_type ();
4744 :
4745 10494 : gcc_assert (type_a.m_token_list);
4746 10494 : gcc_assert (type_b.m_token_list);
4747 :
4748 10494 : bool show_color = pp_show_color (pp);
4749 :
4750 10494 : const char *type_a_text;
4751 10494 : const char *type_b_text;
4752 :
4753 10494 : if (comparable_template_types_p (type_a.m_tree, type_b.m_tree))
4754 : {
4755 167 : type_a_text = type_to_string_with_compare
4756 167 : (type_a.m_tree, type_b.m_tree,
4757 : type_a.m_verbose, show_color,
4758 : percent_h, percent_i);
4759 167 : type_b_text = type_to_string_with_compare
4760 167 : (type_b.m_tree, type_a.m_tree,
4761 : type_b.m_verbose, show_color,
4762 : percent_i, percent_h);
4763 :
4764 167 : if (flag_diagnostics_show_template_tree)
4765 : {
4766 74 : pretty_printer inner_pp;
4767 74 : pp_show_color (&inner_pp) = pp_show_color (pp);
4768 74 : print_template_tree_comparison
4769 74 : (&inner_pp, type_a.m_tree, type_b.m_tree, type_a.m_verbose, 2,
4770 : percent_h, percent_i);
4771 74 : append_formatted_chunk (pp, pp_ggc_formatted_text (&inner_pp));
4772 74 : }
4773 : }
4774 : else
4775 : {
4776 : /* If the types were not comparable (or if only one of %H/%I was
4777 : provided), they are printed normally, and no difference tree
4778 : is printed. */
4779 10327 : type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose,
4780 : true, &type_a.m_quote, show_color,
4781 : percent_h);
4782 10327 : type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose,
4783 : true, &type_b.m_quote, show_color,
4784 : percent_i);
4785 : }
4786 :
4787 10494 : type_a.set_text_for_token_list (type_a_text, type_a.m_quote);
4788 10494 : type_b.set_text_for_token_list (type_b_text, type_b.m_quote);
4789 10494 : }
4790 347701 : }
4791 :
4792 : /* Subroutine for handling %H and %I, to support i18n of messages like:
4793 :
4794 : error_at (loc, "could not convert %qE from %qH to %qI",
4795 : expr, type_a, type_b);
4796 :
4797 : so that we can print things like:
4798 :
4799 : could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4800 :
4801 : and, with type-elision:
4802 :
4803 : could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4804 :
4805 : (with color-coding of the differences between the types).
4806 :
4807 : The %H and %I format codes are peers: both must be present,
4808 : and they affect each other. Hence to handle them, we must
4809 : delay printing until we have both, deferring the printing to
4810 : pretty_printer's m_format_postprocessor hook.
4811 :
4812 : This is called in phase 2 of pp_format, when it is accumulating
4813 : a series of pp_token lists. Since we have to interact with the
4814 : fiddly quoting logic for "aka", we store the pp_token_list *
4815 : and in the m_format_postprocessor hook we generate text for the type
4816 : (possibly with quotes and colors), then replace all tokens in that token list
4817 : (such as [BEGIN_QUOTE, END_QUOTE]) with a text token containing the
4818 : freshly generated text.
4819 :
4820 : We also need to stash whether a 'q' prefix was provided (the QUOTE
4821 : param) so that we can add the quotes when writing out the delayed
4822 : chunk. */
4823 :
4824 : static void
4825 20988 : defer_phase_2_of_type_diff (deferred_printed_type *deferred,
4826 : tree type,
4827 : pp_token_list &formatted_token_list,
4828 : bool verbose, bool quote)
4829 : {
4830 20988 : gcc_assert (deferred->m_tree == NULL_TREE);
4831 41976 : *deferred = deferred_printed_type (type, formatted_token_list,
4832 20988 : verbose, quote);
4833 20988 : }
4834 :
4835 : /* Implementation of pp_markup::element_quoted_type::print_type
4836 : for C++/ObjC++. */
4837 :
4838 : void
4839 752 : pp_markup::element_quoted_type::print_type (pp_markup::context &ctxt)
4840 : {
4841 752 : const char *highlight_color
4842 752 : = pp_show_highlight_colors (&ctxt.m_pp) ? m_highlight_color : nullptr;
4843 752 : const char *result
4844 1504 : = type_to_string (m_type, false, false, &ctxt.m_quoted,
4845 752 : pp_show_color (&ctxt.m_pp), highlight_color);
4846 752 : pp_string (&ctxt.m_pp, result);
4847 752 : }
4848 :
4849 : /* Called from output_format -- during diagnostic message processing --
4850 : to handle C++ specific format specifier with the following meanings:
4851 : %A function argument-list.
4852 : %C tree code.
4853 : %D declaration.
4854 : %E expression.
4855 : %F function declaration.
4856 : %H type difference (from).
4857 : %I type difference (to).
4858 : %L language as used in extern "lang".
4859 : %O binary operator.
4860 : %P function parameter whose position is indicated by an integer.
4861 : %Q assignment operator.
4862 : %S substitution (template + args)
4863 : %T type.
4864 : %V cv-qualifier.
4865 : %X exception-specification. */
4866 : static bool
4867 219508 : cp_printer (pretty_printer *pp, text_info *text, const char *spec,
4868 : int precision, bool wide, bool set_locus, bool verbose,
4869 : bool *quoted, pp_token_list &formatted_token_list)
4870 : {
4871 219508 : gcc_assert (pp_format_postprocessor (pp));
4872 219508 : cxx_format_postprocessor *postprocessor
4873 219508 : = static_cast <cxx_format_postprocessor *> (pp_format_postprocessor (pp));
4874 :
4875 219508 : const char *result;
4876 219508 : tree t = NULL;
4877 : #define next_tree (t = va_arg (*text->m_args_ptr, tree))
4878 : #define next_tcode ((enum tree_code) va_arg (*text->m_args_ptr, int))
4879 : #define next_lang ((enum languages) va_arg (*text->m_args_ptr, int))
4880 : #define next_int va_arg (*text->m_args_ptr, int)
4881 :
4882 219508 : if (precision != 0 || wide)
4883 : return false;
4884 :
4885 219508 : switch (*spec)
4886 : {
4887 3909 : case 'A': result = args_to_string (next_tree, verbose); break;
4888 0 : case 'C': result = code_to_string (next_tcode); break;
4889 99471 : case 'D':
4890 99471 : {
4891 99471 : tree temp = next_tree;
4892 99471 : if (VAR_P (temp)
4893 99471 : && DECL_HAS_DEBUG_EXPR_P (temp))
4894 : {
4895 24 : temp = DECL_DEBUG_EXPR (temp);
4896 24 : if (!DECL_P (temp))
4897 : {
4898 24 : result = expr_to_string (temp);
4899 24 : break;
4900 : }
4901 : }
4902 99447 : result = decl_to_string (temp, verbose, pp_show_color (pp));
4903 : }
4904 99447 : break;
4905 49650 : case 'E': result = expr_to_string (next_tree); break;
4906 350 : case 'F': result = fndecl_to_string (next_tree, verbose); break;
4907 10494 : case 'H':
4908 20988 : defer_phase_2_of_type_diff (&postprocessor->m_type_a, next_tree,
4909 10494 : formatted_token_list, verbose, *quoted);
4910 10494 : return true;
4911 10494 : case 'I':
4912 20988 : defer_phase_2_of_type_diff (&postprocessor->m_type_b, next_tree,
4913 10494 : formatted_token_list, verbose, *quoted);
4914 10494 : return true;
4915 24 : case 'L': result = language_to_string (next_lang); break;
4916 297 : case 'O': result = op_to_string (false, next_tcode); break;
4917 1538 : case 'P': result = parm_to_string (next_int); break;
4918 24 : case 'Q': result = op_to_string (true, next_tcode); break;
4919 1561 : case 'S': result = subst_to_string (next_tree, pp_show_color (pp)); break;
4920 41054 : case 'T':
4921 41054 : {
4922 82108 : result = type_to_string (next_tree, verbose, false, quoted,
4923 41054 : pp_show_color (pp));
4924 : }
4925 41054 : break;
4926 639 : case 'V': result = cv_to_string (next_tree, verbose); break;
4927 3 : case 'X': result = eh_spec_to_string (next_tree, verbose); break;
4928 :
4929 : default:
4930 : return false;
4931 : }
4932 :
4933 198520 : pp_string (pp, result);
4934 198520 : if (set_locus && t != NULL)
4935 1772 : text->set_location (0, location_of (t), SHOW_RANGE_WITH_CARET);
4936 : return true;
4937 : #undef next_tree
4938 : #undef next_tcode
4939 : #undef next_lang
4940 : #undef next_int
4941 : }
4942 :
4943 : /* Warn about the use of C++0x features when appropriate. */
4944 : void
4945 84376918 : maybe_warn_cpp0x (cpp0x_warn_str str, location_t loc/*=input_location*/)
4946 : {
4947 84376918 : if (cxx_dialect == cxx98)
4948 4338 : switch (str)
4949 : {
4950 180 : case CPP0X_INITIALIZER_LISTS:
4951 180 : pedwarn (loc, OPT_Wc__11_extensions,
4952 : "extended initializer lists "
4953 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4954 180 : break;
4955 0 : case CPP0X_EXPLICIT_CONVERSION:
4956 0 : pedwarn (loc, OPT_Wc__11_extensions,
4957 : "explicit conversion operators "
4958 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4959 0 : break;
4960 1390 : case CPP0X_VARIADIC_TEMPLATES:
4961 1390 : pedwarn (loc, OPT_Wc__11_extensions,
4962 : "variadic templates "
4963 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4964 1390 : break;
4965 6 : case CPP0X_LAMBDA_EXPR:
4966 6 : pedwarn (loc, OPT_Wc__11_extensions,
4967 : "lambda expressions "
4968 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4969 6 : break;
4970 0 : case CPP0X_AUTO:
4971 0 : pedwarn (loc, OPT_Wc__11_extensions,
4972 : "C++11 auto only available with %<-std=c++11%> or "
4973 : "%<-std=gnu++11%>");
4974 0 : break;
4975 15 : case CPP0X_SCOPED_ENUMS:
4976 15 : pedwarn (loc, OPT_Wc__11_extensions,
4977 : "scoped enums only available with %<-std=c++11%> or "
4978 : "%<-std=gnu++11%>");
4979 15 : break;
4980 535 : case CPP0X_DEFAULTED_DELETED:
4981 535 : pedwarn (loc, OPT_Wc__11_extensions,
4982 : "defaulted and deleted functions "
4983 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4984 535 : break;
4985 1921 : case CPP0X_INLINE_NAMESPACES:
4986 1921 : if (pedantic)
4987 581 : pedwarn (loc, OPT_Wc__11_extensions,
4988 : "inline namespaces "
4989 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4990 : break;
4991 3 : case CPP0X_OVERRIDE_CONTROLS:
4992 3 : pedwarn (loc, OPT_Wc__11_extensions,
4993 : "override controls (override/final) "
4994 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4995 3 : break;
4996 132 : case CPP0X_NSDMI:
4997 132 : pedwarn (loc, OPT_Wc__11_extensions,
4998 : "non-static data member initializers "
4999 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5000 132 : break;
5001 4 : case CPP0X_USER_DEFINED_LITERALS:
5002 4 : pedwarn (loc, OPT_Wc__11_extensions,
5003 : "user-defined literals "
5004 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5005 4 : break;
5006 3 : case CPP0X_DELEGATING_CTORS:
5007 3 : pedwarn (loc, OPT_Wc__11_extensions,
5008 : "delegating constructors "
5009 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5010 3 : break;
5011 3 : case CPP0X_INHERITING_CTORS:
5012 3 : pedwarn (loc, OPT_Wc__11_extensions,
5013 : "inheriting constructors "
5014 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5015 3 : break;
5016 146 : case CPP0X_ATTRIBUTES:
5017 146 : if (pedantic)
5018 24 : pedwarn (loc, OPT_Wc__11_extensions,
5019 : "C++11 attributes "
5020 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5021 : break;
5022 0 : case CPP0X_REF_QUALIFIER:
5023 0 : pedwarn (loc, OPT_Wc__11_extensions,
5024 : "ref-qualifiers "
5025 : "only available with %<-std=c++11%> or %<-std=gnu++11%>");
5026 0 : break;
5027 0 : default:
5028 0 : gcc_unreachable ();
5029 : }
5030 84376918 : }
5031 :
5032 : /* Warn about the use of variadic templates when appropriate. */
5033 : void
5034 13978204 : maybe_warn_variadic_templates (void)
5035 : {
5036 13978204 : maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES);
5037 13978204 : }
5038 :
5039 :
5040 : /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
5041 : option OPTION_ID with text GMSGID. Use this function to report
5042 : diagnostics for constructs that are invalid C++98, but valid
5043 : C++0x. */
5044 : bool
5045 3677288 : pedwarn_cxx98 (location_t location,
5046 : diagnostics::option_id option_id,
5047 : const char *gmsgid, ...)
5048 : {
5049 3677288 : diagnostics::diagnostic_info diagnostic;
5050 3677288 : va_list ap;
5051 3677288 : bool ret;
5052 3677288 : rich_location richloc (line_table, location);
5053 :
5054 3677288 : va_start (ap, gmsgid);
5055 3677288 : diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
5056 3677288 : (cxx_dialect == cxx98
5057 : ? diagnostics::kind::pedwarn
5058 : : diagnostics::kind::warning));
5059 3677288 : diagnostic.m_option_id = option_id;
5060 3677288 : ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
5061 3677288 : va_end (ap);
5062 7354576 : return ret;
5063 3677288 : }
5064 :
5065 : /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
5066 : we found when we tried to do the lookup. LOCATION is the location of
5067 : the NAME identifier. */
5068 :
5069 : void
5070 557 : qualified_name_lookup_error (tree scope, tree name,
5071 : tree decl, location_t location)
5072 : {
5073 557 : if (scope == error_mark_node)
5074 : ; /* We already complained. */
5075 442 : else if (TYPE_P (scope))
5076 : {
5077 249 : if (!COMPLETE_TYPE_P (scope)
5078 249 : && !currently_open_class (scope))
5079 41 : error_at (location, "incomplete type %qT used in nested name specifier",
5080 : scope);
5081 208 : else if (TREE_CODE (decl) == TREE_LIST)
5082 : {
5083 0 : auto_diagnostic_group d;
5084 0 : error_at (location, "reference to %<%T::%D%> is ambiguous",
5085 : scope, name);
5086 0 : print_candidates (location, decl);
5087 0 : }
5088 : else
5089 : {
5090 208 : auto_diagnostic_group d;
5091 208 : name_hint hint;
5092 208 : if (SCOPED_ENUM_P (scope) && TREE_CODE (name) == IDENTIFIER_NODE)
5093 15 : hint = suggest_alternative_in_scoped_enum (name, scope);
5094 208 : if (const char *suggestion = hint.suggestion ())
5095 : {
5096 9 : gcc_rich_location richloc (location);
5097 9 : richloc.add_fixit_replace (suggestion);
5098 9 : error_at (&richloc,
5099 : "%qD is not a member of %qT; did you mean %qs?",
5100 : name, scope, suggestion);
5101 9 : }
5102 : else
5103 199 : error_at (location, "%qD is not a member of %qT", name, scope);
5104 208 : }
5105 : }
5106 193 : else if (scope != global_namespace)
5107 : {
5108 175 : auto_diagnostic_group d;
5109 175 : bool emit_fixit = true;
5110 175 : name_hint hint
5111 175 : = suggest_alternative_in_explicit_scope (location, name, scope);
5112 175 : if (!hint)
5113 : {
5114 59 : hint = suggest_alternatives_in_other_namespaces (location, name);
5115 : /* "location" is just the location of the name, not of the explicit
5116 : scope, and it's not easy to get at the latter, so we can't issue
5117 : fix-it hints for the suggestion. */
5118 59 : emit_fixit = false;
5119 : }
5120 175 : if (const char *suggestion = hint.suggestion ())
5121 : {
5122 54 : gcc_rich_location richloc (location);
5123 54 : if (emit_fixit)
5124 33 : richloc.add_fixit_replace (suggestion);
5125 54 : error_at (&richloc, "%qD is not a member of %qD; did you mean %qs?",
5126 : name, scope, suggestion);
5127 54 : }
5128 : else
5129 121 : error_at (location, "%qD is not a member of %qD", name, scope);
5130 175 : }
5131 : else
5132 : {
5133 18 : auto_diagnostic_group d;
5134 18 : name_hint hint = suggest_alternatives_for (location, name, true);
5135 18 : if (const char *suggestion = hint.suggestion ())
5136 : {
5137 9 : gcc_rich_location richloc (location);
5138 9 : richloc.add_fixit_replace (suggestion);
5139 9 : error_at (&richloc,
5140 : "%<::%D%> has not been declared; did you mean %qs?",
5141 : name, suggestion);
5142 9 : }
5143 : else
5144 9 : error_at (location, "%<::%D%> has not been declared", name);
5145 18 : }
5146 557 : }
5147 :
5148 : /* C++-specific implementation of range_label::get_text () vfunc for
5149 : range_label_for_type_mismatch.
5150 :
5151 : Compare with print_template_differences above. */
5152 :
5153 : label_text
5154 437 : range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
5155 : {
5156 437 : if (m_labelled_type == NULL_TREE)
5157 0 : return label_text::borrow (NULL);
5158 :
5159 437 : const bool verbose = false;
5160 437 : const bool show_color = false;
5161 :
5162 437 : const char *result;
5163 437 : if (m_other_type
5164 437 : && comparable_template_types_p (m_labelled_type, m_other_type))
5165 2 : result = type_to_string_with_compare (m_labelled_type, m_other_type,
5166 : verbose, show_color,
5167 : nullptr, nullptr);
5168 : else
5169 435 : result = type_to_string (m_labelled_type, verbose, true, NULL, show_color);
5170 :
5171 : /* Both of the above return GC-allocated buffers, so the caller mustn't
5172 : free them. */
5173 437 : return label_text::borrow (result);
5174 : }
|