diff options
author | Dave <dme2223@gmail.com> | 2022-11-16 17:06:44 -0600 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-02-21 12:36:51 +0100 |
commit | 78c70a50f7441d909f9cc3f23c6e970a1d7f1612 (patch) | |
tree | fb0bb901e7f3621258cac08fdd4c5e2b8a0dc2ee | |
parent | 567494f7030b45e79b33ab38ba769826e370280e (diff) | |
download | gcc-78c70a50f7441d909f9cc3f23c6e970a1d7f1612.zip gcc-78c70a50f7441d909f9cc3f23c6e970a1d7f1612.tar.gz gcc-78c70a50f7441d909f9cc3f23c6e970a1d7f1612.tar.bz2 |
gccrs: Remove default location. Add visibility location to create_* functions
gcc/rust/ChangeLog:
* ast/rust-item.h: Remoe default location for Visibility class.
* parse/rust-parse-impl.h (Parser::parse_visibility): Pass proper location
when instantiating visibilities.
-rw-r--r-- | gcc/rust/ast/rust-item.h | 33 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 11 |
2 files changed, 25 insertions, 19 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 96201d6..7ea7b86 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -633,8 +633,7 @@ private: public: // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path, - Location locus = Location ()) + Visibility (VisType vis_type, SimplePath in_path, Location locus) : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) {} @@ -654,10 +653,11 @@ public: Location get_locus () const { return locus; } + // empty? // Creates an error visibility. static Visibility create_error () { - return Visibility (PUB_IN_PATH, SimplePath::create_empty ()); + return Visibility (PUB_IN_PATH, SimplePath::create_empty (), Location ()); } // Unique pointer custom clone function @@ -669,45 +669,50 @@ public: * is one idea but may be too resource-intensive. */ // Creates a public visibility with no further features/arguments. - static Visibility create_public () + // empty? + static Visibility create_public (Location pub_vis_location) { - return Visibility (PUB, SimplePath::create_empty ()); + return Visibility (PUB, SimplePath::create_empty (), pub_vis_location); } // Creates a public visibility with crate-relative paths - static Visibility create_crate (Location crate_tok_location) + static Visibility create_crate (Location crate_tok_location, + Location crate_vis_location) { return Visibility (PUB_CRATE, SimplePath::from_str ("crate", crate_tok_location), - crate_tok_location); + crate_vis_location); } // Creates a public visibility with self-relative paths - static Visibility create_self (Location self_tok_location) + static Visibility create_self (Location self_tok_location, + Location self_vis_location) { return Visibility (PUB_SELF, SimplePath::from_str ("self", self_tok_location), - self_tok_location); + self_vis_location); } // Creates a public visibility with parent module-relative paths - static Visibility create_super (Location super_tok_location) + static Visibility create_super (Location super_tok_location, + Location super_vis_location) { return Visibility (PUB_SUPER, SimplePath::from_str ("super", super_tok_location), - super_tok_location); + super_vis_location); } // Creates a private visibility static Visibility create_private () { - return Visibility (PRIV, SimplePath::create_empty ()); + return Visibility (PRIV, SimplePath::create_empty (), Location ()); } // Creates a public visibility with a given path or whatever. - static Visibility create_in_path (SimplePath in_path) + static Visibility create_in_path (SimplePath in_path, + Location in_path_vis_location) { - return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ()); + return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location); } std::string as_string () const; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a4a912f..ee0282b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2137,12 +2137,13 @@ Parser<ManagedTokenSource>::parse_visibility () return AST::Visibility::create_private (); } + auto vis_loc = lexer.peek_token ()->get_locus (); lexer.skip_token (); // create simple pub visibility if no parentheses if (lexer.peek_token ()->get_id () != LEFT_PAREN) { - return AST::Visibility::create_public (); + return AST::Visibility::create_public (vis_loc); // or whatever } @@ -2158,19 +2159,19 @@ Parser<ManagedTokenSource>::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_crate (path_loc); + return AST::Visibility::create_crate (path_loc, vis_loc); case SELF: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_self (path_loc); + return AST::Visibility::create_self (path_loc, vis_loc); case SUPER: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_super (path_loc); + return AST::Visibility::create_super (path_loc, vis_loc); case IN: { lexer.skip_token (); @@ -2188,7 +2189,7 @@ Parser<ManagedTokenSource>::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_in_path (std::move (path)); + return AST::Visibility::create_in_path (std::move (path), vis_loc); } default: add_error (Error (t->get_locus (), "unexpected token %qs in visibility", |