Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
compiler_module_linker_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
66 const auto result = compiler_link_module_surfaces(descriptors, metadata, order);
67 ASSERT_TRUE(result.valid);
68 ASSERT_EQ(result.modules.size(), 2u);
69
70 const auto & linked_main = result.modules.access(1);
71 EXPECT_EQ(linked_main.module_name, "main.aw");
72 ASSERT_EQ(linked_main.visible_exports.size(), 2u);
73 EXPECT_EQ(linked_main.visible_exports.access(0).name, "answer");
74 EXPECT_FALSE(linked_main.visible_exports.access(0).imported);
75 EXPECT_EQ(linked_main.visible_exports.access(1).name, "add");
76 EXPECT_TRUE(linked_main.visible_exports.access(1).imported);
77}
78
80{
83 main_module.name = "main.aw";
84 main_module.imports.append({"a.aw", {}});
85 main_module.imports.append({"b.aw", {}});
86 descriptors.append(std::move(main_module));
87 descriptors.append({"a.aw", {}});
88 descriptors.append({"b.aw", {}});
89
91 metadata.append({"main.aw", {}, {}});
93 a.name = "a.aw";
94 a.exports.append({Compiler_Module_Export_Kind::Function, "add", {}});
95 metadata.append(std::move(a));
97 b.name = "b.aw";
98 b.exports.append({Compiler_Module_Export_Kind::Global, "add", {}});
99 metadata.append(std::move(b));
100
101 DynArray<size_t> order;
102 order.append(1);
103 order.append(2);
104 order.append(0);
105
106 const auto result = compiler_link_module_surfaces(descriptors, metadata, order);
107 ASSERT_FALSE(result.valid);
108 ASSERT_EQ(result.issues.size(), 1u);
109 EXPECT_EQ(result.issues.access(0).kind,
110 Compiler_Module_Linkage_Issue_Kind::Duplicate_Value_Export);
111 EXPECT_EQ(result.issues.access(0).module_name, "main.aw");
112 EXPECT_EQ(result.issues.access(0).export_name, "add");
113}
Reusable linking helpers for module surfaces and direct imports.
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.
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.