From ec5da37dbfbcc55183f7ea4658c8856b9335ad61 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 5 Jul 2022 16:56:14 +0100 Subject: Refactor Lexer to support an abstract InputSource class This patch allows us to remove the fmemopen lex_string hack to support parsing buffers. This will allow us to support mutliple sources such as metadata imports etc. The patch here updates the parser to hold onto a reference to the lexer rather than 'owning' the lexer which allows us to decouple the move semantics here. Fixes #1203 #1000 --- gcc/rust/parse/rust-cfg-parser.cc | 4 ++-- gcc/rust/parse/rust-parse.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gcc/rust/parse') diff --git a/gcc/rust/parse/rust-cfg-parser.cc b/gcc/rust/parse/rust-cfg-parser.cc index f98419b..00693c4 100644 --- a/gcc/rust/parse/rust-cfg-parser.cc +++ b/gcc/rust/parse/rust-cfg-parser.cc @@ -11,8 +11,8 @@ parse_cfg_option (std::string &input, std::string &key, std::string &value) key.clear (); value.clear (); - auto lexer = Lexer::lex_string (input); - auto parser = Parser (std::move (lexer)); + auto lexer = Lexer (input); + auto parser = Parser (lexer); auto token = parser.peek_current_token (); if (token->get_id () != IDENTIFIER) diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index fa88f8e..d799a56 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -662,7 +662,7 @@ private: public: // Construct parser with specified "managed" token source. - Parser (ManagedTokenSource tokenSource) : lexer (std::move (tokenSource)) {} + Parser (ManagedTokenSource &tokenSource) : lexer (tokenSource) {} // Parse items without parsing an entire crate. This function is the main // parsing loop of AST::Crate::parse_crate(). @@ -689,7 +689,7 @@ public: private: // The token source (usually lexer) associated with the parser. - ManagedTokenSource lexer; + ManagedTokenSource &lexer; // The error list. std::vector error_table; // The names of inline modules while parsing. -- cgit v1.1