@@ -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,
@@ -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 */