Line data Source code
1 : // Copyright (C) 2025-2026 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 2444 : TokenTreeDesugar::go (DelimTokenTree &tts)
28 : {
29 2444 : tts.accept_vis (*this);
30 :
31 2444 : return DelimTokenTree (tts.get_delim_type (), std::move (desugared),
32 2444 : tts.get_locus ());
33 : }
34 :
35 : void
36 18 : TokenTreeDesugar::append (TokenPtr &&new_token)
37 : {
38 18 : desugared.emplace_back (std::make_unique<Token> (std::move (new_token)));
39 18 : }
40 :
41 : void
42 16719 : TokenTreeDesugar::append (std::unique_ptr<TokenTree> &&new_token)
43 : {
44 16719 : desugared.emplace_back (std::move (new_token));
45 16719 : }
46 :
47 : void
48 16722 : TokenTreeDesugar::visit (Token &tts)
49 : {
50 16722 : if (tts.get_id () == TokenId::OUTER_DOC_COMMENT
51 16722 : || tts.get_id () == TokenId::INNER_DOC_COMMENT)
52 : {
53 3 : append (Rust::Token::make (TokenId::HASH, tts.get_locus ()));
54 :
55 3 : if (tts.get_id () == TokenId::INNER_DOC_COMMENT)
56 0 : append (Rust::Token::make (EXCLAM, tts.get_locus ()));
57 :
58 3 : append (Rust::Token::make (TokenId::LEFT_SQUARE, tts.get_locus ()));
59 3 : append (Rust::Token::make_identifier (tts.get_locus (), "doc"));
60 3 : append (Rust::Token::make (TokenId::EQUAL, tts.get_locus ()));
61 6 : append (Rust::Token::make_string (tts.get_locus (),
62 6 : std::string (tts.get_str ())));
63 3 : append (Rust::Token::make (TokenId::RIGHT_SQUARE, tts.get_locus ()));
64 : }
65 : else
66 : {
67 16719 : append (tts.clone_token ());
68 : }
69 16722 : }
70 :
71 : } // namespace AST
72 : } // namespace Rust
|