Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-finalized-name-resolution-context.h"
20 : #include "expected.h"
21 : #include "optional.h"
22 : #include "rust-forever-stack.h"
23 :
24 : namespace Rust {
25 : namespace Resolver2_0 {
26 :
27 : static FinalizedNameResolutionContext *instance = nullptr;
28 :
29 : const FinalizedNameResolutionContext &
30 4538 : FinalizedNameResolutionContext::init (NameResolutionContext &ctx)
31 : {
32 4538 : rust_assert (!instance);
33 :
34 4538 : instance = new FinalizedNameResolutionContext (ctx);
35 :
36 4538 : return *instance;
37 : }
38 :
39 : FinalizedNameResolutionContext &
40 2998838 : FinalizedNameResolutionContext::get ()
41 : {
42 2998838 : rust_assert (instance);
43 :
44 2998838 : return *instance;
45 : }
46 :
47 : void
48 5854 : FinalizedNameResolutionContext::map_usage (Usage usage, Definition definition,
49 : Namespace ns)
50 : {
51 5854 : tl::expected<Definition, LookupFinalizeError> leaf_result
52 5854 : = tl::make_unexpected (LookupFinalizeError::NoDefinition);
53 :
54 5854 : switch (ns)
55 : {
56 4533 : case Namespace::Values:
57 4533 : leaf_result = ctx.values.find_leaf_definition (definition.id);
58 4533 : break;
59 1321 : case Namespace::Types:
60 1321 : leaf_result = ctx.types.find_leaf_definition (definition.id);
61 1321 : break;
62 0 : case Namespace::Labels:
63 0 : leaf_result = ctx.labels.find_leaf_definition (definition.id);
64 0 : break;
65 0 : case Namespace::Macros:
66 0 : leaf_result = ctx.macros.find_leaf_definition (definition.id);
67 0 : break;
68 : }
69 :
70 5854 : ctx.map_usage (usage, leaf_result.value_or (definition), ns);
71 5854 : }
72 :
73 : tl::optional<NodeId>
74 2935699 : FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns) const
75 : {
76 2935699 : return ctx.lookup (usage, ns);
77 : }
78 :
79 : tl::optional<NameResolutionContext::NSLookup>
80 188868 : FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns1,
81 : Namespace ns2) const
82 : {
83 188868 : return ctx.lookup (usage, ns1, ns2);
84 : }
85 :
86 : tl::optional<NameResolutionContext::NSLookup>
87 0 : FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns1,
88 : Namespace ns2, Namespace ns3) const
89 : {
90 0 : return ctx.lookup (usage, ns1, ns2, ns3);
91 : }
92 :
93 : Resolver::CanonicalPath
94 60392 : FinalizedNameResolutionContext::to_canonical_path (NodeId id,
95 : Namespace ns) const
96 : {
97 60392 : return ctx.canonical_ctx.get_path (id, ns);
98 : }
99 :
100 4538 : FinalizedNameResolutionContext::FinalizedNameResolutionContext (
101 4538 : NameResolutionContext &ctx)
102 4538 : : ctx (ctx)
103 4538 : {}
104 :
105 : } // namespace Resolver2_0
106 : } // namespace Rust
|