aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-invoc-lexer.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 13:51:54 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2023-02-24 11:01:27 +0000
commitcda1d7852d6a82df6eea53deb73aab3d459b4443 (patch)
treec194322056777d7e0cb75baf6be2c546e07902d9 /gcc/rust/expand/rust-macro-invoc-lexer.cc
parent53059c7e103baabf76a927e016f8cf79f412327a (diff)
downloadgcc-cda1d7852d6a82df6eea53deb73aab3d459b4443.zip
gcc-cda1d7852d6a82df6eea53deb73aab3d459b4443.tar.gz
gcc-cda1d7852d6a82df6eea53deb73aab3d459b4443.tar.bz2
macro_invoc_lexer: Add `split_current_token` implementation
gcc/rust/ChangeLog: * expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token): Add proper implementation. gcc/testsuite/ChangeLog: * rust/compile/expand_macro_qual_path_in_type.rs: New test.
Diffstat (limited to 'gcc/rust/expand/rust-macro-invoc-lexer.cc')
-rw-r--r--gcc/rust/expand/rust-macro-invoc-lexer.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.cc b/gcc/rust/expand/rust-macro-invoc-lexer.cc
index 321f0f9..66a3a69 100644
--- a/gcc/rust/expand/rust-macro-invoc-lexer.cc
+++ b/gcc/rust/expand/rust-macro-invoc-lexer.cc
@@ -1,4 +1,5 @@
#include "rust-macro-invoc-lexer.h"
+#include "rust-token.h"
namespace Rust {
@@ -19,12 +20,22 @@ MacroInvocLexer::skip_token (int n)
}
void
-MacroInvocLexer::split_current_token (TokenId new_left __attribute__ ((unused)),
- TokenId new_right
- __attribute__ ((unused)))
+MacroInvocLexer::split_current_token (TokenId new_left, TokenId new_right)
{
- // FIXME
- gcc_unreachable ();
+ auto &current_token = token_stream.at (offs);
+ auto current_pos = token_stream.begin () + offs;
+
+ auto l_tok = Token::make (new_left, current_token->get_locus ());
+ auto r_tok = Token::make (new_right, current_token->get_locus ());
+
+ token_stream.erase (current_pos);
+
+ // `insert` inserts before the specified position, so we insert the right one
+ // then the left
+ token_stream.insert (current_pos,
+ std::unique_ptr<AST::Token> (new AST::Token (r_tok)));
+ token_stream.insert (current_pos,
+ std::unique_ptr<AST::Token> (new AST::Token (l_tok)));
}
std::vector<std::unique_ptr<AST::Token>>