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
impl SymbolTable
Sourcepub fn add_import(&mut self, importer: Symbol, imported: Symbol)
pub fn add_import(&mut self, importer: Symbol, imported: Symbol)
Record that importer imports imported.
Sourcepub fn add_imported_by(
&mut self,
imported: Symbol,
importers: &IndexSet<Symbol>,
)
pub fn add_imported_by( &mut self, imported: Symbol, importers: &IndexSet<Symbol>, )
Record that multiple importers import the same imported program.
Sourcepub fn get_imports(&self, program: &Symbol) -> IndexSet<Symbol>
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.
Sourcepub fn get_imports_mut(
&mut self,
program: &Symbol,
) -> Option<&mut IndexSet<Symbol>>
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.
Sourcepub fn iter_imports(&self) -> impl Iterator<Item = (&Symbol, &IndexSet<Symbol>)>
pub fn iter_imports(&self) -> impl Iterator<Item = (&Symbol, &IndexSet<Symbol>)>
Returns an iterator over all import relationships.
Sourcepub fn add_as_library(&mut self, library: Symbol)
pub fn add_as_library(&mut self, library: Symbol)
Adds a library to the symbol table.
Sourcepub fn is_library(&self, name: Symbol) -> bool
pub fn is_library(&self, name: Symbol) -> bool
Checks if a given Symbol is the name of an available library.
Sourcepub fn get_transitive_imports(&self, program: &Symbol) -> IndexSet<Symbol>
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.
Sourcepub fn reset_but_consts(&mut self)
pub fn reset_but_consts(&mut self)
Reset everything except leave consts that have been evaluated.
Sourcepub fn global_scope(&self) -> bool
pub fn global_scope(&self) -> bool
Are we currently in the global scope?
Sourcepub fn iter_structs(&self) -> impl Iterator<Item = (&Location, &Composite)>
pub fn iter_structs(&self) -> impl Iterator<Item = (&Location, &Composite)>
Iterator over all the structs (not records) in this program.
Sourcepub fn iter_records(&self) -> impl Iterator<Item = (&Location, &Composite)>
pub fn iter_records(&self) -> impl Iterator<Item = (&Location, &Composite)>
Iterator over all the records in this program.
Sourcepub fn iter_functions(
&self,
) -> impl Iterator<Item = (&Location, &FunctionSymbol)>
pub fn iter_functions( &self, ) -> impl Iterator<Item = (&Location, &FunctionSymbol)>
Iterator over all the functions in this program.
Sourcepub fn iter_interfaces(&self) -> impl Iterator<Item = (&Location, &Interface)>
pub fn iter_interfaces(&self) -> impl Iterator<Item = (&Location, &Interface)>
Iterator over all the interfaces in this program.
Sourcepub fn lookup_struct(
&self,
current_program: Symbol,
loc: &Location,
) -> Option<&Composite>
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.
Sourcepub fn lookup_record(
&self,
current_program: Symbol,
location: &Location,
) -> Option<&Composite>
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.
Sourcepub fn lookup_function(
&self,
current_program: Symbol,
location: &Location,
) -> Option<&FunctionSymbol>
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.
Sourcepub fn lookup_interface(
&self,
current_program: Symbol,
location: &Location,
) -> Option<&Interface>
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.
Sourcepub fn lookup_path(
&self,
current_program: Symbol,
path: &Path,
) -> Option<VariableSymbol>
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- APath.
§Returns
An Option<VariableSymbol> containing the resolved symbol if found, otherwise None.
Sourcepub fn lookup_local(&self, name: Symbol) -> Option<VariableSymbol>
pub fn lookup_local(&self, name: Symbol) -> Option<VariableSymbol>
Access the variable accessible by this name in the current scope.
Sourcepub fn enter_scope(&mut self, id: Option<NodeID>)
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.
pub fn enter_existing_scope(&mut self, id: Option<NodeID>)
Sourcepub fn enter_scope_duped(
&mut self,
old_id: NodeID,
node_builder: &NodeBuilder,
) -> usize
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.
Sourcepub fn enter_parent(&mut self)
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).
Sourcepub fn is_local_to(&self, scope: NodeID, symbol: Symbol) -> bool
pub fn is_local_to(&self, scope: NodeID, symbol: Symbol) -> bool
Checks if a symbol is local to scope.
Sourcepub fn is_defined_in_scope_or_ancestor_until(
&self,
scope: NodeID,
symbol: Symbol,
) -> bool
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.
Sourcepub fn is_local_to_or_in_child_scope(
&self,
scope: NodeID,
symbol: Symbol,
) -> bool
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.
Sourcepub fn insert_local_const(&mut self, name: Symbol, value: Expression)
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.
Sourcepub fn insert_global_const(&mut self, location: Location, value: Expression)
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.
Sourcepub fn lookup_local_const(&self, name: Symbol) -> Option<Expression>
pub fn lookup_local_const(&self, name: Symbol) -> Option<Expression>
Find the evaluated const accessible by the given name in the current scope.
pub fn lookup_global_const( &self, current_program: Symbol, location: &Location, ) -> Option<Expression>
Sourcepub fn insert_struct(
&mut self,
location: Location,
struct: Composite,
) -> Result<()>
pub fn insert_struct( &mut self, location: Location, struct: Composite, ) -> Result<()>
Insert a struct at this location.
Sourcepub fn insert_record(
&mut self,
location: Location,
record: Composite,
) -> Result<()>
pub fn insert_record( &mut self, location: Location, record: Composite, ) -> Result<()>
Insert a record at this location.
Sourcepub fn insert_function(
&mut self,
location: Location,
function: Function,
) -> Result<()>
pub fn insert_function( &mut self, location: Location, function: Function, ) -> Result<()>
Insert a function at this location.
Sourcepub fn insert_interface(
&mut self,
location: Location,
int: Interface,
) -> Result<()>
pub fn insert_interface( &mut self, location: Location, int: Interface, ) -> Result<()>
Insert an interface at this location.
Sourcepub fn insert_global(
&mut self,
location: Location,
var: VariableSymbol,
) -> Result<()>
pub fn insert_global( &mut self, location: Location, var: VariableSymbol, ) -> Result<()>
Insert a global at this location.
Sourcepub fn lookup_global(
&self,
current_program: Symbol,
location: &Location,
) -> Option<&VariableSymbol>
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.
Sourcepub fn set_local_type(&mut self, name: Symbol, ty: Type) -> bool
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.
Sourcepub fn set_global_type(&mut self, location: &Location, ty: Type) -> bool
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.
pub fn emit_shadow_error(name: Symbol, span: Span, prev_span: Span) -> LeoError
Sourcepub fn insert_variable(
&mut self,
program: Symbol,
path: &[Symbol],
var: VariableSymbol,
) -> Result<()>
pub fn insert_variable( &mut self, program: Symbol, path: &[Symbol], var: VariableSymbol, ) -> Result<()>
Insert a variable into the current scope.
Trait Implementations§
Source§impl Debug for SymbolTable
impl Debug for SymbolTable
Source§impl Default for SymbolTable
impl Default for SymbolTable
Source§fn default() -> SymbolTable
fn default() -> SymbolTable
Auto Trait Implementations§
impl Freeze for SymbolTable
impl !RefUnwindSafe for SymbolTable
impl !Send for SymbolTable
impl !Sync for SymbolTable
impl Unpin for SymbolTable
impl UnsafeUnpin for SymbolTable
impl !UnwindSafe for SymbolTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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