public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] path-id: Add location info on path identifier
@ 2022-06-08 12:08 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:08 UTC (permalink / raw)
  To: gcc-cvs

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

commit ef06769781a76eaa0de6fb500bebb8473e549f7e
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu Feb 17 16:14:01 2022 +0100

    path-id: Add location info on path identifier

Diff:
---
 gcc/rust/ast/rust-path.h             | 20 +++++++++++---------
 gcc/rust/parse/rust-parse-impl.h     | 18 ++++++++++--------
 gcc/rust/resolve/rust-ast-resolve.cc |  2 +-
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index e062dc6b7ac..cff3b09d994 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -33,13 +33,12 @@ namespace AST {
 class PathIdentSegment
 {
   std::string segment_name;
-
-  // TODO: should this have location info stored?
+  Location locus;
 
   // only allow identifiers, "super", "self", "Self", "crate", or "$crate"
 public:
-  PathIdentSegment (std::string segment_name)
-    : segment_name (std::move (segment_name))
+  PathIdentSegment (std::string segment_name, Location locus)
+    : segment_name (std::move (segment_name)), locus (locus)
   {}
 
   /* TODO: insert check in constructor for this? Or is this a semantic error
@@ -49,7 +48,10 @@ public:
    * not entirely sure */
 
   // Creates an error PathIdentSegment.
-  static PathIdentSegment create_error () { return PathIdentSegment (""); }
+  static PathIdentSegment create_error ()
+  {
+    return PathIdentSegment ("", Location ());
+  }
 
   // Returns whether PathIdentSegment is in an error state.
   bool is_error () const { return segment_name.empty (); }
@@ -221,7 +223,7 @@ public:
   bool has_generic_args () const { return generic_args.has_generic_args (); }
 
   // Constructor for segment (from IdentSegment and GenericArgs)
-  PathExprSegment (PathIdentSegment segment_name, Location locus = Location (),
+  PathExprSegment (PathIdentSegment segment_name, Location locus,
 		   GenericArgs generic_args = GenericArgs::create_empty ())
     : segment_name (std::move (segment_name)),
       generic_args (std::move (generic_args)), locus (locus),
@@ -237,7 +239,7 @@ public:
 		   = std::vector<std::unique_ptr<Type> > (),
 		   std::vector<GenericArgsBinding> binding_args
 		   = std::vector<GenericArgsBinding> ())
-    : segment_name (PathIdentSegment (std::move (segment_name))),
+    : segment_name (PathIdentSegment (std::move (segment_name), locus)),
       generic_args (GenericArgs (std::move (lifetime_args),
 				 std::move (type_args),
 				 std::move (binding_args))),
@@ -250,7 +252,7 @@ public:
   // Creates an error-state path expression segment.
   static PathExprSegment create_error ()
   {
-    return PathExprSegment (PathIdentSegment::create_error ());
+    return PathExprSegment (PathIdentSegment::create_error (), Location ());
   }
 
   std::string as_string () const;
@@ -440,7 +442,7 @@ public:
 
   TypePathSegment (std::string segment_name,
 		   bool has_separating_scope_resolution, Location locus)
-    : ident_segment (PathIdentSegment (std::move (segment_name))),
+    : ident_segment (PathIdentSegment (std::move (segment_name), locus)),
       locus (locus),
       has_separating_scope_resolution (has_separating_scope_resolution),
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 6498f3cbb77..3ff122977fd 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -706,29 +706,29 @@ Parser<ManagedTokenSource>::parse_path_ident_segment ()
     case IDENTIFIER:
       lexer.skip_token ();
 
-      return AST::PathIdentSegment (t->get_str ());
+      return AST::PathIdentSegment (t->get_str (), t->get_locus ());
     case SUPER:
       lexer.skip_token ();
 
-      return AST::PathIdentSegment ("super");
+      return AST::PathIdentSegment ("super", t->get_locus ());
     case SELF:
       lexer.skip_token ();
 
-      return AST::PathIdentSegment ("self");
+      return AST::PathIdentSegment ("self", t->get_locus ());
     case SELF_ALIAS:
       lexer.skip_token ();
 
-      return AST::PathIdentSegment ("Self");
+      return AST::PathIdentSegment ("Self", t->get_locus ());
     case CRATE:
       lexer.skip_token ();
 
-      return AST::PathIdentSegment ("crate");
+      return AST::PathIdentSegment ("crate", t->get_locus ());
     case DOLLAR_SIGN:
       if (lexer.peek_token (1)->get_id () == CRATE)
 	{
 	  lexer.skip_token (1);
 
-	  return AST::PathIdentSegment ("$crate");
+	  return AST::PathIdentSegment ("$crate", t->get_locus ());
 	}
       gcc_fallthrough ();
     default:
@@ -14613,8 +14613,10 @@ Parser<ManagedTokenSource>::parse_path_in_expression_pratt (const_TokenPtr tok)
 
       AST::GenericArgs generic_args = parse_path_generic_args ();
 
-      initial_segment = AST::PathExprSegment (initial_str, tok->get_locus (),
-					      std::move (generic_args));
+      initial_segment
+	= AST::PathExprSegment (AST::PathIdentSegment (initial_str,
+						       tok->get_locus ()),
+				tok->get_locus (), std::move (generic_args));
     }
   if (initial_segment.is_error ())
     {
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index 5ac076a1fb9..3fb8b41d053 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -26,7 +26,7 @@
 #define MKBUILTIN_TYPE(_X, _R, _TY)                                            \
   do                                                                           \
     {                                                                          \
-      AST::PathIdentSegment seg (_X);                                          \
+      AST::PathIdentSegment seg (_X, Linemap::predeclared_location ());        \
       auto typePath = ::std::unique_ptr<AST::TypePathSegment> (                \
 	new AST::TypePathSegment (::std::move (seg), false,                    \
 				  Linemap::predeclared_location ()));          \


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

only message in thread, other threads:[~2022-06-08 12:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:08 [gcc/devel/rust/master] path-id: Add location info on path identifier 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).