42#ifndef COMPILER_SYMBOL_BINDINGS_H
43#define COMPILER_SYMBOL_BINDINGS_H
135 const std::string &name,
142 sym.declaration_span = span;
199 const std::string &name,
203 <<
"Compiler_Symbol_Bindings::declare(): no active scope";
212 <<
"Compiler_Symbol_Bindings::declare(): unexpected duplicate insertion for '" << name <<
"'";
225 <<
"Compiler_Symbol_Bindings::symbol(): invalid id " << id;
232 std::ostringstream
out;
234 for (
size_t i = 0; i <
symbols_.size(); ++i)
238 <<
" scope=" <<
sym.scope_depth <<
" @" <<
sym.declaration_span.to_string() <<
'\n';
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
#define ah_out_of_range_error_unless(C)
Throws std::out_of_range if condition does NOT hold.
Source file and span management utilities for compiler-style tooling.
size_t size_t int32_t * out
Reusable lexical symbol table with stable ids and scope tracking.
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.
Compiler_Symbol_Id append_symbol(const Compiler_Symbol_Kind kind, const std::string &name, const Source_Span &span)
const Compiler_Symbol_Id * lookup_local(const std::string &name) const noexcept
Looks up one symbol id only in the current scope.
size_t depth() const noexcept
Returns the current lexical depth.
void clear() noexcept
Clears all scopes and previously recorded symbols.
const Compiler_Symbol & symbol(const Compiler_Symbol_Id id) const
Returns one symbol by its stable 1-based identifier.
DynArray< Compiler_Symbol > symbols_
std::string dump_symbols() const
Dumps the current symbol table in deterministic text form.
Scope< std::string, Compiler_Symbol_Id > scopes_
const Compiler_Symbol_Id * lookup(const std::string &name) const noexcept
Looks up one visible symbol id by name.
size_t symbol_count() const noexcept
Returns the number of recorded symbols.
void leave_scope()
Leaves the current lexical scope.
size_t enter_scope()
Enters one nested lexical scope.
Lexical scope stack for Key to Value associations.
void clear() noexcept
Resets the structure by removing all frames and bindings.
size_t enter_scope()
Creates a new visibility level.
Value * lookup(const Key &key) noexcept
Searches for a key traversing all active scopes (from inside out).
bool insert(const Key &key, const Value &value)
Registers a new association in the current scope.
Value * lookup_local(const Key &key) noexcept
Searches for a key only in the innermost (current) scope.
void leave_scope()
Destroys the current visibility level and all its associations.
size_t depth() const noexcept
Queries the current depth of the scope stack.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
const char * compiler_symbol_kind_name(const Compiler_Symbol_Kind kind) noexcept
Returns a stable debug name for a symbol kind.
Compiler_Symbol_Kind
Generic symbol kinds reusable across multiple frontends.
Compiler_Symbol_Declare_Status
Result status for one declaration attempt.
and
Check uniqueness with explicit hash + equality functors.
size_t Compiler_Symbol_Id
@ Function
Function type such as fn(Int) -> Bool.
Structured result returned after one declaration attempt.
Compiler_Symbol_Id symbol_id
Newly inserted symbol or the conflicting local symbol.
Compiler_Symbol_Declare_Status status
bool inserted() const noexcept
Returns whether the declaration produced a new symbol.
Compiler_Symbol_Id related_symbol_id
Shadowed outer symbol or local duplicate.
bool shadowing() const noexcept
Returns whether the new declaration shadows one outer symbol.
bool duplicate_local() const noexcept
Returns whether the declaration collided with the current scope.
One reusable symbol record tracked by lexical bindings.
Compiler_Symbol_Id id
Stable symbol identifier, 1-based.
std::string name
Declared name.
Source_Span declaration_span
Declaration site.
Compiler_Symbol_Kind kind
Symbol category.
size_t scope_depth
Lexical depth where the symbol was introduced.
Half-open byte range inside a source file.
Lexical scope management using frame stacks.