|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Reusable lexical symbol table with stable ids and scope tracking. More...
#include <Compiler_Symbol_Bindings.H>
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_ |
Reusable lexical symbol table with stable ids and scope tracking.
Definition at line 129 of file Compiler_Symbol_Bindings.H.
|
inlineprivate |
Definition at line 134 of file Compiler_Symbol_Bindings.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Scope< Key, Value >::depth(), Aleph::Compiler_Symbol::id, scopes_, and symbols_.
Referenced by declare().
|
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().
|
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().
|
inlinenoexcept |
Returns the current lexical depth.
Definition at line 157 of file Compiler_Symbol_Bindings.H.
References Aleph::Scope< Key, Value >::depth(), and scopes_.
|
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().
|
inline |
Enters one nested lexical scope.
Definition at line 169 of file Compiler_Symbol_Bindings.H.
References Aleph::Scope< Key, Value >::enter_scope(), and scopes_.
Referenced by Aleph::Compiler_Line_Frontend::analyze(), Aleph::Compiler_Semantic_Analyzer::analyze_block(), Aleph::Compiler_Semantic_Analyzer::analyze_function(), Aleph::Compiler_Semantic_Analyzer::analyze_module(), main(), TEST(), TEST(), and TEST().
|
inline |
Leaves the current lexical scope.
Definition at line 175 of file Compiler_Symbol_Bindings.H.
References Aleph::Scope< Key, Value >::leave_scope(), and scopes_.
Referenced by Aleph::Compiler_Semantic_Analyzer::analyze_block(), Aleph::Compiler_Semantic_Analyzer::analyze_function(), and Aleph::Compiler_Semantic_Analyzer::analyze_module().
|
inlinenoexcept |
Looks up one visible symbol id by name.
Definition at line 181 of file Compiler_Symbol_Bindings.H.
References Aleph::Scope< Key, Value >::lookup(), and scopes_.
Referenced by Aleph::Compiler_Semantic_Analyzer::analyze_expr(), TEST(), and Aleph::Compiler_Line_Frontend::validate_operand_in_function().
|
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_.
|
inline |
Returns one symbol by its stable 1-based identifier.
Definition at line 222 of file Compiler_Symbol_Bindings.H.
References ah_out_of_range_error_unless, Aleph::and, and symbols_.
Referenced by Aleph::Compiler_Line_Frontend::analyze(), Aleph::Compiler_Semantic_Analyzer::resolved_symbol(), Aleph::Compiler_Semantic_Analyzer::symbol(), and TEST().
|
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().
|
private |
Definition at line 132 of file Compiler_Symbol_Bindings.H.
Referenced by append_symbol(), clear(), declare(), depth(), enter_scope(), leave_scope(), lookup(), and lookup_local().
|
private |
Definition at line 131 of file Compiler_Symbol_Bindings.H.
Referenced by append_symbol(), clear(), dump_symbols(), symbol(), and symbol_count().