pub struct InputFiles {
    input_files: Vec<InputFile>,
}
Expand description

Keeps track of all input files and allows to make cheap copy-able spans

Fields§

§input_files: Vec<InputFile>

All input files which are used in this compiler

This vector is append-only and the offset of the input files is guaranteed to be increasing.

Implementations§

source§

impl InputFiles

source

pub fn new() -> Self

source

pub fn add_input(&mut self, code: Code) -> CodeId

Adds a code unit and returns its ID

source

pub fn get_code_ref(&self, code_id: CodeId) -> CodeRef<'_>

source

pub fn find_by_filename(&self, filename: &str) -> Option<CodeId>

Searches the registered InputFiles and returns the first with a matching filename

source

pub fn get_input(&self, code_id: CodeId) -> &Code

Gets the input file with this id

source

pub fn get_input_offset(&self, code_id: CodeId) -> usize

Gets the offset of the file with this id

source

pub fn get_total_offset(&self) -> usize

Calculates the total byte offset

source

fn get_span_file(&self, span: Span) -> (usize, &InputFile)

Searches for the input file that contains the given span

Returns a (index, &input_file) tuple. Since the input files are stored sorted, the search can be completed with O(log n) time complexity

source

pub fn get_span_code(&self, span: Span) -> CodeRef<'_>

source

pub fn get_span_str(&self, span: Span) -> &str

Returns the str that corresponds to a span

Panics

panics if the span is out of bounds

source

pub fn line_col(&self, span: Span) -> (usize, usize)

Returns the line in a file at which this span begins and the column This function starts counting at zero, so that the first character in a file is (0, 0)

Trait Implementations§

source§

impl Debug for InputFiles

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for InputFiles

source§

fn default() -> InputFiles

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.