leo_passes::common::symbol_table

Struct SymbolTable

Source
pub struct SymbolTable {
    functions: IndexMap<Location, FunctionSymbol>,
    records: IndexMap<Location, Composite>,
    structs: IndexMap<Symbol, Composite>,
    global_consts: IndexMap<Location, Expression>,
    globals: IndexMap<Location, VariableSymbol>,
    all_locals: HashMap<NodeID, LocalTable>,
    local: Option<LocalTable>,
}
Expand description

Maps global and local symbols to information about them.

Scopes are indexed by the NodeID of the function, block, or iteration.

Fields§

§functions: IndexMap<Location, FunctionSymbol>

Functions indexed by location.

§records: IndexMap<Location, Composite>

Records indexed by location.

§structs: IndexMap<Symbol, Composite>

Structs indexed by location.

§global_consts: IndexMap<Location, Expression>

Consts that have been successfully evaluated.

§globals: IndexMap<Location, VariableSymbol>

Global variables indexed by location.

§all_locals: HashMap<NodeID, LocalTable>

Local tables index by the NodeID of the function, iteration, or block they’re contained in.

§local: Option<LocalTable>

The current LocalTable we’re looking at.

Implementations§

Source§

impl SymbolTable

Source

pub fn iter_structs(&self) -> impl Iterator<Item = (Symbol, &Composite)>

Iterator over all the structs (not records) in this program.

Source

pub fn iter_records(&self) -> impl Iterator<Item = (Location, &Composite)>

Iterator over all the records in this program.

Source

pub fn iter_functions( &self, ) -> impl Iterator<Item = (Location, &FunctionSymbol)>

Iterator over all the functions in this program.

Source

pub fn lookup_struct(&self, name: Symbol) -> Option<&Composite>

Access the struct by this name if it exists.

Source

pub fn lookup_record(&self, location: Location) -> Option<&Composite>

Access the record at this location if it exists.

Source

pub fn lookup_function(&self, location: Location) -> Option<&FunctionSymbol>

Access the function at this location if it exists.

Source

pub fn lookup_variable( &self, program: Symbol, name: Symbol, ) -> Option<VariableSymbol>

Access the variable accessible by this name in the current scope.

Source

pub fn enter_scope(&mut self, id: Option<NodeID>)

Enter the scope of this NodeID, creating a table if it doesn’t exist yet.

Passing None means to enter the global scope.

Source

pub fn enter_scope_duped(&mut self, new_id: NodeID, old_id: NodeID)

Enter the new scope with id new_id, duplicating its local symbol table from the scope at old_id.

This is useful for a pass like loop unrolling, in which the loop body must be duplicated multiple times.

Source

pub fn enter_parent(&mut self)

Enther the parent scope of the current scope (or the global scope if there is no local parent scope).

Source

pub fn insert_const(&mut self, program: Symbol, name: Symbol, value: Expression)

Insert an evaluated const into the current scope.

Source

pub fn lookup_const(&self, program: Symbol, name: Symbol) -> Option<Expression>

Find the evaluated const accessible by the given name in the current scope.

Source

pub fn insert_struct( &mut self, program: Symbol, name: Symbol, composite: Composite, ) -> Result<()>

Insert a struct at this name.

Since structs are indexed only by name, the program is used only to check shadowing.

Source

pub fn insert_record( &mut self, location: Location, composite: Composite, ) -> Result<()>

Insert a record at this location.

Source

pub fn insert_function( &mut self, location: Location, function: Function, ) -> Result<()>

Insert a function at this location.

Source

pub fn insert_global( &mut self, location: Location, var: VariableSymbol, ) -> Result<()>

Insert a global at this location.

Source

pub fn lookup_global(&self, location: Location) -> Option<&VariableSymbol>

Access the global at this location if it exists.

Source

fn check_shadow_global(&self, location: Location, span: Span) -> Result<()>

Source

fn check_shadow_variable( &self, program: Symbol, name: Symbol, span: Span, ) -> Result<()>

Source

pub fn insert_variable( &mut self, program: Symbol, name: Symbol, var: VariableSymbol, ) -> Result<()>

Insert a variable into the current scope.

Source

pub fn attach_finalizer( &mut self, caller: Location, callee: Location, future_inputs: Vec<Location>, inferred_inputs: Vec<Type>, ) -> Result<()>

Attach a finalizer to a function.

Trait Implementations§

Source§

impl Debug for SymbolTable

Source§

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

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

impl Default for SymbolTable

Source§

fn default() -> SymbolTable

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more