types

package
v0.0.0-...-66c8b22 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2012 License: BSD-3-Clause, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoolKind          = BasicTypeKind(reflect.Bool)
	IntKind           = BasicTypeKind(reflect.Int)
	Int8Kind          = BasicTypeKind(reflect.Int8)
	Int16Kind         = BasicTypeKind(reflect.Int16)
	Int32Kind         = BasicTypeKind(reflect.Int32)
	Int64Kind         = BasicTypeKind(reflect.Int64)
	UintKind          = BasicTypeKind(reflect.Uint)
	Uint8Kind         = BasicTypeKind(reflect.Uint8)
	Uint16Kind        = BasicTypeKind(reflect.Uint16)
	Uint32Kind        = BasicTypeKind(reflect.Uint32)
	Uint64Kind        = BasicTypeKind(reflect.Uint64)
	UintptrKind       = BasicTypeKind(reflect.Uintptr)
	Float32Kind       = BasicTypeKind(reflect.Float32)
	Float64Kind       = BasicTypeKind(reflect.Float64)
	Complex64Kind     = BasicTypeKind(reflect.Complex64)
	Complex128Kind    = BasicTypeKind(reflect.Complex128)
	StringKind        = BasicTypeKind(reflect.String)
	UnsafePointerKind = BasicTypeKind(reflect.UnsafePointer)
)

Constants for basic types.

Variables

View Source
var (
	Universe *ast.Scope
	Unsafe   *ast.Object // package unsafe
	Nil      *ast.Object
)

Functions

func Check

func Check(fset *token.FileSet, pkg *ast.Package) (types map[ast.Expr]Type, err error)

Check typechecks a package. It augments the AST by assigning types to all ast.Objects and returns a map of types for all expression nodes in statements, and a scanner.ErrorList if there are errors.

func FindGcExportData

func FindGcExportData(r *bufio.Reader) (err error)

FindGcExportData positions the reader r at the beginning of the export data section of an underlying GC-created object/archive file by reading from it. The reader must be positioned at the start of the file before calling this function.

func FindPkg

func FindPkg(path, srcDir string) (filename, id string)

FindPkg returns the filename and unique package id for an import path based on package information provided by build.Import (using the build.Default build.Context). If no file was found, an empty filename is returned.

func GcImport

func GcImport(imports map[string]*ast.Object, path string) (pkg *ast.Object, err error)

GcImport imports a gc-generated package given its import path, adds the corresponding package object to the imports map, and returns the object. Local import paths are interpreted relative to the current working directory. The imports map must contains all packages already imported. GcImport satisfies the ast.Importer signature.

func GcImportData

func GcImportData(imports map[string]*ast.Object, filename, id string, data *bufio.Reader) (pkg *ast.Object, err error)

GcImportData imports a package by reading the gc-generated export data, adds the corresponding package object to the imports map indexed by id, and returns the object.

The imports map must contains all packages already imported, and no map entry with id as the key must be present. The data reader position must be the beginning of the export data section. The filename is only used in error messages.

func Identical

func Identical(x, y Type) bool

Identical returns true if two types are identical.

Types

type Array

type Array struct {
	ImplementsType
	Len uint64
	Elt Type
}

An Array represents an array type [Len]Elt.

func (*Array) String

func (a *Array) String() string

type Bad

type Bad struct {
	ImplementsType
	Msg string // for better error reporting/debugging
}

A Bad type is a non-nil placeholder type when we don't know a type.

func (*Bad) String

func (b *Bad) String() string

type Basic

type Basic struct {
	ImplementsType
	Kind BasicTypeKind
}

A Basic represents a (unnamed) basic type.

func (*Basic) String

func (b *Basic) String() string

type BasicTypeKind

type BasicTypeKind reflect.Kind

func (BasicTypeKind) String

func (k BasicTypeKind) String() string

type Chan

type Chan struct {
	ImplementsType
	Dir ast.ChanDir
	Elt Type
}

A Chan represents a channel type chan Elt, <-chan Elt, or chan<-Elt.

func (*Chan) String

func (c *Chan) String() string

type Const

type Const struct {
	// representation of constant values:
	// ideal bool     ->  bool
	// ideal int      ->  *big.Int
	// ideal float    ->  *big.Rat
	// ideal complex  ->  cmplx
	// ideal string   ->  string
	Val interface{}
}

