Line data Source code
1 : // Copyright (C) 2020-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 : #ifndef RUST_MACRO_INVOC_LEXER_H
20 : #define RUST_MACRO_INVOC_LEXER_H
21 :
22 : #include "rust-ast.h"
23 :
24 : namespace Rust {
25 :
26 24363 : class MacroInvocLexer
27 : {
28 : public:
29 17813 : MacroInvocLexer (std::vector<const_TokenPtr> stream)
30 17813 : : offs (0), token_stream (std::move (stream))
31 : {}
32 :
33 6550 : MacroInvocLexer (const std::vector<std::unique_ptr<AST::Token>> &stream)
34 6550 : : offs (0)
35 : {
36 6550 : token_stream.reserve (stream.size ());
37 167789 : for (auto &tk : stream)
38 322478 : token_stream.push_back (tk->get_tok_ptr ());
39 6550 : }
40 :
41 : // Advances current token to n + 1 tokens ahead of current position.
42 6748 : void skip_token (int n) { offs += (n + 1); }
43 :
44 : // Skips the current token.
45 207279 : void skip_token () { skip_token (0); }
46 :
47 : // Returns token n tokens ahead of current position.
48 : const_TokenPtr peek_token (int n);
49 :
50 : // Peeks the current token.
51 784301 : const_TokenPtr peek_token () { return peek_token (0); }
52 :
53 : // Splits the current token into two. Intended for use with nested generics
54 : // closes (i.e. T<U<X>> where >> is wrongly lexed as one token). Note that
55 : // this will only work with "simple" tokens like punctuation.
56 : void split_current_token (TokenId new_left, TokenId new_right);
57 :
58 : void split_current_token (std::vector<TokenPtr> new_tokens);
59 :
60 : std::vector<std::unique_ptr<AST::Token>>
61 : get_token_slice (size_t start_idx, size_t end_idx) const;
62 :
63 0 : std::string get_filename () const
64 : {
65 : // FIXME
66 0 : rust_unreachable ();
67 : return "FIXME";
68 : }
69 :
70 25607 : size_t get_offs () const { return offs; }
71 :
72 : protected:
73 : size_t offs;
74 : std::vector<const_TokenPtr> token_stream;
75 : };
76 :
77 : } // namespace Rust
78 :
79 : #endif // RUST_MACRO_INVOC_LEXER_H
|