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

Small reusable helper that allocates and connects HIR nodes. More...

#include <Compiler_HIR_Builder.H>

Collaboration diagram for Aleph::Compiler_HIR_Builder:
[legend]

Public Member Functions

 Compiler_HIR_Builder (Compiler_HIR_Context &context) noexcept
 Builds HIR nodes inside context.
 
Compiler_HIR_Context & context () const noexcept
 Returns the underlying ownership context.
 
Compiler_HIR_Module * make_module (const Source_Span &span={}) const
 Allocates one empty module.
 
Compiler_HIR_Block_Stmt * make_block (const Source_Span &lbrace={}, const Source_Span &rbrace={}) const
 Allocates one structured block statement.
 
Compiler_HIR_Function * make_function (std::string name, const Compiler_Type_Id type_id=0, const Source_Span &name_span={}, Compiler_HIR_Block_Stmt *body=nullptr, const Source_Span &span={}) const
 Allocates one function node without inserting it into any module.
 
Compiler_HIR_Invalid_Expr * make_invalid_expr (const Compiler_Type_Id type_id=0, const Source_Span &span={}) const
 Allocates one invalid expression placeholder.
 
Compiler_HIR_Constant_Expr * make_constant (const Compiler_HIR_Constant_Kind kind, const Compiler_Type_Id type_id, std::string text, const Source_Span &span={}, const bool bool_value=false) const
 Allocates one generic constant expression.
 
Compiler_HIR_Constant_Expr * make_unit_constant (const Compiler_Type_Id type_id, const Source_Span &span={}) const
 Allocates one unit constant expression.
 
Compiler_HIR_Constant_Expr * make_bool_constant (const bool value, const Compiler_Type_Id type_id, const Source_Span &span={}) const
 Allocates one boolean constant expression.
 
Compiler_HIR_Constant_Expr * make_integer_constant (const long long value, const Compiler_Type_Id type_id, const Source_Span &span={}) const
 Allocates one integer constant expression.
 
Compiler_HIR_Constant_Expr * make_string_constant (std::string text, const Compiler_Type_Id type_id, const Source_Span &span={}) const
 Allocates one string constant expression.
 
Compiler_HIR_Constant_Expr * make_character_constant (std::string text, const Compiler_Type_Id type_id, const Source_Span &span={}) const
 Allocates one character constant expression.
 
Compiler_HIR_Variable_Expr * make_variable (std::string name, const Compiler_Type_Id type_id=0, const Source_Span &span={}) const
 Allocates one variable-reference expression.
 
Compiler_HIR_Unary_Expr * make_unary (const Compiler_Operator_Kind op, Compiler_HIR_Expr *operand, const Compiler_Type_Id type_id=0, const Source_Span &operator_span={}) const
 Allocates one unary expression.
 
Compiler_HIR_Binary_Expr * make_binary (Compiler_HIR_Expr *lhs, const Compiler_Operator_Kind op, Compiler_HIR_Expr *rhs, const Compiler_Type_Id type_id=0, const Source_Span &operator_span={}) const
 Allocates one binary expression.
 
Compiler_HIR_Call_Expr * make_call (Compiler_HIR_Expr *callee, const Compiler_Type_Id type_id=0, const Source_Span &lparen_span={}, const Source_Span &rparen_span={}) const
 Allocates one call expression without arguments.
 
Compiler_HIR_Invalid_Stmt * make_invalid_stmt (const Source_Span &span={}) const
 Allocates one invalid statement placeholder.
 
Compiler_HIR_Eval_Stmt * make_eval_stmt (Compiler_HIR_Expr *expr, const Source_Span &span={}) const
 Allocates one expression statement.
 
Compiler_HIR_Let_Stmt * make_let_stmt (std::string name, const Compiler_Type_Id type_id, const Source_Span &name_span={}, Compiler_HIR_Expr *initializer=nullptr, const Source_Span &span={}) const
 Allocates one lexical binding statement.
 
Compiler_HIR_Return_Stmt * make_return_stmt (Compiler_HIR_Expr *value=nullptr, const Source_Span &span={}) const
 Allocates one return statement.
 
