public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] expansion: Add `get_token_slice` to `MacroInvocLexer` class
@ 2023-02-13 12:01 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-13 12:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b1de4bb869845c6c7dadbc1cf84626e922e80ab9

commit b1de4bb869845c6c7dadbc1cf84626e922e80ab9
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Tue Jan 17 16:44:23 2023 +0100

    expansion: Add `get_token_slice` to `MacroInvocLexer` class
    
    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`.

Diff:
---
 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 0fd4554d02f..8190d7b26fa 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-13 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 12:01 [gcc/devel/rust/master] expansion: Add `get_token_slice` to `MacroInvocLexer` class Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).