Struct leo_compiler::SymbolTable
source · pub struct SymbolTable {
pub functions: IndexMap<Symbol, FunctionSymbol, RandomState>,
pub structs: IndexMap<Symbol, Struct, RandomState>,
/* private fields */
}
Fields
functions: IndexMap<Symbol, FunctionSymbol, RandomState>
Functions represents the name of each function mapped to the AST’s function definition. This field is populated at a first pass.
structs: IndexMap<Symbol, Struct, RandomState>
Maps struct names to struct definitions. This field is populated at a first pass.
Implementations
sourceimpl SymbolTable
impl SymbolTable
sourcepub fn check_shadowing(&self, symbol: Symbol, span: Span) -> Result<(), LeoError>
pub fn check_shadowing(&self, symbol: Symbol, span: Span) -> Result<(), LeoError>
Recursively checks if the symbol table contains an entry for the given symbol. Leo does not allow any variable shadowing or overlap between different symbols.
sourcepub fn scope_index(&mut self) -> usize
pub fn scope_index(&mut self) -> usize
Returns the current scope index. Increments the scope index.
sourcepub fn insert_fn(
&mut self,
symbol: Symbol,
insert: &Function
) -> Result<(), LeoError>
pub fn insert_fn(
&mut self,
symbol: Symbol,
insert: &Function
) -> Result<(), LeoError>
Inserts a function into the symbol table.
sourcepub fn insert_struct(
&mut self,
symbol: Symbol,
insert: &Struct
) -> Result<(), LeoError>
pub fn insert_struct(
&mut self,
symbol: Symbol,
insert: &Struct
) -> Result<(), LeoError>
Inserts a struct into the symbol table.
sourcepub fn insert_variable(
&mut self,
symbol: Symbol,
insert: VariableSymbol
) -> Result<(), LeoError>
pub fn insert_variable(
&mut self,
symbol: Symbol,
insert: VariableSymbol
) -> Result<(), LeoError>
Inserts a variable into the symbol table.
sourcepub fn insert_block(&mut self) -> usize
pub fn insert_block(&mut self) -> usize
Creates a new scope for the block and stores it in the symbol table.
sourcepub fn lookup_fn_symbol(&self, symbol: Symbol) -> Option<&FunctionSymbol>
pub fn lookup_fn_symbol(&self, symbol: Symbol) -> Option<&FunctionSymbol>
Attempts to lookup a function in the symbol table.
sourcepub fn lookup_struct(&self, symbol: Symbol) -> Option<&Struct>
pub fn lookup_struct(&self, symbol: Symbol) -> Option<&Struct>
Attempts to lookup a struct in the symbol table.
sourcepub fn lookup_variable(&self, symbol: Symbol) -> Option<&VariableSymbol>
pub fn lookup_variable(&self, symbol: Symbol) -> Option<&VariableSymbol>
Attempts to lookup a variable in the symbol table.
sourcepub fn variable_in_local_scope(&self, symbol: Symbol) -> bool
pub fn variable_in_local_scope(&self, symbol: Symbol) -> bool
Returns true if the variable exists in the local scope
sourcepub fn variable_in_parent_scope(&self, symbol: Symbol) -> bool
pub fn variable_in_parent_scope(&self, symbol: Symbol) -> bool
Returns true if the variable exists in any parent scope
sourcepub fn lookup_variable_mut(
&mut self,
symbol: Symbol
) -> Option<&mut VariableSymbol>
pub fn lookup_variable_mut(
&mut self,
symbol: Symbol
) -> Option<&mut VariableSymbol>
Returns a mutable reference to the VariableSymbol
if it exists in the symbol table.
sourcepub fn lookup_fn_scope(&self, symbol: Symbol) -> Option<&RefCell<SymbolTable>>
pub fn lookup_fn_scope(&self, symbol: Symbol) -> Option<&RefCell<SymbolTable>>
Returns the scope associated with the function symbol, if it exists in the symbol table.
sourcepub fn lookup_scope_by_index(
&self,
index: usize
) -> Option<&RefCell<SymbolTable>>
pub fn lookup_scope_by_index(
&self,
index: usize
) -> Option<&RefCell<SymbolTable>>
Returns the scope associated with index
, if it exists in the symbol table.
Trait Implementations
sourceimpl Clone for SymbolTable
impl Clone for SymbolTable
sourcefn clone(&self) -> SymbolTable
fn clone(&self) -> SymbolTable
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more