Compiler_HIR_If_Stmt * make_if_stmt (Compiler_HIR_Expr *condition, Compiler_HIR_Stmt *then_branch, Compiler_HIR_Stmt *else_branch=nullptr, const Source_Span &if_span={}, const Source_Span &else_span={}) const
 Allocates one structured conditional statement.
 
Compiler_HIR_While_Stmt * make_while_stmt (Compiler_HIR_Expr *condition, Compiler_HIR_Stmt *body, const Source_Span &keyword_span={}) const
 Allocates one structured while-loop statement.
 
Compiler_HIR_Break_Stmt * make_break_stmt (const Source_Span &span={}) const
 Allocates one break statement.
 
Compiler_HIR_Continue_Stmt * make_continue_stmt (const Source_Span &span={}) const
 Allocates one continue statement.
 

Static Public Member Functions

static void append_function (Compiler_HIR_Module &module, Compiler_HIR_Function *function)
 Appends one function to module and updates the module span.
 
static void append_top_level_statement (Compiler_HIR_Module &module, Compiler_HIR_Stmt *stmt)
 Appends one top-level statement to module and updates the span.
 
static void append_statement (Compiler_HIR_Block_Stmt &block, Compiler_HIR_Stmt *stmt)
 Appends one nested statement to block and updates the span.
 
static void set_body (Compiler_HIR_Function &function, Compiler_HIR_Block_Stmt *body) noexcept
 Attaches body to function and refreshes the aggregate span.
 
static Compiler_HIR_Param & add_parameter (Compiler_HIR_Function &function, std::string name, const Compiler_Type_Id type_id, const Source_Span &span={})
 Adds one parameter metadata entry to function.
 
static void append_argument (Compiler_HIR_Call_Expr &call, Compiler_HIR_Expr *argument)
 Appends one argument to call and updates the aggregate span.
 

Static Private Member Functions

static void merge_span (Source_Span &dst, const Source_Span &src) noexcept
 

Private Attributes

Compiler_HIR_Context * hir = nullptr
 

Detailed Description

Small reusable helper that allocates and connects HIR nodes.

The builder is intentionally lightweight: it owns no memory itself and only wraps a Compiler_HIR_Context. All nodes remain owned by the associated context.

Definition at line 53 of file Compiler_HIR_Builder.H.

Constructor & Destructor Documentation

◆ Compiler_HIR_Builder()

Aleph::Compiler_HIR_Builder::Compiler_HIR_Builder ( Compiler_HIR_Context &  context)
inlineexplicitnoexcept

Builds HIR nodes inside context.

Definition at line 71 of file Compiler_HIR_Builder.H.

Member Function Documentation

◆ add_parameter()

