diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-28 09:47:41 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-28 09:47:41 +0200 |
commit | b4fa67403f3f5f5579e30e03102ca56c4ed6f049 (patch) | |
tree | 1bfdec255eaae4cfd70fa0df4402d2641b5b7651 | |
parent | 9a9bb44058a8406b41bb1ab3110e08a897772bb0 (diff) | |
download | gcc-b4fa67403f3f5f5579e30e03102ca56c4ed6f049.zip gcc-b4fa67403f3f5f5579e30e03102ca56c4ed6f049.tar.gz gcc-b4fa67403f3f5f5579e30e03102ca56c4ed6f049.tar.bz2 |
parse: Add correct location to all public visibilities
-rw-r--r-- | gcc/rust/ast/rust-item.h | 22 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 6 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 7 |
3 files changed, 16 insertions, 19 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 5907516..5d1e0d6 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -666,23 +666,25 @@ public: return Visibility (PUB, SimplePath::create_empty ()); } - // Creates a public visibility with crate-relative paths or whatever. - static Visibility create_crate () + // Creates a public visibility with crate-relative paths + static Visibility create_crate (Location crate_tok_location) { - return Visibility (PUB_CRATE, SimplePath::create_empty ()); + return Visibility (PUB_CRATE, + SimplePath::from_str ("crate", crate_tok_location)); } - // Creates a public visibility with self-relative paths or whatever. - static Visibility create_self () + // Creates a public visibility with self-relative paths + static Visibility create_self (Location self_tok_location) { - return Visibility (PUB_SELF, SimplePath::create_empty ()); + return Visibility (PUB_SELF, + SimplePath::from_str ("self", self_tok_location)); } - // Creates a public visibility with parent module-relative paths or - // whatever. - static Visibility create_super () + // Creates a public visibility with parent module-relative paths + static Visibility create_super (Location super_tok_location) { - return Visibility (PUB_SUPER, SimplePath::create_empty ()); + return Visibility (PUB_SUPER, + SimplePath::from_str ("super", super_tok_location)); } // Creates a private visibility diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 630eded..bc613e1 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -43,14 +43,8 @@ translate_visibility (const AST::Visibility &vis) case AST::Visibility::PRIV: case AST::Visibility::PUB_SELF: return Visibility (Visibility::VisType::PRIVATE); - // Desugar pub(crate) into pub(in crate) and so on - // FIXME: How do we get a location for the SimplePath here? case AST::Visibility::PUB_CRATE: - return Visibility (Visibility::PUBLIC, - AST::SimplePath::from_str ("crate", Location ())); case AST::Visibility::PUB_SUPER: - return Visibility (Visibility::PUBLIC, - AST::SimplePath::from_str ("super", Location ())); case AST::Visibility::PUB_IN_PATH: return Visibility (Visibility::VisType::PUBLIC, vis.get_path ()); break; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6715a77..23ab32c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2136,6 +2136,7 @@ Parser<ManagedTokenSource>::parse_visibility () lexer.skip_token (); const_TokenPtr t = lexer.peek_token (); + auto path_loc = t->get_locus (); switch (t->get_id ()) { @@ -2144,19 +2145,19 @@ Parser<ManagedTokenSource>::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_crate (); + return AST::Visibility::create_crate (path_loc); case SELF: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_self (); + return AST::Visibility::create_self (path_loc); case SUPER: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_super (); + return AST::Visibility::create_super (path_loc); case IN: { lexer.skip_token (); |