-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompiler_Module_Metadata.H
More file actions
117 lines (99 loc) · 3.83 KB
/
Compiler_Module_Metadata.H
File metadata and controls
117 lines (99 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Aleph_w
Data structures & Algorithms
version 2.0.0b
https://github.com/lrleon/Aleph-w
This file is part of Aleph-w library
Copyright (c) 2002-2026 Leandro Rabindranath Leon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** @file Compiler_Module_Metadata.H
* @brief Reusable metadata for parsed or analyzed module surfaces.
*
* This header models the user-visible top-level surface of one module so
* frontends, drivers, and external tools can inspect which declarations a
* source unit contributes without depending on one specific AST.
*
* @ingroup Utilities
*/
#ifndef COMPILER_MODULE_METADATA_H
#define COMPILER_MODULE_METADATA_H
#include <sstream>
#include <string>
#include <ah-source.H>
#include <tpl_dynArray.H>
namespace Aleph {
/** @brief Export kinds currently modeled by reusable module metadata. */
enum class Compiler_Module_Export_Kind
{
Function,
Global,
Type
};
/** @brief Returns the stable debug name for one module-export kind. */
inline const char *compiler_module_export_kind_name(const Compiler_Module_Export_Kind kind) noexcept
{
switch (kind)
{
case Compiler_Module_Export_Kind::Function:
return "Function";
case Compiler_Module_Export_Kind::Global:
return "Global";
case Compiler_Module_Export_Kind::Type:
return "Type";
}
return "Unknown";
}
/** @brief One reusable top-level declaration exposed by a module surface. */
struct Compiler_Module_Export
{
Compiler_Module_Export_Kind kind = Compiler_Module_Export_Kind::Global;
std::string name;
Source_Span declaration_span;
};
/** @brief Reusable metadata describing one parsed or analyzed module surface. */
struct Compiler_Module_Metadata
{
std::string name; ///< Stable module/source name.
Source_Span span; ///< Full module span when available.
DynArray<Compiler_Module_Export> exports; ///< Visible top-level declarations contributed by the module.
};
/** @brief Renders one deterministic text artifact for module metadata. */
inline std::string compiler_render_module_metadata(const DynArray<Compiler_Module_Metadata> &modules)
{
std::ostringstream out;
out << "ModuleMetadata\n";
for (size_t i = 0; i < modules.size(); ++i)
{
const auto &module = modules.access(i);
out << " Module(" << module.name << ")";
if (module.span.is_valid())
out << " @" << module.span.to_string();
out << '\n';
for (size_t j = 0; j < module.exports.size(); ++j)
{
const auto &item = module.exports.access(j);
out << " " << compiler_module_export_kind_name(item.kind) << "(" << item.name << ")";
if (item.declaration_span.is_valid())
out << " @" << item.declaration_span.to_string();
out << '\n';
}
}
return out.str();
}
} // namespace Aleph
#endif