Debian Codegraph @

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

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 #ifndef RUST_TOKEN_TREE_DESUGAR_H
20 #define RUST_TOKEN_TREE_DESUGAR_H
21
22 #include "rust-ast-visitor.h"
23 #include "rust-system.h"
24 #include "rust-ast.h"
25
26 namespace Rust {
27 namespace AST {
28
29 /**
30 * Desugar a given token-tree before parsing it for a macro invocation. At the
31 * moment, the sole purpose of this desugar is to transform doc-comments into
32 * their attribute form (/// comment -> #[doc = "comment"])
33 */
34 class TokenTreeDesugar : public DefaultASTVisitor
35 {
36 public:
37 TokenTreeDesugar () : desugared (std::vector<std::unique_ptr<TokenTree>> ())
38 {}
39
40 DelimTokenTree go (DelimTokenTree &tts);
41
42 private:
43 std::vector<std::unique_ptr<TokenTree>> desugared;
44 void append (TokenPtr &&new_token);
45 void append (std::unique_ptr<TokenTree> &&new_token);
46
47 using DefaultASTVisitor::visit;
48
49 virtual void visit (Token &tts) override;
50 };
51
52 }; // namespace AST
53 }; // namespace Rust
54
55 #endif //! RUST_TOKEN_TREE_DESUGAR_H