gotypes

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinNames = map[string]BuiltinId{
	"append":   Append,
	"cap":      Cap,
	"close":    Close,
	"complex":  Complex,
	"copy":     Copy,
	"delete":   Delete,
	"imag":     Imag,
	"len":      Len,
	"make":     Make,
	"new":      New,
	"panic":    Panic,
	"print":    Print,
	"println":  Println,
	"real":     Real,
	"recover":  Recover,
	"Alignof":  Alignof,
	"Offsetof": Offsetof,
	"Sizeof":   Sizeof,
	"assert":   Assert,
	"trace":    Trace,
}
View Source
var EmptyInterface = Interface{AllMethods: MarkComplete}

EmptyInterface represents the empty (completed) interface

View Source
var MarkComplete = make([]*Func, 0)

MarkComplete is used to mark an empty interface as completely set up by setting the allMethods field to a non-nil empty slice.

View Source
var Typ = []*Basic{
	Invalid: {Invalid, 0, "invalid type"},

	Bool:          {Bool, IsBoolean, "bool"},
	Int:           {Int, IsInteger, "int"},
	Int8:          {Int8, IsInteger, "int8"},
	Int16:         {Int16, IsInteger, "int16"},
	Int32:         {Int32, IsInteger, "int32"},
	Int64:         {Int64, IsInteger, "int64"},
	Uint:          {Uint, IsInteger | IsUnsigned, "uint"},
	Uint8:         {Uint8, IsInteger | IsUnsigned, "uint8"},
	Uint16:        {Uint16, IsInteger | IsUnsigned, "uint16"},
	Uint32:        {Uint32, IsInteger | IsUnsigned, "uint32"},
	Uint64:        {Uint64, IsInteger | IsUnsigned, "uint64"},
	Uintptr:       {Uintptr, IsInteger | IsUnsigned, "uintptr"},
	Float32:       {Float32, IsFloat, "float32"},
	Float64:       {Float64, IsFloat, "float64"},
	Complex64:     {Complex64, IsComplex, "complex64"},
	Complex128:    {Complex128, IsComplex, "complex128"},
	String:        {String, IsString, "string"},
	UnsafePointer: {UnsafePointer, 0, "Pointer"},

	UntypedBool:    {UntypedBool, IsBoolean | IsUntyped, "untyped bool"},
	UntypedInt:     {UntypedInt, IsInteger | IsUntyped, "untyped int"},
	UntypedRune:    {UntypedRune, IsInteger | IsUntyped, "untyped rune"},
	UntypedFloat:   {UntypedFloat, IsFloat | IsUntyped, "untyped float"},
	UntypedComplex: {UntypedComplex, IsComplex | IsUntyped, "untyped complex"},
	UntypedString:  {UntypedString, IsString | IsUntyped, "untyped string"},
	UntypedNil:     {UntypedNil, IsUntyped, "untyped nil"},
}

Functions

func RegisterTypesGob

func RegisterTypesGob()

func RegisterTypesStablegob

func RegisterTypesStablegob()

func TypeString

func TypeString(typ Type, qf Qualifier) string

TypeString returns the string representation of typ. The Qualifier controls the printing of package-level objects, and may be nil.

func WriteSignature

func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier)

WriteSignature writes the representation of the signature sig to buf, without a leading "func" keyword. The Qualifier controls the printing of package-level objects, and may be nil.

func WriteType

func WriteType(buf *bytes.Buffer, typ Type, qf Qualifier)

WriteType writes the string representation of typ to buf. The Qualifier controls the printing of package-level objects, and may be nil.

Types

type Array

type Array struct {
	Len  int64 // Len returns the length of array a.
	Elem Type  // Elem returns element type of array a.
}

An Array represents an array type.

func (Array) Element

func (a Array) Element() Type

func (*Array) String

func (t *Array) String() string

func (*Array) Underlying

func (t *Array) Underlying() Type

type Basic

type Basic struct {
	Kind BasicKind // Kind returns the kind of basic type b.
	Info BasicInfo // Info returns information about properties of basic type b.
	Name string    // Name returns the name of basic type b.
}

A Basic represents a basic type.

func (*Basic) String

func (t *Basic) String() string

func (*Basic) Underlying

func (t *Basic) Underlying() Type

type BasicInfo

type BasicInfo int

BasicInfo is a set of flags describing properties of a basic type.

const (
	IsBoolean BasicInfo = 1 << iota
	IsInteger
	IsUnsigned
	IsFloat
	IsComplex
	IsString
	IsUntyped

	IsOrdered   = IsInteger | IsFloat | IsString
	IsNumeric   = IsInteger | IsFloat | IsComplex
	IsConstType = IsBoolean | IsNumeric | IsString
)

Properties of basic types.

type BasicKind

type BasicKind int

BasicKind describes the kind of basic type.

