Struct leo_compiler::SymbolTable
source · pub struct SymbolTable {
pub functions: IndexMap<Location, FunctionSymbol>,
pub structs: IndexMap<Location, Composite>,
/* private fields */
}Fields§
§functions: IndexMap<Location, FunctionSymbol>Maps parent program name and function name to the AST’s function definition. This field is populated at a first pass.
structs: IndexMap<Location, Composite>Maps parent program name and composite name to composite definitions. This field is populated at a first pass.
Implementations§
source§impl SymbolTable
impl SymbolTable
sourcepub fn check_shadowing(
&self,
location: &Location,
span: Span
) -> Result<(), LeoError>
pub fn check_shadowing( &self, location: &Location, 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,
location: Location,
insert: &Function
) -> Result<(), LeoError>
pub fn insert_fn( &mut self, location: Location, insert: &Function ) -> Result<(), LeoError>
Inserts a function into the symbol table.
sourcepub fn insert_struct(
&mut self,
location: Location,
insert: &Composite
) -> Result<(), LeoError>
pub fn insert_struct( &mut self, location: Location, insert: &Composite ) -> Result<(), LeoError>
Inserts a struct into the symbol table.
sourcepub fn insert_variable(
&mut self,
location: Location,
insert: VariableSymbol
) -> Result<(), LeoError>
pub fn insert_variable( &mut self, location: Location, insert: VariableSymbol ) -> Result<(), LeoError>
Inserts a variable into the symbol table.
sourcepub fn remove_variable_from_current_scope(&mut self, location: Location)
pub fn remove_variable_from_current_scope(&mut self, location: Location)
Removes a variable from 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, location: Location) -> Option<&FunctionSymbol>
pub fn lookup_fn_symbol(&self, location: Location) -> Option<&FunctionSymbol>
Attempts to lookup a function in the symbol table.
sourcepub fn lookup_struct(&self, location: Location) -> Option<&Composite>
pub fn lookup_struct(&self, location: Location) -> Option<&Composite>
Attempts to lookup a struct in the symbol table.
sourcepub fn lookup_variable(&self, location: Location) -> Option<&VariableSymbol>
pub fn lookup_variable(&self, location: Location) -> Option<&VariableSymbol>
Attempts to lookup a variable 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.
sourcepub fn to_json_string(&self) -> Result<String, LeoError>
pub fn to_json_string(&self) -> Result<String, LeoError>
Serializes the symbol table into a JSON string.
sourcepub fn to_json_value(&self) -> Result<Value, LeoError>
pub fn to_json_value(&self) -> Result<Value, LeoError>
Converts the symbol table into a JSON value
pub fn to_json_file( &self, path: PathBuf, file_name: &str ) -> Result<(), LeoError>
sourcepub fn to_json_file_without_keys(
&self,
path: PathBuf,
file_name: &str,
excluded_keys: &[&str]
) -> Result<(), LeoError>
pub fn to_json_file_without_keys( &self, path: PathBuf, file_name: &str, excluded_keys: &[&str] ) -> Result<(), LeoError>
Serializes the symbol table into a JSON value and removes keys from object mappings before writing to a file.
sourcepub fn from_json_string(json: &str) -> Result<SymbolTable, LeoError>
pub fn from_json_string(json: &str) -> Result<SymbolTable, LeoError>
Deserializes the JSON string into a symbol table.
sourcepub fn from_json_file(path: PathBuf) -> Result<SymbolTable, LeoError>
pub fn from_json_file(path: PathBuf) -> Result<SymbolTable, LeoError>
Deserializes the JSON string into a symbol table from a file.
Trait Implementations§
source§impl Clone for SymbolTable
impl Clone for SymbolTable
source§fn clone(&self) -> SymbolTable
fn clone(&self) -> SymbolTable
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for SymbolTable
impl Debug for SymbolTable
source§impl Default for SymbolTable
impl Default for SymbolTable
source§fn default() -> SymbolTable
fn default() -> SymbolTable
source§impl<'de> Deserialize<'de> for SymbolTable
impl<'de> Deserialize<'de> for SymbolTable
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<SymbolTable, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<SymbolTable, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for SymbolTable
impl PartialEq for SymbolTable
source§fn eq(&self, other: &SymbolTable) -> bool
fn eq(&self, other: &SymbolTable) -> bool
self and other values to be equal, and is used
by ==.