A Const implements an ideal constant Value. The zero value z for a Const is not a valid constant value.

func MakeConst

func MakeConst(tok token.Token, lit string) Const

MakeConst makes an ideal constant from a literal token and the corresponding literal string.

func MakeZero

func MakeZero(typ *Type) Const

MakeZero returns the zero constant for the given type.

func (Const) BinaryOp

func (x Const) BinaryOp(op token.Token, y Const) Const

func (Const) Convert

func (x Const) Convert(typ *Type) Const

Convert attempts to convert the constant x to a given type. If the attempt is successful, the result is the new constant; otherwise the result is invalid.

func (Const) Match

func (x Const) Match(y Const) (u, v Const)

Match attempts to match the internal constant representations of x and y. If the attempt is successful, the result is the values of x and y, if necessary converted to have the same internal representation; otherwise the results are invalid.

func (Const) String

func (x Const) String() string

func (Const) UnaryOp

func (x Const) UnaryOp(op token.Token) Const

type Func

type Func struct {
	ImplementsType
	Recv       *ast.Object // nil if not a method
	Params     ObjList     // (incoming) parameters from left to right; or nil
	Results    ObjList     // (outgoing) results from left to right; or nil
	IsVariadic bool        // true if the last parameter's type is of the form ...T
}

A Func represents a function type func(...) (...). Unnamed parameters are represented by objects with empty names.

func (*Func) String

func (f *Func) String() string

type ImplementsType

type ImplementsType struct{}

All concrete types embed ImplementsType which ensures that all types implement the Type interface.

type Interface

type Interface struct {
	ImplementsType
	Methods ObjList // interface methods sorted by name; or nil
}

An Interface represents an interface type interface{...}.

func (*Interface) String

func (i *Interface) String() string

type Map

type Map struct {
	ImplementsType
	Key, Elt Type
}

A Map represents a map type map[Key]Elt.

func (*Map) String

func (m *Map) String() string

type Name

type Name struct {
	ImplementsType
	Underlying Type        // nil if not fully declared
	Obj        *ast.Object // corresponding declared object
	Methods    ObjList
}

A Name represents a named type as declared in a type declaration.

var (
	Uint,
	Uint8,
	Uint16,
	Uint32,
	Uint64,
	Int,
	Int8,
	Int16,
	Int32,
	Int64,
	Float32,
	Float64,
	Complex64,
	Complex128,
	Byte,
	Bool,
	Uintptr,
	Rune,
	UnsafePointer,
	String *Name
)

func (*Name) String

func (n *Name) String() string

type ObjList

type ObjList []*ast.Object

An ObjList represents an ordered (in some fashion) list of objects.

func (ObjList) Len

func (list ObjList) Len() int

ObjList implements sort.Interface.

func (ObjList) Less

func (list ObjList) Less(i, j int) bool

func (ObjList) Sort

func (list ObjList) Sort()

Sort sorts an object list by object name.

func (ObjList) String

func (list ObjList) String() string

func (ObjList) Swap

func (list ObjList) Swap(i, j int)

type Pointer

type Pointer struct {
	ImplementsType
	Base Type
}

A Pointer represents a pointer type *Base.

func (*Pointer) String

func (p *Pointer) String() string

type Slice

type Slice struct {
	ImplementsType
	Elt Type
}

A Slice represents a slice type []Elt.

func (*Slice) String

func (s *Slice) String() string

type Struct

type Struct struct {
	ImplementsType
	Fields       ObjList           // struct fields; or nil
	Tags         []string          // corresponding tags; or nil
	FieldIndices map[string]uint64 // fast field lookup (name -> index)

}

A Struct represents a struct type struct{...}. Anonymous fields are represented by objects with empty names.

func (*Struct) String

func (s *Struct) String() string

type Type

type Type interface {
	String() string
	// contains filtered or unexported methods
}

All types implement the Type interface.

func Deref

func Deref(typ Type) Type

If typ is a pointer type, Deref returns the pointer's base type; otherwise it returns typ.

func Underlying

func Underlying(typ Type) Type

Underlying returns the underlying type of a type.

Jump to

Keyboard shortcuts

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