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
impl SymbolTable
Sourcepub fn iter_structs(&self) -> impl Iterator<Item = (Symbol, &Composite)>
pub fn iter_structs(&self) -> impl Iterator<Item = (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, name: Symbol) -> Option<&Composite>
pub fn lookup_struct(&self, name: 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_variable(
&self,
program: Symbol,
name: Symbol,
) -> Option<VariableSymbol>
pub fn lookup_variable( &self, program: Symbol, 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)
Enther the parent scope of the current scope (or the global scope if there is no local parent scope).
Sourcepub fn insert_const(&mut self, program: Symbol, name: Symbol, value: Expression)
pub fn insert_const(&mut self, program: Symbol, name: Symbol, value: Expression)
Insert an evaluated const into the current scope.
Sourcepub fn lookup_const(&self, program: Symbol, name: Symbol) -> Option<Expression>
pub fn lookup_const(&self, program: Symbol, name: Symbol) -> Option<Expression>
Find the evaluated const accessible by the given name in the current scope.
Sourcepub fn insert_struct(
&mut self,
program: Symbol,
name: Symbol,
composite: Composite,
) -> Result<()>
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.
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, name: Symbol, span: Span, ) -> Result<()>
Sourcepub fn insert_variable(
&mut self,
program: Symbol,
name: Symbol,
var: VariableSymbol,
) -> Result<()>
pub fn insert_variable( &mut self, program: Symbol, name: 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