types

package
v0.0.0-...-909cb6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

contains types converted from AST

Index

Constants

View Source
const BuiltInPackage = "<built-in>"

Variables

View Source
var (
	ErrStop = errors.New("too many errors")
)
View Source
var TransformBasic = func(t TypeRef, basic BasicInfo) BasicInfo {
	return basic
}

TransformBasic is used to make modification to BasicInfo structure when it's returned from all types. Main usage is to change package name references when query for a type.

Functions

func IsString

func IsString(t TypeRef) bool

func IsVoid

func IsVoid(t TypeRef) bool

Types

type AnyType

type AnyType struct {
	// contains filtered or unexported fields
}

func (*AnyType) Basic

func (t *AnyType) Basic() BasicInfo

func (*AnyType) DefaultParam

func (t *AnyType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*AnyType) NeedRelease

func (t *AnyType) NeedRelease() bool

func (*AnyType) Param

func (t *AnyType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type BasicInfo

type BasicInfo struct {
	// Idl name
	Idl string

	// Package name
	Package string

	// Def is short for definition of a type, e.g. Foo
	Def string

	// Internal name for used with methods and need to write some code
	Internal string

	// Template define a template name prefix/suffix
	Template string
}

TypeName contains usage information about a type

type Callback

type Callback struct {
	Return     TypeRef
	Parameters []*Parameter
	// contains filtered or unexported fields
}

func (*Callback) AllSourceReferences

func (t *Callback) AllSourceReferences() []*Ref

func (*Callback) Basic

func (t *Callback) Basic() BasicInfo

func (*Callback) ChangeType

func (t *Callback) ChangeType(typeConv TypeConvert)

func (*Callback) DefaultParam

func (t *Callback) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*Callback) InUse

func (t *Callback) InUse() bool

func (*Callback) NeedRelease

func (t *Callback) NeedRelease() bool

func (*Callback) Param

func (t *Callback) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

func (*Callback) SetBasic

func (t *Callback) SetBasic(basic BasicInfo)

func (*Callback) SetInUse

func (t *Callback) SetInUse(value bool)

func (*Callback) SourceReference

func (t *Callback) SourceReference() *Ref

func (*Callback) TemplateCopy

func (t *Callback) TemplateCopy(targetInfo BasicInfo) *Callback

func (*Callback) TypeID

func (t *Callback) TypeID() TypeID

type Convert

type Convert struct {
	Types      map[string]Type
	All        []Type
	Enums      []*Enum
	Callbacks  []*Callback
	Dictionary []*Dictionary

	Interface []*Interface

	Merge map[string]MergeLink

	Unions []*UnionType

	HaveError bool
	// contains filtered or unexported fields
}

func NewConvert

func NewConvert() *Convert

func (*Convert) Evaluate

func (conv *Convert) Evaluate() error

Evaluate is doing verification on input IDL according to WebIDL specification. It also expand types, like removing typedef etc.

func (*Convert) Load

func (t *Convert) Load(setup *Setup) error

Load is reading a file from disc and Process it

func (*Convert) Parse

func (t *Convert) Parse(content []byte, setup *Setup) error

ParseTest is parsing a text and Process it

func (*Convert) Sort

func (t *Convert) Sort()

Sort is sorting the Enum, Callbacks, Dictionary and Interface.

type DictMember

type DictMember struct {
	Type     TypeRef
	Required bool
	// contains filtered or unexported fields
}

func (*DictMember) GetType

func (t *DictMember) GetType() TypeRef

func (*DictMember) Name

func (t *DictMember) Name() *MethodName

func (*DictMember) SetName

func (t *DictMember) SetName(value *MethodName)

func (*DictMember) SetType

func (t *DictMember) SetType(value TypeRef) string

func (*DictMember) SourceReference

func (t *DictMember) SourceReference() *Ref

type Dictionary

type Dictionary struct {
	Inherits *Dictionary

	Members []*DictMember
	// contains filtered or unexported fields
}

func (*Dictionary) AllSourceReferences

func (t *Dictionary) AllSourceReferences() []*Ref

func (*Dictionary) Basic

