Struct SymbolTable

pub struct SymbolTable { /* private fields */ }
Expand description

The Symbol Table records metadata about identifiers.

The parser and/or sema stage can query the Symbol Table and emit diagnostics such as when a variable, function or type alias is incorrectly redeclared.

In addition, it helps us solve the “typedef-name: identifier” problem when there is grammar ambiguity between a type alias and a variable identifier. One example is:

typedef int AA;
AA aa;              // Declare variable 'aa' of type AA (alias of int).
float AA;           // Declare variable 'AA' of type float.

Implementations§

§

impl SymbolTable

pub fn new() -> Self

Creates a new symbol table.

pub fn add<T: AsRef<AstUniqueName>>( &mut self, unique_name: T, data_type: AstType, attrs: SymbolAttributes, ) -> Result<(), &Symbol>

Adds a symbol to the table.

Returns Ok if the symbol was added, or Err(&Symbol) with the existing symbol if a symbol already exists for the given unique_name.

pub fn set_definition<T: AsRef<AstUniqueName>>( &mut self, unique_name: T, definition: Definition, ) -> Result<(), SetDefinitionError>

Sets that a symbol is defined.

A symbol’s definition can be changed from undefined to either Definition::Tentative or Definition::Defined, but it’s not possible to change a defined symbol back to undefined, or to change a defined symbol to tentative, or vice versa.

Returns Ok if a symbol exists for the given unique_name and if its previous definition was undefined, or Err otherwise.

pub fn get<T: AsRef<AstUniqueName>>(&self, unique_name: T) -> Option<&Symbol>

Returns the symbol for the given unique identifier name, or returns None.

pub fn set_symbol_used(&mut self, unique_name: &AstUniqueName)

Sets that the symbol has been used.

pub fn get_unused_symbols(&self) -> Vec<(String, SymbolKind, SourceLocation)>

Returns a vector of all unused variable and function symbols, excluding ones with external linkage, and unused local typedefs. (Do not warn for unused file-scope typedefs, since they could come from included headers.)

Trait Implementations§

§

impl Debug for SymbolTable

§

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

Formats the value using the given formatter. Read more
§

impl Default for SymbolTable

§

fn default() -> Self

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

impl IntoIterator for SymbolTable

§

type Item = (AstUniqueName, Symbol)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<AstUniqueName, Symbol>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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