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