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>>§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>§scope_index: usize§scopes: Vec<RefCell<SymbolTable>>

Implementations§

source§

impl SymbolTable

source

pub fn check_shadowing( &self, location: &Location, is_struct: bool, 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.

source

pub fn scope_index(&mut self) -> usize

Returns the current scope index. Increments the scope index.

source

pub fn insert_fn( &mut self, location: Location, insert: &Function ) -> Result<(), LeoError>

Inserts a function into the symbol table.

source

pub fn insert_struct( &mut self, location: Location, insert: &Composite ) -> Result<(), LeoError>

Inserts a struct into the symbol table.

source

pub fn attach_finalize( &mut self, caller: Location, callee: Location ) -> Result<(), LeoError>

Attach a finalize to a function.

source

pub fn insert_variable( &mut self, location: Location, insert: VariableSymbol ) -> Result<(), LeoError>

Inserts a variable into the symbol table.

source

pub fn insert_futures( &mut self, program: Symbol, function: Symbol, futures: Vec<Location> ) -> Result<(), LeoError>

Inserts futures into the function definition.

source

pub fn remove_variable_from_current_scope(&mut self, location: Location)

Removes a variable from the symbol table.

source

pub fn insert_block(&mut self) -> usize

Creates a new scope for the block and stores it in the symbol table.

source

pub fn lookup_fn_symbol(&self, location: Location) -> Option<&FunctionSymbol>

Attempts to lookup a function in the symbol table.

source

pub fn lookup_struct( &self, location: Location, main_program: Option<Symbol> ) -> Option<&Composite>

Attempts to lookup a struct in the symbol table.

source

pub fn lookup_variable(&self, location: Location) -> Option<&VariableSymbol>

Attempts to lookup a variable in the symbol table.

source

pub fn lookup_variable_in_current_scope( &self, location: Location ) -> Option<&VariableSymbol>

Attempts to lookup a variable in the current scope.

source

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.

source

pub fn to_json_string(&self) -> Result<String, LeoError>

Serializes the symbol table into a JSON string.

source

pub fn to_json_value(&self) -> Result<Value, LeoError>

Converts the symbol table into a JSON value

source

pub fn to_json_file( &self, path: PathBuf, file_name: &str ) -> Result<(), LeoError>

source

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.

source

pub fn from_json_string(json: &str) -> Result<SymbolTable, LeoError>

Deserializes the JSON string into a symbol table.

source

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

source§

fn clone(&self) -> SymbolTable

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SymbolTable

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for SymbolTable

source§

fn default() -> SymbolTable

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for SymbolTable

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<SymbolTable, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for SymbolTable

source§

fn eq(&self, other: &SymbolTable) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for SymbolTable

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for SymbolTable

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<'de, T> DeserializeExt<'de> for T

§

fn take_from_value<D>( value: &mut Value, field: &str ) -> Result<T, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,