sun::ast::TypeConstraint

sun::ast::TypeConstraint

struct · Source (opens in a new tab)

struct sun::ast::TypeConstraint

One requirement written on a generic type parameter, after the colon:

<T: _Numeric> a built-in trait (see semantic_analysis/type_analysis/type_traits.h) <T: IShape> an interface the type argument must implement <T: IClone<T>> an interface with type arguments <F: _Lambda> any closure type

Parsing records the name, type arguments and source location. Deciding whether the name is a trait or an interface, and whether a given type argument satisfies it, is semantic analysis' job (sun::semantic_analysis::type_analysis::satisfies), which is what lets _is<T> in a body and a constraint on a signature answer with one vocabulary.

Public Functions

TypeConstraint

TypeConstraint(std::string n)

public · function · Source (opens in a new tab)

sun::ast::TypeConstraint::TypeConstraint(std::string n)

Creates a named constraint on the types accepted by a generic parameter.

TypeConstraint()=default

public · function · Source (opens in a new tab)

sun::ast::TypeConstraint::TypeConstraint()=default

Creates a named constraint on the types accepted by a generic parameter.

operator==

public · function · Source (opens in a new tab)

bool sun::ast::TypeConstraint::operator==(const TypeConstraint &other) const

Constraints are compared by what they require, not by where they appear, so two spellings of the same requirement in different files are equal.

Related: TypeConstraint

toAnnotation

public · function · Source (opens in a new tab)

TypeAnnotation sun::ast::TypeConstraint::toAnnotation() const

Represent the required interface using ordinary type syntax.

Related: TypeAnnotation

toString

public · function · Source (opens in a new tab)

std::string sun::ast::TypeConstraint::toString() const

Render the complete requirement for diagnostics.

Public Fields

declarationKey

public · variable · Source (opens in a new tab)

std::optional<sun::semantic_analysis::PortableDeclarationKey> sun::ast::TypeConstraint::declarationKey

No documentation comment.

Related: sun::semantic_analysis::PortableDeclarationKey

name

public · variable · Source (opens in a new tab)

std::string sun::ast::TypeConstraint::name

No documentation comment.

span

public · variable · Source (opens in a new tab)

sun::support::Position sun::ast::TypeConstraint::span {}

No documentation comment.

Related: sun::support::Position

typeArguments

public · variable · Source (opens in a new tab)

std::vector<TypeAnnotation> sun::ast::TypeConstraint::typeArguments

No documentation comment.

Related: TypeAnnotation