]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr2.0: Add lookup of resolved nodes.
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 24 Aug 2023 15:51:11 +0000 (17:51 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 14:52:24 +0000 (16:52 +0200)
gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup):
Add lookup function.
* resolve/rust-name-resolution-context.h: Include mappings and optional.

gcc/rust/resolve/rust-name-resolution-context.cc
gcc/rust/resolve/rust-name-resolution-context.h

index f35db7e925e59322286420da9d4ef25b6266bcb4..9fd8d52968a8d1c98eeedfd02b569c49531bca28 100644 (file)
@@ -17,6 +17,8 @@
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-name-resolution-context.h"
+#include "optional.h"
+#include "rust-mapping-common.h"
 
 namespace Rust {
 namespace Resolver2_0 {
@@ -52,6 +54,17 @@ NameResolutionContext::map_usage (NodeId usage, NodeId definition)
   rust_assert (inserted);
 }
 
+tl::optional<NodeId>
+NameResolutionContext::lookup (NodeId usage)
+{
+  auto it = resolved_nodes.find (usage);
+
+  if (it == resolved_nodes.end ())
+    return tl::nullopt;
+
+  return it->second;
+}
+
 void
 NameResolutionContext::scoped (Rib rib, NodeId id,
                               std::function<void (void)> lambda,
index bc3c4bb5ddb71b8ee6a22888fd5d259473e6670d..e896ca0536086fa6a2799ec0102d4c63574320c9 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef RUST_NAME_RESOLVER_2_0_H
 #define RUST_NAME_RESOLVER_2_0_H
 
+#include "optional.h"
 #include "rust-forever-stack.h"
 #include "rust-hir-map.h"
 
@@ -180,7 +181,9 @@ public:
   Analysis::Mappings &mappings;
 
   // TODO: Rename
+  // TODO: Use newtype pattern for Usage and Definition
   void map_usage (NodeId usage, NodeId definition);
+  tl::optional<NodeId> lookup (NodeId usage);
 
 private:
   /* Map of "usage" nodes which have been resolved to a "definition" node */