Skip to main content

SymbolTable

Struct SymbolTable 

Source
pub struct SymbolTable { /* private fields */ }
Expand description

Maps global and local symbols to information about them.

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

Implementations§

Source§

impl SymbolTable

Source

pub fn add_import(&mut self, importer: Symbol, imported: Symbol)

Record that importer imports imported.

Source

pub fn add_imported_by( &mut self, imported: Symbol, importers: &IndexSet<Symbol>, )

Record that multiple importers import the same imported program.

Source

pub fn get_imports(&self, program: &Symbol) -> IndexSet<Symbol>

Returns all programs imported by a given program. This also includes implicit imports, i.e. libraries.

Source

pub fn get_imports_mut( &mut self, program: &Symbol, ) -> Option<&mut IndexSet<Symbol>>

Returns a mutable reference to the set of imports for a given program.

Source

pub fn iter_imports(&self) -> impl Iterator<Item = (&Symbol, &IndexSet<Symbol>)>

Returns an iterator over all import relationships.

Source

pub fn add_as_library(&mut self, library: Symbol)

Adds a library to the symbol table.

Source

pub fn is_library(&self, name: Symbol) -> bool

Checks if a given Symbol is the name of an available library.

Source

pub fn get_transitive_imports(&self, program: &Symbol) -> IndexSet<Symbol>

Returns the transitive closure of imports for a given program. Libraries are excluded because they are compile-time only and should not appear in bytecode.

Source

pub fn reset_but_consts(&mut self)

Reset everything except leave consts that have been evaluated.

Source

pub fn global_scope(&self) -> bool

Are we currently in the global scope?

Source

pub fn iter_structs(&self) -> impl Iterator<Item = (&Location, &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 iter_interfaces(&self) -> impl Iterator<Item = (&Location, &Interface)>

Iterator over all the interfaces in this program.

Source

pub fn lookup_struct( &self, current_program: Symbol, loc: &Location, ) -> Option<&Composite>

Access a struct by this location if it exists and is accessible from program named current_program.

Source

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

Access a record at this location if it exists and is accessible from program named current_program.

Source

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

Access a function by this name if it exists and is accessible from program named current_program.

Source

pub fn lookup_interface( &self, current_program: Symbol, location: &Location, ) -> Option<&Interface>

Access an interface by this name if it exists and is accessible from program named current_program.

Source

pub fn lookup_path( &self, current_program: Symbol, path: &Path, ) -> Option<VariableSymbol>

Attempts to look up a variable by a path from program named current_program.

First, it tries to resolve the symbol as a global using the full path under the given program. If that fails and the path is non-empty, it falls back to resolving the last component of the path as a local symbol.

§Arguments
  • program - The root symbol representing the program or module context.
  • path - A Path.
§Returns

An Option<VariableSymbol> containing the resolved symbol if found, otherwise None.

Source

pub fn lookup_local(&self, 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_existing_scope(&mut self, id: Option<NodeID>)

Source

pub fn enter_scope_duped( &mut self, old_id: NodeID, node_builder: &NodeBuilder, ) -> usize

Enter a new scope by duplicating the local table at old_id recursively.

Each scope in the subtree receives a fresh NodeID from node_builder. The new root scope’s parent is set to the current scope (if any). Returns the NodeID of the new duplicated root scope.

Source

pub fn enter_parent(&mut self)

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

Source

pub fn is_local_to(&self, scope: NodeID, symbol: Symbol) -> bool

Checks if a symbol is local to scope.

Source

pub fn is_defined_in_scope_or_ancestor_until( &self, scope: NodeID, symbol: Symbol, ) -> bool

Checks whether symbol is defined in the current scope (self.local) or any of its ancestor scopes, up to and including scope.

Returns false if the current scope is not a descendant of scope.

Source

pub fn is_local_to_or_in_child_scope( &self, scope: NodeID, symbol: Symbol, ) -> bool

Checks if a symbol is local to scope or any of its child scopes.

Source

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

Insert an evaluated local const into the current scope. This function does nothing if we’re in a global scope.

Source

pub fn insert_global_const(&mut self, location: Location, value: Expression)

Insert an evaluated global const into the global scope This function does nothing if we’re in a local scope.

Source

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

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

Source

pub fn lookup_global_const( &self, current_program: Symbol, location: &Location, ) -> Option<Expression>

Source

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

Insert a struct at this location.

Source

pub fn insert_record( &mut self, location: Location, record: 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_interface( &mut self, location: Location, int: Interface, ) -> Result<()>

Insert an interface 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, current_program: Symbol, location: &Location, ) -> Option<&VariableSymbol>

Access the global variable at this location if it exists and is visible from the given current_program.

Source

pub fn set_local_type(&mut self, name: Symbol, ty: Type) -> bool

Sets the type of a local using its name. Returns false if the local is not found.

Source

pub fn set_global_type(&mut self, location: &Location, ty: Type) -> bool

Sets the type of a global using its location. Returns false if the global is not found.

Source

pub fn emit_shadow_error(name: Symbol, span: Span, prev_span: Span) -> LeoError

Source

pub fn insert_variable( &mut self, program: Symbol, path: &[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.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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