diff options
Diffstat (limited to 'gcc/rust/resolve/rust-name-resolution-context.h')
-rw-r--r-- | gcc/rust/resolve/rust-name-resolution-context.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index 3605392..2fc8528 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -22,6 +22,7 @@ #include "optional.h" #include "rust-forever-stack.h" #include "rust-hir-map.h" +#include "rust-rib.h" namespace Rust { namespace Resolver2_0 { @@ -198,6 +199,32 @@ public: std::function<void (void)> lambda, tl::optional<Identifier> path = {}); + template <typename P> + tl::optional<std::pair<Rib::Definition, Namespace>> + resolve_path (const P &path) + { + const auto &segments = path.get_segments (); + + // Pair a definition with the namespace it was found in + auto pair_with_ns = [] (Namespace ns) { + return [ns] (Rib::Definition def) { return std::make_pair (def, ns); }; + }; + + // We first check in values, if not found then types, if not found then + // macros. There should not be any ambiguity at this point - this function + // will short circuit and return the first definition it has found. + return values.resolve_path (segments) + .map (pair_with_ns (Namespace::Values)) + .or_else ([&] () { + return types.resolve_path (segments).map ( + pair_with_ns (Namespace::Types)); + }) + .or_else ([&] () { + return macros.resolve_path (segments).map ( + pair_with_ns (Namespace::Macros)); + }); + } + ForeverStack<Namespace::Values> values; ForeverStack<Namespace::Types> types; ForeverStack<Namespace::Macros> macros; |