Module: compiler.diagnostics
Source: ./compiler/diagnostics.reef
Overview
compiler/diagnostics - Diagnostic Collection and Formatting
Provides structured error/warning/note collection and formatting for compilers. Enables collecting multiple errors before stopping.
Usage: import compiler.diagnostics import compiler.source
let bag = diagnostics.create_bag() let pos = source.create_pos("main.reef", 10, 5) diagnostics.add_error(bag, pos, "Undefined variable 'x'") diagnostics.add_warning(bag, pos, "Unused variable 'y'")
if diagnostics.has_errors(bag) diagnostics.print_all(bag) end if
Diagnostic Levels: Error - Compilation error, must be fixed Warning - Potential issue, compilation continues Note - Additional context information Help - Suggestion for fixing the issue
Types
DiagnosticLevel (enum)
Variants:
ErrorWarningNoteHelp
Diagnostic
Fields:
| Name | Type |
|---|---|
level |
DiagnosticLevel |
message |
string |
file |
string |
line |
int |
col |
int |
has_pos |
bool |
DiagnosticBag
Fields:
| Name | Type |
|---|---|
diagnostics |
[Diagnostic] |
count |
int |
errors |
int |
warnings |
int |
Functions
fn max_diagnostics(): int
Maximum diagnostics (avoid unbounded growth)
fn level_to_string(level: DiagnosticLevel): string
fn create_diagnostic(level: DiagnosticLevel, file: string, line: int, col: int, msg: string): Diagnostic
Create a diagnostic with position
fn create_diagnostic_no_pos(level: DiagnosticLevel, msg: string): Diagnostic
Create a diagnostic without position
fn format_diagnostic(d: Diagnostic): string
Format a single diagnostic Output format: "error: main.reef:10:5: message" or "help: message"
fn create_bag(): DiagnosticBag
Create an empty diagnostic bag
fn has_errors(bag: DiagnosticBag): bool
Check if there are any errors
fn error_count(bag: DiagnosticBag): int
Get the number of errors
fn warning_count(bag: DiagnosticBag): int
Get the number of warnings
fn total_count(bag: DiagnosticBag): int
Get the total number of diagnostics
Procedures
proc add_diagnostic(bag: DiagnosticBag, d: Diagnostic)
Add a diagnostic to the bag
proc add_error(bag: DiagnosticBag, file: string, line: int, col: int, msg: string)
Add an error diagnostic
proc add_warning(bag: DiagnosticBag, file: string, line: int, col: int, msg: string)
Add a warning diagnostic
proc add_note(bag: DiagnosticBag, file: string, line: int, col: int, msg: string)
Add a note diagnostic
proc add_help(bag: DiagnosticBag, msg: string)
Add a help diagnostic (no position)
proc print_all(bag: DiagnosticBag)
Print all diagnostics
proc print_errors_only(bag: DiagnosticBag)
Print only errors
proc print_summary(bag: DiagnosticBag)
Print summary line
proc clear(bag: DiagnosticBag)
Clear all diagnostics
Generated by reefc doc