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