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

Structural unifier for compiler types. More...

#include <tpl_constraints.H>

Collaboration diagram for Aleph::Compiler_Type_Unifier:
[legend]

Public Member Functions

 Compiler_Type_Unifier (Compiler_Type_Context &ctx) noexcept
 Constructs a unifier operating over ctx.
 
void clear () noexcept
 Clears substitutions and the last stored result.
 
const Compiler_Unify_Result & last_result () const noexcept
 Returns the last result produced by unify() or solve().
 
const Compiler_Type_Substitution & substitution () const noexcept
 Returns the accumulated substitution.
 
Compiler_Type_Id apply (const Compiler_Type_Id id)
 Applies the current substitution to id.
 
Compiler_Unify_Result unify (const Compiler_Type_Id lhs, const Compiler_Type_Id rhs)
 Attempts to unify lhs and rhs.
 
Compiler_Unify_Result solve (const Compiler_Type_Constraint_Set &constraints)
 Solves a whole ordered set of type constraints.
 
std::string dump_substitution ()
 Dumps the current substitution in a deterministic format.
 

Private Member Functions

Compiler_Unify_Result fail (const Compiler_Unify_Result_Kind kind, const Compiler_Type_Id lhs, const Compiler_Type_Id rhs, const std::string &message, const Source_Span &span={}) noexcept
 
Compiler_Type_Id resolve (const Compiler_Type_Id id) const
 
bool occurs_in (const Compiler_Type_Id variable, const Compiler_Type_Id candidate)
 
Compiler_Unify_Result bind_variable (const Compiler_Type_Id variable, const Compiler_Type_Id replacement)
 

Static Private Member Functions

static Compiler_Unify_Result success () noexcept
 

Private Attributes

Compiler_Type_Context * context = nullptr
 
Compiler_Type_Substitution subst
 
Compiler_Unify_Result last
 

Detailed Description

Structural unifier for compiler types.

Definition at line 378 of file tpl_constraints.H.

Constructor & Destructor Documentation

◆ Compiler_Type_Unifier()

Aleph::Compiler_Type_Unifier::Compiler_Type_Unifier ( Compiler_Type_Context &  ctx)
inlineexplicitnoexcept

Constructs a unifier operating over ctx.

Definition at line 493 of file tpl_constraints.H.

Member Function Documentation

◆ apply()

◆ bind_variable()

◆ clear()

void Aleph::Compiler_Type_Unifier::clear ( )
inlinenoexcept

Clears substitutions and the last stored result.

Definition at line 498 of file tpl_constraints.H.

References Aleph::Compiler_Type_Substitution::clear(), last, and subst.

Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::clear().

◆ dump_substitution()

std::string Aleph::Compiler_Type_Unifier::dump_substitution ( )
inline

Dumps the current substitution in a deterministic format.

Definition at line 653 of file tpl_constraints.H.

References context, subst, and Aleph::Compiler_Type_Substitution::to_string().

Referenced by main(), and TEST().

◆ fail()

Compiler_Unify_Result Aleph::Compiler_Type_Unifier::fail ( const Compiler_Unify_Result_Kind  kind,
const Compiler_Type_Id  lhs,
const Compiler_Type_Id  rhs,
const std::string &  message,
const Source_Span &  span = {} 
)
inlineprivatenoexcept

Definition at line 391 of file tpl_constraints.H.

Referenced by bind_variable(), and unify().

◆ last_result()

const Compiler_Unify_Result & Aleph::Compiler_Type_Unifier::last_result ( ) const
inlinenoexcept

Returns the last result produced by unify() or solve().

Definition at line 505 of file tpl_constraints.H.

References last.

◆ occurs_in()

◆ resolve()

Compiler_Type_Id Aleph::Compiler_Type_Unifier::resolve ( const Compiler_Type_Id  id) const
inlineprivate

◆ solve()

Compiler_Unify_Result Aleph::Compiler_Type_Unifier::solve ( const Compiler_Type_Constraint_Set &  constraints)
inline

Solves a whole ordered set of type constraints.

Constraints are solved in insertion order and the first failing result is returned with the corresponding span.

Parameters
constraintsOrdered equality constraints.
Returns
Final success result or the first failure encountered.

Definition at line 632 of file tpl_constraints.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Constraint_Set< T >::constraint(), last, Aleph::Equality_Constraint< T >::lhs, Aleph::Equality_Constraint< T >::message, Aleph::Equality_Constraint< T >::rhs, Aleph::Constraint_Set< T >::size(), Aleph::Equality_Constraint< T >::span, success(), and unify().

Referenced by main(), TEST(), and TEST().

◆ substitution()

const Compiler_Type_Substitution & Aleph::Compiler_Type_Unifier::substitution ( ) const
inlinenoexcept

Returns the accumulated substitution.

Definition at line 511 of file tpl_constraints.H.

References subst.

◆ success()

static Compiler_Unify_Result Aleph::Compiler_Type_Unifier::success ( )
inlinestaticprivatenoexcept

Definition at line 385 of file tpl_constraints.H.

Referenced by bind_variable(), solve(), and unify().

◆ unify()

Compiler_Unify_Result Aleph::Compiler_Type_Unifier::unify ( const Compiler_Type_Id  lhs,
const Compiler_Type_Id  rhs 
)
inline

Attempts to unify lhs and rhs.

On success, the internal substitution is updated.

Parameters
lhsLeft-hand type.
rhsRight-hand type.
Returns
Success or the first detected failure.

Definition at line 534 of file tpl_constraints.H.

References Aleph::Arity_Mismatch, bind_variable(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Builtin, context, Aleph::Enum, fail(), Aleph::Function, Aleph::Invalid_Type, Aleph::Kind_Mismatch, last, resolve(), Aleph::Struct, success(), Aleph::Compiler_Type_Context::to_string(), Aleph::Tuple, Aleph::Compiler_Type_Context::type(), Aleph::Type_Variable, and unify().

Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::require_unify(), solve(), TEST(), TEST(), TEST(), TEST(), and unify().

Member Data Documentation

◆ context

Compiler_Type_Context* Aleph::Compiler_Type_Unifier::context = nullptr
private

Definition at line 380 of file tpl_constraints.H.

Referenced by apply(), bind_variable(), dump_substitution(), occurs_in(), and unify().

◆ last

Compiler_Unify_Result Aleph::Compiler_Type_Unifier::last
private

Definition at line 382 of file tpl_constraints.H.

Referenced by clear(), last_result(), solve(), and unify().

◆ subst

Compiler_Type_Substitution Aleph::Compiler_Type_Unifier::subst
private

Definition at line 381 of file tpl_constraints.H.

Referenced by apply(), bind_variable(), clear(), dump_substitution(), resolve(), and substitution().


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