|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Arena-backed ownership context for AST nodes. More...
#include <Compiler_AST.H>
Classes | |
| struct | Owned_Object |
| Internal tracking for objects with destructors. More... | |
Public Member Functions | |
| Compiler_Ast_Context (const size_t arena_size=AhArenaAllocator::DEFAULT_SIZE) | |
| Constructs a context with the specified arena capacity. | |
| Compiler_Ast_Context (const Compiler_Ast_Context &)=delete | |
| Compiler_Ast_Context & | operator= (const Compiler_Ast_Context &)=delete |
| ~Compiler_Ast_Context () noexcept | |
| Destroys the context and all managed nodes. | |
| template<typename T , typename... Args> | |
| T * | make (Args &&...args) |
Allocates and constructs an AST node of type T. | |
| void | reset () noexcept |
| Reclaims all memory and destroys managed nodes. | |
| size_t | allocated_size () const noexcept |
| Returns the total bytes currently used in the arena. | |
| size_t | capacity () const noexcept |
| Returns the total capacity of the arena. | |
Private Attributes | |
| AhArenaAllocator | arena_ |
| Underlying memory arena. | |
| DynArray< Owned_Object > | owned_ |
| Tracked objects for destruction. | |
Arena-backed ownership context for AST nodes.
The context uses an AhArenaAllocator for fast allocations and low fragmentation. It also tracks destructors to ensure that nodes with non-trivial members (like std::string or DynArray) are properly cleaned up.
Definition at line 328 of file Compiler_AST.H.
|
inlineexplicit |
Constructs a context with the specified arena capacity.
| arena_size | Capacity in bytes (defaults to arena's default size). |
| std::runtime_error | If memory cannot be reserved. |
Definition at line 348 of file Compiler_AST.H.
|
delete |
|
inlinenoexcept |
Destroys the context and all managed nodes.
Definition at line 361 of file Compiler_AST.H.
|
inlinenoexcept |
Returns the total bytes currently used in the arena.
Definition at line 419 of file Compiler_AST.H.
References Aleph::AhArenaAllocator::allocated_size().
Referenced by TEST().
|
inlinenoexcept |
Returns the total capacity of the arena.
Definition at line 430 of file Compiler_AST.H.
References Aleph::AhArenaAllocator::capacity().
Allocates and constructs an AST node of type T.
Uses arena allocation for performance. If T has a non-trivial destructor, it is registered for automatic cleanup during context reset.
| T | Node type to instantiate. |
| Args | Constructor argument types. |
| args | Values passed to the constructor of T. |
reset() is called. | std::runtime_error | If the arena is out of memory. |
Definition at line 380 of file Compiler_AST.H.
References ah_runtime_error_unless, Aleph::DynArray< T >::append(), and Aleph::blossom_maximum_cardinality_matching().
Referenced by Aleph::Compiler_Driver::merge_modules_from_order(), Aleph::Compiler_MVP_Frontend::merge_modules_from_order(), Aleph::Compiler_Parser::parse_block_statement(), Aleph::Compiler_Parser::parse_break_statement(), Aleph::Compiler_Parser::parse_call_suffix(), Aleph::Compiler_Parser::parse_continue_statement(), Aleph::Compiler_Parser::parse_enum_declaration(), Aleph::Compiler_Parser::parse_expression(), Aleph::Compiler_Parser::parse_expression_statement(), Aleph::Compiler_Parser::parse_function(), Aleph::Compiler_Parser::parse_function_type(), Aleph::Compiler_Parser::parse_grouping_expr(), Aleph::Compiler_Parser::parse_if_statement(), Aleph::Compiler_Parser::parse_import_declaration(), Aleph::Compiler_Parser::parse_let_statement(), Aleph::Compiler_Parser::parse_named_type(), Aleph::Compiler_Parser::parse_parenthesized_type(), Aleph::Compiler_Parser::parse_primary(), Aleph::Compiler_Parser::parse_return_statement(), Aleph::Compiler_Parser::parse_struct_declaration(), Aleph::Compiler_Parser::parse_type_alias_declaration(), Aleph::Compiler_Parser::parse_unary(), Aleph::Compiler_Parser::parse_while_statement(), TEST(), and TEST().
|
delete |
|
inlinenoexcept |
Reclaims all memory and destroys managed nodes.
Calling this method invalidates all pointers previously returned by make(). Useful for recycling the context between compilation units.
Definition at line 401 of file Compiler_AST.H.
References Aleph::DynArray< T >::access(), Aleph::and, Aleph::DynArray< T >::clear(), Aleph::AhArenaAllocator::reset(), and Aleph::DynArray< T >::size().
Referenced by Aleph::Compiler_Driver::clear(), Aleph::Compiler_MVP_Frontend::clear(), and TEST().
|
private |
Underlying memory arena.
Definition at line 337 of file Compiler_AST.H.
|
private |
Tracked objects for destruction.
Definition at line 338 of file Compiler_AST.H.