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

Name-resolution and basic semantic checker for the MVP AST. More...

#include <Compiler_Sema.H>

Collaboration diagram for Aleph::Compiler_Semantic_Analyzer:
[legend]

Public Member Functions

 Compiler_Semantic_Analyzer (Diagnostic_Engine *dx=nullptr, const Compiler_Semantic_Options &opts={})
 Constructs a semantic analyzer.
 
void clear () noexcept
 Clears previously collected semantic state.
 
void analyze_module (const Compiler_Module *module)
 Analyzes a parsed module.
 
size_t symbol_count () const noexcept
 Returns the number of collected symbols.
 
size_t resolution_count () const noexcept
 Returns the number of identifier resolutions.
 
const Compiler_Symbol & symbol (const Compiler_Symbol_Id id) const
 Returns symbol id.
 
const Compiler_Name_Resolution & resolution (const size_t i) const
 Returns resolution record i.
 
const Compiler_Symbol * resolved_symbol (const Compiler_Expr *expr) const noexcept
 Returns the resolved symbol for an identifier expression.
 
std::string dump_symbols () const
 Dumps the current symbol table in a deterministic text format.
 

Private Member Functions

void emit_error (const Source_Span &span, const std::string &message, const std::string &code, const std::string &note="", const std::string &help="") const
 
Compiler_Symbol_Id declare_symbol (const Compiler_Symbol_Kind kind, const std::string &name, const Source_Span &span)
 
void record_resolution (const Compiler_Expr *expr, const Compiler_Symbol_Id symbol_id)
 
void declare_type_name (const std::string &name, const Source_Span &span)
 
void analyze_imports (const Compiler_Module *module) const
 
void analyze_expr (const Compiler_Expr *expr)
 
void analyze_block (const Compiler_Block_Stmt *block)
 
void analyze_stmt (const Compiler_Stmt *stmt)
 
void analyze_function (const Compiler_Function_Decl *fn)
 

Private Attributes

Diagnostic_Engine * diagnostics = nullptr
 
Compiler_Semantic_Options options
 
DynArray< Compiler_Name_Resolution > resolutions
 
DynMapTree< const Compiler_Expr *, size_t > resolution_index
 
Compiler_Symbol_Bindings value_bindings
 
Compiler_Symbol_Bindings type_bindings
 
size_t function_depth = 0
 
size_t loop_depth = 0
 

Detailed Description

Name-resolution and basic semantic checker for the MVP AST.

Definition at line 76 of file Compiler_Sema.H.

Constructor & Destructor Documentation

◆ Compiler_Semantic_Analyzer()

Aleph::Compiler_Semantic_Analyzer::Compiler_Semantic_Analyzer ( Diagnostic_Engine *  dx = nullptr,
const Compiler_Semantic_Options &  opts = {} 
)
inlineexplicit

Constructs a semantic analyzer.

Parameters
dxOptional diagnostic sink to receive semantic errors.
optsAnalyzer behavior options.

Definition at line 345 of file Compiler_Sema.H.

Member Function Documentation

◆ analyze_block()

void Aleph::Compiler_Semantic_Analyzer::analyze_block ( const Compiler_Block_Stmt *  block)
inlineprivate

◆ analyze_expr()

◆ analyze_function()

◆ analyze_imports()

void Aleph::Compiler_Semantic_Analyzer::analyze_imports ( const Compiler_Module *  module) const
inlineprivate

◆ analyze_module()

void Aleph::Compiler_Semantic_Analyzer::analyze_module ( const Compiler_Module *  module)
inline

◆ analyze_stmt()

◆ clear()

void Aleph::Compiler_Semantic_Analyzer::clear ( )
inlinenoexcept

◆ declare_symbol()

◆ declare_type_name()

void Aleph::Compiler_Semantic_Analyzer::declare_type_name ( const std::string &  name,
const Source_Span &  span 
)
inlineprivate

◆ dump_symbols()

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

Dumps the current symbol table in a deterministic text format.

Definition at line 460 of file Compiler_Sema.H.