func (t *Dictionary) Basic() BasicInfo

func (*Dictionary) DefaultParam

func (t *Dictionary) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*Dictionary) InUse

func (t *Dictionary) InUse() bool

func (*Dictionary) NeedRelease

func (t *Dictionary) NeedRelease() bool

func (*Dictionary) Param

func (t *Dictionary) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

func (*Dictionary) SetBasic

func (t *Dictionary) SetBasic(basic BasicInfo)

func (*Dictionary) SetInUse

func (t *Dictionary) SetInUse(value bool)

func (*Dictionary) SourceReference

func (t *Dictionary) SourceReference() *Ref

func (*Dictionary) TypeID

func (t *Dictionary) TypeID() TypeID

type Enum

type Enum struct {
	Values []EnumValue

	// target language prefix and suffix for enum values
	Prefix, Suffix string
	// contains filtered or unexported fields
}

Enum type

func (*Enum) AllSourceReferences

func (t *Enum) AllSourceReferences() []*Ref

func (*Enum) Basic

func (t *Enum) Basic() BasicInfo

func (*Enum) DefaultParam

func (t *Enum) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*Enum) InUse

func (t *Enum) InUse() bool

func (*Enum) NeedRelease

func (t *Enum) NeedRelease() bool

func (*Enum) Param

func (t *Enum) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

func (*Enum) SetBasic

func (t *Enum) SetBasic(basic BasicInfo)

func (*Enum) SetInUse

func (t *Enum) SetInUse(value bool)

func (*Enum) SourceReference

func (t *Enum) SourceReference() *Ref

func (*Enum) TypeID

func (t *Enum) TypeID() TypeID

type EnumValue

type EnumValue struct {
	MethodName
}

EnumValue is a single enum value

func (*EnumValue) GetType

func (t *EnumValue) GetType() TypeRef

func (*EnumValue) Name

func (t *EnumValue) Name() *MethodName

func (*EnumValue) SetType

func (t *EnumValue) SetType(value TypeRef) string

type GetRef

type GetRef interface {
	SourceReference() *Ref
}

type IfConst

type IfConst struct {
	Type  TypeRef
	Value string
	// contains filtered or unexported fields
}

func (*IfConst) GetType

func (t *IfConst) GetType() TypeRef

func (*IfConst) Name

func (t *IfConst) Name() *MethodName

func (*IfConst) SetName

func (t *IfConst) SetName(value *MethodName)

func (*IfConst) SetType

func (t *IfConst) SetType(value TypeRef) string

func (*IfConst) SourceReference

func (t *IfConst) SourceReference() *Ref

type IfMethod

type IfMethod struct {
	Return TypeRef
	Static bool
	Params []*Parameter

	// Specialization indicate if this is a getter, setter or deleter
	Specialization SpecializationType
	// contains filtered or unexported fields
}

func (*IfMethod) Copy

func (t *IfMethod) Copy() *IfMethod

func (*IfMethod) GetType

func (t *IfMethod) GetType() TypeRef

func (*IfMethod) Name

func (t *IfMethod) Name() *MethodName

func (*IfMethod) SetName

func (t *IfMethod) SetName(value *MethodName)

func (*IfMethod) SetType

func (t *IfMethod) SetType(value TypeRef) string

func (*IfMethod) SourceReference

func (t *IfMethod) SourceReference() *Ref

type IfVar

type IfVar struct {
	Type        TypeRef
	Static      bool
	Readonly    bool
	Stringifier bool
	Source      string

	// part of event handling
	ShortName string
	EventName string
	PrimaryEv bool
	// contains filtered or unexported fields
}

func (*IfVar) Copy

func (t *IfVar) Copy() *IfVar

func (*IfVar) GetType

func (t *IfVar) GetType() TypeRef

func (*IfVar) Name

func (t *IfVar) Name() *MethodName

func (*IfVar) SetName

func (t *IfVar) SetName(value *MethodName)

func (*IfVar) SetType

func (t *IfVar) SetType(value TypeRef) string

func (*IfVar) SourceReference

func (t *IfVar) SourceReference() *Ref

