Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Compiler_Symbol_Bindings Class Reference

Reusable lexical symbol table with stable ids and scope tracking. More...

#include <Compiler_Symbol_Bindings.H>

Collaboration diagram for Aleph::Compiler_Symbol_Bindings:
[legend]

Public Member Functions

void clear () noexcept
 Clears all scopes and previously recorded symbols.
 
size_t depth () const noexcept
 Returns the current lexical depth.
 
size_t symbol_count () const noexcept
 Returns the number of recorded symbols.
 
size_t enter_scope ()
 Enters one nested lexical scope.
 
void leave_scope ()
 Leaves the current lexical scope.
 
const Compiler_Symbol_Id * lookup (const std::string &name) const noexcept
 Looks up one visible symbol id by name.
 
const Compiler_Symbol_Id * lookup_local (const std::string &name) const noexcept
 Looks up one symbol id only in the current scope.
 
Compiler_Symbol_Declare_Result declare (const Compiler_Symbol_Kind kind, const std::string &name, const Source_Span &span)
 Declares one symbol in the current scope.
 
const Compiler_Symbol & symbol (const Compiler_Symbol_Id id) const
 Returns one symbol by its stable 1-based identifier.
 
std::string dump_symbols () const
 Dumps the current symbol table in deterministic text form.
 

Private Member Functions

Compiler_Symbol_Id append_symbol (const Compiler_Symbol_Kind kind, const std::string &name, const Source_Span &span)
 

Private Attributes

DynArray< Compiler_Symbol > symbols_
 
Scope< std::string, Compiler_Symbol_Id > scopes_
 

Detailed Description

Reusable lexical symbol table with stable ids and scope tracking.

Definition at line 129 of file Compiler_Symbol_Bindings.H.

Member Function Documentation

◆ append_symbol()

Compiler_Symbol_Id Aleph::Compiler_Symbol_Bindings::append_symbol ( const Compiler_Symbol_Kind  kind,
const std::string &  name,
const Source_Span &  span 
)
inlineprivate

◆ clear()

void Aleph::Compiler_Symbol_Bindings::clear ( )
inlinenoexcept

Clears all scopes and previously recorded symbols.

Definition at line 150 of file Compiler_Symbol_Bindings.H.

References Aleph::Scope< Key, Value >::clear(), scopes_, and symbols_.

Referenced by Aleph::Compiler_Semantic_Analyzer::clear().

◆ declare()

Compiler_Symbol_Declare_Result Aleph::Compiler_Symbol_Bindings::declare ( const Compiler_Symbol_Kind  kind,
const std::string &  name,
const Source_Span &  span 
)
inline

Declares one symbol in the current scope.

Duplicate declarations in the current scope do not insert a new symbol. Shadowing of outer scopes does insert a new symbol and is reported in the returned status so callers can decide whether it is allowed.

Definition at line 198 of file Compiler_Symbol_Bindings.H.

References ah_runtime_error_unless, append_symbol(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Scope< Key, Value >::depth(), Aleph::Duplicate_Local, Aleph::Scope< Key, Value >::insert(), Aleph::Inserted, Aleph::Inserted_Shadowing, Aleph::Scope< Key, Value >::lookup(), Aleph::Scope< Key, Value >::lookup_local(), and scopes_.

Referenced by Aleph::Compiler_Line_Frontend::analyze(), Aleph::Compiler_Semantic_Analyzer::declare_symbol(), Aleph::Compiler_Semantic_Analyzer::declare_type_name(), main(), TEST(), TEST(), and TEST().

◆ depth()

size_t Aleph::Compiler_Symbol_Bindings::depth ( ) const
inlinenoexcept

Returns the current lexical depth.

Definition at line 157 of file Compiler_Symbol_Bindings.H.

References Aleph::Scope< Key, Value >::depth(), and scopes_.

◆ dump_symbols()

std::string Aleph::Compiler_Symbol_Bindings::dump_symbols ( ) const
inline

Dumps the current symbol table in deterministic text form.

Definition at line 230 of file Compiler_Symbol_Bindings.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_symbol_kind_name(), out, and symbols_.

Referenced by Aleph::Compiler_Semantic_Analyzer::dump_symbols().

◆ enter_scope()

◆ leave_scope()

void Aleph::Compiler_Symbol_Bindings::leave_scope ( )
inline

◆ lookup()

const Compiler_Symbol_Id * Aleph::Compiler_Symbol_Bindings::lookup ( const std::string &  name) const
inlinenoexcept

◆ lookup_local()

const Compiler_Symbol_Id * Aleph::Compiler_Symbol_Bindings::lookup_local ( const std::string &  name) const
inlinenoexcept

Looks up one symbol id only in the current scope.

Definition at line 187 of file Compiler_Symbol_Bindings.H.

References Aleph::Scope< Key, Value >::lookup_local(), and scopes_.

◆ symbol()

const Compiler_Symbol & Aleph::Compiler_Symbol_Bindings::symbol ( const Compiler_Symbol_Id  id) const
inline

◆ symbol_count()

size_t Aleph::Compiler_Symbol_Bindings::symbol_count ( ) const
inlinenoexcept

Returns the number of recorded symbols.

Definition at line 163 of file Compiler_Symbol_Bindings.H.

References symbols_.

Referenced by Aleph::Compiler_Semantic_Analyzer::resolved_symbol(), Aleph::Compiler_Semantic_Analyzer::symbol_count(), and TEST().

Member Data Documentation

◆ scopes_

Scope<std::string, Compiler_Symbol_Id> Aleph::Compiler_Symbol_Bindings::scopes_
private

◆ symbols_

DynArray<Compiler_Symbol> Aleph::Compiler_Symbol_Bindings::symbols_
private

Definition at line 131 of file Compiler_Symbol_Bindings.H.

Referenced by append_symbol(), clear(), dump_symbols(), symbol(), and symbol_count().


The documentation for this class was generated from the following file: