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

Mutable substitution from type variables to replacement types. More...

#include <tpl_constraints.H>

Collaboration diagram for Aleph::Compiler_Type_Substitution:
[legend]

Classes

struct  Binding
 One variable binding inside the substitution. More...
 

Public Member Functions

size_t size () const noexcept
 Returns the number of stored variable bindings.
 
bool empty () const noexcept
 Returns whether the substitution is empty.
 
void clear () noexcept
 Removes every binding.
 
const Binding & binding (const size_t i) const
 Returns binding i.
 
Compiler_Type_Id * lookup (const Compiler_Type_Id variable) noexcept
 Looks up a bound replacement for variable.
 
const Compiler_Type_Id * lookup (const Compiler_Type_Id variable) const noexcept
 Looks up a bound replacement for variable.
 
void bind (const Compiler_Type_Id variable, const Compiler_Type_Id replacement)
 Binds or updates one type-variable replacement.
 
Compiler_Type_Id apply (Compiler_Type_Context &ctx, const Compiler_Type_Id id) const
 Applies the substitution to id.
 
std::string to_string (Compiler_Type_Context &ctx) const
 Renders all bindings in insertion order.
 

Private Member Functions

Compiler_Type_Id resolve_alias (const Compiler_Type_Id id) const
 

Private Attributes

DynArray< Binding > bindings
 

Detailed Description

Mutable substitution from type variables to replacement types.

Definition at line 190 of file tpl_constraints.H.

Member Function Documentation

◆ apply()

Compiler_Type_Id Aleph::Compiler_Type_Substitution::apply ( Compiler_Type_Context &  ctx,
const Compiler_Type_Id  id 
) const
inline

Applies the substitution to id.

Composite types are rebuilt only when one of their children changes. This may append new nodes to ctx.

Parameters
ctxType context used to inspect and rebuild types.
idType to normalize.
Returns
Normalized type id.

Definition at line 302 of file tpl_constraints.H.

References Aleph::DynArray< T >::access(), Aleph::DynArray< T >::append(), apply(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Builtin, Aleph::Enum, Aleph::Function, Aleph::Compiler_Type_Context::make_function_type(), Aleph::Compiler_Type_Context::make_tuple_type(), resolve_alias(), Aleph::Struct, Aleph::Tuple, Aleph::Compiler_Type_Context::type(), and Aleph::Type_Variable.

Referenced by apply(), Aleph::Compiler_Type_Unifier::apply(), and to_string().

◆ bind()

void Aleph::Compiler_Type_Substitution::bind ( const Compiler_Type_Id  variable,
const Compiler_Type_Id  replacement 
)
inline

Binds or updates one type-variable replacement.

Parameters
variableType variable to bind.
replacementReplacement type.

Definition at line 281 of file tpl_constraints.H.

References bindings, Aleph::blossom_maximum_cardinality_matching(), and lookup().

Referenced by Aleph::Compiler_Type_Unifier::bind_variable().

◆ binding()

const Binding & Aleph::Compiler_Type_Substitution::binding ( const size_t  i) const
inline

Returns binding i.

Parameters
iBinding index.
Returns
Stored binding.
Exceptions
std::out_of_rangeIf i is invalid.

Definition at line 243 of file tpl_constraints.H.

References ah_out_of_range_error_unless, and bindings.

◆ clear()

void Aleph::Compiler_Type_Substitution::clear ( )
inlinenoexcept

Removes every binding.

Definition at line 232 of file tpl_constraints.H.

References bindings.

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

◆ empty()

bool Aleph::Compiler_Type_Substitution::empty ( ) const
inlinenoexcept

Returns whether the substitution is empty.

Definition at line 226 of file tpl_constraints.H.

References bindings.

◆ lookup() [1/2]

const Compiler_Type_Id * Aleph::Compiler_Type_Substitution::lookup ( const Compiler_Type_Id  variable) const
inlinenoexcept

Looks up a bound replacement for variable.

Parameters
variableType variable id to search.
Returns
Replacement pointer, or nullptr if unbound.

Definition at line 268 of file tpl_constraints.H.

References bindings.

◆ lookup() [2/2]

Compiler_Type_Id * Aleph::Compiler_Type_Substitution::lookup ( const Compiler_Type_Id  variable)
inlinenoexcept

Looks up a bound replacement for variable.

Parameters
variableType variable id to search.
Returns
Replacement pointer, or nullptr if unbound.

Definition at line 255 of file tpl_constraints.H.

References bindings.

Referenced by bind(), Aleph::Compiler_Type_Unifier::resolve(), and resolve_alias().

◆ resolve_alias()

Compiler_Type_Id Aleph::Compiler_Type_Substitution::resolve_alias ( const Compiler_Type_Id  id) const
inlineprivate

Definition at line 204 of file tpl_constraints.H.

References ah_logic_error_if, bindings, and lookup().

Referenced by apply().

◆ size()

size_t Aleph::Compiler_Type_Substitution::size ( ) const
inlinenoexcept

Returns the number of stored variable bindings.

Definition at line 220 of file tpl_constraints.H.

References bindings.

Referenced by Aleph::Compiler_Type_Unifier::resolve().

◆ to_string()

std::string Aleph::Compiler_Type_Substitution::to_string ( Compiler_Type_Context &  ctx) const
inline

Renders all bindings in insertion order.

Parameters
ctxType context used to pretty-print type ids.
Returns
Deterministic text dump of the substitution.

Definition at line 362 of file tpl_constraints.H.

References apply(), bindings, out, and Aleph::Compiler_Type_Context::to_string().

Referenced by Aleph::Compiler_Type_Unifier::dump_substitution().

Member Data Documentation

◆ bindings

DynArray<Binding> Aleph::Compiler_Type_Substitution::bindings
private

Definition at line 201 of file tpl_constraints.H.

Referenced by bind(), binding(), clear(), empty(), lookup(), lookup(), resolve_alias(), size(), and to_string().


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