86 std::ostringstream
out;
132 std::ostringstream
out;
135 out <<
"<invalid-span>";
193 for (
size_t i = 0; i < text.size(); ++i)
203 <<
"Source_Manager: invalid file id " << id;
216 <<
"Source_Manager: offset " <<
off
217 <<
" out of range for file '" <<
file.name <<
"'";
220 size_t hi =
file.line_starts.size();
223 const size_t mid = lo + (hi - lo)/2;
236 <<
"Source_Manager: invalid line index " <<
line_idx;
259 const std::string & text)
278 std::ifstream
input(path, std::ios::binary);
280 <<
"Source_Manager: cannot open file '" << path <<
"'";
282 std::ostringstream
out;
331 <<
"Source_Manager: invalid span [" << begin <<
", " << end
332 <<
") for file '" << src.name <<
"'";
334 return {id, begin, end};
350 <<
"Source_Manager::begin_position(): invalid span";
358 <<
"Source_Manager::end_position(): invalid span";
366 <<
"Source_Manager::slice(): invalid span";
370 <<
"Source_Manager::slice(): span end out of range";
386 <<
"Source_Manager::snippet(): invalid span";
Exception handling system with formatted messages for Aleph-w.
#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.
#define ah_invalid_argument_unless(C)
Throws std::invalid_argument if condition does NOT hold.
size_t size_t int32_t * out
T & append()
Allocate a new entry to the end of array.
Stores source files and resolves offsets into human-readable data.
const std::string & file_name(const Source_File_Id id) const
Returns the display name of file id.
static DynArray< Source_Offset > compute_line_starts(const std::string &text)
const Source_File & checked_file(const Source_File_Id id) const
std::string slice(const Source_Span &span) const
Returns the exact text covered by span.
size_t line_end_offset(const Source_File &file, const size_t line_idx) const
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 line_index_from_offset(const Source_File &file, const Source_Offset off) const
const std::string & file_text(const Source_File_Id id) const
Returns the full text of file id.
const Source_File & file(const Source_File_Id id) const
Returns the registered file record for id.
DynArray< Source_File > files
Source_Span span(const Source_File_Id id, const Source_Offset begin, const Source_Offset end) const
Creates a validated span in file id.
Source_File_Id load_file(const std::string &path)
Loads a file from disk and registers it.
size_t checked_index(const Source_File_Id id) const
size_t num_files() const noexcept
Returns the number of registered files.
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
Source_Position end_position(const Source_Span &span) const
Resolves the end of span to a concrete source position.
size_t file_size(const Source_File_Id id) const
Returns the size in bytes of file id.
Source_Position position(const Source_File_Id id, const Source_Offset off) const
Resolves off to file/offset/line/column information.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Registered source file with cached line starts.
DynArray< Source_Offset > line_starts
Byte offsets for each line start.
std::string name
User-facing file name or path.
Source_File_Id id
Stable file identifier.
std::string text
Full file contents.
Fully resolved source position.
std::string file_name
Human-readable file name.
size_t column
1-based column number.
Source_File_Id file_id
Stable file identifier; 0 means invalid.
std::string to_string() const
Formats the position as file:line:column or line:column.
bool is_valid() const noexcept
Returns whether the position refers to a registered file.
size_t line
1-based line number.
Source_Offset offset
Byte offset in the file text.
Render-ready excerpt for a single source line.
std::string file_name
File name owning the snippet.
std::string line_text
Raw line contents without trailing newline.
size_t highlight_column
1-based column where the underline starts.
size_t line
1-based line number.
size_t column
1-based begin column.
size_t highlight_width
Width of the underline, always >= 1.
Half-open byte range inside a source file.
bool empty() const noexcept
Returns whether the span contains no bytes.
Source_Offset begin
Inclusive begin byte offset.
bool contains(const Source_Offset offset) const noexcept
Returns whether offset lies inside the half-open range.
bool is_valid() const noexcept
Returns whether the span belongs to a registered file.
size_t size() const noexcept
Returns the span length in bytes.
Source_Offset end
Exclusive end byte offset.
Source_File_Id file_id
Stable file identifier; 0 means invalid.
std::string to_string() const
Formats the span as #file:[begin,end).
Lazy and scalable dynamic array implementation.