static Compiler_HIR_Param & Aleph::Compiler_HIR_Builder::add_parameter ( Compiler_HIR_Function &  function,
std::string  name,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Adds one parameter metadata entry to function.

Definition at line 139 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ append_argument()

static void Aleph::Compiler_HIR_Builder::append_argument ( Compiler_HIR_Call_Expr &  call,
Compiler_HIR_Expr *  argument 
)
inlinestatic

Appends one argument to call and updates the aggregate span.

Definition at line 244 of file Compiler_HIR_Builder.H.

References ah_runtime_error_unless, Aleph::Compiler_HIR_Call_Expr::arguments, Aleph::blossom_maximum_cardinality_matching(), merge_span(), and Aleph::Compiler_HIR_Node::span.

Referenced by main(), and TEST().

◆ append_function()

static void Aleph::Compiler_HIR_Builder::append_function ( Compiler_HIR_Module &  module,
Compiler_HIR_Function *  function 
)
inlinestatic

Appends one function to module and updates the module span.

Definition at line 86 of file Compiler_HIR_Builder.H.

References ah_runtime_error_unless, merge_span(), and Aleph::Compiler_HIR_Node::span.

Referenced by main(), and TEST().

◆ append_statement()

static void Aleph::Compiler_HIR_Builder::append_statement ( Compiler_HIR_Block_Stmt &  block,
Compiler_HIR_Stmt *  stmt 
)
inlinestatic

Appends one nested statement to block and updates the span.

Definition at line 111 of file Compiler_HIR_Builder.H.

References ah_runtime_error_unless, merge_span(), Aleph::Compiler_HIR_Node::span, and Aleph::Compiler_SSA_Block::span.

Referenced by main(), and TEST().

◆ append_top_level_statement()

static void Aleph::Compiler_HIR_Builder::append_top_level_statement ( Compiler_HIR_Module &  module,
Compiler_HIR_Stmt *  stmt 
)
inlinestatic

Appends one top-level statement to module and updates the span.

Definition at line 95 of file Compiler_HIR_Builder.H.

References ah_runtime_error_unless, merge_span(), and Aleph::Compiler_HIR_Node::span.

Referenced by main(), and TEST().

◆ context()

Compiler_HIR_Context & Aleph::Compiler_HIR_Builder::context ( ) const
inlinenoexcept

Returns the underlying ownership context.

Definition at line 74 of file Compiler_HIR_Builder.H.

References hir.

◆ make_binary()

Compiler_HIR_Binary_Expr * Aleph::Compiler_HIR_Builder::make_binary ( Compiler_HIR_Expr *  lhs,
const Compiler_Operator_Kind  op,
Compiler_HIR_Expr *  rhs,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  operator_span = {} 
) const
inline

Allocates one binary expression.

Definition at line 225 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_block()

Compiler_HIR_Block_Stmt * Aleph::Compiler_HIR_Builder::make_block ( const Source_Span &  lbrace = {},
const Source_Span &  rbrace = {} 
) const
inline

Allocates one structured block statement.

Definition at line 104 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_bool_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_bool_constant ( const bool  value,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
) const
inline

Allocates one boolean constant expression.

Definition at line 174 of file Compiler_HIR_Builder.H.

◆ make_break_stmt()

Compiler_HIR_Break_Stmt * Aleph::Compiler_HIR_Builder::make_break_stmt ( const Source_Span &  span = {}) const
inline

Allocates one break statement.

Definition at line 300 of file Compiler_HIR_Builder.H.

◆ make_call()

Compiler_HIR_Call_Expr * Aleph::Compiler_HIR_Builder::make_call ( Compiler_HIR_Expr *  callee,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  lparen_span = {},
const Source_Span &  rparen_span = {} 
) const
inline

Allocates one call expression without arguments.

Definition at line 235 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_character_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_character_constant ( std::string  text,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
) const
inline

Allocates one character constant expression.

Definition at line 200 of file Compiler_HIR_Builder.H.

◆ make_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_constant ( const Compiler_HIR_Constant_Kind  kind,
const Compiler_Type_Id  type_id,
std::string  text,
const Source_Span &  span = {},
const bool  bool_value = false 
) const
inline

Allocates one generic constant expression.

Definition at line 157 of file Compiler_HIR_Builder.H.

◆ make_continue_stmt()

Compiler_HIR_Continue_Stmt * Aleph::Compiler_HIR_Builder::make_continue_stmt ( const Source_Span &  span = {}) const
inline

Allocates one continue statement.

Definition at line 306 of file Compiler_HIR_Builder.H.

◆ make_eval_stmt()

Compiler_HIR_Eval_Stmt * Aleph::Compiler_HIR_Builder::make_eval_stmt ( Compiler_HIR_Expr *  expr,
const Source_Span &  span = {} 
) const
inline

Allocates one expression statement.

Definition at line 259 of file Compiler_HIR_Builder.H.

◆ make_function()

Compiler_HIR_Function * Aleph::Compiler_HIR_Builder::make_function ( std::string  name,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  name_span = {},
Compiler_HIR_Block_Stmt *  body = nullptr,
const Source_Span &  span = {} 
) const
inline

Allocates one function node without inserting it into any module.

Definition at line 120 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_if_stmt()

Compiler_HIR_If_Stmt * Aleph::Compiler_HIR_Builder::make_if_stmt ( Compiler_HIR_Expr *  condition,
Compiler_HIR_Stmt *  then_branch,
Compiler_HIR_Stmt *  else_branch = nullptr,
const Source_Span &  if_span = {},
const Source_Span &  else_span = {} 
) const
inline

Allocates one structured conditional statement.

Definition at line 282 of file Compiler_HIR_Builder.H.

◆ make_integer_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_integer_constant ( const long long  value,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
) const
inline

Allocates one integer constant expression.

Definition at line 183 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_invalid_expr()

Compiler_HIR_Invalid_Expr * Aleph::Compiler_HIR_Builder::make_invalid_expr ( const Compiler_Type_Id  type_id = 0,
const Source_Span &  span = {} 
) const
inline

Allocates one invalid expression placeholder.

Definition at line 150 of file Compiler_HIR_Builder.H.

◆ make_invalid_stmt()

Compiler_HIR_Invalid_Stmt * Aleph::Compiler_HIR_Builder::make_invalid_stmt ( const Source_Span &  span = {}) const
inline

Allocates one invalid statement placeholder.

Definition at line 253 of file Compiler_HIR_Builder.H.

◆ make_let_stmt()

Compiler_HIR_Let_Stmt * Aleph::Compiler_HIR_Builder::make_let_stmt ( std::string  name,
const Compiler_Type_Id  type_id,
const Source_Span &  name_span = {},
Compiler_HIR_Expr *  initializer = nullptr,
const Source_Span &  span = {} 
) const
inline

Allocates one lexical binding statement.

Definition at line 265 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_module()

Compiler_HIR_Module * Aleph::Compiler_HIR_Builder::make_module ( const Source_Span &  span = {}) const
inline

Allocates one empty module.

Definition at line 80 of file Compiler_HIR_Builder.H.

Referenced by main().

◆ make_return_stmt()

Compiler_HIR_Return_Stmt * Aleph::Compiler_HIR_Builder::make_return_stmt ( Compiler_HIR_Expr *  value = nullptr,
const Source_Span &  span = {} 
) const
inline

Allocates one return statement.

Definition at line 275 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_string_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_string_constant ( std::string  text,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
) const
inline

Allocates one string constant expression.

Definition at line 192 of file Compiler_HIR_Builder.H.

◆ make_unary()

Compiler_HIR_Unary_Expr * Aleph::Compiler_HIR_Builder::make_unary ( const Compiler_Operator_Kind  op,
Compiler_HIR_Expr *  operand,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  operator_span = {} 
) const
inline

Allocates one unary expression.

Definition at line 216 of file Compiler_HIR_Builder.H.

◆ make_unit_constant()

Compiler_HIR_Constant_Expr * Aleph::Compiler_HIR_Builder::make_unit_constant ( const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
) const
inline

Allocates one unit constant expression.

Definition at line 167 of file Compiler_HIR_Builder.H.

◆ make_variable()

Compiler_HIR_Variable_Expr * Aleph::Compiler_HIR_Builder::make_variable ( std::string  name,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  span = {} 
) const
inline

Allocates one variable-reference expression.

Definition at line 208 of file Compiler_HIR_Builder.H.

Referenced by main(), and TEST().

◆ make_while_stmt()

Compiler_HIR_While_Stmt * Aleph::Compiler_HIR_Builder::make_while_stmt ( Compiler_HIR_Expr *  condition,
Compiler_HIR_Stmt *  body,
const Source_Span &  keyword_span = {} 
) const
inline

Allocates one structured while-loop statement.

Definition at line 292 of file Compiler_HIR_Builder.H.

◆ merge_span()

static void Aleph::Compiler_HIR_Builder::merge_span ( Source_Span &  dst,
const Source_Span &  src 
)
inlinestaticprivatenoexcept

◆ set_body()

static void Aleph::Compiler_HIR_Builder::set_body ( Compiler_HIR_Function &  function,
Compiler_HIR_Block_Stmt *  body 
)
inlinestaticnoexcept

Attaches body to function and refreshes the aggregate span.

Definition at line 130 of file Compiler_HIR_Builder.H.

References merge_span(), and Aleph::Compiler_HIR_Node::span.

Referenced by main(), and TEST().

Member Data Documentation

◆ hir

Compiler_HIR_Context* Aleph::Compiler_HIR_Builder::hir = nullptr
private

Definition at line 55 of file Compiler_HIR_Builder.H.

Referenced by context().


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