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 | 13 +++++++++++++
gcc/rust/resolve/rust-name-resolution-context.h | 3 +++
2 files changed, 16 insertions(+)
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc
b/gcc/rust/resolve/rust-name-resolution-context.cc
index f35db7e925e..9fd8d52968a 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -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,
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h
b/gcc/rust/resolve/rust-name-resolution-context.h
index bc3c4bb5ddb..e896ca05360 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -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 */
--
2.45.2