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