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