Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : :
19 : : #include "rust-ast-collector.h"
20 : : #include "rust-ast.h"
21 : : #include "rust-builtin-ast-nodes.h"
22 : : #include "rust-diagnostics.h"
23 : : #include "rust-expr.h"
24 : : #include "rust-item.h"
25 : : #include "rust-keyword-values.h"
26 : : #include "rust-location.h"
27 : : #include "rust-path.h"
28 : : #include "rust-system.h"
29 : : #include "rust-token.h"
30 : :
31 : : namespace Rust {
32 : : namespace AST {
33 : :
34 : : std::vector<TokenPtr>
35 : 0 : TokenCollector::collect_tokens () const
36 : : {
37 : 0 : std::vector<TokenPtr> result;
38 : 0 : for (auto item : tokens)
39 : : {
40 : 0 : if (item.get_kind () == CollectItem::Kind::Token)
41 : : {
42 : 0 : result.emplace_back (item.get_token ());
43 : : }
44 : 0 : }
45 : 0 : return result;
46 : : }
47 : :
48 : : std::vector<CollectItem>
49 : 2572 : TokenCollector::collect () const
50 : : {
51 : 2572 : return tokens;
52 : : }
53 : :
54 : : void
55 : 0 : TokenCollector::visit (AST::Crate &crate)
56 : : {
57 : 0 : visit_items_as_lines (crate.inner_attrs);
58 : 0 : visit_items_as_lines (crate.items);
59 : 0 : }
60 : :
61 : : void
62 : 2572 : TokenCollector::visit (AST::Item &item)
63 : : {
64 : 2572 : item.accept_vis (*this);
65 : 2572 : }
66 : :
67 : : void
68 : 388 : TokenCollector::trailing_comma ()
69 : : {
70 : 388 : if (output_trailing_commas)
71 : : {
72 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
73 : : }
74 : 388 : }
75 : :
76 : : void
77 : 16015 : TokenCollector::newline ()
78 : : {
79 : 16015 : tokens.push_back ({CollectItem::Kind::Newline});
80 : 16015 : }
81 : :
82 : : void
83 : 10626 : TokenCollector::indentation ()
84 : : {
85 : 10626 : tokens.push_back ({indent_level});
86 : 10626 : }
87 : :
88 : : void
89 : 2807 : TokenCollector::increment_indentation ()
90 : : {
91 : 2807 : indent_level++;
92 : 2807 : }
93 : :
94 : : void
95 : 2807 : TokenCollector::decrement_indentation ()
96 : : {
97 : 2807 : rust_assert (indent_level != 0);
98 : 2807 : indent_level--;
99 : 2807 : }
100 : :
101 : : void
102 : 907 : TokenCollector::comment (std::string comment)
103 : : {
104 : 1814 : tokens.push_back ({comment});
105 : 907 : }
106 : :
107 : : void
108 : 0 : TokenCollector::visit (Visitable &v)
109 : : {
110 : 0 : v.accept_vis (*this);
111 : 0 : }
112 : :
113 : : void
114 : 623 : TokenCollector::visit (FunctionParam ¶m)
115 : : {
116 : 623 : visit_items_as_lines (param.get_outer_attrs ());
117 : 623 : if (!param.is_variadic ())
118 : : {
119 : 623 : visit (param.get_pattern ());
120 : 623 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
121 : 623 : visit (param.get_type ());
122 : : }
123 : : else
124 : : {
125 : 0 : if (param.has_name ())
126 : : {
127 : 0 : visit (param.get_pattern ());
128 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
129 : : }
130 : 0 : push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
131 : : }
132 : 623 : }
133 : :
134 : : void
135 : 0 : TokenCollector::visit (VariadicParam ¶m)
136 : : {
137 : 0 : if (param.has_pattern ())
138 : : {
139 : 0 : visit (param.get_pattern ());
140 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
141 : : }
142 : 0 : push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
143 : 0 : }
144 : :
145 : : void
146 : 2058 : TokenCollector::visit (Attribute &attrib)
147 : : {
148 : 2058 : push (Rust::Token::make (HASH, attrib.get_locus ()));
149 : 2058 : if (attrib.is_inner_attribute ())
150 : 0 : push (Rust::Token::make (EXCLAM, UNDEF_LOCATION));
151 : 2058 : push (Rust::Token::make (LEFT_SQUARE, UNDEF_LOCATION));
152 : 2058 : visit (attrib.get_path ());
153 : :
154 : 2058 : if (attrib.has_attr_input ())
155 : : {
156 : 2004 : switch (attrib.get_attr_input ().get_attr_input_type ())
157 : : {
158 : 1908 : case AST::AttrInput::AttrInputType::LITERAL:
159 : 1908 : {
160 : 1908 : visit (static_cast<AttrInputLiteral &> (attrib.get_attr_input ()));
161 : 1908 : break;
162 : : }
163 : 0 : case AST::AttrInput::AttrInputType::MACRO:
164 : 0 : {
165 : 0 : visit (static_cast<AttrInputMacro &> (attrib.get_attr_input ()));
166 : 0 : break;
167 : : }
168 : 2 : case AST::AttrInput::AttrInputType::META_ITEM:
169 : 2 : {
170 : 2 : visit (static_cast<AttrInputMetaItemContainer &> (
171 : 2 : attrib.get_attr_input ()));
172 : 2 : break;
173 : : }
174 : 94 : case AST::AttrInput::AttrInputType::TOKEN_TREE:
175 : 94 : {
176 : 94 : visit (static_cast<DelimTokenTree &> (attrib.get_attr_input ()));
177 : 94 : break;
178 : : }
179 : 0 : default:
180 : 0 : rust_unreachable ();
181 : : }
182 : : }
183 : 2058 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
184 : 2058 : }
185 : :
186 : : void
187 : 2060 : TokenCollector::visit (SimplePath &path)
188 : : {
189 : 2060 : if (path.has_opening_scope_resolution ())
190 : : {
191 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
192 : : }
193 : 2060 : visit_items_joined_by_separator (path.get_segments (), SCOPE_RESOLUTION);
194 : 2060 : }
195 : :
196 : : void
197 : 2060 : TokenCollector::visit (SimplePathSegment &segment)
198 : : {
199 : 2060 : auto name = segment.get_segment_name ();
200 : 2060 : if (segment.is_crate_path_seg ())
201 : : {
202 : 0 : push (Rust::Token::make (CRATE, segment.get_locus ()));
203 : : }
204 : 2060 : else if (segment.is_super_path_seg ())
205 : : {
206 : 0 : push (Rust::Token::make (SUPER, segment.get_locus ()));
207 : : }
208 : 2060 : else if (segment.is_lower_self_seg ())
209 : : {
210 : 0 : push (Rust::Token::make (SELF, segment.get_locus ()));
211 : : }
212 : 2060 : else if (segment.is_big_self ())
213 : : {
214 : 0 : push (Rust::Token::make (SELF_ALIAS, segment.get_locus ()));
215 : : }
216 : : else
217 : : {
218 : 2060 : push (
219 : 4120 : Rust::Token::make_identifier (segment.get_locus (), std::move (name)));
220 : : }
221 : 2060 : }
222 : :
223 : : void
224 : 3492 : TokenCollector::visit (Visibility &vis)
225 : : {
226 : 3492 : switch (vis.get_vis_type ())
227 : : {
228 : 2572 : case Visibility::PUB:
229 : 2572 : push (Rust::Token::make (PUB, vis.get_locus ()));
230 : 2572 : break;
231 : 0 : case Visibility::PUB_CRATE:
232 : 0 : push (Rust::Token::make (PUB, vis.get_locus ()));
233 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
234 : 0 : push (Rust::Token::make (CRATE, UNDEF_LOCATION));
235 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
236 : 0 : break;
237 : 0 : case Visibility::PUB_SELF:
238 : 0 : push (Rust::Token::make (PUB, vis.get_locus ()));
239 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
240 : 0 : push (Rust::Token::make (SELF, UNDEF_LOCATION));
241 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
242 : 0 : break;
243 : 0 : case Visibility::PUB_SUPER:
244 : 0 : push (Rust::Token::make (PUB, vis.get_locus ()));
245 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
246 : 0 : push (Rust::Token::make (SUPER, UNDEF_LOCATION));
247 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
248 : 0 : break;
249 : 0 : case Visibility::PUB_IN_PATH:
250 : 0 : push (Rust::Token::make (PUB, vis.get_locus ()));
251 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
252 : 0 : push (Rust::Token::make (IN, UNDEF_LOCATION));
253 : 0 : visit (vis.get_path ());
254 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
255 : 0 : break;
256 : : case Visibility::PRIV:
257 : : break;
258 : : }
259 : 3492 : }
260 : :
261 : : void
262 : 1988 : TokenCollector::visit (std::vector<std::unique_ptr<GenericParam>> ¶ms)
263 : : {
264 : 1988 : push (Rust::Token::make (LEFT_ANGLE, UNDEF_LOCATION));
265 : 1988 : visit_items_joined_by_separator (params, COMMA);
266 : 1988 : push (Rust::Token::make (RIGHT_ANGLE, UNDEF_LOCATION));
267 : 1988 : }
268 : :
269 : : void
270 : 101 : TokenCollector::visit (TupleField &field)
271 : : {
272 : 101 : for (auto attr : field.get_outer_attrs ())
273 : : {
274 : 0 : visit (attr);
275 : 0 : }
276 : 101 : visit (field.get_visibility ());
277 : 101 : visit (field.get_field_type ());
278 : 101 : }
279 : :
280 : : void
281 : 14 : TokenCollector::visit (StructField &field)
282 : : {
283 : 14 : for (auto attr : field.get_outer_attrs ())
284 : : {
285 : 0 : visit (attr);
286 : 0 : }
287 : 14 : visit (field.get_visibility ());
288 : 28 : auto name = field.get_field_name ().as_string ();
289 : 14 : push (Rust::Token::make_identifier (field.get_locus (), std::move (name)));
290 : 14 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
291 : 14 : visit (field.get_field_type ());
292 : 14 : }
293 : :
294 : : void
295 : 0 : TokenCollector::visit (std::vector<LifetimeParam> &for_lifetimes)
296 : : {
297 : 0 : push (Rust::Token::make (FOR, UNDEF_LOCATION));
298 : 0 : push (Rust::Token::make (LEFT_ANGLE, UNDEF_LOCATION));
299 : 0 : visit_items_joined_by_separator (for_lifetimes, COMMA);
300 : 0 : push (Rust::Token::make (RIGHT_ANGLE, UNDEF_LOCATION));
301 : 0 : }
302 : :
303 : : void
304 : 1486 : TokenCollector::visit (FunctionQualifiers &qualifiers)
305 : : {
306 : : // Syntax:
307 : : // `const`? `async`? `unsafe`? (`extern` Abi?)?
308 : : // unsafe? (extern Abi?)?
309 : :
310 : 1486 : if (qualifiers.is_async ())
311 : 2 : push (Rust::Token::make (ASYNC, qualifiers.get_locus ()));
312 : 1486 : if (qualifiers.is_const ())
313 : 2 : push (Rust::Token::make (CONST, qualifiers.get_locus ()));
314 : 1486 : if (qualifiers.is_unsafe ())
315 : 86 : push (Rust::Token::make (UNSAFE, qualifiers.get_locus ()));
316 : 1486 : if (qualifiers.is_extern ())
317 : : {
318 : 58 : push (Rust::Token::make (EXTERN_KW, qualifiers.get_locus ()));
319 : 58 : if (qualifiers.has_abi ())
320 : : {
321 : 174 : push (Rust::Token::make_string (UNDEF_LOCATION,
322 : 116 : qualifiers.get_extern_abi ()));
323 : : }
324 : : }
325 : 1486 : }
326 : :
327 : : void
328 : 0 : TokenCollector::visit (MaybeNamedParam ¶m)
329 : : {
330 : : // Syntax:
331 : : // OuterAttribute* ( ( IDENTIFIER | _ ) : )? Type
332 : :
333 : 0 : for (auto attr : param.get_outer_attrs ())
334 : : {
335 : 0 : visit (attr);
336 : 0 : }
337 : 0 : auto param_name = param.get_name ().as_string ();
338 : 0 : switch (param.get_param_kind ())
339 : : {
340 : : case MaybeNamedParam::UNNAMED:
341 : : break;
342 : 0 : case MaybeNamedParam::IDENTIFIER:
343 : 0 : push (
344 : 0 : Rust::Token::make_identifier (UNDEF_LOCATION, std::move (param_name)));
345 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
346 : 0 : break;
347 : 0 : case MaybeNamedParam::WILDCARD:
348 : 0 : push (Rust::Token::make (UNDERSCORE, UNDEF_LOCATION));
349 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
350 : 0 : break;
351 : : }
352 : 0 : visit (param.get_type ());
353 : 0 : }
354 : :
355 : : void
356 : 842 : TokenCollector::visit (Token &tok)
357 : : {
358 : 2428 : std::string data = tok.get_tok_ptr ()->has_str () ? tok.get_str () : "";
359 : 842 : switch (tok.get_id ())
360 : : {
361 : 187 : case IDENTIFIER:
362 : 187 : push (Rust::Token::make_identifier (tok.get_locus (), std::move (data)));
363 : 187 : break;
364 : 1 : case INT_LITERAL:
365 : 1 : push (Rust::Token::make_int (tok.get_locus (), std::move (data),
366 : : tok.get_type_hint ()));
367 : 1 : break;
368 : 0 : case FLOAT_LITERAL:
369 : 0 : push (Rust::Token::make_float (tok.get_locus (), std::move (data),
370 : : tok.get_type_hint ()));
371 : 0 : break;
372 : 184 : case STRING_LITERAL:
373 : 184 : push (Rust::Token::make_string (tok.get_locus (), std::move (data)));
374 : 184 : break;
375 : 0 : case CHAR_LITERAL:
376 : 0 : push (Rust::Token::make_char (
377 : : tok.get_locus (),
378 : : // FIXME: This need to be fixed to properly support UTF-8
379 : 0 : static_cast<uint32_t> (data[0])));
380 : 0 : break;
381 : 0 : case BYTE_CHAR_LITERAL:
382 : 0 : push (Rust::Token::make_byte_char (tok.get_locus (), data[0]));
383 : 0 : break;
384 : 0 : case BYTE_STRING_LITERAL:
385 : 0 : push (Rust::Token::make_byte_string (tok.get_locus (), std::move (data)));
386 : 0 : break;
387 : 0 : case RAW_STRING_LITERAL:
388 : 0 : push (Rust::Token::make_raw_string (tok.get_locus (), std::move (data)));
389 : 0 : break;
390 : 0 : case INNER_DOC_COMMENT:
391 : 0 : push (Rust::Token::make_inner_doc_comment (tok.get_locus (),
392 : : std::move (data)));
393 : 0 : break;
394 : 0 : case OUTER_DOC_COMMENT:
395 : 0 : push (Rust::Token::make_outer_doc_comment (tok.get_locus (),
396 : : std::move (data)));
397 : 0 : break;
398 : 0 : case LIFETIME:
399 : 0 : push (Rust::Token::make_lifetime (tok.get_locus (), std::move (data)));
400 : 0 : break;
401 : 470 : default:
402 : 940 : push (Rust::Token::make (tok.get_id (), tok.get_locus ()));
403 : : }
404 : 842 : }
405 : :
406 : : void
407 : 96 : TokenCollector::visit (DelimTokenTree &delim_tok_tree)
408 : : {
409 : 937 : for (auto &token : delim_tok_tree.to_token_stream ())
410 : : {
411 : 841 : visit (token);
412 : 96 : }
413 : 96 : }
414 : :
415 : : void
416 : 2 : TokenCollector::visit (AttrInputMetaItemContainer &container)
417 : : {
418 : 4 : for (auto &item : container.get_items ())
419 : : {
420 : 2 : visit (item);
421 : : }
422 : 2 : }
423 : :
424 : : void
425 : 1905 : TokenCollector::visit (IdentifierExpr &ident_expr)
426 : : {
427 : 3810 : auto ident = ident_expr.get_ident ().as_string ();
428 : 1905 : push (
429 : 3810 : Rust::Token::make_identifier (ident_expr.get_locus (), std::move (ident)));
430 : 1905 : }
431 : :
432 : : void
433 : 937 : TokenCollector::visit (Lifetime &lifetime)
434 : : {
435 : : // Syntax:
436 : : // Lifetime :
437 : : // LIFETIME_OR_LABEL
438 : : // | 'static
439 : : // | '_
440 : :
441 : 937 : auto name = lifetime.get_lifetime_name ();
442 : 937 : switch (lifetime.get_lifetime_type ())
443 : : {
444 : 31 : case Lifetime::LifetimeType::NAMED:
445 : 31 : push (
446 : 31 : Rust::Token::make_lifetime (lifetime.get_locus (), std::move (name)));
447 : 31 : break;
448 : 1 : case Lifetime::LifetimeType::STATIC:
449 : 2 : push (Rust::Token::make_lifetime (lifetime.get_locus (),
450 : 1 : Values::Keywords::STATIC_KW));
451 : 1 : break;
452 : 905 : case Lifetime::LifetimeType::WILDCARD:
453 : 1810 : push (Rust::Token::make_lifetime (lifetime.get_locus (),
454 : 905 : Values::Keywords::UNDERSCORE));
455 : 905 : break;
456 : : }
457 : 937 : }
458 : :
459 : : void
460 : 20 : TokenCollector::visit (LifetimeParam &lifetime_param)
461 : : {
462 : : // Syntax:
463 : : // LIFETIME_OR_LABEL ( : LifetimeBounds )?
464 : : // LifetimeBounds :
465 : : // ( Lifetime + )* Lifetime?
466 : :
467 : : // TODO what to do with outer attr? They are not mentioned in the reference.
468 : :
469 : 20 : visit_items_as_lines (lifetime_param.get_outer_attrs ());
470 : 20 : auto lifetime = lifetime_param.get_lifetime ();
471 : 20 : visit (lifetime);
472 : :
473 : 20 : if (lifetime_param.has_lifetime_bounds ())
474 : : {
475 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
476 : 0 : for (auto &bound : lifetime_param.get_lifetime_bounds ())
477 : : {
478 : 0 : visit (bound);
479 : : }
480 : : }
481 : 20 : }
482 : :
483 : : void
484 : 0 : TokenCollector::visit (ConstGenericParam ¶m)
485 : : {
486 : : // Syntax:
487 : : // const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?
488 : :
489 : 0 : visit_items_as_lines (param.get_outer_attrs ());
490 : 0 : push (Rust::Token::make (CONST, param.get_locus ()));
491 : 0 : auto id = param.get_name ().as_string ();
492 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
493 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
494 : 0 : if (param.has_type ())
495 : 0 : visit (param.get_type ());
496 : 0 : if (param.has_default_value ())
497 : : {
498 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
499 : 0 : visit (param.get_default_value_unchecked ());
500 : : }
501 : 0 : }
502 : :
503 : : void
504 : 1559 : TokenCollector::visit (PathExprSegment &segment)
505 : : {
506 : 1559 : visit (segment.get_ident_segment ());
507 : 1559 : if (segment.has_generic_args ())
508 : : {
509 : 63 : auto generics = segment.get_generic_args ();
510 : 63 : push (Rust::Token::make (SCOPE_RESOLUTION, segment.get_locus ()));
511 : 63 : push (Rust::Token::make (LEFT_ANGLE, generics.get_locus ()));
512 : :
513 : 63 : auto &lifetime_args = generics.get_lifetime_args ();
514 : 63 : auto &generic_args = generics.get_generic_args ();
515 : 63 : auto &binding_args = generics.get_binding_args ();
516 : :
517 : 63 : visit_items_joined_by_separator (generic_args, COMMA);
518 : :
519 : 63 : if (!lifetime_args.empty ()
520 : 63 : && (!generic_args.empty () || !binding_args.empty ()))
521 : : {
522 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
523 : : }
524 : :
525 : 63 : visit_items_joined_by_separator (binding_args, COMMA);
526 : :
527 : 63 : if (!generic_args.empty () && !binding_args.empty ())
528 : : {
529 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
530 : : }
531 : :
532 : 63 : visit_items_joined_by_separator (lifetime_args, COMMA);
533 : :
534 : 63 : push (Rust::Token::make (RIGHT_ANGLE, UNDEF_LOCATION));
535 : 63 : }
536 : 1559 : }
537 : :
538 : : void
539 : 1143 : TokenCollector::visit (PathInExpression &path)
540 : : {
541 : 1143 : if (path.is_lang_item ())
542 : : {
543 : 64 : push (Rust::Token::make (TokenId::HASH, path.get_locus ()));
544 : 64 : push (Rust::Token::make (TokenId::LEFT_SQUARE, path.get_locus ()));
545 : 128 : push (Rust::Token::make_identifier (path.get_locus (), "lang"));
546 : 64 : push (Rust::Token::make (TokenId::EQUAL, path.get_locus ()));
547 : 64 : push (
548 : 128 : Rust::Token::make_string (path.get_locus (),
549 : 64 : LangItem::ToString (path.get_lang_item ())));
550 : 64 : push (Rust::Token::make (TokenId::RIGHT_SQUARE, path.get_locus ()));
551 : :
552 : 64 : return;
553 : : }
554 : :
555 : 1079 : if (path.opening_scope_resolution ())
556 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
557 : :
558 : 1079 : visit_items_joined_by_separator (path.get_segments (), SCOPE_RESOLUTION);
559 : : }
560 : :
561 : : void
562 : 3368 : TokenCollector::visit (TypePathSegment &segment)
563 : : {
564 : : // Syntax:
565 : : // PathIdentSegment
566 : :
567 : 3368 : auto locus = segment.is_lang_item ()
568 : 3368 : ? segment.get_locus ()
569 : 3368 : : segment.get_ident_segment ().get_locus ();
570 : 3368 : auto segment_string = segment.is_lang_item ()
571 : 3368 : ? LangItem::PrettyString (segment.get_lang_item ())
572 : 3368 : : segment.get_ident_segment ().as_string ();
573 : 6736 : push (Rust::Token::make_identifier (locus, std::move (segment_string)));
574 : 3368 : }
575 : :
576 : : void
577 : 248 : TokenCollector::visit (TypePathSegmentGeneric &segment)
578 : : {
579 : : // Syntax:
580 : : // PathIdentSegment `::`? (GenericArgs)?
581 : : // GenericArgs :
582 : : // `<` `>`
583 : : // | `<` ( GenericArg `,` )* GenericArg `,`? `>`
584 : :
585 : 248 : auto locus = segment.is_lang_item ()
586 : 248 : ? segment.get_locus ()
587 : 248 : : segment.get_ident_segment ().get_locus ();
588 : 248 : auto segment_string = segment.is_lang_item ()
589 : 248 : ? LangItem::PrettyString (segment.get_lang_item ())
590 : 248 : : segment.get_ident_segment ().as_string ();
591 : 248 : push (Rust::Token::make_identifier (locus, std::move (segment_string)));
592 : :
593 : 248 : if (segment.get_separating_scope_resolution ())
594 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
595 : :
596 : 248 : push (Rust::Token::make (LEFT_ANGLE, UNDEF_LOCATION));
597 : :
598 : 248 : {
599 : 248 : auto &lifetime_args = segment.get_generic_args ().get_lifetime_args ();
600 : 248 : auto &generic_args = segment.get_generic_args ().get_generic_args ();
601 : 248 : auto &binding_args = segment.get_generic_args ().get_binding_args ();
602 : :
603 : 248 : visit_items_joined_by_separator (lifetime_args, COMMA);
604 : 248 : if (!lifetime_args.empty ()
605 : 248 : && (!generic_args.empty () || !binding_args.empty ()))
606 : 2 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
607 : 248 : visit_items_joined_by_separator (generic_args, COMMA);
608 : 248 : if (!generic_args.empty () && !binding_args.empty ())
609 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
610 : 248 : visit_items_joined_by_separator (binding_args, COMMA);
611 : : }
612 : :
613 : 496 : push (Rust::Token::make (RIGHT_ANGLE, UNDEF_LOCATION));
614 : 248 : }
615 : :
616 : : void
617 : 32 : TokenCollector::visit (GenericArgsBinding &binding)
618 : : {
619 : : // Syntax:
620 : : // IDENTIFIER `=` Type
621 : 64 : auto identifier = binding.get_identifier ().as_string ();
622 : 32 : push (Rust::Token::make_identifier (binding.get_locus (),
623 : : std::move (identifier)));
624 : :
625 : 32 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
626 : 32 : visit (binding.get_type ());
627 : 32 : }
628 : :
629 : : void
630 : 323 : TokenCollector::visit (GenericArg &arg)
631 : : {
632 : : // `GenericArg` implements `accept_vis` but it is not useful for this case as
633 : : // it ignores unresolved cases (`Kind::Either`).
634 : 323 : switch (arg.get_kind ())
635 : : {
636 : 0 : case GenericArg::Kind::Const:
637 : 0 : visit (arg.get_expression ());
638 : 0 : break;
639 : 323 : case GenericArg::Kind::Type:
640 : 323 : visit (arg.get_type ());
641 : 323 : break;
642 : 0 : case GenericArg::Kind::Either:
643 : 0 : {
644 : 0 : auto path = arg.get_path ();
645 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (path)));
646 : 0 : }
647 : 0 : break;
648 : : }
649 : 323 : }
650 : :
651 : : void
652 : 5 : TokenCollector::visit (TypePathSegmentFunction &segment)
653 : : {
654 : : // Syntax:
655 : : // PathIdentSegment `::`? (TypePathFn)?
656 : :
657 : 5 : auto ident_segment = segment.get_ident_segment ();
658 : 5 : auto id = ident_segment.as_string ();
659 : 5 : push (
660 : 5 : Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
661 : :
662 : 5 : if (segment.get_separating_scope_resolution ())
663 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
664 : :
665 : 5 : if (!segment.is_ident_only ())
666 : 5 : visit (segment.get_type_path_function ());
667 : 5 : }
668 : :
669 : : void
670 : 5 : TokenCollector::visit (TypePathFunction &type_path_fn)
671 : : {
672 : : // Syntax:
673 : : // `(` TypePathFnInputs? `)` (`->` Type)?
674 : : // TypePathFnInputs :
675 : : // Type (`,` Type)* `,`?
676 : :
677 : 5 : push (Rust::Token::make (LEFT_PAREN, type_path_fn.get_locus ()));
678 : 5 : if (type_path_fn.has_inputs ())
679 : 5 : visit_items_joined_by_separator (type_path_fn.get_params (), COMMA);
680 : 5 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
681 : :
682 : 5 : if (type_path_fn.has_return_type ())
683 : : {
684 : 5 : push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
685 : 5 : visit (type_path_fn.get_return_type ());
686 : : }
687 : 5 : }
688 : :
689 : : void
690 : 3055 : TokenCollector::visit (TypePath &path)
691 : : {
692 : : // Syntax:
693 : : // `::`? TypePathSegment (`::` TypePathSegment)*
694 : :
695 : 3055 : if (path.has_opening_scope_resolution_op ())
696 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
697 : :
698 : 3055 : visit_items_joined_by_separator (path.get_segments (), SCOPE_RESOLUTION);
699 : 3055 : }
700 : :
701 : : void
702 : 1559 : TokenCollector::visit (PathIdentSegment &segment)
703 : : {
704 : 1559 : if (segment.is_super_path_seg ())
705 : : {
706 : 0 : push (Rust::Token::make (SUPER, segment.get_locus ()));
707 : : }
708 : 1559 : else if (segment.is_crate_path_seg ())
709 : : {
710 : 14 : push (Rust::Token::make (CRATE, segment.get_locus ()));
711 : : }
712 : 1552 : else if (segment.is_lower_self_seg ())
713 : : {
714 : 182 : push (Rust::Token::make (SELF, segment.get_locus ()));
715 : : }
716 : 1461 : else if (segment.is_big_self_seg ())
717 : : {
718 : 0 : push (Rust::Token::make (SELF_ALIAS, segment.get_locus ()));
719 : : }
720 : : else
721 : : {
722 : 1461 : auto id = segment.as_string ();
723 : 1461 : push (
724 : 2922 : Rust::Token::make_identifier (segment.get_locus (), std::move (id)));
725 : 1461 : }
726 : 1559 : }
727 : :
728 : : void
729 : 23 : TokenCollector::visit (QualifiedPathInExpression &path)
730 : : {
731 : 23 : visit (path.get_qualified_path_type ());
732 : 46 : for (auto &segment : path.get_segments ())
733 : : {
734 : 23 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
735 : 23 : visit (segment);
736 : : }
737 : 23 : }
738 : :
739 : : void
740 : 57 : TokenCollector::visit (QualifiedPathType &path)
741 : : {
742 : 57 : push (Rust::Token::make (LEFT_ANGLE, path.get_locus ()));
743 : 57 : visit (path.get_type ());
744 : 57 : if (path.has_as_clause ())
745 : : {
746 : 49 : push (Rust::Token::make (AS, UNDEF_LOCATION));
747 : 49 : visit (path.get_as_type_path ());
748 : : }
749 : 57 : push (Rust::Token::make (RIGHT_ANGLE, UNDEF_LOCATION));
750 : 57 : }
751 : :
752 : : void
753 : 34 : TokenCollector::visit (QualifiedPathInType &path)
754 : : {
755 : 34 : visit (path.get_qualified_path_type ());
756 : :
757 : 34 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
758 : 34 : visit (path.get_associated_segment ());
759 : 34 : for (auto &segment : path.get_segments ())
760 : : {
761 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
762 : 0 : visit (segment);
763 : : }
764 : 34 : }
765 : :
766 : : void
767 : 3624 : TokenCollector::visit (Literal &lit, location_t locus)
768 : : {
769 : 3624 : auto value = lit.as_string ();
770 : 3624 : switch (lit.get_lit_type ())
771 : : {
772 : 49 : case Literal::LitType::CHAR:
773 : 49 : push (
774 : 49 : Rust::Token::make_char (locus,
775 : : // TODO: Change this to support utf-8 properly
776 : 49 : Codepoint (static_cast<uint32_t> (value[0]))));
777 : 49 : break;
778 : 1984 : case Literal::LitType::STRING:
779 : 1984 : push (Rust::Token::make_string (locus, std::move (value)));
780 : 1984 : break;
781 : 28 : case Literal::LitType::BYTE:
782 : 28 : push (Rust::Token::make_byte_char (locus, value[0]));
783 : 28 : break;
784 : 14 : case Literal::LitType::BYTE_STRING:
785 : 14 : push (Rust::Token::make_byte_string (locus, std::move (value)));
786 : 14 : break;
787 : 0 : case Literal::LitType::RAW_STRING:
788 : 0 : push (Rust::Token::make_raw_string (locus, std::move (value)));
789 : 0 : break;
790 : 1392 : case Literal::LitType::INT:
791 : 1392 : push (
792 : 1392 : Rust::Token::make_int (locus, std::move (value), lit.get_type_hint ()));
793 : 1392 : break;
794 : 16 : case Literal::LitType::FLOAT:
795 : 16 : push (Rust::Token::make_float (locus, std::move (value),
796 : : lit.get_type_hint ()));
797 : 16 : break;
798 : 141 : case Literal::LitType::BOOL:
799 : 141 : {
800 : 141 : if (value == Values::Keywords::FALSE_LITERAL)
801 : 130 : push (Rust::Token::make (FALSE_LITERAL, locus));
802 : 76 : else if (value == Values::Keywords::TRUE_LITERAL)
803 : 152 : push (Rust::Token::make (TRUE_LITERAL, locus));
804 : : else
805 : 0 : rust_unreachable (); // Not a boolean
806 : : break;
807 : : }
808 : 0 : case Literal::LitType::ERROR:
809 : 0 : rust_unreachable ();
810 : 3624 : break;
811 : : }
812 : 3624 : }
813 : :
814 : : void
815 : 3604 : TokenCollector::visit (LiteralExpr &expr)
816 : : {
817 : 3604 : auto lit = expr.get_literal ();
818 : 3604 : visit (lit, expr.get_locus ());
819 : 3604 : }
820 : :
821 : : void
822 : 1908 : TokenCollector::visit (AttrInputLiteral &literal)
823 : : {
824 : 1908 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
825 : 1908 : visit (literal.get_literal ());
826 : 1908 : }
827 : :
828 : : void
829 : 0 : TokenCollector::visit (AttrInputMacro ¯o)
830 : : {
831 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
832 : 0 : visit (macro.get_macro ());
833 : 0 : }
834 : :
835 : : void
836 : 0 : TokenCollector::visit (MetaItemLitExpr &item)
837 : : {
838 : 0 : auto lit = item.get_literal ();
839 : 0 : visit (lit);
840 : 0 : }
841 : :
842 : : void
843 : 0 : TokenCollector::visit (MetaItemPathExpr &item)
844 : : {
845 : 0 : auto &path = item.get_path ();
846 : 0 : auto &expr = item.get_expr ();
847 : 0 : visit (path);
848 : 0 : push (Rust::Token::make (EQUAL, item.get_locus ()));
849 : 0 : visit (expr);
850 : 0 : }
851 : :
852 : : void
853 : 237 : TokenCollector::visit (BorrowExpr &expr)
854 : : {
855 : 237 : push (Rust::Token::make (AMP, expr.get_locus ()));
856 : 237 : if (expr.get_is_double_borrow ())
857 : 32 : push (Rust::Token::make (AMP, UNDEF_LOCATION));
858 : :
859 : 237 : if (expr.is_raw_borrow ())
860 : : {
861 : 0 : push (Rust::Token::make_identifier (expr.get_locus (),
862 : 0 : Values::WeakKeywords::RAW));
863 : 0 : if (expr.get_is_mut ())
864 : 0 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
865 : : else
866 : 0 : push (Rust::Token::make (CONST, UNDEF_LOCATION));
867 : : }
868 : : else
869 : : {
870 : 237 : if (expr.get_is_mut ())
871 : 134 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
872 : : }
873 : :
874 : 237 : if (expr.has_borrow_expr ())
875 : 237 : visit (expr.get_borrowed_expr ());
876 : 237 : }
877 : :
878 : : void
879 : 82 : TokenCollector::visit (DereferenceExpr &expr)
880 : : {
881 : 82 : push (Rust::Token::make (ASTERISK, expr.get_locus ()));
882 : 82 : visit (expr.get_dereferenced_expr ());
883 : 82 : }
884 : :
885 : : void
886 : 0 : TokenCollector::visit (ErrorPropagationExpr &expr)
887 : : {
888 : 0 : visit (expr.get_propagating_expr ());
889 : 0 : push (Rust::Token::make (QUESTION_MARK, expr.get_locus ()));
890 : 0 : }
891 : :
892 : : void
893 : 174 : TokenCollector::visit (NegationExpr &expr)
894 : : {
895 : 174 : switch (expr.get_expr_type ())
896 : : {
897 : 102 : case NegationOperator::NEGATE:
898 : 102 : push (Rust::Token::make (MINUS, expr.get_locus ()));
899 : 102 : break;
900 : 72 : case NegationOperator::NOT:
901 : 72 : push (Rust::Token::make (EXCLAM, expr.get_locus ()));
902 : 72 : break;
903 : : }
904 : 174 : visit (expr.get_negated_expr ());
905 : 174 : }
906 : :
907 : : void
908 : 345 : TokenCollector::visit (ArithmeticOrLogicalExpr &expr)
909 : : {
910 : 345 : visit (expr.get_left_expr ());
911 : 345 : switch (expr.get_expr_type ())
912 : : {
913 : 210 : case ArithmeticOrLogicalOperator::ADD:
914 : 210 : push (Rust::Token::make (PLUS, expr.get_locus ()));
915 : 210 : break;
916 : :
917 : 85 : case ArithmeticOrLogicalOperator::SUBTRACT:
918 : 85 : push (Rust::Token::make (MINUS, expr.get_locus ()));
919 : 85 : break;
920 : :
921 : 22 : case ArithmeticOrLogicalOperator::MULTIPLY:
922 : 22 : push (Rust::Token::make (ASTERISK, expr.get_locus ()));
923 : 22 : break;
924 : :
925 : 8 : case ArithmeticOrLogicalOperator::DIVIDE:
926 : 8 : push (Rust::Token::make (DIV, expr.get_locus ()));
927 : 8 : break;
928 : :
929 : 7 : case ArithmeticOrLogicalOperator::MODULUS:
930 : 7 : push (Rust::Token::make (PERCENT, expr.get_locus ()));
931 : 7 : break;
932 : :
933 : 4 : case ArithmeticOrLogicalOperator::BITWISE_AND:
934 : 4 : push (Rust::Token::make (AMP, expr.get_locus ()));
935 : 4 : break;
936 : :
937 : 3 : case ArithmeticOrLogicalOperator::BITWISE_OR:
938 : 3 : push (Rust::Token::make (PIPE, expr.get_locus ()));
939 : 3 : break;
940 : :
941 : 0 : case ArithmeticOrLogicalOperator::BITWISE_XOR:
942 : 0 : push (Rust::Token::make (CARET, expr.get_locus ()));
943 : 0 : break;
944 : :
945 : 4 : case ArithmeticOrLogicalOperator::LEFT_SHIFT:
946 : 4 : push (Rust::Token::make (LEFT_SHIFT, expr.get_locus ()));
947 : 4 : break;
948 : :
949 : 2 : case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
950 : 2 : push (Rust::Token::make (RIGHT_SHIFT, expr.get_locus ()));
951 : 2 : break;
952 : : }
953 : :
954 : 345 : visit (expr.get_right_expr ());
955 : 345 : }
956 : :
957 : : void
958 : 199 : TokenCollector::visit (ComparisonExpr &expr)
959 : : {
960 : 199 : visit (expr.get_left_expr ());
961 : :
962 : 199 : switch (expr.get_expr_type ())
963 : : {
964 : 17 : case ComparisonOperator::EQUAL:
965 : 17 : push (Rust::Token::make (EQUAL_EQUAL, expr.get_locus ()));
966 : 17 : break;
967 : 99 : case ComparisonOperator::NOT_EQUAL:
968 : 99 : push (Rust::Token::make (NOT_EQUAL, expr.get_locus ()));
969 : 99 : break;
970 : 44 : case ComparisonOperator::GREATER_THAN:
971 : 44 : push (Rust::Token::make (RIGHT_ANGLE, expr.get_locus ()));
972 : 44 : break;
973 : 2 : case ComparisonOperator::LESS_THAN:
974 : 2 : push (Rust::Token::make (LEFT_ANGLE, expr.get_locus ()));
975 : 2 : break;
976 : 2 : case ComparisonOperator::GREATER_OR_EQUAL:
977 : 2 : push (Rust::Token::make (GREATER_OR_EQUAL, expr.get_locus ()));
978 : 2 : break;
979 : :
980 : 35 : case ComparisonOperator::LESS_OR_EQUAL:
981 : 35 : push (Rust::Token::make (LESS_OR_EQUAL, expr.get_locus ()));
982 : 35 : break;
983 : : }
984 : 199 : visit (expr.get_right_expr ());
985 : 199 : }
986 : :
987 : : void
988 : 35 : TokenCollector::visit (LazyBooleanExpr &expr)
989 : : {
990 : 35 : visit (expr.get_left_expr ());
991 : :
992 : 35 : switch (expr.get_expr_type ())
993 : : {
994 : 7 : case LazyBooleanOperator::LOGICAL_AND:
995 : 7 : push (Rust::Token::make (LOGICAL_AND, expr.get_locus ()));
996 : 7 : break;
997 : 28 : case LazyBooleanOperator::LOGICAL_OR:
998 : 28 : push (Rust::Token::make (OR, expr.get_locus ()));
999 : 28 : break;
1000 : : }
1001 : :
1002 : 35 : visit (expr.get_right_expr ());
1003 : 35 : }
1004 : :
1005 : : void
1006 : 223 : TokenCollector::visit (TypeCastExpr &expr)
1007 : : {
1008 : 223 : visit (expr.get_casted_expr ());
1009 : 223 : push (Rust::Token::make (AS, expr.get_locus ()));
1010 : 223 : visit (expr.get_type_to_cast_to ());
1011 : 223 : }
1012 : :
1013 : : void
1014 : 212 : TokenCollector::visit (AssignmentExpr &expr)
1015 : : {
1016 : 212 : expr.visit_lhs (*this);
1017 : 212 : push (Rust::Token::make (EQUAL, expr.get_locus ()));
1018 : 212 : expr.visit_rhs (*this);
1019 : 212 : }
1020 : :
1021 : : void
1022 : 0 : TokenCollector::visit (CompoundAssignmentExpr &expr)
1023 : : {
1024 : 0 : visit (expr.get_left_expr ());
1025 : :
1026 : 0 : switch (expr.get_expr_type ())
1027 : : {
1028 : 0 : case CompoundAssignmentOperator::ADD:
1029 : 0 : push (Rust::Token::make (PLUS_EQ, expr.get_locus ()));
1030 : 0 : break;
1031 : 0 : case CompoundAssignmentOperator::SUBTRACT:
1032 : 0 : push (Rust::Token::make (MINUS_EQ, expr.get_locus ()));
1033 : 0 : break;
1034 : 0 : case CompoundAssignmentOperator::MULTIPLY:
1035 : 0 : push (Rust::Token::make (ASTERISK_EQ, expr.get_locus ()));
1036 : 0 : break;
1037 : 0 : case CompoundAssignmentOperator::DIVIDE:
1038 : 0 : push (Rust::Token::make (DIV_EQ, expr.get_locus ()));
1039 : 0 : break;
1040 : 0 : case CompoundAssignmentOperator::MODULUS:
1041 : 0 : push (Rust::Token::make (PERCENT_EQ, expr.get_locus ()));
1042 : 0 : break;
1043 : 0 : case CompoundAssignmentOperator::BITWISE_AND:
1044 : 0 : push (Rust::Token::make (AMP_EQ, expr.get_locus ()));
1045 : 0 : break;
1046 : 0 : case CompoundAssignmentOperator::BITWISE_OR:
1047 : 0 : push (Rust::Token::make (PIPE_EQ, expr.get_locus ()));
1048 : 0 : break;
1049 : 0 : case CompoundAssignmentOperator::BITWISE_XOR:
1050 : 0 : push (Rust::Token::make (CARET_EQ, expr.get_locus ()));
1051 : 0 : break;
1052 : 0 : case CompoundAssignmentOperator::LEFT_SHIFT:
1053 : 0 : push (Rust::Token::make (LEFT_SHIFT_EQ, expr.get_locus ()));
1054 : 0 : break;
1055 : 0 : case CompoundAssignmentOperator::RIGHT_SHIFT:
1056 : 0 : push (Rust::Token::make (RIGHT_SHIFT_EQ, expr.get_locus ()));
1057 : 0 : break;
1058 : : }
1059 : 0 : visit (expr.get_right_expr ());
1060 : 0 : }
1061 : :
1062 : : void
1063 : 50 : TokenCollector::visit (GroupedExpr &expr)
1064 : : {
1065 : 50 : push (Rust::Token::make (LEFT_PAREN, expr.get_locus ()));
1066 : 50 : visit (expr.get_expr_in_parens ());
1067 : 50 : push (Rust::Token::make (RIGHT_PAREN, expr.get_locus ()));
1068 : 50 : }
1069 : :
1070 : : void
1071 : 8 : TokenCollector::visit (ArrayElemsValues &elems)
1072 : : {
1073 : 8 : visit_items_joined_by_separator (elems.get_values (), COMMA);
1074 : 8 : }
1075 : :
1076 : : void
1077 : 3 : TokenCollector::visit (ArrayElemsCopied &elems)
1078 : : {
1079 : 3 : visit (elems.get_elem_to_copy ());
1080 : 3 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1081 : 3 : visit (elems.get_num_copies ());
1082 : 3 : }
1083 : :
1084 : : void
1085 : 11 : TokenCollector::visit (ArrayExpr &expr)
1086 : : {
1087 : 11 : push (Rust::Token::make (LEFT_SQUARE, expr.get_locus ()));
1088 : 11 : visit (expr.get_array_elems ());
1089 : 11 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
1090 : 11 : }
1091 : :
1092 : : void
1093 : 3 : TokenCollector::visit (ArrayIndexExpr &expr)
1094 : : {
1095 : 3 : visit (expr.get_array_expr ());
1096 : 3 : push (Rust::Token::make (LEFT_SQUARE, expr.get_locus ()));
1097 : 3 : visit (expr.get_index_expr ());
1098 : 3 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
1099 : 3 : }
1100 : :
1101 : : void
1102 : 48 : TokenCollector::visit (TupleExpr &expr)
1103 : : {
1104 : 48 : visit_items_as_lines (expr.get_outer_attrs ());
1105 : 48 : push (Rust::Token::make (LEFT_PAREN, expr.get_locus ()));
1106 : 48 : visit_items_joined_by_separator (expr.get_tuple_elems (), COMMA);
1107 : 48 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
1108 : 48 : }
1109 : :
1110 : : void
1111 : 63 : TokenCollector::visit (TupleIndexExpr &expr)
1112 : : {
1113 : 63 : visit (expr.get_tuple_expr ());
1114 : 63 : push (Rust::Token::make (DOT, expr.get_locus ()));
1115 : 126 : push (Rust::Token::make_int (UNDEF_LOCATION,
1116 : 63 : std::to_string (expr.get_tuple_index ())));
1117 : 63 : }
1118 : :
1119 : : void
1120 : 7 : TokenCollector::visit (StructExprStruct &expr)
1121 : : {
1122 : 7 : visit (expr.get_struct_name ());
1123 : 7 : }
1124 : :
1125 : : void
1126 : 1 : TokenCollector::visit (StructExprFieldIdentifier &expr)
1127 : : {
1128 : 1 : visit_items_as_lines (expr.get_outer_attrs ());
1129 : 2 : auto id = expr.get_field_name ().as_string ();
1130 : 2 : push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
1131 : 1 : }
1132 : :
1133 : : void
1134 : 321 : TokenCollector::visit (StructExprFieldIdentifierValue &expr)
1135 : : {
1136 : 321 : visit_items_as_lines (expr.get_outer_attrs ());
1137 : 321 : auto id = expr.get_field_name ();
1138 : 321 : push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
1139 : 321 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
1140 : 321 : visit (expr.get_value ());
1141 : 321 : }
1142 : :
1143 : : void
1144 : 0 : TokenCollector::visit (StructExprFieldIndexValue &expr)
1145 : : {
1146 : 0 : visit_items_as_lines (expr.get_outer_attrs ());
1147 : 0 : push (Rust::Token::make_int (expr.get_locus (),
1148 : 0 : std::to_string (expr.get_index ())));
1149 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
1150 : 0 : visit (expr.get_value ());
1151 : 0 : }
1152 : :
1153 : : void
1154 : 21 : TokenCollector::visit (StructBase &base)
1155 : : {
1156 : 21 : push (Rust::Token::make (DOT_DOT, UNDEF_LOCATION));
1157 : 21 : visit (base.get_base_struct ());
1158 : 21 : }
1159 : :
1160 : : void
1161 : 122 : TokenCollector::visit (StructExprStructFields &expr)
1162 : : {
1163 : 122 : visit (expr.get_struct_name ());
1164 : 122 : push (Rust::Token::make (LEFT_CURLY, expr.get_locus ()));
1165 : 122 : visit_items_joined_by_separator (expr.get_fields (), COMMA);
1166 : 122 : if (expr.has_struct_base ())
1167 : : {
1168 : 21 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
1169 : 21 : visit (expr.get_struct_base ());
1170 : : }
1171 : : else
1172 : : {
1173 : 101 : trailing_comma ();
1174 : : }
1175 : 122 : push (Rust::Token::make (RIGHT_CURLY, expr.get_locus ()));
1176 : 122 : }
1177 : :
1178 : : void
1179 : 0 : TokenCollector::visit (StructExprStructBase &)
1180 : : {
1181 : : // FIXME: Implement this node
1182 : 0 : rust_unreachable ();
1183 : : }
1184 : :
1185 : : void
1186 : 704 : TokenCollector::visit (CallExpr &expr)
1187 : : {
1188 : 704 : visit (expr.get_function_expr ());
1189 : :
1190 : 704 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
1191 : :
1192 : 704 : visit_items_joined_by_separator (expr.get_params (), COMMA);
1193 : :
1194 : 704 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
1195 : 704 : }
1196 : :
1197 : : void
1198 : 287 : TokenCollector::visit (MethodCallExpr &expr)
1199 : : {
1200 : 287 : visit (expr.get_receiver_expr ());
1201 : 287 : push (Rust::Token::make (DOT, expr.get_locus ()));
1202 : 287 : visit (expr.get_method_name ());
1203 : 287 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
1204 : 287 : visit_items_joined_by_separator (expr.get_params (), COMMA);
1205 : 287 : trailing_comma ();
1206 : 287 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
1207 : 287 : }
1208 : :
1209 : : void
1210 : 124 : TokenCollector::visit (FieldAccessExpr &expr)
1211 : : {
1212 : 124 : visit (expr.get_receiver_expr ());
1213 : 124 : push (Rust::Token::make (DOT, expr.get_locus ()));
1214 : 248 : auto field_name = expr.get_field_name ().as_string ();
1215 : 248 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (field_name)));
1216 : 124 : }
1217 : :
1218 : : void
1219 : 22 : TokenCollector::visit (ClosureParam ¶m)
1220 : : {
1221 : 22 : visit_items_as_lines (param.get_outer_attrs ());
1222 : 22 : visit (param.get_pattern ());
1223 : 22 : if (param.has_type_given ())
1224 : : {
1225 : 22 : push (Rust::Token::make (COLON, param.get_locus ()));
1226 : 22 : visit (param.get_type ());
1227 : : }
1228 : 22 : }
1229 : :
1230 : : void
1231 : 29 : TokenCollector::visit_closure_common (ClosureExpr &expr)
1232 : : {
1233 : 29 : if (expr.get_has_move ())
1234 : : {
1235 : 0 : push (Rust::Token::make (MOVE, expr.get_locus ()));
1236 : : }
1237 : 29 : push (Rust::Token::make (PIPE, UNDEF_LOCATION));
1238 : 29 : visit_items_joined_by_separator (expr.get_params (), COMMA);
1239 : 29 : push (Rust::Token::make (PIPE, UNDEF_LOCATION));
1240 : 29 : }
1241 : :
1242 : : void
1243 : 28 : TokenCollector::visit (ClosureExprInner &expr)
1244 : : {
1245 : 28 : visit_closure_common (expr);
1246 : 28 : visit (expr.get_definition_expr ());
1247 : 28 : }
1248 : :
1249 : : void
1250 : 1496 : TokenCollector::visit (BlockExpr &expr)
1251 : : {
1252 : 1496 : visit_items_as_lines (expr.get_outer_attrs ());
1253 : 1496 : push (Rust::Token::make (LEFT_CURLY, expr.get_locus ()));
1254 : 1496 : newline ();
1255 : 1496 : increment_indentation ();
1256 : 1496 : visit_items_as_lines (expr.get_inner_attrs ());
1257 : :
1258 : 1496 : visit_items_as_lines (expr.get_statements (), {});
1259 : :
1260 : 1496 : if (expr.has_tail_expr ())
1261 : : {
1262 : 907 : indentation ();
1263 : 907 : visit (expr.get_tail_expr ());
1264 : 907 : comment ("tail expr");
1265 : 907 : newline ();
1266 : : }
1267 : :
1268 : 1496 : decrement_indentation ();
1269 : 1496 : indentation ();
1270 : 1496 : push (Rust::Token::make (RIGHT_CURLY, expr.get_locus ()));
1271 : 1496 : newline ();
1272 : 1496 : }
1273 : :
1274 : : void
1275 : 14 : TokenCollector::visit (AnonConst &expr)
1276 : : {
1277 : 14 : if (!expr.is_deferred ())
1278 : : {
1279 : 11 : visit (expr.get_inner_expr ());
1280 : 11 : return;
1281 : : }
1282 : :
1283 : 6 : push (Rust::Token::make_string (expr.get_locus (), "_"));
1284 : : }
1285 : :
1286 : : void
1287 : 0 : TokenCollector::visit (ConstBlock &expr)
1288 : : {
1289 : 0 : push (Rust::Token::make (CONST, expr.get_locus ()));
1290 : :
1291 : : // The inner expression is already a block expr, so we don't need to add
1292 : : // curlies
1293 : 0 : visit (expr.get_const_expr ());
1294 : 0 : }
1295 : :
1296 : : void
1297 : 1 : TokenCollector::visit (ClosureExprInnerTyped &expr)
1298 : : {
1299 : 1 : visit_closure_common (expr);
1300 : 1 : push (Rust::Token::make (RETURN_TYPE, expr.get_locus ()));
1301 : 1 : visit (expr.get_return_type ());
1302 : 1 : visit (expr.get_definition_expr ());
1303 : 1 : }
1304 : :
1305 : : void
1306 : 0 : TokenCollector::visit (ContinueExpr &expr)
1307 : : {
1308 : 0 : push (Rust::Token::make (CONTINUE, expr.get_locus ()));
1309 : 0 : if (expr.has_label ())
1310 : 0 : visit (expr.get_label_unchecked ());
1311 : 0 : }
1312 : :
1313 : : void
1314 : 24 : TokenCollector::visit (BreakExpr &expr)
1315 : : {
1316 : 24 : push (Rust::Token::make (BREAK, expr.get_locus ()));
1317 : 24 : if (expr.has_label ())
1318 : 0 : visit (expr.get_label_unchecked ());
1319 : 24 : if (expr.has_break_expr ())
1320 : 0 : visit (expr.get_break_expr ());
1321 : 24 : }
1322 : :
1323 : : void
1324 : 24 : TokenCollector::visit (RangeFromToExpr &expr)
1325 : : {
1326 : 24 : visit (expr.get_from_expr ());
1327 : 24 : push (Rust::Token::make (DOT_DOT, expr.get_locus ()));
1328 : 24 : visit (expr.get_to_expr ());
1329 : 24 : }
1330 : :
1331 : : void
1332 : 0 : TokenCollector::visit (RangeFromExpr &expr)
1333 : : {
1334 : 0 : visit (expr.get_from_expr ());
1335 : 0 : push (Rust::Token::make (DOT_DOT, expr.get_locus ()));
1336 : 0 : }
1337 : :
1338 : : void
1339 : 0 : TokenCollector::visit (RangeToExpr &expr)
1340 : : {
1341 : 0 : push (Rust::Token::make (DOT_DOT, expr.get_locus ()));
1342 : 0 : visit (expr.get_to_expr ());
1343 : 0 : }
1344 : :
1345 : : void
1346 : 0 : TokenCollector::visit (RangeFullExpr &expr)
1347 : : {
1348 : 0 : push (Rust::Token::make (DOT_DOT, expr.get_locus ()));
1349 : 0 : }
1350 : :
1351 : : void
1352 : 0 : TokenCollector::visit (RangeFromToInclExpr &expr)
1353 : : {
1354 : 0 : visit (expr.get_from_expr ());
1355 : 0 : push (Rust::Token::make (DOT_DOT_EQ, expr.get_locus ()));
1356 : 0 : visit (expr.get_to_expr ());
1357 : 0 : }
1358 : :
1359 : : void
1360 : 0 : TokenCollector::visit (RangeToInclExpr &expr)
1361 : : {
1362 : 0 : push (Rust::Token::make (DOT_DOT_EQ, expr.get_locus ()));
1363 : 0 : visit (expr.get_to_expr ());
1364 : 0 : }
1365 : :
1366 : : void
1367 : 0 : TokenCollector::visit (BoxExpr &expr)
1368 : : {
1369 : 0 : push (Rust::Token::make (BOX, expr.get_locus ()));
1370 : 0 : visit (expr.get_boxed_expr ());
1371 : 0 : }
1372 : :
1373 : : void
1374 : 0 : TokenCollector::visit (ReturnExpr &expr)
1375 : : {
1376 : 0 : push (Rust::Token::make (RETURN_KW, expr.get_locus ()));
1377 : 0 : if (expr.has_returned_expr ())
1378 : 0 : visit (expr.get_returned_expr ());
1379 : 0 : }
1380 : :
1381 : : void
1382 : 0 : TokenCollector::visit (TryExpr &expr)
1383 : : {
1384 : 0 : push (Rust::Token::make (TRY, expr.get_locus ()));
1385 : 0 : visit (expr.get_block_expr ());
1386 : 0 : }
1387 : :
1388 : : void
1389 : 362 : TokenCollector::visit (UnsafeBlockExpr &expr)
1390 : : {
1391 : 362 : push (Rust::Token::make (UNSAFE, expr.get_locus ()));
1392 : 362 : visit (expr.get_block_expr ());
1393 : 362 : }
1394 : :
1395 : : void
1396 : 0 : TokenCollector::visit (LoopLabel &label)
1397 : : {
1398 : 0 : visit (label.get_lifetime ());
1399 : 0 : push (Rust::Token::make (COLON, label.get_locus ()));
1400 : 0 : }
1401 : :
1402 : : void
1403 : 31 : TokenCollector::visit_loop_common (BaseLoopExpr &expr)
1404 : : {
1405 : 31 : if (expr.has_loop_label ())
1406 : 0 : visit (expr.get_loop_label ());
1407 : 31 : }
1408 : :
1409 : : void
1410 : 24 : TokenCollector::visit (LoopExpr &expr)
1411 : : {
1412 : 24 : visit_loop_common (expr);
1413 : 24 : push (Rust::Token::make (LOOP, expr.get_locus ()));
1414 : 24 : visit (expr.get_loop_block ());
1415 : 24 : }
1416 : :
1417 : : void
1418 : 7 : TokenCollector::visit (WhileLoopExpr &expr)
1419 : : {
1420 : 7 : visit_loop_common (expr);
1421 : 7 : push (Rust::Token::make (WHILE, expr.get_locus ()));
1422 : 7 : visit (expr.get_predicate_expr ());
1423 : 7 : visit (expr.get_loop_block ());
1424 : 7 : }
1425 : :
1426 : : void
1427 : 0 : TokenCollector::visit (WhileLetLoopExpr &expr)
1428 : : {
1429 : 0 : visit_loop_common (expr);
1430 : 0 : push (Rust::Token::make (WHILE, expr.get_locus ()));
1431 : 0 : push (Rust::Token::make (LET, UNDEF_LOCATION));
1432 : : // TODO: The reference mention only one Pattern
1433 : 0 : for (auto &item : expr.get_patterns ())
1434 : : {
1435 : 0 : visit (item);
1436 : : }
1437 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
1438 : 0 : visit (expr.get_scrutinee_expr ());
1439 : 0 : visit (expr.get_loop_block ());
1440 : 0 : }
1441 : :
1442 : : void
1443 : 0 : TokenCollector::visit (ForLoopExpr &expr)
1444 : : {
1445 : 0 : visit_loop_common (expr);
1446 : 0 : push (Rust::Token::make (FOR, expr.get_locus ()));
1447 : 0 : visit (expr.get_pattern ());
1448 : 0 : push (Rust::Token::make (IN, UNDEF_LOCATION));
1449 : 0 : visit (expr.get_iterator_expr ());
1450 : 0 : visit (expr.get_loop_block ());
1451 : 0 : }
1452 : :
1453 : : void
1454 : 207 : TokenCollector::visit (IfExpr &expr)
1455 : : {
1456 : 207 : push (Rust::Token::make (IF, expr.get_locus ()));
1457 : 207 : visit (expr.get_condition_expr ());
1458 : 207 : visit (expr.get_if_block ());
1459 : 207 : }
1460 : :
1461 : : void
1462 : 31 : TokenCollector::visit (IfExprConseqElse &expr)
1463 : : {
1464 : 31 : visit (static_cast<IfExpr &> (expr));
1465 : 31 : indentation ();
1466 : 31 : push (Rust::Token::make (ELSE, expr.get_locus ()));
1467 : 31 : visit (expr.get_else_block ());
1468 : 31 : }
1469 : :
1470 : : void
1471 : 3 : TokenCollector::visit (IfLetExpr &expr)
1472 : : {
1473 : 3 : push (Rust::Token::make (IF, expr.get_locus ()));
1474 : 3 : push (Rust::Token::make (LET, UNDEF_LOCATION));
1475 : 6 : for (auto &pattern : expr.get_patterns ())
1476 : : {
1477 : 3 : visit (pattern);
1478 : : }
1479 : 3 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
1480 : 3 : visit (expr.get_value_expr ());
1481 : 3 : visit (expr.get_if_block ());
1482 : 3 : }
1483 : :
1484 : : void
1485 : 2 : TokenCollector::visit (IfLetExprConseqElse &expr)
1486 : : {
1487 : 2 : visit (static_cast<IfLetExpr &> (expr));
1488 : 2 : indentation ();
1489 : 2 : push (Rust::Token::make (ELSE, expr.get_locus ()));
1490 : 2 : visit (expr.get_else_block ());
1491 : 2 : }
1492 : :
1493 : : void
1494 : 105 : TokenCollector::visit (MatchArm &arm)
1495 : : {
1496 : 105 : visit_items_as_lines (arm.get_outer_attrs ());
1497 : 210 : for (auto &pattern : arm.get_patterns ())
1498 : : {
1499 : 105 : visit (pattern);
1500 : : }
1501 : 105 : if (arm.has_match_arm_guard ())
1502 : : {
1503 : 1 : push (Rust::Token::make (IF, UNDEF_LOCATION));
1504 : 1 : visit (arm.get_guard_expr ());
1505 : : }
1506 : 105 : }
1507 : :
1508 : : void
1509 : 105 : TokenCollector::visit (MatchCase &match_case)
1510 : : {
1511 : 105 : indentation ();
1512 : 105 : visit (match_case.get_arm ());
1513 : 105 : push (Rust::Token::make (MATCH_ARROW, UNDEF_LOCATION));
1514 : 105 : visit (match_case.get_expr ());
1515 : 105 : indentation ();
1516 : 105 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
1517 : 105 : newline ();
1518 : 105 : }
1519 : :
1520 : : void
1521 : 62 : TokenCollector::visit (MatchExpr &expr)
1522 : : {
1523 : 62 : push (Rust::Token::make (MATCH_KW, expr.get_locus ()));
1524 : 62 : visit (expr.get_scrutinee_expr ());
1525 : 62 : push (Rust::Token::make (LEFT_CURLY, UNDEF_LOCATION));
1526 : 62 : newline ();
1527 : 62 : increment_indentation ();
1528 : 62 : visit_items_as_lines (expr.get_inner_attrs ());
1529 : 167 : for (auto &arm : expr.get_match_cases ())
1530 : : {
1531 : 105 : visit (arm);
1532 : : }
1533 : 62 : decrement_indentation ();
1534 : 62 : indentation ();
1535 : 62 : push (Rust::Token::make (RIGHT_CURLY, UNDEF_LOCATION));
1536 : 62 : }
1537 : :
1538 : : void
1539 : 0 : TokenCollector::visit (AwaitExpr &expr)
1540 : : {
1541 : 0 : visit (expr.get_awaited_expr ());
1542 : 0 : push (Rust::Token::make (DOT, expr.get_locus ()));
1543 : : // TODO: Check status of await keyword (Context dependant ?)
1544 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, Values::Keywords::AWAIT));
1545 : 0 : }
1546 : :
1547 : : void
1548 : 0 : TokenCollector::visit (AsyncBlockExpr &expr)
1549 : : {
1550 : 0 : push (Rust::Token::make (ASYNC, expr.get_locus ()));
1551 : 0 : if (expr.get_has_move ())
1552 : 0 : push (Rust::Token::make (MOVE, UNDEF_LOCATION));
1553 : 0 : visit (expr.get_block_expr ());
1554 : 0 : }
1555 : :
1556 : : void
1557 : 0 : TokenCollector::visit (InlineAsm &expr)
1558 : : {
1559 : 0 : push (Rust::Token::make_identifier (expr.get_locus (), "asm"));
1560 : 0 : push (Rust::Token::make (EXCLAM, expr.get_locus ()));
1561 : 0 : push (Rust::Token::make (LEFT_PAREN, expr.get_locus ()));
1562 : :
1563 : 0 : for (auto &template_str : expr.get_template_strs ())
1564 : 0 : push (Rust::Token::make_string (template_str.get_locus (),
1565 : 0 : std::move (template_str.symbol)));
1566 : :
1567 : 0 : push (Rust::Token::make (COLON, expr.get_locus ()));
1568 : :
1569 : 0 : for (auto &operand : expr.get_operands ())
1570 : : {
1571 : 0 : using RegisterType = AST::InlineAsmOperand::RegisterType;
1572 : 0 : switch (operand.get_register_type ())
1573 : : {
1574 : 0 : case RegisterType::In:
1575 : 0 : {
1576 : 0 : visit (operand.get_in ().expr);
1577 : 0 : break;
1578 : : }
1579 : 0 : case RegisterType::Out:
1580 : 0 : {
1581 : 0 : visit (operand.get_out ().expr);
1582 : 0 : break;
1583 : : }
1584 : 0 : case RegisterType::InOut:
1585 : 0 : {
1586 : 0 : visit (operand.get_in_out ().expr);
1587 : 0 : break;
1588 : : }
1589 : 0 : case RegisterType::SplitInOut:
1590 : 0 : {
1591 : 0 : auto split = operand.get_split_in_out ();
1592 : 0 : visit (split.in_expr);
1593 : 0 : visit (split.out_expr);
1594 : 0 : break;
1595 : 0 : }
1596 : 0 : case RegisterType::Const:
1597 : 0 : {
1598 : 0 : visit (operand.get_const ().anon_const.get_inner_expr ());
1599 : 0 : break;
1600 : : }
1601 : 0 : case RegisterType::Sym:
1602 : 0 : {
1603 : 0 : visit (operand.get_sym ().expr);
1604 : 0 : break;
1605 : : }
1606 : 0 : case RegisterType::Label:
1607 : 0 : {
1608 : 0 : visit (operand.get_label ().expr);
1609 : 0 : break;
1610 : : }
1611 : : }
1612 : 0 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1613 : 0 : }
1614 : 0 : push (Rust::Token::make (COLON, expr.get_locus ()));
1615 : :
1616 : 0 : for (auto &clobber : expr.get_clobber_abi ())
1617 : : {
1618 : 0 : push (Rust::Token::make_string (expr.get_locus (),
1619 : 0 : std::move (clobber.symbol)));
1620 : 0 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1621 : 0 : }
1622 : 0 : push (Rust::Token::make (COLON, expr.get_locus ()));
1623 : :
1624 : 0 : for (auto it = expr.named_args.begin (); it != expr.named_args.end (); ++it)
1625 : : {
1626 : 0 : auto &arg = *it;
1627 : 0 : push (
1628 : 0 : Rust::Token::make_identifier (expr.get_locus (), arg.first.c_str ()));
1629 : 0 : push (Rust::Token::make (EQUAL, expr.get_locus ()));
1630 : 0 : push (Rust::Token::make_identifier (expr.get_locus (),
1631 : 0 : std::to_string (arg.second)));
1632 : :
1633 : 0 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1634 : : }
1635 : :
1636 : 0 : push (Rust::Token::make (COLON, expr.get_locus ()));
1637 : :
1638 : 0 : for (auto &option : expr.get_options ())
1639 : : {
1640 : 0 : push (Rust::Token::make_identifier (
1641 : 0 : expr.get_locus (), InlineAsm::option_to_string (option).c_str ()));
1642 : 0 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1643 : 0 : }
1644 : :
1645 : 0 : push (Rust::Token::make (RIGHT_PAREN, expr.get_locus ()));
1646 : 0 : }
1647 : :
1648 : : void
1649 : 2 : TokenCollector::visit (LlvmInlineAsm &expr)
1650 : : {
1651 : 4 : push (Rust::Token::make_identifier (expr.get_locus (), "llvm_asm"));
1652 : 2 : push (Rust::Token::make (EXCLAM, expr.get_locus ()));
1653 : 2 : push (Rust::Token::make (LEFT_PAREN, expr.get_locus ()));
1654 : 4 : for (auto &template_str : expr.get_templates ())
1655 : 4 : push (Rust::Token::make_string (template_str.get_locus (),
1656 : 2 : std::move (template_str.symbol)));
1657 : :
1658 : 2 : push (Rust::Token::make (COLON, expr.get_locus ()));
1659 : 2 : for (auto output : expr.get_outputs ())
1660 : : {
1661 : 0 : push (Rust::Token::make_string (expr.get_locus (),
1662 : : std::move (output.constraint)));
1663 : 0 : visit (output.expr);
1664 : 0 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1665 : 0 : }
1666 : :
1667 : 2 : push (Rust::Token::make (COLON, expr.get_locus ()));
1668 : 4 : for (auto input : expr.get_inputs ())
1669 : : {
1670 : 2 : push (Rust::Token::make_string (expr.get_locus (),
1671 : : std::move (input.constraint)));
1672 : 2 : visit (input.expr);
1673 : 4 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1674 : 2 : }
1675 : :
1676 : 2 : push (Rust::Token::make (COLON, expr.get_locus ()));
1677 : 4 : for (auto &clobber : expr.get_clobbers ())
1678 : : {
1679 : 2 : push (Rust::Token::make_string (expr.get_locus (),
1680 : 2 : std::move (clobber.symbol)));
1681 : 4 : push (Rust::Token::make (COMMA, expr.get_locus ()));
1682 : : }
1683 : 2 : push (Rust::Token::make (COLON, expr.get_locus ()));
1684 : : // Dump options
1685 : :
1686 : 2 : push (Rust::Token::make (RIGHT_PAREN, expr.get_locus ()));
1687 : 2 : }
1688 : :
1689 : : // rust-item.h
1690 : :
1691 : : void
1692 : 408 : TokenCollector::visit (TypeParam ¶m)
1693 : : {
1694 : : // Syntax:
1695 : : // IDENTIFIER( : TypeParamBounds? )? ( = Type )?
1696 : : // TypeParamBounds :
1697 : : // TypeParamBound ( + TypeParamBound )* +?
1698 : :
1699 : 408 : visit_items_as_lines (param.get_outer_attrs ());
1700 : 816 : auto id = param.get_type_representation ().as_string ();
1701 : 408 : push (Rust::Token::make_identifier (param.get_locus (), std::move (id)));
1702 : 408 : if (param.has_type_param_bounds ())
1703 : : {
1704 : 85 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
1705 : 85 : visit_items_joined_by_separator (param.get_type_param_bounds (), PLUS);
1706 : : }
1707 : 408 : if (param.has_type ())
1708 : : {
1709 : 134 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
1710 : 134 : visit (param.get_type ());
1711 : : }
1712 : 408 : }
1713 : :
1714 : : void
1715 : 20 : TokenCollector::visit (WhereClause &rule)
1716 : : {
1717 : : // Syntax:
1718 : : // where ( WhereClauseItem , )* WhereClauseItem ?
1719 : : // WhereClauseItem :
1720 : : // LifetimeWhereClauseItem
1721 : : // | TypeBoundWhereClauseItem
1722 : :
1723 : 20 : push (Rust::Token::make (WHERE, UNDEF_LOCATION));
1724 : 20 : newline ();
1725 : 20 : increment_indentation ();
1726 : 20 : visit_items_joined_by_separator (rule.get_items (), COMMA);
1727 : 20 : decrement_indentation ();
1728 : 20 : }
1729 : :
1730 : : void
1731 : 0 : TokenCollector::visit (LifetimeWhereClauseItem &item)
1732 : : {
1733 : : // Syntax:
1734 : : // Lifetime : LifetimeBounds
1735 : : // LifetimeBounds :
1736 : : // ( Lifetime + )* Lifetime?
1737 : :
1738 : 0 : visit (item.get_lifetime ());
1739 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
1740 : 0 : visit_items_joined_by_separator (item.get_lifetime_bounds (), PLUS);
1741 : 0 : }
1742 : :
1743 : : void
1744 : 38 : TokenCollector::visit (TypeBoundWhereClauseItem &item)
1745 : : {
1746 : : // Syntax:
1747 : : // ForLifetimes? Type : TypeParamBounds?
1748 : : // TypeParamBounds :
1749 : : // TypeParamBound ( + TypeParamBound )* +?
1750 : : // TypeParamBound :
1751 : : // Lifetime | TraitBound
1752 : :
1753 : 38 : if (item.has_for_lifetimes ())
1754 : 0 : visit (item.get_for_lifetimes ());
1755 : :
1756 : 38 : visit (item.get_type ());
1757 : :
1758 : 38 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
1759 : 38 : visit_items_joined_by_separator (item.get_type_param_bounds (), PLUS);
1760 : 38 : }
1761 : :
1762 : : void
1763 : 0 : TokenCollector::visit (Module &module)
1764 : : {
1765 : : // Syntax:
1766 : : // mod IDENTIFIER ;
1767 : : // | mod IDENTIFIER {
1768 : : // InnerAttribute*
1769 : : // Item*
1770 : : // }
1771 : :
1772 : 0 : visit_items_as_lines (module.get_outer_attrs ());
1773 : 0 : visit (module.get_visibility ());
1774 : 0 : auto name = module.get_name ().as_string ();
1775 : 0 : push (Rust::Token::make (MOD, module.get_locus ()));
1776 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (name)));
1777 : :
1778 : 0 : if (module.get_kind () == Module::UNLOADED)
1779 : : {
1780 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1781 : 0 : newline ();
1782 : : }
1783 : : else /* Module::LOADED */
1784 : : {
1785 : 0 : push (Rust::Token::make (LEFT_CURLY, UNDEF_LOCATION));
1786 : 0 : newline ();
1787 : 0 : increment_indentation ();
1788 : :
1789 : 0 : visit_items_as_lines (module.get_inner_attrs ());
1790 : 0 : visit_items_as_lines (module.get_items ());
1791 : :
1792 : 0 : decrement_indentation ();
1793 : :
1794 : 0 : push (Rust::Token::make (RIGHT_CURLY, UNDEF_LOCATION));
1795 : 0 : newline ();
1796 : : }
1797 : 0 : }
1798 : :
1799 : : void
1800 : 0 : TokenCollector::visit (ExternCrate &crate)
1801 : : {
1802 : 0 : visit_items_as_lines (crate.get_outer_attrs ());
1803 : 0 : push (Rust::Token::make (EXTERN_KW, crate.get_locus ()));
1804 : 0 : push (Rust::Token::make (CRATE, UNDEF_LOCATION));
1805 : 0 : auto ref = crate.get_referenced_crate ();
1806 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (ref)));
1807 : 0 : if (crate.has_as_clause ())
1808 : : {
1809 : 0 : auto as_clause = crate.get_as_clause ();
1810 : 0 : push (Rust::Token::make (AS, UNDEF_LOCATION));
1811 : 0 : push (
1812 : 0 : Rust::Token::make_identifier (UNDEF_LOCATION, std::move (as_clause)));
1813 : 0 : }
1814 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1815 : 0 : newline ();
1816 : 0 : }
1817 : :
1818 : : void
1819 : 0 : TokenCollector::visit (UseTreeGlob &use_tree)
1820 : : {
1821 : 0 : switch (use_tree.get_glob_type ())
1822 : : {
1823 : 0 : case UseTreeGlob::PathType::PATH_PREFIXED:
1824 : 0 : {
1825 : 0 : auto path = use_tree.get_path ();
1826 : 0 : visit (path);
1827 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
1828 : 0 : }
1829 : 0 : break;
1830 : 0 : case UseTreeGlob::PathType::NO_PATH:
1831 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
1832 : 0 : break;
1833 : : case UseTreeGlob::PathType::GLOBAL:
1834 : : break;
1835 : : }
1836 : 0 : push (Rust::Token::make (ASTERISK, UNDEF_LOCATION));
1837 : 0 : }
1838 : :
1839 : : void
1840 : 0 : TokenCollector::visit (UseTreeList &use_tree)
1841 : : {
1842 : 0 : switch (use_tree.get_path_type ())
1843 : : {
1844 : 0 : case UseTreeList::PathType::PATH_PREFIXED:
1845 : 0 : {
1846 : 0 : auto path = use_tree.get_path ();
1847 : 0 : visit (path);
1848 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
1849 : 0 : }
1850 : 0 : break;
1851 : 0 : case UseTreeList::PathType::NO_PATH:
1852 : 0 : push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
1853 : 0 : break;
1854 : : case UseTreeList::PathType::GLOBAL:
1855 : : break;
1856 : : }
1857 : :
1858 : 0 : push (Rust::Token::make (LEFT_CURLY, UNDEF_LOCATION));
1859 : 0 : if (use_tree.has_trees ())
1860 : : {
1861 : 0 : visit_items_joined_by_separator (use_tree.get_trees (), COMMA);
1862 : : }
1863 : 0 : push (Rust::Token::make (RIGHT_CURLY, UNDEF_LOCATION));
1864 : 0 : }
1865 : :
1866 : : void
1867 : 0 : TokenCollector::visit (UseTreeRebind &use_tree)
1868 : : {
1869 : 0 : auto path = use_tree.get_path ();
1870 : 0 : visit (path);
1871 : 0 : switch (use_tree.get_new_bind_type ())
1872 : : {
1873 : 0 : case UseTreeRebind::NewBindType::IDENTIFIER:
1874 : 0 : {
1875 : 0 : push (Rust::Token::make (AS, UNDEF_LOCATION));
1876 : 0 : auto id = use_tree.get_identifier ().as_string ();
1877 : 0 : push (
1878 : 0 : Rust::Token::make_identifier (use_tree.get_locus (), std::move (id)));
1879 : 0 : }
1880 : 0 : break;
1881 : 0 : case UseTreeRebind::NewBindType::WILDCARD:
1882 : 0 : push (Rust::Token::make (AS, UNDEF_LOCATION));
1883 : 0 : push (Rust::Token::make (UNDERSCORE, use_tree.get_locus ()));
1884 : 0 : break;
1885 : : case UseTreeRebind::NewBindType::NONE:
1886 : : break;
1887 : : }
1888 : 0 : }
1889 : :
1890 : : void
1891 : 0 : TokenCollector::visit (UseDeclaration &decl)
1892 : : {
1893 : 0 : visit_items_as_lines (decl.get_outer_attrs ());
1894 : 0 : push (Rust::Token::make (USE, decl.get_locus ()));
1895 : 0 : visit (*decl.get_tree ());
1896 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1897 : 0 : newline ();
1898 : 0 : }
1899 : :
1900 : : void
1901 : 1484 : TokenCollector::visit (Function &function)
1902 : : {
1903 : : // Syntax:
1904 : : // FunctionQualifiers fn IDENTIFIER GenericParams?
1905 : : // ( FunctionParameters? )
1906 : : // FunctionReturnType? WhereClause?
1907 : : // ( BlockExpression | ; )
1908 : 1484 : visit_items_as_lines (function.get_outer_attrs ());
1909 : :
1910 : 1484 : visit (function.get_visibility ());
1911 : 1484 : auto qualifiers = function.get_qualifiers ();
1912 : 1484 : visit (qualifiers);
1913 : :
1914 : 1484 : push (Rust::Token::make (FN_KW, function.get_locus ()));
1915 : 2968 : auto name = function.get_function_name ().as_string ();
1916 : 1484 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (name)));
1917 : 1484 : if (function.has_generics ())
1918 : 93 : visit (function.get_generic_params ());
1919 : :
1920 : 1484 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
1921 : :
1922 : 1484 : visit_items_joined_by_separator (function.get_function_params ());
1923 : 1484 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
1924 : :
1925 : 1484 : if (function.has_return_type ())
1926 : : {
1927 : 1077 : push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
1928 : 1077 : visit (function.get_return_type ());
1929 : : }
1930 : :
1931 : 1484 : if (function.has_where_clause ())
1932 : 20 : visit (function.get_where_clause ());
1933 : :
1934 : 1484 : if (function.has_body ())
1935 : 792 : visit (*function.get_definition ());
1936 : : else
1937 : 1384 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1938 : 1484 : newline ();
1939 : 1484 : }
1940 : :
1941 : : void
1942 : 0 : TokenCollector::visit (TypeAlias &type_alias)
1943 : : {
1944 : : // Syntax:
1945 : : // Visibility? type IDENTIFIER GenericParams? WhereClause? = Type;
1946 : :
1947 : : // Note: Associated types are handled by `AST::TraitItemType`.
1948 : :
1949 : 0 : visit_items_as_lines (type_alias.get_outer_attrs ());
1950 : 0 : if (type_alias.has_visibility ())
1951 : 0 : visit (type_alias.get_visibility ());
1952 : 0 : auto alias_name = type_alias.get_new_type_name ().as_string ();
1953 : 0 : push (Rust::Token::make (TYPE, type_alias.get_locus ()));
1954 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (alias_name)));
1955 : :
1956 : 0 : if (type_alias.has_generics ())
1957 : 0 : visit (type_alias.get_generic_params ());
1958 : :
1959 : 0 : if (type_alias.has_where_clause ())
1960 : 0 : visit (type_alias.get_where_clause ());
1961 : :
1962 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
1963 : 0 : visit (type_alias.get_type_aliased ());
1964 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1965 : 0 : }
1966 : :
1967 : : void
1968 : 7 : TokenCollector::visit (StructStruct &struct_item)
1969 : : {
1970 : 7 : visit_items_as_lines (struct_item.get_outer_attrs ());
1971 : 7 : if (struct_item.has_visibility ())
1972 : 0 : visit (struct_item.get_visibility ());
1973 : 14 : auto struct_name = struct_item.get_identifier ().as_string ();
1974 : 7 : push (Rust::Token::make (STRUCT_KW, struct_item.get_locus ()));
1975 : 7 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name)));
1976 : :
1977 : 7 : if (struct_item.has_generics ())
1978 : 0 : visit (struct_item.get_generic_params ());
1979 : 7 : if (struct_item.has_where_clause ())
1980 : 0 : visit (struct_item.get_where_clause ());
1981 : 7 : if (struct_item.is_unit_struct ())
1982 : : {
1983 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
1984 : 0 : newline ();
1985 : : }
1986 : : else
1987 : 14 : visit_items_as_block (struct_item.get_fields (),
1988 : : {Rust::Token::make (COMMA, UNDEF_LOCATION)});
1989 : 7 : }
1990 : :
1991 : : void
1992 : 22 : TokenCollector::visit (TupleStruct &tuple_struct)
1993 : : {
1994 : 22 : visit_items_as_lines (tuple_struct.get_outer_attrs ());
1995 : 44 : auto struct_name = tuple_struct.get_identifier ().as_string ();
1996 : 22 : push (Rust::Token::make (STRUCT_KW, tuple_struct.get_locus ()));
1997 : 22 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name)));
1998 : 22 : if (tuple_struct.has_generics ())
1999 : 0 : visit (tuple_struct.get_generic_params ());
2000 : 22 : if (tuple_struct.has_where_clause ())
2001 : 0 : visit (tuple_struct.get_where_clause ());
2002 : :
2003 : 22 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2004 : 22 : visit_items_joined_by_separator (tuple_struct.get_fields (), COMMA);
2005 : 22 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2006 : 22 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2007 : 22 : newline ();
2008 : 22 : }
2009 : :
2010 : : void
2011 : 1 : TokenCollector::visit (EnumItem &item)
2012 : : {
2013 : 1 : visit_items_as_lines (item.get_outer_attrs ());
2014 : 2 : auto id = item.get_identifier ().as_string ();
2015 : 2 : push (Rust::Token::make_identifier (item.get_locus (), std::move (id)));
2016 : 1 : }
2017 : :
2018 : : void
2019 : 2 : TokenCollector::visit (EnumItemTuple &item)
2020 : : {
2021 : 4 : auto id = item.get_identifier ().as_string ();
2022 : 2 : push (Rust::Token::make_identifier (item.get_locus (), std::move (id)));
2023 : 2 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2024 : 2 : visit_items_joined_by_separator (item.get_tuple_fields (), COMMA);
2025 : 4 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2026 : 2 : }
2027 : :
2028 : : void
2029 : 0 : TokenCollector::visit (EnumItemStruct &item)
2030 : : {
2031 : 0 : auto id = item.get_identifier ().as_string ();
2032 : 0 : push (Rust::Token::make_identifier (item.get_locus (), std::move (id)));
2033 : 0 : visit_items_as_block (item.get_struct_fields (),
2034 : : {Rust::Token::make (COMMA, UNDEF_LOCATION)});
2035 : 0 : }
2036 : :
2037 : : void
2038 : 0 : TokenCollector::visit (EnumItemDiscriminant &item)
2039 : : {
2040 : 0 : auto id = item.get_identifier ().as_string ();
2041 : 0 : push (Rust::Token::make_identifier (item.get_locus (), std::move (id)));
2042 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
2043 : 0 : visit (item.get_expr ());
2044 : 0 : }
2045 : :
2046 : : void
2047 : 2 : TokenCollector::visit (Enum &enumeration)
2048 : : {
2049 : 2 : visit_items_as_lines (enumeration.get_outer_attrs ());
2050 : 2 : if (enumeration.has_visibility ())
2051 : 0 : visit (enumeration.get_visibility ());
2052 : 2 : push (Rust::Token::make (ENUM_KW, enumeration.get_locus ()));
2053 : 4 : auto id = enumeration.get_identifier ().as_string ();
2054 : 2 : push (
2055 : 2 : Rust::Token::make_identifier (enumeration.get_locus (), std::move (id)));
2056 : 2 : if (enumeration.has_generics ())
2057 : 0 : visit (enumeration.get_generic_params ());
2058 : 2 : if (enumeration.has_where_clause ())
2059 : 0 : visit (enumeration.get_where_clause ());
2060 : :
2061 : 4 : visit_items_as_block (enumeration.get_variants (),
2062 : : {Rust::Token::make (COMMA, UNDEF_LOCATION)});
2063 : 2 : }
2064 : :
2065 : : void
2066 : 0 : TokenCollector::visit (Union &union_item)
2067 : : {
2068 : 0 : visit_items_as_lines (union_item.get_outer_attrs ());
2069 : 0 : auto id = union_item.get_identifier ().as_string ();
2070 : 0 : push (Rust::Token::make_identifier (union_item.get_locus (),
2071 : 0 : Values::WeakKeywords::UNION));
2072 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2073 : :
2074 : 0 : if (union_item.has_generics ())
2075 : 0 : visit (union_item.get_generic_params ());
2076 : :
2077 : 0 : if (union_item.has_where_clause ())
2078 : 0 : visit (union_item.get_where_clause ());
2079 : :
2080 : 0 : visit_items_as_block (union_item.get_variants (),
2081 : : {Rust::Token::make (COMMA, UNDEF_LOCATION)});
2082 : 0 : }
2083 : :
2084 : : void
2085 : 0 : TokenCollector::visit (ConstantItem &item)
2086 : : {
2087 : 0 : visit_items_as_lines (item.get_outer_attrs ());
2088 : 0 : push (Rust::Token::make (CONST, item.get_locus ()));
2089 : 0 : if (item.is_unnamed ())
2090 : : {
2091 : 0 : push (Rust::Token::make (UNDERSCORE, UNDEF_LOCATION));
2092 : : }
2093 : : else
2094 : : {
2095 : 0 : push (Rust::Token::make_identifier (item.get_identifier ()));
2096 : : }
2097 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2098 : 0 : visit (item.get_type ());
2099 : 0 : if (item.has_expr ())
2100 : : {
2101 : 0 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
2102 : 0 : visit (item.get_expr ());
2103 : : }
2104 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2105 : 0 : }
2106 : :
2107 : : void
2108 : 1 : TokenCollector::visit (StaticItem &item)
2109 : : {
2110 : 1 : visit_items_as_lines (item.get_outer_attrs ());
2111 : 1 : push (Rust::Token::make (STATIC_KW, item.get_locus ()));
2112 : 1 : if (item.is_mutable ())
2113 : 0 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2114 : :
2115 : 2 : auto id = item.get_identifier ().as_string ();
2116 : 1 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2117 : 1 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2118 : :
2119 : 1 : visit (item.get_type ());
2120 : :
2121 : 1 : if (item.has_expr ())
2122 : : {
2123 : 1 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
2124 : 1 : visit (item.get_expr ());
2125 : : }
2126 : 2 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2127 : 1 : }
2128 : :
2129 : : void
2130 : 0 : TokenCollector::visit_function_common (std::unique_ptr<Type> &return_type,
2131 : : std::unique_ptr<BlockExpr> &block)
2132 : : {
2133 : : // FIXME: This should format the `<vis> fn <name> ( [args] )` as well
2134 : 0 : if (return_type)
2135 : : {
2136 : 0 : push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
2137 : 0 : visit (return_type);
2138 : : }
2139 : :
2140 : 0 : if (block)
2141 : : {
2142 : 0 : visit (block);
2143 : : }
2144 : : else
2145 : : {
2146 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2147 : 0 : newline ();
2148 : : }
2149 : 0 : }
2150 : :
2151 : : void
2152 : 702 : TokenCollector::visit (SelfParam ¶m)
2153 : : {
2154 : 702 : if (param.get_has_ref ())
2155 : : {
2156 : 380 : push (Rust::Token::make (AMP, UNDEF_LOCATION));
2157 : 380 : if (param.has_lifetime ())
2158 : : {
2159 : 380 : auto lifetime = param.get_lifetime ();
2160 : 380 : visit (lifetime);
2161 : 380 : }
2162 : 380 : if (param.get_is_mut ())
2163 : 242 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2164 : : }
2165 : 702 : push (Rust::Token::make (SELF, UNDEF_LOCATION));
2166 : 702 : if (param.has_type ())
2167 : : {
2168 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2169 : 0 : visit (param.get_type ());
2170 : : }
2171 : 702 : }
2172 : :
2173 : : void
2174 : 1 : TokenCollector::visit (TraitItemConst &item)
2175 : : {
2176 : 2 : auto id = item.get_identifier ().as_string ();
2177 : 1 : indentation ();
2178 : 1 : push (Rust::Token::make (CONST, item.get_locus ()));
2179 : 1 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2180 : 1 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2181 : 1 : visit (item.get_type ());
2182 : 1 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2183 : 1 : newline ();
2184 : 1 : }
2185 : :
2186 : : void
2187 : 440 : TokenCollector::visit (TraitItemType &item)
2188 : : {
2189 : 440 : visit_items_as_lines (item.get_outer_attrs ());
2190 : 880 : auto id = item.get_identifier ().as_string ();
2191 : 440 : indentation ();
2192 : :
2193 : 440 : push (Rust::Token::make (TYPE, item.get_locus ()));
2194 : 440 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2195 : 440 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2196 : 440 : newline ();
2197 : 440 : }
2198 : :
2199 : : void
2200 : 1893 : TokenCollector::visit (Trait &trait)
2201 : : {
2202 : 3515 : for (auto &attr : trait.get_outer_attrs ())
2203 : : {
2204 : 1622 : visit (attr);
2205 : 1622 : newline ();
2206 : 1622 : indentation ();
2207 : : }
2208 : :
2209 : 1893 : visit (trait.get_visibility ());
2210 : :
2211 : 3786 : auto id = trait.get_identifier ().as_string ();
2212 : 1893 : push (Rust::Token::make (TRAIT, trait.get_locus ()));
2213 : 1893 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2214 : :
2215 : 1893 : visit (trait.get_generic_params ());
2216 : :
2217 : 1893 : visit_items_as_block (trait.get_trait_items (), {});
2218 : 1893 : }
2219 : :
2220 : : void
2221 : 0 : TokenCollector::visit (InherentImpl &impl)
2222 : : {
2223 : 0 : visit_items_as_lines (impl.get_outer_attrs ());
2224 : 0 : push (Rust::Token::make (IMPL, impl.get_locus ()));
2225 : 0 : visit (impl.get_generic_params ());
2226 : :
2227 : 0 : visit (impl.get_type ());
2228 : :
2229 : 0 : if (impl.has_where_clause ())
2230 : 0 : visit (impl.get_where_clause ());
2231 : :
2232 : : // FIXME: Handle inner attributes
2233 : :
2234 : 0 : visit_items_as_block (impl.get_impl_items (), {});
2235 : 0 : }
2236 : :
2237 : : void
2238 : 2 : TokenCollector::visit (TraitImpl &impl)
2239 : : {
2240 : 2 : visit_items_as_lines (impl.get_outer_attrs ());
2241 : 2 : push (Rust::Token::make (IMPL, impl.get_locus ()));
2242 : 2 : visit (impl.get_generic_params ());
2243 : 2 : if (impl.is_exclam ())
2244 : 0 : push (Rust::Token::make (EXCLAM, UNDEF_LOCATION));
2245 : 2 : visit (impl.get_trait_path ());
2246 : 2 : push (Rust::Token::make (FOR, UNDEF_LOCATION));
2247 : 2 : visit (impl.get_type ());
2248 : :
2249 : 2 : if (impl.has_where_clause ())
2250 : 0 : visit (impl.get_where_clause ());
2251 : :
2252 : 2 : visit_items_as_block (impl.get_impl_items ());
2253 : 2 : }
2254 : :
2255 : : void
2256 : 0 : TokenCollector::visit (ExternalTypeItem &type)
2257 : : {
2258 : 0 : visit (type.get_visibility ());
2259 : :
2260 : 0 : auto id = type.get_identifier ().as_string ();
2261 : :
2262 : 0 : push (Rust::Token::make (TYPE, UNDEF_LOCATION));
2263 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2264 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2265 : 0 : }
2266 : :
2267 : : void
2268 : 0 : TokenCollector::visit (ExternalStaticItem &item)
2269 : : {
2270 : 0 : auto id = item.get_identifier ().as_string ();
2271 : 0 : visit_items_as_lines (item.get_outer_attrs ());
2272 : 0 : if (item.has_visibility ())
2273 : 0 : visit (item.get_visibility ());
2274 : 0 : push (Rust::Token::make (STATIC_KW, item.get_locus ()));
2275 : 0 : if (item.is_mut ())
2276 : 0 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2277 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2278 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2279 : 0 : visit (item.get_type ());
2280 : : // TODO: No expr ? The "(= Expression)?" part from the reference seems missing
2281 : : // in the ast.
2282 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2283 : 0 : }
2284 : :
2285 : : void
2286 : 599 : TokenCollector::visit (ExternBlock &block)
2287 : : {
2288 : 599 : visit_items_as_lines (block.get_outer_attrs ());
2289 : 599 : push (Rust::Token::make (EXTERN_KW, block.get_locus ()));
2290 : :
2291 : 599 : if (block.has_abi ())
2292 : : {
2293 : 599 : auto abi = block.get_abi ();
2294 : 1198 : push (Rust::Token::make_string (UNDEF_LOCATION, std::move (abi)));
2295 : 599 : }
2296 : :
2297 : 599 : visit_items_as_block (block.get_extern_items (), {});
2298 : 599 : }
2299 : :
2300 : : static std::pair<TokenId, TokenId>
2301 : 2 : get_delimiters (DelimType delim)
2302 : : {
2303 : 2 : switch (delim)
2304 : : {
2305 : 2 : case PARENS:
2306 : 2 : return {LEFT_PAREN, RIGHT_PAREN};
2307 : 0 : case SQUARE:
2308 : 0 : return {LEFT_SQUARE, RIGHT_SQUARE};
2309 : 0 : case CURLY:
2310 : 0 : return {LEFT_CURLY, RIGHT_CURLY};
2311 : 0 : default:
2312 : 0 : rust_unreachable ();
2313 : : }
2314 : : }
2315 : :
2316 : : void
2317 : 0 : TokenCollector::visit (MacroMatchFragment &match)
2318 : : {
2319 : 0 : auto id = match.get_ident ().as_string ();
2320 : 0 : auto frag_spec = match.get_frag_spec ().as_string ();
2321 : 0 : push (Rust::Token::make (DOLLAR_SIGN, UNDEF_LOCATION));
2322 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2323 : 0 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2324 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (frag_spec)));
2325 : 0 : }
2326 : :
2327 : : void
2328 : 0 : TokenCollector::visit (MacroMatchRepetition &repetition)
2329 : : {
2330 : 0 : push (Rust::Token::make (DOLLAR_SIGN, UNDEF_LOCATION));
2331 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2332 : :
2333 : 0 : for (auto &match : repetition.get_matches ())
2334 : : {
2335 : 0 : visit (match);
2336 : : }
2337 : :
2338 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2339 : :
2340 : 0 : if (repetition.has_sep ())
2341 : : {
2342 : 0 : push (Rust::Token::make (repetition.get_sep ()->get_id (),
2343 : 0 : repetition.get_sep ()->get_locus ()));
2344 : : }
2345 : 0 : switch (repetition.get_op ())
2346 : : {
2347 : 0 : case MacroMatchRepetition::ANY:
2348 : 0 : push (Rust::Token::make (ASTERISK, UNDEF_LOCATION));
2349 : 0 : break;
2350 : 0 : case MacroMatchRepetition::ONE_OR_MORE:
2351 : 0 : push (Rust::Token::make (PLUS, UNDEF_LOCATION));
2352 : 0 : break;
2353 : 0 : case MacroMatchRepetition::ZERO_OR_ONE:
2354 : 0 : push (Rust::Token::make (QUESTION_MARK, UNDEF_LOCATION));
2355 : 0 : break;
2356 : : case MacroMatchRepetition::NONE:
2357 : : break;
2358 : : }
2359 : 0 : }
2360 : :
2361 : : void
2362 : 2 : TokenCollector::visit (MacroMatcher &matcher)
2363 : : {
2364 : 2 : auto delimiters = get_delimiters (matcher.get_delim_type ());
2365 : :
2366 : 2 : push (Rust::Token::make (delimiters.first, UNDEF_LOCATION));
2367 : :
2368 : 3 : for (auto &item : matcher.get_matches ())
2369 : : {
2370 : 1 : visit (item);
2371 : : }
2372 : :
2373 : 2 : push (Rust::Token::make (delimiters.second, UNDEF_LOCATION));
2374 : 2 : }
2375 : :
2376 : : void
2377 : 2 : TokenCollector::visit (MacroRule &rule)
2378 : : {
2379 : 2 : visit (rule.get_matcher ());
2380 : 2 : push (Rust::Token::make (MATCH_ARROW, rule.get_locus ()));
2381 : 2 : visit (rule.get_transcriber ().get_token_tree ());
2382 : 2 : }
2383 : :
2384 : : void
2385 : 2 : TokenCollector::visit (MacroRulesDefinition &rules_def)
2386 : : {
2387 : 3 : for (auto &outer_attr : rules_def.get_outer_attrs ())
2388 : 1 : visit (outer_attr);
2389 : :
2390 : 4 : auto rule_name = rules_def.get_rule_name ().as_string ();
2391 : :
2392 : 4 : push (Rust::Token::make_identifier (rules_def.get_locus (),
2393 : 2 : Values::WeakKeywords::MACRO_RULES));
2394 : 2 : push (Rust::Token::make (EXCLAM, UNDEF_LOCATION));
2395 : :
2396 : 2 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (rule_name)));
2397 : :
2398 : 4 : visit_items_as_block (rules_def.get_rules (),
2399 : : {Rust::Token::make (SEMICOLON, UNDEF_LOCATION)});
2400 : 2 : }
2401 : :
2402 : : void
2403 : 0 : TokenCollector::visit (MacroInvocation &invocation)
2404 : : {
2405 : 0 : auto data = invocation.get_invoc_data ();
2406 : 0 : visit (data.get_path ());
2407 : 0 : push (Rust::Token::make (EXCLAM, UNDEF_LOCATION));
2408 : 0 : visit (data.get_delim_tok_tree ());
2409 : 0 : if (invocation.has_semicolon ())
2410 : 0 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2411 : 0 : }
2412 : :
2413 : : void
2414 : 0 : TokenCollector::visit (MetaItemPath &item)
2415 : : {
2416 : 0 : auto path = item.to_path_item ();
2417 : 0 : visit (path);
2418 : 0 : }
2419 : :
2420 : : void
2421 : 2 : TokenCollector::visit (MetaItemSeq &item)
2422 : : {
2423 : 2 : visit (item.get_path ());
2424 : : // TODO: Double check this, there is probably a mistake.
2425 : 2 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2426 : 2 : visit_items_joined_by_separator (item.get_seq (), COMMA);
2427 : 2 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2428 : 2 : }
2429 : :
2430 : : void
2431 : 0 : TokenCollector::visit (MetaWord &word)
2432 : : {
2433 : 0 : auto id = word.get_ident ().as_string ();
2434 : :
2435 : 0 : push (Rust::Token::make_identifier (word.get_locus (), std::move (id)));
2436 : 0 : }
2437 : :
2438 : : void
2439 : 5 : TokenCollector::visit (MetaNameValueStr &name)
2440 : : {
2441 : 5 : auto pair = name.get_name_value_pair ();
2442 : 5 : auto id = std::get<0> (pair).as_string ();
2443 : 5 : auto value = std::get<1> (pair);
2444 : :
2445 : 5 : push (Rust::Token::make_identifier (name.get_locus (), std::move (id)));
2446 : 5 : push (Rust::Token::make (EQUAL, name.get_locus ()));
2447 : 5 : push (Rust::Token::make (DOUBLE_QUOTE, UNDEF_LOCATION));
2448 : 5 : push (Rust::Token::make_identifier (name.get_locus (), std::move (value)));
2449 : 10 : push (Rust::Token::make (DOUBLE_QUOTE, UNDEF_LOCATION));
2450 : 5 : }
2451 : :
2452 : : void
2453 : 0 : TokenCollector::visit (MetaListPaths &list)
2454 : : {
2455 : 0 : auto id = list.get_ident ().as_string ();
2456 : :
2457 : 0 : push (Rust::Token::make_identifier (list.get_locus (), std::move (id)));
2458 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2459 : :
2460 : 0 : visit_items_joined_by_separator (list.get_paths (), COMMA);
2461 : :
2462 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2463 : 0 : }
2464 : :
2465 : : void
2466 : 0 : TokenCollector::visit (MetaListNameValueStr &list)
2467 : : {
2468 : 0 : auto id = list.get_ident ().as_string ();
2469 : :
2470 : 0 : push (Rust::Token::make_identifier (list.get_locus (), std::move (id)));
2471 : 0 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2472 : :
2473 : 0 : visit_items_joined_by_separator (list.get_values (), COMMA);
2474 : :
2475 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2476 : 0 : }
2477 : :
2478 : : // rust-pattern.h
2479 : : void
2480 : 20 : TokenCollector::visit (LiteralPattern &pattern)
2481 : : {
2482 : 20 : visit (pattern.get_literal (), pattern.get_locus ());
2483 : 20 : }
2484 : :
2485 : : void
2486 : 2039 : TokenCollector::visit (IdentifierPattern &pattern)
2487 : : {
2488 : 2039 : if (pattern.get_is_ref ())
2489 : : {
2490 : 0 : push (Rust::Token::make (REF, pattern.get_locus ()));
2491 : : }
2492 : 2039 : if (pattern.get_is_mut ())
2493 : : {
2494 : 238 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2495 : : }
2496 : :
2497 : 4078 : auto id = pattern.get_ident ().as_string ();
2498 : 2039 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2499 : :
2500 : 2039 : if (pattern.has_subpattern ())
2501 : : {
2502 : 0 : push (Rust::Token::make (PATTERN_BIND, UNDEF_LOCATION));
2503 : 0 : visit (pattern.get_subpattern ());
2504 : : }
2505 : 2039 : }
2506 : :
2507 : : void
2508 : 112 : TokenCollector::visit (WildcardPattern &pattern)
2509 : : {
2510 : 112 : push (Rust::Token::make (UNDERSCORE, pattern.get_locus ()));
2511 : 112 : }
2512 : :
2513 : : void
2514 : 0 : TokenCollector::visit (RestPattern &pattern)
2515 : : {
2516 : 0 : push (Rust::Token::make (DOT_DOT, pattern.get_locus ()));
2517 : 0 : }
2518 : :
2519 : : // void TokenCollector::visit(RangePatternBound& ){}
2520 : :
2521 : : void
2522 : 0 : TokenCollector::visit (RangePatternBoundLiteral &pattern)
2523 : : {
2524 : 0 : if (pattern.get_has_minus ())
2525 : : {
2526 : 0 : push (Rust::Token::make (MINUS, pattern.get_locus ()));
2527 : : }
2528 : 0 : auto literal = pattern.get_literal ();
2529 : 0 : visit (literal);
2530 : 0 : }
2531 : :
2532 : : void
2533 : 0 : TokenCollector::visit (RangePatternBoundPath &pattern)
2534 : : {
2535 : 0 : visit (pattern.get_path ());
2536 : 0 : }
2537 : :
2538 : : void
2539 : 0 : TokenCollector::visit (RangePatternBoundQualPath &pattern)
2540 : : {
2541 : 0 : visit (pattern.get_qualified_path ());
2542 : 0 : }
2543 : :
2544 : : void
2545 : 0 : TokenCollector::visit (RangePattern &pattern)
2546 : : {
2547 : 0 : if (pattern.get_has_lower_bound () && pattern.get_has_upper_bound ())
2548 : : {
2549 : 0 : visit (pattern.get_lower_bound ());
2550 : 0 : if (pattern.get_has_ellipsis_syntax ())
2551 : 0 : push (Rust::Token::make (ELLIPSIS, pattern.get_locus ()));
2552 : : else
2553 : 0 : push (Rust::Token::make (DOT_DOT_EQ, pattern.get_locus ()));
2554 : 0 : visit (pattern.get_upper_bound ());
2555 : : }
2556 : 0 : else if (pattern.get_has_lower_bound ())
2557 : : {
2558 : 0 : visit (pattern.get_lower_bound ());
2559 : 0 : push (Rust::Token::make (DOT_DOT, pattern.get_locus ()));
2560 : : }
2561 : : else
2562 : : {
2563 : 0 : push (Rust::Token::make (DOT_DOT_EQ, pattern.get_locus ()));
2564 : 0 : visit (pattern.get_upper_bound ());
2565 : : }
2566 : 0 : }
2567 : :
2568 : : void
2569 : 2 : TokenCollector::visit (ReferencePattern &pattern)
2570 : : {
2571 : 2 : if (pattern.is_double_reference ())
2572 : : {
2573 : 2 : push (Rust::Token::make (LOGICAL_AND, pattern.get_locus ()));
2574 : : }
2575 : : else
2576 : : {
2577 : 2 : push (Rust::Token::make (AMP, pattern.get_locus ()));
2578 : : }
2579 : :
2580 : 2 : if (pattern.get_is_mut ())
2581 : : {
2582 : 0 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2583 : : }
2584 : :
2585 : 2 : visit (pattern.get_referenced_pattern ());
2586 : 2 : }
2587 : :
2588 : : // void TokenCollector::visit(StructPatternField& ){}
2589 : :
2590 : : void
2591 : 0 : TokenCollector::visit (StructPatternFieldTuplePat &pattern)
2592 : : {
2593 : 0 : visit_items_as_lines (pattern.get_outer_attrs ());
2594 : 0 : push (Rust::Token::make_int (pattern.get_locus (),
2595 : 0 : std::to_string (pattern.get_index ())));
2596 : 0 : push (Rust::Token::make (COLON, pattern.get_locus ()));
2597 : 0 : visit (pattern.get_index_pattern ());
2598 : 0 : }
2599 : :
2600 : : void
2601 : 1 : TokenCollector::visit (StructPatternFieldIdentPat &pattern)
2602 : : {
2603 : 1 : visit_items_as_lines (pattern.get_outer_attrs ());
2604 : :
2605 : 1 : auto id = pattern.get_identifier ().as_string ();
2606 : 1 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2607 : :
2608 : 1 : push (Rust::Token::make (COLON, pattern.get_locus ()));
2609 : :
2610 : 1 : visit (pattern.get_ident_pattern ());
2611 : 1 : }
2612 : :
2613 : : void
2614 : 0 : TokenCollector::visit (StructPatternFieldIdent &pattern)
2615 : : {
2616 : 0 : visit_items_as_lines (pattern.get_outer_attrs ());
2617 : 0 : if (pattern.is_ref ())
2618 : 0 : push (Rust::Token::make (REF, UNDEF_LOCATION));
2619 : 0 : if (pattern.is_mut ())
2620 : 0 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2621 : :
2622 : 0 : auto id = pattern.get_identifier ().as_string ();
2623 : 0 : push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2624 : 0 : }
2625 : :
2626 : : void
2627 : 1 : TokenCollector::visit (StructPattern &pattern)
2628 : : {
2629 : 1 : visit (pattern.get_path ());
2630 : 1 : push (Rust::Token::make (LEFT_CURLY, pattern.get_locus ()));
2631 : 1 : auto elems = pattern.get_struct_pattern_elems ();
2632 : 1 : if (elems.has_struct_pattern_fields ())
2633 : : {
2634 : 1 : visit_items_joined_by_separator (elems.get_struct_pattern_fields ());
2635 : 1 : if (elems.has_etc ())
2636 : : {
2637 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
2638 : 0 : visit_items_as_lines (elems.get_etc_outer_attrs ());
2639 : : }
2640 : : }
2641 : : else
2642 : : {
2643 : 0 : visit_items_as_lines (elems.get_etc_outer_attrs ());
2644 : : }
2645 : :
2646 : 2 : push (Rust::Token::make (RIGHT_CURLY, UNDEF_LOCATION));
2647 : 1 : }
2648 : :
2649 : : // void TokenCollector::visit(TupleStructItems& ){}
2650 : :
2651 : : void
2652 : 26 : TokenCollector::visit (TupleStructItemsNoRange &pattern)
2653 : : {
2654 : 26 : visit_items_joined_by_separator (pattern.get_patterns ());
2655 : 26 : }
2656 : :
2657 : : void
2658 : 0 : TokenCollector::visit (TupleStructItemsRange &pattern)
2659 : : {
2660 : 0 : for (auto &lower : pattern.get_lower_patterns ())
2661 : : {
2662 : 0 : visit (lower);
2663 : : }
2664 : 0 : push (Rust::Token::make (DOT_DOT, UNDEF_LOCATION));
2665 : 0 : for (auto &upper : pattern.get_lower_patterns ())
2666 : : {
2667 : 0 : visit (upper);
2668 : : }
2669 : 0 : }
2670 : :
2671 : : void
2672 : 26 : TokenCollector::visit (TupleStructPattern &pattern)
2673 : : {
2674 : 26 : visit (pattern.get_path ());
2675 : 26 : push (Rust::Token::make (LEFT_PAREN, pattern.get_locus ()));
2676 : 26 : visit (pattern.get_items ());
2677 : 26 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2678 : 26 : }
2679 : :
2680 : : // void
2681 : : // TokenCollector::visit (TuplePatternItems &)
2682 : : // {}
2683 : :
2684 : : void
2685 : 5 : TokenCollector::visit (TuplePatternItemsMultiple &pattern)
2686 : : {
2687 : 5 : visit_items_joined_by_separator (pattern.get_patterns (), COMMA);
2688 : 5 : }
2689 : :
2690 : : void
2691 : 0 : TokenCollector::visit (TuplePatternItemsRanged &pattern)
2692 : : {
2693 : 0 : for (auto &lower : pattern.get_lower_patterns ())
2694 : : {
2695 : 0 : visit (lower);
2696 : : }
2697 : 0 : push (Rust::Token::make (DOT_DOT, UNDEF_LOCATION));
2698 : 0 : for (auto &upper : pattern.get_lower_patterns ())
2699 : : {
2700 : 0 : visit (upper);
2701 : : }
2702 : 0 : }
2703 : :
2704 : : void
2705 : 5 : TokenCollector::visit (TuplePattern &pattern)
2706 : : {
2707 : 5 : push (Rust::Token::make (LEFT_PAREN, pattern.get_locus ()));
2708 : 5 : visit (pattern.get_items ());
2709 : 5 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2710 : 5 : }
2711 : :
2712 : : void
2713 : 0 : TokenCollector::visit (GroupedPattern &pattern)
2714 : : {
2715 : 0 : push (Rust::Token::make (LEFT_PAREN, pattern.get_locus ()));
2716 : 0 : visit (pattern.get_pattern_in_parens ());
2717 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2718 : 0 : }
2719 : :
2720 : : void
2721 : 0 : TokenCollector::visit (SlicePatternItemsNoRest &items)
2722 : : {
2723 : 0 : visit_items_joined_by_separator (items.get_patterns (), COMMA);
2724 : 0 : }
2725 : :
2726 : : void
2727 : 0 : TokenCollector::visit (SlicePatternItemsHasRest &items)
2728 : : {
2729 : 0 : if (!items.get_lower_patterns ().empty ())
2730 : : {
2731 : 0 : visit_items_joined_by_separator (items.get_lower_patterns (), COMMA);
2732 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
2733 : : }
2734 : :
2735 : 0 : push (Rust::Token::make (DOT_DOT, UNDEF_LOCATION));
2736 : :
2737 : 0 : if (!items.get_upper_patterns ().empty ())
2738 : : {
2739 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
2740 : 0 : visit_items_joined_by_separator (items.get_upper_patterns (), COMMA);
2741 : : }
2742 : 0 : }
2743 : :
2744 : : void
2745 : 0 : TokenCollector::visit (SlicePattern &pattern)
2746 : : {
2747 : 0 : push (Rust::Token::make (LEFT_SQUARE, pattern.get_locus ()));
2748 : 0 : visit (pattern.get_items ());
2749 : 0 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
2750 : 0 : }
2751 : :
2752 : : void
2753 : 3 : TokenCollector::visit (AltPattern &pattern)
2754 : : {
2755 : 3 : visit_items_joined_by_separator (pattern.get_alts (), PIPE);
2756 : 3 : }
2757 : :
2758 : : // rust-stmt.h
2759 : : void
2760 : 7 : TokenCollector::visit (EmptyStmt &)
2761 : 7 : {}
2762 : :
2763 : : void
2764 : 1440 : TokenCollector::visit (LetStmt &stmt)
2765 : : {
2766 : 1440 : push (Rust::Token::make (LET, stmt.get_locus ()));
2767 : 1440 : auto &pattern = stmt.get_pattern ();
2768 : 1440 : visit (pattern);
2769 : :
2770 : 1440 : if (stmt.has_type ())
2771 : : {
2772 : 269 : push (Rust::Token::make (COLON, UNDEF_LOCATION));
2773 : 269 : visit (stmt.get_type ());
2774 : : }
2775 : :
2776 : 1440 : if (stmt.has_init_expr ())
2777 : : {
2778 : 1337 : push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
2779 : 1337 : visit (stmt.get_init_expr ());
2780 : : }
2781 : :
2782 : 1440 : if (stmt.has_else_expr ())
2783 : : {
2784 : 0 : push (Rust::Token::make (ELSE, UNDEF_LOCATION));
2785 : 0 : visit (stmt.get_else_expr ());
2786 : : }
2787 : :
2788 : 1440 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2789 : 1440 : }
2790 : :
2791 : : void
2792 : 844 : TokenCollector::visit (ExprStmt &stmt)
2793 : : {
2794 : 844 : visit (stmt.get_expr ());
2795 : 844 : if (stmt.is_semicolon_followed ())
2796 : 1238 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2797 : 844 : }
2798 : :
2799 : : // rust-type.h
2800 : : void
2801 : 183 : TokenCollector::visit (TraitBound &bound)
2802 : : {
2803 : : // Syntax:
2804 : : // ?? ForLifetimes? TypePath
2805 : : // | ( ?? ForLifetimes? TypePath )
2806 : :
2807 : 183 : if (bound.has_opening_question_mark ())
2808 : 76 : push (Rust::Token::make (QUESTION_MARK, bound.get_locus ()));
2809 : :
2810 : 183 : if (bound.has_for_lifetimes ())
2811 : 0 : visit (bound.get_for_lifetimes ());
2812 : :
2813 : 183 : visit (bound.get_type_path ());
2814 : 183 : }
2815 : :
2816 : : void
2817 : 0 : TokenCollector::visit (ImplTraitType &type)
2818 : : {
2819 : : // Syntax:
2820 : : // impl TypeParamBounds
2821 : : // TypeParamBounds :
2822 : : // TypeParamBound ( + TypeParamBound )* +?
2823 : :
2824 : 0 : push (Rust::Token::make (IMPL, type.get_locus ()));
2825 : 0 : visit_items_joined_by_separator (type.get_type_param_bounds (), PLUS);
2826 : 0 : }
2827 : :
2828 : : void
2829 : 0 : TokenCollector::visit (TraitObjectType &type)
2830 : : {
2831 : : // Syntax:
2832 : : // dyn? TypeParamBounds
2833 : : // TypeParamBounds :
2834 : : // TypeParamBound ( + TypeParamBound )* +?
2835 : :
2836 : 0 : if (type.is_dyn ())
2837 : 0 : push (Rust::Token::make (DYN, type.get_locus ()));
2838 : 0 : visit_items_joined_by_separator (type.get_type_param_bounds (), PLUS);
2839 : 0 : }
2840 : :
2841 : : void
2842 : 0 : TokenCollector::visit (ParenthesisedType &type)
2843 : : {
2844 : : // Syntax:
2845 : : // ( Type )
2846 : :
2847 : 0 : push (Rust::Token::make (LEFT_PAREN, type.get_locus ()));
2848 : 0 : visit (type.get_type_in_parens ());
2849 : 0 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2850 : 0 : }
2851 : :
2852 : : void
2853 : 0 : TokenCollector::visit (ImplTraitTypeOneBound &type)
2854 : : {
2855 : : // Syntax:
2856 : : // impl TraitBound
2857 : :
2858 : 0 : push (Rust::Token::make (IMPL, type.get_locus ()));
2859 : 0 : visit (type.get_trait_bound ());
2860 : 0 : }
2861 : :
2862 : : void
2863 : 59 : TokenCollector::visit (TraitObjectTypeOneBound &type)
2864 : : {
2865 : : // Syntax:
2866 : : // dyn? TraitBound
2867 : :
2868 : 59 : if (type.is_dyn ())
2869 : 118 : push (Rust::Token::make (DYN, type.get_locus ()));
2870 : 59 : visit (type.get_trait_bound ());
2871 : 59 : }
2872 : :
2873 : : void
2874 : 16 : TokenCollector::visit (TupleType &type)
2875 : : {
2876 : : // Syntax:
2877 : : // ( )
2878 : : // | ( ( Type , )+ Type? )
2879 : :
2880 : 16 : push (Rust::Token::make (LEFT_PAREN, type.get_locus ()));
2881 : 16 : visit_items_joined_by_separator (type.get_elems (), COMMA);
2882 : 16 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
2883 : 16 : }
2884 : :
2885 : : void
2886 : 0 : TokenCollector::visit (NeverType &type)
2887 : : {
2888 : : // Syntax:
2889 : : // !
2890 : :
2891 : 0 : push (Rust::Token::make (EXCLAM, type.get_locus ()));
2892 : 0 : }
2893 : :
2894 : : void
2895 : 240 : TokenCollector::visit (RawPointerType &type)
2896 : : {
2897 : : // Syntax:
2898 : : // * ( mut | const ) TypeNoBounds
2899 : :
2900 : 240 : push (Rust::Token::make (ASTERISK, type.get_locus ()));
2901 : 240 : if (type.get_pointer_type () == RawPointerType::MUT)
2902 : 16 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2903 : : else /* RawPointerType::CONST */
2904 : 464 : push (Rust::Token::make (CONST, UNDEF_LOCATION));
2905 : :
2906 : 240 : visit (type.get_type_pointed_to ());
2907 : 240 : }
2908 : :
2909 : : void
2910 : 536 : TokenCollector::visit (ReferenceType &type)
2911 : : {
2912 : : // Syntax:
2913 : : // & Lifetime? mut? TypeNoBounds
2914 : :
2915 : 536 : push (Rust::Token::make (AMP, type.get_locus ()));
2916 : :
2917 : 536 : if (type.has_lifetime ())
2918 : : {
2919 : 536 : visit (type.get_lifetime ());
2920 : : }
2921 : :
2922 : 536 : if (type.get_has_mut ())
2923 : 82 : push (Rust::Token::make (MUT, UNDEF_LOCATION));
2924 : :
2925 : 536 : visit (type.get_type_referenced ());
2926 : 536 : }
2927 : :
2928 : : void
2929 : 14 : TokenCollector::visit (ArrayType &type)
2930 : : {
2931 : : // Syntax:
2932 : : // [ Type ; Expression ]
2933 : :
2934 : 14 : push (Rust::Token::make (LEFT_SQUARE, type.get_locus ()));
2935 : 14 : visit (type.get_elem_type ());
2936 : 14 : push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2937 : 14 : visit (type.get_size_expr ());
2938 : 14 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
2939 : 14 : }
2940 : :
2941 : : void
2942 : 4 : TokenCollector::visit (SliceType &type)
2943 : : {
2944 : : // Syntax:
2945 : : // [ Type ]
2946 : :
2947 : 4 : push (Rust::Token::make (LEFT_SQUARE, type.get_locus ()));
2948 : 4 : visit (type.get_elem_type ());
2949 : 4 : push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
2950 : 4 : }
2951 : :
2952 : : void
2953 : 6 : TokenCollector::visit (InferredType &type)
2954 : : {
2955 : : // Syntax:
2956 : : // _
2957 : :
2958 : 6 : push (Rust::Token::make (UNDERSCORE, type.get_locus ()));
2959 : 6 : }
2960 : :
2961 : : void
2962 : 2 : TokenCollector::visit (BareFunctionType &type)
2963 : : {
2964 : : // Syntax:
2965 : : // ForLifetimes? FunctionTypeQualifiers fn
2966 : : // ( FunctionParametersMaybeNamedVariadic? ) BareFunctionReturnType?
2967 : : //
2968 : : // BareFunctionReturnType:
2969 : : // -> TypeNoBounds
2970 : : //
2971 : : // FunctionParametersMaybeNamedVariadic :
2972 : : // MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic
2973 : : //
2974 : : // MaybeNamedFunctionParameters :
2975 : : // MaybeNamedParam ( , MaybeNamedParam )* ,?
2976 : : //
2977 : : // MaybeNamedFunctionParametersVariadic :
2978 : : // ( MaybeNamedParam , )* MaybeNamedParam , OuterAttribute* ...
2979 : :
2980 : 2 : if (type.has_for_lifetimes ())
2981 : 0 : visit (type.get_for_lifetimes ());
2982 : :
2983 : 2 : visit (type.get_function_qualifiers ());
2984 : :
2985 : 2 : push (Rust::Token::make (FN_KW, type.get_locus ()));
2986 : 2 : push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
2987 : :
2988 : 2 : visit_items_joined_by_separator (type.get_function_params (), COMMA);
2989 : :
2990 : 2 : if (type.is_variadic ())
2991 : : {
2992 : 0 : push (Rust::Token::make (COMMA, UNDEF_LOCATION));
2993 : 0 : for (auto &item : type.get_variadic_attr ())
2994 : : {
2995 : 0 : visit (item);
2996 : : }
2997 : 0 : push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
2998 : : }
2999 : :
3000 : 2 : push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
3001 : :
3002 : 2 : if (type.has_return_type ())
3003 : : {
3004 : 0 : push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
3005 : 0 : visit (type.get_return_type ());
3006 : : }
3007 : 2 : }
3008 : :
3009 : : void
3010 : 0 : TokenCollector::visit (AST::FormatArgs &fmt)
3011 : : {
3012 : 0 : rust_sorry_at (fmt.get_locus (), "%s:%u: unimplemented FormatArgs visitor",
3013 : : __FILE__, __LINE__);
3014 : 0 : }
3015 : :
3016 : : void
3017 : 0 : TokenCollector::visit (AST::OffsetOf &offset_of)
3018 : : {
3019 : 0 : auto loc = offset_of.get_locus ();
3020 : :
3021 : 0 : push (Rust::Token::make_identifier (loc, "offset_of"));
3022 : 0 : push (Rust::Token::make (EXCLAM, loc));
3023 : 0 : push (Rust::Token::make (LEFT_PAREN, loc));
3024 : :
3025 : 0 : visit (offset_of.get_type ());
3026 : :
3027 : 0 : push (Rust::Token::make (COMMA, loc));
3028 : :
3029 : 0 : push (Rust::Token::make_identifier (offset_of.get_field ()));
3030 : :
3031 : 0 : push (Rust::Token::make (RIGHT_PAREN, loc));
3032 : 0 : }
3033 : :
3034 : : } // namespace AST
3035 : : } // namespace Rust
|