References Aleph::Compiler_Symbol_Bindings::dump_symbols(), and value_bindings.

◆ emit_error()

void Aleph::Compiler_Semantic_Analyzer::emit_error ( const Source_Span &  span,
const std::string &  message,
const std::string &  code,
const std::string &  note = "",
const std::string &  help = "" 
) const
inlineprivate

◆ record_resolution()

void Aleph::Compiler_Semantic_Analyzer::record_resolution ( const Compiler_Expr *  expr,
const Compiler_Symbol_Id  symbol_id 
)
inlineprivate

◆ resolution()

const Compiler_Name_Resolution & Aleph::Compiler_Semantic_Analyzer::resolution ( const size_t  i) const
inline

Returns resolution record i.

Parameters
iResolution index.
Returns
Stored resolution.
Exceptions
std::out_of_rangeIf i is invalid.

Definition at line 431 of file Compiler_Sema.H.

References ah_out_of_range_error_unless, and resolutions.

◆ resolution_count()

size_t Aleph::Compiler_Semantic_Analyzer::resolution_count ( ) const
inlinenoexcept

Returns the number of identifier resolutions.

Definition at line 409 of file Compiler_Sema.H.

References resolutions.

◆ resolved_symbol()

const Compiler_Symbol * Aleph::Compiler_Semantic_Analyzer::resolved_symbol ( const Compiler_Expr *  expr) const
inlinenoexcept

Returns the resolved symbol for an identifier expression.

Parameters
exprIdentifier expression node.
Returns
Resolved symbol, or nullptr if unresolved/not recorded.

Definition at line 443 of file Compiler_Sema.H.

References Aleph::blossom_maximum_cardinality_matching(), resolution_index, resolutions, Aleph::Compiler_Symbol_Bindings::symbol(), Aleph::Compiler_Symbol_Bindings::symbol_count(), and value_bindings.

◆ symbol()

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

Returns symbol id.

Parameters
id1-based symbol id.
Returns
Symbol record.
Exceptions
std::out_of_rangeIf id is invalid.

Definition at line 420 of file Compiler_Sema.H.

References Aleph::Compiler_Symbol_Bindings::symbol(), and value_bindings.

◆ symbol_count()

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

Returns the number of collected symbols.

Definition at line 403 of file Compiler_Sema.H.

References Aleph::Compiler_Symbol_Bindings::symbol_count(), and value_bindings.

Member Data Documentation

◆ diagnostics

Diagnostic_Engine* Aleph::Compiler_Semantic_Analyzer::diagnostics = nullptr
private

Definition at line 78 of file Compiler_Sema.H.

Referenced by emit_error().

◆ function_depth

size_t Aleph::Compiler_Semantic_Analyzer::function_depth = 0
private

Definition at line 84 of file Compiler_Sema.H.

Referenced by analyze_function(), analyze_stmt(), and clear().

◆ loop_depth

size_t Aleph::Compiler_Semantic_Analyzer::loop_depth = 0
private

Definition at line 85 of file Compiler_Sema.H.

Referenced by analyze_stmt(), and clear().

◆ options

Compiler_Semantic_Options Aleph::Compiler_Semantic_Analyzer::options
private

Definition at line 79 of file Compiler_Sema.H.

Referenced by declare_symbol().

◆ resolution_index

DynMapTree<const Compiler_Expr *, size_t> Aleph::Compiler_Semantic_Analyzer::resolution_index
private

Definition at line 81 of file Compiler_Sema.H.

Referenced by clear(), record_resolution(), and resolved_symbol().

◆ resolutions

DynArray<Compiler_Name_Resolution> Aleph::Compiler_Semantic_Analyzer::resolutions
private

◆ type_bindings

Compiler_Symbol_Bindings Aleph::Compiler_Semantic_Analyzer::type_bindings
private

Definition at line 83 of file Compiler_Sema.H.

Referenced by analyze_module(), clear(), and declare_type_name().

◆ value_bindings

Compiler_Symbol_Bindings Aleph::Compiler_Semantic_Analyzer::value_bindings
private

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