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