]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Call-backs for C++ error reporting. |
2 | This code is non-reentrant. | |
8d9254fc | 3 | Copyright (C) 1993-2020 Free Software Foundation, Inc. |
f5adbb8d | 4 | This file is part of GCC. |
8d08fdba | 5 | |
f5adbb8d | 6 | GCC is free software; you can redistribute it and/or modify |
8d08fdba | 7 | it under the terms of the GNU General Public License as published by |
e77f031d | 8 | the Free Software Foundation; either version 3, or (at your option) |
8d08fdba MS |
9 | any later version. |
10 | ||
f5adbb8d | 11 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
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 | |
e77f031d NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
8d08fdba MS |
19 | |
20 | #include "config.h" | |
7e2de6df DM |
21 | /* For use with name_hint. */ |
22 | #define INCLUDE_UNIQUE_PTR | |
8d052bc7 | 23 | #include "system.h" |
4977bab6 | 24 | #include "coretypes.h" |
8d08fdba | 25 | #include "cp-tree.h" |
2adfab87 | 26 | #include "stringpool.h" |
cf835838 | 27 | #include "tree-diagnostic.h" |
7cb32822 | 28 | #include "langhooks-def.h" |
b02cec6e | 29 | #include "intl.h" |
e1a4dd13 | 30 | #include "cxx-pretty-print.h" |
cf835838 | 31 | #include "tree-pretty-print.h" |
da67acb9 | 32 | #include "gimple-pretty-print.h" |
61d3ce20 | 33 | #include "c-family/c-objc.h" |
de5a5fa1 | 34 | #include "ubsan.h" |
0b274c17 | 35 | #include "internal-fn.h" |
96e6ae57 | 36 | #include "gcc-rich-location.h" |
7e2de6df | 37 | #include "cp-name-hint.h" |
8d08fdba | 38 | |
73bbafe5 | 39 | #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') |
ca17c07b | 40 | #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') |
a1066c99 | 41 | |
d723bb7c MLI |
42 | /* cxx_pp is a C++ front-end-specific pretty printer: this is where we |
43 | dump C++ ASTs as strings. It is mostly used only by the various | |
44 | tree -> string functions that are occasionally called from the | |
45 | debugger or by the front-end for things like | |
46 | __PRETTY_FUNCTION__. */ | |
5d58db82 PP |
47 | static cxx_pretty_printer actual_pretty_printer; |
48 | static cxx_pretty_printer * const cxx_pp = &actual_pretty_printer; | |
0aafb128 | 49 | |
f41c4af3 JM |
50 | /* Translate if being used for diagnostics, but not for dump files or |
51 | __PRETTY_FUNCTION. */ | |
52 | #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid)) | |
53 | ||
b34c06e3 | 54 | # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T))) |
8d08fdba | 55 | |
3f8548e7 | 56 | static const char *args_to_string (tree, int); |
4e3f84b7 | 57 | static const char *code_to_string (enum tree_code); |
3f8548e7 GDR |
58 | static const char *cv_to_string (tree, int); |
59 | static const char *decl_to_string (tree, int); | |
3f8548e7 | 60 | static const char *fndecl_to_string (tree, int); |
88a819be | 61 | static const char *op_to_string (bool, enum tree_code); |
4e3f84b7 | 62 | static const char *parm_to_string (int); |
ce95abc4 | 63 | static const char *type_to_string (tree, int, bool, bool *, bool); |
3f8548e7 | 64 | |
3c1ab1ab GDR |
65 | static void dump_alias_template_specialization (cxx_pretty_printer *, tree, int); |
66 | static void dump_type (cxx_pretty_printer *, tree, int); | |
67 | static void dump_typename (cxx_pretty_printer *, tree, int); | |
68 | static void dump_simple_decl (cxx_pretty_printer *, tree, tree, int); | |
69 | static void dump_decl (cxx_pretty_printer *, tree, int); | |
70 | static void dump_template_decl (cxx_pretty_printer *, tree, int); | |
71 | static void dump_function_decl (cxx_pretty_printer *, tree, int); | |
72 | static void dump_expr (cxx_pretty_printer *, tree, int); | |
73 | static void dump_unary_op (cxx_pretty_printer *, const char *, tree, int); | |
74 | static void dump_binary_op (cxx_pretty_printer *, const char *, tree, int); | |
75 | static void dump_aggr_type (cxx_pretty_printer *, tree, int); | |
76 | static void dump_type_prefix (cxx_pretty_printer *, tree, int); | |
77 | static void dump_type_suffix (cxx_pretty_printer *, tree, int); | |
78 | static void dump_function_name (cxx_pretty_printer *, tree, int); | |
79 | static void dump_call_expr_args (cxx_pretty_printer *, tree, int, bool); | |
80 | static void dump_aggr_init_expr_args (cxx_pretty_printer *, tree, int, bool); | |
81 | static void dump_expr_list (cxx_pretty_printer *, tree, int); | |
82 | static void dump_global_iord (cxx_pretty_printer *, tree); | |
83 | static void dump_parameters (cxx_pretty_printer *, tree, int); | |
84 | static void dump_ref_qualifier (cxx_pretty_printer *, tree, int); | |
85 | static void dump_exception_spec (cxx_pretty_printer *, tree, int); | |
86 | static void dump_template_argument (cxx_pretty_printer *, tree, int); | |
87 | static void dump_template_argument_list (cxx_pretty_printer *, tree, int); | |
88 | static void dump_template_parameter (cxx_pretty_printer *, tree, int); | |
89 | static void dump_template_bindings (cxx_pretty_printer *, tree, tree, | |
90 | vec<tree, va_gc> *); | |
91 | static void dump_scope (cxx_pretty_printer *, tree, int); | |
92 | static void dump_template_parms (cxx_pretty_printer *, tree, int, int); | |
1a048f82 | 93 | static int get_non_default_template_args_count (tree, int); |
3f8548e7 | 94 | static const char *function_category (tree); |
2bfe0527 | 95 | static void maybe_print_constexpr_context (diagnostic_context *); |
3f8548e7 GDR |
96 | static void maybe_print_instantiation_context (diagnostic_context *); |
97 | static void print_instantiation_full_context (diagnostic_context *); | |
98 | static void print_instantiation_partial_context (diagnostic_context *, | |
e2c3721c PB |
99 | struct tinst_level *, |
100 | location_t); | |
cb57504a | 101 | static void maybe_print_constraint_context (diagnostic_context *); |
3f8548e7 | 102 | static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *); |
3f8548e7 GDR |
103 | static void cp_print_error_function (diagnostic_context *, diagnostic_info *); |
104 | ||
39ce81c9 | 105 | static bool cp_printer (pretty_printer *, text_info *, const char *, |
ce95abc4 | 106 | int, bool, bool, bool, bool *, const char **); |
f012c8ef DM |
107 | |
108 | /* Struct for handling %H or %I, which require delaying printing the | |
109 | type until a postprocessing stage. */ | |
110 | ||
6c1dae73 | 111 | class deferred_printed_type |
f012c8ef | 112 | { |
6c1dae73 | 113 | public: |
f012c8ef DM |
114 | deferred_printed_type () |
115 | : m_tree (NULL_TREE), m_buffer_ptr (NULL), m_verbose (false), m_quote (false) | |
116 | {} | |
117 | ||
118 | deferred_printed_type (tree type, const char **buffer_ptr, bool verbose, | |
119 | bool quote) | |
120 | : m_tree (type), m_buffer_ptr (buffer_ptr), m_verbose (verbose), | |
121 | m_quote (quote) | |
122 | { | |
123 | gcc_assert (type); | |
124 | gcc_assert (buffer_ptr); | |
125 | } | |
126 | ||
127 | /* The tree is not GTY-marked: they are only non-NULL within a | |
128 | call to pp_format. */ | |
129 | tree m_tree; | |
130 | const char **m_buffer_ptr; | |
131 | bool m_verbose; | |
132 | bool m_quote; | |
133 | }; | |
134 | ||
135 | /* Subclass of format_postprocessor for the C++ frontend. | |
136 | This handles the %H and %I formatting codes, printing them | |
137 | in a postprocessing phase (since they affect each other). */ | |
138 | ||
139 | class cxx_format_postprocessor : public format_postprocessor | |
140 | { | |
141 | public: | |
142 | cxx_format_postprocessor () | |
143 | : m_type_a (), m_type_b () | |
144 | {} | |
145 | ||
368877a1 DM |
146 | format_postprocessor *clone() const FINAL OVERRIDE |
147 | { | |
148 | return new cxx_format_postprocessor (); | |
149 | } | |
150 | ||
f012c8ef DM |
151 | void handle (pretty_printer *pp) FINAL OVERRIDE; |
152 | ||
153 | deferred_printed_type m_type_a; | |
154 | deferred_printed_type m_type_b; | |
155 | }; | |
8d08fdba | 156 | |
d723bb7c MLI |
157 | /* CONTEXT->printer is a basic pretty printer that was constructed |
158 | presumably by diagnostic_initialize(), called early in the | |
159 | compiler's initialization process (in general_init) Before the FE | |
160 | is initialized. This (C++) FE-specific diagnostic initializer is | |
161 | thus replacing the basic pretty printer with one that has C++-aware | |
162 | capacities. */ | |
163 | ||
8d08fdba | 164 | void |
d723bb7c | 165 | cxx_initialize_diagnostics (diagnostic_context *context) |
8d08fdba | 166 | { |
d723bb7c MLI |
167 | pretty_printer *base = context->printer; |
168 | cxx_pretty_printer *pp = XNEW (cxx_pretty_printer); | |
169 | context->printer = new (pp) cxx_pretty_printer (); | |
170 | ||
171 | /* It is safe to free this object because it was previously XNEW()'d. */ | |
172 | base->~pretty_printer (); | |
173 | XDELETE (base); | |
174 | ||
175 | c_common_diagnostics_set_defaults (context); | |
176 | diagnostic_starter (context) = cp_diagnostic_starter; | |
18767f65 | 177 | /* diagnostic_finalizer is already c_diagnostic_finalizer. */ |
d723bb7c | 178 | diagnostic_format_decoder (context) = cp_printer; |
f012c8ef | 179 | pp->m_format_postprocessor = new cxx_format_postprocessor (); |
d723bb7c | 180 | } |
749ced52 | 181 | |
9e93bc9d | 182 | /* Dump a scope, if deemed necessary. */ |
bbcec105 | 183 | |
9e93bc9d | 184 | static void |
3c1ab1ab | 185 | dump_scope (cxx_pretty_printer *pp, tree scope, int flags) |
bbcec105 | 186 | { |
af88c58f | 187 | int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF); |
761f0855 | 188 | |
9e93bc9d NS |
189 | if (scope == NULL_TREE) |
190 | return; | |
bb20cc46 | 191 | |
3ded6ffd DM |
192 | /* Enum values within an unscoped enum will be CONST_DECL with an |
193 | ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the | |
194 | ENUMERAL_TYPE, so as to print any enclosing namespace. */ | |
195 | if (UNSCOPED_ENUM_P (scope)) | |
196 | scope = CP_TYPE_CONTEXT (scope); | |
197 | ||
9e93bc9d NS |
198 | if (TREE_CODE (scope) == NAMESPACE_DECL) |
199 | { | |
200 | if (scope != global_namespace) | |
0cbd7506 | 201 | { |
3c1ab1ab GDR |
202 | dump_decl (pp, scope, f); |
203 | pp_cxx_colon_colon (pp); | |
0cbd7506 | 204 | } |
9e93bc9d | 205 | } |
3ded6ffd DM |
206 | else if (AGGREGATE_TYPE_P (scope) |
207 | || SCOPED_ENUM_P (scope)) | |
9e93bc9d | 208 | { |
3c1ab1ab GDR |
209 | dump_type (pp, scope, f); |
210 | pp_cxx_colon_colon (pp); | |
9e93bc9d | 211 | } |
761f0855 | 212 | else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL) |
9e93bc9d | 213 | { |
1dcb7799 PP |
214 | if (DECL_USE_TEMPLATE (scope)) |
215 | f |= TFF_NO_FUNCTION_ARGUMENTS; | |
3c1ab1ab GDR |
216 | dump_function_decl (pp, scope, f); |
217 | pp_cxx_colon_colon (pp); | |
9e93bc9d | 218 | } |
bbcec105 JM |
219 | } |
220 | ||
612c671a | 221 | /* Dump the template ARGument under control of FLAGS. */ |
5f77d6cc GDR |
222 | |
223 | static void | |
3c1ab1ab | 224 | dump_template_argument (cxx_pretty_printer *pp, tree arg, int flags) |
5f77d6cc | 225 | { |
5d80a306 | 226 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 227 | dump_template_argument_list (pp, ARGUMENT_PACK_ARGS (arg), |
89a27d8f JM |
228 | /* No default args in argument packs. */ |
229 | flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
5d80a306 | 230 | else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL) |
3c1ab1ab | 231 | dump_type (pp, arg, flags & ~TFF_CLASS_KEY_OR_ENUM); |
5f77d6cc | 232 | else |
a9fe2f76 PC |
233 | { |
234 | if (TREE_CODE (arg) == TREE_LIST) | |
235 | arg = TREE_VALUE (arg); | |
236 | ||
16b61424 JM |
237 | /* Strip implicit conversions. */ |
238 | while (CONVERT_EXPR_P (arg)) | |
239 | arg = TREE_OPERAND (arg, 0); | |
240 | ||
3c1ab1ab | 241 | dump_expr (pp, arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM); |
a9fe2f76 | 242 | } |
5f77d6cc GDR |
243 | } |
244 | ||
53b39fe5 JM |
245 | /* Count the number of template arguments ARGS whose value does not |
246 | match the (optional) default template parameter in PARAMS */ | |
247 | ||
248 | static int | |
1a048f82 | 249 | get_non_default_template_args_count (tree args, int flags) |
53b39fe5 | 250 | { |
1a048f82 | 251 | int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 | 252 | |
1a048f82 | 253 | if (/* We use this flag when generating debug information. We don't |
b5b8b0ac AO |
254 | want to expand templates at this point, for this may generate |
255 | new decls, which gets decl counts out of sync, which may in | |
256 | turn cause codegen differences between compilations with and | |
257 | without -g. */ | |
1a048f82 | 258 | (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0 |
b5b8b0ac | 259 | || !flag_pretty_templates) |
53b39fe5 JM |
260 | return n; |
261 | ||
1a048f82 | 262 | return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args)); |
53b39fe5 JM |
263 | } |
264 | ||
612c671a GDR |
265 | /* Dump a template-argument-list ARGS (always a TREE_VEC) under control |
266 | of FLAGS. */ | |
267 | ||
268 | static void | |
3c1ab1ab | 269 | dump_template_argument_list (cxx_pretty_printer *pp, tree args, int flags) |
612c671a | 270 | { |
1a048f82 | 271 | int n = get_non_default_template_args_count (args, flags); |
612c671a GDR |
272 | int need_comma = 0; |
273 | int i; | |
274 | ||
53b39fe5 | 275 | for (i = 0; i < n; ++i) |
612c671a | 276 | { |
5d80a306 DG |
277 | tree arg = TREE_VEC_ELT (args, i); |
278 | ||
279 | /* Only print a comma if we know there is an argument coming. In | |
280 | the case of an empty template argument pack, no actual | |
281 | argument will be printed. */ | |
282 | if (need_comma | |
283 | && (!ARGUMENT_PACK_P (arg) | |
284 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 285 | pp_separate_with_comma (pp); |
5d80a306 | 286 | |
3c1ab1ab | 287 | dump_template_argument (pp, arg, flags); |
612c671a GDR |
288 | need_comma = 1; |
289 | } | |
290 | } | |
291 | ||
292 | /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */ | |
293 | ||
294 | static void | |
3c1ab1ab | 295 | dump_template_parameter (cxx_pretty_printer *pp, tree parm, int flags) |
612c671a | 296 | { |
42b304f1 LM |
297 | tree p; |
298 | tree a; | |
299 | ||
300 | if (parm == error_mark_node) | |
301 | return; | |
302 | ||
303 | p = TREE_VALUE (parm); | |
304 | a = TREE_PURPOSE (parm); | |
612c671a GDR |
305 | |
306 | if (TREE_CODE (p) == TYPE_DECL) | |
307 | { | |
761f0855 | 308 | if (flags & TFF_DECL_SPECIFIERS) |
0cbd7506 | 309 | { |
3c1ab1ab | 310 | pp_cxx_ws_string (pp, "class"); |
5d80a306 | 311 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p))) |
3c1ab1ab | 312 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 | 313 | if (DECL_NAME (p)) |
3c1ab1ab | 314 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
0cbd7506 | 315 | } |
612c671a | 316 | else if (DECL_NAME (p)) |
3c1ab1ab | 317 | pp_cxx_tree_identifier (pp, DECL_NAME (p)); |
612c671a | 318 | else |
3c1ab1ab | 319 | pp_cxx_canonical_template_parameter (pp, TREE_TYPE (p)); |
612c671a GDR |
320 | } |
321 | else | |
3c1ab1ab | 322 | dump_decl (pp, p, flags | TFF_DECL_SPECIFIERS); |
612c671a | 323 | |
761f0855 | 324 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE) |
612c671a | 325 | { |
3c1ab1ab GDR |
326 | pp_cxx_whitespace (pp); |
327 | pp_equal (pp); | |
328 | pp_cxx_whitespace (pp); | |
31bb3027 | 329 | if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL) |
3c1ab1ab | 330 | dump_type (pp, a, flags & ~TFF_CHASE_TYPEDEF); |
612c671a | 331 | else |
3c1ab1ab | 332 | dump_expr (pp, a, flags | TFF_EXPR_IN_PARENS); |
612c671a GDR |
333 | } |
334 | } | |
335 | ||
336 | /* Dump, under control of FLAGS, a template-parameter-list binding. | |
337 | PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a | |
338 | TREE_VEC. */ | |
339 | ||
340 | static void | |
3c1ab1ab GDR |
341 | dump_template_bindings (cxx_pretty_printer *pp, tree parms, tree args, |
342 | vec<tree, va_gc> *typenames) | |
612c671a | 343 | { |
ca17c07b | 344 | bool need_semicolon = false; |
d5c8be27 JM |
345 | int i; |
346 | tree t; | |
612c671a GDR |
347 | |
348 | while (parms) | |
349 | { | |
350 | tree p = TREE_VALUE (parms); | |
b5ac18ea MM |
351 | int lvl = TMPL_PARMS_DEPTH (parms); |
352 | int arg_idx = 0; | |
612c671a | 353 | int i; |
53b39fe5 JM |
354 | tree lvl_args = NULL_TREE; |
355 | ||
356 | /* Don't crash if we had an invalid argument list. */ | |
357 | if (TMPL_ARGS_DEPTH (args) >= lvl) | |
358 | lvl_args = TMPL_ARGS_LEVEL (args, lvl); | |
612c671a GDR |
359 | |
360 | for (i = 0; i < TREE_VEC_LENGTH (p); ++i) | |
b5ac18ea | 361 | { |
2bb5d995 JM |
362 | tree arg = NULL_TREE; |
363 | ||
364 | /* Don't crash if we had an invalid argument list. */ | |
53b39fe5 JM |
365 | if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx) |
366 | arg = TREE_VEC_ELT (lvl_args, arg_idx); | |
b5ac18ea | 367 | |
ca17c07b | 368 | if (need_semicolon) |
3c1ab1ab GDR |
369 | pp_separate_with_semicolon (pp); |
370 | dump_template_parameter (pp, TREE_VEC_ELT (p, i), | |
371 | TFF_PLAIN_IDENTIFIER); | |
372 | pp_cxx_whitespace (pp); | |
373 | pp_equal (pp); | |
374 | pp_cxx_whitespace (pp); | |
b5ac18ea | 375 | if (arg) |
af16209f JM |
376 | { |
377 | if (ARGUMENT_PACK_P (arg)) | |
3c1ab1ab GDR |
378 | pp_cxx_left_brace (pp); |
379 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
af16209f | 380 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 381 | pp_cxx_right_brace (pp); |
af16209f | 382 | } |
b5ac18ea | 383 | else |
3c1ab1ab | 384 | pp_string (pp, M_("<missing>")); |
bb20cc46 | 385 | |
b5ac18ea | 386 | ++arg_idx; |
ca17c07b | 387 | need_semicolon = true; |
b5ac18ea | 388 | } |
612c671a GDR |
389 | |
390 | parms = TREE_CHAIN (parms); | |
391 | } | |
d5c8be27 | 392 | |
21d69a5b | 393 | /* Don't bother with typenames for a partial instantiation. */ |
9771b263 | 394 | if (vec_safe_is_empty (typenames) || uses_template_parms (args)) |
21d69a5b JM |
395 | return; |
396 | ||
1ed5f1d3 JM |
397 | /* Don't try to print typenames when we're processing a clone. */ |
398 | if (current_function_decl | |
399 | && !DECL_LANG_SPECIFIC (current_function_decl)) | |
400 | return; | |
401 | ||
e5e58dbe JM |
402 | /* Don't try to do this once cgraph starts throwing away front-end |
403 | information. */ | |
404 | if (at_eof >= 2) | |
405 | return; | |
406 | ||
9771b263 | 407 | FOR_EACH_VEC_SAFE_ELT (typenames, i, t) |
d5c8be27 | 408 | { |
ca17c07b | 409 | if (need_semicolon) |
3c1ab1ab GDR |
410 | pp_separate_with_semicolon (pp); |
411 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); | |
412 | pp_cxx_whitespace (pp); | |
413 | pp_equal (pp); | |
414 | pp_cxx_whitespace (pp); | |
42d1e31d | 415 | push_deferring_access_checks (dk_no_check); |
a4d674fc | 416 | t = tsubst (t, args, tf_none, NULL_TREE); |
42d1e31d | 417 | pop_deferring_access_checks (); |
a4d674fc JM |
418 | /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because |
419 | pp_simple_type_specifier doesn't know about it. */ | |
10bce48f | 420 | t = strip_typedefs (t, NULL, STF_USER_VISIBLE); |
3c1ab1ab | 421 | dump_type (pp, t, TFF_PLAIN_IDENTIFIER); |
d5c8be27 | 422 | } |
612c671a GDR |
423 | } |
424 | ||
28704289 DS |
425 | /* Dump a human-readable equivalent of the alias template |
426 | specialization of T. */ | |
427 | ||
428 | static void | |
3c1ab1ab | 429 | dump_alias_template_specialization (cxx_pretty_printer *pp, tree t, int flags) |
28704289 | 430 | { |
96cbfa7f | 431 | gcc_assert (alias_template_specialization_p (t, nt_opaque)); |
28704289 | 432 | |
5bfd81e7 | 433 | tree decl = TYPE_NAME (t); |
7d29c953 | 434 | if (!(flags & TFF_UNQUALIFIED_NAME)) |
5bfd81e7 NS |
435 | dump_scope (pp, CP_DECL_CONTEXT (decl), flags); |
436 | pp_cxx_tree_identifier (pp, DECL_NAME (decl)); | |
437 | dump_template_parms (pp, DECL_TEMPLATE_INFO (decl), | |
28704289 DS |
438 | /*primary=*/false, |
439 | flags & ~TFF_TEMPLATE_HEADER); | |
440 | } | |
441 | ||
b3426eb9 GK |
442 | /* Dump a human-readable equivalent of TYPE. FLAGS controls the |
443 | format. */ | |
e92cc029 | 444 | |
8d08fdba | 445 | static void |
3c1ab1ab | 446 | dump_type (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
447 | { |
448 | if (t == NULL_TREE) | |
449 | return; | |
bb20cc46 | 450 | |
3333a2dd JM |
451 | /* Don't print e.g. "struct mytypedef". */ |
452 | if (TYPE_P (t) && typedef_variant_p (t)) | |
453 | { | |
454 | tree decl = TYPE_NAME (t); | |
455 | if ((flags & TFF_CHASE_TYPEDEF) | |
28704289 DS |
456 | || DECL_SELF_REFERENCE_P (decl) |
457 | || (!flag_pretty_templates | |
458 | && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))) | |
10bce48f RS |
459 | { |
460 | unsigned int stf_flags = (!(pp->flags & pp_c_flag_gnu_v3) | |
461 | ? STF_USER_VISIBLE : 0); | |
462 | t = strip_typedefs (t, NULL, stf_flags); | |
463 | } | |
96cbfa7f | 464 | else if (alias_template_specialization_p (t, nt_opaque)) |
28704289 | 465 | { |
3c1ab1ab | 466 | dump_alias_template_specialization (pp, t, flags); |
28704289 DS |
467 | return; |
468 | } | |
3333a2dd JM |
469 | else if (same_type_p (t, TREE_TYPE (decl))) |
470 | t = decl; | |
471 | else | |
472 | { | |
3c1ab1ab GDR |
473 | pp_cxx_cv_qualifier_seq (pp, t); |
474 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
3333a2dd JM |
475 | return; |
476 | } | |
477 | } | |
478 | ||
8d08fdba MS |
479 | if (TYPE_PTRMEMFUNC_P (t)) |
480 | goto offset_type; | |
481 | ||
482 | switch (TREE_CODE (t)) | |
483 | { | |
fbfc8363 | 484 | case LANG_TYPE: |
09357846 | 485 | if (t == init_list_type_node) |
3c1ab1ab | 486 | pp_string (pp, M_("<brace-enclosed initializer list>")); |
fbfc8363 | 487 | else if (t == unknown_type_node) |
3c1ab1ab | 488 | pp_string (pp, M_("<unresolved overloaded function type>")); |
fbfc8363 | 489 | else |
5116acc6 | 490 | { |
3c1ab1ab GDR |
491 | pp_cxx_cv_qualifier_seq (pp, t); |
492 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
5116acc6 | 493 | } |
8d08fdba MS |
494 | break; |
495 | ||
dcd08efc JM |
496 | case TREE_LIST: |
497 | /* A list of function parms. */ | |
3c1ab1ab | 498 | dump_parameters (pp, t, flags); |
dcd08efc JM |
499 | break; |
500 | ||
8d08fdba | 501 | case IDENTIFIER_NODE: |
3c1ab1ab | 502 | pp_cxx_tree_identifier (pp, t); |
8d08fdba MS |
503 | break; |
504 | ||
c81f61b2 | 505 | case TREE_BINFO: |
3c1ab1ab | 506 | dump_type (pp, BINFO_TYPE (t), flags); |
8d08fdba MS |
507 | break; |
508 | ||
509 | case RECORD_TYPE: | |
510 | case UNION_TYPE: | |
511 | case ENUMERAL_TYPE: | |
3c1ab1ab | 512 | dump_aggr_type (pp, t, flags); |
8d08fdba MS |
513 | break; |
514 | ||
515 | case TYPE_DECL: | |
761f0855 | 516 | if (flags & TFF_CHASE_TYPEDEF) |
0cbd7506 | 517 | { |
3c1ab1ab | 518 | dump_type (pp, DECL_ORIGINAL_TYPE (t) |
0cbd7506 MS |
519 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags); |
520 | break; | |
521 | } | |
191816a3 | 522 | /* Fall through. */ |
bb20cc46 | 523 | |
67c2a928 | 524 | case TEMPLATE_DECL: |
009425e1 | 525 | case NAMESPACE_DECL: |
3c1ab1ab | 526 | dump_decl (pp, t, flags & ~TFF_DECL_SPECIFIERS); |
8d08fdba | 527 | break; |
bb20cc46 | 528 | |
8d08fdba | 529 | case INTEGER_TYPE: |
8d08fdba MS |
530 | case REAL_TYPE: |
531 | case VOID_TYPE: | |
1e2d8575 | 532 | case OPAQUE_TYPE: |
2986ae00 | 533 | case BOOLEAN_TYPE: |
53de5204 GDR |
534 | case COMPLEX_TYPE: |
535 | case VECTOR_TYPE: | |
998ceda2 | 536 | case FIXED_POINT_TYPE: |
3c1ab1ab | 537 | pp_type_specifier_seq (pp, t); |
8d08fdba MS |
538 | break; |
539 | ||
73b0fce8 | 540 | case TEMPLATE_TEMPLATE_PARM: |
c6002625 | 541 | /* For parameters inside template signature. */ |
a1281f45 | 542 | if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 543 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
73b0fce8 | 544 | else |
3c1ab1ab | 545 | pp_cxx_canonical_template_parameter (pp, t); |
a1281f45 KL |
546 | break; |
547 | ||
548 | case BOUND_TEMPLATE_TEMPLATE_PARM: | |
549 | { | |
550 | tree args = TYPE_TI_ARGS (t); | |
3c1ab1ab GDR |
551 | pp_cxx_cv_qualifier_seq (pp, t); |
552 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
553 | pp_cxx_begin_template_argument_list (pp); | |
554 | dump_template_argument_list (pp, args, flags); | |
555 | pp_cxx_end_template_argument_list (pp); | |
a1281f45 | 556 | } |
73b0fce8 KL |
557 | break; |
558 | ||
8d08fdba | 559 | case TEMPLATE_TYPE_PARM: |
3c1ab1ab | 560 | pp_cxx_cv_qualifier_seq (pp, t); |
cb57504a | 561 | if (template_placeholder_p (t)) |
33f746e5 AO |
562 | { |
563 | t = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t)); | |
564 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); | |
565 | pp_string (pp, "<...auto...>"); | |
566 | } | |
4fea442d | 567 | else if (TYPE_IDENTIFIER (t)) |
3c1ab1ab | 568 | pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t)); |
ec255269 | 569 | else |
0cbd7506 | 570 | pp_cxx_canonical_template_parameter |
3c1ab1ab | 571 | (pp, TEMPLATE_TYPE_PARM_INDEX (t)); |
cb57504a JM |
572 | /* If this is a constrained placeholder, add the requirements. */ |
573 | if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t)) | |
574 | pp_cxx_constrained_type_spec (pp, c); | |
8d08fdba MS |
575 | break; |
576 | ||
8d08fdba MS |
577 | /* This is not always necessary for pointers and such, but doing this |
578 | reduces code size. */ | |
579 | case ARRAY_TYPE: | |
580 | case POINTER_TYPE: | |
581 | case REFERENCE_TYPE: | |
582 | case OFFSET_TYPE: | |
583 | offset_type: | |
584 | case FUNCTION_TYPE: | |
585 | case METHOD_TYPE: | |
9e93bc9d | 586 | { |
3c1ab1ab GDR |
587 | dump_type_prefix (pp, t, flags); |
588 | dump_type_suffix (pp, t, flags); | |
8d08fdba | 589 | break; |
9e93bc9d | 590 | } |
5566b478 | 591 | case TYPENAME_TYPE: |
a4d674fc JM |
592 | if (! (flags & TFF_CHASE_TYPEDEF) |
593 | && DECL_ORIGINAL_TYPE (TYPE_NAME (t))) | |
594 | { | |
3c1ab1ab | 595 | dump_decl (pp, TYPE_NAME (t), TFF_PLAIN_IDENTIFIER); |
a4d674fc JM |
596 | break; |
597 | } | |
3c1ab1ab GDR |
598 | pp_cxx_cv_qualifier_seq (pp, t); |
599 | pp_cxx_ws_string (pp, | |
c8094d83 | 600 | TYPENAME_IS_ENUM_P (t) ? "enum" |
fc6a28d7 MM |
601 | : TYPENAME_IS_CLASS_P (t) ? "class" |
602 | : "typename"); | |
3c1ab1ab | 603 | dump_typename (pp, t, flags); |
5566b478 MS |
604 | break; |
605 | ||
b8c6534b | 606 | case UNBOUND_CLASS_TEMPLATE: |
e1faa105 JM |
607 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
608 | { | |
3c1ab1ab GDR |
609 | dump_type (pp, TYPE_CONTEXT (t), flags); |
610 | pp_cxx_colon_colon (pp); | |
e1faa105 | 611 | } |
3c1ab1ab | 612 | pp_cxx_ws_string (pp, "template"); |
cc27b5cd | 613 | dump_type (pp, TYPE_IDENTIFIER (t), flags); |
b8c6534b KL |
614 | break; |
615 | ||
b894fc05 | 616 | case TYPEOF_TYPE: |
3c1ab1ab GDR |
617 | pp_cxx_ws_string (pp, "__typeof__"); |
618 | pp_cxx_whitespace (pp); | |
619 | pp_cxx_left_paren (pp); | |
620 | dump_expr (pp, TYPEOF_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
621 | pp_cxx_right_paren (pp); | |
b894fc05 JM |
622 | break; |
623 | ||
a0d260fc | 624 | case UNDERLYING_TYPE: |
3c1ab1ab GDR |
625 | pp_cxx_ws_string (pp, "__underlying_type"); |
626 | pp_cxx_whitespace (pp); | |
627 | pp_cxx_left_paren (pp); | |
628 | dump_expr (pp, UNDERLYING_TYPE_TYPE (t), flags & ~TFF_EXPR_IN_PARENS); | |
629 | pp_cxx_right_paren (pp); | |
a0d260fc PC |
630 | break; |
631 | ||
5d80a306 | 632 | case TYPE_PACK_EXPANSION: |
3c1ab1ab GDR |
633 | dump_type (pp, PACK_EXPANSION_PATTERN (t), flags); |
634 | pp_cxx_ws_string (pp, "..."); | |
5d80a306 DG |
635 | break; |
636 | ||
b1d7b1c0 | 637 | case TYPE_ARGUMENT_PACK: |
3c1ab1ab | 638 | dump_template_argument (pp, t, flags); |
b1d7b1c0 DG |
639 | break; |
640 | ||
3ad6a8e1 | 641 | case DECLTYPE_TYPE: |
3c1ab1ab GDR |
642 | pp_cxx_ws_string (pp, "decltype"); |
643 | pp_cxx_whitespace (pp); | |
644 | pp_cxx_left_paren (pp); | |
645 | dump_expr (pp, DECLTYPE_TYPE_EXPR (t), flags & ~TFF_EXPR_IN_PARENS); | |
646 | pp_cxx_right_paren (pp); | |
3ad6a8e1 DG |
647 | break; |
648 | ||
1e85e720 | 649 | case NULLPTR_TYPE: |
3c1ab1ab | 650 | pp_string (pp, "std::nullptr_t"); |
1e85e720 RG |
651 | break; |
652 | ||
8d08fdba | 653 | default: |
3c1ab1ab | 654 | pp_unsupported_tree (pp, t); |
295844f6 | 655 | /* Fall through. */ |
9e93bc9d NS |
656 | |
657 | case ERROR_MARK: | |
3c1ab1ab | 658 | pp_string (pp, M_("<type error>")); |
9e93bc9d | 659 | break; |
8d08fdba MS |
660 | } |
661 | } | |
662 | ||
46e2747c NS |
663 | /* Dump a TYPENAME_TYPE. We need to notice when the context is itself |
664 | a TYPENAME_TYPE. */ | |
665 | ||
666 | static void | |
3c1ab1ab | 667 | dump_typename (cxx_pretty_printer *pp, tree t, int flags) |
46e2747c NS |
668 | { |
669 | tree ctx = TYPE_CONTEXT (t); | |
bb20cc46 | 670 | |
46e2747c | 671 | if (TREE_CODE (ctx) == TYPENAME_TYPE) |
3c1ab1ab | 672 | dump_typename (pp, ctx, flags); |
46e2747c | 673 | else |
3c1ab1ab GDR |
674 | dump_type (pp, ctx, flags & ~TFF_CLASS_KEY_OR_ENUM); |
675 | pp_cxx_colon_colon (pp); | |
676 | dump_decl (pp, TYPENAME_TYPE_FULLNAME (t), flags); | |
46e2747c NS |
677 | } |
678 | ||
9e93bc9d NS |
679 | /* Return the name of the supplied aggregate, or enumeral type. */ |
680 | ||
3cabd8f9 MA |
681 | const char * |
682 | class_key_or_enum_as_string (tree t) | |
8d08fdba | 683 | { |
adf2edec DG |
684 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
685 | { | |
686 | if (SCOPED_ENUM_P (t)) | |
687 | return "enum class"; | |
688 | else | |
689 | return "enum"; | |
690 | } | |
8d08fdba | 691 | else if (TREE_CODE (t) == UNION_TYPE) |
51c184be | 692 | return "union"; |
8d08fdba | 693 | else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t)) |
51c184be | 694 | return "class"; |
8d08fdba | 695 | else |
51c184be MS |
696 | return "struct"; |
697 | } | |
698 | ||
9e93bc9d NS |
699 | /* Print out a class declaration T under the control of FLAGS, |
700 | in the form `class foo'. */ | |
e92cc029 | 701 | |
51c184be | 702 | static void |
3c1ab1ab | 703 | dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags) |
51c184be | 704 | { |
3cabd8f9 | 705 | const char *variety = class_key_or_enum_as_string (t); |
9e93bc9d NS |
706 | int typdef = 0; |
707 | int tmplate = 0; | |
8d08fdba | 708 | |
3c1ab1ab | 709 | pp_cxx_cv_qualifier_seq (pp, t); |
8d08fdba | 710 | |
761f0855 | 711 | if (flags & TFF_CLASS_KEY_OR_ENUM) |
3c1ab1ab | 712 | pp_cxx_ws_string (pp, variety); |
bb20cc46 | 713 | |
0f32c94f | 714 | tree decl = TYPE_NAME (t); |
9e93bc9d | 715 | |
0f32c94f | 716 | if (decl) |
8d08fdba | 717 | { |
0f32c94f | 718 | typdef = (!DECL_ARTIFICIAL (decl) |
28704289 DS |
719 | /* An alias specialization is not considered to be a |
720 | typedef. */ | |
96cbfa7f | 721 | && !alias_template_specialization_p (t, nt_opaque)); |
f6f5e3a1 | 722 | |
abd5730b JM |
723 | if ((typdef |
724 | && ((flags & TFF_CHASE_TYPEDEF) | |
0f32c94f NS |
725 | || (!flag_pretty_templates && DECL_LANG_SPECIFIC (decl) |
726 | && DECL_TEMPLATE_INFO (decl)))) | |
727 | || DECL_SELF_REFERENCE_P (decl)) | |
f6f5e3a1 JM |
728 | { |
729 | t = TYPE_MAIN_VARIANT (t); | |
0f32c94f | 730 | decl = TYPE_NAME (t); |
f6f5e3a1 JM |
731 | typdef = 0; |
732 | } | |
733 | ||
9e93bc9d | 734 | tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE |
0cbd7506 | 735 | && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t) |
f0d60e22 | 736 | && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL |
0cbd7506 | 737 | || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t))); |
a0ad3539 MM |
738 | |
739 | if (! (flags & TFF_UNQUALIFIED_NAME)) | |
0f32c94f | 740 | dump_scope (pp, CP_DECL_CONTEXT (decl), flags | TFF_SCOPE); |
a0ad3539 | 741 | flags &= ~TFF_UNQUALIFIED_NAME; |
9e93bc9d | 742 | if (tmplate) |
0cbd7506 MS |
743 | { |
744 | /* Because the template names are mangled, we have to locate | |
745 | the most general template, and use that name. */ | |
28704289 | 746 | tree tpl = TYPE_TI_TEMPLATE (t); |
0cbd7506 MS |
747 | |
748 | while (DECL_TEMPLATE_INFO (tpl)) | |
749 | tpl = DECL_TI_TEMPLATE (tpl); | |
0f32c94f | 750 | decl = tpl; |
0cbd7506 | 751 | } |
8d08fdba MS |
752 | } |
753 | ||
ca3edeae | 754 | if (LAMBDA_TYPE_P (t)) |
d5f4eddd JM |
755 | { |
756 | /* A lambda's "type" is essentially its signature. */ | |
3c1ab1ab | 757 | pp_string (pp, M_("<lambda")); |
d5f4eddd | 758 | if (lambda_function (t)) |
3c1ab1ab GDR |
759 | dump_parameters (pp, |
760 | FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t)), | |
d5f4eddd | 761 | flags); |
3c1ab1ab | 762 | pp_greater (pp); |
d5f4eddd | 763 | } |
0f32c94f | 764 | else if (!decl || IDENTIFIER_ANON_P (DECL_NAME (decl))) |
ca3edeae NS |
765 | { |
766 | if (flags & TFF_CLASS_KEY_OR_ENUM) | |
767 | pp_string (pp, M_("<unnamed>")); | |
768 | else | |
769 | pp_printf (pp, M_("<unnamed %s>"), variety); | |
770 | } | |
8d08fdba | 771 | else |
0f32c94f | 772 | pp_cxx_tree_identifier (pp, DECL_NAME (decl)); |
ca3edeae | 773 | |
9e93bc9d | 774 | if (tmplate) |
3c1ab1ab | 775 | dump_template_parms (pp, TYPE_TEMPLATE_INFO (t), |
0cbd7506 MS |
776 | !CLASSTYPE_USE_TEMPLATE (t), |
777 | flags & ~TFF_TEMPLATE_HEADER); | |
8d08fdba MS |
778 | } |
779 | ||
780 | /* Dump into the obstack the initial part of the output for a given type. | |
781 | This is necessary when dealing with things like functions returning | |
782 | functions. Examples: | |
783 | ||
784 | return type of `int (* fee ())()': pointer -> function -> int. Both | |
785 | pointer (and reference and offset) and function (and member) types must | |
786 | deal with prefix and suffix. | |
787 | ||
788 | Arrays must also do this for DECL nodes, like int a[], and for things like | |
b9b44fb9 | 789 | int *[]&. */ |
8d08fdba | 790 | |
c8094d83 | 791 | static void |
3c1ab1ab | 792 | dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
793 | { |
794 | if (TYPE_PTRMEMFUNC_P (t)) | |
795 | { | |
796 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
797 | goto offset_type; | |
798 | } | |
bb20cc46 | 799 | |
8d08fdba MS |
800 | switch (TREE_CODE (t)) |
801 | { | |
802 | case POINTER_TYPE: | |
91063b51 | 803 | case REFERENCE_TYPE: |
8d08fdba MS |
804 | { |
805 | tree sub = TREE_TYPE (t); | |
bb20cc46 | 806 | |
3c1ab1ab | 807 | dump_type_prefix (pp, sub, flags); |
0d9c0892 JM |
808 | if (TREE_CODE (sub) == ARRAY_TYPE |
809 | || TREE_CODE (sub) == FUNCTION_TYPE) | |
8d08fdba | 810 | { |
3c1ab1ab GDR |
811 | pp_cxx_whitespace (pp); |
812 | pp_cxx_left_paren (pp); | |
813 | pp_c_attributes_display (pp, TYPE_ATTRIBUTES (sub)); | |
8d08fdba | 814 | } |
50e10fa8 | 815 | if (TYPE_PTR_P (t)) |
3c1ab1ab | 816 | pp_star (pp); |
9f613f06 PC |
817 | else if (TYPE_REF_P (t)) |
818 | { | |
819 | if (TYPE_REF_IS_RVALUE (t)) | |
820 | pp_ampersand_ampersand (pp); | |
821 | else | |
822 | pp_ampersand (pp); | |
823 | } | |
3c1ab1ab GDR |
824 | pp->padding = pp_before; |
825 | pp_cxx_cv_qualifier_seq (pp, t); | |
8d08fdba | 826 | } |
8d08fdba MS |
827 | break; |
828 | ||
829 | case OFFSET_TYPE: | |
830 | offset_type: | |
3c1ab1ab | 831 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
51c184be MS |
832 | if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */ |
833 | { | |
3c1ab1ab | 834 | pp_maybe_space (pp); |
0cbd7506 | 835 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) |
3c1ab1ab GDR |
836 | pp_cxx_left_paren (pp); |
837 | dump_type (pp, TYPE_OFFSET_BASETYPE (t), flags); | |
838 | pp_cxx_colon_colon (pp); | |
51c184be | 839 | } |
3c1ab1ab GDR |
840 | pp_cxx_star (pp); |
841 | pp_cxx_cv_qualifier_seq (pp, t); | |
842 | pp->padding = pp_before; | |
8d08fdba MS |
843 | break; |
844 | ||
0d9c0892 JM |
845 | /* This can be reached without a pointer when dealing with |
846 | templates, e.g. std::is_function. */ | |
8d08fdba | 847 | case FUNCTION_TYPE: |
3c1ab1ab | 848 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
849 | break; |
850 | ||
851 | case METHOD_TYPE: | |
3c1ab1ab GDR |
852 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
853 | pp_maybe_space (pp); | |
854 | pp_cxx_left_paren (pp); | |
855 | dump_aggr_type (pp, TYPE_METHOD_BASETYPE (t), flags); | |
856 | pp_cxx_colon_colon (pp); | |
8d08fdba MS |
857 | break; |
858 | ||
859 | case ARRAY_TYPE: | |
3c1ab1ab | 860 | dump_type_prefix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
861 | break; |
862 | ||
863 | case ENUMERAL_TYPE: | |
8d08fdba MS |
864 | case IDENTIFIER_NODE: |
865 | case INTEGER_TYPE: | |
2986ae00 | 866 | case BOOLEAN_TYPE: |
8d08fdba MS |
867 | case REAL_TYPE: |
868 | case RECORD_TYPE: | |
869 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 870 | case TEMPLATE_TEMPLATE_PARM: |
a1281f45 | 871 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
872 | case TREE_LIST: |
873 | case TYPE_DECL: | |
874 | case TREE_VEC: | |
8d08fdba | 875 | case UNION_TYPE: |
fbfc8363 | 876 | case LANG_TYPE: |
8d08fdba | 877 | case VOID_TYPE: |
1e2d8575 | 878 | case OPAQUE_TYPE: |
5566b478 | 879 | case TYPENAME_TYPE: |
37c46b43 | 880 | case COMPLEX_TYPE: |
c00996a3 | 881 | case VECTOR_TYPE: |
0df4ae96 | 882 | case TYPEOF_TYPE: |
a0d260fc | 883 | case UNDERLYING_TYPE: |
3ad6a8e1 | 884 | case DECLTYPE_TYPE: |
e7de2d6f | 885 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 886 | case FIXED_POINT_TYPE: |
1e85e720 | 887 | case NULLPTR_TYPE: |
3c1ab1ab GDR |
888 | dump_type (pp, t, flags); |
889 | pp->padding = pp_before; | |
8d08fdba | 890 | break; |
bb20cc46 | 891 | |
8d08fdba | 892 | default: |
3c1ab1ab | 893 | pp_unsupported_tree (pp, t); |
99885b3f | 894 | /* fall through. */ |
9e93bc9d | 895 | case ERROR_MARK: |
3c1ab1ab | 896 | pp_string (pp, M_("<typeprefixerror>")); |
9e93bc9d | 897 | break; |
8d08fdba MS |
898 | } |
899 | } | |
900 | ||
9e93bc9d NS |
901 | /* Dump the suffix of type T, under control of FLAGS. This is the part |
902 | which appears after the identifier (or function parms). */ | |
903 | ||
8d08fdba | 904 | static void |
3c1ab1ab | 905 | dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
906 | { |
907 | if (TYPE_PTRMEMFUNC_P (t)) | |
908 | t = TYPE_PTRMEMFUNC_FN_TYPE (t); | |
909 | ||
910 | switch (TREE_CODE (t)) | |
911 | { | |
912 | case POINTER_TYPE: | |
913 | case REFERENCE_TYPE: | |
914 | case OFFSET_TYPE: | |
0d9c0892 JM |
915 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE |
916 | || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) | |
3c1ab1ab | 917 | pp_cxx_right_paren (pp); |
985acf5a PC |
918 | if (TREE_CODE (t) == POINTER_TYPE) |
919 | flags |= TFF_POINTER; | |
3c1ab1ab | 920 | dump_type_suffix (pp, TREE_TYPE (t), flags); |
8d08fdba MS |
921 | break; |
922 | ||
8d08fdba MS |
923 | case FUNCTION_TYPE: |
924 | case METHOD_TYPE: | |
925 | { | |
926 | tree arg; | |
0d9c0892 JM |
927 | if (TREE_CODE (t) == METHOD_TYPE) |
928 | /* Can only be reached through a pointer. */ | |
3c1ab1ab | 929 | pp_cxx_right_paren (pp); |
8d08fdba MS |
930 | arg = TYPE_ARG_TYPES (t); |
931 | if (TREE_CODE (t) == METHOD_TYPE) | |
932 | arg = TREE_CHAIN (arg); | |
933 | ||
4995028c NS |
934 | /* Function pointers don't have default args. Not in standard C++, |
935 | anyway; they may in g++, but we'll just pretend otherwise. */ | |
3c1ab1ab | 936 | dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS); |
4995028c | 937 | |
3c1ab1ab | 938 | pp->padding = pp_before; |
985acf5a PC |
939 | pp_cxx_cv_qualifiers (pp, type_memfn_quals (t), |
940 | TREE_CODE (t) == FUNCTION_TYPE | |
941 | && (flags & TFF_POINTER)); | |
3c1ab1ab | 942 | dump_ref_qualifier (pp, t, flags); |
b8fd7909 JM |
943 | if (tx_safe_fn_type_p (t)) |
944 | pp_cxx_ws_string (pp, "transaction_safe"); | |
3c1ab1ab GDR |
945 | dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags); |
946 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba MS |
947 | break; |
948 | } | |
949 | ||
950 | case ARRAY_TYPE: | |
3c1ab1ab GDR |
951 | pp_maybe_space (pp); |
952 | pp_cxx_left_bracket (pp); | |
05dd97db | 953 | if (tree dtype = TYPE_DOMAIN (t)) |
5156628f | 954 | { |
5e203bf8 | 955 | tree max = TYPE_MAX_VALUE (dtype); |
1be51a3a MS |
956 | /* Zero-length arrays have a null upper bound in C and SIZE_MAX |
957 | in C++. Handle both since the type might be constructed by | |
958 | the middle end and end up here as a result of a warning (see | |
959 | PR c++/97201). */ | |
960 | if (!max || integer_all_onesp (max)) | |
3c1ab1ab | 961 | pp_character (pp, '0'); |
9541ffee | 962 | else if (tree_fits_shwi_p (max)) |
9439e9a1 | 963 | pp_wide_integer (pp, tree_to_shwi (max) + 1); |
5156628f | 964 | else |
785b887e JM |
965 | { |
966 | STRIP_NOPS (max); | |
967 | if (TREE_CODE (max) == SAVE_EXPR) | |
968 | max = TREE_OPERAND (max, 0); | |
969 | if (TREE_CODE (max) == MINUS_EXPR | |
970 | || TREE_CODE (max) == PLUS_EXPR) | |
971 | { | |
972 | max = TREE_OPERAND (max, 0); | |
973 | while (CONVERT_EXPR_P (max)) | |
974 | max = TREE_OPERAND (max, 0); | |
975 | } | |
976 | else | |
977 | max = fold_build2_loc (input_location, | |
978 | PLUS_EXPR, dtype, max, | |
979 | build_int_cst (dtype, 1)); | |
3c1ab1ab | 980 | dump_expr (pp, max, flags & ~TFF_EXPR_IN_PARENS); |
785b887e | 981 | } |
5156628f | 982 | } |
3c1ab1ab GDR |
983 | pp_cxx_right_bracket (pp); |
984 | dump_type_suffix (pp, TREE_TYPE (t), flags); | |
8d08fdba | 985 | break; |
bb20cc46 | 986 | |
8d08fdba | 987 | case ENUMERAL_TYPE: |
8d08fdba MS |
988 | case IDENTIFIER_NODE: |
989 | case INTEGER_TYPE: | |
2986ae00 | 990 | case BOOLEAN_TYPE: |
8d08fdba MS |
991 | case REAL_TYPE: |
992 | case RECORD_TYPE: | |
993 | case TEMPLATE_TYPE_PARM: | |
73b0fce8 | 994 | case TEMPLATE_TEMPLATE_PARM: |
a97d0689 | 995 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
8d08fdba MS |
996 | case TREE_LIST: |
997 | case TYPE_DECL: | |
998 | case TREE_VEC: | |
8d08fdba | 999 | case UNION_TYPE: |
fbfc8363 | 1000 | case LANG_TYPE: |
8d08fdba | 1001 | case VOID_TYPE: |
1e2d8575 | 1002 | case OPAQUE_TYPE: |
5566b478 | 1003 | case TYPENAME_TYPE: |
37c46b43 | 1004 | case COMPLEX_TYPE: |
c00996a3 | 1005 | case VECTOR_TYPE: |
0df4ae96 | 1006 | case TYPEOF_TYPE: |
a0d260fc | 1007 | case UNDERLYING_TYPE: |
3ad6a8e1 | 1008 | case DECLTYPE_TYPE: |
e7de2d6f | 1009 | case TYPE_PACK_EXPANSION: |
1fae3e66 | 1010 | case FIXED_POINT_TYPE: |
1e85e720 | 1011 | case NULLPTR_TYPE: |
8d08fdba MS |
1012 | break; |
1013 | ||
1014 | default: | |
3c1ab1ab | 1015 | pp_unsupported_tree (pp, t); |
9e93bc9d NS |
1016 | case ERROR_MARK: |
1017 | /* Don't mark it here, we should have already done in | |
0cbd7506 | 1018 | dump_type_prefix. */ |
9e93bc9d | 1019 | break; |
8d08fdba MS |
1020 | } |
1021 | } | |
1022 | ||
49c249e1 | 1023 | static void |
3c1ab1ab | 1024 | dump_global_iord (cxx_pretty_printer *pp, tree t) |
8d08fdba | 1025 | { |
99885b3f | 1026 | const char *p = NULL; |
8d08fdba | 1027 | |
92643fea | 1028 | if (DECL_GLOBAL_CTOR_P (t)) |
f41c4af3 | 1029 | p = M_("(static initializers for %s)"); |
92643fea | 1030 | else if (DECL_GLOBAL_DTOR_P (t)) |
f41c4af3 | 1031 | p = M_("(static destructors for %s)"); |
8d08fdba | 1032 | else |
8dc2b103 | 1033 | gcc_unreachable (); |
bb20cc46 | 1034 | |
7c010e27 | 1035 | pp_printf (pp, p, DECL_SOURCE_FILE (t)); |
8d08fdba MS |
1036 | } |
1037 | ||
07389efe | 1038 | static void |
3c1ab1ab | 1039 | dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) |
07389efe | 1040 | { |
4be5c72c JM |
1041 | if (template_parm_object_p (t)) |
1042 | return dump_expr (pp, DECL_INITIAL (t), flags); | |
1043 | ||
761f0855 | 1044 | if (flags & TFF_DECL_SPECIFIERS) |
07389efe | 1045 | { |
91f4fc40 PP |
1046 | if (concept_definition_p (t)) |
1047 | pp_cxx_ws_string (pp, "concept"); | |
1048 | else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t)) | |
1049 | pp_cxx_ws_string (pp, "constexpr"); | |
1050 | ||
1051 | if (!standard_concept_p (t)) | |
1052 | dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME); | |
3c1ab1ab | 1053 | pp_maybe_space (pp); |
07389efe | 1054 | } |
a0ad3539 | 1055 | if (! (flags & TFF_UNQUALIFIED_NAME) |
af88c58f | 1056 | && TREE_CODE (t) != PARM_DECL |
a0ad3539 MM |
1057 | && (!DECL_INITIAL (t) |
1058 | || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)) | |
3c1ab1ab | 1059 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 1060 | flags &= ~TFF_UNQUALIFIED_NAME; |
a022041e DG |
1061 | if ((flags & TFF_DECL_SPECIFIERS) |
1062 | && DECL_TEMPLATE_PARM_P (t) | |
1063 | && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t))) | |
3c1ab1ab | 1064 | pp_string (pp, "..."); |
07389efe | 1065 | if (DECL_NAME (t)) |
af580858 | 1066 | { |
76089b28 | 1067 | if (TREE_CODE (t) == FIELD_DECL && DECL_NORMAL_CAPTURE_P (t)) |
af580858 | 1068 | { |
3c1ab1ab GDR |
1069 | pp_less (pp); |
1070 | pp_string (pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2); | |
1071 | pp_string (pp, " capture>"); | |
af580858 JM |
1072 | } |
1073 | else | |
3c1ab1ab | 1074 | dump_decl (pp, DECL_NAME (t), flags); |
af580858 | 1075 | } |
5726acd7 JM |
1076 | else if (DECL_DECOMPOSITION_P (t)) |
1077 | pp_string (pp, M_("<structured bindings>")); | |
07389efe | 1078 | else |
3c1ab1ab | 1079 | pp_string (pp, M_("<anonymous>")); |
761f0855 | 1080 | if (flags & TFF_DECL_SPECIFIERS) |
3c1ab1ab | 1081 | dump_type_suffix (pp, type, flags); |
07389efe MM |
1082 | } |
1083 | ||
fd338b13 JM |
1084 | /* Print an IDENTIFIER_NODE that is the name of a declaration. */ |
1085 | ||
1086 | static void | |
1087 | dump_decl_name (cxx_pretty_printer *pp, tree t, int flags) | |
1088 | { | |
1089 | /* These special cases are duplicated here so that other functions | |
1090 | can feed identifiers to error and get them demangled properly. */ | |
84c0088f | 1091 | if (IDENTIFIER_CONV_OP_P (t)) |
fd338b13 JM |
1092 | { |
1093 | pp_cxx_ws_string (pp, "operator"); | |
1094 | /* Not exactly IDENTIFIER_TYPE_VALUE. */ | |
1095 | dump_type (pp, TREE_TYPE (t), flags); | |
1096 | return; | |
1097 | } | |
1098 | if (dguide_name_p (t)) | |
1099 | { | |
1100 | dump_decl (pp, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t)), | |
a56c0ac0 | 1101 | TFF_UNQUALIFIED_NAME); |
fd338b13 JM |
1102 | return; |
1103 | } | |
1104 | ||
1105 | const char *str = IDENTIFIER_POINTER (t); | |
13686ece | 1106 | if (!strncmp (str, "_ZGR", 4)) |
fd338b13 JM |
1107 | { |
1108 | pp_cxx_ws_string (pp, "<temporary>"); | |
1109 | return; | |
1110 | } | |
1111 | ||
1112 | pp_cxx_tree_identifier (pp, t); | |
1113 | } | |
1114 | ||
9e93bc9d NS |
1115 | /* Dump a human readable string for the decl T under control of FLAGS. */ |
1116 | ||
8d08fdba | 1117 | static void |
3c1ab1ab | 1118 | dump_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1119 | { |
1120 | if (t == NULL_TREE) | |
1121 | return; | |
1122 | ||
be8cf3b5 NP |
1123 | /* If doing Objective-C++, give Objective-C a chance to demangle |
1124 | Objective-C method names. */ | |
1125 | if (c_dialect_objc ()) | |
1126 | { | |
1127 | const char *demangled = objc_maybe_printable_name (t, flags); | |
1128 | if (demangled) | |
1129 | { | |
3c1ab1ab | 1130 | pp_string (pp, demangled); |
be8cf3b5 NP |
1131 | return; |
1132 | } | |
1133 | } | |
1134 | ||
8d08fdba MS |
1135 | switch (TREE_CODE (t)) |
1136 | { | |
7177d104 | 1137 | case TYPE_DECL: |
b54a07e8 | 1138 | /* Don't say 'typedef class A' */ |
7c8b00f9 | 1139 | if (DECL_ARTIFICIAL (t) && !DECL_SELF_REFERENCE_P (t)) |
b54a07e8 NS |
1140 | { |
1141 | if ((flags & TFF_DECL_SPECIFIERS) | |
1142 | && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM) | |
a022041e DG |
1143 | { |
1144 | /* Say `class T' not just `T'. */ | |
3c1ab1ab | 1145 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1146 | |
1147 | /* Emit the `...' for a parameter pack. */ | |
1148 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1149 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1150 | } |
c8094d83 | 1151 | |
3c1ab1ab | 1152 | dump_type (pp, TREE_TYPE (t), flags); |
b54a07e8 NS |
1153 | break; |
1154 | } | |
28704289 DS |
1155 | if (TYPE_DECL_ALIAS_P (t) |
1156 | && (flags & TFF_DECL_SPECIFIERS | |
1157 | || flags & TFF_CLASS_KEY_OR_ENUM)) | |
1158 | { | |
3c1ab1ab GDR |
1159 | pp_cxx_ws_string (pp, "using"); |
1160 | dump_decl (pp, DECL_NAME (t), flags); | |
1161 | pp_cxx_whitespace (pp); | |
1162 | pp_cxx_ws_string (pp, "="); | |
1163 | pp_cxx_whitespace (pp); | |
e7555e42 JM |
1164 | dump_type (pp, (DECL_ORIGINAL_TYPE (t) |
1165 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t)), | |
1166 | flags); | |
28704289 DS |
1167 | break; |
1168 | } | |
5a080ad7 JM |
1169 | if ((flags & TFF_DECL_SPECIFIERS) |
1170 | && !DECL_SELF_REFERENCE_P (t)) | |
3c1ab1ab GDR |
1171 | pp_cxx_ws_string (pp, "typedef"); |
1172 | dump_simple_decl (pp, t, DECL_ORIGINAL_TYPE (t) | |
9e93bc9d | 1173 | ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), |
0cbd7506 | 1174 | flags); |
7177d104 | 1175 | break; |
bb20cc46 | 1176 | |
8d08fdba | 1177 | case VAR_DECL: |
b7484fbe | 1178 | if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) |
8d08fdba | 1179 | { |
3c1ab1ab | 1180 | pp_string (pp, M_("vtable for ")); |
50bc768d | 1181 | gcc_assert (TYPE_P (DECL_CONTEXT (t))); |
3c1ab1ab | 1182 | dump_type (pp, DECL_CONTEXT (t), flags); |
8d08fdba MS |
1183 | break; |
1184 | } | |
191816a3 | 1185 | /* Fall through. */ |
8d08fdba MS |
1186 | case FIELD_DECL: |
1187 | case PARM_DECL: | |
3c1ab1ab | 1188 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
aed67566 JM |
1189 | |
1190 | /* Handle variable template specializations. */ | |
56a6f1d3 | 1191 | if (VAR_P (t) |
aed67566 JM |
1192 | && DECL_LANG_SPECIFIC (t) |
1193 | && DECL_TEMPLATE_INFO (t) | |
1194 | && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))) | |
1195 | { | |
1196 | pp_cxx_begin_template_argument_list (pp); | |
1197 | tree args = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t)); | |
1198 | dump_template_argument_list (pp, args, flags); | |
1199 | pp_cxx_end_template_argument_list (pp); | |
1200 | } | |
8d08fdba MS |
1201 | break; |
1202 | ||
f6a898ba | 1203 | case RESULT_DECL: |
3c1ab1ab GDR |
1204 | pp_string (pp, M_("<return value> ")); |
1205 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); | |
f6a898ba AO |
1206 | break; |
1207 | ||
a9aedbc2 | 1208 | case NAMESPACE_DECL: |
a2a9e21c | 1209 | if (flags & TFF_DECL_SPECIFIERS) |
8f0e4d72 | 1210 | pp->declaration (t); |
0c8feefe | 1211 | else |
0cbd7506 | 1212 | { |
a0ad3539 | 1213 | if (! (flags & TFF_UNQUALIFIED_NAME)) |
3c1ab1ab | 1214 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
a0ad3539 | 1215 | flags &= ~TFF_UNQUALIFIED_NAME; |
0cbd7506 | 1216 | if (DECL_NAME (t) == NULL_TREE) |
7496cd5b | 1217 | { |
3c1ab1ab GDR |
1218 | if (!(pp->flags & pp_c_flag_gnu_v3)) |
1219 | pp_cxx_ws_string (pp, M_("{anonymous}")); | |
7496cd5b | 1220 | else |
3c1ab1ab | 1221 | pp_cxx_ws_string (pp, M_("(anonymous namespace)")); |
7496cd5b | 1222 | } |
0cbd7506 | 1223 | else |
3c1ab1ab | 1224 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); |
0cbd7506 | 1225 | } |
a9aedbc2 MS |
1226 | break; |
1227 | ||
3e3f722c | 1228 | case SCOPE_REF: |
3c1ab1ab | 1229 | dump_type (pp, TREE_OPERAND (t, 0), flags); |
5256a7f5 | 1230 | pp_cxx_colon_colon (pp); |
3c1ab1ab | 1231 | dump_decl (pp, TREE_OPERAND (t, 1), TFF_UNQUALIFIED_NAME); |
bb20cc46 | 1232 | break; |
3e3f722c | 1233 | |
8d08fdba | 1234 | case ARRAY_REF: |
3c1ab1ab GDR |
1235 | dump_decl (pp, TREE_OPERAND (t, 0), flags); |
1236 | pp_cxx_left_bracket (pp); | |
1237 | dump_decl (pp, TREE_OPERAND (t, 1), flags); | |
1238 | pp_cxx_right_bracket (pp); | |
8d08fdba MS |
1239 | break; |
1240 | ||
9e93bc9d | 1241 | /* So that we can do dump_decl on an aggr type. */ |
8d08fdba MS |
1242 | case RECORD_TYPE: |
1243 | case UNION_TYPE: | |
1244 | case ENUMERAL_TYPE: | |
3c1ab1ab | 1245 | dump_type (pp, t, flags); |
8d08fdba MS |
1246 | break; |
1247 | ||
814ae570 | 1248 | case BIT_NOT_EXPR: |
82911f36 | 1249 | /* This is a pseudo destructor call which has not been folded into |
0cbd7506 | 1250 | a PSEUDO_DTOR_EXPR yet. */ |
3c1ab1ab GDR |
1251 | pp_cxx_complement (pp); |
1252 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
814ae570 GB |
1253 | break; |
1254 | ||
8d08fdba | 1255 | case TYPE_EXPR: |
8dc2b103 | 1256 | gcc_unreachable (); |
8d08fdba MS |
1257 | break; |
1258 | ||
8d08fdba | 1259 | case IDENTIFIER_NODE: |
fd338b13 | 1260 | dump_decl_name (pp, t, flags); |
8d08fdba MS |
1261 | break; |
1262 | ||
8f032717 | 1263 | case OVERLOAD: |
6f2f4050 | 1264 | if (!OVL_SINGLE_P (t)) |
65a5559b | 1265 | { |
5256a7f5 | 1266 | tree ctx = ovl_scope (t); |
6f2f4050 | 1267 | if (ctx != global_namespace) |
65a5559b | 1268 | { |
6f2f4050 NS |
1269 | if (TYPE_P (ctx)) |
1270 | dump_type (pp, ctx, flags); | |
1271 | else | |
1272 | dump_decl (pp, ctx, flags); | |
3c1ab1ab | 1273 | pp_cxx_colon_colon (pp); |
65a5559b | 1274 | } |
5256a7f5 | 1275 | dump_decl (pp, OVL_NAME (t), flags); |
65a5559b MM |
1276 | break; |
1277 | } | |
c8094d83 | 1278 | |
65a5559b MM |
1279 | /* If there's only one function, just treat it like an ordinary |
1280 | FUNCTION_DECL. */ | |
848bf88d | 1281 | t = OVL_FIRST (t); |
8f032717 MM |
1282 | /* Fall through. */ |
1283 | ||
8d08fdba | 1284 | case FUNCTION_DECL: |
2d0db225 | 1285 | if (! DECL_LANG_SPECIFIC (t)) |
8aa1cce6 | 1286 | { |
716c5ace MJ |
1287 | if (DECL_ABSTRACT_ORIGIN (t) |
1288 | && DECL_ABSTRACT_ORIGIN (t) != t) | |
8aa1cce6 RB |
1289 | dump_decl (pp, DECL_ABSTRACT_ORIGIN (t), flags); |
1290 | else | |
716c5ace | 1291 | dump_function_name (pp, t, flags); |
8aa1cce6 | 1292 | } |
2d0db225 | 1293 | else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) |
3c1ab1ab | 1294 | dump_global_iord (pp, t); |
8d08fdba | 1295 | else |
3c1ab1ab | 1296 | dump_function_decl (pp, t, flags); |
8d08fdba MS |
1297 | break; |
1298 | ||
1299 | case TEMPLATE_DECL: | |
3c1ab1ab | 1300 | dump_template_decl (pp, t, flags); |
8d08fdba MS |
1301 | break; |
1302 | ||
cb57504a | 1303 | case CONCEPT_DECL: |
91f4fc40 | 1304 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
cb57504a JM |
1305 | break; |
1306 | ||
1307 | case WILDCARD_DECL: | |
1308 | pp_string (pp, "<wildcard>"); | |
1309 | break; | |
1310 | ||
74cd8397 JM |
1311 | case TEMPLATE_ID_EXPR: |
1312 | { | |
aa36c081 | 1313 | tree name = TREE_OPERAND (t, 0); |
6c1e7aa9 | 1314 | tree args = TREE_OPERAND (t, 1); |
c8094d83 | 1315 | |
848bf88d NS |
1316 | if (!identifier_p (name)) |
1317 | name = OVL_NAME (name); | |
3c1ab1ab GDR |
1318 | dump_decl (pp, name, flags); |
1319 | pp_cxx_begin_template_argument_list (pp); | |
6c1e7aa9 | 1320 | if (args == error_mark_node) |
3c1ab1ab | 1321 | pp_string (pp, M_("<template arguments error>")); |
6c1e7aa9 | 1322 | else if (args) |
4757fa7f JM |
1323 | dump_template_argument_list |
1324 | (pp, args, flags|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
3c1ab1ab | 1325 | pp_cxx_end_template_argument_list (pp); |
74cd8397 JM |
1326 | } |
1327 | break; | |
1328 | ||
8d08fdba | 1329 | case LABEL_DECL: |
3c1ab1ab | 1330 | pp_cxx_tree_identifier (pp, DECL_NAME (t)); |
8d08fdba MS |
1331 | break; |
1332 | ||
1333 | case CONST_DECL: | |
6467930b | 1334 | if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) |
03555413 | 1335 | || (DECL_INITIAL (t) && |
f84b4be9 | 1336 | TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX)) |
3c1ab1ab | 1337 | dump_simple_decl (pp, t, TREE_TYPE (t), flags); |
224c649b | 1338 | else if (DECL_NAME (t)) |
3c1ab1ab | 1339 | dump_decl (pp, DECL_NAME (t), flags); |
03555413 | 1340 | else if (DECL_INITIAL (t)) |
3c1ab1ab | 1341 | dump_expr (pp, DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS); |
03555413 | 1342 | else |
3c1ab1ab | 1343 | pp_string (pp, M_("<enumerator>")); |
8d08fdba MS |
1344 | break; |
1345 | ||
cffa8729 | 1346 | case USING_DECL: |
f4da28a0 JM |
1347 | { |
1348 | pp_cxx_ws_string (pp, "using"); | |
1349 | tree scope = USING_DECL_SCOPE (t); | |
1350 | bool variadic = false; | |
1351 | if (PACK_EXPANSION_P (scope)) | |
1352 | { | |
1353 | scope = PACK_EXPANSION_PATTERN (scope); | |
1354 | variadic = true; | |
1355 | } | |
1356 | dump_type (pp, scope, flags); | |
1357 | pp_cxx_colon_colon (pp); | |
1358 | dump_decl (pp, DECL_NAME (t), flags); | |
1359 | if (variadic) | |
1360 | pp_cxx_ws_string (pp, "..."); | |
1361 | } | |
cffa8729 MS |
1362 | break; |
1363 | ||
55a3debe | 1364 | case STATIC_ASSERT: |
8f0e4d72 | 1365 | pp->declaration (t); |
55a3debe DG |
1366 | break; |
1367 | ||
50ad9642 | 1368 | case BASELINK: |
3c1ab1ab | 1369 | dump_decl (pp, BASELINK_FUNCTIONS (t), flags); |
50ad9642 MM |
1370 | break; |
1371 | ||
d17811fd | 1372 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 1373 | dump_expr (pp, t, flags); |
d17811fd MM |
1374 | break; |
1375 | ||
bf3e8283 GDR |
1376 | case TEMPLATE_TYPE_PARM: |
1377 | if (flags & TFF_DECL_SPECIFIERS) | |
8f0e4d72 | 1378 | pp->declaration (t); |
bf3e8283 | 1379 | else |
20059c8b | 1380 | pp->type_id (t); |
bf3e8283 GDR |
1381 | break; |
1382 | ||
2658bdae | 1383 | case UNBOUND_CLASS_TEMPLATE: |
930a1e63 | 1384 | case TYPE_PACK_EXPANSION: |
06be4f56 | 1385 | case TREE_BINFO: |
3c1ab1ab | 1386 | dump_type (pp, t, flags); |
2658bdae PC |
1387 | break; |
1388 | ||
8d08fdba | 1389 | default: |
3c1ab1ab | 1390 | pp_unsupported_tree (pp, t); |
295844f6 | 1391 | /* Fall through. */ |
9e93bc9d NS |
1392 | |
1393 | case ERROR_MARK: | |
3c1ab1ab | 1394 | pp_string (pp, M_("<declaration error>")); |
9e93bc9d NS |
1395 | break; |
1396 | } | |
1397 | } | |
1398 | ||
1399 | /* Dump a template declaration T under control of FLAGS. This means the | |
1400 | 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */ | |
1401 | ||
1402 | static void | |
3c1ab1ab | 1403 | dump_template_decl (cxx_pretty_printer *pp, tree t, int flags) |
9e93bc9d | 1404 | { |
b5ac18ea MM |
1405 | tree orig_parms = DECL_TEMPLATE_PARMS (t); |
1406 | tree parms; | |
bb20cc46 AJ |
1407 | int i; |
1408 | ||
761f0855 | 1409 | if (flags & TFF_TEMPLATE_HEADER) |
9e93bc9d | 1410 | { |
bb20cc46 | 1411 | for (parms = orig_parms = nreverse (orig_parms); |
0cbd7506 MS |
1412 | parms; |
1413 | parms = TREE_CHAIN (parms)) | |
1414 | { | |
b5ac18ea | 1415 | tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms); |
0cbd7506 | 1416 | int len = TREE_VEC_LENGTH (inner_parms); |
bb20cc46 | 1417 | |
c5540945 PP |
1418 | if (len == 0) |
1419 | { | |
1420 | /* Skip over the dummy template levels of a template template | |
1421 | parm. */ | |
1422 | gcc_assert (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TEMPLATE_PARM); | |
1423 | continue; | |
1424 | } | |
1425 | ||
3c1ab1ab GDR |
1426 | pp_cxx_ws_string (pp, "template"); |
1427 | pp_cxx_begin_template_argument_list (pp); | |
38066e83 KL |
1428 | |
1429 | /* If we've shown the template prefix, we'd better show the | |
1430 | parameters' and decl's type too. */ | |
1431 | flags |= TFF_DECL_SPECIFIERS; | |
1432 | ||
0cbd7506 MS |
1433 | for (i = 0; i < len; i++) |
1434 | { | |
1435 | if (i) | |
3c1ab1ab GDR |
1436 | pp_separate_with_comma (pp); |
1437 | dump_template_parameter (pp, TREE_VEC_ELT (inner_parms, i), | |
1438 | flags); | |
0cbd7506 | 1439 | } |
3c1ab1ab GDR |
1440 | pp_cxx_end_template_argument_list (pp); |
1441 | pp_cxx_whitespace (pp); | |
0cbd7506 | 1442 | } |
b5ac18ea | 1443 | nreverse(orig_parms); |
38066e83 KL |
1444 | |
1445 | if (DECL_TEMPLATE_TEMPLATE_PARM_P (t)) | |
a022041e DG |
1446 | { |
1447 | /* Say `template<arg> class TT' not just `template<arg> TT'. */ | |
3c1ab1ab | 1448 | pp_cxx_ws_string (pp, "class"); |
a022041e DG |
1449 | |
1450 | /* If this is a parameter pack, print the ellipsis. */ | |
1451 | if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t))) | |
3c1ab1ab | 1452 | pp_cxx_ws_string (pp, "..."); |
a022041e | 1453 | } |
f078dc7d AS |
1454 | |
1455 | /* Only print the requirements if we're also printing | |
1456 | the template header. */ | |
1457 | if (flag_concepts) | |
1458 | if (tree ci = get_constraints (t)) | |
1459 | if (check_constraint_info (ci)) | |
1460 | if (tree reqs = CI_TEMPLATE_REQS (ci)) | |
1461 | { | |
1462 | pp_cxx_requires_clause (pp, reqs); | |
1463 | pp_cxx_whitespace (pp); | |
1464 | } | |
9e93bc9d | 1465 | } |
38066e83 | 1466 | |
971e17ff | 1467 | |
28704289 | 1468 | if (DECL_CLASS_TEMPLATE_P (t)) |
3c1ab1ab | 1469 | dump_type (pp, TREE_TYPE (t), |
0cbd7506 MS |
1470 | ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1471 | | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0))); | |
b55276c8 | 1472 | else if (DECL_TEMPLATE_RESULT (t) |
5a6ccc94 | 1473 | && (VAR_P (DECL_TEMPLATE_RESULT (t)) |
28704289 | 1474 | /* Alias template. */ |
cb57504a JM |
1475 | || DECL_TYPE_TEMPLATE_P (t) |
1476 | /* Concept definition. &*/ | |
1477 | || TREE_CODE (DECL_TEMPLATE_RESULT (t)) == CONCEPT_DECL)) | |
3c1ab1ab | 1478 | dump_decl (pp, DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME); |
9e93bc9d | 1479 | else |
9e93bc9d | 1480 | { |
8dc2b103 NS |
1481 | gcc_assert (TREE_TYPE (t)); |
1482 | switch (NEXT_CODE (t)) | |
1483 | { | |
1484 | case METHOD_TYPE: | |
1485 | case FUNCTION_TYPE: | |
3c1ab1ab | 1486 | dump_function_decl (pp, t, flags | TFF_TEMPLATE_NAME); |
8dc2b103 NS |
1487 | break; |
1488 | default: | |
1489 | /* This case can occur with some invalid code. */ | |
3c1ab1ab | 1490 | dump_type (pp, TREE_TYPE (t), |
8dc2b103 NS |
1491 | (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME |
1492 | | (flags & TFF_DECL_SPECIFIERS | |
1493 | ? TFF_CLASS_KEY_OR_ENUM : 0)); | |
1494 | } | |
8d08fdba MS |
1495 | } |
1496 | } | |
1497 | ||
d5c8be27 | 1498 | /* find_typenames looks through the type of the function template T |
9771b263 | 1499 | and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs |
7cb4dfec | 1500 | it finds. */ |
d5c8be27 JM |
1501 | |
1502 | struct find_typenames_t | |
1503 | { | |
6e2830c3 | 1504 | hash_set<tree> *p_set; |
9771b263 | 1505 | vec<tree, va_gc> *typenames; |
d5c8be27 JM |
1506 | }; |
1507 | ||
1508 | static tree | |
ff9b4073 | 1509 | find_typenames_r (tree *tp, int *walk_subtrees, void *data) |
d5c8be27 JM |
1510 | { |
1511 | struct find_typenames_t *d = (struct find_typenames_t *)data; | |
a4d674fc JM |
1512 | tree mv = NULL_TREE; |
1513 | ||
1514 | if (TYPE_P (*tp) && is_typedef_decl (TYPE_NAME (*tp))) | |
1515 | /* Add the type of the typedef without any additional cv-quals. */ | |
1516 | mv = TREE_TYPE (TYPE_NAME (*tp)); | |
7cb4dfec JM |
1517 | else if (TREE_CODE (*tp) == TYPENAME_TYPE |
1518 | || TREE_CODE (*tp) == DECLTYPE_TYPE) | |
a4d674fc JM |
1519 | /* Add the typename without any cv-qualifiers. */ |
1520 | mv = TYPE_MAIN_VARIANT (*tp); | |
1521 | ||
e6875743 | 1522 | if (PACK_EXPANSION_P (*tp)) |
ff9b4073 JM |
1523 | { |
1524 | /* Don't mess with parameter packs since we don't remember | |
1525 | the pack expansion context for a particular typename. */ | |
1526 | *walk_subtrees = false; | |
1527 | return NULL_TREE; | |
1528 | } | |
1529 | ||
6e2830c3 | 1530 | if (mv && (mv == *tp || !d->p_set->add (mv))) |
9771b263 | 1531 | vec_safe_push (d->typenames, mv); |
d5c8be27 | 1532 | |
d5c8be27 JM |
1533 | return NULL_TREE; |
1534 | } | |
1535 | ||
9771b263 | 1536 | static vec<tree, va_gc> * |
d5c8be27 JM |
1537 | find_typenames (tree t) |
1538 | { | |
1539 | struct find_typenames_t ft; | |
6e2830c3 | 1540 | ft.p_set = new hash_set<tree>; |
d5c8be27 JM |
1541 | ft.typenames = NULL; |
1542 | cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)), | |
1543 | find_typenames_r, &ft, ft.p_set); | |
6e2830c3 | 1544 | delete ft.p_set; |
d5c8be27 JM |
1545 | return ft.typenames; |
1546 | } | |
1547 | ||
753c4989 AB |
1548 | /* Output the "[with ...]" clause for a template instantiation T iff |
1549 | TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if | |
1550 | formatting a deduction/substitution diagnostic rather than an | |
1551 | instantiation. */ | |
1552 | ||
1553 | static void | |
1554 | dump_substitution (cxx_pretty_printer *pp, | |
1555 | tree t, tree template_parms, tree template_args, | |
1556 | int flags) | |
1557 | { | |
1558 | if (template_parms != NULL_TREE && template_args != NULL_TREE | |
1559 | && !(flags & TFF_NO_TEMPLATE_BINDINGS)) | |
1560 | { | |
1561 | vec<tree, va_gc> *typenames = t ? find_typenames (t) : NULL; | |
1562 | pp_cxx_whitespace (pp); | |
1563 | pp_cxx_left_bracket (pp); | |
1564 | pp->translate_string ("with"); | |
1565 | pp_cxx_whitespace (pp); | |
1566 | dump_template_bindings (pp, template_parms, template_args, typenames); | |
1567 | pp_cxx_right_bracket (pp); | |
1568 | } | |
1569 | } | |
1570 | ||
1571 | /* Dump the lambda function FN including its 'mutable' qualifier and any | |
1572 | template bindings. */ | |
1573 | ||
1574 | static void | |
1575 | dump_lambda_function (cxx_pretty_printer *pp, | |
1576 | tree fn, tree template_parms, tree template_args, | |
1577 | int flags) | |
1578 | { | |
1579 | /* A lambda's signature is essentially its "type". */ | |
1580 | dump_type (pp, DECL_CONTEXT (fn), flags); | |
1581 | if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST)) | |
1582 | { | |
1583 | pp->padding = pp_before; | |
1584 | pp_c_ws_string (pp, "mutable"); | |
1585 | } | |
1586 | dump_substitution (pp, fn, template_parms, template_args, flags); | |
1587 | } | |
1588 | ||
4995028c | 1589 | /* Pretty print a function decl. There are several ways we want to print a |
761f0855 | 1590 | function declaration. The TFF_ bits in FLAGS tells us how to behave. |
33bd39a2 | 1591 | As error can only apply the '#' flag once to give 0 and 1 for V, there |
c6002625 | 1592 | is %D which doesn't print the throw specs, and %F which does. */ |
8d08fdba MS |
1593 | |
1594 | static void | |
3c1ab1ab | 1595 | dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 1596 | { |
98c1c668 JM |
1597 | tree fntype; |
1598 | tree parmtypes; | |
8d08fdba | 1599 | tree cname = NULL_TREE; |
612c671a GDR |
1600 | tree template_args = NULL_TREE; |
1601 | tree template_parms = NULL_TREE; | |
761f0855 | 1602 | int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS; |
a0ad3539 | 1603 | int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME); |
4d4e036d | 1604 | tree exceptions; |
c561b091 | 1605 | bool constexpr_p; |
420db574 | 1606 | tree ret = NULL_TREE; |
d5f4eddd | 1607 | |
ee38ecd4 | 1608 | flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME); |
98c1c668 JM |
1609 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1610 | t = DECL_TEMPLATE_RESULT (t); | |
1611 | ||
4d4e036d PC |
1612 | /* Save the exceptions, in case t is a specialization and we are |
1613 | emitting an error about incompatible specifications. */ | |
1614 | exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t)); | |
1615 | ||
c561b091 PC |
1616 | /* Likewise for the constexpr specifier, in case t is a specialization. */ |
1617 | constexpr_p = DECL_DECLARED_CONSTEXPR_P (t); | |
1618 | ||
612c671a | 1619 | /* Pretty print template instantiations only. */ |
6ea2bd47 | 1620 | if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t) |
98e5a19a | 1621 | && !(flags & TFF_NO_TEMPLATE_BINDINGS) |
6ea2bd47 | 1622 | && flag_pretty_templates) |
612c671a | 1623 | { |
f9a7ae04 MM |
1624 | tree tmpl; |
1625 | ||
612c671a | 1626 | template_args = DECL_TI_ARGS (t); |
f9a7ae04 MM |
1627 | tmpl = most_general_template (t); |
1628 | if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL) | |
1629 | { | |
1630 | template_parms = DECL_TEMPLATE_PARMS (tmpl); | |
1631 | t = tmpl; | |
1632 | } | |
612c671a GDR |
1633 | } |
1634 | ||
753c4989 AB |
1635 | if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) |
1636 | return dump_lambda_function (pp, t, template_parms, template_args, flags); | |
1637 | ||
98c1c668 | 1638 | fntype = TREE_TYPE (t); |
e0fff4b3 | 1639 | parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t); |
98c1c668 | 1640 | |
2642b9bf | 1641 | if (DECL_CLASS_SCOPE_P (t)) |
4f1c5b7d | 1642 | cname = DECL_CONTEXT (t); |
f4f206f4 | 1643 | /* This is for partially instantiated template methods. */ |
8d08fdba MS |
1644 | else if (TREE_CODE (fntype) == METHOD_TYPE) |
1645 | cname = TREE_TYPE (TREE_VALUE (parmtypes)); | |
1646 | ||
2842beb6 JM |
1647 | if (flags & TFF_DECL_SPECIFIERS) |
1648 | { | |
1649 | if (DECL_STATIC_FUNCTION_P (t)) | |
3c1ab1ab | 1650 | pp_cxx_ws_string (pp, "static"); |
2842beb6 | 1651 | else if (DECL_VIRTUAL_P (t)) |
3c1ab1ab | 1652 | pp_cxx_ws_string (pp, "virtual"); |
2842beb6 | 1653 | |
c561b091 | 1654 | if (constexpr_p) |
f078dc7d AS |
1655 | { |
1656 | if (DECL_DECLARED_CONCEPT_P (t)) | |
1657 | pp_cxx_ws_string (pp, "concept"); | |
f968ef9b JJ |
1658 | else if (DECL_IMMEDIATE_FUNCTION_P (t)) |
1659 | pp_cxx_ws_string (pp, "consteval"); | |
1660 | else | |
f078dc7d AS |
1661 | pp_cxx_ws_string (pp, "constexpr"); |
1662 | } | |
2842beb6 | 1663 | } |
bb20cc46 | 1664 | |
9e93bc9d NS |
1665 | /* Print the return type? */ |
1666 | if (show_return) | |
76b294d4 JM |
1667 | show_return = (!DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t) |
1668 | && !DECL_DESTRUCTOR_P (t) && !deduction_guide_p (t)); | |
9e93bc9d | 1669 | if (show_return) |
79d8a272 | 1670 | { |
420db574 | 1671 | ret = fndecl_declared_return_type (t); |
3c1ab1ab | 1672 | dump_type_prefix (pp, ret, flags); |
79d8a272 | 1673 | } |
8d08fdba | 1674 | |
61cd552e | 1675 | /* Print the function name. */ |
a0ad3539 MM |
1676 | if (!do_outer_scope) |
1677 | /* Nothing. */; | |
1678 | else if (cname) | |
8d08fdba | 1679 | { |
3c1ab1ab GDR |
1680 | dump_type (pp, cname, flags); |
1681 | pp_cxx_colon_colon (pp); | |
2642b9bf | 1682 | } |
9e93bc9d | 1683 | else |
3c1ab1ab | 1684 | dump_scope (pp, CP_DECL_CONTEXT (t), flags); |
8d08fdba | 1685 | |
3c1ab1ab | 1686 | dump_function_name (pp, t, flags); |
bb20cc46 | 1687 | |
303357a7 | 1688 | if (!(flags & TFF_NO_FUNCTION_ARGUMENTS)) |
ad50e811 | 1689 | { |
3c1ab1ab | 1690 | dump_parameters (pp, parmtypes, flags); |
bb20cc46 | 1691 | |
ad50e811 | 1692 | if (TREE_CODE (fntype) == METHOD_TYPE) |
0cbd7506 | 1693 | { |
3c1ab1ab GDR |
1694 | pp->padding = pp_before; |
1695 | pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (fntype)); | |
1696 | dump_ref_qualifier (pp, fntype, flags); | |
0cbd7506 | 1697 | } |
bb20cc46 | 1698 | |
b8fd7909 JM |
1699 | if (tx_safe_fn_type_p (fntype)) |
1700 | { | |
1701 | pp->padding = pp_before; | |
1702 | pp_cxx_ws_string (pp, "transaction_safe"); | |
1703 | } | |
1704 | ||
761f0855 | 1705 | if (flags & TFF_EXCEPTION_SPECIFICATION) |
0cbd7506 | 1706 | { |
3c1ab1ab GDR |
1707 | pp->padding = pp_before; |
1708 | dump_exception_spec (pp, exceptions, flags); | |
0cbd7506 | 1709 | } |
ad6b1795 JM |
1710 | |
1711 | if (show_return) | |
420db574 | 1712 | dump_type_suffix (pp, ret, flags); |
76b294d4 JM |
1713 | else if (deduction_guide_p (t)) |
1714 | { | |
1715 | pp_cxx_ws_string (pp, "->"); | |
1716 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
1717 | } | |
612c671a | 1718 | |
971e17ff AS |
1719 | if (flag_concepts) |
1720 | if (tree ci = get_constraints (t)) | |
1721 | if (tree reqs = CI_DECLARATOR_REQS (ci)) | |
1722 | pp_cxx_requires_clause (pp, reqs); | |
1723 | ||
753c4989 | 1724 | dump_substitution (pp, t, template_parms, template_args, flags); |
31f7f784 JM |
1725 | |
1726 | if (tree base = DECL_INHERITED_CTOR_BASE (t)) | |
1727 | { | |
1728 | pp_cxx_ws_string (pp, "[inherited from"); | |
1729 | dump_type (pp, base, TFF_PLAIN_IDENTIFIER); | |
1730 | pp_character (pp, ']'); | |
1731 | } | |
21d69a5b JM |
1732 | } |
1733 | else if (template_args) | |
612c671a | 1734 | { |
21d69a5b JM |
1735 | bool need_comma = false; |
1736 | int i; | |
3c1ab1ab | 1737 | pp_cxx_begin_template_argument_list (pp); |
21d69a5b JM |
1738 | template_args = INNERMOST_TEMPLATE_ARGS (template_args); |
1739 | for (i = 0; i < TREE_VEC_LENGTH (template_args); ++i) | |
1740 | { | |
1741 | tree arg = TREE_VEC_ELT (template_args, i); | |
1742 | if (need_comma) | |
3c1ab1ab | 1743 | pp_separate_with_comma (pp); |
21d69a5b | 1744 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab GDR |
1745 | pp_cxx_left_brace (pp); |
1746 | dump_template_argument (pp, arg, TFF_PLAIN_IDENTIFIER); | |
21d69a5b | 1747 | if (ARGUMENT_PACK_P (arg)) |
3c1ab1ab | 1748 | pp_cxx_right_brace (pp); |
21d69a5b JM |
1749 | need_comma = true; |
1750 | } | |
3c1ab1ab | 1751 | pp_cxx_end_template_argument_list (pp); |
612c671a | 1752 | } |
4995028c NS |
1753 | } |
1754 | ||
9e93bc9d NS |
1755 | /* Print a parameter list. If this is for a member function, the |
1756 | member object ptr (and any other hidden args) should have | |
c6002625 | 1757 | already been removed. */ |
4995028c NS |
1758 | |
1759 | static void | |
3c1ab1ab | 1760 | dump_parameters (cxx_pretty_printer *pp, tree parmtypes, int flags) |
4995028c | 1761 | { |
5d80a306 | 1762 | int first = 1; |
af88c58f | 1763 | flags &= ~TFF_SCOPE; |
3c1ab1ab | 1764 | pp_cxx_left_paren (pp); |
4995028c NS |
1765 | |
1766 | for (first = 1; parmtypes != void_list_node; | |
1767 | parmtypes = TREE_CHAIN (parmtypes)) | |
1768 | { | |
1769 | if (!first) | |
3c1ab1ab | 1770 | pp_separate_with_comma (pp); |
4995028c NS |
1771 | first = 0; |
1772 | if (!parmtypes) | |
0cbd7506 | 1773 | { |
3c1ab1ab | 1774 | pp_cxx_ws_string (pp, "..."); |
0cbd7506 MS |
1775 | break; |
1776 | } | |
31d40008 | 1777 | |
3c1ab1ab | 1778 | dump_type (pp, TREE_VALUE (parmtypes), flags); |
bb20cc46 | 1779 | |
761f0855 | 1780 | if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes)) |
0cbd7506 | 1781 | { |
3c1ab1ab GDR |
1782 | pp_cxx_whitespace (pp); |
1783 | pp_equal (pp); | |
1784 | pp_cxx_whitespace (pp); | |
1785 | dump_expr (pp, TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS); | |
0cbd7506 | 1786 | } |
4995028c NS |
1787 | } |
1788 | ||
3c1ab1ab | 1789 | pp_cxx_right_paren (pp); |
4995028c NS |
1790 | } |
1791 | ||
2eed8e37 BK |
1792 | /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */ |
1793 | ||
1794 | static void | |
3c1ab1ab | 1795 | dump_ref_qualifier (cxx_pretty_printer *pp, tree t, int flags ATTRIBUTE_UNUSED) |
2eed8e37 BK |
1796 | { |
1797 | if (FUNCTION_REF_QUALIFIED (t)) | |
1798 | { | |
3c1ab1ab | 1799 | pp->padding = pp_before; |
2eed8e37 | 1800 | if (FUNCTION_RVALUE_QUALIFIED (t)) |
3c1ab1ab | 1801 | pp_cxx_ws_string (pp, "&&"); |
2eed8e37 | 1802 | else |
3c1ab1ab | 1803 | pp_cxx_ws_string (pp, "&"); |
2eed8e37 BK |
1804 | } |
1805 | } | |
1806 | ||
c6002625 | 1807 | /* Print an exception specification. T is the exception specification. */ |
4995028c NS |
1808 | |
1809 | static void | |
3c1ab1ab | 1810 | dump_exception_spec (cxx_pretty_printer *pp, tree t, int flags) |
4995028c | 1811 | { |
3a55fb4c JM |
1812 | if (t && TREE_PURPOSE (t)) |
1813 | { | |
3c1ab1ab | 1814 | pp_cxx_ws_string (pp, "noexcept"); |
1a1f2bc5 JM |
1815 | if (!integer_onep (TREE_PURPOSE (t))) |
1816 | { | |
1817 | pp_cxx_whitespace (pp); | |
1818 | pp_cxx_left_paren (pp); | |
1819 | if (DEFERRED_NOEXCEPT_SPEC_P (t)) | |
1820 | pp_cxx_ws_string (pp, "<uninstantiated>"); | |
1821 | else | |
1822 | dump_expr (pp, TREE_PURPOSE (t), flags); | |
1823 | pp_cxx_right_paren (pp); | |
1824 | } | |
3a55fb4c JM |
1825 | } |
1826 | else if (t) | |
4995028c | 1827 | { |
3c1ab1ab GDR |
1828 | pp_cxx_ws_string (pp, "throw"); |
1829 | pp_cxx_whitespace (pp); | |
1830 | pp_cxx_left_paren (pp); | |
4995028c | 1831 | if (TREE_VALUE (t) != NULL_TREE) |
0cbd7506 MS |
1832 | while (1) |
1833 | { | |
3c1ab1ab | 1834 | dump_type (pp, TREE_VALUE (t), flags); |
0cbd7506 MS |
1835 | t = TREE_CHAIN (t); |
1836 | if (!t) | |
1837 | break; | |
3c1ab1ab | 1838 | pp_separate_with_comma (pp); |
0cbd7506 | 1839 | } |
3c1ab1ab | 1840 | pp_cxx_right_paren (pp); |
4995028c | 1841 | } |
8d08fdba MS |
1842 | } |
1843 | ||
1844 | /* Handle the function name for a FUNCTION_DECL node, grokking operators | |
1845 | and destructors properly. */ | |
e92cc029 | 1846 | |
8d08fdba | 1847 | static void |
3c1ab1ab | 1848 | dump_function_name (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba MS |
1849 | { |
1850 | tree name = DECL_NAME (t); | |
1851 | ||
93604b1a ZW |
1852 | /* We can get here with a decl that was synthesized by language- |
1853 | independent machinery (e.g. coverage.c) in which case it won't | |
1854 | have a lang_specific structure attached and DECL_CONSTRUCTOR_P | |
1855 | will crash. In this case it is safe just to print out the | |
1856 | literal name. */ | |
1857 | if (!DECL_LANG_SPECIFIC (t)) | |
1858 | { | |
3c1ab1ab | 1859 | pp_cxx_tree_identifier (pp, name); |
93604b1a ZW |
1860 | return; |
1861 | } | |
1862 | ||
78abea27 RS |
1863 | if (TREE_CODE (t) == TEMPLATE_DECL) |
1864 | t = DECL_TEMPLATE_RESULT (t); | |
1865 | ||
5e818b93 JM |
1866 | /* Don't let the user see __comp_ctor et al. */ |
1867 | if (DECL_CONSTRUCTOR_P (t) | |
1868 | || DECL_DESTRUCTOR_P (t)) | |
d5f4eddd JM |
1869 | { |
1870 | if (LAMBDA_TYPE_P (DECL_CONTEXT (t))) | |
1871 | name = get_identifier ("<lambda>"); | |
6a7b9203 | 1872 | else if (TYPE_UNNAMED_P (DECL_CONTEXT (t))) |
7996b727 | 1873 | name = get_identifier ("<constructor>"); |
d5f4eddd JM |
1874 | else |
1875 | name = constructor_name (DECL_CONTEXT (t)); | |
1876 | } | |
5e818b93 | 1877 | |
aa45967f | 1878 | if (DECL_DESTRUCTOR_P (t)) |
8d08fdba | 1879 | { |
3c1ab1ab GDR |
1880 | pp_cxx_complement (pp); |
1881 | dump_decl (pp, name, TFF_PLAIN_IDENTIFIER); | |
8d08fdba | 1882 | } |
aa45967f | 1883 | else if (DECL_CONV_FN_P (t)) |
8d08fdba MS |
1884 | { |
1885 | /* This cannot use the hack that the operator's return | |
1886 | type is stashed off of its name because it may be | |
1887 | used for error reporting. In the case of conflicting | |
1888 | declarations, both will have the same name, yet | |
1889 | the types will be different, hence the TREE_TYPE field | |
1890 | of the first name will be clobbered by the second. */ | |
3c1ab1ab GDR |
1891 | pp_cxx_ws_string (pp, "operator"); |
1892 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba | 1893 | } |
8d08fdba | 1894 | else |
3c1ab1ab | 1895 | dump_decl (pp, name, flags); |
386b8a85 | 1896 | |
93604b1a | 1897 | if (DECL_TEMPLATE_INFO (t) |
05fd666b | 1898 | && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t) |
f0d60e22 | 1899 | && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL |
36a117a5 | 1900 | || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))) |
3c1ab1ab GDR |
1901 | dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), |
1902 | flags); | |
9e93bc9d | 1903 | } |
75650646 | 1904 | |
9e93bc9d NS |
1905 | /* Dump the template parameters from the template info INFO under control of |
1906 | FLAGS. PRIMARY indicates whether this is a primary template decl, or | |
1907 | specialization (partial or complete). For partial specializations we show | |
1908 | the specialized parameter values. For a primary template we show no | |
1909 | decoration. */ | |
1910 | ||
1911 | static void | |
3c1ab1ab GDR |
1912 | dump_template_parms (cxx_pretty_printer *pp, tree info, |
1913 | int primary, int flags) | |
9e93bc9d NS |
1914 | { |
1915 | tree args = info ? TI_ARGS (info) : NULL_TREE; | |
bb20cc46 | 1916 | |
761f0855 | 1917 | if (primary && flags & TFF_TEMPLATE_NAME) |
9e93bc9d | 1918 | return; |
761f0855 | 1919 | flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME); |
3c1ab1ab | 1920 | pp_cxx_begin_template_argument_list (pp); |
9e93bc9d NS |
1921 | |
1922 | /* Be careful only to print things when we have them, so as not | |
8cc77ebe | 1923 | to crash producing error messages. */ |
9e93bc9d NS |
1924 | if (args && !primary) |
1925 | { | |
bf12d54d | 1926 | int len, ix; |
1a048f82 | 1927 | len = get_non_default_template_args_count (args, flags); |
bb20cc46 | 1928 | |
11d7788d | 1929 | args = INNERMOST_TEMPLATE_ARGS (args); |
bf12d54d | 1930 | for (ix = 0; ix != len; ix++) |
0cbd7506 MS |
1931 | { |
1932 | tree arg = TREE_VEC_ELT (args, ix); | |
bf12d54d | 1933 | |
5d80a306 DG |
1934 | /* Only print a comma if we know there is an argument coming. In |
1935 | the case of an empty template argument pack, no actual | |
1936 | argument will be printed. */ | |
1937 | if (ix | |
1938 | && (!ARGUMENT_PACK_P (arg) | |
1939 | || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0)) | |
3c1ab1ab | 1940 | pp_separate_with_comma (pp); |
5d80a306 DG |
1941 | |
1942 | if (!arg) | |
3c1ab1ab | 1943 | pp_string (pp, M_("<template parameter error>")); |
5d80a306 | 1944 | else |
3c1ab1ab | 1945 | dump_template_argument (pp, arg, flags); |
5d80a306 | 1946 | } |
9e93bc9d | 1947 | } |
9e93bc9d NS |
1948 | else if (primary) |
1949 | { | |
1950 | tree tpl = TI_TEMPLATE (info); | |
1951 | tree parms = DECL_TEMPLATE_PARMS (tpl); | |
1952 | int len, ix; | |
bb20cc46 | 1953 | |
9e93bc9d NS |
1954 | parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE; |
1955 | len = parms ? TREE_VEC_LENGTH (parms) : 0; | |
bb20cc46 | 1956 | |
9e93bc9d | 1957 | for (ix = 0; ix != len; ix++) |
0cbd7506 | 1958 | { |
2d8ba2c7 LM |
1959 | tree parm; |
1960 | ||
1961 | if (TREE_VEC_ELT (parms, ix) == error_mark_node) | |
1962 | { | |
3c1ab1ab | 1963 | pp_string (pp, M_("<template parameter error>")); |
2d8ba2c7 LM |
1964 | continue; |
1965 | } | |
1966 | ||
1967 | parm = TREE_VALUE (TREE_VEC_ELT (parms, ix)); | |
9e93bc9d | 1968 | |
0cbd7506 | 1969 | if (ix) |
3c1ab1ab | 1970 | pp_separate_with_comma (pp); |
bb20cc46 | 1971 | |
3c1ab1ab | 1972 | dump_decl (pp, parm, flags & ~TFF_DECL_SPECIFIERS); |
0cbd7506 | 1973 | } |
386b8a85 | 1974 | } |
3c1ab1ab | 1975 | pp_cxx_end_template_argument_list (pp); |
8d08fdba MS |
1976 | } |
1977 | ||
5039610b SL |
1978 | /* Print out the arguments of CALL_EXPR T as a parenthesized list using |
1979 | flags FLAGS. Skip over the first argument if SKIPFIRST is true. */ | |
1980 | ||
1981 | static void | |
3c1ab1ab | 1982 | dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst) |
5039610b SL |
1983 | { |
1984 | tree arg; | |
1985 | call_expr_arg_iterator iter; | |
1986 | ||
3c1ab1ab | 1987 | pp_cxx_left_paren (pp); |
5039610b SL |
1988 | FOR_EACH_CALL_EXPR_ARG (arg, iter, t) |
1989 | { | |
1990 | if (skipfirst) | |
1991 | skipfirst = false; | |
1992 | else | |
1993 | { | |
3c1ab1ab | 1994 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 1995 | if (more_call_expr_args_p (&iter)) |
3c1ab1ab | 1996 | pp_separate_with_comma (pp); |
5039610b SL |
1997 | } |
1998 | } | |
3c1ab1ab | 1999 | pp_cxx_right_paren (pp); |
5039610b SL |
2000 | } |
2001 | ||
2002 | /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list | |
2003 | using flags FLAGS. Skip over the first argument if SKIPFIRST is | |
2004 | true. */ | |
2005 | ||
2006 | static void | |
3c1ab1ab GDR |
2007 | dump_aggr_init_expr_args (cxx_pretty_printer *pp, tree t, int flags, |
2008 | bool skipfirst) | |
5039610b SL |
2009 | { |
2010 | tree arg; | |
2011 | aggr_init_expr_arg_iterator iter; | |
2012 | ||
3c1ab1ab | 2013 | pp_cxx_left_paren (pp); |
5039610b SL |
2014 | FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t) |
2015 | { | |
2016 | if (skipfirst) | |
2017 | skipfirst = false; | |
2018 | else | |
2019 | { | |
3c1ab1ab | 2020 | dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); |
5039610b | 2021 | if (more_aggr_init_expr_args_p (&iter)) |
3c1ab1ab | 2022 | pp_separate_with_comma (pp); |
5039610b SL |
2023 | } |
2024 | } | |
3c1ab1ab | 2025 | pp_cxx_right_paren (pp); |
5039610b SL |
2026 | } |
2027 | ||
f4f206f4 | 2028 | /* Print out a list of initializers (subr of dump_expr). */ |
e92cc029 | 2029 | |
8d08fdba | 2030 | static void |
3c1ab1ab | 2031 | dump_expr_list (cxx_pretty_printer *pp, tree l, int flags) |
8d08fdba MS |
2032 | { |
2033 | while (l) | |
2034 | { | |
3c1ab1ab | 2035 | dump_expr (pp, TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS); |
8d08fdba | 2036 | l = TREE_CHAIN (l); |
9e93bc9d | 2037 | if (l) |
3c1ab1ab | 2038 | pp_separate_with_comma (pp); |
8d08fdba MS |
2039 | } |
2040 | } | |
2041 | ||
4038c495 GB |
2042 | /* Print out a vector of initializers (subr of dump_expr). */ |
2043 | ||
2044 | static void | |
3c1ab1ab GDR |
2045 | dump_expr_init_vec (cxx_pretty_printer *pp, vec<constructor_elt, va_gc> *v, |
2046 | int flags) | |
4038c495 GB |
2047 | { |
2048 | unsigned HOST_WIDE_INT idx; | |
2049 | tree value; | |
2050 | ||
2051 | FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
2052 | { | |
3c1ab1ab | 2053 | dump_expr (pp, value, flags | TFF_EXPR_IN_PARENS); |
9771b263 | 2054 | if (idx != v->length () - 1) |
3c1ab1ab | 2055 | pp_separate_with_comma (pp); |
4038c495 GB |
2056 | } |
2057 | } | |
2058 | ||
2059 | ||
7f58e7ac GDR |
2060 | /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual |
2061 | function. Resolve it to a close relative -- in the sense of static | |
2062 | type -- variant being overridden. That is close to what was written in | |
2063 | the source code. Subroutine of dump_expr. */ | |
2064 | ||
2065 | static tree | |
2066 | resolve_virtual_fun_from_obj_type_ref (tree ref) | |
2067 | { | |
2068 | tree obj_type = TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref)); | |
ae7e9ddd | 2069 | HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref)); |
7f58e7ac | 2070 | tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type))); |
c6f3d2f4 JJ |
2071 | while (index) |
2072 | { | |
7f58e7ac | 2073 | fun = TREE_CHAIN (fun); |
c6f3d2f4 JJ |
2074 | index -= (TARGET_VTABLE_USES_DESCRIPTORS |
2075 | ? TARGET_VTABLE_USES_DESCRIPTORS : 1); | |
2076 | } | |
7f58e7ac GDR |
2077 | |
2078 | return BV_FN (fun); | |
2079 | } | |
2080 | ||
c6002625 | 2081 | /* Print out an expression E under control of FLAGS. */ |
e92cc029 | 2082 | |
8d08fdba | 2083 | static void |
3c1ab1ab | 2084 | dump_expr (cxx_pretty_printer *pp, tree t, int flags) |
8d08fdba | 2085 | { |
a1e03bc5 JM |
2086 | tree op; |
2087 | ||
8c048a52 GDR |
2088 | if (t == 0) |
2089 | return; | |
c8094d83 | 2090 | |
10a6624a PC |
2091 | if (STATEMENT_CLASS_P (t)) |
2092 | { | |
3c1ab1ab | 2093 | pp_cxx_ws_string (pp, M_("<statement>")); |
10a6624a PC |
2094 | return; |
2095 | } | |
2096 | ||
8d08fdba MS |
2097 | switch (TREE_CODE (t)) |
2098 | { | |
2099 | case VAR_DECL: | |
2100 | case PARM_DECL: | |
2101 | case FIELD_DECL: | |
2102 | case CONST_DECL: | |
2103 | case FUNCTION_DECL: | |
ec255269 | 2104 | case TEMPLATE_DECL: |
6b57ac29 | 2105 | case NAMESPACE_DECL: |
39e837db | 2106 | case LABEL_DECL: |
cb57504a | 2107 | case WILDCARD_DECL: |
5d73aa63 | 2108 | case OVERLOAD: |
501c95ff | 2109 | case TYPE_DECL: |
a723baf1 | 2110 | case IDENTIFIER_NODE: |
3c1ab1ab GDR |
2111 | dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE |
2112 | |TFF_TEMPLATE_HEADER)) | |
98e5a19a | 2113 | | TFF_NO_TEMPLATE_BINDINGS |
3c1ab1ab | 2114 | | TFF_NO_FUNCTION_ARGUMENTS)); |
8d08fdba MS |
2115 | break; |
2116 | ||
a5952633 | 2117 | case SSA_NAME: |
70b5e7dc RG |
2118 | if (SSA_NAME_VAR (t) |
2119 | && !DECL_ARTIFICIAL (SSA_NAME_VAR (t))) | |
3c1ab1ab | 2120 | dump_expr (pp, SSA_NAME_VAR (t), flags); |
a5952633 | 2121 | else |
3c1ab1ab | 2122 | pp_cxx_ws_string (pp, M_("<unknown>")); |
a5952633 RG |
2123 | break; |
2124 | ||
632f2871 | 2125 | case VOID_CST: |
7a8380ae | 2126 | case INTEGER_CST: |
8d08fdba | 2127 | case REAL_CST: |
a176426f | 2128 | case STRING_CST: |
7368348c | 2129 | case COMPLEX_CST: |
20059c8b | 2130 | pp->constant (t); |
8d08fdba MS |
2131 | break; |
2132 | ||
3ce4f9e4 | 2133 | case USERDEF_LITERAL: |
3c1ab1ab | 2134 | pp_cxx_userdef_literal (pp, t); |
3ce4f9e4 ESR |
2135 | break; |
2136 | ||
1c09c5e5 | 2137 | case THROW_EXPR: |
d8b4270d PC |
2138 | /* While waiting for caret diagnostics, avoid printing |
2139 | __cxa_allocate_exception, __cxa_throw, and the like. */ | |
3c1ab1ab | 2140 | pp_cxx_ws_string (pp, M_("<throw-expression>")); |
1c09c5e5 GDR |
2141 | break; |
2142 | ||
61a127b3 | 2143 | case PTRMEM_CST: |
3c1ab1ab GDR |
2144 | pp_ampersand (pp); |
2145 | dump_type (pp, PTRMEM_CST_CLASS (t), flags); | |
2146 | pp_cxx_colon_colon (pp); | |
2147 | pp_cxx_tree_identifier (pp, DECL_NAME (PTRMEM_CST_MEMBER (t))); | |
61a127b3 MM |
2148 | break; |
2149 | ||
8d08fdba | 2150 | case COMPOUND_EXPR: |
3c1ab1ab GDR |
2151 | pp_cxx_left_paren (pp); |
2152 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2153 | pp_separate_with_comma (pp); | |
2154 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2155 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2156 | break; |
2157 | ||
2158 | case COND_EXPR: | |
82665822 | 2159 | case VEC_COND_EXPR: |
3c1ab1ab GDR |
2160 | pp_cxx_left_paren (pp); |
2161 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2162 | pp_string (pp, " ? "); | |
2163 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2164 | pp_string (pp, " : "); | |
2165 | dump_expr (pp, TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS); | |
2166 | pp_cxx_right_paren (pp); | |
8d08fdba MS |
2167 | break; |
2168 | ||
2169 | case SAVE_EXPR: | |
2170 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2171 | { | |
3c1ab1ab GDR |
2172 | pp_cxx_ws_string (pp, "new"); |
2173 | pp_cxx_whitespace (pp); | |
2174 | dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags); | |
8d08fdba MS |
2175 | } |
2176 | else | |
3c1ab1ab | 2177 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2178 | break; |
2179 | ||
02531345 | 2180 | case AGGR_INIT_EXPR: |
27b8d0cd MM |
2181 | { |
2182 | tree fn = NULL_TREE; | |
bb20cc46 | 2183 | |
5039610b SL |
2184 | if (TREE_CODE (AGGR_INIT_EXPR_FN (t)) == ADDR_EXPR) |
2185 | fn = TREE_OPERAND (AGGR_INIT_EXPR_FN (t), 0); | |
27b8d0cd MM |
2186 | |
2187 | if (fn && TREE_CODE (fn) == FUNCTION_DECL) | |
2188 | { | |
2189 | if (DECL_CONSTRUCTOR_P (fn)) | |
3c1ab1ab | 2190 | dump_type (pp, DECL_CONTEXT (fn), flags); |
27b8d0cd | 2191 | else |
3c1ab1ab | 2192 | dump_decl (pp, fn, 0); |
27b8d0cd MM |
2193 | } |
2194 | else | |
3c1ab1ab | 2195 | dump_expr (pp, AGGR_INIT_EXPR_FN (t), 0); |
27b8d0cd | 2196 | } |
3c1ab1ab | 2197 | dump_aggr_init_expr_args (pp, t, flags, true); |
8d08fdba MS |
2198 | break; |
2199 | ||
2200 | case CALL_EXPR: | |
2201 | { | |
5039610b SL |
2202 | tree fn = CALL_EXPR_FN (t); |
2203 | bool skipfirst = false; | |
bb20cc46 | 2204 | |
0b274c17 MP |
2205 | /* Deal with internal functions. */ |
2206 | if (fn == NULL_TREE) | |
2207 | { | |
2208 | pp_string (pp, internal_fn_name (CALL_EXPR_IFN (t))); | |
2209 | dump_call_expr_args (pp, t, flags, skipfirst); | |
2210 | break; | |
2211 | } | |
2212 | ||
8d08fdba MS |
2213 | if (TREE_CODE (fn) == ADDR_EXPR) |
2214 | fn = TREE_OPERAND (fn, 0); | |
2215 | ||
3db45ab5 MS |
2216 | /* Nobody is interested in seeing the guts of vcalls. */ |
2217 | if (TREE_CODE (fn) == OBJ_TYPE_REF) | |
2218 | fn = resolve_virtual_fun_from_obj_type_ref (fn); | |
7f58e7ac | 2219 | |
dd6f4f89 JJ |
2220 | if (TREE_TYPE (fn) != NULL_TREE |
2221 | && NEXT_CODE (fn) == METHOD_TYPE | |
2222 | && call_expr_nargs (t)) | |
8d08fdba | 2223 | { |
5039610b | 2224 | tree ob = CALL_EXPR_ARG (t, 0); |
8d08fdba MS |
2225 | if (TREE_CODE (ob) == ADDR_EXPR) |
2226 | { | |
3c1ab1ab GDR |
2227 | dump_expr (pp, TREE_OPERAND (ob, 0), |
2228 | flags | TFF_EXPR_IN_PARENS); | |
2229 | pp_cxx_dot (pp); | |
8d08fdba | 2230 | } |
c3b0f4c6 | 2231 | else if (!is_this_parameter (ob)) |
8d08fdba | 2232 | { |
3c1ab1ab GDR |
2233 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2234 | pp_cxx_arrow (pp); | |
8d08fdba | 2235 | } |
5039610b | 2236 | skipfirst = true; |
8d08fdba | 2237 | } |
de5a5fa1 MP |
2238 | if (flag_sanitize & SANITIZE_UNDEFINED |
2239 | && is_ubsan_builtin_p (fn)) | |
2240 | { | |
2241 | pp_string (cxx_pp, M_("<ubsan routine call>")); | |
2242 | break; | |
2243 | } | |
3c1ab1ab GDR |
2244 | dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS); |
2245 | dump_call_expr_args (pp, t, flags, skipfirst); | |
8d08fdba MS |
2246 | } |
2247 | break; | |
2248 | ||
8d08fdba MS |
2249 | case TARGET_EXPR: |
2250 | /* Note that this only works for G++ target exprs. If somebody | |
2251 | builds a general TARGET_EXPR, there's no way to represent that | |
2252 | it initializes anything other that the parameter slot for the | |
2253 | default argument. Note we may have cleared out the first | |
2254 | operand in expand_expr, so don't go killing ourselves. */ | |
2255 | if (TREE_OPERAND (t, 1)) | |
3c1ab1ab | 2256 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2257 | break; |
2258 | ||
d7705934 | 2259 | case POINTER_PLUS_EXPR: |
3c1ab1ab | 2260 | dump_binary_op (pp, "+", t, flags); |
d7705934 DB |
2261 | break; |
2262 | ||
1af4ebf5 MG |
2263 | case POINTER_DIFF_EXPR: |
2264 | dump_binary_op (pp, "-", t, flags); | |
2265 | break; | |
2266 | ||
b3ab27f3 | 2267 | case INIT_EXPR: |
8d08fdba | 2268 | case MODIFY_EXPR: |
88a819be | 2269 | dump_binary_op (pp, OVL_OP_INFO (true, NOP_EXPR)->name, t, flags); |
a11e05f4 JM |
2270 | break; |
2271 | ||
8d08fdba MS |
2272 | case PLUS_EXPR: |
2273 | case MINUS_EXPR: | |
2274 | case MULT_EXPR: | |
2275 | case TRUNC_DIV_EXPR: | |
2276 | case TRUNC_MOD_EXPR: | |
2277 | case MIN_EXPR: | |
2278 | case MAX_EXPR: | |
2279 | case LSHIFT_EXPR: | |
2280 | case RSHIFT_EXPR: | |
2281 | case BIT_IOR_EXPR: | |
2282 | case BIT_XOR_EXPR: | |
2283 | case BIT_AND_EXPR: | |
8d08fdba MS |
2284 | case TRUTH_ANDIF_EXPR: |
2285 | case TRUTH_ORIF_EXPR: | |
2286 | case LT_EXPR: | |
2287 | case LE_EXPR: | |
2288 | case GT_EXPR: | |
2289 | case GE_EXPR: | |
2290 | case EQ_EXPR: | |
2291 | case NE_EXPR: | |
b7689b96 | 2292 | case SPACESHIP_EXPR: |
2adeacc9 | 2293 | case EXACT_DIV_EXPR: |
88a819be | 2294 | dump_binary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags); |
8d08fdba MS |
2295 | break; |
2296 | ||
2297 | case CEIL_DIV_EXPR: | |
2298 | case FLOOR_DIV_EXPR: | |
2299 | case ROUND_DIV_EXPR: | |
ba52691c | 2300 | case RDIV_EXPR: |
3c1ab1ab | 2301 | dump_binary_op (pp, "/", t, flags); |
8d08fdba MS |
2302 | break; |
2303 | ||
2304 | case CEIL_MOD_EXPR: | |
2305 | case FLOOR_MOD_EXPR: | |
2306 | case ROUND_MOD_EXPR: | |
3c1ab1ab | 2307 | dump_binary_op (pp, "%", t, flags); |
8d08fdba MS |
2308 | break; |
2309 | ||
2310 | case COMPONENT_REF: | |
2311 | { | |
2312 | tree ob = TREE_OPERAND (t, 0); | |
591cb3cf | 2313 | if (INDIRECT_REF_P (ob)) |
8d08fdba MS |
2314 | { |
2315 | ob = TREE_OPERAND (ob, 0); | |
c3b0f4c6 | 2316 | if (!is_this_parameter (ob)) |
8d08fdba | 2317 | { |
3c1ab1ab | 2318 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
9f613f06 | 2319 | if (TYPE_REF_P (TREE_TYPE (ob))) |
3c1ab1ab | 2320 | pp_cxx_dot (pp); |
87fd3cf1 | 2321 | else |
3c1ab1ab | 2322 | pp_cxx_arrow (pp); |
8d08fdba MS |
2323 | } |
2324 | } | |
2325 | else | |
2326 | { | |
3c1ab1ab | 2327 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
19bdccb4 JJ |
2328 | if (TREE_CODE (ob) != ARROW_EXPR) |
2329 | pp_cxx_dot (pp); | |
8d08fdba | 2330 | } |
3c1ab1ab | 2331 | dump_expr (pp, TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2332 | } |
2333 | break; | |
2334 | ||
28cbf42c | 2335 | case ARRAY_REF: |
3c1ab1ab GDR |
2336 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
2337 | pp_cxx_left_bracket (pp); | |
2338 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); | |
2339 | pp_cxx_right_bracket (pp); | |
28cbf42c MS |
2340 | break; |
2341 | ||
392e3d51 | 2342 | case UNARY_PLUS_EXPR: |
3c1ab1ab | 2343 | dump_unary_op (pp, "+", t, flags); |
8d08fdba MS |
2344 | break; |
2345 | ||
2346 | case ADDR_EXPR: | |
2347 | if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL | |
fd74ca0b MM |
2348 | || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST |
2349 | /* An ADDR_EXPR can have reference type. In that case, we | |
2350 | shouldn't print the `&' doing so indicates to the user | |
2351 | that the expression has pointer type. */ | |
bb20cc46 | 2352 | || (TREE_TYPE (t) |
9f613f06 | 2353 | && TYPE_REF_P (TREE_TYPE (t)))) |
3c1ab1ab | 2354 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
39e837db | 2355 | else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL) |
3c1ab1ab | 2356 | dump_unary_op (pp, "&&", t, flags); |
8d08fdba | 2357 | else |
3c1ab1ab | 2358 | dump_unary_op (pp, "&", t, flags); |
8d08fdba MS |
2359 | break; |
2360 | ||
2361 | case INDIRECT_REF: | |
2362 | if (TREE_HAS_CONSTRUCTOR (t)) | |
2363 | { | |
2364 | t = TREE_OPERAND (t, 0); | |
50bc768d | 2365 | gcc_assert (TREE_CODE (t) == CALL_EXPR); |
3c1ab1ab GDR |
2366 | dump_expr (pp, CALL_EXPR_FN (t), flags | TFF_EXPR_IN_PARENS); |
2367 | dump_call_expr_args (pp, t, flags, true); | |
8d08fdba MS |
2368 | } |
2369 | else | |
2370 | { | |
6467930b | 2371 | if (TREE_OPERAND (t,0) != NULL_TREE |
5082a355 | 2372 | && TREE_TYPE (TREE_OPERAND (t, 0)) |
6467930b | 2373 | && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE) |
3c1ab1ab | 2374 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
8d08fdba | 2375 | else |
3c1ab1ab | 2376 | dump_unary_op (pp, "*", t, flags); |
8d08fdba MS |
2377 | } |
2378 | break; | |
2379 | ||
892f6119 RG |
2380 | case MEM_REF: |
2381 | if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR | |
2382 | && integer_zerop (TREE_OPERAND (t, 1))) | |
3c1ab1ab | 2383 | dump_expr (pp, TREE_OPERAND (TREE_OPERAND (t, 0), 0), flags); |
892f6119 RG |
2384 | else |
2385 | { | |
3c1ab1ab | 2386 | pp_cxx_star (pp); |
892f6119 RG |
2387 | if (!integer_zerop (TREE_OPERAND (t, 1))) |
2388 | { | |
3c1ab1ab | 2389 | pp_cxx_left_paren (pp); |
892f6119 RG |
2390 | if (!integer_onep (TYPE_SIZE_UNIT |
2391 | (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)))))) | |
2392 | { | |
3c1ab1ab GDR |
2393 | pp_cxx_left_paren (pp); |
2394 | dump_type (pp, ptr_type_node, flags); | |
2395 | pp_cxx_right_paren (pp); | |
892f6119 RG |
2396 | } |
2397 | } | |
3c1ab1ab | 2398 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
892f6119 RG |
2399 | if (!integer_zerop (TREE_OPERAND (t, 1))) |
2400 | { | |
3c1ab1ab GDR |
2401 | pp_cxx_ws_string (pp, "+"); |
2402 | dump_expr (pp, fold_convert (ssizetype, TREE_OPERAND (t, 1)), | |
2403 | flags); | |
2404 | pp_cxx_right_paren (pp); | |
892f6119 RG |
2405 | } |
2406 | } | |
2407 | break; | |
2408 | ||
ac1c65ad JJ |
2409 | case TARGET_MEM_REF: |
2410 | /* TARGET_MEM_REF can't appear directly from source, but can appear | |
2411 | during late GIMPLE optimizations and through late diagnostic we might | |
2412 | need to support it. Print it as dereferencing of a pointer after | |
2413 | cast to the TARGET_MEM_REF type, with pointer arithmetics on some | |
2414 | pointer to single byte types, so | |
2415 | *(type *)((char *) ptr + step * index + index2) if all the operands | |
2416 | are present and the casts are needed. */ | |
2417 | pp_cxx_star (pp); | |
2418 | pp_cxx_left_paren (pp); | |
2419 | if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t)))) == NULL_TREE | |
2420 | || !integer_onep (TYPE_SIZE_UNIT | |
2421 | (TREE_TYPE (TREE_TYPE (TMR_BASE (t)))))) | |
2422 | { | |
2423 | if (TYPE_SIZE_UNIT (TREE_TYPE (t)) | |
2424 | && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t)))) | |
2425 | { | |
2426 | pp_cxx_left_paren (pp); | |
2427 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2428 | } | |
2429 | else | |
2430 | { | |
2431 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2432 | pp_cxx_right_paren (pp); | |
2433 | pp_cxx_left_paren (pp); | |
2434 | pp_cxx_left_paren (pp); | |
2435 | dump_type (pp, build_pointer_type (char_type_node), flags); | |
2436 | } | |
2437 | pp_cxx_right_paren (pp); | |
2438 | } | |
2439 | else if (!same_type_p (TREE_TYPE (t), | |
2440 | TREE_TYPE (TREE_TYPE (TMR_BASE (t))))) | |
2441 | { | |
2442 | dump_type (pp, build_pointer_type (TREE_TYPE (t)), flags); | |
2443 | pp_cxx_right_paren (pp); | |
2444 | pp_cxx_left_paren (pp); | |
2445 | } | |
2446 | dump_expr (pp, TMR_BASE (t), flags); | |
2447 | if (TMR_STEP (t) && TMR_INDEX (t)) | |
2448 | { | |
2449 | pp_cxx_ws_string (pp, "+"); | |
2450 | dump_expr (pp, TMR_INDEX (t), flags); | |
2451 | pp_cxx_ws_string (pp, "*"); | |
2452 | dump_expr (pp, TMR_STEP (t), flags); | |
2453 | } | |
2454 | if (TMR_INDEX2 (t)) | |
2455 | { | |
2456 | pp_cxx_ws_string (pp, "+"); | |
2457 | dump_expr (pp, TMR_INDEX2 (t), flags); | |
2458 | } | |
2459 | if (!integer_zerop (TMR_OFFSET (t))) | |
2460 | { | |
2461 | pp_cxx_ws_string (pp, "+"); | |
2462 | dump_expr (pp, fold_convert (ssizetype, TMR_OFFSET (t)), flags); | |
2463 | } | |
2464 | pp_cxx_right_paren (pp); | |
2465 | break; | |
2466 | ||
8d08fdba MS |
2467 | case NEGATE_EXPR: |
2468 | case BIT_NOT_EXPR: | |
2469 | case TRUTH_NOT_EXPR: | |
2470 | case PREDECREMENT_EXPR: | |
2471 | case PREINCREMENT_EXPR: | |
88a819be | 2472 | dump_unary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags); |
8d08fdba MS |
2473 | break; |
2474 | ||
2475 | case POSTDECREMENT_EXPR: | |
2476 | case POSTINCREMENT_EXPR: | |
3c1ab1ab GDR |
2477 | pp_cxx_left_paren (pp); |
2478 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
88a819be | 2479 | pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name); |
3c1ab1ab | 2480 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2481 | break; |
2482 | ||
2483 | case NON_LVALUE_EXPR: | |
2484 | /* FIXME: This is a KLUDGE workaround for a parsing problem. There | |
2485 | should be another level of INDIRECT_REF so that I don't have to do | |
2486 | this. */ | |
6467930b | 2487 | if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE) |
8d08fdba MS |
2488 | { |
2489 | tree next = TREE_TYPE (TREE_TYPE (t)); | |
2490 | ||
50e10fa8 | 2491 | while (TYPE_PTR_P (next)) |
8d08fdba | 2492 | next = TREE_TYPE (next); |
bb20cc46 | 2493 | |
8d08fdba MS |
2494 | if (TREE_CODE (next) == FUNCTION_TYPE) |
2495 | { | |
761f0855 | 2496 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
2497 | pp_cxx_left_paren (pp); |
2498 | pp_cxx_star (pp); | |
2499 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 2500 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2501 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2502 | break; |
2503 | } | |
f4f206f4 | 2504 | /* Else fall through. */ |
8d08fdba | 2505 | } |
3c1ab1ab | 2506 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); |
8d08fdba MS |
2507 | break; |
2508 | ||
63a906f0 | 2509 | CASE_CONVERT: |
a4474a38 | 2510 | case IMPLICIT_CONV_EXPR: |
b8ce93da | 2511 | case VIEW_CONVERT_EXPR: |
ffc76561 NS |
2512 | { |
2513 | tree op = TREE_OPERAND (t, 0); | |
75d980ab JM |
2514 | tree ttype = TREE_TYPE (t); |
2515 | tree optype = TREE_TYPE (op); | |
2516 | ||
2517 | if (TREE_CODE (ttype) != TREE_CODE (optype) | |
71a93b08 PC |
2518 | && INDIRECT_TYPE_P (ttype) |
2519 | && INDIRECT_TYPE_P (optype) | |
75d980ab JM |
2520 | && same_type_p (TREE_TYPE (optype), |
2521 | TREE_TYPE (ttype))) | |
2522 | { | |
9f613f06 | 2523 | if (TYPE_REF_P (ttype)) |
e4c4792d JM |
2524 | { |
2525 | STRIP_NOPS (op); | |
2526 | if (TREE_CODE (op) == ADDR_EXPR) | |
2527 | dump_expr (pp, TREE_OPERAND (op, 0), flags); | |
2528 | else | |
2529 | dump_unary_op (pp, "*", t, flags); | |
2530 | } | |
75d980ab | 2531 | else |
3c1ab1ab | 2532 | dump_unary_op (pp, "&", t, flags); |
75d980ab JM |
2533 | } |
2534 | else if (!same_type_p (TREE_TYPE (op), TREE_TYPE (t))) | |
ffc76561 NS |
2535 | { |
2536 | /* It is a cast, but we cannot tell whether it is a | |
2537 | reinterpret or static cast. Use the C style notation. */ | |
2538 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab GDR |
2539 | pp_cxx_left_paren (pp); |
2540 | pp_cxx_left_paren (pp); | |
2541 | dump_type (pp, TREE_TYPE (t), flags); | |
2542 | pp_cxx_right_paren (pp); | |
2543 | dump_expr (pp, op, flags | TFF_EXPR_IN_PARENS); | |
ffc76561 | 2544 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2545 | pp_cxx_right_paren (pp); |
ffc76561 NS |
2546 | } |
2547 | else | |
3c1ab1ab | 2548 | dump_expr (pp, op, flags); |
ffc76561 NS |
2549 | break; |
2550 | } | |
c8094d83 | 2551 | |
8d08fdba | 2552 | case CONSTRUCTOR: |
9a3b49ac MS |
2553 | if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) |
2554 | { | |
50ad9642 | 2555 | tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier); |
9a3b49ac | 2556 | |
c4372ef4 | 2557 | if (integer_zerop (idx)) |
e08a8f45 MM |
2558 | { |
2559 | /* A NULL pointer-to-member constant. */ | |
3c1ab1ab GDR |
2560 | pp_cxx_left_paren (pp); |
2561 | pp_cxx_left_paren (pp); | |
2562 | dump_type (pp, TREE_TYPE (t), flags); | |
2563 | pp_cxx_right_paren (pp); | |
2564 | pp_character (pp, '0'); | |
2565 | pp_cxx_right_paren (pp); | |
e08a8f45 MM |
2566 | break; |
2567 | } | |
9541ffee | 2568 | else if (tree_fits_shwi_p (idx)) |
9a3b49ac MS |
2569 | { |
2570 | tree virtuals; | |
2571 | unsigned HOST_WIDE_INT n; | |
2572 | ||
2573 | t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t))); | |
2574 | t = TYPE_METHOD_BASETYPE (t); | |
604a3205 | 2575 | virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t))); |
bb20cc46 | 2576 | |
9439e9a1 | 2577 | n = tree_to_shwi (idx); |
9a3b49ac MS |
2578 | |
2579 | /* Map vtable index back one, to allow for the null pointer to | |
2580 | member. */ | |
2581 | --n; | |
2582 | ||
2583 | while (n > 0 && virtuals) | |
2584 | { | |
2585 | --n; | |
2586 | virtuals = TREE_CHAIN (virtuals); | |
2587 | } | |
2588 | if (virtuals) | |
2589 | { | |
3c1ab1ab | 2590 | dump_expr (pp, BV_FN (virtuals), |
0cbd7506 | 2591 | flags | TFF_EXPR_IN_PARENS); |
9a3b49ac MS |
2592 | break; |
2593 | } | |
2594 | } | |
2595 | } | |
539b471b | 2596 | if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t))) |
3c1ab1ab | 2597 | pp_string (pp, "<lambda closure object>"); |
4038c495 | 2598 | if (TREE_TYPE (t) && EMPTY_CONSTRUCTOR_P (t)) |
f3146d75 | 2599 | { |
3c1ab1ab GDR |
2600 | dump_type (pp, TREE_TYPE (t), 0); |
2601 | pp_cxx_left_paren (pp); | |
2602 | pp_cxx_right_paren (pp); | |
f3146d75 NS |
2603 | } |
2604 | else | |
2605 | { | |
11a36a27 | 2606 | if (!BRACE_ENCLOSED_INITIALIZER_P (t)) |
3c1ab1ab GDR |
2607 | dump_type (pp, TREE_TYPE (t), 0); |
2608 | pp_cxx_left_brace (pp); | |
2609 | dump_expr_init_vec (pp, CONSTRUCTOR_ELTS (t), flags); | |
2610 | pp_cxx_right_brace (pp); | |
f3146d75 | 2611 | } |
c8094d83 | 2612 | |
8d08fdba MS |
2613 | break; |
2614 | ||
51c184be MS |
2615 | case OFFSET_REF: |
2616 | { | |
2617 | tree ob = TREE_OPERAND (t, 0); | |
51924768 | 2618 | if (is_dummy_object (ob)) |
61a127b3 | 2619 | { |
05e0b2f4 JM |
2620 | t = TREE_OPERAND (t, 1); |
2621 | if (TREE_CODE (t) == FUNCTION_DECL) | |
61a127b3 | 2622 | /* A::f */ |
3c1ab1ab | 2623 | dump_expr (pp, t, flags | TFF_EXPR_IN_PARENS); |
05e0b2f4 | 2624 | else if (BASELINK_P (t)) |
848bf88d | 2625 | dump_expr (pp, OVL_FIRST (BASELINK_FUNCTIONS (t)), |
da15dae6 | 2626 | flags | TFF_EXPR_IN_PARENS); |
61a127b3 | 2627 | else |
3c1ab1ab | 2628 | dump_decl (pp, t, flags); |
61a127b3 | 2629 | } |
51c184be MS |
2630 | else |
2631 | { | |
591cb3cf | 2632 | if (INDIRECT_REF_P (ob)) |
bbcec105 | 2633 | { |
3c1ab1ab GDR |
2634 | dump_expr (pp, TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS); |
2635 | pp_cxx_arrow (pp); | |
2636 | pp_cxx_star (pp); | |
bbcec105 JM |
2637 | } |
2638 | else | |
2639 | { | |
3c1ab1ab GDR |
2640 | dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); |
2641 | pp_cxx_dot (pp); | |
2642 | pp_cxx_star (pp); | |
bbcec105 | 2643 | } |
3c1ab1ab | 2644 | dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); |
51c184be MS |
2645 | } |
2646 | break; | |
2647 | } | |
2648 | ||
f84b4be9 | 2649 | case TEMPLATE_PARM_INDEX: |
3c1ab1ab | 2650 | dump_decl (pp, TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS); |
de22184b | 2651 | break; |
5566b478 | 2652 | |
5566b478 | 2653 | case CAST_EXPR: |
e349ee73 MS |
2654 | if (TREE_OPERAND (t, 0) == NULL_TREE |
2655 | || TREE_CHAIN (TREE_OPERAND (t, 0))) | |
e76a2646 | 2656 | { |
3c1ab1ab GDR |
2657 | dump_type (pp, TREE_TYPE (t), flags); |
2658 | pp_cxx_left_paren (pp); | |
2659 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2660 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2661 | } |
2662 | else | |
2663 | { | |
3c1ab1ab GDR |
2664 | pp_cxx_left_paren (pp); |
2665 | dump_type (pp, TREE_TYPE (t), flags); | |
2666 | pp_cxx_right_paren (pp); | |
2667 | pp_cxx_left_paren (pp); | |
2668 | dump_expr_list (pp, TREE_OPERAND (t, 0), flags); | |
2669 | pp_cxx_right_paren (pp); | |
e76a2646 MS |
2670 | } |
2671 | break; | |
2672 | ||
477f6664 | 2673 | case STATIC_CAST_EXPR: |
3c1ab1ab | 2674 | pp_cxx_ws_string (pp, "static_cast"); |
477f6664 JM |
2675 | goto cast; |
2676 | case REINTERPRET_CAST_EXPR: | |
3c1ab1ab | 2677 | pp_cxx_ws_string (pp, "reinterpret_cast"); |
477f6664 JM |
2678 | goto cast; |
2679 | case CONST_CAST_EXPR: | |
3c1ab1ab | 2680 | pp_cxx_ws_string (pp, "const_cast"); |
477f6664 JM |
2681 | goto cast; |
2682 | case DYNAMIC_CAST_EXPR: | |
3c1ab1ab | 2683 | pp_cxx_ws_string (pp, "dynamic_cast"); |
477f6664 | 2684 | cast: |
3c1ab1ab GDR |
2685 | pp_cxx_begin_template_argument_list (pp); |
2686 | dump_type (pp, TREE_TYPE (t), flags); | |
2687 | pp_cxx_end_template_argument_list (pp); | |
2688 | pp_cxx_left_paren (pp); | |
2689 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2690 | pp_cxx_right_paren (pp); | |
477f6664 JM |
2691 | break; |
2692 | ||
5a11e05b | 2693 | case ARROW_EXPR: |
3c1ab1ab GDR |
2694 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
2695 | pp_cxx_arrow (pp); | |
5a11e05b BK |
2696 | break; |
2697 | ||
e76a2646 | 2698 | case SIZEOF_EXPR: |
abff8e06 JM |
2699 | case ALIGNOF_EXPR: |
2700 | if (TREE_CODE (t) == SIZEOF_EXPR) | |
3c1ab1ab | 2701 | pp_cxx_ws_string (pp, "sizeof"); |
bb20cc46 | 2702 | else |
abff8e06 | 2703 | { |
50bc768d | 2704 | gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR); |
3c1ab1ab | 2705 | pp_cxx_ws_string (pp, "__alignof__"); |
abff8e06 | 2706 | } |
a1e03bc5 JM |
2707 | op = TREE_OPERAND (t, 0); |
2708 | if (PACK_EXPANSION_P (op)) | |
2709 | { | |
3c1ab1ab | 2710 | pp_string (pp, "..."); |
a1e03bc5 JM |
2711 | op = PACK_EXPANSION_PATTERN (op); |
2712 | } | |
3c1ab1ab GDR |
2713 | pp_cxx_whitespace (pp); |
2714 | pp_cxx_left_paren (pp); | |
0d23cf7a | 2715 | if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t)) |
3c1ab1ab | 2716 | dump_type (pp, TREE_TYPE (op), flags); |
0d23cf7a | 2717 | else if (TYPE_P (TREE_OPERAND (t, 0))) |
3c1ab1ab | 2718 | dump_type (pp, op, flags); |
e76a2646 | 2719 | else |
3c1ab1ab GDR |
2720 | dump_expr (pp, op, flags); |
2721 | pp_cxx_right_paren (pp); | |
e76a2646 | 2722 | break; |
5566b478 | 2723 | |
c154b3d8 | 2724 | case AT_ENCODE_EXPR: |
3c1ab1ab GDR |
2725 | pp_cxx_ws_string (pp, "@encode"); |
2726 | pp_cxx_whitespace (pp); | |
2727 | pp_cxx_left_paren (pp); | |
2728 | dump_type (pp, TREE_OPERAND (t, 0), flags); | |
2729 | pp_cxx_right_paren (pp); | |
c154b3d8 NP |
2730 | break; |
2731 | ||
3a55fb4c | 2732 | case NOEXCEPT_EXPR: |
3c1ab1ab GDR |
2733 | pp_cxx_ws_string (pp, "noexcept"); |
2734 | pp_cxx_whitespace (pp); | |
2735 | pp_cxx_left_paren (pp); | |
2736 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
2737 | pp_cxx_right_paren (pp); | |
3a55fb4c JM |
2738 | break; |
2739 | ||
19948e32 GDR |
2740 | case REALPART_EXPR: |
2741 | case IMAGPART_EXPR: | |
88a819be | 2742 | pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name); |
3c1ab1ab GDR |
2743 | pp_cxx_whitespace (pp); |
2744 | dump_expr (pp, TREE_OPERAND (t, 0), flags); | |
19948e32 GDR |
2745 | break; |
2746 | ||
7b49e3da | 2747 | case DEFERRED_PARSE: |
3c1ab1ab | 2748 | pp_string (pp, M_("<unparsed>")); |
da20811c JM |
2749 | break; |
2750 | ||
6748b643 | 2751 | case TRY_CATCH_EXPR: |
6748b643 | 2752 | case CLEANUP_POINT_EXPR: |
3c1ab1ab | 2753 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
6748b643 JM |
2754 | break; |
2755 | ||
40242ccf | 2756 | case PSEUDO_DTOR_EXPR: |
c0c66032 | 2757 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
3c1ab1ab | 2758 | pp_cxx_dot (pp); |
c0c66032 PC |
2759 | if (TREE_OPERAND (t, 1)) |
2760 | { | |
2761 | dump_type (pp, TREE_OPERAND (t, 1), flags); | |
2762 | pp_cxx_colon_colon (pp); | |
2763 | } | |
3c1ab1ab | 2764 | pp_cxx_complement (pp); |
c0c66032 | 2765 | dump_type (pp, TREE_OPERAND (t, 2), flags); |
40242ccf MM |
2766 | break; |
2767 | ||
7ac7b28f | 2768 | case TEMPLATE_ID_EXPR: |
3c1ab1ab | 2769 | dump_decl (pp, t, flags); |
7ac7b28f MM |
2770 | break; |
2771 | ||
744b12b6 | 2772 | case BIND_EXPR: |
558475f0 | 2773 | case STMT_EXPR: |
aee5c3ed | 2774 | case EXPR_STMT: |
744b12b6 | 2775 | case STATEMENT_LIST: |
558475f0 MM |
2776 | /* We don't yet have a way of dumping statements in a |
2777 | human-readable format. */ | |
3c1ab1ab | 2778 | pp_string (pp, "({...})"); |
558475f0 MM |
2779 | break; |
2780 | ||
0045e0bc | 2781 | case LOOP_EXPR: |
3c1ab1ab GDR |
2782 | pp_string (pp, "while (1) { "); |
2783 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2784 | pp_cxx_right_brace (pp); | |
0045e0bc MM |
2785 | break; |
2786 | ||
2787 | case EXIT_EXPR: | |
3c1ab1ab GDR |
2788 | pp_string (pp, "if ("); |
2789 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
2790 | pp_string (pp, ") break; "); | |
0045e0bc MM |
2791 | break; |
2792 | ||
a723baf1 | 2793 | case BASELINK: |
3c1ab1ab | 2794 | dump_expr (pp, BASELINK_FUNCTIONS (t), flags & ~TFF_EXPR_IN_PARENS); |
a723baf1 MM |
2795 | break; |
2796 | ||
98ed3906 | 2797 | case EMPTY_CLASS_EXPR: |
3c1ab1ab GDR |
2798 | dump_type (pp, TREE_TYPE (t), flags); |
2799 | pp_cxx_left_paren (pp); | |
2800 | pp_cxx_right_paren (pp); | |
98ed3906 GDR |
2801 | break; |
2802 | ||
d17811fd | 2803 | case NON_DEPENDENT_EXPR: |
3c1ab1ab | 2804 | dump_expr (pp, TREE_OPERAND (t, 0), flags); |
d17811fd | 2805 | break; |
00595019 | 2806 | |
31d40008 | 2807 | case ARGUMENT_PACK_SELECT: |
3c1ab1ab | 2808 | dump_template_argument (pp, ARGUMENT_PACK_SELECT_FROM_PACK (t), flags); |
31d40008 PC |
2809 | break; |
2810 | ||
5a023baa GDR |
2811 | case RECORD_TYPE: |
2812 | case UNION_TYPE: | |
2813 | case ENUMERAL_TYPE: | |
2814 | case REAL_TYPE: | |
2815 | case VOID_TYPE: | |
1e2d8575 | 2816 | case OPAQUE_TYPE: |
5a023baa GDR |
2817 | case BOOLEAN_TYPE: |
2818 | case INTEGER_TYPE: | |
2819 | case COMPLEX_TYPE: | |
2820 | case VECTOR_TYPE: | |
06756ed9 | 2821 | case DECLTYPE_TYPE: |
3c1ab1ab | 2822 | pp_type_specifier_seq (pp, t); |
5a023baa GDR |
2823 | break; |
2824 | ||
2825 | case TYPENAME_TYPE: | |
2826 | /* We get here when we want to print a dependent type as an | |
2827 | id-expression, without any disambiguator decoration. */ | |
20059c8b | 2828 | pp->id_expression (t); |
5a023baa GDR |
2829 | break; |
2830 | ||
0a8fc247 | 2831 | case TEMPLATE_TYPE_PARM: |
fcb13a10 | 2832 | case TEMPLATE_TEMPLATE_PARM: |
0a8fc247 | 2833 | case BOUND_TEMPLATE_TEMPLATE_PARM: |
3c1ab1ab | 2834 | dump_type (pp, t, flags); |
0a8fc247 PC |
2835 | break; |
2836 | ||
e74392f0 | 2837 | case TRAIT_EXPR: |
3c1ab1ab | 2838 | pp_cxx_trait_expression (pp, t); |
e74392f0 PC |
2839 | break; |
2840 | ||
fdb8f418 | 2841 | case VA_ARG_EXPR: |
3c1ab1ab | 2842 | pp_cxx_va_arg_expression (pp, t); |
fdb8f418 PC |
2843 | break; |
2844 | ||
094a5fe2 | 2845 | case OFFSETOF_EXPR: |
3c1ab1ab | 2846 | pp_cxx_offsetof_expression (pp, t); |
094a5fe2 JJ |
2847 | break; |
2848 | ||
be845b04 JJ |
2849 | case ADDRESSOF_EXPR: |
2850 | pp_cxx_addressof_expression (pp, t); | |
2851 | break; | |
2852 | ||
066f956c | 2853 | case SCOPE_REF: |
3c1ab1ab | 2854 | dump_decl (pp, t, flags); |
e1faa105 JM |
2855 | break; |
2856 | ||
066f956c | 2857 | case EXPR_PACK_EXPANSION: |
f078dc7d AS |
2858 | case UNARY_LEFT_FOLD_EXPR: |
2859 | case UNARY_RIGHT_FOLD_EXPR: | |
2860 | case BINARY_LEFT_FOLD_EXPR: | |
2861 | case BINARY_RIGHT_FOLD_EXPR: | |
066f956c | 2862 | case TYPEID_EXPR: |
1e3eacc7 JJ |
2863 | case MEMBER_REF: |
2864 | case DOTSTAR_EXPR: | |
a84a98ca PC |
2865 | case NEW_EXPR: |
2866 | case VEC_NEW_EXPR: | |
62081704 PC |
2867 | case DELETE_EXPR: |
2868 | case VEC_DELETE_EXPR: | |
066f956c | 2869 | case MODOP_EXPR: |
214452b9 | 2870 | case ABS_EXPR: |
e28fadbc | 2871 | case ABSU_EXPR: |
998ceda2 | 2872 | case CONJ_EXPR: |
e94384db | 2873 | case VECTOR_CST: |
998ceda2 | 2874 | case FIXED_CST: |
07874f1f JJ |
2875 | case UNORDERED_EXPR: |
2876 | case ORDERED_EXPR: | |
2877 | case UNLT_EXPR: | |
2878 | case UNLE_EXPR: | |
2879 | case UNGT_EXPR: | |
2880 | case UNGE_EXPR: | |
2881 | case UNEQ_EXPR: | |
2882 | case LTGT_EXPR: | |
66e68191 | 2883 | case COMPLEX_EXPR: |
5eddced5 | 2884 | case BIT_FIELD_REF: |
1fae3e66 PC |
2885 | case FIX_TRUNC_EXPR: |
2886 | case FLOAT_EXPR: | |
20059c8b | 2887 | pp->expression (t); |
62081704 PC |
2888 | break; |
2889 | ||
6f536f74 JJ |
2890 | case TRUTH_AND_EXPR: |
2891 | case TRUTH_OR_EXPR: | |
2892 | case TRUTH_XOR_EXPR: | |
2893 | if (flags & TFF_EXPR_IN_PARENS) | |
3c1ab1ab | 2894 | pp_cxx_left_paren (pp); |
20059c8b | 2895 | pp->expression (t); |
6f536f74 | 2896 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2897 | pp_cxx_right_paren (pp); |
6f536f74 JJ |
2898 | break; |
2899 | ||
89ab8ba0 | 2900 | case OBJ_TYPE_REF: |
3c1ab1ab | 2901 | dump_expr (pp, resolve_virtual_fun_from_obj_type_ref (t), flags); |
89ab8ba0 JJ |
2902 | break; |
2903 | ||
f030a1dc | 2904 | case LAMBDA_EXPR: |
3c1ab1ab | 2905 | pp_string (pp, M_("<lambda>")); |
f030a1dc PC |
2906 | break; |
2907 | ||
10c6dc8e | 2908 | case PAREN_EXPR: |
3c1ab1ab GDR |
2909 | pp_cxx_left_paren (pp); |
2910 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2911 | pp_cxx_right_paren (pp); | |
10c6dc8e JM |
2912 | break; |
2913 | ||
971e17ff AS |
2914 | case REQUIRES_EXPR: |
2915 | pp_cxx_requires_expr (cxx_pp, t); | |
2916 | break; | |
2917 | ||
2918 | case SIMPLE_REQ: | |
2919 | pp_cxx_simple_requirement (cxx_pp, t); | |
2920 | break; | |
2921 | ||
2922 | case TYPE_REQ: | |
2923 | pp_cxx_type_requirement (cxx_pp, t); | |
2924 | break; | |
2925 | ||
2926 | case COMPOUND_REQ: | |
2927 | pp_cxx_compound_requirement (cxx_pp, t); | |
2928 | break; | |
2929 | ||
2930 | case NESTED_REQ: | |
2931 | pp_cxx_nested_requirement (cxx_pp, t); | |
2932 | break; | |
2933 | ||
cb57504a | 2934 | case ATOMIC_CONSTR: |
f078dc7d | 2935 | case CHECK_CONSTR: |
971e17ff AS |
2936 | case CONJ_CONSTR: |
2937 | case DISJ_CONSTR: | |
cb57504a JM |
2938 | { |
2939 | pp_cxx_constraint (cxx_pp, t); | |
2940 | break; | |
2941 | } | |
971e17ff | 2942 | |
3e605b20 JM |
2943 | case PLACEHOLDER_EXPR: |
2944 | pp_string (pp, M_("*this")); | |
2945 | break; | |
2946 | ||
d6e3e8a5 MP |
2947 | case TREE_LIST: |
2948 | dump_expr_list (pp, t, flags); | |
2949 | break; | |
2950 | ||
8d08fdba MS |
2951 | /* This list is incomplete, but should suffice for now. |
2952 | It is very important that `sorry' does not call | |
2953 | `report_error_function'. That could cause an infinite loop. */ | |
2954 | default: | |
3c1ab1ab | 2955 | pp_unsupported_tree (pp, t); |
295844f6 | 2956 | /* Fall through. */ |
8d08fdba | 2957 | case ERROR_MARK: |
3c1ab1ab | 2958 | pp_string (pp, M_("<expression error>")); |
8d08fdba MS |
2959 | break; |
2960 | } | |
2961 | } | |
2962 | ||
2963 | static void | |
3c1ab1ab GDR |
2964 | dump_binary_op (cxx_pretty_printer *pp, const char *opstring, tree t, |
2965 | int flags) | |
8d08fdba | 2966 | { |
3c1ab1ab GDR |
2967 | pp_cxx_left_paren (pp); |
2968 | dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); | |
2969 | pp_cxx_whitespace (pp); | |
2adeacc9 | 2970 | if (opstring) |
3c1ab1ab | 2971 | pp_cxx_ws_string (pp, opstring); |
2adeacc9 | 2972 | else |
3c1ab1ab GDR |
2973 | pp_string (pp, M_("<unknown operator>")); |
2974 | pp_cxx_whitespace (pp); | |
5094c440 JM |
2975 | tree op1 = TREE_OPERAND (t, 1); |
2976 | if (TREE_CODE (t) == POINTER_PLUS_EXPR | |
2977 | && TREE_CODE (op1) == INTEGER_CST | |
2978 | && tree_int_cst_sign_bit (op1)) | |
2979 | /* A pointer minus an integer is represented internally as plus a very | |
2980 | large number, don't expose that to users. */ | |
2981 | op1 = convert (ssizetype, op1); | |
2982 | dump_expr (pp, op1, flags | TFF_EXPR_IN_PARENS); | |
3c1ab1ab | 2983 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2984 | } |
2985 | ||
2986 | static void | |
3c1ab1ab | 2987 | dump_unary_op (cxx_pretty_printer *pp, const char *opstring, tree t, int flags) |
8d08fdba | 2988 | { |
761f0855 | 2989 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab GDR |
2990 | pp_cxx_left_paren (pp); |
2991 | pp_cxx_ws_string (pp, opstring); | |
2992 | dump_expr (pp, TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS); | |
761f0855 | 2993 | if (flags & TFF_EXPR_IN_PARENS) |
3c1ab1ab | 2994 | pp_cxx_right_paren (pp); |
8d08fdba MS |
2995 | } |
2996 | ||
73bbafe5 GDR |
2997 | static void |
2998 | reinit_cxx_pp (void) | |
2999 | { | |
3000 | pp_clear_output_area (cxx_pp); | |
b066401f | 3001 | cxx_pp->padding = pp_none; |
73bbafe5 GDR |
3002 | pp_indentation (cxx_pp) = 0; |
3003 | pp_needs_newline (cxx_pp) = false; | |
d5aa2cf0 | 3004 | cxx_pp->enclosing_scope = current_function_decl; |
73bbafe5 GDR |
3005 | } |
3006 | ||
8ccb81bd GDR |
3007 | /* Same as pp_formatted_text, except the return string is a separate |
3008 | copy and has a GGC storage duration, e.g. an indefinite lifetime. */ | |
3009 | ||
3010 | inline const char * | |
3011 | pp_ggc_formatted_text (pretty_printer *pp) | |
3012 | { | |
3013 | return ggc_strdup (pp_formatted_text (pp)); | |
3014 | } | |
73bbafe5 | 3015 | |
761f0855 | 3016 | /* Exported interface to stringifying types, exprs and decls under TFF_* |
9e93bc9d | 3017 | control. */ |
4995028c | 3018 | |
e1def31b | 3019 | const char * |
3f8548e7 | 3020 | type_as_string (tree typ, int flags) |
f41c4af3 JM |
3021 | { |
3022 | reinit_cxx_pp (); | |
3023 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 3024 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 3025 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
3026 | } |
3027 | ||
3028 | const char * | |
3029 | type_as_string_translate (tree typ, int flags) | |
8d08fdba | 3030 | { |
73bbafe5 | 3031 | reinit_cxx_pp (); |
3c1ab1ab | 3032 | dump_type (cxx_pp, typ, flags); |
8ccb81bd | 3033 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3034 | } |
3035 | ||
e1def31b | 3036 | const char * |
3f8548e7 | 3037 | expr_as_string (tree decl, int flags) |
8d08fdba | 3038 | { |
73bbafe5 | 3039 | reinit_cxx_pp (); |
f41c4af3 | 3040 | pp_translate_identifiers (cxx_pp) = false; |
3c1ab1ab | 3041 | dump_expr (cxx_pp, decl, flags); |
8ccb81bd | 3042 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3043 | } |
3044 | ||
7496cd5b SA |
3045 | /* Wrap decl_as_string with options appropriate for dwarf. */ |
3046 | ||
3047 | const char * | |
3048 | decl_as_dwarf_string (tree decl, int flags) | |
3049 | { | |
3050 | const char *name; | |
3051 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
9c582551 | 3052 | here will be adequate to get the desired behavior. */ |
b066401f | 3053 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
3054 | name = decl_as_string (decl, flags); |
3055 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 3056 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
3057 | return name; |
3058 | } | |
3059 | ||
e1def31b | 3060 | const char * |
3f8548e7 | 3061 | decl_as_string (tree decl, int flags) |
f41c4af3 JM |
3062 | { |
3063 | reinit_cxx_pp (); | |
3064 | pp_translate_identifiers (cxx_pp) = false; | |
3c1ab1ab | 3065 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3066 | return pp_ggc_formatted_text (cxx_pp); |
f41c4af3 JM |
3067 | } |
3068 | ||
3069 | const char * | |
3070 | decl_as_string_translate (tree decl, int flags) | |
8d08fdba | 3071 | { |
73bbafe5 | 3072 | reinit_cxx_pp (); |
3c1ab1ab | 3073 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3074 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3075 | } |
3076 | ||
7496cd5b SA |
3077 | /* Wrap lang_decl_name with options appropriate for dwarf. */ |
3078 | ||
3079 | const char * | |
3080 | lang_decl_dwarf_name (tree decl, int v, bool translate) | |
3081 | { | |
3082 | const char *name; | |
3083 | /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag | |
9c582551 | 3084 | here will be adequate to get the desired behavior. */ |
b066401f | 3085 | cxx_pp->flags |= pp_c_flag_gnu_v3; |
7496cd5b SA |
3086 | name = lang_decl_name (decl, v, translate); |
3087 | /* Subsequent calls to the pretty printer shouldn't use this style. */ | |
b066401f | 3088 | cxx_pp->flags &= ~pp_c_flag_gnu_v3; |
7496cd5b SA |
3089 | return name; |
3090 | } | |
3091 | ||
7afff7cf | 3092 | /* Generate the three forms of printable names for cxx_printable_name. */ |
2ba25f50 | 3093 | |
e1def31b | 3094 | const char * |
f41c4af3 | 3095 | lang_decl_name (tree decl, int v, bool translate) |
2ba25f50 MS |
3096 | { |
3097 | if (v >= 2) | |
f41c4af3 JM |
3098 | return (translate |
3099 | ? decl_as_string_translate (decl, TFF_DECL_SPECIFIERS) | |
3100 | : decl_as_string (decl, TFF_DECL_SPECIFIERS)); | |
2ba25f50 | 3101 | |
73bbafe5 | 3102 | reinit_cxx_pp (); |
f41c4af3 | 3103 | pp_translate_identifiers (cxx_pp) = translate; |
b96fe38e DS |
3104 | if (v == 1 |
3105 | && (DECL_CLASS_SCOPE_P (decl) | |
3106 | || (DECL_NAMESPACE_SCOPE_P (decl) | |
3107 | && CP_DECL_CONTEXT (decl) != global_namespace))) | |
2ba25f50 | 3108 | { |
3c1ab1ab | 3109 | dump_type (cxx_pp, CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER); |
73bbafe5 | 3110 | pp_cxx_colon_colon (cxx_pp); |
2ba25f50 MS |
3111 | } |
3112 | ||
3113 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3c1ab1ab | 3114 | dump_function_name (cxx_pp, decl, TFF_PLAIN_IDENTIFIER); |
7496cd5b SA |
3115 | else if ((DECL_NAME (decl) == NULL_TREE) |
3116 | && TREE_CODE (decl) == NAMESPACE_DECL) | |
3c1ab1ab | 3117 | dump_decl (cxx_pp, decl, TFF_PLAIN_IDENTIFIER | TFF_UNQUALIFIED_NAME); |
2ba25f50 | 3118 | else |
3c1ab1ab | 3119 | dump_decl (cxx_pp, DECL_NAME (decl), TFF_PLAIN_IDENTIFIER); |
2ba25f50 | 3120 | |
8ccb81bd | 3121 | return pp_ggc_formatted_text (cxx_pp); |
2ba25f50 | 3122 | } |
2ba25f50 | 3123 | |
dee15844 JM |
3124 | /* Return the location of a tree passed to %+ formats. */ |
3125 | ||
501c95ff | 3126 | location_t |
9a472a42 | 3127 | location_of (tree t) |
8d08fdba | 3128 | { |
aeda100f | 3129 | if (TYPE_P (t)) |
06be4922 JM |
3130 | { |
3131 | t = TYPE_MAIN_DECL (t); | |
3132 | if (t == NULL_TREE) | |
3133 | return input_location; | |
3134 | } | |
8f032717 | 3135 | else if (TREE_CODE (t) == OVERLOAD) |
848bf88d | 3136 | t = OVL_FIRST (t); |
c8094d83 | 3137 | |
9e115cec JM |
3138 | if (DECL_P (t)) |
3139 | return DECL_SOURCE_LOCATION (t); | |
7b49e3da MP |
3140 | if (TREE_CODE (t) == DEFERRED_PARSE) |
3141 | return defparse_location (t); | |
f9d0ca40 | 3142 | return cp_expr_loc_or_input_loc (t); |
8d08fdba MS |
3143 | } |
3144 | ||
33bd39a2 | 3145 | /* Now the interfaces from error et al to dump_type et al. Each takes an |
761f0855 | 3146 | on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_ |
9e93bc9d NS |
3147 | function. */ |
3148 | ||
3149 | static const char * | |
3f8548e7 | 3150 | decl_to_string (tree decl, int verbose) |
9e93bc9d | 3151 | { |
761f0855 | 3152 | int flags = 0; |
d67cdbc3 | 3153 | |
9e93bc9d NS |
3154 | if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE |
3155 | || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE) | |
761f0855 | 3156 | flags = TFF_CLASS_KEY_OR_ENUM; |
9e93bc9d | 3157 | if (verbose) |
4a386498 | 3158 | flags |= TFF_DECL_SPECIFIERS; |
9e93bc9d | 3159 | else if (TREE_CODE (decl) == FUNCTION_DECL) |
761f0855 GDR |
3160 | flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE; |
3161 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 3162 | |
73bbafe5 | 3163 | reinit_cxx_pp (); |
3c1ab1ab | 3164 | dump_decl (cxx_pp, decl, flags); |
8ccb81bd | 3165 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3166 | } |
3167 | ||
7e2de6df | 3168 | const char * |
4e3f84b7 | 3169 | expr_to_string (tree decl) |
9e93bc9d | 3170 | { |
73bbafe5 | 3171 | reinit_cxx_pp (); |
3c1ab1ab | 3172 | dump_expr (cxx_pp, decl, 0); |
8ccb81bd | 3173 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3174 | } |
3175 | ||
3176 | static const char * | |
3f8548e7 | 3177 | fndecl_to_string (tree fndecl, int verbose) |
9e93bc9d | 3178 | { |
761f0855 | 3179 | int flags; |
bb20cc46 | 3180 | |
e1f0e7a6 MM |
3181 | flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS |
3182 | | TFF_TEMPLATE_HEADER; | |
9e93bc9d | 3183 | if (verbose) |
761f0855 | 3184 | flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS; |
73bbafe5 | 3185 | reinit_cxx_pp (); |
3c1ab1ab | 3186 | dump_decl (cxx_pp, fndecl, flags); |
8ccb81bd | 3187 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3188 | } |
3189 | ||
3190 | ||
3191 | static const char * | |
4e3f84b7 | 3192 | code_to_string (enum tree_code c) |
8d08fdba | 3193 | { |
5806f481 | 3194 | return get_tree_code_name (c); |
8d08fdba MS |
3195 | } |
3196 | ||
421844e7 | 3197 | const char * |
4e3f84b7 | 3198 | language_to_string (enum languages c) |
8d08fdba MS |
3199 | { |
3200 | switch (c) | |
3201 | { | |
3202 | case lang_c: | |
3203 | return "C"; | |
3204 | ||
3205 | case lang_cplusplus: | |
3206 | return "C++"; | |
3207 | ||
3208 | default: | |
8dc2b103 | 3209 | gcc_unreachable (); |
8d08fdba | 3210 | } |
6aed477a | 3211 | return NULL; |
8d08fdba MS |
3212 | } |
3213 | ||
3214 | /* Return the proper printed version of a parameter to a C++ function. */ | |
e92cc029 | 3215 | |
9e93bc9d | 3216 | static const char * |
4e3f84b7 | 3217 | parm_to_string (int p) |
8d08fdba | 3218 | { |
73bbafe5 | 3219 | reinit_cxx_pp (); |
8d08fdba | 3220 | if (p < 0) |
b6fe0bb8 | 3221 | pp_string (cxx_pp, "'this'"); |
4e3f84b7 | 3222 | else |
b6fe0bb8 | 3223 | pp_decimal_int (cxx_pp, p + 1); |
8ccb81bd | 3224 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba MS |
3225 | } |
3226 | ||
9e93bc9d | 3227 | static const char * |
88a819be | 3228 | op_to_string (bool assop, enum tree_code p) |
8d08fdba | 3229 | { |
88a819be | 3230 | tree id = ovl_op_identifier (assop, p); |
f41c4af3 | 3231 | return id ? IDENTIFIER_POINTER (id) : M_("<unknown>"); |
8d08fdba MS |
3232 | } |
3233 | ||
ce95abc4 DM |
3234 | /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE. |
3235 | ||
3236 | If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the | |
3237 | string in appropriate places, and *QUOTE is written to with false | |
3238 | to suppress pp_format's trailing close quote so that e.g. | |
3239 | foo_typedef {aka underlying_foo} {enum} | |
3240 | can be printed by "%qT" as: | |
3241 | `foo_typedef' {aka `underlying_foo'} {enum} | |
3242 | rather than: | |
3243 | `foo_typedef {aka underlying_foo} {enum}' | |
3244 | When adding such quotes, if POSTPROCESSED is true (for handling %H and %I) | |
3245 | then a leading open quote will be added, whereas if POSTPROCESSED is false | |
3246 | (for handling %T) then any leading quote has already been added by | |
3247 | pp_format, or is not needed due to QUOTE being NULL (for template arguments | |
3248 | within %H and %I). | |
3249 | ||
3250 | SHOW_COLOR is used to determine the colorization of any quotes that | |
3251 | are added. */ | |
3252 | ||
9e93bc9d | 3253 | static const char * |
ce95abc4 DM |
3254 | type_to_string (tree typ, int verbose, bool postprocessed, bool *quote, |
3255 | bool show_color) | |
9e93bc9d | 3256 | { |
b6fe0bb8 | 3257 | int flags = 0; |
9e93bc9d | 3258 | if (verbose) |
761f0855 GDR |
3259 | flags |= TFF_CLASS_KEY_OR_ENUM; |
3260 | flags |= TFF_TEMPLATE_HEADER; | |
bb20cc46 | 3261 | |
73bbafe5 | 3262 | reinit_cxx_pp (); |
ce95abc4 DM |
3263 | |
3264 | if (postprocessed && quote && *quote) | |
3265 | pp_begin_quote (cxx_pp, show_color); | |
3266 | ||
3267 | struct obstack *ob = pp_buffer (cxx_pp)->obstack; | |
3268 | int type_start, type_len; | |
3269 | type_start = obstack_object_size (ob); | |
3270 | ||
3c1ab1ab | 3271 | dump_type (cxx_pp, typ, flags); |
ce95abc4 DM |
3272 | |
3273 | /* Remember the end of the initial dump. */ | |
3274 | type_len = obstack_object_size (ob) - type_start; | |
3275 | ||
0d3128d6 JM |
3276 | /* If we're printing a type that involves typedefs, also print the |
3277 | stripped version. But sometimes the stripped version looks | |
3278 | exactly the same, so we don't want it after all. To avoid printing | |
3279 | it in that case, we play ugly obstack games. */ | |
8722cdee JM |
3280 | if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ) |
3281 | && !uses_template_parms (typ)) | |
3282 | { | |
045af2d7 | 3283 | int aka_start, aka_len; char *p; |
10bce48f | 3284 | tree aka = strip_typedefs (typ, NULL, STF_USER_VISIBLE); |
ce95abc4 DM |
3285 | if (quote && *quote) |
3286 | pp_end_quote (cxx_pp, show_color); | |
8722cdee JM |
3287 | pp_string (cxx_pp, " {aka"); |
3288 | pp_cxx_whitespace (cxx_pp); | |
ce95abc4 DM |
3289 | if (quote && *quote) |
3290 | pp_begin_quote (cxx_pp, show_color); | |
0d3128d6 JM |
3291 | /* And remember the start of the aka dump. */ |
3292 | aka_start = obstack_object_size (ob); | |
3c1ab1ab | 3293 | dump_type (cxx_pp, aka, flags); |
045af2d7 | 3294 | aka_len = obstack_object_size (ob) - aka_start; |
ce95abc4 DM |
3295 | if (quote && *quote) |
3296 | pp_end_quote (cxx_pp, show_color); | |
07838b13 | 3297 | pp_right_brace (cxx_pp); |
0d3128d6 | 3298 | p = (char*)obstack_base (ob); |
ce95abc4 DM |
3299 | /* If they are identical, cut off the aka by unwinding the obstack. */ |
3300 | if (type_len == aka_len | |
3301 | && memcmp (p + type_start, p+aka_start, type_len) == 0) | |
3302 | { | |
3303 | /* We can't add a '\0' here, since we may be adding a closing quote | |
3304 | below, and it would be hidden by the '\0'. | |
3305 | Instead, manually unwind the current object within the obstack | |
3306 | so that the insertion point is at the end of the type, before | |
3307 | the "' {aka". */ | |
3308 | int delta = type_start + type_len - obstack_object_size (ob); | |
3309 | gcc_assert (delta <= 0); | |
3310 | obstack_blank_fast (ob, delta); | |
3311 | } | |
3312 | else | |
3313 | if (quote) | |
3314 | /* No further closing quotes are needed. */ | |
3315 | *quote = false; | |
3316 | } | |
3317 | ||
3318 | if (quote && *quote) | |
3319 | { | |
3320 | pp_end_quote (cxx_pp, show_color); | |
3321 | *quote = false; | |
8722cdee | 3322 | } |
8ccb81bd | 3323 | return pp_ggc_formatted_text (cxx_pp); |
9e93bc9d NS |
3324 | } |
3325 | ||
9e93bc9d | 3326 | static const char * |
3f8548e7 | 3327 | args_to_string (tree p, int verbose) |
8d08fdba | 3328 | { |
761f0855 | 3329 | int flags = 0; |
9e93bc9d | 3330 | if (verbose) |
761f0855 | 3331 | flags |= TFF_CLASS_KEY_OR_ENUM; |
bb20cc46 | 3332 | |
8d08fdba | 3333 | if (p == NULL_TREE) |
c73964b2 | 3334 | return ""; |
8d08fdba | 3335 | |
2f939d94 | 3336 | if (TYPE_P (TREE_VALUE (p))) |
f41c4af3 | 3337 | return type_as_string_translate (p, flags); |
c73964b2 | 3338 | |
73bbafe5 | 3339 | reinit_cxx_pp (); |
c73964b2 MS |
3340 | for (; p; p = TREE_CHAIN (p)) |
3341 | { | |
9a004410 | 3342 | if (null_node_p (TREE_VALUE (p))) |
b02cec6e | 3343 | pp_cxx_ws_string (cxx_pp, "NULL"); |
a6967cc0 | 3344 | else |
3c1ab1ab | 3345 | dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags); |
c73964b2 | 3346 | if (TREE_CHAIN (p)) |
b6fe0bb8 | 3347 | pp_separate_with_comma (cxx_pp); |
c73964b2 | 3348 | } |
8ccb81bd | 3349 | return pp_ggc_formatted_text (cxx_pp); |
8d08fdba | 3350 | } |
f30432d7 | 3351 | |
3ff60975 JM |
3352 | /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P |
3353 | is a TREE_LIST with purpose the TEMPLATE_DECL, value the template | |
3354 | arguments. */ | |
3355 | ||
3356 | static const char * | |
3357 | subst_to_string (tree p) | |
3358 | { | |
3359 | tree decl = TREE_PURPOSE (p); | |
3360 | tree targs = TREE_VALUE (p); | |
3361 | tree tparms = DECL_TEMPLATE_PARMS (decl); | |
3579964b JM |
3362 | int flags = (TFF_DECL_SPECIFIERS|TFF_TEMPLATE_HEADER |
3363 | |TFF_NO_TEMPLATE_BINDINGS); | |
3ff60975 JM |
3364 | |
3365 | if (p == NULL_TREE) | |
3366 | return ""; | |
3367 | ||
3368 | reinit_cxx_pp (); | |
3c1ab1ab | 3369 | dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags); |
753c4989 | 3370 | dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0); |
8ccb81bd | 3371 | return pp_ggc_formatted_text (cxx_pp); |
3ff60975 JM |
3372 | } |
3373 | ||
9e93bc9d | 3374 | static const char * |
3f8548e7 | 3375 | cv_to_string (tree p, int v) |
f30432d7 | 3376 | { |
73bbafe5 | 3377 | reinit_cxx_pp (); |
b066401f | 3378 | cxx_pp->padding = v ? pp_before : pp_none; |
b9b44fb9 | 3379 | pp_cxx_cv_qualifier_seq (cxx_pp, p); |
8ccb81bd | 3380 | return pp_ggc_formatted_text (cxx_pp); |
f30432d7 | 3381 | } |
cb753e49 | 3382 | |
3f04b1bb JM |
3383 | static const char * |
3384 | eh_spec_to_string (tree p, int /*v*/) | |
3385 | { | |
3386 | int flags = 0; | |
3387 | reinit_cxx_pp (); | |
3388 | dump_exception_spec (cxx_pp, p, flags); | |
3389 | return pp_ggc_formatted_text (cxx_pp); | |
3390 | } | |
3391 | ||
7cb32822 NB |
3392 | /* Langhook for print_error_function. */ |
3393 | void | |
c94ed7a1 JJ |
3394 | cxx_print_error_function (diagnostic_context *context, const char *file, |
3395 | diagnostic_info *diagnostic) | |
a72462a4 | 3396 | { |
653fee19 DM |
3397 | char *prefix; |
3398 | if (file) | |
3399 | prefix = xstrdup (file); | |
3400 | else | |
3401 | prefix = NULL; | |
c94ed7a1 | 3402 | lhd_print_error_function (context, file, diagnostic); |
653fee19 | 3403 | pp_set_prefix (context->printer, prefix); |
47b69537 | 3404 | maybe_print_instantiation_context (context); |
a72462a4 GDR |
3405 | } |
3406 | ||
cb753e49 | 3407 | static void |
3f8548e7 | 3408 | cp_diagnostic_starter (diagnostic_context *context, |
0cbd7506 | 3409 | diagnostic_info *diagnostic) |
cb753e49 | 3410 | { |
2a2703a2 | 3411 | diagnostic_report_current_module (context, diagnostic_location (diagnostic)); |
47b69537 GDR |
3412 | cp_print_error_function (context, diagnostic); |
3413 | maybe_print_instantiation_context (context); | |
2bfe0527 | 3414 | maybe_print_constexpr_context (context); |
cb57504a | 3415 | maybe_print_constraint_context (context); |
b066401f | 3416 | pp_set_prefix (context->printer, diagnostic_build_prefix (context, |
243fbddd | 3417 | diagnostic)); |
cb753e49 GDR |
3418 | } |
3419 | ||
cb753e49 GDR |
3420 | /* Print current function onto BUFFER, in the process of reporting |
3421 | a diagnostic message. Called from cp_diagnostic_starter. */ | |
3422 | static void | |
3f8548e7 | 3423 | cp_print_error_function (diagnostic_context *context, |
0cbd7506 | 3424 | diagnostic_info *diagnostic) |
cb753e49 | 3425 | { |
6573e8a0 JM |
3426 | /* If we are in an instantiation context, current_function_decl is likely |
3427 | to be wrong, so just rely on print_instantiation_full_context. */ | |
3428 | if (current_instantiation ()) | |
3429 | return; | |
1906392b AS |
3430 | /* The above is true for constraint satisfaction also. */ |
3431 | if (current_failed_constraint) | |
3432 | return; | |
c94ed7a1 | 3433 | if (diagnostic_last_function_changed (context, diagnostic)) |
cb753e49 | 3434 | { |
653fee19 | 3435 | char *old_prefix = pp_take_prefix (context->printer); |
2a2703a2 | 3436 | const char *file = LOCATION_FILE (diagnostic_location (diagnostic)); |
cf835838 | 3437 | tree abstract_origin = diagnostic_abstract_origin (diagnostic); |
c94ed7a1 | 3438 | char *new_prefix = (file && abstract_origin == NULL) |
e78e8a0b | 3439 | ? file_name_as_prefix (context, file) : NULL; |
cb753e49 | 3440 | |
b066401f | 3441 | pp_set_prefix (context->printer, new_prefix); |
bb20cc46 | 3442 | |
cb753e49 | 3443 | if (current_function_decl == NULL) |
b066401f | 3444 | pp_string (context->printer, _("At global scope:")); |
cb753e49 | 3445 | else |
c94ed7a1 JJ |
3446 | { |
3447 | tree fndecl, ao; | |
3448 | ||
3449 | if (abstract_origin) | |
3450 | { | |
3451 | ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin); | |
c94ed7a1 JJ |
3452 | gcc_assert (TREE_CODE (ao) == FUNCTION_DECL); |
3453 | fndecl = ao; | |
3454 | } | |
3455 | else | |
3456 | fndecl = current_function_decl; | |
3457 | ||
b02cec6e | 3458 | pp_printf (context->printer, function_category (fndecl), |
f41c4af3 | 3459 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3460 | |
3461 | while (abstract_origin) | |
3462 | { | |
3463 | location_t *locus; | |
3464 | tree block = abstract_origin; | |
3465 | ||
3466 | locus = &BLOCK_SOURCE_LOCATION (block); | |
3467 | fndecl = NULL; | |
3468 | block = BLOCK_SUPERCONTEXT (block); | |
3469 | while (block && TREE_CODE (block) == BLOCK | |
3470 | && BLOCK_ABSTRACT_ORIGIN (block)) | |
3471 | { | |
3472 | ao = BLOCK_ABSTRACT_ORIGIN (block); | |
c94ed7a1 JJ |
3473 | if (TREE_CODE (ao) == FUNCTION_DECL) |
3474 | { | |
3475 | fndecl = ao; | |
3476 | break; | |
3477 | } | |
3478 | else if (TREE_CODE (ao) != BLOCK) | |
3479 | break; | |
3480 | ||
3481 | block = BLOCK_SUPERCONTEXT (block); | |
3482 | } | |
3483 | if (fndecl) | |
3484 | abstract_origin = block; | |
3485 | else | |
3486 | { | |
3487 | while (block && TREE_CODE (block) == BLOCK) | |
3488 | block = BLOCK_SUPERCONTEXT (block); | |
3489 | ||
9304142e | 3490 | if (block && TREE_CODE (block) == FUNCTION_DECL) |
c94ed7a1 JJ |
3491 | fndecl = block; |
3492 | abstract_origin = NULL; | |
3493 | } | |
3494 | if (fndecl) | |
3495 | { | |
3496 | expanded_location s = expand_location (*locus); | |
b066401f GDR |
3497 | pp_character (context->printer, ','); |
3498 | pp_newline (context->printer); | |
c94ed7a1 JJ |
3499 | if (s.file != NULL) |
3500 | { | |
243fbddd | 3501 | if (context->show_column && s.column != 0) |
c94ed7a1 | 3502 | pp_printf (context->printer, |
4b84d650 | 3503 | _(" inlined from %qs at %r%s:%d:%d%R"), |
f41c4af3 | 3504 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3505 | "locus", s.file, s.line, s.column); |
c94ed7a1 | 3506 | else |
c94ed7a1 | 3507 | pp_printf (context->printer, |
4b84d650 | 3508 | _(" inlined from %qs at %r%s:%d%R"), |
f41c4af3 | 3509 | cxx_printable_name_translate (fndecl, 2), |
4b84d650 | 3510 | "locus", s.file, s.line); |
c94ed7a1 JJ |
3511 | |
3512 | } | |
3513 | else | |
b02cec6e | 3514 | pp_printf (context->printer, _(" inlined from %qs"), |
f41c4af3 | 3515 | cxx_printable_name_translate (fndecl, 2)); |
c94ed7a1 JJ |
3516 | } |
3517 | } | |
b066401f | 3518 | pp_character (context->printer, ':'); |
c94ed7a1 | 3519 | } |
b066401f | 3520 | pp_newline (context->printer); |
47b69537 | 3521 | |
c94ed7a1 | 3522 | diagnostic_set_last_function (context, diagnostic); |
b066401f | 3523 | pp_destroy_prefix (context->printer); |
b6fe0bb8 | 3524 | context->printer->prefix = old_prefix; |
cb753e49 GDR |
3525 | } |
3526 | } | |
3527 | ||
b02cec6e JM |
3528 | /* Returns a description of FUNCTION using standard terminology. The |
3529 | result is a format string of the form "In CATEGORY %qs". */ | |
cb753e49 | 3530 | static const char * |
3f8548e7 | 3531 | function_category (tree fn) |
cb753e49 | 3532 | { |
a406865a RG |
3533 | /* We can get called from the middle-end for diagnostics of function |
3534 | clones. Make sure we have language specific information before | |
3535 | dereferencing it. */ | |
3536 | if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn)) | |
3537 | && DECL_FUNCTION_MEMBER_P (fn)) | |
cb753e49 GDR |
3538 | { |
3539 | if (DECL_STATIC_FUNCTION_P (fn)) | |
b02cec6e | 3540 | return _("In static member function %qs"); |
cb753e49 | 3541 | else if (DECL_COPY_CONSTRUCTOR_P (fn)) |
b02cec6e | 3542 | return _("In copy constructor %qs"); |
cb753e49 | 3543 | else if (DECL_CONSTRUCTOR_P (fn)) |
b02cec6e | 3544 | return _("In constructor %qs"); |
cb753e49 | 3545 | else if (DECL_DESTRUCTOR_P (fn)) |
b02cec6e | 3546 | return _("In destructor %qs"); |
d5f4eddd JM |
3547 | else if (LAMBDA_FUNCTION_P (fn)) |
3548 | return _("In lambda function"); | |
cb753e49 | 3549 | else |
b02cec6e | 3550 | return _("In member function %qs"); |
cb753e49 GDR |
3551 | } |
3552 | else | |
b02cec6e | 3553 | return _("In function %qs"); |
cb753e49 GDR |
3554 | } |
3555 | ||
3556 | /* Report the full context of a current template instantiation, | |
3557 | onto BUFFER. */ | |
3558 | static void | |
3f8548e7 | 3559 | print_instantiation_full_context (diagnostic_context *context) |
cb753e49 | 3560 | { |
e2c3721c | 3561 | struct tinst_level *p = current_instantiation (); |
82a98427 | 3562 | location_t location = input_location; |
c8094d83 | 3563 | |
cb753e49 GDR |
3564 | if (p) |
3565 | { | |
6573e8a0 | 3566 | pp_verbatim (context->printer, |
a56e2f69 | 3567 | p->list_p () |
6573e8a0 JM |
3568 | ? _("%s: In substitution of %qS:\n") |
3569 | : _("%s: In instantiation of %q#D:\n"), | |
3570 | LOCATION_FILE (location), | |
a56e2f69 | 3571 | p->get_node ()); |
6573e8a0 JM |
3572 | |
3573 | location = p->locus; | |
3574 | p = p->next; | |
cb753e49 | 3575 | } |
bb20cc46 | 3576 | |
35773471 | 3577 | print_instantiation_partial_context (context, p, location); |
cb753e49 GDR |
3578 | } |
3579 | ||
f89b94d9 MLI |
3580 | /* Helper function of print_instantiation_partial_context() that |
3581 | prints a single line of instantiation context. */ | |
3582 | ||
cb753e49 | 3583 | static void |
f89b94d9 | 3584 | print_instantiation_partial_context_line (diagnostic_context *context, |
a56e2f69 | 3585 | struct tinst_level *t, |
4b414c93 | 3586 | location_t loc, bool recursive_p) |
cb753e49 | 3587 | { |
4f90d3e0 JH |
3588 | if (loc == UNKNOWN_LOCATION) |
3589 | return; | |
3590 | ||
3591 | expanded_location xloc = expand_location (loc); | |
f89b94d9 | 3592 | |
3ff60975 | 3593 | if (context->show_column) |
4b84d650 JJ |
3594 | pp_verbatim (context->printer, _("%r%s:%d:%d:%R "), |
3595 | "locus", xloc.file, xloc.line, xloc.column); | |
3ff60975 | 3596 | else |
4b84d650 JJ |
3597 | pp_verbatim (context->printer, _("%r%s:%d:%R "), |
3598 | "locus", xloc.file, xloc.line); | |
3ff60975 JM |
3599 | |
3600 | if (t != NULL) | |
4b414c93 | 3601 | { |
a56e2f69 | 3602 | if (t->list_p ()) |
4b414c93 MLI |
3603 | pp_verbatim (context->printer, |
3604 | recursive_p | |
3ff60975 JM |
3605 | ? _("recursively required by substitution of %qS\n") |
3606 | : _("required by substitution of %qS\n"), | |
a56e2f69 | 3607 | t->get_node ()); |
4b414c93 MLI |
3608 | else |
3609 | pp_verbatim (context->printer, | |
3610 | recursive_p | |
3ff60975 JM |
3611 | ? _("recursively required from %q#D\n") |
3612 | : _("required from %q#D\n"), | |
a56e2f69 | 3613 | t->get_node ()); |
4b414c93 MLI |
3614 | } |
3615 | else | |
3616 | { | |
3ff60975 JM |
3617 | pp_verbatim (context->printer, |
3618 | recursive_p | |
01e1dea3 DM |
3619 | ? _("recursively required from here\n") |
3620 | : _("required from here\n")); | |
4b414c93 | 3621 | } |
f89b94d9 MLI |
3622 | } |
3623 | ||
3624 | /* Same as print_instantiation_full_context but less verbose. */ | |
3625 | ||
3626 | static void | |
3627 | print_instantiation_partial_context (diagnostic_context *context, | |
3628 | struct tinst_level *t0, location_t loc) | |
3629 | { | |
3630 | struct tinst_level *t; | |
3631 | int n_total = 0; | |
3632 | int n; | |
4b414c93 | 3633 | location_t prev_loc = loc; |
f89b94d9 MLI |
3634 | |
3635 | for (t = t0; t != NULL; t = t->next) | |
4b414c93 MLI |
3636 | if (prev_loc != t->locus) |
3637 | { | |
3638 | prev_loc = t->locus; | |
3639 | n_total++; | |
3640 | } | |
f89b94d9 MLI |
3641 | |
3642 | t = t0; | |
3643 | ||
a12bf402 MLI |
3644 | if (template_backtrace_limit |
3645 | && n_total > template_backtrace_limit) | |
cb753e49 | 3646 | { |
a12bf402 MLI |
3647 | int skip = n_total - template_backtrace_limit; |
3648 | int head = template_backtrace_limit / 2; | |
3649 | ||
3650 | /* Avoid skipping just 1. If so, skip 2. */ | |
3651 | if (skip == 1) | |
3652 | { | |
3653 | skip = 2; | |
3654 | head = (template_backtrace_limit - 1) / 2; | |
3655 | } | |
3656 | ||
3657 | for (n = 0; n < head; n++) | |
f89b94d9 MLI |
3658 | { |
3659 | gcc_assert (t != NULL); | |
4b414c93 MLI |
3660 | if (loc != t->locus) |
3661 | print_instantiation_partial_context_line (context, t, loc, | |
3662 | /*recursive_p=*/false); | |
f89b94d9 MLI |
3663 | loc = t->locus; |
3664 | t = t->next; | |
3665 | } | |
a12bf402 | 3666 | if (t != NULL && skip > 0) |
f89b94d9 MLI |
3667 | { |
3668 | expanded_location xloc; | |
3669 | xloc = expand_location (loc); | |
243fbddd | 3670 | if (context->show_column) |
f89b94d9 | 3671 | pp_verbatim (context->printer, |
4b84d650 JJ |
3672 | _("%r%s:%d:%d:%R [ skipping %d instantiation " |
3673 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3674 | "disable ]\n"), | |
3675 | "locus", xloc.file, xloc.line, xloc.column, skip); | |
f89b94d9 MLI |
3676 | else |
3677 | pp_verbatim (context->printer, | |
4b84d650 JJ |
3678 | _("%r%s:%d:%R [ skipping %d instantiation " |
3679 | "contexts, use -ftemplate-backtrace-limit=0 to " | |
3680 | "disable ]\n"), | |
3681 | "locus", xloc.file, xloc.line, skip); | |
f89b94d9 MLI |
3682 | |
3683 | do { | |
4b414c93 MLI |
3684 | loc = t->locus; |
3685 | t = t->next; | |
3686 | } while (t != NULL && --skip > 0); | |
f89b94d9 MLI |
3687 | } |
3688 | } | |
3689 | ||
4b414c93 | 3690 | while (t != NULL) |
f89b94d9 | 3691 | { |
4b414c93 MLI |
3692 | while (t->next != NULL && t->locus == t->next->locus) |
3693 | { | |
3694 | loc = t->locus; | |
3695 | t = t->next; | |
3696 | } | |
3697 | print_instantiation_partial_context_line (context, t, loc, | |
3698 | t->locus == loc); | |
e2c3721c | 3699 | loc = t->locus; |
4b414c93 | 3700 | t = t->next; |
cb753e49 | 3701 | } |
4b414c93 MLI |
3702 | print_instantiation_partial_context_line (context, NULL, loc, |
3703 | /*recursive_p=*/false); | |
cb753e49 GDR |
3704 | } |
3705 | ||
3706 | /* Called from cp_thing to print the template context for an error. */ | |
3707 | static void | |
3f8548e7 | 3708 | maybe_print_instantiation_context (diagnostic_context *context) |
cb753e49 GDR |
3709 | { |
3710 | if (!problematic_instantiation_changed () || current_instantiation () == 0) | |
3711 | return; | |
3712 | ||
3713 | record_last_problematic_instantiation (); | |
47b69537 | 3714 | print_instantiation_full_context (context); |
cb753e49 | 3715 | } |
a1066c99 | 3716 | \f |
2bfe0527 JM |
3717 | /* Report what constexpr call(s) we're trying to expand, if any. */ |
3718 | ||
3719 | void | |
3720 | maybe_print_constexpr_context (diagnostic_context *context) | |
3721 | { | |
9771b263 | 3722 | vec<tree> call_stack = cx_error_context (); |
2bfe0527 JM |
3723 | unsigned ix; |
3724 | tree t; | |
3725 | ||
9771b263 | 3726 | FOR_EACH_VEC_ELT (call_stack, ix, t) |
2bfe0527 JM |
3727 | { |
3728 | expanded_location xloc = expand_location (EXPR_LOCATION (t)); | |
3729 | const char *s = expr_as_string (t, 0); | |
3730 | if (context->show_column) | |
3731 | pp_verbatim (context->printer, | |
84fa214d | 3732 | _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"), |
4b84d650 | 3733 | "locus", xloc.file, xloc.line, xloc.column, s); |
2bfe0527 JM |
3734 | else |
3735 | pp_verbatim (context->printer, | |
84fa214d | 3736 | _("%r%s:%d:%R in %<constexpr%> expansion of %qs"), |
4b84d650 | 3737 | "locus", xloc.file, xloc.line, s); |
b066401f | 3738 | pp_newline (context->printer); |
2bfe0527 JM |
3739 | } |
3740 | } | |
3741 | \f | |
f012c8ef | 3742 | |
cb57504a JM |
3743 | static void |
3744 | print_location (diagnostic_context *context, location_t loc) | |
3745 | { | |
3746 | expanded_location xloc = expand_location (loc); | |
3747 | if (context->show_column) | |
3748 | pp_verbatim (context->printer, _("%r%s:%d:%d:%R "), | |
3749 | "locus", xloc.file, xloc.line, xloc.column); | |
3750 | else | |
3751 | pp_verbatim (context->printer, _("%r%s:%d:%R "), | |
3752 | "locus", xloc.file, xloc.line); | |
3753 | } | |
3754 | ||
cb57504a JM |
3755 | static void |
3756 | print_constrained_decl_info (diagnostic_context *context, tree decl) | |
3757 | { | |
3758 | print_location (context, DECL_SOURCE_LOCATION (decl)); | |
3759 | pp_verbatim (context->printer, "required by the constraints of %q#D\n", decl); | |
3760 | } | |
3761 | ||
3762 | static void | |
3763 | print_concept_check_info (diagnostic_context *context, tree expr, tree map, tree args) | |
3764 | { | |
3765 | gcc_assert (concept_check_p (expr)); | |
3766 | ||
3767 | tree id = unpack_concept_check (expr); | |
3768 | tree tmpl = TREE_OPERAND (id, 0); | |
3769 | if (OVL_P (tmpl)) | |
3770 | tmpl = OVL_FIRST (tmpl); | |
cb57504a JM |
3771 | |
3772 | print_location (context, DECL_SOURCE_LOCATION (tmpl)); | |
828878c3 PP |
3773 | |
3774 | cxx_pretty_printer *pp = (cxx_pretty_printer *)context->printer; | |
3775 | pp_verbatim (pp, "required for the satisfaction of %qE", expr); | |
3776 | if (map && map != error_mark_node) | |
3777 | { | |
3778 | tree subst_map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE); | |
3779 | pp_cxx_parameter_mapping (pp, (subst_map != error_mark_node | |
3780 | ? subst_map : map)); | |
3781 | } | |
3782 | pp_newline (pp); | |
cb57504a JM |
3783 | } |
3784 | ||
3785 | /* Diagnose the entry point into the satisfaction error. Returns the next | |
3786 | context, if any. */ | |
3787 | ||
3788 | static tree | |
3789 | print_constraint_context_head (diagnostic_context *context, tree cxt, tree args) | |
3790 | { | |
3791 | tree src = TREE_VALUE (cxt); | |
3792 | if (!src) | |
3793 | { | |
3794 | print_location (context, input_location); | |
3795 | pp_verbatim (context->printer, "required for constraint satisfaction\n"); | |
3796 | return NULL_TREE; | |
3797 | } | |
3798 | if (DECL_P (src)) | |
3799 | { | |
3800 | print_constrained_decl_info (context, src); | |
3801 | return NULL_TREE; | |
3802 | } | |
3803 | else | |
3804 | { | |
3805 | print_concept_check_info (context, src, TREE_PURPOSE (cxt), args); | |
3806 | return TREE_CHAIN (cxt); | |
3807 | } | |
3808 | } | |
3809 | ||
3810 | static void | |
3811 | print_requires_expression_info (diagnostic_context *context, tree constr, tree args) | |
3812 | { | |
3813 | ||
3814 | tree expr = ATOMIC_CONSTR_EXPR (constr); | |
3815 | tree map = ATOMIC_CONSTR_MAP (constr); | |
3816 | map = tsubst_parameter_mapping (map, args, tf_none, NULL_TREE); | |
3817 | if (map == error_mark_node) | |
3818 | return; | |
cb57504a JM |
3819 | |
3820 | print_location (context, cp_expr_loc_or_input_loc (expr)); | |
3821 | pp_verbatim (context->printer, "in requirements "); | |
3822 | ||
3823 | tree parms = TREE_OPERAND (expr, 0); | |
3824 | if (parms) | |
3825 | pp_verbatim (context->printer, "with "); | |
3826 | while (parms) | |
3827 | { | |
43439d5e PP |
3828 | pp_verbatim (context->printer, "%q#D", parms); |
3829 | if (TREE_CHAIN (parms)) | |
cb57504a | 3830 | pp_separate_with_comma ((cxx_pretty_printer *)context->printer); |
43439d5e | 3831 | parms = TREE_CHAIN (parms); |
cb57504a | 3832 | } |
43439d5e | 3833 | pp_cxx_parameter_mapping ((cxx_pretty_printer *)context->printer, map); |
cb57504a JM |
3834 | |
3835 | pp_verbatim (context->printer, "\n"); | |
3836 | } | |
3837 | ||
3838 | void | |
3839 | maybe_print_single_constraint_context (diagnostic_context *context, tree failed) | |
3840 | { | |
3841 | if (!failed) | |
3842 | return; | |
3843 | ||
3844 | tree constr = TREE_VALUE (failed); | |
3845 | if (!constr || constr == error_mark_node) | |
3846 | return; | |
3847 | tree cxt = CONSTR_CONTEXT (constr); | |
3848 | if (!cxt) | |
3849 | return; | |
3850 | tree args = TREE_PURPOSE (failed); | |
3851 | ||
3852 | /* Print the stack of requirements. */ | |
3853 | cxt = print_constraint_context_head (context, cxt, args); | |
3854 | while (cxt && !DECL_P (TREE_VALUE (cxt))) | |
3855 | { | |
3856 | tree expr = TREE_VALUE (cxt); | |
3857 | tree map = TREE_PURPOSE (cxt); | |
3858 | print_concept_check_info (context, expr, map, args); | |
3859 | cxt = TREE_CHAIN (cxt); | |
3860 | } | |
3861 | ||
3862 | /* For certain constraints, we can provide additional context. */ | |
3863 | if (TREE_CODE (constr) == ATOMIC_CONSTR | |
3864 | && TREE_CODE (ATOMIC_CONSTR_EXPR (constr)) == REQUIRES_EXPR) | |
3865 | print_requires_expression_info (context, constr, args); | |
3866 | } | |
3867 | ||
3868 | void | |
3869 | maybe_print_constraint_context (diagnostic_context *context) | |
3870 | { | |
3871 | if (!current_failed_constraint) | |
3872 | return; | |
3873 | ||
3874 | tree cur = current_failed_constraint; | |
3875 | ||
3876 | /* Recursively print nested contexts. */ | |
3877 | current_failed_constraint = TREE_CHAIN (current_failed_constraint); | |
3878 | if (current_failed_constraint) | |
3879 | maybe_print_constraint_context (context); | |
3880 | ||
3881 | /* Print this context. */ | |
3882 | maybe_print_single_constraint_context (context, cur); | |
3883 | } | |
3884 | ||
f012c8ef DM |
3885 | /* Return true iff TYPE_A and TYPE_B are template types that are |
3886 | meaningful to compare. */ | |
3887 | ||
3888 | static bool | |
3889 | comparable_template_types_p (tree type_a, tree type_b) | |
3890 | { | |
3891 | if (!CLASS_TYPE_P (type_a)) | |
3892 | return false; | |
3893 | if (!CLASS_TYPE_P (type_b)) | |
3894 | return false; | |
3895 | ||
3896 | tree tinfo_a = TYPE_TEMPLATE_INFO (type_a); | |
3897 | tree tinfo_b = TYPE_TEMPLATE_INFO (type_b); | |
3898 | if (!tinfo_a || !tinfo_b) | |
3899 | return false; | |
3900 | ||
3901 | return TI_TEMPLATE (tinfo_a) == TI_TEMPLATE (tinfo_b); | |
3902 | } | |
3903 | ||
3904 | /* Start a new line indented by SPC spaces on PP. */ | |
3905 | ||
3906 | static void | |
3907 | newline_and_indent (pretty_printer *pp, int spc) | |
3908 | { | |
3909 | pp_newline (pp); | |
3910 | for (int i = 0; i < spc; i++) | |
3911 | pp_space (pp); | |
3912 | } | |
3913 | ||
3914 | /* Generate a GC-allocated string for ARG, an expression or type. */ | |
3915 | ||
3916 | static const char * | |
3917 | arg_to_string (tree arg, bool verbose) | |
3918 | { | |
3919 | if (TYPE_P (arg)) | |
ce95abc4 | 3920 | return type_to_string (arg, verbose, true, NULL, false); |
f012c8ef DM |
3921 | else |
3922 | return expr_to_string (arg); | |
3923 | } | |
3924 | ||
3925 | /* Subroutine to type_to_string_with_compare and | |
3926 | print_template_tree_comparison. | |
3927 | ||
3928 | Print a representation of ARG (an expression or type) to PP, | |
3929 | colorizing it as "type-diff" if PP->show_color. */ | |
3930 | ||
3931 | static void | |
3932 | print_nonequal_arg (pretty_printer *pp, tree arg, bool verbose) | |
3933 | { | |
3934 | pp_printf (pp, "%r%s%R", | |
3935 | "type-diff", | |
3936 | (arg | |
3937 | ? arg_to_string (arg, verbose) | |
3938 | : G_("(no argument)"))); | |
3939 | } | |
3940 | ||
3941 | /* Recursively print template TYPE_A to PP, as compared to template TYPE_B. | |
3942 | ||
3943 | The types must satisfy comparable_template_types_p. | |
3944 | ||
3945 | If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but | |
3946 | potentially colorizing/eliding in comparison with TYPE_B. | |
3947 | ||
3948 | For example given types: | |
3949 | vector<map<int,double>> | |
3950 | and | |
3951 | vector<map<int,float>> | |
3952 | then the result on PP would be: | |
3953 | vector<map<[...],double>> | |
3954 | with type elision, and: | |
3955 | vector<map<int,double>> | |
3956 | without type elision. | |
3957 | ||
3958 | In both cases the parts of TYPE that differ from PEER will be colorized | |
3959 | if pp_show_color (pp) is true. In the above example, this would be | |
3960 | "double". | |
3961 | ||
3962 | If INDENT is non-zero, then the types are printed in a tree-like form | |
3963 | which shows both types. In the above example, the result on PP would be: | |
3964 | ||
3965 | vector< | |
3966 | map< | |
3967 | [...], | |
3968 | [double != float]>> | |
3969 | ||
3970 | and without type-elision would be: | |
3971 | ||
3972 | vector< | |
3973 | map< | |
3974 | int, | |
3975 | [double != float]>> | |
3976 | ||
3977 | As before, the differing parts of the types are colorized if | |
3978 | pp_show_color (pp) is true ("double" and "float" in this example). | |
3979 | ||
3980 | Template arguments in which both types are using the default arguments | |
3981 | are not printed; if at least one of the two types is using a non-default | |
3982 | argument, then that argument is printed (or both arguments for the | |
3983 | tree-like print format). */ | |
3984 | ||
3985 | static void | |
3986 | print_template_differences (pretty_printer *pp, tree type_a, tree type_b, | |
3987 | bool verbose, int indent) | |
3988 | { | |
3989 | if (indent) | |
3990 | newline_and_indent (pp, indent); | |
3991 | ||
3992 | tree tinfo_a = TYPE_TEMPLATE_INFO (type_a); | |
3993 | tree tinfo_b = TYPE_TEMPLATE_INFO (type_b); | |
3994 | ||
3995 | pp_printf (pp, "%s<", | |
3996 | IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a)))); | |
3997 | ||
3998 | tree args_a = TI_ARGS (tinfo_a); | |
3999 | tree args_b = TI_ARGS (tinfo_b); | |
4000 | gcc_assert (TREE_CODE (args_a) == TREE_VEC); | |
4001 | gcc_assert (TREE_CODE (args_b) == TREE_VEC); | |
4002 | int flags = 0; | |
4003 | int len_a = get_non_default_template_args_count (args_a, flags); | |
4004 | args_a = INNERMOST_TEMPLATE_ARGS (args_a); | |
4005 | int len_b = get_non_default_template_args_count (args_b, flags); | |
4006 | args_b = INNERMOST_TEMPLATE_ARGS (args_b); | |
4007 | /* Determine the maximum range of args for which non-default template args | |
4008 | were used; beyond this, only default args (if any) were used, and so | |
4009 | they will be equal from this point onwards. | |
4010 | One of the two peers might have used default arguments within this | |
4011 | range, but the other will be using non-default arguments, and so | |
4012 | it's more readable to print both within this range, to highlight | |
4013 | the differences. */ | |
4014 | int len_max = MAX (len_a, len_b); | |
4015 | gcc_assert (TREE_CODE (args_a) == TREE_VEC); | |
4016 | gcc_assert (TREE_CODE (args_b) == TREE_VEC); | |
4017 | for (int idx = 0; idx < len_max; idx++) | |
4018 | { | |
4019 | if (idx) | |
4020 | pp_character (pp, ','); | |
4021 | ||
4022 | tree arg_a = TREE_VEC_ELT (args_a, idx); | |
4023 | tree arg_b = TREE_VEC_ELT (args_b, idx); | |
4024 | if (arg_a == arg_b) | |
4025 | { | |
4026 | if (indent) | |
4027 | newline_and_indent (pp, indent + 2); | |
4028 | /* Can do elision here, printing "[...]". */ | |
4029 | if (flag_elide_type) | |
4030 | pp_string (pp, G_("[...]")); | |
4031 | else | |
4032 | pp_string (pp, arg_to_string (arg_a, verbose)); | |
4033 | } | |
4034 | else | |
4035 | { | |
4036 | int new_indent = indent ? indent + 2 : 0; | |
4037 | if (comparable_template_types_p (arg_a, arg_b)) | |
4038 | print_template_differences (pp, arg_a, arg_b, verbose, new_indent); | |
4039 | else | |
4040 | if (indent) | |
4041 | { | |
4042 | newline_and_indent (pp, indent + 2); | |
4043 | pp_character (pp, '['); | |
4044 | print_nonequal_arg (pp, arg_a, verbose); | |
4045 | pp_string (pp, " != "); | |
4046 | print_nonequal_arg (pp, arg_b, verbose); | |
4047 | pp_character (pp, ']'); | |
4048 | } | |
4049 | else | |
4050 | print_nonequal_arg (pp, arg_a, verbose); | |
4051 | } | |
4052 | } | |
4053 | pp_printf (pp, ">"); | |
4054 | } | |
4055 | ||
4056 | /* As type_to_string, but for a template, potentially colorizing/eliding | |
4057 | in comparison with PEER. | |
4058 | For example, if TYPE is map<int,double> and PEER is map<int,int>, | |
4059 | then the resulting string would be: | |
4060 | map<[...],double> | |
4061 | with type elision, and: | |
4062 | map<int,double> | |
4063 | without type elision. | |
4064 | ||
4065 | In both cases the parts of TYPE that differ from PEER will be colorized | |
4066 | if SHOW_COLOR is true. In the above example, this would be "double". | |
4067 | ||
4068 | Template arguments in which both types are using the default arguments | |
4069 | are not printed; if at least one of the two types is using a non-default | |
4070 | argument, then both arguments are printed. | |
4071 | ||
4072 | The resulting string is in a GC-allocated buffer. */ | |
4073 | ||
4074 | static const char * | |
4075 | type_to_string_with_compare (tree type, tree peer, bool verbose, | |
4076 | bool show_color) | |
4077 | { | |
4078 | pretty_printer inner_pp; | |
4079 | pretty_printer *pp = &inner_pp; | |
4080 | pp_show_color (pp) = show_color; | |
4081 | ||
4082 | print_template_differences (pp, type, peer, verbose, 0); | |
4083 | return pp_ggc_formatted_text (pp); | |
4084 | } | |
4085 | ||
4086 | /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP, | |
4087 | indented by INDENT spaces. | |
4088 | ||
4089 | For example given types: | |
4090 | ||
4091 | vector<map<int,double>> | |
4092 | ||
4093 | and | |
4094 | ||
4095 | vector<map<double,float>> | |
4096 | ||
4097 | the output with type elision would be: | |
4098 | ||
4099 | vector< | |
4100 | map< | |
4101 | [...], | |
4102 | [double != float]>> | |
4103 | ||
4104 | and without type-elision would be: | |
4105 | ||
4106 | vector< | |
4107 | map< | |
4108 | int, | |
4109 | [double != float]>> | |
4110 | ||
4111 | TYPE_A and TYPE_B must both be comparable template types | |
4112 | (as per comparable_template_types_p). | |
4113 | ||
4114 | Template arguments in which both types are using the default arguments | |
4115 | are not printed; if at least one of the two types is using a non-default | |
4116 | argument, then both arguments are printed. */ | |
4117 | ||
4118 | static void | |
4119 | print_template_tree_comparison (pretty_printer *pp, tree type_a, tree type_b, | |
4120 | bool verbose, int indent) | |
4121 | { | |
4122 | print_template_differences (pp, type_a, type_b, verbose, indent); | |
4123 | } | |
4124 | ||
4125 | /* Subroutine for use in a format_postprocessor::handle | |
4126 | implementation. Adds a chunk to the end of | |
4127 | formatted output, so that it will be printed | |
4128 | by pp_output_formatted_text. */ | |
4129 | ||
4130 | static void | |
4131 | append_formatted_chunk (pretty_printer *pp, const char *content) | |
4132 | { | |
4133 | output_buffer *buffer = pp_buffer (pp); | |
4134 | struct chunk_info *chunk_array = buffer->cur_chunk_array; | |
4135 | const char **args = chunk_array->args; | |
4136 | ||
4137 | unsigned int chunk_idx; | |
4138 | for (chunk_idx = 0; args[chunk_idx]; chunk_idx++) | |
4139 | ; | |
4140 | args[chunk_idx++] = content; | |
4141 | args[chunk_idx] = NULL; | |
4142 | } | |
4143 | ||
4144 | /* Create a copy of CONTENT, with quotes added, and, | |
4145 | potentially, with colorization. | |
4146 | No escaped is performed on CONTENT. | |
4147 | The result is in a GC-allocated buffer. */ | |
4148 | ||
4149 | static const char * | |
4150 | add_quotes (const char *content, bool show_color) | |
4151 | { | |
4152 | pretty_printer tmp_pp; | |
4153 | pp_show_color (&tmp_pp) = show_color; | |
4154 | ||
4155 | /* We have to use "%<%s%>" rather than "%qs" here in order to avoid | |
4156 | quoting colorization bytes within the results. */ | |
4157 | pp_printf (&tmp_pp, "%<%s%>", content); | |
4158 | ||
4159 | return pp_ggc_formatted_text (&tmp_pp); | |
4160 | } | |
4161 | ||
4162 | /* If we had %H and %I, and hence deferred printing them, | |
4163 | print them now, storing the result into the chunk_info | |
4164 | for pp_format. Quote them if 'q' was provided. | |
4165 | Also print the difference in tree form, adding it as | |
4166 | an additional chunk. */ | |
4167 | ||
4168 | void | |
4169 | cxx_format_postprocessor::handle (pretty_printer *pp) | |
4170 | { | |
4171 | /* If we have one of %H and %I, the other should have | |
4172 | been present. */ | |
4173 | if (m_type_a.m_tree || m_type_b.m_tree) | |
4174 | { | |
4175 | /* Avoid reentrancy issues by working with a copy of | |
4176 | m_type_a and m_type_b, resetting them now. */ | |
4177 | deferred_printed_type type_a = m_type_a; | |
4178 | deferred_printed_type type_b = m_type_b; | |
4179 | m_type_a = deferred_printed_type (); | |
4180 | m_type_b = deferred_printed_type (); | |
4181 | ||
4182 | gcc_assert (type_a.m_buffer_ptr); | |
4183 | gcc_assert (type_b.m_buffer_ptr); | |
4184 | ||
4185 | bool show_color = pp_show_color (pp); | |
4186 | ||
4187 | const char *type_a_text; | |
4188 | const char *type_b_text; | |
4189 | ||
4190 | if (comparable_template_types_p (type_a.m_tree, type_b.m_tree)) | |
4191 | { | |
4192 | type_a_text | |
4193 | = type_to_string_with_compare (type_a.m_tree, type_b.m_tree, | |
4194 | type_a.m_verbose, show_color); | |
4195 | type_b_text | |
4196 | = type_to_string_with_compare (type_b.m_tree, type_a.m_tree, | |
4197 | type_b.m_verbose, show_color); | |
4198 | ||
4199 | if (flag_diagnostics_show_template_tree) | |
4200 | { | |
4201 | pretty_printer inner_pp; | |
4202 | pp_show_color (&inner_pp) = pp_show_color (pp); | |
4203 | print_template_tree_comparison | |
4204 | (&inner_pp, type_a.m_tree, type_b.m_tree, type_a.m_verbose, 2); | |
4205 | append_formatted_chunk (pp, pp_ggc_formatted_text (&inner_pp)); | |
4206 | } | |
4207 | } | |
4208 | else | |
4209 | { | |
ce95abc4 DM |
4210 | /* If the types were not comparable (or if only one of %H/%I was |
4211 | provided), they are printed normally, and no difference tree | |
4212 | is printed. */ | |
4213 | type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose, | |
4214 | true, &type_a.m_quote, show_color); | |
4215 | type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose, | |
4216 | true, &type_b.m_quote, show_color); | |
f012c8ef DM |
4217 | } |
4218 | ||
4219 | if (type_a.m_quote) | |
4220 | type_a_text = add_quotes (type_a_text, show_color); | |
4221 | *type_a.m_buffer_ptr = type_a_text; | |
4222 | ||
4223 | if (type_b.m_quote) | |
4224 | type_b_text = add_quotes (type_b_text, show_color); | |
4225 | *type_b.m_buffer_ptr = type_b_text; | |
4226 | } | |
4227 | } | |
4228 | ||
4229 | /* Subroutine for handling %H and %I, to support i18n of messages like: | |
4230 | ||
4231 | error_at (loc, "could not convert %qE from %qH to %qI", | |
4232 | expr, type_a, type_b); | |
4233 | ||
4234 | so that we can print things like: | |
4235 | ||
4236 | could not convert 'foo' from 'map<int,double>' to 'map<int,int>' | |
4237 | ||
4238 | and, with type-elision: | |
4239 | ||
4240 | could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>' | |
4241 | ||
4242 | (with color-coding of the differences between the types). | |
4243 | ||
4244 | The %H and %I format codes are peers: both must be present, | |
4245 | and they affect each other. Hence to handle them, we must | |
4246 | delay printing until we have both, deferring the printing to | |
4247 | pretty_printer's m_format_postprocessor hook. | |
4248 | ||
4249 | This is called in phase 2 of pp_format, when it is accumulating | |
4250 | a series of formatted chunks. We stash the location of the chunk | |
4251 | we're meant to have written to, so that we can write to it in the | |
4252 | m_format_postprocessor hook. | |
4253 | ||
4254 | We also need to stash whether a 'q' prefix was provided (the QUOTE | |
4255 | param) so that we can add the quotes when writing out the delayed | |
4256 | chunk. */ | |
4257 | ||
4258 | static void | |
4259 | defer_phase_2_of_type_diff (deferred_printed_type *deferred, | |
4260 | tree type, const char **buffer_ptr, | |
4261 | bool verbose, bool quote) | |
4262 | { | |
4263 | gcc_assert (deferred->m_tree == NULL_TREE); | |
4264 | gcc_assert (deferred->m_buffer_ptr == NULL); | |
4265 | *deferred = deferred_printed_type (type, buffer_ptr, verbose, quote); | |
4266 | } | |
4267 | ||
4268 | ||
a1066c99 GDR |
4269 | /* Called from output_format -- during diagnostic message processing -- |
4270 | to handle C++ specific format specifier with the following meanings: | |
4271 | %A function argument-list. | |
749ced52 | 4272 | %C tree code. |
a1066c99 GDR |
4273 | %D declaration. |
4274 | %E expression. | |
4275 | %F function declaration. | |
081b70a9 DM |
4276 | %G gcall * |
4277 | %H type difference (from). | |
4278 | %I type difference (to). | |
4279 | %K tree | |
749ced52 ZW |
4280 | %L language as used in extern "lang". |
4281 | %O binary operator. | |
a1066c99 | 4282 | %P function parameter whose position is indicated by an integer. |
749ced52 | 4283 | %Q assignment operator. |
3f04b1bb | 4284 | %S substitution (template + args) |
a1066c99 | 4285 | %T type. |
3f04b1bb | 4286 | %V cv-qualifier. |
081b70a9 | 4287 | %X exception-specification. */ |
47b69537 | 4288 | static bool |
39ce81c9 | 4289 | cp_printer (pretty_printer *pp, text_info *text, const char *spec, |
f012c8ef | 4290 | int precision, bool wide, bool set_locus, bool verbose, |
ce95abc4 | 4291 | bool *quoted, const char **buffer_ptr) |
a1066c99 | 4292 | { |
f012c8ef DM |
4293 | gcc_assert (pp->m_format_postprocessor); |
4294 | cxx_format_postprocessor *postprocessor | |
4295 | = static_cast <cxx_format_postprocessor *> (pp->m_format_postprocessor); | |
4296 | ||
749ced52 | 4297 | const char *result; |
39ce81c9 ZW |
4298 | tree t = NULL; |
4299 | #define next_tree (t = va_arg (*text->args_ptr, tree)) | |
72b5577d ILT |
4300 | #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int)) |
4301 | #define next_lang ((enum languages) va_arg (*text->args_ptr, int)) | |
47b69537 GDR |
4302 | #define next_int va_arg (*text->args_ptr, int) |
4303 | ||
39ce81c9 ZW |
4304 | if (precision != 0 || wide) |
4305 | return false; | |
4306 | ||
39ce81c9 | 4307 | switch (*spec) |
22a4158c | 4308 | { |
749ced52 | 4309 | case 'A': result = args_to_string (next_tree, verbose); break; |
0cbd7506 | 4310 | case 'C': result = code_to_string (next_tcode); break; |
dd90d2b2 RH |
4311 | case 'D': |
4312 | { | |
4313 | tree temp = next_tree; | |
5a6ccc94 | 4314 | if (VAR_P (temp) |
839b422f | 4315 | && DECL_HAS_DEBUG_EXPR_P (temp)) |
dd90d2b2 RH |
4316 | { |
4317 | temp = DECL_DEBUG_EXPR (temp); | |
4318 | if (!DECL_P (temp)) | |
4319 | { | |
4320 | result = expr_to_string (temp); | |
4321 | break; | |
4322 | } | |
4323 | } | |
4324 | result = decl_to_string (temp, verbose); | |
4325 | } | |
4326 | break; | |
0cbd7506 | 4327 | case 'E': result = expr_to_string (next_tree); break; |
749ced52 | 4328 | case 'F': result = fndecl_to_string (next_tree, verbose); break; |
081b70a9 DM |
4329 | case 'G': |
4330 | percent_G_format (text); | |
4331 | return true; | |
4332 | case 'H': | |
4333 | defer_phase_2_of_type_diff (&postprocessor->m_type_a, next_tree, | |
4334 | buffer_ptr, verbose, *quoted); | |
4335 | return true; | |
4336 | case 'I': | |
4337 | defer_phase_2_of_type_diff (&postprocessor->m_type_b, next_tree, | |
4338 | buffer_ptr, verbose, *quoted); | |
4339 | return true; | |
4340 | case 'K': | |
4341 | t = va_arg (*text->args_ptr, tree); | |
8a45b051 | 4342 | percent_K_format (text, EXPR_LOCATION (t), TREE_BLOCK (t)); |
081b70a9 | 4343 | return true; |
0cbd7506 | 4344 | case 'L': result = language_to_string (next_lang); break; |
88a819be | 4345 | case 'O': result = op_to_string (false, next_tcode); break; |
0cbd7506 | 4346 | case 'P': result = parm_to_string (next_int); break; |
88a819be | 4347 | case 'Q': result = op_to_string (true, next_tcode); break; |
3ff60975 | 4348 | case 'S': result = subst_to_string (next_tree); break; |
ce95abc4 DM |
4349 | case 'T': |
4350 | { | |
4351 | result = type_to_string (next_tree, verbose, false, quoted, | |
4352 | pp_show_color (pp)); | |
4353 | } | |
4354 | break; | |
749ced52 | 4355 | case 'V': result = cv_to_string (next_tree, verbose); break; |
3f04b1bb | 4356 | case 'X': result = eh_spec_to_string (next_tree, verbose); break; |
c8094d83 | 4357 | |
22a4158c | 4358 | default: |
47b69537 | 4359 | return false; |
a1066c99 | 4360 | } |
bb20cc46 | 4361 | |
b066401f | 4362 | pp_string (pp, result); |
39ce81c9 | 4363 | if (set_locus && t != NULL) |
85204e23 | 4364 | text->set_location (0, location_of (t), SHOW_RANGE_WITH_CARET); |
47b69537 | 4365 | return true; |
749ced52 ZW |
4366 | #undef next_tree |
4367 | #undef next_tcode | |
4368 | #undef next_lang | |
4369 | #undef next_int | |
a1066c99 | 4370 | } |
178b58b5 | 4371 | \f |
09357846 | 4372 | /* Warn about the use of C++0x features when appropriate. */ |
5d80a306 | 4373 | void |
848f237b | 4374 | maybe_warn_cpp0x (cpp0x_warn_str str) |
5d80a306 | 4375 | { |
ac4c7868 | 4376 | if (cxx_dialect == cxx98) |
848f237b SZ |
4377 | switch (str) |
4378 | { | |
4379 | case CPP0X_INITIALIZER_LISTS: | |
4380 | pedwarn (input_location, 0, | |
4381 | "extended initializer lists " | |
a3f9f006 | 4382 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4383 | break; |
4384 | case CPP0X_EXPLICIT_CONVERSION: | |
4385 | pedwarn (input_location, 0, | |
4386 | "explicit conversion operators " | |
a3f9f006 | 4387 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4388 | break; |
4389 | case CPP0X_VARIADIC_TEMPLATES: | |
4390 | pedwarn (input_location, 0, | |
4391 | "variadic templates " | |
a3f9f006 | 4392 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4393 | break; |
4394 | case CPP0X_LAMBDA_EXPR: | |
4395 | pedwarn (input_location, 0, | |
4396 | "lambda expressions " | |
a3f9f006 | 4397 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
848f237b SZ |
4398 | break; |
4399 | case CPP0X_AUTO: | |
4400 | pedwarn (input_location, 0, | |
a3f9f006 ML |
4401 | "C++11 auto only available with %<-std=c++11%> or " |
4402 | "%<-std=gnu++11%>"); | |
848f237b SZ |
4403 | break; |
4404 | case CPP0X_SCOPED_ENUMS: | |
4405 | pedwarn (input_location, 0, | |
a3f9f006 ML |
4406 | "scoped enums only available with %<-std=c++11%> or " |
4407 | "%<-std=gnu++11%>"); | |
848f237b SZ |
4408 | break; |
4409 | case CPP0X_DEFAULTED_DELETED: | |
4410 | pedwarn (input_location, 0, | |
4411 | "defaulted and deleted functions " | |
a3f9f006 | 4412 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
bc2c4cb4 RRC |
4413 | break; |
4414 | case CPP0X_INLINE_NAMESPACES: | |
c1771a20 | 4415 | pedwarn (input_location, OPT_Wpedantic, |
bc2c4cb4 | 4416 | "inline namespaces " |
a3f9f006 | 4417 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
3ce4f9e4 | 4418 | break; |
eda42c4f VV |
4419 | case CPP0X_OVERRIDE_CONTROLS: |
4420 | pedwarn (input_location, 0, | |
4421 | "override controls (override/final) " | |
a3f9f006 | 4422 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
eda42c4f | 4423 | break; |
0e5f8a59 JM |
4424 | case CPP0X_NSDMI: |
4425 | pedwarn (input_location, 0, | |
4426 | "non-static data member initializers " | |
a3f9f006 | 4427 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
0e5f8a59 | 4428 | break; |
3ce4f9e4 ESR |
4429 | case CPP0X_USER_DEFINED_LITERALS: |
4430 | pedwarn (input_location, 0, | |
4431 | "user-defined literals " | |
a3f9f006 | 4432 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
3ce4f9e4 | 4433 | break; |
238e471c VV |
4434 | case CPP0X_DELEGATING_CTORS: |
4435 | pedwarn (input_location, 0, | |
4436 | "delegating constructors " | |
a3f9f006 | 4437 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
85b5d65a JM |
4438 | break; |
4439 | case CPP0X_INHERITING_CTORS: | |
4440 | pedwarn (input_location, 0, | |
4441 | "inheriting constructors " | |
a3f9f006 | 4442 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
238e471c | 4443 | break; |
e28d52cf DS |
4444 | case CPP0X_ATTRIBUTES: |
4445 | pedwarn (input_location, 0, | |
4446 | "c++11 attributes " | |
a3f9f006 | 4447 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
e28d52cf | 4448 | break; |
2eed8e37 BK |
4449 | case CPP0X_REF_QUALIFIER: |
4450 | pedwarn (input_location, 0, | |
4451 | "ref-qualifiers " | |
a3f9f006 | 4452 | "only available with %<-std=c++11%> or %<-std=gnu++11%>"); |
2eed8e37 | 4453 | break; |
848f237b | 4454 | default: |
3ce4f9e4 | 4455 | gcc_unreachable (); |
848f237b | 4456 | } |
09357846 JM |
4457 | } |
4458 | ||
4459 | /* Warn about the use of variadic templates when appropriate. */ | |
4460 | void | |
4461 | maybe_warn_variadic_templates (void) | |
4462 | { | |
848f237b | 4463 | maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES); |
5d80a306 | 4464 | } |
9c650d90 MLI |
4465 | |
4466 | ||
4467 | /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on | |
4468 | option OPT with text GMSGID. Use this function to report | |
4469 | diagnostics for constructs that are invalid C++98, but valid | |
4470 | C++0x. */ | |
4471 | bool | |
4472 | pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...) | |
4473 | { | |
4474 | diagnostic_info diagnostic; | |
4475 | va_list ap; | |
c522573e | 4476 | bool ret; |
ebedc9a3 | 4477 | rich_location richloc (line_table, location); |
9c650d90 MLI |
4478 | |
4479 | va_start (ap, gmsgid); | |
8a645150 | 4480 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, |
9c650d90 MLI |
4481 | (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING); |
4482 | diagnostic.option_index = opt; | |
56d35585 | 4483 | ret = diagnostic_report_diagnostic (global_dc, &diagnostic); |
9c650d90 | 4484 | va_end (ap); |
c522573e | 4485 | return ret; |
9c650d90 | 4486 | } |
993acb36 NF |
4487 | |
4488 | /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what | |
4489 | we found when we tried to do the lookup. LOCATION is the location of | |
4490 | the NAME identifier. */ | |
4491 | ||
4492 | void | |
4493 | qualified_name_lookup_error (tree scope, tree name, | |
4494 | tree decl, location_t location) | |
4495 | { | |
4496 | if (scope == error_mark_node) | |
4497 | ; /* We already complained. */ | |
4498 | else if (TYPE_P (scope)) | |
4499 | { | |
4500 | if (!COMPLETE_TYPE_P (scope)) | |
4501 | error_at (location, "incomplete type %qT used in nested name specifier", | |
4502 | scope); | |
4503 | else if (TREE_CODE (decl) == TREE_LIST) | |
4504 | { | |
4505 | error_at (location, "reference to %<%T::%D%> is ambiguous", | |
4506 | scope, name); | |
4507 | print_candidates (decl); | |
4508 | } | |
4509 | else | |
3ded6ffd DM |
4510 | { |
4511 | name_hint hint; | |
883c0796 | 4512 | if (SCOPED_ENUM_P (scope) && TREE_CODE (name) == IDENTIFIER_NODE) |
3ded6ffd DM |
4513 | hint = suggest_alternative_in_scoped_enum (name, scope); |
4514 | if (const char *suggestion = hint.suggestion ()) | |
4515 | { | |
4516 | gcc_rich_location richloc (location); | |
4517 | richloc.add_fixit_replace (suggestion); | |
4518 | error_at (&richloc, | |
4519 | "%qD is not a member of %qT; did you mean %qs?", | |
4520 | name, scope, suggestion); | |
4521 | } | |
4522 | else | |
4523 | error_at (location, "%qD is not a member of %qT", name, scope); | |
4524 | } | |
993acb36 NF |
4525 | } |
4526 | else if (scope != global_namespace) | |
4527 | { | |
097f82ec | 4528 | auto_diagnostic_group d; |
7e2de6df DM |
4529 | bool emit_fixit = true; |
4530 | name_hint hint | |
4531 | = suggest_alternative_in_explicit_scope (location, name, scope); | |
4532 | if (!hint) | |
4533 | { | |
4534 | hint = suggest_alternatives_in_other_namespaces (location, name); | |
4535 | /* "location" is just the location of the name, not of the explicit | |
4536 | scope, and it's not easy to get at the latter, so we can't issue | |
4537 | fix-it hints for the suggestion. */ | |
4538 | emit_fixit = false; | |
4539 | } | |
4540 | if (const char *suggestion = hint.suggestion ()) | |
4541 | { | |
4542 | gcc_rich_location richloc (location); | |
4543 | if (emit_fixit) | |
4544 | richloc.add_fixit_replace (suggestion); | |
4545 | error_at (&richloc, "%qD is not a member of %qD; did you mean %qs?", | |
4546 | name, scope, suggestion); | |
4547 | } | |
4548 | else | |
4549 | error_at (location, "%qD is not a member of %qD", name, scope); | |
993acb36 NF |
4550 | } |
4551 | else | |
4552 | { | |
097f82ec | 4553 | auto_diagnostic_group d; |
7e2de6df DM |
4554 | name_hint hint = suggest_alternatives_for (location, name, true); |
4555 | if (const char *suggestion = hint.suggestion ()) | |
4556 | { | |
4557 | gcc_rich_location richloc (location); | |
4558 | richloc.add_fixit_replace (suggestion); | |
4559 | error_at (&richloc, | |
4560 | "%<::%D%> has not been declared; did you mean %qs?", | |
4561 | name, suggestion); | |
4562 | } | |
4563 | else | |
4564 | error_at (location, "%<::%D%> has not been declared", name); | |
993acb36 NF |
4565 | } |
4566 | } | |
96e6ae57 DM |
4567 | |
4568 | /* C++-specific implementation of range_label::get_text () vfunc for | |
4569 | range_label_for_type_mismatch. | |
4570 | ||
4571 | Compare with print_template_differences above. */ | |
4572 | ||
4573 | label_text | |
9c4a4b3c | 4574 | range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const |
96e6ae57 DM |
4575 | { |
4576 | if (m_labelled_type == NULL_TREE) | |
d68f5d45 | 4577 | return label_text::borrow (NULL); |
96e6ae57 DM |
4578 | |
4579 | const bool verbose = false; | |
4580 | const bool show_color = false; | |
4581 | ||
4582 | const char *result; | |
4583 | if (m_other_type | |
4584 | && comparable_template_types_p (m_labelled_type, m_other_type)) | |
4585 | result = type_to_string_with_compare (m_labelled_type, m_other_type, | |
4586 | verbose, show_color); | |
4587 | else | |
4588 | result = type_to_string (m_labelled_type, verbose, true, NULL, show_color); | |
4589 | ||
4590 | /* Both of the above return GC-allocated buffers, so the caller mustn't | |
4591 | free them. */ | |
d68f5d45 | 4592 | return label_text::borrow (result); |
96e6ae57 | 4593 | } |