annotate gcc/cp/cxx-pretty-print.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Implementation of subroutines for the GNU C++ pretty-printer.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "cp-tree.h"
kono
parents:
diff changeset
25 #include "cxx-pretty-print.h"
kono
parents:
diff changeset
26 #include "tree-pretty-print.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
29 static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
30 static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
31 static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
32 static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
33 static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
34 static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
35 static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
36 static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
37 static void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
38 static void pp_cxx_unary_left_fold_expression (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
39 static void pp_cxx_unary_right_fold_expression (cxx_pretty_printer *, tree);
kono
parents:
diff changeset
40 static void pp_cxx_binary_fold_expression (cxx_pretty_printer *, tree);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 static void pp_cxx_concept_definition (cxx_pretty_printer *, tree);
111
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 static inline void
kono
parents:
diff changeset
45 pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 const char *p = pp_last_position_in_text (pp);
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 if (p != NULL && *p == c)
kono
parents:
diff changeset
50 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
51 pp_character (pp, c);
kono
parents:
diff changeset
52 pp->padding = pp_none;
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #define pp_cxx_expression_list(PP, T) \
kono
parents:
diff changeset
56 pp_c_expression_list (PP, T)
kono
parents:
diff changeset
57 #define pp_cxx_space_for_pointer_operator(PP, T) \
kono
parents:
diff changeset
58 pp_c_space_for_pointer_operator (PP, T)
kono
parents:
diff changeset
59 #define pp_cxx_init_declarator(PP, T) \
kono
parents:
diff changeset
60 pp_c_init_declarator (PP, T)
kono
parents:
diff changeset
61 #define pp_cxx_call_argument_list(PP, T) \
kono
parents:
diff changeset
62 pp_c_call_argument_list (PP, T)
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 void
kono
parents:
diff changeset
65 pp_cxx_colon_colon (cxx_pretty_printer *pp)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 pp_colon_colon (pp);
kono
parents:
diff changeset
68 pp->padding = pp_none;
kono
parents:
diff changeset
69 }
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 void
kono
parents:
diff changeset
72 pp_cxx_begin_template_argument_list (cxx_pretty_printer *pp)
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 pp_cxx_nonconsecutive_character (pp, '<');
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 void
kono
parents:
diff changeset
78 pp_cxx_end_template_argument_list (cxx_pretty_printer *pp)
kono
parents:
diff changeset
79 {
kono
parents:
diff changeset
80 pp_cxx_nonconsecutive_character (pp, '>');
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 void
kono
parents:
diff changeset
84 pp_cxx_separate_with (cxx_pretty_printer *pp, int c)
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 pp_separate_with (pp, c);
kono
parents:
diff changeset
87 pp->padding = pp_none;
kono
parents:
diff changeset
88 }
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* Expressions. */
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* conversion-function-id:
kono
parents:
diff changeset
93 operator conversion-type-id
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 conversion-type-id:
kono
parents:
diff changeset
96 type-specifier-seq conversion-declarator(opt)
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 conversion-declarator:
kono
parents:
diff changeset
99 ptr-operator conversion-declarator(opt) */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 static inline void
kono
parents:
diff changeset
102 pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 pp_cxx_ws_string (pp, "operator");
kono
parents:
diff changeset
105 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 static inline void
kono
parents:
diff changeset
109 pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
112 pp_cxx_begin_template_argument_list (pp);
kono
parents:
diff changeset
113 pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
114 pp_cxx_end_template_argument_list (pp);
kono
parents:
diff changeset
115 }
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* Prints the unqualified part of the id-expression T.
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 unqualified-id:
kono
parents:
diff changeset
120 identifier
kono
parents:
diff changeset
121 operator-function-id
kono
parents:
diff changeset
122 conversion-function-id
kono
parents:
diff changeset
123 ~ class-name
kono
parents:
diff changeset
124 template-id */
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 static void
kono
parents:
diff changeset
127 pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 enum tree_code code = TREE_CODE (t);
kono
parents:
diff changeset
130 switch (code)
kono
parents:
diff changeset
131 {
kono
parents:
diff changeset
132 case RESULT_DECL:
kono
parents:
diff changeset
133 pp->translate_string ("<return-value>");
kono
parents:
diff changeset
134 break;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 case OVERLOAD:
kono
parents:
diff changeset
137 t = OVL_FIRST (t);
kono
parents:
diff changeset
138 /* FALLTHRU */
kono
parents:
diff changeset
139 case VAR_DECL:
kono
parents:
diff changeset
140 case PARM_DECL:
kono
parents:
diff changeset
141 case CONST_DECL:
kono
parents:
diff changeset
142 case TYPE_DECL:
kono
parents:
diff changeset
143 case FUNCTION_DECL:
kono
parents:
diff changeset
144 case NAMESPACE_DECL:
kono
parents:
diff changeset
145 case FIELD_DECL:
kono
parents:
diff changeset
146 case LABEL_DECL:
kono
parents:
diff changeset
147 case USING_DECL:
kono
parents:
diff changeset
148 case TEMPLATE_DECL:
kono
parents:
diff changeset
149 t = DECL_NAME (t);
kono
parents:
diff changeset
150 /* FALLTHRU */
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 case IDENTIFIER_NODE:
kono
parents:
diff changeset
153 if (t == NULL)
kono
parents:
diff changeset
154 pp->translate_string ("<unnamed>");
kono
parents:
diff changeset
155 else if (IDENTIFIER_CONV_OP_P (t))
kono
parents:
diff changeset
156 pp_cxx_conversion_function_id (pp, t);
kono
parents:
diff changeset
157 else
kono
parents:
diff changeset
158 pp_cxx_tree_identifier (pp, t);
kono
parents:
diff changeset
159 break;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 case TEMPLATE_ID_EXPR:
kono
parents:
diff changeset
162 pp_cxx_template_id (pp, t);
kono
parents:
diff changeset
163 break;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 case BASELINK:
kono
parents:
diff changeset
166 pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t));
kono
parents:
diff changeset
167 break;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 case RECORD_TYPE:
kono
parents:
diff changeset
170 case UNION_TYPE:
kono
parents:
diff changeset
171 case ENUMERAL_TYPE:
kono
parents:
diff changeset
172 case TYPENAME_TYPE:
kono
parents:
diff changeset
173 case UNBOUND_CLASS_TEMPLATE:
kono
parents:
diff changeset
174 pp_cxx_unqualified_id (pp, TYPE_NAME (t));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
175 if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (t))
111
kono
parents:
diff changeset
176 {
kono
parents:
diff changeset
177 pp_cxx_begin_template_argument_list (pp);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
178 tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
179 pp_cxx_template_argument_list (pp, args);
111
kono
parents:
diff changeset
180 pp_cxx_end_template_argument_list (pp);
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182 break;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 case BIT_NOT_EXPR:
kono
parents:
diff changeset
185 pp_cxx_complement (pp);
kono
parents:
diff changeset
186 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
187 break;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
190 case TEMPLATE_TEMPLATE_PARM:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
191 if (template_placeholder_p (t))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
192 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
193 t = TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
194 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
195 pp_string (pp, "<...auto...>");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
196 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
197 else if (TYPE_IDENTIFIER (t))
111
kono
parents:
diff changeset
198 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
kono
parents:
diff changeset
199 else
kono
parents:
diff changeset
200 pp_cxx_canonical_template_parameter (pp, t);
kono
parents:
diff changeset
201 break;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
204 pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
kono
parents:
diff changeset
205 break;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 case BOUND_TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
208 pp_cxx_cv_qualifier_seq (pp, t);
kono
parents:
diff changeset
209 pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t));
kono
parents:
diff changeset
210 pp_cxx_begin_template_argument_list (pp);
kono
parents:
diff changeset
211 pp_cxx_template_argument_list (pp, TYPE_TI_ARGS (t));
kono
parents:
diff changeset
212 pp_cxx_end_template_argument_list (pp);
kono
parents:
diff changeset
213 break;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 default:
kono
parents:
diff changeset
216 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
217 break;
kono
parents:
diff changeset
218 }
kono
parents:
diff changeset
219 }
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 /* Pretty-print out the token sequence ":: template" in template codes
kono
parents:
diff changeset
222 where it is needed to "inline declare" the (following) member as
kono
parents:
diff changeset
223 a template. This situation arises when SCOPE of T is dependent
kono
parents:
diff changeset
224 on template parameters. */
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 static inline void
kono
parents:
diff changeset
227 pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
kono
parents:
diff changeset
228 {
kono
parents:
diff changeset
229 if (TREE_CODE (t) == TEMPLATE_ID_EXPR
kono
parents:
diff changeset
230 && TYPE_P (scope) && dependent_type_p (scope))
kono
parents:
diff changeset
231 pp_cxx_ws_string (pp, "template");
kono
parents:
diff changeset
232 }
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 /* nested-name-specifier:
kono
parents:
diff changeset
235 class-or-namespace-name :: nested-name-specifier(opt)
kono
parents:
diff changeset
236 class-or-namespace-name :: template nested-name-specifier */
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 static void
kono
parents:
diff changeset
239 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
240 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
241 /* FIXME: When diagnosing references to concepts (especially as types?)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
242 we end up adding too many '::' to the name. This is partially due
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
243 to the fact that pp->enclosing_namespace is null. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
244 if (t == global_namespace)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
245 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
246 pp_cxx_colon_colon (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
247 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
248 else if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
111
kono
parents:
diff changeset
249 {
kono
parents:
diff changeset
250 tree scope = get_containing_scope (t);
kono
parents:
diff changeset
251 pp_cxx_nested_name_specifier (pp, scope);
kono
parents:
diff changeset
252 pp_cxx_template_keyword_if_needed (pp, scope, t);
kono
parents:
diff changeset
253 pp_cxx_unqualified_id (pp, t);
kono
parents:
diff changeset
254 pp_cxx_colon_colon (pp);
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256 }
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 /* qualified-id:
kono
parents:
diff changeset
259 nested-name-specifier template(opt) unqualified-id */
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 static void
kono
parents:
diff changeset
262 pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
263 {
kono
parents:
diff changeset
264 switch (TREE_CODE (t))
kono
parents:
diff changeset
265 {
kono
parents:
diff changeset
266 /* A pointer-to-member is always qualified. */
kono
parents:
diff changeset
267 case PTRMEM_CST:
kono
parents:
diff changeset
268 pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
kono
parents:
diff changeset
269 pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
kono
parents:
diff changeset
270 break;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 /* In Standard C++, functions cannot possibly be used as
kono
parents:
diff changeset
273 nested-name-specifiers. However, there are situations where
kono
parents:
diff changeset
274 is "makes sense" to output the surrounding function name for the
kono
parents:
diff changeset
275 purpose of emphasizing on the scope kind. Just printing the
kono
parents:
diff changeset
276 function name might not be sufficient as it may be overloaded; so,
kono
parents:
diff changeset
277 we decorate the function with its signature too.
kono
parents:
diff changeset
278 FIXME: This is probably the wrong pretty-printing for conversion
kono
parents:
diff changeset
279 functions and some function templates. */
kono
parents:
diff changeset
280 case OVERLOAD:
kono
parents:
diff changeset
281 t = OVL_FIRST (t);
kono
parents:
diff changeset
282 /* FALLTHRU */
kono
parents:
diff changeset
283 case FUNCTION_DECL:
kono
parents:
diff changeset
284 if (DECL_FUNCTION_MEMBER_P (t))
kono
parents:
diff changeset
285 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
kono
parents:
diff changeset
286 pp_cxx_unqualified_id
kono
parents:
diff changeset
287 (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
kono
parents:
diff changeset
288 pp_cxx_parameter_declaration_clause (pp, TREE_TYPE (t));
kono
parents:
diff changeset
289 break;
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 case OFFSET_REF:
kono
parents:
diff changeset
292 case SCOPE_REF:
kono
parents:
diff changeset
293 pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
294 pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
295 break;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 default:
kono
parents:
diff changeset
298 {
kono
parents:
diff changeset
299 tree scope = get_containing_scope (t);
kono
parents:
diff changeset
300 if (scope != pp->enclosing_scope)
kono
parents:
diff changeset
301 {
kono
parents:
diff changeset
302 pp_cxx_nested_name_specifier (pp, scope);
kono
parents:
diff changeset
303 pp_cxx_template_keyword_if_needed (pp, scope, t);
kono
parents:
diff changeset
304 }
kono
parents:
diff changeset
305 pp_cxx_unqualified_id (pp, t);
kono
parents:
diff changeset
306 }
kono
parents:
diff changeset
307 break;
kono
parents:
diff changeset
308 }
kono
parents:
diff changeset
309 }
kono
parents:
diff changeset
310
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
311 /* Given a value e of ENUMERAL_TYPE:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
312 Print out the first ENUMERATOR id with value e, if one is found,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313 (including nested names but excluding the enum name if unscoped)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
314 else print out the value as a C-style cast (type-id)value. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
315
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 pp_cxx_enumeration_constant (cxx_pretty_printer *pp, tree e)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 tree type = TREE_TYPE (e);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
320 tree value = NULL_TREE;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 /* Find the name of this constant. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
323 if ((pp->flags & pp_c_flag_gnu_v3) == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
324 for (value = TYPE_VALUES (type); value != NULL_TREE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
325 value = TREE_CHAIN (value))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
326 if (tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
327 break;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
328
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
329 if (value != NULL_TREE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
330 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
331 if (!ENUM_IS_SCOPED (type))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
332 type = get_containing_scope (type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
333 pp_cxx_nested_name_specifier (pp, type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
334 pp->id_expression (TREE_PURPOSE (value));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
336 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
337 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
338 /* Value must have been cast. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
339 pp_c_type_cast (pp, type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
340 pp_c_integer_constant (pp, e);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
342 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343
111
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 void
kono
parents:
diff changeset
346 cxx_pretty_printer::constant (tree t)
kono
parents:
diff changeset
347 {
kono
parents:
diff changeset
348 switch (TREE_CODE (t))
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 case STRING_CST:
kono
parents:
diff changeset
351 {
kono
parents:
diff changeset
352 const bool in_parens = PAREN_STRING_LITERAL_P (t);
kono
parents:
diff changeset
353 if (in_parens)
kono
parents:
diff changeset
354 pp_cxx_left_paren (this);
kono
parents:
diff changeset
355 c_pretty_printer::constant (t);
kono
parents:
diff changeset
356 if (in_parens)
kono
parents:
diff changeset
357 pp_cxx_right_paren (this);
kono
parents:
diff changeset
358 }
kono
parents:
diff changeset
359 break;
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 case INTEGER_CST:
kono
parents:
diff changeset
362 if (NULLPTR_TYPE_P (TREE_TYPE (t)))
kono
parents:
diff changeset
363 {
kono
parents:
diff changeset
364 pp_string (this, "nullptr");
kono
parents:
diff changeset
365 break;
kono
parents:
diff changeset
366 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
367 else if (TREE_CODE (TREE_TYPE (t)) == ENUMERAL_TYPE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
368 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
369 pp_cxx_enumeration_constant (this, t);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
371 }
111
kono
parents:
diff changeset
372 /* fall through. */
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 default:
kono
parents:
diff changeset
375 c_pretty_printer::constant (t);
kono
parents:
diff changeset
376 break;
kono
parents:
diff changeset
377 }
kono
parents:
diff changeset
378 }
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 /* id-expression:
kono
parents:
diff changeset
381 unqualified-id
kono
parents:
diff changeset
382 qualified-id */
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 void
kono
parents:
diff changeset
385 cxx_pretty_printer::id_expression (tree t)
kono
parents:
diff changeset
386 {
kono
parents:
diff changeset
387 if (TREE_CODE (t) == OVERLOAD)
kono
parents:
diff changeset
388 t = OVL_FIRST (t);
kono
parents:
diff changeset
389 if (DECL_P (t) && DECL_CONTEXT (t))
kono
parents:
diff changeset
390 pp_cxx_qualified_id (this, t);
kono
parents:
diff changeset
391 else
kono
parents:
diff changeset
392 pp_cxx_unqualified_id (this, t);
kono
parents:
diff changeset
393 }
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 /* user-defined literal:
kono
parents:
diff changeset
396 literal ud-suffix */
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 void
kono
parents:
diff changeset
399 pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 pp->constant (USERDEF_LITERAL_VALUE (t));
kono
parents:
diff changeset
402 pp->id_expression (USERDEF_LITERAL_SUFFIX_ID (t));
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 /* primary-expression:
kono
parents:
diff changeset
407 literal
kono
parents:
diff changeset
408 this
kono
parents:
diff changeset
409 :: identifier
kono
parents:
diff changeset
410 :: operator-function-id
kono
parents:
diff changeset
411 :: qualifier-id
kono
parents:
diff changeset
412 ( expression )
kono
parents:
diff changeset
413 id-expression
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 GNU Extensions:
kono
parents:
diff changeset
416 __builtin_va_arg ( assignment-expression , type-id )
kono
parents:
diff changeset
417 __builtin_offsetof ( type-id, offsetof-expression )
kono
parents:
diff changeset
418 __builtin_addressof ( expression )
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 __has_nothrow_assign ( type-id )
kono
parents:
diff changeset
421 __has_nothrow_constructor ( type-id )
kono
parents:
diff changeset
422 __has_nothrow_copy ( type-id )
kono
parents:
diff changeset
423 __has_trivial_assign ( type-id )
kono
parents:
diff changeset
424 __has_trivial_constructor ( type-id )
kono
parents:
diff changeset
425 __has_trivial_copy ( type-id )
kono
parents:
diff changeset
426 __has_unique_object_representations ( type-id )
kono
parents:
diff changeset
427 __has_trivial_destructor ( type-id )
kono
parents:
diff changeset
428 __has_virtual_destructor ( type-id )
kono
parents:
diff changeset
429 __is_abstract ( type-id )
kono
parents:
diff changeset
430 __is_base_of ( type-id , type-id )
kono
parents:
diff changeset
431 __is_class ( type-id )
kono
parents:
diff changeset
432 __is_empty ( type-id )
kono
parents:
diff changeset
433 __is_enum ( type-id )
kono
parents:
diff changeset
434 __is_literal_type ( type-id )
kono
parents:
diff changeset
435 __is_pod ( type-id )
kono
parents:
diff changeset
436 __is_polymorphic ( type-id )
kono
parents:
diff changeset
437 __is_std_layout ( type-id )
kono
parents:
diff changeset
438 __is_trivial ( type-id )
kono
parents:
diff changeset
439 __is_union ( type-id ) */
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 void
kono
parents:
diff changeset
442 cxx_pretty_printer::primary_expression (tree t)
kono
parents:
diff changeset
443 {
kono
parents:
diff changeset
444 switch (TREE_CODE (t))
kono
parents:
diff changeset
445 {
kono
parents:
diff changeset
446 case VOID_CST:
kono
parents:
diff changeset
447 case INTEGER_CST:
kono
parents:
diff changeset
448 case REAL_CST:
kono
parents:
diff changeset
449 case COMPLEX_CST:
kono
parents:
diff changeset
450 case STRING_CST:
kono
parents:
diff changeset
451 constant (t);
kono
parents:
diff changeset
452 break;
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 case USERDEF_LITERAL:
kono
parents:
diff changeset
455 pp_cxx_userdef_literal (this, t);
kono
parents:
diff changeset
456 break;
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 case BASELINK:
kono
parents:
diff changeset
459 t = BASELINK_FUNCTIONS (t);
kono
parents:
diff changeset
460 /* FALLTHRU */
kono
parents:
diff changeset
461 case VAR_DECL:
kono
parents:
diff changeset
462 case PARM_DECL:
kono
parents:
diff changeset
463 case FIELD_DECL:
kono
parents:
diff changeset
464 case FUNCTION_DECL:
kono
parents:
diff changeset
465 case OVERLOAD:
kono
parents:
diff changeset
466 case CONST_DECL:
kono
parents:
diff changeset
467 case TEMPLATE_DECL:
kono
parents:
diff changeset
468 id_expression (t);
kono
parents:
diff changeset
469 break;
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 case RESULT_DECL:
kono
parents:
diff changeset
472 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
473 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
474 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
475 pp_cxx_unqualified_id (this, t);
kono
parents:
diff changeset
476 break;
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 case STMT_EXPR:
kono
parents:
diff changeset
479 pp_cxx_left_paren (this);
kono
parents:
diff changeset
480 statement (STMT_EXPR_STMT (t));
kono
parents:
diff changeset
481 pp_cxx_right_paren (this);
kono
parents:
diff changeset
482 break;
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 case TRAIT_EXPR:
kono
parents:
diff changeset
485 pp_cxx_trait_expression (this, t);
kono
parents:
diff changeset
486 break;
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 case VA_ARG_EXPR:
kono
parents:
diff changeset
489 pp_cxx_va_arg_expression (this, t);
kono
parents:
diff changeset
490 break;
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 case OFFSETOF_EXPR:
kono
parents:
diff changeset
493 pp_cxx_offsetof_expression (this, t);
kono
parents:
diff changeset
494 break;
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 case ADDRESSOF_EXPR:
kono
parents:
diff changeset
497 pp_cxx_addressof_expression (this, t);
kono
parents:
diff changeset
498 break;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 case REQUIRES_EXPR:
kono
parents:
diff changeset
501 pp_cxx_requires_expr (this, t);
kono
parents:
diff changeset
502 break;
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 default:
kono
parents:
diff changeset
505 c_pretty_printer::primary_expression (t);
kono
parents:
diff changeset
506 break;
kono
parents:
diff changeset
507 }
kono
parents:
diff changeset
508 }
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 /* postfix-expression:
kono
parents:
diff changeset
511 primary-expression
kono
parents:
diff changeset
512 postfix-expression [ expression ]
kono
parents:
diff changeset
513 postfix-expression ( expression-list(opt) )
kono
parents:
diff changeset
514 simple-type-specifier ( expression-list(opt) )
kono
parents:
diff changeset
515 typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
kono
parents:
diff changeset
516 typename ::(opt) nested-name-specifier template(opt)
kono
parents:
diff changeset
517 template-id ( expression-list(opt) )
kono
parents:
diff changeset
518 postfix-expression . template(opt) ::(opt) id-expression
kono
parents:
diff changeset
519 postfix-expression -> template(opt) ::(opt) id-expression
kono
parents:
diff changeset
520 postfix-expression . pseudo-destructor-name
kono
parents:
diff changeset
521 postfix-expression -> pseudo-destructor-name
kono
parents:
diff changeset
522 postfix-expression ++
kono
parents:
diff changeset
523 postfix-expression --
kono
parents:
diff changeset
524 dynamic_cast < type-id > ( expression )
kono
parents:
diff changeset
525 static_cast < type-id > ( expression )
kono
parents:
diff changeset
526 reinterpret_cast < type-id > ( expression )
kono
parents:
diff changeset
527 const_cast < type-id > ( expression )
kono
parents:
diff changeset
528 typeid ( expression )
kono
parents:
diff changeset
529 typeid ( type-id ) */
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 void
kono
parents:
diff changeset
532 cxx_pretty_printer::postfix_expression (tree t)
kono
parents:
diff changeset
533 {
kono
parents:
diff changeset
534 enum tree_code code = TREE_CODE (t);
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 switch (code)
kono
parents:
diff changeset
537 {
kono
parents:
diff changeset
538 case AGGR_INIT_EXPR:
kono
parents:
diff changeset
539 case CALL_EXPR:
kono
parents:
diff changeset
540 {
kono
parents:
diff changeset
541 tree fun = cp_get_callee (t);
kono
parents:
diff changeset
542 tree saved_scope = enclosing_scope;
kono
parents:
diff changeset
543 bool skipfirst = false;
kono
parents:
diff changeset
544 tree arg;
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 if (TREE_CODE (fun) == ADDR_EXPR)
kono
parents:
diff changeset
547 fun = TREE_OPERAND (fun, 0);
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 /* In templates, where there is no way to tell whether a given
kono
parents:
diff changeset
550 call uses an actual member function. So the parser builds
kono
parents:
diff changeset
551 FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
kono
parents:
diff changeset
552 instantiation time. */
kono
parents:
diff changeset
553 if (TREE_CODE (fun) != FUNCTION_DECL)
kono
parents:
diff changeset
554 ;
kono
parents:
diff changeset
555 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
kono
parents:
diff changeset
556 {
kono
parents:
diff changeset
557 tree object = (code == AGGR_INIT_EXPR
kono
parents:
diff changeset
558 ? (AGGR_INIT_VIA_CTOR_P (t)
kono
parents:
diff changeset
559 ? AGGR_INIT_EXPR_SLOT (t)
kono
parents:
diff changeset
560 : AGGR_INIT_EXPR_ARG (t, 0))
kono
parents:
diff changeset
561 : CALL_EXPR_ARG (t, 0));
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 while (TREE_CODE (object) == NOP_EXPR)
kono
parents:
diff changeset
564 object = TREE_OPERAND (object, 0);
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 if (TREE_CODE (object) == ADDR_EXPR)
kono
parents:
diff changeset
567 object = TREE_OPERAND (object, 0);
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 if (!TYPE_PTR_P (TREE_TYPE (object)))
kono
parents:
diff changeset
570 {
kono
parents:
diff changeset
571 postfix_expression (object);
kono
parents:
diff changeset
572 pp_cxx_dot (this);
kono
parents:
diff changeset
573 }
kono
parents:
diff changeset
574 else
kono
parents:
diff changeset
575 {
kono
parents:
diff changeset
576 postfix_expression (object);
kono
parents:
diff changeset
577 pp_cxx_arrow (this);
kono
parents:
diff changeset
578 }
kono
parents:
diff changeset
579 skipfirst = true;
kono
parents:
diff changeset
580 enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
kono
parents:
diff changeset
581 }
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 postfix_expression (fun);
kono
parents:
diff changeset
584 enclosing_scope = saved_scope;
kono
parents:
diff changeset
585 pp_cxx_left_paren (this);
kono
parents:
diff changeset
586 if (code == AGGR_INIT_EXPR)
kono
parents:
diff changeset
587 {
kono
parents:
diff changeset
588 aggr_init_expr_arg_iterator iter;
kono
parents:
diff changeset
589 FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t)
kono
parents:
diff changeset
590 {
kono
parents:
diff changeset
591 if (skipfirst)
kono
parents:
diff changeset
592 skipfirst = false;
kono
parents:
diff changeset
593 else
kono
parents:
diff changeset
594 {
kono
parents:
diff changeset
595 expression (arg);
kono
parents:
diff changeset
596 if (more_aggr_init_expr_args_p (&iter))
kono
parents:
diff changeset
597 pp_cxx_separate_with (this, ',');
kono
parents:
diff changeset
598 }
kono
parents:
diff changeset
599 }
kono
parents:
diff changeset
600 }
kono
parents:
diff changeset
601 else
kono
parents:
diff changeset
602 {
kono
parents:
diff changeset
603 call_expr_arg_iterator iter;
kono
parents:
diff changeset
604 FOR_EACH_CALL_EXPR_ARG (arg, iter, t)
kono
parents:
diff changeset
605 {
kono
parents:
diff changeset
606 if (skipfirst)
kono
parents:
diff changeset
607 skipfirst = false;
kono
parents:
diff changeset
608 else
kono
parents:
diff changeset
609 {
kono
parents:
diff changeset
610 expression (arg);
kono
parents:
diff changeset
611 if (more_call_expr_args_p (&iter))
kono
parents:
diff changeset
612 pp_cxx_separate_with (this, ',');
kono
parents:
diff changeset
613 }
kono
parents:
diff changeset
614 }
kono
parents:
diff changeset
615 }
kono
parents:
diff changeset
616 pp_cxx_right_paren (this);
kono
parents:
diff changeset
617 }
kono
parents:
diff changeset
618 if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
kono
parents:
diff changeset
619 {
kono
parents:
diff changeset
620 pp_cxx_separate_with (this, ',');
kono
parents:
diff changeset
621 postfix_expression (AGGR_INIT_EXPR_SLOT (t));
kono
parents:
diff changeset
622 }
kono
parents:
diff changeset
623 break;
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 case BASELINK:
kono
parents:
diff changeset
626 case VAR_DECL:
kono
parents:
diff changeset
627 case PARM_DECL:
kono
parents:
diff changeset
628 case FIELD_DECL:
kono
parents:
diff changeset
629 case FUNCTION_DECL:
kono
parents:
diff changeset
630 case OVERLOAD:
kono
parents:
diff changeset
631 case CONST_DECL:
kono
parents:
diff changeset
632 case TEMPLATE_DECL:
kono
parents:
diff changeset
633 case RESULT_DECL:
kono
parents:
diff changeset
634 primary_expression (t);
kono
parents:
diff changeset
635 break;
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 case DYNAMIC_CAST_EXPR:
kono
parents:
diff changeset
638 case STATIC_CAST_EXPR:
kono
parents:
diff changeset
639 case REINTERPRET_CAST_EXPR:
kono
parents:
diff changeset
640 case CONST_CAST_EXPR:
kono
parents:
diff changeset
641 if (code == DYNAMIC_CAST_EXPR)
kono
parents:
diff changeset
642 pp_cxx_ws_string (this, "dynamic_cast");
kono
parents:
diff changeset
643 else if (code == STATIC_CAST_EXPR)
kono
parents:
diff changeset
644 pp_cxx_ws_string (this, "static_cast");
kono
parents:
diff changeset
645 else if (code == REINTERPRET_CAST_EXPR)
kono
parents:
diff changeset
646 pp_cxx_ws_string (this, "reinterpret_cast");
kono
parents:
diff changeset
647 else
kono
parents:
diff changeset
648 pp_cxx_ws_string (this, "const_cast");
kono
parents:
diff changeset
649 pp_cxx_begin_template_argument_list (this);
kono
parents:
diff changeset
650 type_id (TREE_TYPE (t));
kono
parents:
diff changeset
651 pp_cxx_end_template_argument_list (this);
kono
parents:
diff changeset
652 pp_left_paren (this);
kono
parents:
diff changeset
653 expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
654 pp_right_paren (this);
kono
parents:
diff changeset
655 break;
kono
parents:
diff changeset
656
kono
parents:
diff changeset
657 case EMPTY_CLASS_EXPR:
kono
parents:
diff changeset
658 type_id (TREE_TYPE (t));
kono
parents:
diff changeset
659 pp_left_paren (this);
kono
parents:
diff changeset
660 pp_right_paren (this);
kono
parents:
diff changeset
661 break;
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 case TYPEID_EXPR:
kono
parents:
diff changeset
664 pp_cxx_typeid_expression (this, t);
kono
parents:
diff changeset
665 break;
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 case PSEUDO_DTOR_EXPR:
kono
parents:
diff changeset
668 postfix_expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
669 pp_cxx_dot (this);
kono
parents:
diff changeset
670 if (TREE_OPERAND (t, 1))
kono
parents:
diff changeset
671 {
kono
parents:
diff changeset
672 pp_cxx_qualified_id (this, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
673 pp_cxx_colon_colon (this);
kono
parents:
diff changeset
674 }
kono
parents:
diff changeset
675 pp_complement (this);
kono
parents:
diff changeset
676 pp_cxx_unqualified_id (this, TREE_OPERAND (t, 2));
kono
parents:
diff changeset
677 break;
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 case ARROW_EXPR:
kono
parents:
diff changeset
680 postfix_expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
681 pp_cxx_arrow (this);
kono
parents:
diff changeset
682 break;
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 default:
kono
parents:
diff changeset
685 c_pretty_printer::postfix_expression (t);
kono
parents:
diff changeset
686 break;
kono
parents:
diff changeset
687 }
kono
parents:
diff changeset
688 }
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 /* new-expression:
kono
parents:
diff changeset
691 ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
kono
parents:
diff changeset
692 ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
kono
parents:
diff changeset
693
kono
parents:
diff changeset
694 new-placement:
kono
parents:
diff changeset
695 ( expression-list )
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 new-type-id:
kono
parents:
diff changeset
698 type-specifier-seq new-declarator(opt)
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 new-declarator:
kono
parents:
diff changeset
701 ptr-operator new-declarator(opt)
kono
parents:
diff changeset
702 direct-new-declarator
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 direct-new-declarator
kono
parents:
diff changeset
705 [ expression ]
kono
parents:
diff changeset
706 direct-new-declarator [ constant-expression ]
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 new-initializer:
kono
parents:
diff changeset
709 ( expression-list(opt) ) */
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 static void
kono
parents:
diff changeset
712 pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
713 {
kono
parents:
diff changeset
714 enum tree_code code = TREE_CODE (t);
kono
parents:
diff changeset
715 tree type = TREE_OPERAND (t, 1);
kono
parents:
diff changeset
716 tree init = TREE_OPERAND (t, 2);
kono
parents:
diff changeset
717 switch (code)
kono
parents:
diff changeset
718 {
kono
parents:
diff changeset
719 case NEW_EXPR:
kono
parents:
diff changeset
720 case VEC_NEW_EXPR:
kono
parents:
diff changeset
721 if (NEW_EXPR_USE_GLOBAL (t))
kono
parents:
diff changeset
722 pp_cxx_colon_colon (pp);
kono
parents:
diff changeset
723 pp_cxx_ws_string (pp, "new");
kono
parents:
diff changeset
724 if (TREE_OPERAND (t, 0))
kono
parents:
diff changeset
725 {
kono
parents:
diff changeset
726 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
727 pp_space (pp);
kono
parents:
diff changeset
728 }
kono
parents:
diff changeset
729 if (TREE_CODE (type) == ARRAY_REF)
kono
parents:
diff changeset
730 type = build_cplus_array_type
kono
parents:
diff changeset
731 (TREE_OPERAND (type, 0),
kono
parents:
diff changeset
732 build_index_type (fold_build2_loc (input_location,
kono
parents:
diff changeset
733 MINUS_EXPR, integer_type_node,
kono
parents:
diff changeset
734 TREE_OPERAND (type, 1),
kono
parents:
diff changeset
735 integer_one_node)));
kono
parents:
diff changeset
736 pp->type_id (type);
kono
parents:
diff changeset
737 if (init)
kono
parents:
diff changeset
738 {
kono
parents:
diff changeset
739 pp_left_paren (pp);
kono
parents:
diff changeset
740 if (TREE_CODE (init) == TREE_LIST)
kono
parents:
diff changeset
741 pp_c_expression_list (pp, init);
kono
parents:
diff changeset
742 else if (init == void_node)
kono
parents:
diff changeset
743 ; /* OK, empty initializer list. */
kono
parents:
diff changeset
744 else
kono
parents:
diff changeset
745 pp->expression (init);
kono
parents:
diff changeset
746 pp_right_paren (pp);
kono
parents:
diff changeset
747 }
kono
parents:
diff changeset
748 break;
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 default:
kono
parents:
diff changeset
751 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
752 }
kono
parents:
diff changeset
753 }
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 /* delete-expression:
kono
parents:
diff changeset
756 ::(opt) delete cast-expression
kono
parents:
diff changeset
757 ::(opt) delete [ ] cast-expression */
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 static void
kono
parents:
diff changeset
760 pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
761 {
kono
parents:
diff changeset
762 enum tree_code code = TREE_CODE (t);
kono
parents:
diff changeset
763 switch (code)
kono
parents:
diff changeset
764 {
kono
parents:
diff changeset
765 case DELETE_EXPR:
kono
parents:
diff changeset
766 case VEC_DELETE_EXPR:
kono
parents:
diff changeset
767 if (DELETE_EXPR_USE_GLOBAL (t))
kono
parents:
diff changeset
768 pp_cxx_colon_colon (pp);
kono
parents:
diff changeset
769 pp_cxx_ws_string (pp, "delete");
kono
parents:
diff changeset
770 pp_space (pp);
kono
parents:
diff changeset
771 if (code == VEC_DELETE_EXPR
kono
parents:
diff changeset
772 || DELETE_EXPR_USE_VEC (t))
kono
parents:
diff changeset
773 {
kono
parents:
diff changeset
774 pp_left_bracket (pp);
kono
parents:
diff changeset
775 pp_right_bracket (pp);
kono
parents:
diff changeset
776 pp_space (pp);
kono
parents:
diff changeset
777 }
kono
parents:
diff changeset
778 pp_c_cast_expression (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
779 break;
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 default:
kono
parents:
diff changeset
782 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
783 }
kono
parents:
diff changeset
784 }
kono
parents:
diff changeset
785
kono
parents:
diff changeset
786 /* unary-expression:
kono
parents:
diff changeset
787 postfix-expression
kono
parents:
diff changeset
788 ++ cast-expression
kono
parents:
diff changeset
789 -- cast-expression
kono
parents:
diff changeset
790 unary-operator cast-expression
kono
parents:
diff changeset
791 sizeof unary-expression
kono
parents:
diff changeset
792 sizeof ( type-id )
kono
parents:
diff changeset
793 sizeof ... ( identifier )
kono
parents:
diff changeset
794 new-expression
kono
parents:
diff changeset
795 delete-expression
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 unary-operator: one of
kono
parents:
diff changeset
798 * & + - !
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 GNU extensions:
kono
parents:
diff changeset
801 __alignof__ unary-expression
kono
parents:
diff changeset
802 __alignof__ ( type-id ) */
kono
parents:
diff changeset
803
kono
parents:
diff changeset
804 void
kono
parents:
diff changeset
805 cxx_pretty_printer::unary_expression (tree t)
kono
parents:
diff changeset
806 {
kono
parents:
diff changeset
807 enum tree_code code = TREE_CODE (t);
kono
parents:
diff changeset
808 switch (code)
kono
parents:
diff changeset
809 {
kono
parents:
diff changeset
810 case NEW_EXPR:
kono
parents:
diff changeset
811 case VEC_NEW_EXPR:
kono
parents:
diff changeset
812 pp_cxx_new_expression (this, t);
kono
parents:
diff changeset
813 break;
kono
parents:
diff changeset
814
kono
parents:
diff changeset
815 case DELETE_EXPR:
kono
parents:
diff changeset
816 case VEC_DELETE_EXPR:
kono
parents:
diff changeset
817 pp_cxx_delete_expression (this, t);
kono
parents:
diff changeset
818 break;
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 case SIZEOF_EXPR:
kono
parents:
diff changeset
821 if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
822 {
kono
parents:
diff changeset
823 pp_cxx_ws_string (this, "sizeof");
kono
parents:
diff changeset
824 pp_cxx_ws_string (this, "...");
kono
parents:
diff changeset
825 pp_cxx_whitespace (this);
kono
parents:
diff changeset
826 pp_cxx_left_paren (this);
kono
parents:
diff changeset
827 if (TYPE_P (TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
828 type_id (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
829 else
kono
parents:
diff changeset
830 unary_expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
831 pp_cxx_right_paren (this);
kono
parents:
diff changeset
832 break;
kono
parents:
diff changeset
833 }
kono
parents:
diff changeset
834 /* Fall through */
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 case ALIGNOF_EXPR:
kono
parents:
diff changeset
837 pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
kono
parents:
diff changeset
838 pp_cxx_whitespace (this);
kono
parents:
diff changeset
839 if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
kono
parents:
diff changeset
840 {
kono
parents:
diff changeset
841 pp_cxx_left_paren (this);
kono
parents:
diff changeset
842 type_id (TREE_TYPE (TREE_OPERAND (t, 0)));
kono
parents:
diff changeset
843 pp_cxx_right_paren (this);
kono
parents:
diff changeset
844 }
kono
parents:
diff changeset
845 else if (TYPE_P (TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
846 {
kono
parents:
diff changeset
847 pp_cxx_left_paren (this);
kono
parents:
diff changeset
848 type_id (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
849 pp_cxx_right_paren (this);
kono
parents:
diff changeset
850 }
kono
parents:
diff changeset
851 else
kono
parents:
diff changeset
852 unary_expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
853 break;
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 case AT_ENCODE_EXPR:
kono
parents:
diff changeset
856 pp_cxx_ws_string (this, "@encode");
kono
parents:
diff changeset
857 pp_cxx_whitespace (this);
kono
parents:
diff changeset
858 pp_cxx_left_paren (this);
kono
parents:
diff changeset
859 type_id (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
860 pp_cxx_right_paren (this);
kono
parents:
diff changeset
861 break;
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 case NOEXCEPT_EXPR:
kono
parents:
diff changeset
864 pp_cxx_ws_string (this, "noexcept");
kono
parents:
diff changeset
865 pp_cxx_whitespace (this);
kono
parents:
diff changeset
866 pp_cxx_left_paren (this);
kono
parents:
diff changeset
867 expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
868 pp_cxx_right_paren (this);
kono
parents:
diff changeset
869 break;
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 case UNARY_PLUS_EXPR:
kono
parents:
diff changeset
872 pp_plus (this);
kono
parents:
diff changeset
873 pp_cxx_cast_expression (this, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
874 break;
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 default:
kono
parents:
diff changeset
877 c_pretty_printer::unary_expression (t);
kono
parents:
diff changeset
878 break;
kono
parents:
diff changeset
879 }
kono
parents:
diff changeset
880 }
kono
parents:
diff changeset
881
kono
parents:
diff changeset
882 /* cast-expression:
kono
parents:
diff changeset
883 unary-expression
kono
parents:
diff changeset
884 ( type-id ) cast-expression */
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 static void
kono
parents:
diff changeset
887 pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
888 {
kono
parents:
diff changeset
889 switch (TREE_CODE (t))
kono
parents:
diff changeset
890 {
kono
parents:
diff changeset
891 case CAST_EXPR:
kono
parents:
diff changeset
892 case IMPLICIT_CONV_EXPR:
kono
parents:
diff changeset
893 pp->type_id (TREE_TYPE (t));
kono
parents:
diff changeset
894 pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
895 break;
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 default:
kono
parents:
diff changeset
898 pp_c_cast_expression (pp, t);
kono
parents:
diff changeset
899 break;
kono
parents:
diff changeset
900 }
kono
parents:
diff changeset
901 }
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 /* pm-expression:
kono
parents:
diff changeset
904 cast-expression
kono
parents:
diff changeset
905 pm-expression .* cast-expression
kono
parents:
diff changeset
906 pm-expression ->* cast-expression */
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 static void
kono
parents:
diff changeset
909 pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
910 {
kono
parents:
diff changeset
911 switch (TREE_CODE (t))
kono
parents:
diff changeset
912 {
kono
parents:
diff changeset
913 /* Handle unfortunate OFFSET_REF overloading here. */
kono
parents:
diff changeset
914 case OFFSET_REF:
kono
parents:
diff changeset
915 if (TYPE_P (TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
916 {
kono
parents:
diff changeset
917 pp_cxx_qualified_id (pp, t);
kono
parents:
diff changeset
918 break;
kono
parents:
diff changeset
919 }
kono
parents:
diff changeset
920 /* Fall through. */
kono
parents:
diff changeset
921 case MEMBER_REF:
kono
parents:
diff changeset
922 case DOTSTAR_EXPR:
kono
parents:
diff changeset
923 pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
kono
parents:
diff changeset
924 if (TREE_CODE (t) == MEMBER_REF)
kono
parents:
diff changeset
925 pp_cxx_arrow (pp);
kono
parents:
diff changeset
926 else
kono
parents:
diff changeset
927 pp_cxx_dot (pp);
kono
parents:
diff changeset
928 pp_star(pp);
kono
parents:
diff changeset
929 pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
930 break;
kono
parents:
diff changeset
931
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 default:
kono
parents:
diff changeset
934 pp_cxx_cast_expression (pp, t);
kono
parents:
diff changeset
935 break;
kono
parents:
diff changeset
936 }
kono
parents:
diff changeset
937 }
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 /* multiplicative-expression:
kono
parents:
diff changeset
940 pm-expression
kono
parents:
diff changeset
941 multiplicative-expression * pm-expression
kono
parents:
diff changeset
942 multiplicative-expression / pm-expression
kono
parents:
diff changeset
943 multiplicative-expression % pm-expression */
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 void
kono
parents:
diff changeset
946 cxx_pretty_printer::multiplicative_expression (tree e)
kono
parents:
diff changeset
947 {
kono
parents:
diff changeset
948 enum tree_code code = TREE_CODE (e);
kono
parents:
diff changeset
949 switch (code)
kono
parents:
diff changeset
950 {
kono
parents:
diff changeset
951 case MULT_EXPR:
kono
parents:
diff changeset
952 case TRUNC_DIV_EXPR:
kono
parents:
diff changeset
953 case TRUNC_MOD_EXPR:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
954 case EXACT_DIV_EXPR:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
955 case RDIV_EXPR:
111
kono
parents:
diff changeset
956 multiplicative_expression (TREE_OPERAND (e, 0));
kono
parents:
diff changeset
957 pp_space (this);
kono
parents:
diff changeset
958 if (code == MULT_EXPR)
kono
parents:
diff changeset
959 pp_star (this);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
960 else if (code != TRUNC_MOD_EXPR)
111
kono
parents:
diff changeset
961 pp_slash (this);
kono
parents:
diff changeset
962 else
kono
parents:
diff changeset
963 pp_modulo (this);
kono
parents:
diff changeset
964 pp_space (this);
kono
parents:
diff changeset
965 pp_cxx_pm_expression (this, TREE_OPERAND (e, 1));
kono
parents:
diff changeset
966 break;
kono
parents:
diff changeset
967
kono
parents:
diff changeset
968 default:
kono
parents:
diff changeset
969 pp_cxx_pm_expression (this, e);
kono
parents:
diff changeset
970 break;
kono
parents:
diff changeset
971 }
kono
parents:
diff changeset
972 }
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 /* conditional-expression:
kono
parents:
diff changeset
975 logical-or-expression
kono
parents:
diff changeset
976 logical-or-expression ? expression : assignment-expression */
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 void
kono
parents:
diff changeset
979 cxx_pretty_printer::conditional_expression (tree e)
kono
parents:
diff changeset
980 {
kono
parents:
diff changeset
981 if (TREE_CODE (e) == COND_EXPR)
kono
parents:
diff changeset
982 {
kono
parents:
diff changeset
983 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
kono
parents:
diff changeset
984 pp_space (this);
kono
parents:
diff changeset
985 pp_question (this);
kono
parents:
diff changeset
986 pp_space (this);
kono
parents:
diff changeset
987 expression (TREE_OPERAND (e, 1));
kono
parents:
diff changeset
988 pp_space (this);
kono
parents:
diff changeset
989 assignment_expression (TREE_OPERAND (e, 2));
kono
parents:
diff changeset
990 }
kono
parents:
diff changeset
991 else
kono
parents:
diff changeset
992 pp_c_logical_or_expression (this, e);
kono
parents:
diff changeset
993 }
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 /* Pretty-print a compound assignment operator token as indicated by T. */
kono
parents:
diff changeset
996
kono
parents:
diff changeset
997 static void
kono
parents:
diff changeset
998 pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
999 {
kono
parents:
diff changeset
1000 const char *op;
kono
parents:
diff changeset
1001
kono
parents:
diff changeset
1002 switch (TREE_CODE (t))
kono
parents:
diff changeset
1003 {
kono
parents:
diff changeset
1004 case NOP_EXPR:
kono
parents:
diff changeset
1005 op = "=";
kono
parents:
diff changeset
1006 break;
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 case PLUS_EXPR:
kono
parents:
diff changeset
1009 op = "+=";
kono
parents:
diff changeset
1010 break;
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 case MINUS_EXPR:
kono
parents:
diff changeset
1013 op = "-=";
kono
parents:
diff changeset
1014 break;
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 case TRUNC_DIV_EXPR:
kono
parents:
diff changeset
1017 op = "/=";
kono
parents:
diff changeset
1018 break;
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 case TRUNC_MOD_EXPR:
kono
parents:
diff changeset
1021 op = "%=";
kono
parents:
diff changeset
1022 break;
kono
parents:
diff changeset
1023
kono
parents:
diff changeset
1024 default:
kono
parents:
diff changeset
1025 op = get_tree_code_name (TREE_CODE (t));
kono
parents:
diff changeset
1026 break;
kono
parents:
diff changeset
1027 }
kono
parents:
diff changeset
1028
kono
parents:
diff changeset
1029 pp_cxx_ws_string (pp, op);
kono
parents:
diff changeset
1030 }
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 /* assignment-expression:
kono
parents:
diff changeset
1034 conditional-expression
kono
parents:
diff changeset
1035 logical-or-expression assignment-operator assignment-expression
kono
parents:
diff changeset
1036 throw-expression
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 throw-expression:
kono
parents:
diff changeset
1039 throw assignment-expression(opt)
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 assignment-operator: one of
kono
parents:
diff changeset
1042 = *= /= %= += -= >>= <<= &= ^= |= */
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 void
kono
parents:
diff changeset
1045 cxx_pretty_printer::assignment_expression (tree e)
kono
parents:
diff changeset
1046 {
kono
parents:
diff changeset
1047 switch (TREE_CODE (e))
kono
parents:
diff changeset
1048 {
kono
parents:
diff changeset
1049 case MODIFY_EXPR:
kono
parents:
diff changeset
1050 case INIT_EXPR:
kono
parents:
diff changeset
1051 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
kono
parents:
diff changeset
1052 pp_space (this);
kono
parents:
diff changeset
1053 pp_equal (this);
kono
parents:
diff changeset
1054 pp_space (this);
kono
parents:
diff changeset
1055 assignment_expression (TREE_OPERAND (e, 1));
kono
parents:
diff changeset
1056 break;
kono
parents:
diff changeset
1057
kono
parents:
diff changeset
1058 case THROW_EXPR:
kono
parents:
diff changeset
1059 pp_cxx_ws_string (this, "throw");
kono
parents:
diff changeset
1060 if (TREE_OPERAND (e, 0))
kono
parents:
diff changeset
1061 assignment_expression (TREE_OPERAND (e, 0));
kono
parents:
diff changeset
1062 break;
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 case MODOP_EXPR:
kono
parents:
diff changeset
1065 pp_c_logical_or_expression (this, TREE_OPERAND (e, 0));
kono
parents:
diff changeset
1066 pp_cxx_assignment_operator (this, TREE_OPERAND (e, 1));
kono
parents:
diff changeset
1067 assignment_expression (TREE_OPERAND (e, 2));
kono
parents:
diff changeset
1068 break;
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 default:
kono
parents:
diff changeset
1071 conditional_expression (e);
kono
parents:
diff changeset
1072 break;
kono
parents:
diff changeset
1073 }
kono
parents:
diff changeset
1074 }
kono
parents:
diff changeset
1075
kono
parents:
diff changeset
1076 void
kono
parents:
diff changeset
1077 cxx_pretty_printer::expression (tree t)
kono
parents:
diff changeset
1078 {
kono
parents:
diff changeset
1079 switch (TREE_CODE (t))
kono
parents:
diff changeset
1080 {
kono
parents:
diff changeset
1081 case STRING_CST:
kono
parents:
diff changeset
1082 case VOID_CST:
kono
parents:
diff changeset
1083 case INTEGER_CST:
kono
parents:
diff changeset
1084 case REAL_CST:
kono
parents:
diff changeset
1085 case COMPLEX_CST:
kono
parents:
diff changeset
1086 constant (t);
kono
parents:
diff changeset
1087 break;
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 case USERDEF_LITERAL:
kono
parents:
diff changeset
1090 pp_cxx_userdef_literal (this, t);
kono
parents:
diff changeset
1091 break;
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 case RESULT_DECL:
kono
parents:
diff changeset
1094 pp_cxx_unqualified_id (this, t);
kono
parents:
diff changeset
1095 break;
kono
parents:
diff changeset
1096
kono
parents:
diff changeset
1097 #if 0
kono
parents:
diff changeset
1098 case OFFSET_REF:
kono
parents:
diff changeset
1099 #endif
kono
parents:
diff changeset
1100 case SCOPE_REF:
kono
parents:
diff changeset
1101 case PTRMEM_CST:
kono
parents:
diff changeset
1102 pp_cxx_qualified_id (this, t);
kono
parents:
diff changeset
1103 break;
kono
parents:
diff changeset
1104
kono
parents:
diff changeset
1105 case OVERLOAD:
kono
parents:
diff changeset
1106 t = OVL_FIRST (t);
kono
parents:
diff changeset
1107 /* FALLTHRU */
kono
parents:
diff changeset
1108 case VAR_DECL:
kono
parents:
diff changeset
1109 case PARM_DECL:
kono
parents:
diff changeset
1110 case FIELD_DECL:
kono
parents:
diff changeset
1111 case CONST_DECL:
kono
parents:
diff changeset
1112 case FUNCTION_DECL:
kono
parents:
diff changeset
1113 case BASELINK:
kono
parents:
diff changeset
1114 case TEMPLATE_DECL:
kono
parents:
diff changeset
1115 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1116 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
1117 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1118 case STMT_EXPR:
kono
parents:
diff changeset
1119 case REQUIRES_EXPR:
kono
parents:
diff changeset
1120 primary_expression (t);
kono
parents:
diff changeset
1121 break;
kono
parents:
diff changeset
1122
kono
parents:
diff changeset
1123 case CALL_EXPR:
kono
parents:
diff changeset
1124 case DYNAMIC_CAST_EXPR:
kono
parents:
diff changeset
1125 case STATIC_CAST_EXPR:
kono
parents:
diff changeset
1126 case REINTERPRET_CAST_EXPR:
kono
parents:
diff changeset
1127 case CONST_CAST_EXPR:
kono
parents:
diff changeset
1128 #if 0
kono
parents:
diff changeset
1129 case MEMBER_REF:
kono
parents:
diff changeset
1130 #endif
kono
parents:
diff changeset
1131 case EMPTY_CLASS_EXPR:
kono
parents:
diff changeset
1132 case TYPEID_EXPR:
kono
parents:
diff changeset
1133 case PSEUDO_DTOR_EXPR:
kono
parents:
diff changeset
1134 case AGGR_INIT_EXPR:
kono
parents:
diff changeset
1135 case ARROW_EXPR:
kono
parents:
diff changeset
1136 postfix_expression (t);
kono
parents:
diff changeset
1137 break;
kono
parents:
diff changeset
1138
kono
parents:
diff changeset
1139 case NEW_EXPR:
kono
parents:
diff changeset
1140 case VEC_NEW_EXPR:
kono
parents:
diff changeset
1141 pp_cxx_new_expression (this, t);
kono
parents:
diff changeset
1142 break;
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 case DELETE_EXPR:
kono
parents:
diff changeset
1145 case VEC_DELETE_EXPR:
kono
parents:
diff changeset
1146 pp_cxx_delete_expression (this, t);
kono
parents:
diff changeset
1147 break;
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 case SIZEOF_EXPR:
kono
parents:
diff changeset
1150 case ALIGNOF_EXPR:
kono
parents:
diff changeset
1151 case NOEXCEPT_EXPR:
kono
parents:
diff changeset
1152 case UNARY_PLUS_EXPR:
kono
parents:
diff changeset
1153 unary_expression (t);
kono
parents:
diff changeset
1154 break;
kono
parents:
diff changeset
1155
kono
parents:
diff changeset
1156 case CAST_EXPR:
kono
parents:
diff changeset
1157 case IMPLICIT_CONV_EXPR:
kono
parents:
diff changeset
1158 pp_cxx_cast_expression (this, t);
kono
parents:
diff changeset
1159 break;
kono
parents:
diff changeset
1160
kono
parents:
diff changeset
1161 case OFFSET_REF:
kono
parents:
diff changeset
1162 case MEMBER_REF:
kono
parents:
diff changeset
1163 case DOTSTAR_EXPR:
kono
parents:
diff changeset
1164 pp_cxx_pm_expression (this, t);
kono
parents:
diff changeset
1165 break;
kono
parents:
diff changeset
1166
kono
parents:
diff changeset
1167 case MULT_EXPR:
kono
parents:
diff changeset
1168 case TRUNC_DIV_EXPR:
kono
parents:
diff changeset
1169 case TRUNC_MOD_EXPR:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1170 case EXACT_DIV_EXPR:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1171 case RDIV_EXPR:
111
kono
parents:
diff changeset
1172 multiplicative_expression (t);
kono
parents:
diff changeset
1173 break;
kono
parents:
diff changeset
1174
kono
parents:
diff changeset
1175 case COND_EXPR:
kono
parents:
diff changeset
1176 conditional_expression (t);
kono
parents:
diff changeset
1177 break;
kono
parents:
diff changeset
1178
kono
parents:
diff changeset
1179 case MODIFY_EXPR:
kono
parents:
diff changeset
1180 case INIT_EXPR:
kono
parents:
diff changeset
1181 case THROW_EXPR:
kono
parents:
diff changeset
1182 case MODOP_EXPR:
kono
parents:
diff changeset
1183 assignment_expression (t);
kono
parents:
diff changeset
1184 break;
kono
parents:
diff changeset
1185
kono
parents:
diff changeset
1186 case NON_DEPENDENT_EXPR:
kono
parents:
diff changeset
1187 case MUST_NOT_THROW_EXPR:
kono
parents:
diff changeset
1188 expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
1189 break;
kono
parents:
diff changeset
1190
kono
parents:
diff changeset
1191 case EXPR_PACK_EXPANSION:
kono
parents:
diff changeset
1192 expression (PACK_EXPANSION_PATTERN (t));
kono
parents:
diff changeset
1193 pp_cxx_ws_string (this, "...");
kono
parents:
diff changeset
1194 break;
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 case UNARY_LEFT_FOLD_EXPR:
kono
parents:
diff changeset
1197 pp_cxx_unary_left_fold_expression (this, t);
kono
parents:
diff changeset
1198 break;
kono
parents:
diff changeset
1199
kono
parents:
diff changeset
1200 case UNARY_RIGHT_FOLD_EXPR:
kono
parents:
diff changeset
1201 pp_cxx_unary_right_fold_expression (this, t);
kono
parents:
diff changeset
1202 break;
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204 case BINARY_LEFT_FOLD_EXPR:
kono
parents:
diff changeset
1205 case BINARY_RIGHT_FOLD_EXPR:
kono
parents:
diff changeset
1206 pp_cxx_binary_fold_expression (this, t);
kono
parents:
diff changeset
1207 break;
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 case TEMPLATE_ID_EXPR:
kono
parents:
diff changeset
1210 pp_cxx_template_id (this, t);
kono
parents:
diff changeset
1211 break;
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 case NONTYPE_ARGUMENT_PACK:
kono
parents:
diff changeset
1214 {
kono
parents:
diff changeset
1215 tree args = ARGUMENT_PACK_ARGS (t);
kono
parents:
diff changeset
1216 int i, len = TREE_VEC_LENGTH (args);
kono
parents:
diff changeset
1217 for (i = 0; i < len; ++i)
kono
parents:
diff changeset
1218 {
kono
parents:
diff changeset
1219 if (i > 0)
kono
parents:
diff changeset
1220 pp_cxx_separate_with (this, ',');
kono
parents:
diff changeset
1221 expression (TREE_VEC_ELT (args, i));
kono
parents:
diff changeset
1222 }
kono
parents:
diff changeset
1223 }
kono
parents:
diff changeset
1224 break;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1225
111
kono
parents:
diff changeset
1226 case LAMBDA_EXPR:
kono
parents:
diff changeset
1227 pp_cxx_ws_string (this, "<lambda>");
kono
parents:
diff changeset
1228 break;
kono
parents:
diff changeset
1229
kono
parents:
diff changeset
1230 case TRAIT_EXPR:
kono
parents:
diff changeset
1231 pp_cxx_trait_expression (this, t);
kono
parents:
diff changeset
1232 break;
kono
parents:
diff changeset
1233
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1234 case ATOMIC_CONSTR:
111
kono
parents:
diff changeset
1235 case CHECK_CONSTR:
kono
parents:
diff changeset
1236 case CONJ_CONSTR:
kono
parents:
diff changeset
1237 case DISJ_CONSTR:
kono
parents:
diff changeset
1238 pp_cxx_constraint (this, t);
kono
parents:
diff changeset
1239 break;
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 case PAREN_EXPR:
kono
parents:
diff changeset
1242 pp_cxx_left_paren (this);
kono
parents:
diff changeset
1243 expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
1244 pp_cxx_right_paren (this);
kono
parents:
diff changeset
1245 break;
kono
parents:
diff changeset
1246
kono
parents:
diff changeset
1247 default:
kono
parents:
diff changeset
1248 c_pretty_printer::expression (t);
kono
parents:
diff changeset
1249 break;
kono
parents:
diff changeset
1250 }
kono
parents:
diff changeset
1251 }
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 /* Declarations. */
kono
parents:
diff changeset
1255
kono
parents:
diff changeset
1256 /* function-specifier:
kono
parents:
diff changeset
1257 inline
kono
parents:
diff changeset
1258 virtual
kono
parents:
diff changeset
1259 explicit */
kono
parents:
diff changeset
1260
kono
parents:
diff changeset
1261 void
kono
parents:
diff changeset
1262 cxx_pretty_printer::function_specifier (tree t)
kono
parents:
diff changeset
1263 {
kono
parents:
diff changeset
1264 switch (TREE_CODE (t))
kono
parents:
diff changeset
1265 {
kono
parents:
diff changeset
1266 case FUNCTION_DECL:
kono
parents:
diff changeset
1267 if (DECL_VIRTUAL_P (t))
kono
parents:
diff changeset
1268 pp_cxx_ws_string (this, "virtual");
kono
parents:
diff changeset
1269 else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
kono
parents:
diff changeset
1270 pp_cxx_ws_string (this, "explicit");
kono
parents:
diff changeset
1271 else
kono
parents:
diff changeset
1272 c_pretty_printer::function_specifier (t);
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 default:
kono
parents:
diff changeset
1275 break;
kono
parents:
diff changeset
1276 }
kono
parents:
diff changeset
1277 }
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 /* decl-specifier-seq:
kono
parents:
diff changeset
1280 decl-specifier-seq(opt) decl-specifier
kono
parents:
diff changeset
1281
kono
parents:
diff changeset
1282 decl-specifier:
kono
parents:
diff changeset
1283 storage-class-specifier
kono
parents:
diff changeset
1284 type-specifier
kono
parents:
diff changeset
1285 function-specifier
kono
parents:
diff changeset
1286 friend
kono
parents:
diff changeset
1287 typedef */
kono
parents:
diff changeset
1288
kono
parents:
diff changeset
1289 void
kono
parents:
diff changeset
1290 cxx_pretty_printer::declaration_specifiers (tree t)
kono
parents:
diff changeset
1291 {
kono
parents:
diff changeset
1292 switch (TREE_CODE (t))
kono
parents:
diff changeset
1293 {
kono
parents:
diff changeset
1294 case VAR_DECL:
kono
parents:
diff changeset
1295 case PARM_DECL:
kono
parents:
diff changeset
1296 case CONST_DECL:
kono
parents:
diff changeset
1297 case FIELD_DECL:
kono
parents:
diff changeset
1298 storage_class_specifier (t);
kono
parents:
diff changeset
1299 declaration_specifiers (TREE_TYPE (t));
kono
parents:
diff changeset
1300 break;
kono
parents:
diff changeset
1301
kono
parents:
diff changeset
1302 case TYPE_DECL:
kono
parents:
diff changeset
1303 pp_cxx_ws_string (this, "typedef");
kono
parents:
diff changeset
1304 declaration_specifiers (TREE_TYPE (t));
kono
parents:
diff changeset
1305 break;
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 case FUNCTION_DECL:
kono
parents:
diff changeset
1308 /* Constructors don't have return types. And conversion functions
kono
parents:
diff changeset
1309 do not have a type-specifier in their return types. */
kono
parents:
diff changeset
1310 if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
kono
parents:
diff changeset
1311 function_specifier (t);
kono
parents:
diff changeset
1312 else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
kono
parents:
diff changeset
1313 declaration_specifiers (TREE_TYPE (TREE_TYPE (t)));
kono
parents:
diff changeset
1314 else
kono
parents:
diff changeset
1315 c_pretty_printer::declaration_specifiers (t);
kono
parents:
diff changeset
1316 break;
kono
parents:
diff changeset
1317 default:
kono
parents:
diff changeset
1318 c_pretty_printer::declaration_specifiers (t);
kono
parents:
diff changeset
1319 break;
kono
parents:
diff changeset
1320 }
kono
parents:
diff changeset
1321 }
kono
parents:
diff changeset
1322
kono
parents:
diff changeset
1323 /* simple-type-specifier:
kono
parents:
diff changeset
1324 ::(opt) nested-name-specifier(opt) type-name
kono
parents:
diff changeset
1325 ::(opt) nested-name-specifier(opt) template(opt) template-id
kono
parents:
diff changeset
1326 char
kono
parents:
diff changeset
1327 wchar_t
kono
parents:
diff changeset
1328 bool
kono
parents:
diff changeset
1329 short
kono
parents:
diff changeset
1330 int
kono
parents:
diff changeset
1331 long
kono
parents:
diff changeset
1332 signed
kono
parents:
diff changeset
1333 unsigned
kono
parents:
diff changeset
1334 float
kono
parents:
diff changeset
1335 double
kono
parents:
diff changeset
1336 void */
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 void
kono
parents:
diff changeset
1339 cxx_pretty_printer::simple_type_specifier (tree t)
kono
parents:
diff changeset
1340 {
kono
parents:
diff changeset
1341 switch (TREE_CODE (t))
kono
parents:
diff changeset
1342 {
kono
parents:
diff changeset
1343 case RECORD_TYPE:
kono
parents:
diff changeset
1344 case UNION_TYPE:
kono
parents:
diff changeset
1345 case ENUMERAL_TYPE:
kono
parents:
diff changeset
1346 pp_cxx_qualified_id (this, t);
kono
parents:
diff changeset
1347 break;
kono
parents:
diff changeset
1348
kono
parents:
diff changeset
1349 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1350 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1351 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
1352 case BOUND_TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1353 pp_cxx_unqualified_id (this, t);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1354 if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1355 pp_cxx_constrained_type_spec (this, c);
111
kono
parents:
diff changeset
1356 break;
kono
parents:
diff changeset
1357
kono
parents:
diff changeset
1358 case TYPENAME_TYPE:
kono
parents:
diff changeset
1359 pp_cxx_ws_string (this, "typename");
kono
parents:
diff changeset
1360 pp_cxx_nested_name_specifier (this, TYPE_CONTEXT (t));
kono
parents:
diff changeset
1361 pp_cxx_unqualified_id (this, TYPE_NAME (t));
kono
parents:
diff changeset
1362 break;
kono
parents:
diff changeset
1363
kono
parents:
diff changeset
1364 default:
kono
parents:
diff changeset
1365 c_pretty_printer::simple_type_specifier (t);
kono
parents:
diff changeset
1366 break;
kono
parents:
diff changeset
1367 }
kono
parents:
diff changeset
1368 }
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370 /* type-specifier-seq:
kono
parents:
diff changeset
1371 type-specifier type-specifier-seq(opt)
kono
parents:
diff changeset
1372
kono
parents:
diff changeset
1373 type-specifier:
kono
parents:
diff changeset
1374 simple-type-specifier
kono
parents:
diff changeset
1375 class-specifier
kono
parents:
diff changeset
1376 enum-specifier
kono
parents:
diff changeset
1377 elaborated-type-specifier
kono
parents:
diff changeset
1378 cv-qualifier */
kono
parents:
diff changeset
1379
kono
parents:
diff changeset
1380 static void
kono
parents:
diff changeset
1381 pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1382 {
kono
parents:
diff changeset
1383 switch (TREE_CODE (t))
kono
parents:
diff changeset
1384 {
kono
parents:
diff changeset
1385 case TEMPLATE_DECL:
kono
parents:
diff changeset
1386 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1387 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1388 case TYPE_DECL:
kono
parents:
diff changeset
1389 case BOUND_TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1390 pp_cxx_cv_qualifier_seq (pp, t);
kono
parents:
diff changeset
1391 pp->simple_type_specifier (t);
kono
parents:
diff changeset
1392 break;
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 case METHOD_TYPE:
kono
parents:
diff changeset
1395 pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
kono
parents:
diff changeset
1396 pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
kono
parents:
diff changeset
1397 pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
kono
parents:
diff changeset
1398 break;
kono
parents:
diff changeset
1399
kono
parents:
diff changeset
1400 case DECLTYPE_TYPE:
kono
parents:
diff changeset
1401 pp_cxx_ws_string (pp, "decltype");
kono
parents:
diff changeset
1402 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1403 pp->expression (DECLTYPE_TYPE_EXPR (t));
kono
parents:
diff changeset
1404 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
1405 break;
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 case RECORD_TYPE:
kono
parents:
diff changeset
1408 if (TYPE_PTRMEMFUNC_P (t))
kono
parents:
diff changeset
1409 {
kono
parents:
diff changeset
1410 tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
kono
parents:
diff changeset
1411 pp->declaration_specifiers (TREE_TYPE (TREE_TYPE (pfm)));
kono
parents:
diff changeset
1412 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1413 pp_cxx_ptr_operator (pp, t);
kono
parents:
diff changeset
1414 break;
kono
parents:
diff changeset
1415 }
kono
parents:
diff changeset
1416 /* fall through */
kono
parents:
diff changeset
1417
kono
parents:
diff changeset
1418 default:
kono
parents:
diff changeset
1419 if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
kono
parents:
diff changeset
1420 pp_c_specifier_qualifier_list (pp, t);
kono
parents:
diff changeset
1421 }
kono
parents:
diff changeset
1422 }
kono
parents:
diff changeset
1423
kono
parents:
diff changeset
1424 /* ptr-operator:
kono
parents:
diff changeset
1425 * cv-qualifier-seq(opt)
kono
parents:
diff changeset
1426 &
kono
parents:
diff changeset
1427 ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429 static void
kono
parents:
diff changeset
1430 pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1431 {
kono
parents:
diff changeset
1432 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
kono
parents:
diff changeset
1433 t = TREE_TYPE (t);
kono
parents:
diff changeset
1434 switch (TREE_CODE (t))
kono
parents:
diff changeset
1435 {
kono
parents:
diff changeset
1436 case REFERENCE_TYPE:
kono
parents:
diff changeset
1437 case POINTER_TYPE:
kono
parents:
diff changeset
1438 if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t)))
kono
parents:
diff changeset
1439 pp_cxx_ptr_operator (pp, TREE_TYPE (t));
kono
parents:
diff changeset
1440 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (TREE_TYPE (t)));
kono
parents:
diff changeset
1441 if (TYPE_PTR_P (t))
kono
parents:
diff changeset
1442 {
kono
parents:
diff changeset
1443 pp_star (pp);
kono
parents:
diff changeset
1444 pp_cxx_cv_qualifier_seq (pp, t);
kono
parents:
diff changeset
1445 }
kono
parents:
diff changeset
1446 else
kono
parents:
diff changeset
1447 pp_ampersand (pp);
kono
parents:
diff changeset
1448 break;
kono
parents:
diff changeset
1449
kono
parents:
diff changeset
1450 case RECORD_TYPE:
kono
parents:
diff changeset
1451 if (TYPE_PTRMEMFUNC_P (t))
kono
parents:
diff changeset
1452 {
kono
parents:
diff changeset
1453 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1454 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
kono
parents:
diff changeset
1455 pp_star (pp);
kono
parents:
diff changeset
1456 break;
kono
parents:
diff changeset
1457 }
kono
parents:
diff changeset
1458 /* FALLTHRU */
kono
parents:
diff changeset
1459 case OFFSET_TYPE:
kono
parents:
diff changeset
1460 if (TYPE_PTRMEM_P (t))
kono
parents:
diff changeset
1461 {
kono
parents:
diff changeset
1462 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
kono
parents:
diff changeset
1463 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1464 pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
kono
parents:
diff changeset
1465 pp_star (pp);
kono
parents:
diff changeset
1466 pp_cxx_cv_qualifier_seq (pp, t);
kono
parents:
diff changeset
1467 break;
kono
parents:
diff changeset
1468 }
kono
parents:
diff changeset
1469 /* fall through. */
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 default:
kono
parents:
diff changeset
1472 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
1473 break;
kono
parents:
diff changeset
1474 }
kono
parents:
diff changeset
1475 }
kono
parents:
diff changeset
1476
kono
parents:
diff changeset
1477 static inline tree
kono
parents:
diff changeset
1478 pp_cxx_implicit_parameter_type (tree mf)
kono
parents:
diff changeset
1479 {
kono
parents:
diff changeset
1480 return class_of_this_parm (TREE_TYPE (mf));
kono
parents:
diff changeset
1481 }
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 /*
kono
parents:
diff changeset
1484 parameter-declaration:
kono
parents:
diff changeset
1485 decl-specifier-seq declarator
kono
parents:
diff changeset
1486 decl-specifier-seq declarator = assignment-expression
kono
parents:
diff changeset
1487 decl-specifier-seq abstract-declarator(opt)
kono
parents:
diff changeset
1488 decl-specifier-seq abstract-declarator(opt) assignment-expression */
kono
parents:
diff changeset
1489
kono
parents:
diff changeset
1490 static inline void
kono
parents:
diff changeset
1491 pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1492 {
kono
parents:
diff changeset
1493 pp->declaration_specifiers (t);
kono
parents:
diff changeset
1494 if (TYPE_P (t))
kono
parents:
diff changeset
1495 pp->abstract_declarator (t);
kono
parents:
diff changeset
1496 else
kono
parents:
diff changeset
1497 pp->declarator (t);
kono
parents:
diff changeset
1498 }
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 /* parameter-declaration-clause:
kono
parents:
diff changeset
1501 parameter-declaration-list(opt) ...(opt)
kono
parents:
diff changeset
1502 parameter-declaration-list , ...
kono
parents:
diff changeset
1503
kono
parents:
diff changeset
1504 parameter-declaration-list:
kono
parents:
diff changeset
1505 parameter-declaration
kono
parents:
diff changeset
1506 parameter-declaration-list , parameter-declaration */
kono
parents:
diff changeset
1507
kono
parents:
diff changeset
1508 static void
kono
parents:
diff changeset
1509 pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1510 {
kono
parents:
diff changeset
1511 tree args;
kono
parents:
diff changeset
1512 tree types;
kono
parents:
diff changeset
1513 bool abstract;
kono
parents:
diff changeset
1514
kono
parents:
diff changeset
1515 // For a requires clause or the explicit printing of a parameter list
kono
parents:
diff changeset
1516 // we expect T to be a chain of PARM_DECLs. Otherwise, the list of
kono
parents:
diff changeset
1517 // args and types are taken from the function decl T.
kono
parents:
diff changeset
1518 if (TREE_CODE (t) == PARM_DECL)
kono
parents:
diff changeset
1519 {
kono
parents:
diff changeset
1520 args = t;
kono
parents:
diff changeset
1521 types = t;
kono
parents:
diff changeset
1522 abstract = false;
kono
parents:
diff changeset
1523 }
kono
parents:
diff changeset
1524 else
kono
parents:
diff changeset
1525 {
kono
parents:
diff changeset
1526 bool type_p = TYPE_P (t);
kono
parents:
diff changeset
1527 args = type_p ? NULL : FUNCTION_FIRST_USER_PARM (t);
kono
parents:
diff changeset
1528 types = type_p ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
kono
parents:
diff changeset
1529 abstract = args == NULL || pp->flags & pp_c_flag_abstract;
kono
parents:
diff changeset
1530 }
kono
parents:
diff changeset
1531 bool first = true;
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533 /* Skip artificial parameter for nonstatic member functions. */
kono
parents:
diff changeset
1534 if (TREE_CODE (t) == METHOD_TYPE)
kono
parents:
diff changeset
1535 types = TREE_CHAIN (types);
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1538 for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
kono
parents:
diff changeset
1539 {
kono
parents:
diff changeset
1540 if (!first)
kono
parents:
diff changeset
1541 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
1542 first = false;
kono
parents:
diff changeset
1543 pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
kono
parents:
diff changeset
1544 if (!abstract && pp->flags & pp_cxx_flag_default_argument)
kono
parents:
diff changeset
1545 {
kono
parents:
diff changeset
1546 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1547 pp_equal (pp);
kono
parents:
diff changeset
1548 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1549 pp->assignment_expression (TREE_PURPOSE (types));
kono
parents:
diff changeset
1550 }
kono
parents:
diff changeset
1551 }
kono
parents:
diff changeset
1552 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
1553 }
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 /* exception-specification:
kono
parents:
diff changeset
1556 throw ( type-id-list(opt) )
kono
parents:
diff changeset
1557
kono
parents:
diff changeset
1558 type-id-list
kono
parents:
diff changeset
1559 type-id
kono
parents:
diff changeset
1560 type-id-list , type-id */
kono
parents:
diff changeset
1561
kono
parents:
diff changeset
1562 static void
kono
parents:
diff changeset
1563 pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1564 {
kono
parents:
diff changeset
1565 tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
kono
parents:
diff changeset
1566 bool need_comma = false;
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 if (ex_spec == NULL)
kono
parents:
diff changeset
1569 return;
kono
parents:
diff changeset
1570 if (TREE_PURPOSE (ex_spec))
kono
parents:
diff changeset
1571 {
kono
parents:
diff changeset
1572 pp_cxx_ws_string (pp, "noexcept");
kono
parents:
diff changeset
1573 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1574 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1575 if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
kono
parents:
diff changeset
1576 pp_cxx_ws_string (pp, "<uninstantiated>");
kono
parents:
diff changeset
1577 else
kono
parents:
diff changeset
1578 pp->expression (TREE_PURPOSE (ex_spec));
kono
parents:
diff changeset
1579 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
1580 return;
kono
parents:
diff changeset
1581 }
kono
parents:
diff changeset
1582 pp_cxx_ws_string (pp, "throw");
kono
parents:
diff changeset
1583 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
1584 for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
kono
parents:
diff changeset
1585 {
kono
parents:
diff changeset
1586 tree type = TREE_VALUE (ex_spec);
kono
parents:
diff changeset
1587 tree argpack = NULL_TREE;
kono
parents:
diff changeset
1588 int i, len = 1;
kono
parents:
diff changeset
1589
kono
parents:
diff changeset
1590 if (ARGUMENT_PACK_P (type))
kono
parents:
diff changeset
1591 {
kono
parents:
diff changeset
1592 argpack = ARGUMENT_PACK_ARGS (type);
kono
parents:
diff changeset
1593 len = TREE_VEC_LENGTH (argpack);
kono
parents:
diff changeset
1594 }
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 for (i = 0; i < len; ++i)
kono
parents:
diff changeset
1597 {
kono
parents:
diff changeset
1598 if (argpack)
kono
parents:
diff changeset
1599 type = TREE_VEC_ELT (argpack, i);
kono
parents:
diff changeset
1600
kono
parents:
diff changeset
1601 if (need_comma)
kono
parents:
diff changeset
1602 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
1603 else
kono
parents:
diff changeset
1604 need_comma = true;
kono
parents:
diff changeset
1605
kono
parents:
diff changeset
1606 pp->type_id (type);
kono
parents:
diff changeset
1607 }
kono
parents:
diff changeset
1608 }
kono
parents:
diff changeset
1609 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
1610 }
kono
parents:
diff changeset
1611
kono
parents:
diff changeset
1612 /* direct-declarator:
kono
parents:
diff changeset
1613 declarator-id
kono
parents:
diff changeset
1614 direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
kono
parents:
diff changeset
1615 exception-specification(opt)
kono
parents:
diff changeset
1616 direct-declaration [ constant-expression(opt) ]
kono
parents:
diff changeset
1617 ( declarator ) */
kono
parents:
diff changeset
1618
kono
parents:
diff changeset
1619 void
kono
parents:
diff changeset
1620 cxx_pretty_printer::direct_declarator (tree t)
kono
parents:
diff changeset
1621 {
kono
parents:
diff changeset
1622 switch (TREE_CODE (t))
kono
parents:
diff changeset
1623 {
kono
parents:
diff changeset
1624 case VAR_DECL:
kono
parents:
diff changeset
1625 case PARM_DECL:
kono
parents:
diff changeset
1626 case CONST_DECL:
kono
parents:
diff changeset
1627 case FIELD_DECL:
kono
parents:
diff changeset
1628 if (DECL_NAME (t))
kono
parents:
diff changeset
1629 {
kono
parents:
diff changeset
1630 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (t));
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 if ((TREE_CODE (t) == PARM_DECL && DECL_PACK_P (t))
kono
parents:
diff changeset
1633 || template_parameter_pack_p (t))
kono
parents:
diff changeset
1634 /* A function parameter pack or non-type template
kono
parents:
diff changeset
1635 parameter pack. */
kono
parents:
diff changeset
1636 pp_cxx_ws_string (this, "...");
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638 id_expression (DECL_NAME (t));
kono
parents:
diff changeset
1639 }
kono
parents:
diff changeset
1640 abstract_declarator (TREE_TYPE (t));
kono
parents:
diff changeset
1641 break;
kono
parents:
diff changeset
1642
kono
parents:
diff changeset
1643 case FUNCTION_DECL:
kono
parents:
diff changeset
1644 pp_cxx_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t)));
kono
parents:
diff changeset
1645 expression (t);
kono
parents:
diff changeset
1646 pp_cxx_parameter_declaration_clause (this, t);
kono
parents:
diff changeset
1647
kono
parents:
diff changeset
1648 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
kono
parents:
diff changeset
1649 {
kono
parents:
diff changeset
1650 padding = pp_before;
kono
parents:
diff changeset
1651 pp_cxx_cv_qualifier_seq (this, pp_cxx_implicit_parameter_type (t));
kono
parents:
diff changeset
1652 }
kono
parents:
diff changeset
1653
kono
parents:
diff changeset
1654 pp_cxx_exception_specification (this, TREE_TYPE (t));
kono
parents:
diff changeset
1655 break;
kono
parents:
diff changeset
1656
kono
parents:
diff changeset
1657 case TYPENAME_TYPE:
kono
parents:
diff changeset
1658 case TEMPLATE_DECL:
kono
parents:
diff changeset
1659 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1660 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
1661 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1662 break;
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 default:
kono
parents:
diff changeset
1665 c_pretty_printer::direct_declarator (t);
kono
parents:
diff changeset
1666 break;
kono
parents:
diff changeset
1667 }
kono
parents:
diff changeset
1668 }
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 /* declarator:
kono
parents:
diff changeset
1671 direct-declarator
kono
parents:
diff changeset
1672 ptr-operator declarator */
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 void
kono
parents:
diff changeset
1675 cxx_pretty_printer::declarator (tree t)
kono
parents:
diff changeset
1676 {
kono
parents:
diff changeset
1677 direct_declarator (t);
kono
parents:
diff changeset
1678
kono
parents:
diff changeset
1679 // Print a requires clause.
kono
parents:
diff changeset
1680 if (flag_concepts)
kono
parents:
diff changeset
1681 if (tree ci = get_constraints (t))
kono
parents:
diff changeset
1682 if (tree reqs = CI_DECLARATOR_REQS (ci))
kono
parents:
diff changeset
1683 pp_cxx_requires_clause (this, reqs);
kono
parents:
diff changeset
1684 }
kono
parents:
diff changeset
1685
kono
parents:
diff changeset
1686 /* ctor-initializer:
kono
parents:
diff changeset
1687 : mem-initializer-list
kono
parents:
diff changeset
1688
kono
parents:
diff changeset
1689 mem-initializer-list:
kono
parents:
diff changeset
1690 mem-initializer
kono
parents:
diff changeset
1691 mem-initializer , mem-initializer-list
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693 mem-initializer:
kono
parents:
diff changeset
1694 mem-initializer-id ( expression-list(opt) )
kono
parents:
diff changeset
1695
kono
parents:
diff changeset
1696 mem-initializer-id:
kono
parents:
diff changeset
1697 ::(opt) nested-name-specifier(opt) class-name
kono
parents:
diff changeset
1698 identifier */
kono
parents:
diff changeset
1699
kono
parents:
diff changeset
1700 static void
kono
parents:
diff changeset
1701 pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1702 {
kono
parents:
diff changeset
1703 t = TREE_OPERAND (t, 0);
kono
parents:
diff changeset
1704 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1705 pp_colon (pp);
kono
parents:
diff changeset
1706 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
1707 for (; t; t = TREE_CHAIN (t))
kono
parents:
diff changeset
1708 {
kono
parents:
diff changeset
1709 tree purpose = TREE_PURPOSE (t);
kono
parents:
diff changeset
1710 bool is_pack = PACK_EXPANSION_P (purpose);
kono
parents:
diff changeset
1711
kono
parents:
diff changeset
1712 if (is_pack)
kono
parents:
diff changeset
1713 pp->primary_expression (PACK_EXPANSION_PATTERN (purpose));
kono
parents:
diff changeset
1714 else
kono
parents:
diff changeset
1715 pp->primary_expression (purpose);
kono
parents:
diff changeset
1716 pp_cxx_call_argument_list (pp, TREE_VALUE (t));
kono
parents:
diff changeset
1717 if (is_pack)
kono
parents:
diff changeset
1718 pp_cxx_ws_string (pp, "...");
kono
parents:
diff changeset
1719 if (TREE_CHAIN (t))
kono
parents:
diff changeset
1720 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
1721 }
kono
parents:
diff changeset
1722 }
kono
parents:
diff changeset
1723
kono
parents:
diff changeset
1724 /* function-definition:
kono
parents:
diff changeset
1725 decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
kono
parents:
diff changeset
1726 decl-specifier-seq(opt) declarator function-try-block */
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 static void
kono
parents:
diff changeset
1729 pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1730 {
kono
parents:
diff changeset
1731 tree saved_scope = pp->enclosing_scope;
kono
parents:
diff changeset
1732 pp->declaration_specifiers (t);
kono
parents:
diff changeset
1733 pp->declarator (t);
kono
parents:
diff changeset
1734 pp_needs_newline (pp) = true;
kono
parents:
diff changeset
1735 pp->enclosing_scope = DECL_CONTEXT (t);
kono
parents:
diff changeset
1736 if (DECL_SAVED_TREE (t))
kono
parents:
diff changeset
1737 pp->statement (DECL_SAVED_TREE (t));
kono
parents:
diff changeset
1738 else
kono
parents:
diff changeset
1739 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
1740 pp_newline_and_flush (pp);
kono
parents:
diff changeset
1741 pp->enclosing_scope = saved_scope;
kono
parents:
diff changeset
1742 }
kono
parents:
diff changeset
1743
kono
parents:
diff changeset
1744 /* abstract-declarator:
kono
parents:
diff changeset
1745 ptr-operator abstract-declarator(opt)
kono
parents:
diff changeset
1746 direct-abstract-declarator */
kono
parents:
diff changeset
1747
kono
parents:
diff changeset
1748 void
kono
parents:
diff changeset
1749 cxx_pretty_printer::abstract_declarator (tree t)
kono
parents:
diff changeset
1750 {
kono
parents:
diff changeset
1751 if (TYPE_PTRMEM_P (t))
kono
parents:
diff changeset
1752 pp_cxx_right_paren (this);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1753 else if (INDIRECT_TYPE_P (t))
111
kono
parents:
diff changeset
1754 {
kono
parents:
diff changeset
1755 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
kono
parents:
diff changeset
1756 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
kono
parents:
diff changeset
1757 pp_cxx_right_paren (this);
kono
parents:
diff changeset
1758 t = TREE_TYPE (t);
kono
parents:
diff changeset
1759 }
kono
parents:
diff changeset
1760 direct_abstract_declarator (t);
kono
parents:
diff changeset
1761 }
kono
parents:
diff changeset
1762
kono
parents:
diff changeset
1763 /* direct-abstract-declarator:
kono
parents:
diff changeset
1764 direct-abstract-declarator(opt) ( parameter-declaration-clause )
kono
parents:
diff changeset
1765 cv-qualifier-seq(opt) exception-specification(opt)
kono
parents:
diff changeset
1766 direct-abstract-declarator(opt) [ constant-expression(opt) ]
kono
parents:
diff changeset
1767 ( abstract-declarator ) */
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 void
kono
parents:
diff changeset
1770 cxx_pretty_printer::direct_abstract_declarator (tree t)
kono
parents:
diff changeset
1771 {
kono
parents:
diff changeset
1772 switch (TREE_CODE (t))
kono
parents:
diff changeset
1773 {
kono
parents:
diff changeset
1774 case REFERENCE_TYPE:
kono
parents:
diff changeset
1775 abstract_declarator (t);
kono
parents:
diff changeset
1776 break;
kono
parents:
diff changeset
1777
kono
parents:
diff changeset
1778 case RECORD_TYPE:
kono
parents:
diff changeset
1779 if (TYPE_PTRMEMFUNC_P (t))
kono
parents:
diff changeset
1780 direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t));
kono
parents:
diff changeset
1781 break;
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 case METHOD_TYPE:
kono
parents:
diff changeset
1784 case FUNCTION_TYPE:
kono
parents:
diff changeset
1785 pp_cxx_parameter_declaration_clause (this, t);
kono
parents:
diff changeset
1786 direct_abstract_declarator (TREE_TYPE (t));
kono
parents:
diff changeset
1787 if (TREE_CODE (t) == METHOD_TYPE)
kono
parents:
diff changeset
1788 {
kono
parents:
diff changeset
1789 padding = pp_before;
kono
parents:
diff changeset
1790 pp_cxx_cv_qualifier_seq (this, class_of_this_parm (t));
kono
parents:
diff changeset
1791 }
kono
parents:
diff changeset
1792 pp_cxx_exception_specification (this, t);
kono
parents:
diff changeset
1793 break;
kono
parents:
diff changeset
1794
kono
parents:
diff changeset
1795 case TYPENAME_TYPE:
kono
parents:
diff changeset
1796 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1797 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1798 case BOUND_TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1799 case UNBOUND_CLASS_TEMPLATE:
kono
parents:
diff changeset
1800 break;
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 default:
kono
parents:
diff changeset
1803 c_pretty_printer::direct_abstract_declarator (t);
kono
parents:
diff changeset
1804 break;
kono
parents:
diff changeset
1805 }
kono
parents:
diff changeset
1806 }
kono
parents:
diff changeset
1807
kono
parents:
diff changeset
1808 /* type-id:
kono
parents:
diff changeset
1809 type-specifier-seq abstract-declarator(opt) */
kono
parents:
diff changeset
1810
kono
parents:
diff changeset
1811 void
kono
parents:
diff changeset
1812 cxx_pretty_printer::type_id (tree t)
kono
parents:
diff changeset
1813 {
kono
parents:
diff changeset
1814 pp_flags saved_flags = flags;
kono
parents:
diff changeset
1815 flags |= pp_c_flag_abstract;
kono
parents:
diff changeset
1816
kono
parents:
diff changeset
1817 switch (TREE_CODE (t))
kono
parents:
diff changeset
1818 {
kono
parents:
diff changeset
1819 case TYPE_DECL:
kono
parents:
diff changeset
1820 case UNION_TYPE:
kono
parents:
diff changeset
1821 case RECORD_TYPE:
kono
parents:
diff changeset
1822 case ENUMERAL_TYPE:
kono
parents:
diff changeset
1823 case TYPENAME_TYPE:
kono
parents:
diff changeset
1824 case BOUND_TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1825 case UNBOUND_CLASS_TEMPLATE:
kono
parents:
diff changeset
1826 case TEMPLATE_TEMPLATE_PARM:
kono
parents:
diff changeset
1827 case TEMPLATE_TYPE_PARM:
kono
parents:
diff changeset
1828 case TEMPLATE_PARM_INDEX:
kono
parents:
diff changeset
1829 case TEMPLATE_DECL:
kono
parents:
diff changeset
1830 case TYPEOF_TYPE:
kono
parents:
diff changeset
1831 case UNDERLYING_TYPE:
kono
parents:
diff changeset
1832 case DECLTYPE_TYPE:
kono
parents:
diff changeset
1833 case TEMPLATE_ID_EXPR:
kono
parents:
diff changeset
1834 pp_cxx_type_specifier_seq (this, t);
kono
parents:
diff changeset
1835 break;
kono
parents:
diff changeset
1836
kono
parents:
diff changeset
1837 case TYPE_PACK_EXPANSION:
kono
parents:
diff changeset
1838 type_id (PACK_EXPANSION_PATTERN (t));
kono
parents:
diff changeset
1839 pp_cxx_ws_string (this, "...");
kono
parents:
diff changeset
1840 break;
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 default:
kono
parents:
diff changeset
1843 c_pretty_printer::type_id (t);
kono
parents:
diff changeset
1844 break;
kono
parents:
diff changeset
1845 }
kono
parents:
diff changeset
1846
kono
parents:
diff changeset
1847 flags = saved_flags;
kono
parents:
diff changeset
1848 }
kono
parents:
diff changeset
1849
kono
parents:
diff changeset
1850 /* template-argument-list:
kono
parents:
diff changeset
1851 template-argument ...(opt)
kono
parents:
diff changeset
1852 template-argument-list, template-argument ...(opt)
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 template-argument:
kono
parents:
diff changeset
1855 assignment-expression
kono
parents:
diff changeset
1856 type-id
kono
parents:
diff changeset
1857 template-name */
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 static void
kono
parents:
diff changeset
1860 pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1861 {
kono
parents:
diff changeset
1862 int i;
kono
parents:
diff changeset
1863 bool need_comma = false;
kono
parents:
diff changeset
1864
kono
parents:
diff changeset
1865 if (t == NULL)
kono
parents:
diff changeset
1866 return;
kono
parents:
diff changeset
1867 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
kono
parents:
diff changeset
1868 {
kono
parents:
diff changeset
1869 tree arg = TREE_VEC_ELT (t, i);
kono
parents:
diff changeset
1870 tree argpack = NULL_TREE;
kono
parents:
diff changeset
1871 int idx, len = 1;
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 if (ARGUMENT_PACK_P (arg))
kono
parents:
diff changeset
1874 {
kono
parents:
diff changeset
1875 argpack = ARGUMENT_PACK_ARGS (arg);
kono
parents:
diff changeset
1876 len = TREE_VEC_LENGTH (argpack);
kono
parents:
diff changeset
1877 }
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 for (idx = 0; idx < len; idx++)
kono
parents:
diff changeset
1880 {
kono
parents:
diff changeset
1881 if (argpack)
kono
parents:
diff changeset
1882 arg = TREE_VEC_ELT (argpack, idx);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1883
111
kono
parents:
diff changeset
1884 if (need_comma)
kono
parents:
diff changeset
1885 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
1886 else
kono
parents:
diff changeset
1887 need_comma = true;
kono
parents:
diff changeset
1888
kono
parents:
diff changeset
1889 if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
kono
parents:
diff changeset
1890 && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
kono
parents:
diff changeset
1891 pp->type_id (arg);
kono
parents:
diff changeset
1892 else
kono
parents:
diff changeset
1893 pp->expression (arg);
kono
parents:
diff changeset
1894 }
kono
parents:
diff changeset
1895 }
kono
parents:
diff changeset
1896 }
kono
parents:
diff changeset
1897
kono
parents:
diff changeset
1898
kono
parents:
diff changeset
1899 static void
kono
parents:
diff changeset
1900 pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
1901 {
kono
parents:
diff changeset
1902 t = DECL_EXPR_DECL (t);
kono
parents:
diff changeset
1903 pp_cxx_type_specifier_seq (pp, t);
kono
parents:
diff changeset
1904 if (TYPE_P (t))
kono
parents:
diff changeset
1905 pp->abstract_declarator (t);
kono
parents:
diff changeset
1906 else
kono
parents:
diff changeset
1907 pp->declarator (t);
kono
parents:
diff changeset
1908 }
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 /* Statements. */
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 void
kono
parents:
diff changeset
1913 cxx_pretty_printer::statement (tree t)
kono
parents:
diff changeset
1914 {
kono
parents:
diff changeset
1915 switch (TREE_CODE (t))
kono
parents:
diff changeset
1916 {
kono
parents:
diff changeset
1917 case CTOR_INITIALIZER:
kono
parents:
diff changeset
1918 pp_cxx_ctor_initializer (this, t);
kono
parents:
diff changeset
1919 break;
kono
parents:
diff changeset
1920
kono
parents:
diff changeset
1921 case USING_STMT:
kono
parents:
diff changeset
1922 pp_cxx_ws_string (this, "using");
kono
parents:
diff changeset
1923 pp_cxx_ws_string (this, "namespace");
kono
parents:
diff changeset
1924 if (DECL_CONTEXT (t))
kono
parents:
diff changeset
1925 pp_cxx_nested_name_specifier (this, DECL_CONTEXT (t));
kono
parents:
diff changeset
1926 pp_cxx_qualified_id (this, USING_STMT_NAMESPACE (t));
kono
parents:
diff changeset
1927 break;
kono
parents:
diff changeset
1928
kono
parents:
diff changeset
1929 case USING_DECL:
kono
parents:
diff changeset
1930 pp_cxx_ws_string (this, "using");
kono
parents:
diff changeset
1931 pp_cxx_nested_name_specifier (this, USING_DECL_SCOPE (t));
kono
parents:
diff changeset
1932 pp_cxx_unqualified_id (this, DECL_NAME (t));
kono
parents:
diff changeset
1933 break;
kono
parents:
diff changeset
1934
kono
parents:
diff changeset
1935 case EH_SPEC_BLOCK:
kono
parents:
diff changeset
1936 break;
kono
parents:
diff changeset
1937
kono
parents:
diff changeset
1938 /* try-block:
kono
parents:
diff changeset
1939 try compound-statement handler-seq */
kono
parents:
diff changeset
1940 case TRY_BLOCK:
kono
parents:
diff changeset
1941 pp_maybe_newline_and_indent (this, 0);
kono
parents:
diff changeset
1942 pp_cxx_ws_string (this, "try");
kono
parents:
diff changeset
1943 pp_newline_and_indent (this, 3);
kono
parents:
diff changeset
1944 statement (TRY_STMTS (t));
kono
parents:
diff changeset
1945 pp_newline_and_indent (this, -3);
kono
parents:
diff changeset
1946 if (CLEANUP_P (t))
kono
parents:
diff changeset
1947 ;
kono
parents:
diff changeset
1948 else
kono
parents:
diff changeset
1949 statement (TRY_HANDLERS (t));
kono
parents:
diff changeset
1950 break;
kono
parents:
diff changeset
1951
kono
parents:
diff changeset
1952 /*
kono
parents:
diff changeset
1953 handler-seq:
kono
parents:
diff changeset
1954 handler handler-seq(opt)
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 handler:
kono
parents:
diff changeset
1957 catch ( exception-declaration ) compound-statement
kono
parents:
diff changeset
1958
kono
parents:
diff changeset
1959 exception-declaration:
kono
parents:
diff changeset
1960 type-specifier-seq declarator
kono
parents:
diff changeset
1961 type-specifier-seq abstract-declarator
kono
parents:
diff changeset
1962 ... */
kono
parents:
diff changeset
1963 case HANDLER:
kono
parents:
diff changeset
1964 pp_cxx_ws_string (this, "catch");
kono
parents:
diff changeset
1965 pp_cxx_left_paren (this);
kono
parents:
diff changeset
1966 pp_cxx_exception_declaration (this, HANDLER_PARMS (t));
kono
parents:
diff changeset
1967 pp_cxx_right_paren (this);
kono
parents:
diff changeset
1968 pp_indentation (this) += 3;
kono
parents:
diff changeset
1969 pp_needs_newline (this) = true;
kono
parents:
diff changeset
1970 statement (HANDLER_BODY (t));
kono
parents:
diff changeset
1971 pp_indentation (this) -= 3;
kono
parents:
diff changeset
1972 pp_needs_newline (this) = true;
kono
parents:
diff changeset
1973 break;
kono
parents:
diff changeset
1974
kono
parents:
diff changeset
1975 /* selection-statement:
kono
parents:
diff changeset
1976 if ( expression ) statement
kono
parents:
diff changeset
1977 if ( expression ) statement else statement */
kono
parents:
diff changeset
1978 case IF_STMT:
kono
parents:
diff changeset
1979 pp_cxx_ws_string (this, "if");
kono
parents:
diff changeset
1980 pp_cxx_whitespace (this);
kono
parents:
diff changeset
1981 pp_cxx_left_paren (this);
kono
parents:
diff changeset
1982 expression (IF_COND (t));
kono
parents:
diff changeset
1983 pp_cxx_right_paren (this);
kono
parents:
diff changeset
1984 pp_newline_and_indent (this, 2);
kono
parents:
diff changeset
1985 statement (THEN_CLAUSE (t));
kono
parents:
diff changeset
1986 pp_newline_and_indent (this, -2);
kono
parents:
diff changeset
1987 if (ELSE_CLAUSE (t))
kono
parents:
diff changeset
1988 {
kono
parents:
diff changeset
1989 tree else_clause = ELSE_CLAUSE (t);
kono
parents:
diff changeset
1990 pp_cxx_ws_string (this, "else");
kono
parents:
diff changeset
1991 if (TREE_CODE (else_clause) == IF_STMT)
kono
parents:
diff changeset
1992 pp_cxx_whitespace (this);
kono
parents:
diff changeset
1993 else
kono
parents:
diff changeset
1994 pp_newline_and_indent (this, 2);
kono
parents:
diff changeset
1995 statement (else_clause);
kono
parents:
diff changeset
1996 if (TREE_CODE (else_clause) != IF_STMT)
kono
parents:
diff changeset
1997 pp_newline_and_indent (this, -2);
kono
parents:
diff changeset
1998 }
kono
parents:
diff changeset
1999 break;
kono
parents:
diff changeset
2000
kono
parents:
diff changeset
2001 case SWITCH_STMT:
kono
parents:
diff changeset
2002 pp_cxx_ws_string (this, "switch");
kono
parents:
diff changeset
2003 pp_space (this);
kono
parents:
diff changeset
2004 pp_cxx_left_paren (this);
kono
parents:
diff changeset
2005 expression (SWITCH_STMT_COND (t));
kono
parents:
diff changeset
2006 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2007 pp_indentation (this) += 3;
kono
parents:
diff changeset
2008 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2009 statement (SWITCH_STMT_BODY (t));
kono
parents:
diff changeset
2010 pp_newline_and_indent (this, -3);
kono
parents:
diff changeset
2011 break;
kono
parents:
diff changeset
2012
kono
parents:
diff changeset
2013 /* iteration-statement:
kono
parents:
diff changeset
2014 while ( expression ) statement
kono
parents:
diff changeset
2015 do statement while ( expression ) ;
kono
parents:
diff changeset
2016 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
kono
parents:
diff changeset
2017 for ( declaration expression(opt) ; expression(opt) ) statement */
kono
parents:
diff changeset
2018 case WHILE_STMT:
kono
parents:
diff changeset
2019 pp_cxx_ws_string (this, "while");
kono
parents:
diff changeset
2020 pp_space (this);
kono
parents:
diff changeset
2021 pp_cxx_left_paren (this);
kono
parents:
diff changeset
2022 expression (WHILE_COND (t));
kono
parents:
diff changeset
2023 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2024 pp_newline_and_indent (this, 3);
kono
parents:
diff changeset
2025 statement (WHILE_BODY (t));
kono
parents:
diff changeset
2026 pp_indentation (this) -= 3;
kono
parents:
diff changeset
2027 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2028 break;
kono
parents:
diff changeset
2029
kono
parents:
diff changeset
2030 case DO_STMT:
kono
parents:
diff changeset
2031 pp_cxx_ws_string (this, "do");
kono
parents:
diff changeset
2032 pp_newline_and_indent (this, 3);
kono
parents:
diff changeset
2033 statement (DO_BODY (t));
kono
parents:
diff changeset
2034 pp_newline_and_indent (this, -3);
kono
parents:
diff changeset
2035 pp_cxx_ws_string (this, "while");
kono
parents:
diff changeset
2036 pp_space (this);
kono
parents:
diff changeset
2037 pp_cxx_left_paren (this);
kono
parents:
diff changeset
2038 expression (DO_COND (t));
kono
parents:
diff changeset
2039 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2040 pp_cxx_semicolon (this);
kono
parents:
diff changeset
2041 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2042 break;
kono
parents:
diff changeset
2043
kono
parents:
diff changeset
2044 case FOR_STMT:
kono
parents:
diff changeset
2045 pp_cxx_ws_string (this, "for");
kono
parents:
diff changeset
2046 pp_space (this);
kono
parents:
diff changeset
2047 pp_cxx_left_paren (this);
kono
parents:
diff changeset
2048 if (FOR_INIT_STMT (t))
kono
parents:
diff changeset
2049 statement (FOR_INIT_STMT (t));
kono
parents:
diff changeset
2050 else
kono
parents:
diff changeset
2051 pp_cxx_semicolon (this);
kono
parents:
diff changeset
2052 pp_needs_newline (this) = false;
kono
parents:
diff changeset
2053 pp_cxx_whitespace (this);
kono
parents:
diff changeset
2054 if (FOR_COND (t))
kono
parents:
diff changeset
2055 expression (FOR_COND (t));
kono
parents:
diff changeset
2056 pp_cxx_semicolon (this);
kono
parents:
diff changeset
2057 pp_needs_newline (this) = false;
kono
parents:
diff changeset
2058 pp_cxx_whitespace (this);
kono
parents:
diff changeset
2059 if (FOR_EXPR (t))
kono
parents:
diff changeset
2060 expression (FOR_EXPR (t));
kono
parents:
diff changeset
2061 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2062 pp_newline_and_indent (this, 3);
kono
parents:
diff changeset
2063 statement (FOR_BODY (t));
kono
parents:
diff changeset
2064 pp_indentation (this) -= 3;
kono
parents:
diff changeset
2065 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2066 break;
kono
parents:
diff changeset
2067
kono
parents:
diff changeset
2068 case RANGE_FOR_STMT:
kono
parents:
diff changeset
2069 pp_cxx_ws_string (this, "for");
kono
parents:
diff changeset
2070 pp_space (this);
kono
parents:
diff changeset
2071 pp_cxx_left_paren (this);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2072 if (RANGE_FOR_INIT_STMT (t))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2073 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2074 statement (RANGE_FOR_INIT_STMT (t));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2075 pp_needs_newline (this) = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2076 pp_cxx_whitespace (this);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2077 }
111
kono
parents:
diff changeset
2078 statement (RANGE_FOR_DECL (t));
kono
parents:
diff changeset
2079 pp_space (this);
kono
parents:
diff changeset
2080 pp_needs_newline (this) = false;
kono
parents:
diff changeset
2081 pp_colon (this);
kono
parents:
diff changeset
2082 pp_space (this);
kono
parents:
diff changeset
2083 statement (RANGE_FOR_EXPR (t));
kono
parents:
diff changeset
2084 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2085 pp_newline_and_indent (this, 3);
kono
parents:
diff changeset
2086 statement (FOR_BODY (t));
kono
parents:
diff changeset
2087 pp_indentation (this) -= 3;
kono
parents:
diff changeset
2088 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2089 break;
kono
parents:
diff changeset
2090
kono
parents:
diff changeset
2091 /* jump-statement:
kono
parents:
diff changeset
2092 goto identifier;
kono
parents:
diff changeset
2093 continue ;
kono
parents:
diff changeset
2094 return expression(opt) ; */
kono
parents:
diff changeset
2095 case BREAK_STMT:
kono
parents:
diff changeset
2096 case CONTINUE_STMT:
kono
parents:
diff changeset
2097 pp_string (this, TREE_CODE (t) == BREAK_STMT ? "break" : "continue");
kono
parents:
diff changeset
2098 pp_cxx_semicolon (this);
kono
parents:
diff changeset
2099 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2100 break;
kono
parents:
diff changeset
2101
kono
parents:
diff changeset
2102 /* expression-statement:
kono
parents:
diff changeset
2103 expression(opt) ; */
kono
parents:
diff changeset
2104 case EXPR_STMT:
kono
parents:
diff changeset
2105 expression (EXPR_STMT_EXPR (t));
kono
parents:
diff changeset
2106 pp_cxx_semicolon (this);
kono
parents:
diff changeset
2107 pp_needs_newline (this) = true;
kono
parents:
diff changeset
2108 break;
kono
parents:
diff changeset
2109
kono
parents:
diff changeset
2110 case CLEANUP_STMT:
kono
parents:
diff changeset
2111 pp_cxx_ws_string (this, "try");
kono
parents:
diff changeset
2112 pp_newline_and_indent (this, 2);
kono
parents:
diff changeset
2113 statement (CLEANUP_BODY (t));
kono
parents:
diff changeset
2114 pp_newline_and_indent (this, -2);
kono
parents:
diff changeset
2115 pp_cxx_ws_string (this, CLEANUP_EH_ONLY (t) ? "catch" : "finally");
kono
parents:
diff changeset
2116 pp_newline_and_indent (this, 2);
kono
parents:
diff changeset
2117 statement (CLEANUP_EXPR (t));
kono
parents:
diff changeset
2118 pp_newline_and_indent (this, -2);
kono
parents:
diff changeset
2119 break;
kono
parents:
diff changeset
2120
kono
parents:
diff changeset
2121 case STATIC_ASSERT:
kono
parents:
diff changeset
2122 declaration (t);
kono
parents:
diff changeset
2123 break;
kono
parents:
diff changeset
2124
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2125 case OMP_DEPOBJ:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2126 pp_cxx_ws_string (this, "#pragma omp depobj");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2127 pp_space (this);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2128 pp_cxx_left_paren (this);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2129 expression (OMP_DEPOBJ_DEPOBJ (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2130 pp_cxx_right_paren (this);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2131 if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2132 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2133 if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2134 dump_omp_clauses (this, OMP_DEPOBJ_CLAUSES (t),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2135 pp_indentation (this), TDF_NONE);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2136 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2137 switch (tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2138 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2139 case OMP_CLAUSE_DEPEND_IN:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2140 pp_cxx_ws_string (this, " update(in)");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2141 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2142 case OMP_CLAUSE_DEPEND_INOUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2143 pp_cxx_ws_string (this, " update(inout)");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2144 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2145 case OMP_CLAUSE_DEPEND_OUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2146 pp_cxx_ws_string (this, " update(out)");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2147 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2148 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2149 pp_cxx_ws_string (this, " update(mutexinoutset)");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2150 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2151 case OMP_CLAUSE_DEPEND_LAST:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2152 pp_cxx_ws_string (this, " destroy");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2153 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2154 default:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2155 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2156 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2157 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2158 pp_needs_newline (this) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2159 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2160
111
kono
parents:
diff changeset
2161 default:
kono
parents:
diff changeset
2162 c_pretty_printer::statement (t);
kono
parents:
diff changeset
2163 break;
kono
parents:
diff changeset
2164 }
kono
parents:
diff changeset
2165 }
kono
parents:
diff changeset
2166
kono
parents:
diff changeset
2167 /* original-namespace-definition:
kono
parents:
diff changeset
2168 namespace identifier { namespace-body }
kono
parents:
diff changeset
2169
kono
parents:
diff changeset
2170 As an edge case, we also handle unnamed namespace definition here. */
kono
parents:
diff changeset
2171
kono
parents:
diff changeset
2172 static void
kono
parents:
diff changeset
2173 pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2174 {
kono
parents:
diff changeset
2175 pp_cxx_ws_string (pp, "namespace");
kono
parents:
diff changeset
2176 if (DECL_CONTEXT (t))
kono
parents:
diff changeset
2177 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
kono
parents:
diff changeset
2178 if (DECL_NAME (t))
kono
parents:
diff changeset
2179 pp_cxx_unqualified_id (pp, t);
kono
parents:
diff changeset
2180 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
2181 pp_cxx_left_brace (pp);
kono
parents:
diff changeset
2182 /* We do not print the namespace-body. */
kono
parents:
diff changeset
2183 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
2184 pp_cxx_right_brace (pp);
kono
parents:
diff changeset
2185 }
kono
parents:
diff changeset
2186
kono
parents:
diff changeset
2187 /* namespace-alias:
kono
parents:
diff changeset
2188 identifier
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 namespace-alias-definition:
kono
parents:
diff changeset
2191 namespace identifier = qualified-namespace-specifier ;
kono
parents:
diff changeset
2192
kono
parents:
diff changeset
2193 qualified-namespace-specifier:
kono
parents:
diff changeset
2194 ::(opt) nested-name-specifier(opt) namespace-name */
kono
parents:
diff changeset
2195
kono
parents:
diff changeset
2196 static void
kono
parents:
diff changeset
2197 pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2198 {
kono
parents:
diff changeset
2199 pp_cxx_ws_string (pp, "namespace");
kono
parents:
diff changeset
2200 if (DECL_CONTEXT (t))
kono
parents:
diff changeset
2201 pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
kono
parents:
diff changeset
2202 pp_cxx_unqualified_id (pp, t);
kono
parents:
diff changeset
2203 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
2204 pp_equal (pp);
kono
parents:
diff changeset
2205 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
2206 if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
kono
parents:
diff changeset
2207 pp_cxx_nested_name_specifier (pp,
kono
parents:
diff changeset
2208 DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
kono
parents:
diff changeset
2209 pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
kono
parents:
diff changeset
2210 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2211 }
kono
parents:
diff changeset
2212
kono
parents:
diff changeset
2213 /* simple-declaration:
kono
parents:
diff changeset
2214 decl-specifier-seq(opt) init-declarator-list(opt) */
kono
parents:
diff changeset
2215
kono
parents:
diff changeset
2216 static void
kono
parents:
diff changeset
2217 pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2218 {
kono
parents:
diff changeset
2219 pp->declaration_specifiers (t);
kono
parents:
diff changeset
2220 pp_cxx_init_declarator (pp, t);
kono
parents:
diff changeset
2221 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2222 pp_needs_newline (pp) = true;
kono
parents:
diff changeset
2223 }
kono
parents:
diff changeset
2224
kono
parents:
diff changeset
2225 /*
kono
parents:
diff changeset
2226 template-parameter-list:
kono
parents:
diff changeset
2227 template-parameter
kono
parents:
diff changeset
2228 template-parameter-list , template-parameter */
kono
parents:
diff changeset
2229
kono
parents:
diff changeset
2230 static inline void
kono
parents:
diff changeset
2231 pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2232 {
kono
parents:
diff changeset
2233 const int n = TREE_VEC_LENGTH (t);
kono
parents:
diff changeset
2234 int i;
kono
parents:
diff changeset
2235 for (i = 0; i < n; ++i)
kono
parents:
diff changeset
2236 {
kono
parents:
diff changeset
2237 if (i)
kono
parents:
diff changeset
2238 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
2239 pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
kono
parents:
diff changeset
2240 }
kono
parents:
diff changeset
2241 }
kono
parents:
diff changeset
2242
kono
parents:
diff changeset
2243 /* template-parameter:
kono
parents:
diff changeset
2244 type-parameter
kono
parents:
diff changeset
2245 parameter-declaration
kono
parents:
diff changeset
2246
kono
parents:
diff changeset
2247 type-parameter:
kono
parents:
diff changeset
2248 class ...(opt) identifier(opt)
kono
parents:
diff changeset
2249 class identifier(opt) = type-id
kono
parents:
diff changeset
2250 typename identifier(opt)
kono
parents:
diff changeset
2251 typename ...(opt) identifier(opt) = type-id
kono
parents:
diff changeset
2252 template < template-parameter-list > class ...(opt) identifier(opt)
kono
parents:
diff changeset
2253 template < template-parameter-list > class identifier(opt) = template-name */
kono
parents:
diff changeset
2254
kono
parents:
diff changeset
2255 static void
kono
parents:
diff changeset
2256 pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2257 {
kono
parents:
diff changeset
2258 tree parameter = TREE_VALUE (t);
kono
parents:
diff changeset
2259 switch (TREE_CODE (parameter))
kono
parents:
diff changeset
2260 {
kono
parents:
diff changeset
2261 case TYPE_DECL:
kono
parents:
diff changeset
2262 pp_cxx_ws_string (pp, "class");
kono
parents:
diff changeset
2263 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t)))
kono
parents:
diff changeset
2264 pp_cxx_ws_string (pp, "...");
kono
parents:
diff changeset
2265 if (DECL_NAME (parameter))
kono
parents:
diff changeset
2266 pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
kono
parents:
diff changeset
2267 /* FIXME: Check if we should print also default argument. */
kono
parents:
diff changeset
2268 break;
kono
parents:
diff changeset
2269
kono
parents:
diff changeset
2270 case PARM_DECL:
kono
parents:
diff changeset
2271 pp_cxx_parameter_declaration (pp, parameter);
kono
parents:
diff changeset
2272 break;
kono
parents:
diff changeset
2273
kono
parents:
diff changeset
2274 case TEMPLATE_DECL:
kono
parents:
diff changeset
2275 break;
kono
parents:
diff changeset
2276
kono
parents:
diff changeset
2277 default:
kono
parents:
diff changeset
2278 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
2279 break;
kono
parents:
diff changeset
2280 }
kono
parents:
diff changeset
2281 }
kono
parents:
diff changeset
2282
kono
parents:
diff changeset
2283 /* Pretty-print a template parameter in the canonical form
kono
parents:
diff changeset
2284 "template-parameter-<level>-<position in parameter list>". */
kono
parents:
diff changeset
2285
kono
parents:
diff changeset
2286 void
kono
parents:
diff changeset
2287 pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm)
kono
parents:
diff changeset
2288 {
kono
parents:
diff changeset
2289 const enum tree_code code = TREE_CODE (parm);
kono
parents:
diff changeset
2290
kono
parents:
diff changeset
2291 /* Brings type template parameters to the canonical forms. */
kono
parents:
diff changeset
2292 if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM
kono
parents:
diff changeset
2293 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
kono
parents:
diff changeset
2294 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
kono
parents:
diff changeset
2295
kono
parents:
diff changeset
2296 pp_cxx_begin_template_argument_list (pp);
kono
parents:
diff changeset
2297 pp->translate_string ("template-parameter-");
kono
parents:
diff changeset
2298 pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm));
kono
parents:
diff changeset
2299 pp_minus (pp);
kono
parents:
diff changeset
2300 pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1);
kono
parents:
diff changeset
2301 pp_cxx_end_template_argument_list (pp);
kono
parents:
diff changeset
2302 }
kono
parents:
diff changeset
2303
kono
parents:
diff changeset
2304 /* Print a constrained-type-specifier. */
kono
parents:
diff changeset
2305
kono
parents:
diff changeset
2306 void
kono
parents:
diff changeset
2307 pp_cxx_constrained_type_spec (cxx_pretty_printer *pp, tree c)
kono
parents:
diff changeset
2308 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2309 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2310 pp_cxx_left_bracket (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2311 pp->translate_string ("requires");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2312 pp_cxx_whitespace (pp);
111
kono
parents:
diff changeset
2313 if (c == error_mark_node)
kono
parents:
diff changeset
2314 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2315 pp_cxx_ws_string(pp, "<unsatisfied-type-constraint>");
111
kono
parents:
diff changeset
2316 return;
kono
parents:
diff changeset
2317 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2318 tree t, a;
111
kono
parents:
diff changeset
2319 placeholder_extract_concept_and_args (c, t, a);
kono
parents:
diff changeset
2320 pp->id_expression (t);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2321 pp_cxx_begin_template_argument_list (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2322 pp_cxx_ws_string (pp, "<placeholder>");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2323 pp_cxx_separate_with (pp, ',');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2324 tree args = make_tree_vec (TREE_VEC_LENGTH (a) - 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2325 for (int i = 0; i < TREE_VEC_LENGTH (a) - 1; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2326 TREE_VEC_ELT (args, i) = TREE_VEC_ELT (a, i + 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2327 pp_cxx_template_argument_list (pp, args);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2328 ggc_free (args);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2329 pp_cxx_end_template_argument_list (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2330 pp_cxx_right_bracket (pp);
111
kono
parents:
diff changeset
2331 }
kono
parents:
diff changeset
2332
kono
parents:
diff changeset
2333 /*
kono
parents:
diff changeset
2334 template-declaration:
kono
parents:
diff changeset
2335 export(opt) template < template-parameter-list > declaration
kono
parents:
diff changeset
2336
kono
parents:
diff changeset
2337 Concept extensions:
kono
parents:
diff changeset
2338
kono
parents:
diff changeset
2339 template-declaration:
kono
parents:
diff changeset
2340 export(opt) template < template-parameter-list >
kono
parents:
diff changeset
2341 requires-clause(opt) declaration */
kono
parents:
diff changeset
2342
kono
parents:
diff changeset
2343 static void
kono
parents:
diff changeset
2344 pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2345 {
kono
parents:
diff changeset
2346 tree tmpl = most_general_template (t);
kono
parents:
diff changeset
2347 tree level;
kono
parents:
diff changeset
2348
kono
parents:
diff changeset
2349 pp_maybe_newline_and_indent (pp, 0);
kono
parents:
diff changeset
2350 for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
kono
parents:
diff changeset
2351 {
kono
parents:
diff changeset
2352 pp_cxx_ws_string (pp, "template");
kono
parents:
diff changeset
2353 pp_cxx_begin_template_argument_list (pp);
kono
parents:
diff changeset
2354 pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
kono
parents:
diff changeset
2355 pp_cxx_end_template_argument_list (pp);
kono
parents:
diff changeset
2356 pp_newline_and_indent (pp, 3);
kono
parents:
diff changeset
2357 }
kono
parents:
diff changeset
2358
kono
parents:
diff changeset
2359 if (flag_concepts)
kono
parents:
diff changeset
2360 if (tree ci = get_constraints (t))
kono
parents:
diff changeset
2361 if (tree reqs = CI_TEMPLATE_REQS (ci))
kono
parents:
diff changeset
2362 {
kono
parents:
diff changeset
2363 pp_cxx_requires_clause (pp, reqs);
kono
parents:
diff changeset
2364 pp_newline_and_indent (pp, 6);
kono
parents:
diff changeset
2365 }
kono
parents:
diff changeset
2366
kono
parents:
diff changeset
2367 if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
kono
parents:
diff changeset
2368 pp_cxx_function_definition (pp, t);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2369 else if (TREE_CODE (t) == CONCEPT_DECL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2370 pp_cxx_concept_definition (pp, t);
111
kono
parents:
diff changeset
2371 else
kono
parents:
diff changeset
2372 pp_cxx_simple_declaration (pp, t);
kono
parents:
diff changeset
2373 }
kono
parents:
diff changeset
2374
kono
parents:
diff changeset
2375 static void
kono
parents:
diff changeset
2376 pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2377 {
kono
parents:
diff changeset
2378 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
2379 }
kono
parents:
diff changeset
2380
kono
parents:
diff changeset
2381 static void
kono
parents:
diff changeset
2382 pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2383 {
kono
parents:
diff changeset
2384 pp_unsupported_tree (pp, t);
kono
parents:
diff changeset
2385 }
kono
parents:
diff changeset
2386
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2387 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2388 pp_cxx_concept_definition (cxx_pretty_printer *pp, tree t)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2389 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2390 pp_cxx_unqualified_id (pp, DECL_NAME (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2391 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2392 pp_cxx_ws_string (pp, "=");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2393 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2394 pp->expression (DECL_INITIAL (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2395 pp_cxx_semicolon (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2396 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2397
111
kono
parents:
diff changeset
2398 /*
kono
parents:
diff changeset
2399 declaration:
kono
parents:
diff changeset
2400 block-declaration
kono
parents:
diff changeset
2401 function-definition
kono
parents:
diff changeset
2402 template-declaration
kono
parents:
diff changeset
2403 explicit-instantiation
kono
parents:
diff changeset
2404 explicit-specialization
kono
parents:
diff changeset
2405 linkage-specification
kono
parents:
diff changeset
2406 namespace-definition
kono
parents:
diff changeset
2407
kono
parents:
diff changeset
2408 block-declaration:
kono
parents:
diff changeset
2409 simple-declaration
kono
parents:
diff changeset
2410 asm-definition
kono
parents:
diff changeset
2411 namespace-alias-definition
kono
parents:
diff changeset
2412 using-declaration
kono
parents:
diff changeset
2413 using-directive
kono
parents:
diff changeset
2414 static_assert-declaration */
kono
parents:
diff changeset
2415 void
kono
parents:
diff changeset
2416 cxx_pretty_printer::declaration (tree t)
kono
parents:
diff changeset
2417 {
kono
parents:
diff changeset
2418 if (TREE_CODE (t) == STATIC_ASSERT)
kono
parents:
diff changeset
2419 {
kono
parents:
diff changeset
2420 pp_cxx_ws_string (this, "static_assert");
kono
parents:
diff changeset
2421 pp_cxx_left_paren (this);
kono
parents:
diff changeset
2422 expression (STATIC_ASSERT_CONDITION (t));
kono
parents:
diff changeset
2423 pp_cxx_separate_with (this, ',');
kono
parents:
diff changeset
2424 expression (STATIC_ASSERT_MESSAGE (t));
kono
parents:
diff changeset
2425 pp_cxx_right_paren (this);
kono
parents:
diff changeset
2426 }
kono
parents:
diff changeset
2427 else if (!DECL_LANG_SPECIFIC (t))
kono
parents:
diff changeset
2428 pp_cxx_simple_declaration (this, t);
kono
parents:
diff changeset
2429 else if (DECL_USE_TEMPLATE (t))
kono
parents:
diff changeset
2430 switch (DECL_USE_TEMPLATE (t))
kono
parents:
diff changeset
2431 {
kono
parents:
diff changeset
2432 case 1:
kono
parents:
diff changeset
2433 pp_cxx_template_declaration (this, t);
kono
parents:
diff changeset
2434 break;
kono
parents:
diff changeset
2435
kono
parents:
diff changeset
2436 case 2:
kono
parents:
diff changeset
2437 pp_cxx_explicit_specialization (this, t);
kono
parents:
diff changeset
2438 break;
kono
parents:
diff changeset
2439
kono
parents:
diff changeset
2440 case 3:
kono
parents:
diff changeset
2441 pp_cxx_explicit_instantiation (this, t);
kono
parents:
diff changeset
2442 break;
kono
parents:
diff changeset
2443
kono
parents:
diff changeset
2444 default:
kono
parents:
diff changeset
2445 break;
kono
parents:
diff changeset
2446 }
kono
parents:
diff changeset
2447 else switch (TREE_CODE (t))
kono
parents:
diff changeset
2448 {
kono
parents:
diff changeset
2449 case VAR_DECL:
kono
parents:
diff changeset
2450 case TYPE_DECL:
kono
parents:
diff changeset
2451 pp_cxx_simple_declaration (this, t);
kono
parents:
diff changeset
2452 break;
kono
parents:
diff changeset
2453
kono
parents:
diff changeset
2454 case FUNCTION_DECL:
kono
parents:
diff changeset
2455 if (DECL_SAVED_TREE (t))
kono
parents:
diff changeset
2456 pp_cxx_function_definition (this, t);
kono
parents:
diff changeset
2457 else
kono
parents:
diff changeset
2458 pp_cxx_simple_declaration (this, t);
kono
parents:
diff changeset
2459 break;
kono
parents:
diff changeset
2460
kono
parents:
diff changeset
2461 case NAMESPACE_DECL:
kono
parents:
diff changeset
2462 if (DECL_NAMESPACE_ALIAS (t))
kono
parents:
diff changeset
2463 pp_cxx_namespace_alias_definition (this, t);
kono
parents:
diff changeset
2464 else
kono
parents:
diff changeset
2465 pp_cxx_original_namespace_definition (this, t);
kono
parents:
diff changeset
2466 break;
kono
parents:
diff changeset
2467
kono
parents:
diff changeset
2468 default:
kono
parents:
diff changeset
2469 pp_unsupported_tree (this, t);
kono
parents:
diff changeset
2470 break;
kono
parents:
diff changeset
2471 }
kono
parents:
diff changeset
2472 }
kono
parents:
diff changeset
2473
kono
parents:
diff changeset
2474 static void
kono
parents:
diff changeset
2475 pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2476 {
kono
parents:
diff changeset
2477 t = TREE_OPERAND (t, 0);
kono
parents:
diff changeset
2478 pp_cxx_ws_string (pp, "typeid");
kono
parents:
diff changeset
2479 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2480 if (TYPE_P (t))
kono
parents:
diff changeset
2481 pp->type_id (t);
kono
parents:
diff changeset
2482 else
kono
parents:
diff changeset
2483 pp->expression (t);
kono
parents:
diff changeset
2484 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2485 }
kono
parents:
diff changeset
2486
kono
parents:
diff changeset
2487 void
kono
parents:
diff changeset
2488 pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2489 {
kono
parents:
diff changeset
2490 pp_cxx_ws_string (pp, "va_arg");
kono
parents:
diff changeset
2491 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2492 pp->assignment_expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2493 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
2494 pp->type_id (TREE_TYPE (t));
kono
parents:
diff changeset
2495 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2496 }
kono
parents:
diff changeset
2497
kono
parents:
diff changeset
2498 static bool
kono
parents:
diff changeset
2499 pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2500 {
kono
parents:
diff changeset
2501 switch (TREE_CODE (t))
kono
parents:
diff changeset
2502 {
kono
parents:
diff changeset
2503 case ARROW_EXPR:
kono
parents:
diff changeset
2504 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2505 && INDIRECT_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
111
kono
parents:
diff changeset
2506 {
kono
parents:
diff changeset
2507 pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
kono
parents:
diff changeset
2508 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
2509 return true;
kono
parents:
diff changeset
2510 }
kono
parents:
diff changeset
2511 return false;
kono
parents:
diff changeset
2512 case COMPONENT_REF:
kono
parents:
diff changeset
2513 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
2514 return false;
kono
parents:
diff changeset
2515 if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
kono
parents:
diff changeset
2516 pp_cxx_dot (pp);
kono
parents:
diff changeset
2517 pp->expression (TREE_OPERAND (t, 1));
kono
parents:
diff changeset
2518 return true;
kono
parents:
diff changeset
2519 case ARRAY_REF:
kono
parents:
diff changeset
2520 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
2521 return false;
kono
parents:
diff changeset
2522 pp_left_bracket (pp);
kono
parents:
diff changeset
2523 pp->expression (TREE_OPERAND (t, 1));
kono
parents:
diff changeset
2524 pp_right_bracket (pp);
kono
parents:
diff changeset
2525 return true;
kono
parents:
diff changeset
2526 default:
kono
parents:
diff changeset
2527 return false;
kono
parents:
diff changeset
2528 }
kono
parents:
diff changeset
2529 }
kono
parents:
diff changeset
2530
kono
parents:
diff changeset
2531 void
kono
parents:
diff changeset
2532 pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2533 {
kono
parents:
diff changeset
2534 pp_cxx_ws_string (pp, "offsetof");
kono
parents:
diff changeset
2535 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2536 if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
kono
parents:
diff changeset
2537 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2538 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2539 }
kono
parents:
diff changeset
2540
kono
parents:
diff changeset
2541 void
kono
parents:
diff changeset
2542 pp_cxx_addressof_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2543 {
kono
parents:
diff changeset
2544 pp_cxx_ws_string (pp, "__builtin_addressof");
kono
parents:
diff changeset
2545 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2546 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2547 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2548 }
kono
parents:
diff changeset
2549
kono
parents:
diff changeset
2550 static char const*
kono
parents:
diff changeset
2551 get_fold_operator (tree t)
kono
parents:
diff changeset
2552 {
kono
parents:
diff changeset
2553 int op = int_cst_value (FOLD_EXPR_OP (t));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2554 ovl_op_info_t *info = OVL_OP_INFO (FOLD_EXPR_MODIFY_P (t), op);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2555 return info->name;
111
kono
parents:
diff changeset
2556 }
kono
parents:
diff changeset
2557
kono
parents:
diff changeset
2558 void
kono
parents:
diff changeset
2559 pp_cxx_unary_left_fold_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2560 {
kono
parents:
diff changeset
2561 char const* op = get_fold_operator (t);
kono
parents:
diff changeset
2562 tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t));
kono
parents:
diff changeset
2563 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2564 pp_cxx_ws_string (pp, "...");
kono
parents:
diff changeset
2565 pp_cxx_ws_string (pp, op);
kono
parents:
diff changeset
2566 pp->expression (expr);
kono
parents:
diff changeset
2567 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2568 }
kono
parents:
diff changeset
2569
kono
parents:
diff changeset
2570 void
kono
parents:
diff changeset
2571 pp_cxx_unary_right_fold_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2572 {
kono
parents:
diff changeset
2573 char const* op = get_fold_operator (t);
kono
parents:
diff changeset
2574 tree expr = PACK_EXPANSION_PATTERN (FOLD_EXPR_PACK (t));
kono
parents:
diff changeset
2575 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2576 pp->expression (expr);
kono
parents:
diff changeset
2577 pp_space (pp);
kono
parents:
diff changeset
2578 pp_cxx_ws_string (pp, op);
kono
parents:
diff changeset
2579 pp_cxx_ws_string (pp, "...");
kono
parents:
diff changeset
2580 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2581 }
kono
parents:
diff changeset
2582
kono
parents:
diff changeset
2583 void
kono
parents:
diff changeset
2584 pp_cxx_binary_fold_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2585 {
kono
parents:
diff changeset
2586 char const* op = get_fold_operator (t);
kono
parents:
diff changeset
2587 tree t1 = TREE_OPERAND (t, 1);
kono
parents:
diff changeset
2588 tree t2 = TREE_OPERAND (t, 2);
kono
parents:
diff changeset
2589 if (t1 == FOLD_EXPR_PACK (t))
kono
parents:
diff changeset
2590 t1 = PACK_EXPANSION_PATTERN (t1);
kono
parents:
diff changeset
2591 else
kono
parents:
diff changeset
2592 t2 = PACK_EXPANSION_PATTERN (t2);
kono
parents:
diff changeset
2593 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2594 pp->expression (t1);
kono
parents:
diff changeset
2595 pp_cxx_ws_string (pp, op);
kono
parents:
diff changeset
2596 pp_cxx_ws_string (pp, "...");
kono
parents:
diff changeset
2597 pp_cxx_ws_string (pp, op);
kono
parents:
diff changeset
2598 pp->expression (t2);
kono
parents:
diff changeset
2599 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2600 }
kono
parents:
diff changeset
2601
kono
parents:
diff changeset
2602 void
kono
parents:
diff changeset
2603 pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2604 {
kono
parents:
diff changeset
2605 cp_trait_kind kind = TRAIT_EXPR_KIND (t);
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 switch (kind)
kono
parents:
diff changeset
2608 {
kono
parents:
diff changeset
2609 case CPTK_HAS_NOTHROW_ASSIGN:
kono
parents:
diff changeset
2610 pp_cxx_ws_string (pp, "__has_nothrow_assign");
kono
parents:
diff changeset
2611 break;
kono
parents:
diff changeset
2612 case CPTK_HAS_TRIVIAL_ASSIGN:
kono
parents:
diff changeset
2613 pp_cxx_ws_string (pp, "__has_trivial_assign");
kono
parents:
diff changeset
2614 break;
kono
parents:
diff changeset
2615 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
kono
parents:
diff changeset
2616 pp_cxx_ws_string (pp, "__has_nothrow_constructor");
kono
parents:
diff changeset
2617 break;
kono
parents:
diff changeset
2618 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
kono
parents:
diff changeset
2619 pp_cxx_ws_string (pp, "__has_trivial_constructor");
kono
parents:
diff changeset
2620 break;
kono
parents:
diff changeset
2621 case CPTK_HAS_NOTHROW_COPY:
kono
parents:
diff changeset
2622 pp_cxx_ws_string (pp, "__has_nothrow_copy");
kono
parents:
diff changeset
2623 break;
kono
parents:
diff changeset
2624 case CPTK_HAS_TRIVIAL_COPY:
kono
parents:
diff changeset
2625 pp_cxx_ws_string (pp, "__has_trivial_copy");
kono
parents:
diff changeset
2626 break;
kono
parents:
diff changeset
2627 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
kono
parents:
diff changeset
2628 pp_cxx_ws_string (pp, "__has_trivial_destructor");
kono
parents:
diff changeset
2629 break;
kono
parents:
diff changeset
2630 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
kono
parents:
diff changeset
2631 pp_cxx_ws_string (pp, "__has_unique_object_representations");
kono
parents:
diff changeset
2632 break;
kono
parents:
diff changeset
2633 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
kono
parents:
diff changeset
2634 pp_cxx_ws_string (pp, "__has_virtual_destructor");
kono
parents:
diff changeset
2635 break;
kono
parents:
diff changeset
2636 case CPTK_IS_ABSTRACT:
kono
parents:
diff changeset
2637 pp_cxx_ws_string (pp, "__is_abstract");
kono
parents:
diff changeset
2638 break;
kono
parents:
diff changeset
2639 case CPTK_IS_AGGREGATE:
kono
parents:
diff changeset
2640 pp_cxx_ws_string (pp, "__is_aggregate");
kono
parents:
diff changeset
2641 break;
kono
parents:
diff changeset
2642 case CPTK_IS_BASE_OF:
kono
parents:
diff changeset
2643 pp_cxx_ws_string (pp, "__is_base_of");
kono
parents:
diff changeset
2644 break;
kono
parents:
diff changeset
2645 case CPTK_IS_CLASS:
kono
parents:
diff changeset
2646 pp_cxx_ws_string (pp, "__is_class");
kono
parents:
diff changeset
2647 break;
kono
parents:
diff changeset
2648 case CPTK_IS_EMPTY:
kono
parents:
diff changeset
2649 pp_cxx_ws_string (pp, "__is_empty");
kono
parents:
diff changeset
2650 break;
kono
parents:
diff changeset
2651 case CPTK_IS_ENUM:
kono
parents:
diff changeset
2652 pp_cxx_ws_string (pp, "__is_enum");
kono
parents:
diff changeset
2653 break;
kono
parents:
diff changeset
2654 case CPTK_IS_FINAL:
kono
parents:
diff changeset
2655 pp_cxx_ws_string (pp, "__is_final");
kono
parents:
diff changeset
2656 break;
kono
parents:
diff changeset
2657 case CPTK_IS_POD:
kono
parents:
diff changeset
2658 pp_cxx_ws_string (pp, "__is_pod");
kono
parents:
diff changeset
2659 break;
kono
parents:
diff changeset
2660 case CPTK_IS_POLYMORPHIC:
kono
parents:
diff changeset
2661 pp_cxx_ws_string (pp, "__is_polymorphic");
kono
parents:
diff changeset
2662 break;
kono
parents:
diff changeset
2663 case CPTK_IS_SAME_AS:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2664 pp_cxx_ws_string (pp, "__is_same");
111
kono
parents:
diff changeset
2665 break;
kono
parents:
diff changeset
2666 case CPTK_IS_STD_LAYOUT:
kono
parents:
diff changeset
2667 pp_cxx_ws_string (pp, "__is_std_layout");
kono
parents:
diff changeset
2668 break;
kono
parents:
diff changeset
2669 case CPTK_IS_TRIVIAL:
kono
parents:
diff changeset
2670 pp_cxx_ws_string (pp, "__is_trivial");
kono
parents:
diff changeset
2671 break;
kono
parents:
diff changeset
2672 case CPTK_IS_TRIVIALLY_ASSIGNABLE:
kono
parents:
diff changeset
2673 pp_cxx_ws_string (pp, "__is_trivially_assignable");
kono
parents:
diff changeset
2674 break;
kono
parents:
diff changeset
2675 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
kono
parents:
diff changeset
2676 pp_cxx_ws_string (pp, "__is_trivially_constructible");
kono
parents:
diff changeset
2677 break;
kono
parents:
diff changeset
2678 case CPTK_IS_TRIVIALLY_COPYABLE:
kono
parents:
diff changeset
2679 pp_cxx_ws_string (pp, "__is_trivially_copyable");
kono
parents:
diff changeset
2680 break;
kono
parents:
diff changeset
2681 case CPTK_IS_UNION:
kono
parents:
diff changeset
2682 pp_cxx_ws_string (pp, "__is_union");
kono
parents:
diff changeset
2683 break;
kono
parents:
diff changeset
2684 case CPTK_IS_LITERAL_TYPE:
kono
parents:
diff changeset
2685 pp_cxx_ws_string (pp, "__is_literal_type");
kono
parents:
diff changeset
2686 break;
kono
parents:
diff changeset
2687 case CPTK_IS_ASSIGNABLE:
kono
parents:
diff changeset
2688 pp_cxx_ws_string (pp, "__is_assignable");
kono
parents:
diff changeset
2689 break;
kono
parents:
diff changeset
2690 case CPTK_IS_CONSTRUCTIBLE:
kono
parents:
diff changeset
2691 pp_cxx_ws_string (pp, "__is_constructible");
kono
parents:
diff changeset
2692 break;
kono
parents:
diff changeset
2693
kono
parents:
diff changeset
2694 default:
kono
parents:
diff changeset
2695 gcc_unreachable ();
kono
parents:
diff changeset
2696 }
kono
parents:
diff changeset
2697
kono
parents:
diff changeset
2698 pp_cxx_left_paren (pp);
kono
parents:
diff changeset
2699 pp->type_id (TRAIT_EXPR_TYPE1 (t));
kono
parents:
diff changeset
2700
kono
parents:
diff changeset
2701 if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_SAME_AS)
kono
parents:
diff changeset
2702 {
kono
parents:
diff changeset
2703 pp_cxx_separate_with (pp, ',');
kono
parents:
diff changeset
2704 pp->type_id (TRAIT_EXPR_TYPE2 (t));
kono
parents:
diff changeset
2705 }
kono
parents:
diff changeset
2706
kono
parents:
diff changeset
2707 pp_cxx_right_paren (pp);
kono
parents:
diff changeset
2708 }
kono
parents:
diff changeset
2709
kono
parents:
diff changeset
2710 // requires-clause:
kono
parents:
diff changeset
2711 // 'requires' logical-or-expression
kono
parents:
diff changeset
2712 void
kono
parents:
diff changeset
2713 pp_cxx_requires_clause (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2714 {
kono
parents:
diff changeset
2715 if (!t)
kono
parents:
diff changeset
2716 return;
kono
parents:
diff changeset
2717 pp->padding = pp_before;
kono
parents:
diff changeset
2718 pp_cxx_ws_string (pp, "requires");
kono
parents:
diff changeset
2719 pp_space (pp);
kono
parents:
diff changeset
2720 pp->expression (t);
kono
parents:
diff changeset
2721 }
kono
parents:
diff changeset
2722
kono
parents:
diff changeset
2723 /* requirement:
kono
parents:
diff changeset
2724 simple-requirement
kono
parents:
diff changeset
2725 compound-requirement
kono
parents:
diff changeset
2726 type-requirement
kono
parents:
diff changeset
2727 nested-requirement */
kono
parents:
diff changeset
2728 static void
kono
parents:
diff changeset
2729 pp_cxx_requirement (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2730 {
kono
parents:
diff changeset
2731 switch (TREE_CODE (t))
kono
parents:
diff changeset
2732 {
kono
parents:
diff changeset
2733 case SIMPLE_REQ:
kono
parents:
diff changeset
2734 pp_cxx_simple_requirement (pp, t);
kono
parents:
diff changeset
2735 break;
kono
parents:
diff changeset
2736
kono
parents:
diff changeset
2737 case TYPE_REQ:
kono
parents:
diff changeset
2738 pp_cxx_type_requirement (pp, t);
kono
parents:
diff changeset
2739 break;
kono
parents:
diff changeset
2740
kono
parents:
diff changeset
2741 case COMPOUND_REQ:
kono
parents:
diff changeset
2742 pp_cxx_compound_requirement (pp, t);
kono
parents:
diff changeset
2743 break;
kono
parents:
diff changeset
2744
kono
parents:
diff changeset
2745 case NESTED_REQ:
kono
parents:
diff changeset
2746 pp_cxx_nested_requirement (pp, t);
kono
parents:
diff changeset
2747 break;
kono
parents:
diff changeset
2748
kono
parents:
diff changeset
2749 default:
kono
parents:
diff changeset
2750 gcc_unreachable ();
kono
parents:
diff changeset
2751 }
kono
parents:
diff changeset
2752 }
kono
parents:
diff changeset
2753
kono
parents:
diff changeset
2754 // requirement-list:
kono
parents:
diff changeset
2755 // requirement
kono
parents:
diff changeset
2756 // requirement-list ';' requirement[opt]
kono
parents:
diff changeset
2757 //
kono
parents:
diff changeset
2758 static void
kono
parents:
diff changeset
2759 pp_cxx_requirement_list (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2760 {
kono
parents:
diff changeset
2761 for (; t; t = TREE_CHAIN (t))
kono
parents:
diff changeset
2762 pp_cxx_requirement (pp, TREE_VALUE (t));
kono
parents:
diff changeset
2763 }
kono
parents:
diff changeset
2764
kono
parents:
diff changeset
2765 // requirement-body:
kono
parents:
diff changeset
2766 // '{' requirement-list '}'
kono
parents:
diff changeset
2767 static void
kono
parents:
diff changeset
2768 pp_cxx_requirement_body (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2769 {
kono
parents:
diff changeset
2770 pp_cxx_left_brace (pp);
kono
parents:
diff changeset
2771 pp_cxx_requirement_list (pp, t);
kono
parents:
diff changeset
2772 pp_cxx_right_brace (pp);
kono
parents:
diff changeset
2773 }
kono
parents:
diff changeset
2774
kono
parents:
diff changeset
2775 // requires-expression:
kono
parents:
diff changeset
2776 // 'requires' requirement-parameter-list requirement-body
kono
parents:
diff changeset
2777 void
kono
parents:
diff changeset
2778 pp_cxx_requires_expr (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2779 {
kono
parents:
diff changeset
2780 pp_string (pp, "requires");
kono
parents:
diff changeset
2781 if (tree parms = TREE_OPERAND (t, 0))
kono
parents:
diff changeset
2782 {
kono
parents:
diff changeset
2783 pp_cxx_parameter_declaration_clause (pp, parms);
kono
parents:
diff changeset
2784 pp_cxx_whitespace (pp);
kono
parents:
diff changeset
2785 }
kono
parents:
diff changeset
2786 pp_cxx_requirement_body (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
2787 }
kono
parents:
diff changeset
2788
kono
parents:
diff changeset
2789 /* simple-requirement:
kono
parents:
diff changeset
2790 expression ';' */
kono
parents:
diff changeset
2791 void
kono
parents:
diff changeset
2792 pp_cxx_simple_requirement (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2793 {
kono
parents:
diff changeset
2794 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2795 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2796 }
kono
parents:
diff changeset
2797
kono
parents:
diff changeset
2798 /* type-requirement:
kono
parents:
diff changeset
2799 typename type-name ';' */
kono
parents:
diff changeset
2800 void
kono
parents:
diff changeset
2801 pp_cxx_type_requirement (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2802 {
kono
parents:
diff changeset
2803 pp->type_id (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2804 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2805 }
kono
parents:
diff changeset
2806
kono
parents:
diff changeset
2807 /* compound-requirement:
kono
parents:
diff changeset
2808 '{' expression '}' 'noexcept' [opt] trailing-return-type [opt] */
kono
parents:
diff changeset
2809 void
kono
parents:
diff changeset
2810 pp_cxx_compound_requirement (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2811 {
kono
parents:
diff changeset
2812 pp_cxx_left_brace (pp);
kono
parents:
diff changeset
2813 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2814 pp_cxx_right_brace (pp);
kono
parents:
diff changeset
2815
kono
parents:
diff changeset
2816 if (COMPOUND_REQ_NOEXCEPT_P (t))
kono
parents:
diff changeset
2817 pp_cxx_ws_string (pp, "noexcept");
kono
parents:
diff changeset
2818
kono
parents:
diff changeset
2819 if (tree type = TREE_OPERAND (t, 1))
kono
parents:
diff changeset
2820 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2821 pp_cxx_whitespace (pp);
111
kono
parents:
diff changeset
2822 pp_cxx_ws_string (pp, "->");
kono
parents:
diff changeset
2823 pp->type_id (type);
kono
parents:
diff changeset
2824 }
kono
parents:
diff changeset
2825 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2826 }
kono
parents:
diff changeset
2827
kono
parents:
diff changeset
2828 /* nested requirement:
kono
parents:
diff changeset
2829 'requires' constraint-expression */
kono
parents:
diff changeset
2830 void
kono
parents:
diff changeset
2831 pp_cxx_nested_requirement (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2832 {
kono
parents:
diff changeset
2833 pp_cxx_ws_string (pp, "requires");
kono
parents:
diff changeset
2834 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2835 pp_cxx_semicolon (pp);
kono
parents:
diff changeset
2836 }
kono
parents:
diff changeset
2837
kono
parents:
diff changeset
2838 void
kono
parents:
diff changeset
2839 pp_cxx_check_constraint (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2840 {
kono
parents:
diff changeset
2841 tree decl = CHECK_CONSTR_CONCEPT (t);
kono
parents:
diff changeset
2842 tree tmpl = DECL_TI_TEMPLATE (decl);
kono
parents:
diff changeset
2843 tree args = CHECK_CONSTR_ARGS (t);
kono
parents:
diff changeset
2844 tree id = build_nt (TEMPLATE_ID_EXPR, tmpl, args);
kono
parents:
diff changeset
2845
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2846 if (TREE_CODE (decl) == CONCEPT_DECL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2847 pp->expression (id);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2848 else if (VAR_P (decl))
111
kono
parents:
diff changeset
2849 pp->expression (id);
kono
parents:
diff changeset
2850 else if (TREE_CODE (decl) == FUNCTION_DECL)
kono
parents:
diff changeset
2851 {
kono
parents:
diff changeset
2852 tree call = build_vl_exp (CALL_EXPR, 2);
kono
parents:
diff changeset
2853 TREE_OPERAND (call, 0) = integer_two_node;
kono
parents:
diff changeset
2854 TREE_OPERAND (call, 1) = id;
kono
parents:
diff changeset
2855 pp->expression (call);
kono
parents:
diff changeset
2856 }
kono
parents:
diff changeset
2857 else
kono
parents:
diff changeset
2858 gcc_unreachable ();
kono
parents:
diff changeset
2859 }
kono
parents:
diff changeset
2860
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2861 /* Output the "[with ...]" clause for a parameter mapping of an atomic
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2862 constraint. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2863
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2864 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2865 pp_cxx_parameter_mapping (cxx_pretty_printer *pp, tree map)
111
kono
parents:
diff changeset
2866 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2867 for (tree p = map; p; p = TREE_CHAIN (p))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2868 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2869 tree parm = TREE_VALUE (p);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2870 tree arg = TREE_PURPOSE (p);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2871
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2872 if (TYPE_P (parm))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2873 pp->type_id (parm);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2874 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2875 pp_cxx_tree_identifier (pp, DECL_NAME (TEMPLATE_PARM_DECL (parm)));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2876
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2877 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2878 pp_equal (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2879 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2880
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2881 if (TYPE_P (arg) || DECL_TEMPLATE_TEMPLATE_PARM_P (arg))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2882 pp->type_id (arg);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2883 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2884 pp->expression (arg);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2885
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2886 if (TREE_CHAIN (p) != NULL_TREE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2887 pp_cxx_separate_with (pp, ';');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2888 }
111
kono
parents:
diff changeset
2889 }
kono
parents:
diff changeset
2890
kono
parents:
diff changeset
2891 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2892 pp_cxx_atomic_constraint (cxx_pretty_printer *pp, tree t)
111
kono
parents:
diff changeset
2893 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2894 /* Emit the expression. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2895 pp->expression (ATOMIC_CONSTR_EXPR (t));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2896
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2897 /* Emit the parameter mapping. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2898 tree map = ATOMIC_CONSTR_MAP (t);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2899 if (map && map != error_mark_node)
111
kono
parents:
diff changeset
2900 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2901 pp_cxx_whitespace (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2902 pp_cxx_left_bracket (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2903 pp->translate_string ("with");
111
kono
parents:
diff changeset
2904 pp_cxx_whitespace (pp);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2905 pp_cxx_parameter_mapping (pp, map);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2906 pp_cxx_right_bracket (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2907 }
111
kono
parents:
diff changeset
2908 }
kono
parents:
diff changeset
2909
kono
parents:
diff changeset
2910 void
kono
parents:
diff changeset
2911 pp_cxx_conjunction (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2912 {
kono
parents:
diff changeset
2913 pp_cxx_constraint (pp, TREE_OPERAND (t, 0));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2914 pp_string (pp, " /\\ ");
111
kono
parents:
diff changeset
2915 pp_cxx_constraint (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
2916 }
kono
parents:
diff changeset
2917
kono
parents:
diff changeset
2918 void
kono
parents:
diff changeset
2919 pp_cxx_disjunction (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2920 {
kono
parents:
diff changeset
2921 pp_cxx_constraint (pp, TREE_OPERAND (t, 0));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2922 pp_string (pp, " \\/ ");
111
kono
parents:
diff changeset
2923 pp_cxx_constraint (pp, TREE_OPERAND (t, 1));
kono
parents:
diff changeset
2924 }
kono
parents:
diff changeset
2925
kono
parents:
diff changeset
2926 void
kono
parents:
diff changeset
2927 pp_cxx_constraint (cxx_pretty_printer *pp, tree t)
kono
parents:
diff changeset
2928 {
kono
parents:
diff changeset
2929 if (t == error_mark_node)
kono
parents:
diff changeset
2930 return pp->expression (t);
kono
parents:
diff changeset
2931
kono
parents:
diff changeset
2932 switch (TREE_CODE (t))
kono
parents:
diff changeset
2933 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2934 case ATOMIC_CONSTR:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2935 pp_cxx_atomic_constraint (pp, t);
111
kono
parents:
diff changeset
2936 break;
kono
parents:
diff changeset
2937
kono
parents:
diff changeset
2938 case CHECK_CONSTR:
kono
parents:
diff changeset
2939 pp_cxx_check_constraint (pp, t);
kono
parents:
diff changeset
2940 break;
kono
parents:
diff changeset
2941
kono
parents:
diff changeset
2942 case CONJ_CONSTR:
kono
parents:
diff changeset
2943 pp_cxx_conjunction (pp, t);
kono
parents:
diff changeset
2944 break;
kono
parents:
diff changeset
2945
kono
parents:
diff changeset
2946 case DISJ_CONSTR:
kono
parents:
diff changeset
2947 pp_cxx_disjunction (pp, t);
kono
parents:
diff changeset
2948 break;
kono
parents:
diff changeset
2949
kono
parents:
diff changeset
2950 case EXPR_PACK_EXPANSION:
kono
parents:
diff changeset
2951 pp->expression (TREE_OPERAND (t, 0));
kono
parents:
diff changeset
2952 break;
kono
parents:
diff changeset
2953
kono
parents:
diff changeset
2954 default:
kono
parents:
diff changeset
2955 gcc_unreachable ();
kono
parents:
diff changeset
2956 }
kono
parents:
diff changeset
2957 }
kono
parents:
diff changeset
2958
kono
parents:
diff changeset
2959
kono
parents:
diff changeset
2960 typedef c_pretty_print_fn pp_fun;
kono
parents:
diff changeset
2961
kono
parents:
diff changeset
2962 /* Initialization of a C++ pretty-printer object. */
kono
parents:
diff changeset
2963
kono
parents:
diff changeset
2964 cxx_pretty_printer::cxx_pretty_printer ()
kono
parents:
diff changeset
2965 : c_pretty_printer (),
kono
parents:
diff changeset
2966 enclosing_scope (global_namespace)
kono
parents:
diff changeset
2967 {
kono
parents:
diff changeset
2968 type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
kono
parents:
diff changeset
2969 parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
kono
parents:
diff changeset
2970 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2971
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2972 /* cxx_pretty_printer's implementation of pretty_printer::clone vfunc. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2973
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2974 pretty_printer *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2975 cxx_pretty_printer::clone () const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2976 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2977 return new cxx_pretty_printer (*this);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2978 }