Struct brane_dsl::symbol_table::SymbolTable

source ·
pub struct SymbolTable {
    pub parent: Option<Rc<RefCell<SymbolTable>>>,
    /* private fields */
}
Expand description

Defines a SymbolTable that contains all definitions of a single scope.

Fields§

§parent: Option<Rc<RefCell<SymbolTable>>>

Contains the parent symbol table, if any.

Implementations§

source§

impl SymbolTable

source

pub fn new() -> Rc<RefCell<Self>>

Constructor for the SymbolTable.

§Returns

A new SymbolTable that does not have any definitions within it yet. It is already wrapped in an Rc and RefCell for convenience.

source

pub fn add_func( &mut self, entry: FunctionEntry, ) -> Result<Rc<RefCell<FunctionEntry>>, Error>

Adds the given FunctionEntry to the function namespace in the SymbolTable.

§Arguments
  • entry: The new FunctionEntry to add.
§Returns

The newly created entry (or rather, a reference-counted pointer to it).

§Errors

This function may error if an entry with this name in this namespace already exists.

source

pub fn add_class( &mut self, entry: ClassEntry, ) -> Result<Rc<RefCell<ClassEntry>>, Error>

Adds the given ClassEntry to the class namespace in the SymbolTable.

§Arguments
  • entry: The new ClassEntry to add.
§Returns

The newly created entry (or rather, a reference-counted pointer to it).

§Errors

This function may error if an entry with this name in this namespace already exists.

source

pub fn add_var( &mut self, entry: VarEntry, ) -> Result<Rc<RefCell<VarEntry>>, Error>

Adds the given VarEntry to the variable namespace in the SymbolTable.

§Arguments
  • entry: The new VarEntry to add.
§Returns

The newly created entry (or rather, a reference-counted pointer to it).

§Errors

This function may error if an entry with this name in this namespace already exists.

source

pub fn get<S: AsRef<str>>(&self, name: S) -> Option<SymbolTableEntry>

Returns the entry in all namespaces with the given name if it exists.

This implies that the name is unique across namespaces, so it relies on an external source to make that happen.

If that somehow fails, returns the first occurrence in the order of functions -> classes -> variables.

§Generic arguments
  • S: The &str-like type of the target name.
§Arguments
  • name: The name of the entry to retrieve.
§Returns

A reference-counter pointer to the entry if it exists, or else None.

source

pub fn get_func<S: AsRef<str>>( &self, name: S, ) -> Option<Rc<RefCell<FunctionEntry>>>

Returns the entry in the function namespace with the given name if it exists.

§Generic arguments
  • S: The &str-like type of the target name.
§Arguments
  • name: The name of the entry to retrieve.
§Returns

A reference-counter pointer to the entry if it exists, or else None.

source

pub fn get_class<S: AsRef<str>>( &self, name: S, ) -> Option<Rc<RefCell<ClassEntry>>>

Returns the entry in the class namespace with the given name if it exists.

§Generic arguments
  • S: The &str-like type of the target name.
§Arguments
  • name: The name of the entry to retrieve.
§Returns

A reference-counter pointer to the entry if it exists, or else None.

source

pub fn get_var<S: AsRef<str>>(&self, name: S) -> Option<Rc<RefCell<VarEntry>>>

Returns the entry in the variable namespace with the given name if it exists.

§Generic arguments
  • S: The &str-like type of the target name.
§Arguments
  • name: The name of the entry to retrieve.
§Returns

A reference-counter pointer to the entry if it exists, or else None.

source

pub fn has_functions(&self) -> bool

Returns whether this SymbolTable has any functions defined at all.

source

pub fn n_functions(&self) -> usize

Returns the number of functions defined in the SymbolTable.

source

pub fn functions(&self) -> Iter<'_, String, Rc<RefCell<FunctionEntry>>>

Returns an iterator over the defined functions (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn functions_mut( &mut self, ) -> IterMut<'_, String, Rc<RefCell<FunctionEntry>>>

Returns a muteable iterator over the defined functions (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn into_functions(&mut self) -> IntoIter<String, Rc<RefCell<FunctionEntry>>>

Returns a consuming iterator over the defined functions (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn has_classes(&self) -> bool

Returns whether this SymbolTable has any classes defined at all.

source

pub fn n_classes(&self) -> usize

Returns the number of classes defined in the SymbolTable.

source

pub fn classes(&self) -> Iter<'_, String, Rc<RefCell<ClassEntry>>>

Returns an iterator over the defined classes (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn classes_mut(&mut self) -> IterMut<'_, String, Rc<RefCell<ClassEntry>>>

Returns a muteable iterator over the defined classes (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn into_classes(&mut self) -> IntoIter<String, Rc<RefCell<ClassEntry>>>

Returns a consuming iterator over the defined classes (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn has_variables(&self) -> bool

Returns whether this SymbolTable has any variables defined at all.

source

pub fn n_variables(&self) -> usize

Returns the number of variables defined in the SymbolTable.

source

pub fn variables(&self) -> Iter<'_, String, Rc<RefCell<VarEntry>>>

Returns an iterator over the defined variables (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn variables_mut(&mut self) -> IterMut<'_, String, Rc<RefCell<VarEntry>>>

Returns a muteable iterator over the defined variables (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

source

pub fn into_variables(&mut self) -> IntoIter<String, Rc<RefCell<VarEntry>>>

Returns a consuming iterator over the defined variables (as (name, entry) pairs).

§Returns

The iterator returned by the internal HashMap.

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

Formats the value using the given formatter. Read more

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

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

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

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

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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

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

source§

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>,

source§

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>,

source§

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.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T