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