type Interface

type Interface struct {
	Inherits *Interface

	// Global indicate that this "interface" is actually the
	// global scope of javascript
	Global bool

	// Callback specify that this is an interface that the
	// developer should implement.
	Callback bool

	// FunctionCB indicate that an extra function implementation
	// shall be added in final output
	FunctionCB bool

	// variable naming prefix and suffix for const variables
	ConstPrefix, ConstSuffix string

	Constructor *IfMethod

	Consts         []*IfConst
	Vars           []*IfVar
	StaticVars     []*IfVar
	Method         []*IfMethod
	StaticMethod   []*IfMethod
	Specialization []*IfMethod
	Events         []*IfVar

	// SpecProperty is used by transform step to assign names
	// for getters, setters and deleters
	SpecProperty map[SpecializationType]string
	// contains filtered or unexported fields
}

func (*Interface) AllSourceReferences

func (t *Interface) AllSourceReferences() []*Ref

func (*Interface) Basic

func (t *Interface) Basic() BasicInfo

func (*Interface) ChangeType

func (t *Interface) ChangeType(typeConv TypeConvert)

func (*Interface) DefaultParam

func (t *Interface) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*Interface) InUse

func (t *Interface) InUse() bool

func (*Interface) MergeList

func (t *Interface) MergeList() []MergeLink

func (*Interface) NeedRelease

func (t *Interface) NeedRelease() bool

func (*Interface) Param

func (t *Interface) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

func (*Interface) SetBasic

func (t *Interface) SetBasic(value BasicInfo)

func (*Interface) SetInUse

func (t *Interface) SetInUse(value bool)

func (*Interface) SourceReference

func (t *Interface) SourceReference() *Ref

func (*Interface) TemplateCopy

func (t *Interface) TemplateCopy(targetInfo BasicInfo) *Interface

func (*Interface) TypeID

func (t *Interface) TypeID() TypeID
type MergeLink interface {
	MergeList() []MergeLink
}

type MethodName

type MethodName struct {
	// Idl name
	Idl string

	// Def contains method name to use e.g. Foo
	Def string

	// Internal name for used with methods and need to write some code
	Internal string
}

type Parameter

type Parameter struct {
	Type     TypeRef
	Optional bool
	Variadic bool
	Name     string
	// contains filtered or unexported fields
}

type ParametrizedType

type ParametrizedType struct {
	*Ref

	ParamName string
	Elems     []TypeRef
	Type      TypeRef
	// contains filtered or unexported fields
}

ParametrizedType is e.g. "Promise<any>"

func (*ParametrizedType) Basic

func (t *ParametrizedType) Basic() BasicInfo

func (*ParametrizedType) DefaultParam

func (t *ParametrizedType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*ParametrizedType) NeedRelease

func (t *ParametrizedType) NeedRelease() bool

func (*ParametrizedType) Param

