From 53756e1a01c7ac93e8467f577f50c491ca4b2525 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Sat, 7 Aug 2021 13:15:18 +0200 Subject: lexer: Add function to get original filename When parsing an external module, it is important to be able to access the original "including" file in order to resolve the path of the desired module. Take the following example ```rust // /project/src/foo.rs mod bar; /* External module */ ``` The file which contains the `bar` module could be located at `/project/src/bar.rs`, or at `/project/src/foo/bar.rs` (careful, this isn't an exhaustive list of all possible cases). We must therefore be able to access the `/project/src` directory in order to find valid candidates for `mod bar` --- gcc/rust/parse/rust-parse-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/rust/parse') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c94c637..0e50168 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2103,8 +2103,8 @@ Parser::parse_module (AST::Visibility vis, return std::unique_ptr ( new AST::Module (std::move (name), std::move (vis), - std::move (outer_attrs), - locus)); // module name? + std::move (outer_attrs), locus, + lexer.get_filename ())); case LEFT_CURLY: { lexer.skip_token (); -- cgit v1.1 From b4993a629348279023b2c0159169ed62f10ac453 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Fri, 6 Aug 2021 23:49:47 +0200 Subject: module: Add basic filename discovery --- gcc/rust/parse/rust-parse-impl.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/rust/parse') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 0e50168..731e0b3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2101,6 +2101,7 @@ Parser::parse_module (AST::Visibility vis, case SEMICOLON: lexer.skip_token (); + // Construct an external module return std::unique_ptr ( new AST::Module (std::move (name), std::move (vis), std::move (outer_attrs), locus, -- cgit v1.1