Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Compiler_Module_Name_Resolver.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
42#ifndef COMPILER_MODULE_NAME_RESOLVER_H
43#define COMPILER_MODULE_NAME_RESOLVER_H
44
45#include <string>
46#include <string_view>
47
50
51namespace Aleph {
54{
55 Any,
56 Value,
58 Global,
59 Type
60};
61
71
88
91{
92 switch (filter)
93 {
95 return "Any";
97 return "Value";
99 return "Function";
101 return "Global";
103 return "Type";
104 }
105
106 return "Unknown";
107}
108
111 const Compiler_Module_Name_Resolution_Status status) noexcept
112{
113 switch (status)
114 {
116 return "Resolved";
118 return "Missing_Module";
120 return "Missing_Name";
122 return "Wrong_Kind";
124 return "Ambiguous_Name";
125 }
126
127 return "Unknown";
128}
129
130namespace Compiler_Module_Name_Resolver_Detail {
132 const Compiler_Module_Name_Filter filter) noexcept
133{
134 switch (filter)
135 {
137 return true;
139 return binding.kind != Compiler_Module_Export_Kind::Type;
141 return binding.kind == Compiler_Module_Export_Kind::Function;
143 return binding.kind == Compiler_Module_Export_Kind::Global;
145 return binding.kind == Compiler_Module_Export_Kind::Type;
146 }
147
148 return false;
149}
150
152 const std::string_view module_name,
153 const std::string_view symbol_name,
154 const Compiler_Module_Name_Filter filter) noexcept
155{
156 if (issue.module_name != module_name)
157 return false;
158 if (issue.symbol_name != symbol_name)
159 return false;
160
166 return false;
167}
168} // namespace Compiler_Module_Name_Resolver_Detail
169
179 const Compiler_Module_Binding_Result &bindings,
180 const std::string_view module_name,
181 const std::string_view symbol_name,
183{
185 result.module_name = std::string(module_name);
186 result.symbol_name = std::string(symbol_name);
187 result.filter = filter;
188
189 const Compiler_Module_Bindings *bound_module = nullptr;
190 for (size_t i = 0; i < bindings.modules.size(); ++i)
191 if (bindings.modules.access(i).module_name == module_name)
192 {
193 bound_module = &bindings.modules.access(i);
194 break;
195 }
196
197 if (bound_module == nullptr)
198 {
200 return result;
201 }
202
203 bool found_wrong_kind = false;
204 for (size_t i = 0; i < bound_module->names.size(); ++i)
205 {
206 const auto &current = bound_module->names.access(i);
207 if (current.name != symbol_name)
208 continue;
209
211 {
213 result.binding = current;
214 return result;
215 }
216
217 result.binding = current;
218 found_wrong_kind = true;
219 }
220
221 for (size_t i = 0; i < bindings.issues.size(); ++i)
223 bindings.issues.access(i), module_name, symbol_name, filter))
224 {
226 return result;
227 }
228
231 return result;
232}
233
243 const Compiler_Module_Name_Table &table,
244 const std::string_view module_name,
245 const std::string_view symbol_name,
247{
249 result.module_name = std::string(module_name);
250 result.symbol_name = std::string(symbol_name);
251 result.filter = filter;
252
254 for (size_t i = 0; i < table.modules.size(); ++i)
255 if (table.modules.access(i).module_name == module_name)
256 {
257 bound_module = &table.modules.access(i);
258 break;
259 }
260
261 if (bound_module == nullptr)
262 {
264 return result;
265 }
266
267 bool found_wrong_kind = false;
268 for (size_t i = 0; i < bound_module->names.size(); ++i)
269 {
270 const auto &current = bound_module->names.access(i);
271 if (current.name != symbol_name)
272 continue;
273
275 {
277 result.binding = current;
278 return result;
279 }
280
281 result.binding = current;
282 found_wrong_kind = true;
283 }
284
285 for (size_t i = 0; i < bound_module->ambiguous_names.size(); ++i)
286 {
287 const auto &current = bound_module->ambiguous_names.access(i);
288 if (current.name != symbol_name)
289 continue;
290
292 and current.namespace_kind == Compiler_Module_Export_Kind::Type)
293 {
295 return result;
296 }
297
301 and current.namespace_kind != Compiler_Module_Export_Kind::Type)
302 {
304 return result;
305 }
306 }
307
310 return result;
311}
312} // namespace Aleph
313
314#endif
Reusable binding helpers for linked module surfaces.
Reusable per-module cache for top-level name resolution.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
bool issue_matches_query(const Compiler_Module_Binding_Issue &issue, const std::string_view module_name, const std::string_view symbol_name, const Compiler_Module_Name_Filter filter) noexcept
bool matches_filter(const Compiler_Module_Bound_Name &binding, const Compiler_Module_Name_Filter filter) noexcept
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Compiler_Module_Name_Resolution_Status
Result status for one module-name query.
@ Value
Regular runtime payload stored as Interpreter_Value.
const char * compiler_module_name_filter_name(const Compiler_Module_Name_Filter filter) noexcept
Returns the stable debug name for one module-name filter.
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
and
Check uniqueness with explicit hash + equality functors.
const char * compiler_module_name_resolution_status_name(const Compiler_Module_Name_Resolution_Status status) noexcept
Returns the stable debug name for one module-name resolution status.
Compiler_Module_Name_Resolution compiler_resolve_module_name(const Compiler_Module_Binding_Result &bindings, const std::string_view module_name, const std::string_view symbol_name, const Compiler_Module_Name_Filter filter=Compiler_Module_Name_Filter::Any)
Resolves one top-level name through reusable per-module bindings.
Compiler_Module_Name_Filter
Query filters supported by reusable module-name resolution.
@ Function
Function type such as fn(Int) -> Bool.
One structural issue reported by the reusable module binder.
Binding result over one linked module-surface view.
DynArray< Compiler_Module_Bindings > modules
DynArray< Compiler_Module_Binding_Issue > issues
Bound top-level names visible from one module.
One top-level name successfully bound in a module namespace.
Structured result returned by reusable module-name resolution.
Compiler_Module_Name_Resolution_Status status
bool ok() const noexcept
Returns whether the query resolved to one concrete bound name.
Cached top-level names for one module.
Cached top-level name table over all visible modules.
DynArray< Compiler_Module_Name_Table_Entry > modules