Documentation
¶
Overview ¶
Package types defines the Papyrus type system.
Types are broken down into two main categories: Invokable and Value types; as the names imply, the former describes function type information and the latter value type information (e.g. for variables and parameters).
Value types again break down into two categories: Scalar and Array types; the former represent single values while the latter represent sequence of some scalar type.
Scalar types again break down into two categories: Object and Primitive types; the former representing an script object and the latter the four primitive types: BoolType, IntType, FloatType, StringType.
There are also two special types: NoneType and VoidType. None is a scalar value type that is compatible with any object type and is used exclusively with the 'None' literal. Void is a value type that is used for functions that do not return a value.
Index ¶
- Variables
- type Array
- func (a *Array) Element() Scalar
- func (a *Array) IsAssignable(other Type) bool
- func (*Array) IsComparable(Type) bool
- func (*Array) IsConvertible(Type) bool
- func (*Array) IsEquatable(Type) bool
- func (a *Array) IsIdentical(other Type) bool
- func (a *Array) Name() string
- func (a *Array) Normalized() string
- func (a *Array) String() string
- type Invokable
- func (i *Invokable) Global() bool
- func (*Invokable) IsAssignable(Type) bool
- func (*Invokable) IsComparable(Type) bool
- func (*Invokable) IsConvertible(Type) bool
- func (*Invokable) IsEquatable(Type) bool
- func (i *Invokable) IsIdentical(other Type) bool
- func (i *Invokable) Kind() InvokableKind
- func (i *Invokable) Name() string
- func (i *Invokable) Native() bool
- func (i *Invokable) Normalized() string
- func (i *Invokable) Parameters() []Parameter
- func (i *Invokable) ReturnType() Value
- func (i *Invokable) String() string
- type InvokableKind
- type None
- type NotFoundError
- type Object
- func (o *Object) IsAssignable(other Type) bool
- func (*Object) IsComparable(Type) bool
- func (o *Object) IsConvertible(other Type) bool
- func (o *Object) IsEquatable(other Type) bool
- func (o *Object) IsIdentical(other Type) bool
- func (o *Object) Name() string
- func (o *Object) Node() ast.Node
- func (o *Object) Normalized() string
- func (o *Object) Parent() *Object
- func (o *Object) String() string
- type Parameter
- type Primitive
- func (p *Primitive) IsAssignable(other Type) bool
- func (p *Primitive) IsComparable(other Type) bool
- func (p *Primitive) IsConvertible(other Type) bool
- func (p *Primitive) IsEquatable(other Type) bool
- func (p *Primitive) IsIdentical(other Type) bool
- func (p *Primitive) Kind() PrimitiveKind
- func (p *Primitive) Name() string
- func (p *Primitive) Normalized() string
- func (p *Primitive) String() string
- type PrimitiveKind
- type Resolver
- type Scalar
- type Type
- type Value
- type Void
Constants ¶
This section is empty.
Variables ¶
var ( // BoolType is the boolean type. BoolType = &Primitive{BoolKind, "Bool", "bool"} // IntType is the integer type. IntType = &Primitive{IntKind, "Int", "int"} // FloatType is the floating-point type. FloatType = &Primitive{FloatKind, "Float", "float"} // StringType is the string type. StringType = &Primitive{StringKind, "String", "string"} // BoolArrayType is the boolean array type. BoolArrayType = &Array{BoolType} // IntArrayType is the integer array type. IntArrayType = &Array{IntType} // FloatArrayType is the floating-point array type. FloatArrayType = &Array{FloatType} // StringArrayType is the string array type. StringArrayType = &Array{StringType} // NoneType is the type that is compatible with any object or array // type. This is used exclusively with the 'None' literal. NoneType = None{} // VoidType is the type used for functions that do not return a value. VoidType = Void{} )
var ErrNotTyped = errors.New("node has no type")
ErrNotTyped indicates type resolution failed because the node does not have an intrinsic type, i.e. it's not one of the following:
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents an array type with an optionally known length.
func ArrayOf ¶
ArrayOf returns a new array type with the given element type or nil if the element is None or nil.
func (*Array) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (*Array) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (*Array) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (*Array) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (*Array) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (*Array) Normalized ¶
Normalized returns the normalized name for the type.
type Invokable ¶
type Invokable struct {
// contains filtered or unexported fields
}
Invokable is a function or event type.
func NewFunction ¶
func NewFunction(name string, returnType Value, native, global bool, params ...Parameter) *Invokable
NewFunction returns a new function Invokable type with an optional return type and zero or more parameters.
func (*Invokable) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (*Invokable) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (*Invokable) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (*Invokable) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (*Invokable) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (*Invokable) Kind ¶
func (i *Invokable) Kind() InvokableKind
Kind returns the kind of this invokable.
func (*Invokable) Normalized ¶
Normalized returns the normalized name for the type.
func (*Invokable) Parameters ¶
Parameters returns the parameters in declaration order.
func (*Invokable) ReturnType ¶
ReturnType returns the return type of the function or VoidType if there isn't one.
type InvokableKind ¶
type InvokableKind uint8
InvokableKind defines the different kinds of invokable types.
const ( // FunctionKind represents the function invokable type. FunctionKind InvokableKind = iota // EventKind represents the event invokable type. EventKind )
type None ¶
type None struct{}
None is the special type used for the 'None' literal.
func (None) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (None) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (None) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (None) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (None) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (None) Normalized ¶
Normalized returns the normalized name for the type.
type NotFoundError ¶
type NotFoundError struct {
Name string
}
NotFoundError indicates type resolution failed because the type refers to a script (object) type that the resolver could not find.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents a named typed (i.e. a script).
func (*Object) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (*Object) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (*Object) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (*Object) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (*Object) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (*Object) Normalized ¶
Normalized returns the normalized name for the type.
type Parameter ¶
type Parameter struct {
// contains filtered or unexported fields
}
Parameter is a function or event parameter (though not a type itself).
func NewParameter ¶
NewParameter returns a new parameter with the given name, type and default flag (true if the parameter has a default value and false otherwise).
func (Parameter) Normalized ¶
Normalized returns the normalized name for the parameter.
type Primitive ¶
type Primitive struct {
// contains filtered or unexported fields
}
Primitive represents a single Primitive, built-in type.
func (*Primitive) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (*Primitive) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (*Primitive) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (*Primitive) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (*Primitive) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (*Primitive) Kind ¶
func (p *Primitive) Kind() PrimitiveKind
Kind returns the kind of basic type.
func (*Primitive) Normalized ¶
Normalized returns the normalized name for the type.
type PrimitiveKind ¶
type PrimitiveKind uint8
PrimitiveKind defines the various primitive types.
const ( // BoolKind represents the primitive boolean type. BoolKind PrimitiveKind = iota // IntKind represents the primitive integer type. IntKind // FloatKind represents the primitive floating-point type. FloatKind // StringKind represents the primitive string type. StringKind )
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver creates types for ast.Node instances.
Note: Resolver is stateful! In order to resolve script (object) types correctly, the script they extend must have been resolved first.
func (*Resolver) Resolve ¶
Resolve returns the type for a given ast.Node or an error that wraps one of the following errors if type resolution fails:
- NotFoundError if a node refers to an script (object) type the resolver does not know, i.e. it hasn't been resolved yet
- ErrNotTyped if a node does not have an intrinsic type
type Scalar ¶
type Scalar interface {
Value
// contains filtered or unexported methods
}
Scalar is the common interface for all scalar (i.e. non-array) types.
type Type ¶
type Type interface {
fmt.Stringer
// Name returns the standard name for the type.
Name() string
// Normalized returns the normalized name for the type.
Normalized() string
// IsIdentical returns true if this type is
// identical to another type and false otherwise.
//
// This method is commutative; both of the following expressions will always
// evaluate to the same value:
//
// a.IsIdentical(b)
// b.IsIdentical(a)
IsIdentical(Type) bool
// IsAssignable returns true if a value of another type can be assigned to a
// variable of this type without an explicit type conversion and false
// otherwise.
//
// This method is NOT commutative; the following expressions may not evaluate
// to the same value:
//
// a.IsAssignable(b)
// b.IsAssignable(a)
IsAssignable(Type) bool
// IsComparable returns true if a value of this type can be compared (i.e.
// with '>', '<=', etc.) with a value of another type and false otherwise.
//
// This method is commutative; both of the following expressions will always
// evaluate to the same value:
//
// a.IsComparable(b)
// b.IsComparable(a)
IsComparable(Type) bool
// IsEquatable returns true if a value of this type can be checked for
// equality (i.e. with '==' or '!=') with a value of another type and false
// otherwise.
//
// This method is commutative; both of the following expressions will always
// evaluate to the same value:
//
// a.IsEquatable(b)
// b.IsEquatable(a)
IsEquatable(Type) bool
// IsConvertible returns true if a value of this type can be converted to
// a value of another type through an explicit cast and false otherwise.
//
// This method is NOT commutative; the following expressions may not evaluate
// to the same value:
//
// a.IsConvertible(b)
// b.IsConvertible(a)
IsConvertible(Type) bool
// contains filtered or unexported methods
}
Type is the common interface for all types.
type Value ¶
type Value interface {
Type
// contains filtered or unexported methods
}
Value is a common interface for all value types (scalars and arrays).
type Void ¶
type Void struct{}
Void is special type used for functions that do not return a value.
func (Void) IsAssignable ¶
IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsAssignable(b) b.IsAssignable(a)
func (Void) IsComparable ¶
IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsComparable(b) b.IsComparable(a)
func (Void) IsConvertible ¶
IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.
This method is NOT commutative; the following expressions may not evaluate to the same value:
a.IsConvertible(b) b.IsConvertible(a)
func (Void) IsEquatable ¶
IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsEquatable(b) b.IsEquatable(a)
func (Void) IsIdentical ¶
IsIdentical returns true if this type is identical to another type and false otherwise.
This method is commutative; both of the following expressions will always evaluate to the same value:
a.IsIdentical(b) b.IsIdentical(a)
func (Void) Normalized ¶
Normalized returns the normalized name for the type.