|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Name-resolution and basic semantic checker for the MVP AST. More...
#include <Compiler_Sema.H>
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 ¬e="", 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 |
Name-resolution and basic semantic checker for the MVP AST.
Definition at line 76 of file Compiler_Sema.H.
|
inlineexplicit |
Constructs a semantic analyzer.
| dx | Optional diagnostic sink to receive semantic errors. |
| opts | Analyzer behavior options. |
Definition at line 345 of file Compiler_Sema.H.
|
inlineprivate |
Definition at line 237 of file Compiler_Sema.H.
References analyze_stmt(), Aleph::Compiler_Symbol_Bindings::enter_scope(), Aleph::Compiler_Symbol_Bindings::leave_scope(), and value_bindings.
Referenced by analyze_function(), and analyze_stmt().
|
inlineprivate |
Definition at line 182 of file Compiler_Sema.H.
References analyze_expr(), Aleph::Binary, Aleph::Bool_Literal, Aleph::Call, Aleph::Char_Literal, emit_error(), Aleph::Grouping, Aleph::Identifier, Aleph::Integer_Literal, Aleph::Invalid, Aleph::Compiler_Expr::kind, Aleph::Compiler_Symbol_Bindings::lookup(), record_resolution(), Aleph::String_Literal, Aleph::Unary, and value_bindings.
Referenced by analyze_expr(), and analyze_stmt().
|
inlineprivate |
Definition at line 322 of file Compiler_Sema.H.
References analyze_block(), Aleph::blossom_maximum_cardinality_matching(), declare_symbol(), Aleph::Compiler_Symbol_Bindings::enter_scope(), function_depth, Aleph::Compiler_Symbol_Bindings::leave_scope(), Aleph::Parameter, and value_bindings.
Referenced by analyze_module().
|
inlineprivate |
Definition at line 148 of file Compiler_Sema.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), emit_error(), Aleph::Import, and Aleph::Compiler_Module::source_name.
Referenced by analyze_module().
|
inline |
Analyzes a parsed module.
Existing semantic state is discarded before the new analysis.
| module | Parsed module to analyze. |
Definition at line 367 of file Compiler_Sema.H.
References analyze_function(), analyze_imports(), analyze_stmt(), Aleph::blossom_maximum_cardinality_matching(), clear(), declare_symbol(), declare_type_name(), Aleph::Compiler_Symbol_Bindings::enter_scope(), Aleph::Function, Aleph::Compiler_Module::functions, Aleph::Compiler_Symbol_Bindings::leave_scope(), Aleph::Compiler_Module::statements, type_bindings, and value_bindings.
Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::analyze_module().
|
inlineprivate |
Definition at line 248 of file Compiler_Sema.H.
References analyze_block(), analyze_expr(), analyze_stmt(), Aleph::Block, Aleph::blossom_maximum_cardinality_matching(), Aleph::Break, Aleph::Continue, declare_symbol(), emit_error(), Aleph::Expr, function_depth, Aleph::Global, Aleph::If, Aleph::Invalid, Aleph::Compiler_Stmt::kind, Aleph::Let, Aleph::Local, loop_depth, Aleph::Return, and Aleph::While.
Referenced by analyze_block(), analyze_module(), and analyze_stmt().
|
inlinenoexcept |
Clears previously collected semantic state.
Definition at line 351 of file Compiler_Sema.H.
References Aleph::Compiler_Symbol_Bindings::clear(), function_depth, loop_depth, resolution_index, resolutions, type_bindings, and value_bindings.
Referenced by analyze_module(), and Aleph::Compiler_Typed_Semantic_Analyzer::clear().
|
inlineprivate |
Definition at line 104 of file Compiler_Sema.H.
References Aleph::Compiler_Semantic_Options::allow_shadowing, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Compiler_Symbol_Bindings::declare(), emit_error(), options, and value_bindings.
Referenced by analyze_function(), analyze_module(), and analyze_stmt().
|
inlineprivate |
Definition at line 138 of file Compiler_Sema.H.
References Aleph::Compiler_Symbol_Bindings::declare(), emit_error(), Aleph::Type, and type_bindings.
Referenced by analyze_module().
|
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.
|
inlineprivate |
Definition at line 87 of file Compiler_Sema.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Diagnostic_Builder::code(), Aleph::code(), diagnostics, Aleph::Diagnostic_Builder::emit(), Aleph::Diagnostic_Engine::error(), Aleph::Diagnostic_Builder::help(), Aleph::message(), and Aleph::Diagnostic_Builder::note().
Referenced by analyze_expr(), analyze_imports(), analyze_stmt(), declare_symbol(), and declare_type_name().
|
inlineprivate |
Definition at line 121 of file Compiler_Sema.H.
References Aleph::blossom_maximum_cardinality_matching(), resolution_index, and resolutions.
Referenced by analyze_expr().
|
inline |
Returns resolution record i.
| i | Resolution index. |
| std::out_of_range | If i is invalid. |
Definition at line 431 of file Compiler_Sema.H.
References ah_out_of_range_error_unless, and resolutions.
|
inlinenoexcept |
Returns the number of identifier resolutions.
Definition at line 409 of file Compiler_Sema.H.
References resolutions.
|
inlinenoexcept |
Returns the resolved symbol for an identifier expression.
| expr | Identifier expression node. |
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.
|
inline |
Returns symbol id.
| id | 1-based symbol id. |
| std::out_of_range | If id is invalid. |
Definition at line 420 of file Compiler_Sema.H.
References Aleph::Compiler_Symbol_Bindings::symbol(), and value_bindings.
|
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.
|
private |
Definition at line 78 of file Compiler_Sema.H.
Referenced by emit_error().
|
private |
Definition at line 84 of file Compiler_Sema.H.
Referenced by analyze_function(), analyze_stmt(), and clear().
|
private |
Definition at line 85 of file Compiler_Sema.H.
Referenced by analyze_stmt(), and clear().
|
private |
Definition at line 79 of file Compiler_Sema.H.
Referenced by declare_symbol().
|
private |
Definition at line 81 of file Compiler_Sema.H.
Referenced by clear(), record_resolution(), and resolved_symbol().
|
private |
Definition at line 80 of file Compiler_Sema.H.
Referenced by clear(), record_resolution(), resolution(), resolution_count(), and resolved_symbol().
|
private |
Definition at line 83 of file Compiler_Sema.H.
Referenced by analyze_module(), clear(), and declare_type_name().
|
private |
Definition at line 82 of file Compiler_Sema.H.
Referenced by analyze_block(), analyze_expr(), analyze_function(), analyze_module(), clear(), declare_symbol(), dump_symbols(), resolved_symbol(), symbol(), and symbol_count().