[committed,070/103] gccrs: add Location to AST::Visibility

Message ID 20230221120230.596966-71-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: Add location member.
	* hir/rust-ast-lower.cc (translate_visibility): Pass location argument.
	* hir/tree/rust-hir-item.h: Fix constructor to accept Location argument.
---
 gcc/rust/ast/rust-item.h          | 19 +++++++++++++------
 gcc/rust/hir/rust-ast-lower.cc    |  3 ++-
 gcc/rust/hir/tree/rust-hir-item.h |  6 ++++--
 3 files changed, 19 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index d66dd615319..17d11e4de38 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -625,13 +625,15 @@  private:
   VisType vis_type;
   // Only assigned if vis_type is IN_PATH
   SimplePath in_path;
+  Location locus;
 
   // should this store location info?
 
 public:
   // Creates a Visibility - TODO make constructor protected or private?
-  Visibility (VisType vis_type, SimplePath in_path)
-    : vis_type (vis_type), in_path (std::move (in_path))
+  Visibility (VisType vis_type, SimplePath in_path,
+	      Location locus = Location ())
+    : vis_type (vis_type), in_path (std::move (in_path)), locus (locus)
   {}
 
   VisType get_vis_type () const { return vis_type; }
@@ -648,6 +650,8 @@  public:
   // Returns whether visibility is public or not.
   bool is_public () const { return vis_type != PRIV && !is_error (); }
 
+  Location get_locus () const { return locus; }
+
   // Creates an error visibility.
   static Visibility create_error ()
   {
@@ -672,21 +676,24 @@  public:
   static Visibility create_crate (Location crate_tok_location)
   {
     return Visibility (PUB_CRATE,
-		       SimplePath::from_str ("crate", crate_tok_location));
+		       SimplePath::from_str ("crate", crate_tok_location),
+		       crate_tok_location);
   }
 
   // Creates a public visibility with self-relative paths
   static Visibility create_self (Location self_tok_location)
   {
     return Visibility (PUB_SELF,
-		       SimplePath::from_str ("self", self_tok_location));
+		       SimplePath::from_str ("self", self_tok_location),
+		       self_tok_location);
   }
 
   // Creates a public visibility with parent module-relative paths
   static Visibility create_super (Location super_tok_location)
   {
     return Visibility (PUB_SUPER,
-		       SimplePath::from_str ("super", super_tok_location));
+		       SimplePath::from_str ("super", super_tok_location),
+		       super_tok_location);
   }
 
   // Creates a private visibility
@@ -698,7 +705,7 @@  public:
   // Creates a public visibility with a given path or whatever.
   static Visibility create_in_path (SimplePath in_path)
   {
-    return Visibility (PUB_IN_PATH, std::move (in_path));
+    return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ());
   }
 
   std::string as_string () const;
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index fdf8abe3ed3..2e25be75a5a 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -50,7 +50,8 @@  translate_visibility (const AST::Visibility &vis)
     case AST::Visibility::PUB_SUPER:
     case AST::Visibility::PUB_IN_PATH:
       return Visibility (Visibility::VisType::RESTRICTED,
-			 ASTLoweringSimplePath::translate (vis.get_path ()));
+			 ASTLoweringSimplePath::translate (vis.get_path ()),
+			 vis.get_locus ());
       break;
     }
 
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 7f665159572..f7bf1f879c8 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -571,13 +571,15 @@  public:
 private:
   VisType vis_type;
   HIR::SimplePath path;
+  Location locus;
 
   // should this store location info?
 
 public:
   Visibility (VisType vis_type,
-	      HIR::SimplePath path = HIR::SimplePath::create_empty ())
-    : vis_type (vis_type), path (std::move (path))
+	      HIR::SimplePath path = HIR::SimplePath::create_empty (),
+	      Location locus = Location ())
+    : vis_type (vis_type), path (std::move (path)), locus (locus)
   {}
 
   // Returns whether visibility is in an error state.