pub struct SymbolTable {
functions: IndexMap<Location, FunctionSymbol>,
records: IndexMap<Location, Composite>,
structs: IndexMap<Vec<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<Vec<Symbol>, Composite>
Structs indexed by a path.
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
impl SymbolTable
Sourcepub fn reset_but_consts(&mut self)
pub fn reset_but_consts(&mut self)
Reset everything except leave global 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 = (&Vec<Symbol>, &Composite)>
pub fn iter_structs(&self) -> impl Iterator<Item = (&Vec<Symbol>, &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 lookup_struct(&self, path: &[Symbol]) -> Option<&Composite>
pub fn lookup_struct(&self, path: &[Symbol]) -> Option<&Composite>
Access the struct by this name if it exists.
Sourcepub fn lookup_record(&self, location: &Location) -> Option<&Composite>
pub fn lookup_record(&self, location: &Location) -> Option<&Composite>
Access the record at this location if it exists.
Sourcepub fn lookup_function(&self, location: &Location) -> Option<&FunctionSymbol>
pub fn lookup_function(&self, location: &Location) -> Option<&FunctionSymbol>
Access the function at this location if it exists.
Sourcepub fn lookup_path(
&self,
program: Symbol,
path: &[Symbol],
) -> Option<VariableSymbol>
pub fn lookup_path( &self, program: Symbol, path: &[Symbol], ) -> Option<VariableSymbol>
Attempts to look up a variable by a path.
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 slice of symbols representing the absolute path to the variable.
§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.
Sourcepub fn enter_scope_duped(&mut self, new_id: NodeID, old_id: NodeID)
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.
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_const(
&mut self,
program: Symbol,
path: &[Symbol],
value: Expression,
)
pub fn insert_const( &mut self, program: Symbol, path: &[Symbol], value: Expression, )
Insert an evaluated const into the current scope.
Sourcepub fn lookup_const(
&self,
program: Symbol,
path: &[Symbol],
) -> Option<Expression>
pub fn lookup_const( &self, program: Symbol, path: &[Symbol], ) -> Option<Expression>
Find the evaluated const accessible by the given name in the current scope.
Sourcepub fn insert_struct(
&mut self,
program: Symbol,
path: &[Symbol],
composite: Composite,
) -> Result<()>
pub fn insert_struct( &mut self, program: Symbol, path: &[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.
Sourcepub fn insert_record(
&mut self,
location: Location,
composite: Composite,
) -> Result<()>
pub fn insert_record( &mut self, location: Location, composite: 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_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, location: &Location) -> Option<&VariableSymbol>
pub fn lookup_global(&self, location: &Location) -> Option<&VariableSymbol>
Access the global at this location if it exists.
fn check_shadow_global(&self, location: &Location, span: Span) -> Result<()>
fn check_shadow_variable( &self, program: Symbol, path: &[Symbol], span: Span, ) -> Result<()>
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 !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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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