const (
	Invalid BasicKind = iota // type is invalid

	// predeclared types
	Bool
	Int
	Int8
	Int16
	Int32
	Int64
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Uintptr
	Float32
	Float64
	Complex64
	Complex128
	String
	UnsafePointer

	// types for untyped values
	UntypedBool
	UntypedInt
	UntypedRune
	UntypedFloat
	UntypedComplex
	UntypedString
	UntypedNil

	// aliases
	Byte = Uint8
	Rune = Int32
)

type Builtin

type Builtin struct {
	Obj
	BuiltinId BuiltinId
}

A Builtin represents a built-in function. Builtins don't have a valid type.

func (*Builtin) String

func (obj *Builtin) String() string

type BuiltinId

type BuiltinId int

A builtinId is the id of a builtin function.

const (
	// universe scope
	Append BuiltinId = iota
	Cap
	Close
	Complex
	Copy
	Delete
	Imag
	Len
	Make
	New
	Panic
	Print
	Println
	Real
	Recover

	// package unsafe
	Alignof
	Offsetof
	Sizeof

	// testing support
	Assert
	Trace
)

type Chan

type Chan struct {
	Dir  ChanDir // Dir returns the direction of channel c.
	Elem Type    // Elem returns the element type of channel c.
}

A Chan represents a channel type.

func (Chan) Element

func (c Chan) Element() Type

func (*Chan) String

func (t *Chan) String() string

func (*Chan) Underlying

func (t *Chan) Underlying() Type

type ChanDir

type ChanDir int

A ChanDir value indicates a channel direction.

const (
	SendRecv ChanDir = iota
	SendOnly
	RecvOnly
)

The direction of a channel is indicated by one of these constants.

type Const

type Const struct {
	Obj
	Kind ConstKind
}

A Const represents a declared constant.

func (*Const) String

func (obj *Const) String() string

type ConstKind

type ConstKind int

Kind specifies the kind of value represented by a Value.

const (
	UnknownConst ConstKind = iota
	BoolConst
	StringConst
	IntConst
	FloatConst
	ComplexConst
)

type Func

type Func struct {
	Obj
}

A Func represents a declared function, concrete method, or abstract (interface) method. Its Type() is always a Signature. An abstract method may belong to many interfaces due to embedding.

func (Func) FullName

func (obj Func) FullName() string

FullName returns the package- or receiver-type-qualified name of function or method obj.

func (*Func) String

func (obj *Func) String() string

type Identifier

type Identifier struct {
	Path string
	Name string
}

func (Identifier) Exported

func (i Identifier) Exported() bool

func (Identifier) String

func (i Identifier) String() string

String returns name if it is exported, otherwise it returns the name qualified with the package path.

type Interface

type Interface struct {
	Methods   []*Func      // ordered list of explicitly declared methods
	Embeddeds []*Reference // ordered list of explicitly embedded types

	AllMethods []*Func // ordered list of methods declared with or embedded in this interface (TODO(gri): replace with mset)
}

An Interface represents an interface type.

func (Interface) Embedded

func (t Interface) Embedded(i int) Type

Embedded returns the i'th embedded type of interface t for 0 <= i < t.NumEmbeddeds(). The types are ordered by the corresponding TypeName's unique Id.

func (Interface) Empty

func (t Interface) Empty() bool

Empty returns true if t is the empty interface.

func (Interface) ExplicitMethod

func (t Interface) ExplicitMethod(i int) *Func

ExplicitMethod returns the i'th explicitly declared method of interface t for 0 <= i < t.NumExplicitMethods(). The methods are ordered by their unique Id.

func (Interface) Method

func (t Interface) Method(i int) *Func

Method returns the i'th method of interface t for 0 <= i < t.NumMethods(). The methods are ordered by their unique Id.

func (Interface) NumEmbeddeds

func (t Interface) NumEmbeddeds() int

NumEmbeddeds returns the number of embedded types in interface t.

func (Interface) NumExplicitMethods

func (t Interface) NumExplicitMethods() int

NumExplicitMethods returns the number of explicitly declared methods of interface t.

func (Interface) NumMethods

func (t Interface) NumMethods() int

NumMethods returns the total number of methods of interface t.

func (*Interface) String

func (t *Interface) String() string

func (*Interface) Underlying

func (t *Interface) Underlying() Type

type Label

type Label struct {
	Obj
}

A Label represents a declared label. Labels don't have a type.

func (*Label) String

func (obj *Label) String() string

type Map

type Map struct {
	Key  Type // Key returns the key type of map m.
	Elem Type // Elem returns the element type of map m.
}

A Map represents a map type.

func (Map) Element

func (m Map) Element() Type

func (*Map) String

func (t *Map) String() string

func (*Map) Underlying

func (t *Map) Underlying() Type

type Named

type Named struct {
	Type    Type    // possibly a Named during setup; never a Named once set up completely
	Methods []*Func // methods declared for this type (not the method set of this type)
}

A Named represents a named type.

func (Named) Method

func (t Named) Method(i int) *Func

Method returns the i'th method of named type t for 0 <= i < t.NumMethods().

func (Named) NumMethods

func (t Named) NumMethods() int

NumMethods returns the number of explicit methods whose receiver is named type t.

