From: Arthur Cohen Date: Thu, 24 Aug 2023 15:51:11 +0000 (+0200) Subject: nr2.0: Add lookup of resolved nodes. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77a6a631b4b2421d0a7b7b8753b9d677ec611104;p=thirdparty%2Fgcc.git nr2.0: Add lookup of resolved nodes. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup): Add lookup function. * resolve/rust-name-resolution-context.h: Include mappings and optional. --- diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index f35db7e925e5..9fd8d52968a8 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -17,6 +17,8 @@ // . #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 +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 lambda, diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index bc3c4bb5ddb7..e896ca053608 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 lookup (NodeId usage); private: /* Map of "usage" nodes which have been resolved to a "definition" node */