public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Remove default location. Add visibility location to create_* functions
@ 2022-11-18 23:34 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-11-18 23:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bea720bef773efce55391ef005b7be990b9bfc50

commit bea720bef773efce55391ef005b7be990b9bfc50
Author: Dave <dme2223@gmail.com>
Date:   Wed Nov 16 17:06:44 2022 -0600

    Remove default location. Add visibility location to create_* functions

Diff:
---
 gcc/rust/ast/rust-item.h         | 33 +++++++++++++++++++--------------
 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 2ba3cf5ef47..ab772ce9737 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -631,8 +631,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)
   {}
 
@@ -652,10 +651,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
@@ -667,45 +667,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 54f3c5c25a6..5642990c14b 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -2128,12 +2128,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
     }
 
@@ -2149,19 +2150,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 ();
 
@@ -2179,7 +2180,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",

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-18 23:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 23:34 [gcc/devel/rust/master] Remove default location. Add visibility location to create_* functions Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).