[committed,091/103] gccrs: Remove default location. Add visibility location to create_* functions

Message ID 20230221120230.596966-92-arthur.cohen@embecosm.com
State Unresolved
Headers
Series [committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Feb. 21, 2023, 12:02 p.m. UTC
  From: Dave <dme2223@gmail.com>

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.
---
 gcc/rust/ast/rust-item.h         | 33 ++++++++++++++++++--------------
 gcc/rust/parse/rust-parse-impl.h | 11 ++++++-----
 2 files changed, 25 insertions(+), 19 deletions(-)
  

Patch

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 96201d668de..7ea7b86562f 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 a4a912f8c1d..ee0282bdab3 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",