func (*Named) String

func (t *Named) String() string

func (*Named) Underlying

func (t *Named) Underlying() Type

type Nil

type Nil struct {
	Obj
}

Nil represents the predeclared value nil.

func (*Nil) String

func (obj *Nil) String() string

type Obj

type Obj struct {
	Identifier
	Type Type
}

An object implements the common parts of an Object.

func (Obj) Id

func (obj Obj) Id() Identifier

func (Obj) Object

func (obj Obj) Object() Obj

type Object

type Object interface {
	Object() Obj
}

type PkgName

type PkgName struct {
	Obj
	Imported string // Imported returns the package that was imported. It is distinct from Pkg(), which is the package containing the import statement.
}

A PkgName represents an imported Go package. PkgNames don't have a type.

func (*PkgName) String

func (obj *PkgName) String() string

type Pointer

type Pointer struct {
	Elem Type // Elem returns the element type for the given pointer p.
}

A Pointer represents a pointer type.

func (Pointer) Element

func (p Pointer) Element() Type

func (*Pointer) String

func (t *Pointer) String() string

func (*Pointer) Underlying

func (t *Pointer) Underlying() Type

type Qualifier

type Qualifier func(string) string

A Qualifier controls how named package-level objects are printed in calls to TypeString, ObjectString, and SelectionString.

These three formatting routines call the Qualifier for each package-level object O, and if the Qualifier returns a non-empty string p, the object is printed in the form p.O. If it returns an empty string, only the object name O is printed.

Using a nil Qualifier is equivalent to using (*Package).Path: the object is qualified by the import path, e.g., "encoding/json.Marshal".

func RelativeTo

func RelativeTo(pkg string) Qualifier

RelativeTo(pkg) returns a Qualifier that fully qualifies members of all packages other than pkg.

type Reference

type Reference struct {
	Identifier
}

func (Reference) String

func (r Reference) String() string

func (Reference) Underlying

func (r Reference) Underlying() Type

type Signature

type Signature struct {
	// Recv returns the receiver of signature s (if a method), or nil if a
	// function. It is ignored when comparing signatures for identity.
	//
	// For an abstract method, Recv returns the enclosing interface either
	// as a *Named or an *Interface. Due to embedding, an interface may
	// contain methods whose receiver type is a different interface.
	Recv     *Var
	Params   *Tuple // Params returns the parameters of signature s, or nil.
	Results  *Tuple // Results returns the results of signature s, or nil.
	Variadic bool   // Variadic reports whether the signature s is variadic.
}

A Signature represents a (non-builtin) function or method type. The receiver is ignored when comparing signatures for identity.

func (*Signature) String

func (t *Signature) String() string

func (*Signature) Underlying

func (t *Signature) Underlying() Type

type Slice

type Slice struct {
	Elem Type // Elem returns the element type of slice s.
}

A Slice represents a slice type.

func (Slice) Element

func (s Slice) Element() Type

func (*Slice) String

func (t *Slice) String() string

func (*Slice) Underlying

func (t *Slice) Underlying() Type

type Struct

type Struct struct {
	Fields []*Var
	Tags   []string // field tags; nil if there are no tags
}

A Struct represents a struct type.

func (Struct) Field

func (s Struct) Field(i int) *Var

Field returns the i'th field for 0 <= i < NumFields().

func (Struct) NumFields

func (s Struct) NumFields() int

NumFields returns the number of fields in the struct (including blank and anonymous fields).

func (*Struct) String

func (t *Struct) String() string

func (Struct) Tag

func (s Struct) Tag(i int) string

Tag returns the i'th field tag for 0 <= i < NumFields().

func (*Struct) Underlying

func (t *Struct) Underlying() Type

type Tuple

type Tuple struct {
	Vars []*Var
}

A Tuple represents an ordered list of variables; a nil *Tuple is a valid (empty) tuple. Tuples are used as components of signatures and to represent the type of multiple assignments; they are not first class types of Go.

func (Tuple) At

func (t Tuple) At(i int) *Var

At returns the i'th variable of tuple t.

func (Tuple) Len

func (t Tuple) Len() int

Len returns the number variables of tuple t.

func (*Tuple) String

func (t *Tuple) String() string

func (*Tuple) Underlying

func (t *Tuple) Underlying() Type

type Type

type Type interface {
	// Underlying returns the underlying type of a type.
	Underlying() Type

	// String returns a string representation of a type.
	String() string
}

A Type represents a type of Go. All types implement the Type interface.

type TypeName

type TypeName struct {
	Obj
}

A TypeName represents a name for a (named or alias) type.

func (*TypeName) String

func (obj *TypeName) String() string

type Var

type Var struct {
	Obj
	Anonymous bool // Anonymous reports whether the variable is an anonymous field. If set, the variable is an anonymous struct field, and name is the type name
	IsField   bool // IsField reports whether the variable is a struct field.
}

A Variable represents a declared variable (including function parameters and results, and struct fields).

func (*Var) String

func (obj *Var) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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