From: Arthur Cohen <[email protected]>

Which enables looking up resolved nodes in three different namespaces.
This is used in select cases but still important.

gcc/rust/ChangeLog:

        * resolve/rust-finalized-name-resolution-context.cc
        (FinalizedNameResolutionContext::lookup): New function.
        * resolve/rust-finalized-name-resolution-context.h: Declare it.
        * resolve/rust-name-resolution-context.cc 
(NameResolutionContext::lookup): New function.
        * resolve/rust-name-resolution-context.h: Declare it.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/b1c00d7d5227564f389dd0c03a61d8a34d16854a

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4551

 .../rust-finalized-name-resolution-context.cc        |  7 +++++++
 .../resolve/rust-finalized-name-resolution-context.h |  2 ++
 gcc/rust/resolve/rust-name-resolution-context.cc     | 12 ++++++++++++
 gcc/rust/resolve/rust-name-resolution-context.h      |  2 ++
 4 files changed, 23 insertions(+)

diff --git a/gcc/rust/resolve/rust-finalized-name-resolution-context.cc 
b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc
index 71d1269f3..8e6600a49 100644
--- a/gcc/rust/resolve/rust-finalized-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc
@@ -83,6 +83,13 @@ FinalizedNameResolutionContext::lookup (NodeId usage, 
Namespace ns1,
   return ctx.lookup (usage, ns1, ns2);
 }
 
+tl::optional<NameResolutionContext::NSLookup>
+FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns1,
+                                       Namespace ns2, Namespace ns3) const
+{
+  return ctx.lookup (usage, ns1, ns2, ns3);
+}
+
 Resolver::CanonicalPath
 FinalizedNameResolutionContext::to_canonical_path (NodeId id,
                                                   Namespace ns) const
diff --git a/gcc/rust/resolve/rust-finalized-name-resolution-context.h 
b/gcc/rust/resolve/rust-finalized-name-resolution-context.h
index 5f3354936..3bfba3bc0 100644
--- a/gcc/rust/resolve/rust-finalized-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.h
@@ -71,6 +71,8 @@ public:
   tl::optional<NodeId> lookup (NodeId usage, Namespace ns) const;
   tl::optional<NameResolutionContext::NSLookup>
   lookup (NodeId usage, Namespace ns1, Namespace ns2) const;
+  tl::optional<NameResolutionContext::NSLookup>
+  lookup (NodeId usage, Namespace ns1, Namespace ns2, Namespace ns3) const;
 
   /**
    * Same as NameResolutionContext::to_canonical_path
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc 
b/gcc/rust/resolve/rust-name-resolution-context.cc
index 7bb74b7e5..e05c1c665 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -315,6 +315,18 @@ NameResolutionContext::lookup (NodeId usage, Namespace 
ns1, Namespace ns2) const
   });
 }
 
+tl::optional<NameResolutionContext::NSLookup>
+NameResolutionContext::lookup (NodeId usage, Namespace ns1, Namespace ns2,
+                              Namespace ns3) const
+{
+  if (auto result = lookup (usage, ns1, ns2))
+    return result;
+
+  return lookup (usage, ns3).map ([&ns3] (NodeId id) {
+    return NSLookup (id, ns3);
+  });
+}
+
 void
 NameResolutionContext::scoped (Rib::Kind rib_kind, 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 779f6a725..6cbcfbb76 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -553,6 +553,8 @@ public:
    */
   tl::optional<NSLookup> lookup (NodeId usage, Namespace ns1,
                                 Namespace ns2) const;
+  tl::optional<NSLookup> lookup (NodeId usage, Namespace ns1, Namespace ns2,
+                                Namespace ns3) const;
 
   Resolver::CanonicalPath to_canonical_path (NodeId id, Namespace ns) const
   {
-- 
2.54.0

Reply via email to