Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
compiler_module_binder_test.cc
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
36#include <gtest/gtest.h>
37
39
40using namespace Aleph;
41
43{
46 main_module.name = "main.aw";
47 main_module.imports.append({"math.aw", {}});
48 descriptors.append(std::move(main_module));
49 descriptors.append({"math.aw", {}});
50
53 main_metadata.name = "main.aw";
54 main_metadata.exports.append({Compiler_Module_Export_Kind::Global, "answer", {}});
55 metadata.append(std::move(main_metadata));
56
58 math_metadata.name = "math.aw";
59 math_metadata.exports.append({Compiler_Module_Export_Kind::Function, "add", {}});
60 metadata.append(std::move(math_metadata));
61
62 DynArray<size_t> order;
63 order.append(1);
64 order.append(0);
65
67 const auto result = compiler_bind_module_surfaces(linkage);
68 ASSERT_TRUE(result.valid);
69 ASSERT_EQ(result.modules.size(), 2u);
70
71 const auto & bound_main = result.modules.access(1);
72 EXPECT_EQ(bound_main.module_name, "main.aw");
73 ASSERT_EQ(bound_main.names.size(), 2u);
74 EXPECT_EQ(bound_main.names.access(0).name, "answer");
75 EXPECT_FALSE(bound_main.names.access(0).imported);
76 EXPECT_EQ(bound_main.names.access(1).name, "add");
77 EXPECT_TRUE(bound_main.names.access(1).imported);
78 EXPECT_EQ(bound_main.names.access(1).provider_module_name, "math.aw");
79}
80
82{
85 main_module.name = "main.aw";
86 main_module.imports.append({"a.aw", {}});
87 main_module.imports.append({"b.aw", {}});
88 descriptors.append(std::move(main_module));
89 descriptors.append({"a.aw", {}});
90 descriptors.append({"b.aw", {}});
91
93 metadata.append({"main.aw", {}, {}});
95 a.name = "a.aw";
96 a.exports.append({Compiler_Module_Export_Kind::Function, "add", {}});
97 metadata.append(std::move(a));
99 b.name = "b.aw";
100 b.exports.append({Compiler_Module_Export_Kind::Global, "add", {}});
101 metadata.append(std::move(b));
102
103 DynArray<size_t> order;
104 order.append(1);
105 order.append(2);
106 order.append(0);
107
109 const auto result = compiler_bind_module_surfaces(linkage);
110 ASSERT_FALSE(result.valid);
111 ASSERT_EQ(result.issues.size(), 1u);
112 EXPECT_EQ(result.issues.access(0).kind,
113 Compiler_Module_Binding_Issue_Kind::Ambiguous_Value_Name);
114
115 const auto & bound_main = result.modules.access(2);
116 EXPECT_EQ(bound_main.module_name, "main.aw");
117 EXPECT_TRUE(bound_main.names.is_empty());
118}
Reusable binding helpers for linked module surfaces.
T & append()
Allocate a new entry to the end of array.
#define TEST(name)
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
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Compiler_Module_Link_Result compiler_link_module_surfaces(const DynArray< Compiler_Module_Descriptor > &descriptors, const DynArray< Compiler_Module_Metadata > &metadata, const DynArray< size_t > &order)
Links direct-import module surfaces into visible top-level views.
Compiler_Module_Binding_Result compiler_bind_module_surfaces(const Compiler_Module_Link_Result &linkage)
Binds linked module surfaces into one deterministic name view.
One module descriptor consumed by the reusable resolver.
std::string name
Stable module/source name.
Reusable metadata describing one parsed or analyzed module surface.
DynArray< Compiler_Module_Export > exports
Visible top-level declarations contributed by the module.
std::string name
Stable module/source name.