Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Compiler_Module_Name_Diagnostics.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
43#ifndef COMPILER_MODULE_NAME_DIAGNOSTICS_H
44#define COMPILER_MODULE_NAME_DIAGNOSTICS_H
45
46#include <string>
47
49#include <ah-diagnostics.H>
50
51namespace Aleph {
64 Diagnostic_Engine &diagnostics,
65 const Source_Span &span,
67 const std::string &code,
68 const std::string &subject)
69{
70 if (resolution.ok())
71 return 0;
72
73 switch (resolution.status)
74 {
76 return 0;
77
79 return diagnostics
80 .error(span,
81 "cannot resolve " + subject + " '" + resolution.symbol_name + "' because module '"
82 + resolution.module_name + "' is not available")
83 .code(code)
84 .note("the current binding view does not contain that module")
85 .help("ensure the source was loaded and its imports were resolved before semantic checks")
86 .emit();
87
89 return diagnostics.error(span, "unknown " + subject + " '" + resolution.symbol_name + "'")
90 .code(code)
91 .note("module '" + resolution.module_name
92 + "' does not expose that name through local declarations or direct imports")
93 .help("declare the symbol locally or import a module that exports it")
94 .emit();
95
97 return diagnostics.error(span, "invalid " + subject + " '" + resolution.symbol_name + "'")
98 .code(code)
99 .note("module '" + resolution.module_name + "' resolves that name as "
101 .help("use a symbol exported with the expected kind")
102 .emit();
103
105 return diagnostics.error(span, "ambiguous " + subject + " '" + resolution.symbol_name + "'")
106 .code(code)
107 .note("module '" + resolution.module_name
108 + "' sees multiple matching providers for that name")
109 .help("rename one provider or reduce the set of direct imports")
110 .emit();
111 }
112
113 return 0;
114}
115} // namespace Aleph
116
117#endif
Reusable top-level name lookup over bound module surfaces.
Plain-text diagnostic engine for compiler-style tooling.
Diagnostic_Builder & code(const std::string &value)
Sets the stable diagnostic code.
size_t emit() const noexcept
Finalizes the builder and returns the diagnostic index.
Diagnostic_Builder & help(const std::string &msg)
Appends a help line.
Diagnostic_Builder & note(const std::string &msg)
Appends a note line.
Diagnostic accumulator and renderer.
Diagnostic_Builder error(const Source_Span &span, const std::string &msg)
Starts an error diagnostic.
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
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
size_t compiler_emit_module_name_resolution_diagnostic(Diagnostic_Engine &diagnostics, const Source_Span &span, const Compiler_Module_Name_Resolution &resolution, const std::string &code, const std::string &subject)
Emits one structured diagnostic for a module-name resolution failure.
const char * compiler_module_export_kind_name(const Compiler_Module_Export_Kind kind) noexcept
Returns the stable debug name for one module-export kind.
Structured result returned by reusable module-name resolution.
Half-open byte range inside a source file.
Definition ah-source.H:100
long double resolution