public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: Return resolved_node_id when possible
@ 2023-03-21  8:35 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-21  8:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:70b83a23f508d3694aa08cda793bab118a9be768

commit 70b83a23f508d3694aa08cda793bab118a9be768
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Fri Mar 17 22:46:20 2023 +0000

    gccrs: Return resolved_node_id when possible
    
    To enable use statement to export a name to a path such as the prelude
    example: use option::Option::{self, None, Some} we need to get the resolved
    node id of the self, None and Some in order to export the name of None and
    Some to their respective NodeId.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-ast-resolve-path.cc (ResolvePath::ResolvePath): return NodeId
            (ResolvePath::go): update signiture
            (ResolvePath::resolve_path): return resolved_node_id
            * resolve/rust-ast-resolve-path.h: update prototypes
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-path.cc | 38 ++++++++++++++++++-------------
 gcc/rust/resolve/rust-ast-resolve-path.h  | 12 +++++-----
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc
index 702c42c7375..c5b8deaa107 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-path.cc
@@ -25,28 +25,28 @@ namespace Resolver {
 
 ResolvePath::ResolvePath () : ResolverBase () {}
 
-void
+NodeId
 ResolvePath::go (AST::PathInExpression *expr)
 {
   ResolvePath resolver;
-  resolver.resolve_path (expr);
+  return resolver.resolve_path (expr);
 }
 
-void
+NodeId
 ResolvePath::go (AST::QualifiedPathInExpression *expr)
 {
   ResolvePath resolver;
-  resolver.resolve_path (expr);
+  return resolver.resolve_path (expr);
 }
 
-void
+NodeId
 ResolvePath::go (AST::SimplePath *expr)
 {
   ResolvePath resolver;
-  resolver.resolve_path (expr);
+  return resolver.resolve_path (expr);
 }
 
-void
+NodeId
 ResolvePath::resolve_path (AST::PathInExpression *expr)
 {
   NodeId resolved_node_id = UNKNOWN_NODEID;
@@ -68,7 +68,7 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
 			 "failed to resolve: %<%s%> in paths can only be used "
 			 "in start position",
 			 segment.as_string ().c_str ());
-	  return;
+	  return UNKNOWN_NODEID;
 	}
 
       NodeId crate_scope_id = resolver->peek_crate_module_scope ();
@@ -87,7 +87,7 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
 	    {
 	      rust_error_at (segment.get_locus (),
 			     "cannot use %<super%> at the crate scope");
-	      return;
+	      return UNKNOWN_NODEID;
 	    }
 
 	  module_scope_id = resolver->peek_parent_module_scope ();
@@ -191,7 +191,7 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
 		  rust_error_at (segment.get_locus (),
 				 "Cannot find path %<%s%> in this scope",
 				 segment.as_string ().c_str ());
-		  return;
+		  return UNKNOWN_NODEID;
 		}
 	    }
 	}
@@ -211,7 +211,7 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
 	  rust_error_at (segment.get_locus (),
 			 "Cannot find path %<%s%> in this scope",
 			 segment.as_string ().c_str ());
-	  return;
+	  return UNKNOWN_NODEID;
 	}
     }
 
@@ -236,9 +236,10 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
 	  gcc_unreachable ();
 	}
     }
+  return resolved_node_id;
 }
 
-void
+NodeId
 ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr)
 {
   AST::QualifiedPathType &root_segment = expr->get_qualified_path_type ();
@@ -254,9 +255,13 @@ ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr)
       if (segment.has_generic_args ())
 	ResolveGenericArgs::go (segment.get_generic_args ());
     }
+
+  // cannot fully resolve a qualified path as it is dependant on associated
+  // items
+  return UNKNOWN_NODEID;
 }
 
-void
+NodeId
 ResolvePath::resolve_path (AST::SimplePath *expr)
 {
   NodeId crate_scope_id = resolver->peek_crate_module_scope ();
@@ -283,7 +288,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr)
 	    {
 	      rust_error_at (segment.get_locus (),
 			     "cannot use %<super%> at the crate scope");
-	      return;
+	      return UNKNOWN_NODEID;
 	    }
 
 	  module_scope_id = resolver->peek_parent_module_scope ();
@@ -317,7 +322,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr)
 	      rust_error_at (segment.get_locus (),
 			     "Cannot find path %<%s%> in this scope",
 			     segment.as_string ().c_str ());
-	      return;
+	      return UNKNOWN_NODEID;
 	    }
 	}
 
@@ -348,7 +353,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr)
 	  rust_error_at (segment.get_locus (),
 			 "cannot find simple path segment %<%s%> in this scope",
 			 segment.as_string ().c_str ());
-	  return;
+	  return UNKNOWN_NODEID;
 	}
 
       if (mappings->node_is_module (resolved_node_id))
@@ -378,6 +383,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr)
 	  gcc_unreachable ();
 	}
     }
+  return resolved_node_id;
 }
 
 } // namespace Resolver
diff --git a/gcc/rust/resolve/rust-ast-resolve-path.h b/gcc/rust/resolve/rust-ast-resolve-path.h
index 3599fffe4c7..c6d2e1a3304 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.h
+++ b/gcc/rust/resolve/rust-ast-resolve-path.h
@@ -29,16 +29,16 @@ class ResolvePath : public ResolverBase
   using Rust::Resolver::ResolverBase::visit;
 
 public:
-  static void go (AST::PathInExpression *expr);
-  static void go (AST::QualifiedPathInExpression *expr);
-  static void go (AST::SimplePath *expr);
+  static NodeId go (AST::PathInExpression *expr);
+  static NodeId go (AST::QualifiedPathInExpression *expr);
+  static NodeId go (AST::SimplePath *expr);
 
 private:
   ResolvePath ();
 
-  void resolve_path (AST::PathInExpression *expr);
-  void resolve_path (AST::QualifiedPathInExpression *expr);
-  void resolve_path (AST::SimplePath *expr);
+  NodeId resolve_path (AST::PathInExpression *expr);
+  NodeId resolve_path (AST::QualifiedPathInExpression *expr);
+  NodeId resolve_path (AST::SimplePath *expr);
 
   void
   resolve_simple_path_segments (CanonicalPath prefix, size_t offs,

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

only message in thread, other threads:[~2023-03-21  8:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21  8:35 [gcc/devel/rust/master] gccrs: Return resolved_node_id when possible 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).