46# ifndef AH_DIAGNOSTICS_H
47# define AH_DIAGNOSTICS_H
126 const std::string & msg =
"");
130 const std::string & msg);
173 const std::string & msg)
181 diags.append(std::move(diag));
188 return diags.size() - 1;
194 for (
size_t i = 0; i < diag.labels.size(); ++i)
196 const auto & label = diag.labels.access(i);
201 for (
size_t i = 0; i < diag.labels.size(); ++i)
203 const auto & label = diag.labels.access(i);
204 if (label.span.is_valid())
220 out <<
" --> " << pos.to_string() <<
'\n';
222 std::ostringstream
ln;
227 out <<
" " << std::string(
line_no.size(),
' ') <<
" | ";
228 out << std::string(
snip.highlight_column > 1 ?
snip.highlight_column - 1 : 0,
' ');
230 for (
size_t i = 1; i <
snip.highlight_width; ++i)
240 for (
size_t i = 0; i < diag.
labels.size(); ++i)
242 const auto & label = diag.
labels.access(i);
247 if (label.span.is_valid())
249 if (
not label.message.empty())
250 out <<
": " << label.message;
297 <<
"Diagnostic_Engine::get(): invalid index " << i;
298 return diags.access(i);
336 for (
size_t i = 0; i <
diags.size(); ++i)
338 const auto & diag =
diags.access(i);
340 if (
not diag.code.empty())
341 out <<
"[" << diag.code <<
"]";
342 out <<
": " << diag.message <<
'\n';
350 for (
size_t j = 0; j < diag.notes.size(); ++j)
351 out <<
" = note: " << diag.notes.access(j) <<
'\n';
353 for (
size_t j = 0; j < diag.help.size(); ++j)
354 out <<
" = help: " << diag.help.access(j) <<
'\n';
356 if (i + 1 <
diags.size())
368 <<
"Diagnostic_Builder: detached builder";
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
#define ah_out_of_range_error_unless(C)
Throws std::out_of_range if condition does NOT hold.
Source file and span management utilities for compiler-style tooling.
size_t size_t int32_t value
size_t size_t int32_t * out
Fluent builder used to enrich a just-created diagnostic.
Diagnostic_Engine * engine
Diagnostic_Builder & code(const std::string &value)
Sets the stable diagnostic code.
Diagnostic_Builder(Diagnostic_Engine &engine, const size_t index) noexcept
Constructs a builder bound to engine[index].
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 & secondary(const Source_Span &span, const std::string &msg)
Adds a secondary label.
Diagnostic_Builder & primary(const Source_Span &span, const std::string &msg="")
Adds a primary label.
Diagnostic_Builder & note(const std::string &msg)
Appends a note line.
Diagnostic accumulator and renderer.
size_t warning_count() const noexcept
Returns the number of warnings.
void clear() noexcept
Removes all accumulated diagnostics and resets counters.
size_t append_diagnostic(const Diagnostic_Severity severity, const Source_Span &span, const std::string &msg)
friend class Diagnostic_Builder
Diagnostic_Engine(const Source_Manager &sm) noexcept
Constructs an engine bound to sm.
void render_plain(std::ostream &out) const
Renders all diagnostics as deterministic plain text.
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
const Diagnostic_Label * first_primary_label(const Diagnostic &diag) const noexcept
const Source_Manager * sources
Diagnostic_Builder fatal(const Source_Span &span, const std::string &msg)
Starts a fatal diagnostic.
Diagnostic_Builder warning(const Source_Span &span, const std::string &msg)
Starts a warning diagnostic.
DynArray< Diagnostic > diags
const Diagnostic & get(const size_t i) const
Returns diagnostic i.
size_t error_count() const noexcept
Returns the number of error and fatal diagnostics.
Diagnostic_Builder note(const Source_Span &span, const std::string &msg)
Starts a note diagnostic.
void render_secondary_labels(std::ostream &out, const Diagnostic &diag) const
Diagnostic_Builder error(const Source_Span &span, const std::string &msg)
Starts an error diagnostic.
void render_label_snippet(std::ostream &out, const Diagnostic_Label &label) const
size_t size() const noexcept
Returns the number of stored diagnostics.
static const char * severity_string(const Diagnostic_Severity severity)
T & append()
Allocate a new entry to the end of array.
Stores source files and resolves offsets into human-readable data.
Source_Snippet snippet(const Source_Span &span) const
Builds a single-line diagnostic snippet from span.
Source_Position begin_position(const Source_Span &span) const
Resolves the begin of span to a concrete source position.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Diagnostic_Label_Kind
Kind of source label attached to a diagnostic.
Diagnostic_Severity
Severity level of a diagnostic message.
Span annotation attached to a diagnostic.
Diagnostic_Label_Kind kind
Label role.
Source_Span span
Highlighted region.
std::string message
Optional label-specific message.
Fully accumulated diagnostic.
std::string code
Optional stable code such as E001.
DynArray< Diagnostic_Label > labels
Source annotations.
Diagnostic_Severity severity
Severity level.
std::string message
Main headline message.
DynArray< std::string > help
Suggested next actions.
DynArray< std::string > notes
Additional notes.
std::string to_string() const
Formats the position as file:line:column or line:column.
size_t line
1-based line number.
Half-open byte range inside a source file.
bool is_valid() const noexcept
Returns whether the span belongs to a registered file.
Lazy and scalable dynamic array implementation.