|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Stores source files and resolves offsets into human-readable data. More...
#include <ah-source.H>
Public Member Functions | |
| Source_File_Id | add_virtual_file (const std::string &name, const std::string &text) |
| Registers an in-memory source file. | |
| Source_File_Id | load_file (const std::string &path) |
| Loads a file from disk and registers it. | |
| const Source_File & | file (const Source_File_Id id) const |
Returns the registered file record for id. | |
| const std::string & | file_name (const Source_File_Id id) const |
Returns the display name of file id. | |
| const std::string & | file_text (const Source_File_Id id) const |
Returns the full text of file id. | |
| size_t | file_size (const Source_File_Id id) const |
Returns the size in bytes of file id. | |
| size_t | num_files () const noexcept |
| Returns the number of registered 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_Position | position (const Source_File_Id id, const Source_Offset off) const |
Resolves off to file/offset/line/column information. | |
| Source_Position | begin_position (const Source_Span &span) const |
Resolves the begin of span to a concrete source position. | |
| Source_Position | end_position (const Source_Span &span) const |
Resolves the end of span to a concrete source position. | |
| std::string | slice (const Source_Span &span) const |
Returns the exact text covered by span. | |
| Source_Snippet | snippet (const Source_Span &span) const |
Builds a single-line diagnostic snippet from span. | |
Private Member Functions | |
| size_t | checked_index (const Source_File_Id id) const |
| const Source_File & | checked_file (const Source_File_Id id) const |
| size_t | line_index_from_offset (const Source_File &file, const Source_Offset off) const |
| size_t | line_end_offset (const Source_File &file, const size_t line_idx) const |
Static Private Member Functions | |
| static DynArray< Source_Offset > | compute_line_starts (const std::string &text) |
Private Attributes | |
| DynArray< Source_File > | files |
Stores source files and resolves offsets into human-readable data.
Source_Manager owns source texts and offers the core conversions required by lexer/parser infrastructure:
Definition at line 183 of file ah-source.H.
|
inline |
Registers an in-memory source file.
| name | User-facing file name. |
| text | Full source contents. |
Definition at line 258 of file ah-source.H.
References compute_line_starts(), file, files, and Aleph::Source_File::id.
Referenced by load_file(), Aleph::Compiler_Line_Frontend::load_sources(), Aleph::Compiler_MVP_Frontend::load_sources(), main(), Aleph::Compiler_Driver::prepare_inputs(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Resolves the begin of span to a concrete source position.
Definition at line 347 of file ah-source.H.
References ah_invalid_argument_unless, Aleph::Source_Span::begin, Aleph::Source_Span::file_id, Aleph::Source_Span::is_valid(), position(), and span().
Referenced by Aleph::Diagnostic_Engine::render_label_snippet(), Aleph::Diagnostic_Engine::render_secondary_labels(), and snippet().
|
inlineprivate |
Definition at line 207 of file ah-source.H.
References checked_index(), and files.
Referenced by file(), file_name(), file_size(), file_text(), position(), slice(), snippet(), and span().
|
inlineprivate |
Definition at line 200 of file ah-source.H.
References ah_out_of_range_error_unless, Aleph::and, and files.
Referenced by checked_file().
|
inlinestaticprivate |
Definition at line 188 of file ah-source.H.
References Aleph::DynArray< T >::append(), and Aleph::blossom_maximum_cardinality_matching().
Referenced by add_virtual_file().
|
inline |
Resolves the end of span to a concrete source position.
Definition at line 355 of file ah-source.H.
References ah_invalid_argument_unless, Aleph::Source_Span::end, Aleph::Source_Span::file_id, Aleph::Source_Span::is_valid(), position(), and span().
|
inline |
Returns the registered file record for id.
Definition at line 288 of file ah-source.H.
References checked_file().
|
inline |
Returns the display name of file id.
Definition at line 294 of file ah-source.H.
References checked_file(), and Aleph::Source_File::name.
|
inline |
Returns the size in bytes of file id.
Definition at line 306 of file ah-source.H.
References checked_file(), and Aleph::Source_File::text.
|
inline |
Returns the full text of file id.
Definition at line 300 of file ah-source.H.
References checked_file(), and Aleph::Source_File::text.
Referenced by Aleph::Compiler_Line_Frontend::parse_source_file().
|
inlineprivate |
Definition at line 233 of file ah-source.H.
References ah_out_of_range_error_unless, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), and file.
Referenced by snippet().
|
inlineprivate |
Definition at line 212 of file ah-source.H.
References ah_out_of_range_error_unless, Aleph::blossom_maximum_cardinality_matching(), and file.
Referenced by position().
|
inline |
Loads a file from disk and registers it.
| path | Path to the file to load. |
| std::runtime_error | If the file cannot be opened. |
Definition at line 276 of file ah-source.H.
References add_virtual_file(), ah_runtime_error_unless, Aleph::blossom_maximum_cardinality_matching(), and out.
Referenced by Aleph::Compiler_Driver::execute_files(), and TEST().
|
inlinenoexcept |
Returns the number of registered files.
Definition at line 312 of file ah-source.H.
References files.
|
inline |
Resolves off to file/offset/line/column information.
Definition at line 338 of file ah-source.H.
References Aleph::blossom_maximum_cardinality_matching(), checked_file(), and line_index_from_offset().
Referenced by begin_position(), and end_position().
|
inline |
Returns the exact text covered by span.
Definition at line 363 of file ah-source.H.
References ah_invalid_argument_unless, ah_out_of_range_error_unless, Aleph::Source_Span::begin, checked_file(), Aleph::Source_Span::end, Aleph::Source_Span::file_id, Aleph::Source_Span::is_valid(), Aleph::Source_Span::size(), and span().
Referenced by Aleph::Compiler_Lexer::lex_block_comment(), Aleph::Compiler_Lexer::lex_char_literal(), Aleph::Compiler_Lexer::lex_identifier_or_keyword(), Aleph::Compiler_Lexer::lex_punctuation_or_operator(), Aleph::Compiler_Lexer::lex_string(), and Aleph::Compiler_Lexer::make_token().
|
inline |
Builds a single-line diagnostic snippet from span.
Multi-line spans are clipped to the first line because plain-text diagnostics in the MVP render a single highlighted line.
| span | Span to inspect. |
Definition at line 383 of file ah-source.H.
References ah_invalid_argument_unless, Aleph::Source_Span::begin, begin_position(), Aleph::blossom_maximum_cardinality_matching(), checked_file(), Aleph::Source_Span::end, Aleph::Source_Span::file_id, Aleph::Source_Span::is_valid(), line_end_offset(), and span().
Referenced by Aleph::Diagnostic_Engine::render_label_snippet().
|
inline |
Creates a validated span in file id.
| id | File id. |
| begin | Inclusive begin offset. |
| end | Exclusive end offset. |
id. | std::out_of_range | If offsets are invalid. |
Definition at line 325 of file ah-source.H.
References ah_out_of_range_error_unless, Aleph::and, and checked_file().
Referenced by begin_position(), end_position(), Aleph::Compiler_Lexer::make_span(), slice(), and snippet().
|
private |
Definition at line 185 of file ah-source.H.
Referenced by add_virtual_file(), checked_file(), checked_index(), and num_files().