func (t *ParametrizedType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type PrimitiveType

type PrimitiveType struct {
	Idl      string
	Lang     string
	JsMethod string
	Cast     bool
	// contains filtered or unexported fields
}

func (*PrimitiveType) Basic

func (t *PrimitiveType) Basic() BasicInfo

func (*PrimitiveType) DefaultParam

func (t *PrimitiveType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*PrimitiveType) NeedRelease

func (t *PrimitiveType) NeedRelease() bool

func (*PrimitiveType) Param

func (t *PrimitiveType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type RawJSType

type RawJSType struct {
	IdlType string
}

RawJSType used when no conversion should take place and the raw underlying js.Value should be returned or inserted instead

func NewRawJSType

func NewRawJSType(idlType string) *RawJSType

func (*RawJSType) Basic

func (t *RawJSType) Basic() BasicInfo

func (*RawJSType) DefaultParam

func (t *RawJSType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*RawJSType) NeedRelease

func (t *RawJSType) NeedRelease() bool

func (*RawJSType) Param

func (t *RawJSType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type Ref

type Ref struct {
	Filename      string
	Line          int
	TransformFile string
}

Reference in input file

func (*Ref) SourceReference

func (t *Ref) SourceReference() *Ref

func (*Ref) String

func (t *Ref) String() string

type SequenceType

type SequenceType struct {
	Elem TypeRef
	// contains filtered or unexported fields
}

func (*SequenceType) Basic

func (t *SequenceType) Basic() BasicInfo

func (*SequenceType) DefaultParam

func (t *SequenceType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*SequenceType) NeedRelease

func (t *SequenceType) NeedRelease() bool

func (*SequenceType) Param

func (t *SequenceType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type Setup

type Setup struct {
	Package        string
	Filename       string
	Warning, Error UserMsgFn
}

type SpecializationType

type SpecializationType int
const (
	// Nothing assigned
	SpecNone SpecializationType = iota
	// getter with integer index
	SpecIndexGetter
	SpecIndexSetter
	SpecKeyGetter
	SpecKeySetter
	SpecKeyDeleter
)

func (SpecializationType) String

func (i SpecializationType) String() string

type Type

type Type interface {
	TypeRef
	GetRef

	AllSourceReferences() []*Ref

	// Used indicate that it's a interface or a type that is used by
	// an interface
	InUse() bool
	SetInUse(value bool)

	SetBasic(basic BasicInfo)

	TypeID() TypeID
	// contains filtered or unexported methods
}

type TypeConvert

type TypeConvert func(in TypeRef) TypeRef

type TypeID

type TypeID int
const (
	TypeInterface TypeID = iota
	TypeEnum
	TypeCallback
	TypeDictionary
	TypeTypeDef
)

func (TypeID) IsPublic

func (id TypeID) IsPublic() bool

type TypeInfo

type TypeInfo struct {
	BasicInfo

	// GoTagText is a name syntax correct version of BasicInfo.Def
	GoTagText string

	// Input is method parameter type
	Input string

	// VarIn used in variable definition in Input cases
	VarIn string

	// VarInInner is the inner type of a variadic/sequence in Input cases
	VarInInner string

	// Output define type out from a method
	Output string

	// VarOut used in variable definition in Output cases
	VarOut string

	// VarOut is the intter type of variadic/sequence in Output cases
	VarOutInner string

	// Pointer is true if InOut is a pointer type
	Pointer bool

	// NeedRelease define if the type need a release handle
	NeedRelease bool

	// Nullable indicate that a null/nil value is a possibility
	Nullable bool

	// Optional input value
	Option bool

	// Variadic is variable number of input values
	Variadic bool
}

TypeName contains usage information about a type

type TypeRef

type TypeRef interface {

	// Basic type infomation
	Basic() BasicInfo
	// Param type information
	Param(nullable, option, vardic bool) (info *TypeInfo, inner TypeRef)
	// DefaultParam return how this parameter should be processed by default
	DefaultParam() (info *TypeInfo, inner TypeRef)

	// the type is doing some allocation that needs manual release.
	NeedRelease() bool
	// contains filtered or unexported methods
}

func ChangeTemplateName

func ChangeTemplateName(on TypeRef, name string) TypeRef

type TypedArrayType

type TypedArrayType struct {
	Elem *PrimitiveType
	// contains filtered or unexported fields
}

func (*TypedArrayType) Basic

func (t *TypedArrayType) Basic() BasicInfo

func (*TypedArrayType) DefaultParam

func (t *TypedArrayType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*TypedArrayType) NeedRelease

func (t *TypedArrayType) NeedRelease() bool

func (*TypedArrayType) Param

func (t *TypedArrayType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type UnionType

type UnionType struct {
	Types []TypeRef
	// contains filtered or unexported fields
}

func (*UnionType) Basic

func (t *UnionType) Basic() BasicInfo

func (*UnionType) DefaultParam

func (t *UnionType) DefaultParam() (info *TypeInfo, inner TypeRef)

func (*UnionType) NeedRelease

func (t *UnionType) NeedRelease() bool

func (*UnionType) Param

func (t *UnionType) Param(nullable, option, variadic bool) (info *TypeInfo, inner TypeRef)

type UserMsgFn

type UserMsgFn func(ref GetRef, format string, args ...interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL