From: Arthur Cohen <[email protected]>
gcc/rust/ChangeLog:
* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice):
Add API to retrieve token slices when lexing macro expansions.
* expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`.
---
gcc/rust/expand/rust-macro-invoc-lexer.cc | 14 ++++++++++++++
gcc/rust/expand/rust-macro-invoc-lexer.h | 3 +++
2 files changed, 17 insertions(+)
diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.cc
b/gcc/rust/expand/rust-macro-invoc-lexer.cc
index 8a43d29e0d1..321f0f97a76 100644
--- a/gcc/rust/expand/rust-macro-invoc-lexer.cc
+++ b/gcc/rust/expand/rust-macro-invoc-lexer.cc
@@ -26,4 +26,18 @@ MacroInvocLexer::split_current_token (TokenId new_left
__attribute__ ((unused)),
// FIXME
gcc_unreachable ();
}
+
+std::vector<std::unique_ptr<AST::Token>>
+MacroInvocLexer::get_token_slice (size_t start_idx, size_t end_idx) const
+{
+ std::vector<std::unique_ptr<AST::Token>> slice;
+
+ rust_assert (end_idx < token_stream.size ());
+
+ for (size_t i = start_idx; i < end_idx; i++)
+ slice.emplace_back (token_stream[i]->clone_token ());
+
+ return slice;
+}
+
} // namespace Rust
diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.h
b/gcc/rust/expand/rust-macro-invoc-lexer.h
index a0d30164850..0923c18c84d 100644
--- a/gcc/rust/expand/rust-macro-invoc-lexer.h
+++ b/gcc/rust/expand/rust-macro-invoc-lexer.h
@@ -55,6 +55,9 @@ public:
size_t get_offs () const { return offs; }
+ std::vector<std::unique_ptr<AST::Token>>
+ get_token_slice (size_t start_idx, size_t end_idx) const;
+
private:
size_t offs;
std::vector<std::unique_ptr<AST::Token>> token_stream;
--
2.40.0
--
Gcc-rust mailing list
[email protected]
https://gcc.gnu.org/mailman/listinfo/gcc-rust