Documentation
¶
Index ¶
- Constants
- Variables
- func DeepEqual(t1, t2 Type) bool
- func Equal(t1, t2 Type) bool
- func InstantiatedFrom(s *StructType) (*GenericStructType, []Type)
- func IsAny(t Type) bool
- func IsGeneric(t Type) bool
- func IsList(t Type) bool
- func IsNumeric(t Type) bool
- func IsPrimitive(t Type) bool
- func IsPrimitiveOrVoid(t Type) bool
- func IsStruct(t Type) bool
- func IsTypeAlias(t Type) bool
- func IsTypeDef(t Type) bool
- func IsVoid(t Type) bool
- func MatchesGender(t Type, genders ...GrammaticalGender) bool
- func ParamTypesEqual(p1, p2 ParameterType) bool
- func StructurallyEqual(t1, t2 *StructType) bool
- type GenericStructInstantiation
- type GenericStructType
- type GenericType
- type GrammaticalGender
- type InstantiatedGenericType
- type ListType
- type ParameterType
- type PrimitiveType
- type StructField
- type StructType
- type Type
- func GetInstantiatedType(t Type, genericTypes map[string]Type) Type
- func GetListElementType(typ Type) Type
- func GetNestedListElementType(typ Type) Type
- func GetUnderlying(t Type) Type
- func ListTrueUnderlying(typ Type) Type
- func TrueUnderlying(t Type) Type
- func UnifyGenericType(argType Type, paramType ParameterType, genericTypes map[string]Type) Type
- type TypeAlias
- type TypeDef
- type Variable
- type VoidType
Constants ¶
const ( INVALID_GENDER GrammaticalGender = -1 MASKULIN = iota FEMININ NEUTRUM )
Variables ¶
var VARIABLE = Variable{}
Functions ¶
func DeepEqual ¶
checks wether t1 equals t2, that is, wether t1 and t2 refer to the same type throughout TypeAliases and TypeDefs and also List Types
func Equal ¶
checks wether t1 equals t2, that is, wether t1 and t2 refer to the same type throughout TypeAliases but not TypeDefs
func InstantiatedFrom ¶ added in v1.0.0
func InstantiatedFrom(s *StructType) (*GenericStructType, []Type)
returns the Generic Type this struct was instantiated from or nil if it is not generic
func IsPrimitive ¶
func IsPrimitiveOrVoid ¶
func IsTypeAlias ¶
func MatchesGender ¶ added in v1.0.0
func MatchesGender(t Type, genders ...GrammaticalGender) bool
checks wether t matches any of the provided genders
func ParamTypesEqual ¶
func ParamTypesEqual(p1, p2 ParameterType) bool
func StructurallyEqual ¶
func StructurallyEqual(t1, t2 *StructType) bool
checks wether two structs are structurally equal, that is their fields have the same type and are in the same order even ignoring TypeDefs
Types ¶
type GenericStructInstantiation ¶ added in v1.0.0
type GenericStructInstantiation struct {
Type *StructType
}
type GenericStructType ¶ added in v1.0.0
type GenericStructType struct {
StructType StructType
GenericTypes []GenericType
Instantiations []*StructType
}
func CastGenericStructType ¶ added in v1.0.0
func CastGenericStructType(t Type) (*GenericStructType, bool)
func (*GenericStructType) Gender ¶ added in v1.0.0
func (t *GenericStructType) Gender() GrammaticalGender
func (*GenericStructType) String ¶ added in v1.0.0
func (t *GenericStructType) String() string
type GenericType ¶ added in v1.0.0
type GenericType struct {
Name string
}
represents a generic type in a declaration (not yet resolved)
func CastDeeplyNestedGenerics ¶ added in v1.0.0
func CastDeeplyNestedGenerics(t Type) ([]GenericType, bool)
func CastGeneric ¶ added in v1.0.0
func CastGeneric(t Type) (GenericType, bool)
func (GenericType) Gender ¶ added in v1.0.0
func (GenericType) Gender() GrammaticalGender
func (GenericType) String ¶ added in v1.0.0
func (t GenericType) String() string
type InstantiatedGenericType ¶ added in v1.0.0
type InstantiatedGenericType struct {
Actual Type
}
represents a resolved generic type that is used during parsing of the generic function
func (*InstantiatedGenericType) Gender ¶ added in v1.0.0
func (t *InstantiatedGenericType) Gender() GrammaticalGender
func (*InstantiatedGenericType) String ¶ added in v1.0.0
func (t *InstantiatedGenericType) String() string
type ListType ¶
type ListType struct {
ElementType Type
}
func (ListType) Gender ¶
func (ListType) Gender() GrammaticalGender
type ParameterType ¶
represents the type of a function parameter which may be a reference
func (ParameterType) String ¶
func (paramType ParameterType) String() string
type PrimitiveType ¶
type PrimitiveType int
enum type for primitive types (+ void)
const ( ZAHL PrimitiveType = iota // int64 KOMMAZAHL // float64 BYTE // uint8 WAHRHEITSWERT // bool BUCHSTABE // int32 TEXT // string )
func CastPrimitive ¶
func CastPrimitive(t Type) (PrimitiveType, bool)
acts like primitiveType, ok := t.(PrimitiveType) but respects TypeAliases
func (PrimitiveType) Gender ¶
func (p PrimitiveType) Gender() GrammaticalGender
func (PrimitiveType) String ¶
func (p PrimitiveType) String() string
type StructField ¶
represents a single field of a struct
type StructType ¶
type StructType struct {
// name of the struct
Name string
// grammatical gender of the struct name
GramGender GrammaticalGender
// fields of the struct
// in order of declaration
Fields []StructField
// contains filtered or unexported fields
}
represents the type of a ddp struct
func CastStruct ¶
func CastStruct(t Type) (*StructType, bool)
acts like primitiveType, ok := t.(*StructType) but respects TypeAliases
func GetInstantiatedStructType ¶ added in v1.0.0
func GetInstantiatedStructType(s *GenericStructType, genericTypes []Type) *StructType
returns a new struct type with the fields filled in correctly
func (*StructType) Gender ¶
func (t *StructType) Gender() GrammaticalGender
func (*StructType) String ¶
func (t *StructType) String() string
type Type ¶
type Type interface {
// the grammatical Gender of the Type
Gender() GrammaticalGender
// string representation of the type (its name)
String() string
// contains filtered or unexported methods
}
holds information about a DDP-Type
func GetInstantiatedType ¶ added in v1.0.0
instantiates a type by replacing nested occurences of generic types with the actual types
func GetListElementType ¶ added in v1.0.0
gets the underlying type of a List if typ is not a list it is returned unchanged
func GetNestedListElementType ¶ added in v1.0.0
gets the underlying type for nested lists if typ is not a list type typ is returned
func GetUnderlying ¶
returns the underlying type for nested TypeAliases
func ListTrueUnderlying ¶
Returns the True Underlying type for a list that is the element type of a list all the way down example: - int -> int - list(int) -> int - list(typedef(int)) -> int - list(list(int)) -> int - list(list(typedef(int))) -> int
func TrueUnderlying ¶
returns the underlying type for nested TypeAliases and TypeDefs does not recurse through list element types examples: - int -> int - typealias(int) -> int - typedef(int) -> int - list(int) -> list(int) - typedef(list(int)) -> list(int)
func UnifyGenericType ¶ added in v1.0.0
func UnifyGenericType(argType Type, paramType ParameterType, genericTypes map[string]Type) Type
helper to unify generic types in a loop
type TypeAlias ¶
type TypeAlias struct {
Name string
Underlying Type
GramGender GrammaticalGender
}
a type alias only refers to another type with a new name
func CastTypeAlias ¶
func (*TypeAlias) Gender ¶
func (a *TypeAlias) Gender() GrammaticalGender
type TypeDef ¶
type TypeDef struct {
Name string
Underlying Type
GramGender GrammaticalGender
}
a typedef defines a new type that is equal to another
func CastTypeDef ¶
func (*TypeDef) Gender ¶
func (d *TypeDef) Gender() GrammaticalGender