Struct leo_passes::common::symbol_table::SymbolTable
source · pub struct SymbolTable {
pub(crate) parent: Option<Box<SymbolTable>>,
pub functions: IndexMap<Location, FunctionSymbol>,
pub structs: IndexMap<Location, Composite>,
pub(crate) variables: IndexMap<Location, VariableSymbol>,
pub(crate) scope_index: usize,
pub(crate) scopes: Vec<RefCell<SymbolTable>>,
}
Fields§
§parent: Option<Box<SymbolTable>>
The parent scope if it exists. For example, the parent scope of a then-block is the scope containing the associated ConditionalStatement.
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.
variables: IndexMap<Location, VariableSymbol>
The variables defined in a scope. This field is populated as necessary.
scope_index: usize
The index of the current scope.
scopes: Vec<RefCell<SymbolTable>>
The sub-scopes of this scope.
Implementations§
source§impl SymbolTable
impl SymbolTable
pub(crate) fn new_function_symbol(id: usize, func: &Function) -> FunctionSymbol
source§impl SymbolTable
impl SymbolTable
sourcepub fn check_shadowing(
&self,
location: &Location,
is_struct: bool,
span: Span,
) -> Result<()>
pub fn check_shadowing( &self, location: &Location, is_struct: bool, span: Span, ) -> Result<()>
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<()>
pub fn insert_fn(&mut self, location: Location, insert: &Function) -> Result<()>
Inserts a function into the symbol table.
sourcepub fn insert_struct(
&mut self,
location: Location,
insert: &Composite,
) -> Result<()>
pub fn insert_struct( &mut self, location: Location, insert: &Composite, ) -> Result<()>
Inserts a struct into the symbol table.
sourcefn check_eq_struct(&self, new: &Composite, old: &Composite) -> bool
fn check_eq_struct(&self, new: &Composite, old: &Composite) -> bool
Checks if two structs are equal.
sourcepub fn attach_finalize(
&mut self,
caller: Location,
callee: Location,
) -> Result<()>
pub fn attach_finalize( &mut self, caller: Location, callee: Location, ) -> Result<()>
Attach a finalize to a function.
sourcepub fn insert_variable(
&mut self,
location: Location,
insert: VariableSymbol,
) -> Result<()>
pub fn insert_variable( &mut self, location: Location, insert: VariableSymbol, ) -> Result<()>
Inserts a variable into the symbol table.
sourcepub fn insert_futures(
&mut self,
program: Symbol,
function: Symbol,
futures: Vec<Location>,
) -> Result<()>
pub fn insert_futures( &mut self, program: Symbol, function: Symbol, futures: Vec<Location>, ) -> Result<()>
Inserts futures into the function definition.
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,
main_program: Option<Symbol>,
) -> Option<&Composite>
pub fn lookup_struct( &self, location: Location, main_program: Option<Symbol>, ) -> 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_variable_in_current_scope(
&self,
location: Location,
) -> Option<&VariableSymbol>
pub fn lookup_variable_in_current_scope( &self, location: Location, ) -> Option<&VariableSymbol>
Attempts to lookup a variable in the current scope.
sourcepub fn lookup_scope_by_index(&self, index: usize) -> Option<&RefCell<Self>>
pub fn lookup_scope_by_index(&self, index: usize) -> Option<&RefCell<Self>>
Returns the scope associated with index
, if it exists in the symbol table.
sourcepub fn to_json_string(&self) -> Result<String>
pub fn to_json_string(&self) -> Result<String>
Serializes the symbol table into a JSON string.
sourcepub fn to_json_value(&self) -> Result<Value>
pub fn to_json_value(&self) -> Result<Value>
Converts the symbol table into a JSON value
pub fn to_json_file(&self, path: PathBuf, file_name: &str) -> Result<()>
sourcepub fn to_json_file_without_keys(
&self,
path: PathBuf,
file_name: &str,
excluded_keys: &[&str],
) -> Result<()>
pub fn to_json_file_without_keys( &self, path: PathBuf, file_name: &str, excluded_keys: &[&str], ) -> Result<()>
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<Self>
pub fn from_json_string(json: &str) -> Result<Self>
Deserializes the JSON string into a symbol table.
sourcepub fn from_json_file(path: PathBuf) -> Result<Self>
pub fn from_json_file(path: PathBuf) -> Result<Self>
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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 ==
.source§impl Serialize for SymbolTable
impl Serialize for SymbolTable
impl StructuralPartialEq for 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
fn take_from_value<D>(
value: &mut Value,
field: &str,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§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