Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 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-name-resolution-context.h"
20 : :
21 : : namespace Rust {
22 : : namespace Resolver2_0 {
23 : :
24 : 5257 : NameResolutionContext::NameResolutionContext ()
25 : 5257 : : mappings (*Analysis::Mappings::get ())
26 : 5257 : {}
27 : :
28 : : tl::expected<NodeId, DuplicateNameError>
29 : 41 : NameResolutionContext::insert (Identifier name, NodeId id, Namespace ns)
30 : : {
31 : 41 : switch (ns)
32 : : {
33 : 39 : case Namespace::Values:
34 : 39 : return values.insert (name, id);
35 : 0 : case Namespace::Types:
36 : 0 : return types.insert (name, id);
37 : 2 : case Namespace::Macros:
38 : 2 : return macros.insert (name, id);
39 : 0 : case Namespace::Labels:
40 : 0 : default:
41 : : // return labels.insert (name, id);
42 : 0 : rust_unreachable ();
43 : : }
44 : : }
45 : :
46 : : void
47 : 0 : NameResolutionContext::map_usage (NodeId usage, NodeId definition)
48 : : {
49 : 0 : auto inserted = resolved_nodes.emplace (usage, definition).second;
50 : :
51 : : // is that valid?
52 : 0 : rust_assert (inserted);
53 : 0 : }
54 : :
55 : : void
56 : 248 : NameResolutionContext::scoped (Rib rib, NodeId id,
57 : : std::function<void (void)> lambda,
58 : : tl::optional<Identifier> path)
59 : : {
60 : 248 : values.push (rib, id, path);
61 : 248 : types.push (rib, id, path);
62 : 248 : macros.push (rib, id, path);
63 : : // labels.push (rib, id);
64 : :
65 : 248 : lambda ();
66 : :
67 : 248 : values.pop ();
68 : 248 : types.pop ();
69 : 248 : macros.pop ();
70 : : // labels.pop (rib);
71 : 248 : }
72 : :
73 : : void
74 : 0 : NameResolutionContext::scoped (Rib rib, Namespace ns, NodeId scope_id,
75 : : std::function<void (void)> lambda,
76 : : tl::optional<Identifier> path)
77 : : {
78 : 0 : switch (ns)
79 : : {
80 : 0 : case Namespace::Values:
81 : 0 : values.push (rib, scope_id, path);
82 : 0 : break;
83 : 0 : case Namespace::Types:
84 : 0 : types.push (rib, scope_id, path);
85 : 0 : break;
86 : 0 : case Namespace::Labels:
87 : 0 : case Namespace::Macros:
88 : 0 : gcc_unreachable ();
89 : : }
90 : :
91 : 0 : lambda ();
92 : :
93 : 0 : switch (ns)
94 : : {
95 : 0 : case Namespace::Values:
96 : 0 : values.pop ();
97 : 0 : break;
98 : 0 : case Namespace::Types:
99 : 0 : types.pop ();
100 : 0 : break;
101 : : case Namespace::Labels:
102 : : case Namespace::Macros:
103 : : gcc_unreachable ();
104 : : }
105 : 0 : }
106 : :
107 : : } // namespace Resolver2_0
108 : : } // namespace Rust
|