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