Debian Codegraph @

gcc/rust/expand/rust-token-tree-desugar.cc

raw
1 // Copyright (C) 2025 Free Software Foundation, Inc.
2
3 // This file is part of GCC.
4
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
8 // version.
9
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 // for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #include "rust-token-tree-desugar.h"
20 #include "rust-ast.h"
21 #include "rust-token.h"
22
23 namespace Rust {
24 namespace AST {
25
26 DelimTokenTree
27 TokenTreeDesugar::go (DelimTokenTree &tts)
28 {
29 tts.accept_vis (*this);
30
31 return DelimTokenTree (tts.get_delim_type (), std::move (desugared),
32 tts.get_locus ());
33 }
34
35 void
36 TokenTreeDesugar::append (TokenPtr &&new_token)
37 {
38 desugared.emplace_back (std::make_unique<Token> (std::move (new_token)));
39 }
40
41 void
42 TokenTreeDesugar::append (std::unique_ptr<TokenTree> &&new_token)
43 {
44 desugared.emplace_back (std::move (new_token));
45 }
46
47 void
48 TokenTreeDesugar::visit (Token &tts)
49 {
50 if (tts.get_id () == TokenId::OUTER_DOC_COMMENT
51 || tts.get_id () == TokenId::INNER_DOC_COMMENT)
52 {
53 append (Rust::Token::make (TokenId::HASH, tts.get_locus ()));
54
55 if (tts.get_id () == TokenId::INNER_DOC_COMMENT)
56 append (Rust::Token::make (EXCLAM, tts.get_locus ()));
57
58 append (Rust::Token::make (TokenId::LEFT_SQUARE, tts.get_locus ()));
59 append (Rust::Token::make_identifier (tts.get_locus (), "doc"));
60 append (Rust::Token::make (TokenId::EQUAL, tts.get_locus ()));
61 append (Rust::Token::make_string (tts.get_locus (),
62 std::string (tts.get_str ())));
63 append (Rust::Token::make (TokenId::RIGHT_SQUARE, tts.get_locus ()));
64 }
65 else
66 {
67 append (tts.clone_token ());
68 }
69 }
70
71 }; // namespace AST
72 }; // namespace Rust