gox

package module
v1.14.12 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

README

gox - Code generator for the Go language

Build Status Go Report Card GitHub release Coverage Status GoDoc

Quick start

Create a file named hellogen.go, like below:

package main

import (
	"go/token"
	"go/types"
	"os"

	"github.com/goplus/gox"
)

func main() {
	pkg := gox.NewPackage("", "main", nil)
	fmt := pkg.Import("fmt")
	v := pkg.NewParam(token.NoPos, "v", types.Typ[types.String]) // v string

	pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
		DefineVarStart(token.NoPos, "a", "b").Val("Hi").Val(3).EndInit(2). // a, b := "Hi", 3
		NewVarStart(nil, "c").VarVal("b").EndInit(1).                      // var c = b
		NewVar(gox.TyEmptyInterface, "x", "y").                            // var x, y interface{}
		Val(fmt.Ref("Println")).
		/**/ VarVal("a").VarVal("b").VarVal("c"). // fmt.Println(a, b, c)
		/**/ Call(3).EndStmt().
		NewClosure(gox.NewTuple(v), nil, false).BodyStart(pkg).
		/**/ Val(fmt.Ref("Println")).Val(v).Call(1).EndStmt(). // fmt.Println(v)
		/**/ End().
		Val("Hello").Call(1).EndStmt(). // func(v string) { ... } ("Hello")
		End()

	pkg.WriteTo(os.Stdout)
}

Try it like:

go mod init hello
go mod tidy
go run hellogen.go

This will dump Go source code to stdout. The following is the output content:

package main

import fmt "fmt"

func main() {
	a, b := "Hi", 3
	var c = b
	var x, y interface {
	}
	fmt.Println(a, b, c)
	func(v string) {
		fmt.Println(v)
	}("Hello")
}

Documentation

Index

Constants

View Source
const (
	DbgFlagInstruction = 1 << iota
	DbgFlagImport
	DbgFlagMatch
	DbgFlagComments
	DbgFlagWriteFile
	DbgFlagSetDebug
	DbgFlagPersistCache
	DbgFlagAll = DbgFlagInstruction | DbgFlagImport | DbgFlagMatch |
		DbgFlagComments | DbgFlagWriteFile | DbgFlagSetDebug | DbgFlagPersistCache
)
View Source
const (
	FlagDepModGop = 1 << iota // depends module github.com/goplus/gop
	FlagDepModX               // depends module github.com/qiniu/x
)

Variables

View Source
var (
	TyByte = types.Universe.Lookup("byte").Type().(*types.Basic)
	TyRune = types.Universe.Lookup("rune").Type().(*types.Basic)
)
View Source
var (
	TyEmptyInterface = types.NewInterfaceType(nil, nil)
	TyError          = types.Universe.Lookup("error").Type()
)
View Source
var (
	GeneratedHeader = "// Code generated by gox; DO NOT EDIT.\n\n"
)

GeneratedHeader is the default string that the source file generated by gox start with. Change it if you want to make it different.

Functions

func ASTFile deprecated added in v0.2.0

func ASTFile(pkg *Package, fname ...string) *ast.File

ASTFile returns AST of a file by its fname. If fname is not provided, it returns AST of the default (NOT current) file.

Deprecated: Use pkg.ASTFile instead.

func AssignableConv added in v1.0.0

func AssignableConv(pkg *Package, V, T types.Type, pv *Element) bool

func AssignableTo added in v0.6.0

func AssignableTo(pkg *Package, V, T types.Type) bool

AssignableTo reports whether a value of type V is assignable to a variable of type T.

func CPubName added in v1.11.20

func CPubName(name string) string

func CheckOverloadFunc deprecated added in v1.11.39

func CheckOverloadFunc(sig *types.Signature) (funcs []types.Object, ok bool)

CheckOverloadFunc checks a func is overload func or not.

Deprecated: please use CheckFuncEx.

func CheckOverloadMethod deprecated added in v1.0.2

func CheckOverloadMethod(sig *types.Signature) (methods []types.Object, ok bool)

CheckOverloadMethod checks a func is overload method or not.

Deprecated: please use CheckFuncEx.

func CheckSigFuncEx added in v1.14.2

func CheckSigFuncEx(sig *types.Signature) (types.Type, bool)

CheckSigFuncEx retrun hide recv type from func($overloadArgs ...interface{$overloadMethod()}) The return type can be OverloadType (*TyOverloadFunc, *TyOverloadMethod, *TyOverloadNamed) or *TyTemplateRecvMethod.

func CheckSigFuncExObjects added in v1.14.2

func CheckSigFuncExObjects(sig *types.Signature) (typ types.Type, objs []types.Object)

CheckSigFuncExObjects retruns hide recv type and objects from func($overloadArgs ...interface{$overloadMethod()}) The return type can be OverloadType (*TyOverloadFunc, *TyOverloadMethod, *TyOverloadNamed) or *TyTemplateRecvMethod.

func CommentedASTFile deprecated added in v1.7.10

func CommentedASTFile(pkg *Package, fname ...string) *printer.CommentedNodes

CommentedASTFile returns commented AST of a file by its fname. If fname is not provided, it returns AST of the default (NOT current) file.

Deprecated: Use pkg.CommentedASTFile instead.

func ComparableTo added in v0.6.3

func ComparableTo(pkg *Package, varg, targ *Element) bool

func ConvertibleTo added in v1.10.10

func ConvertibleTo(pkg *Package, V, T types.Type) bool

func Default added in v0.8.13

func Default(pkg *Package, t types.Type) types.Type

Default returns the default "typed" type for an "untyped" type; it returns the incoming type for all other types. The default type for untyped nil is untyped nil.

func DefaultConv added in v1.0.0

func DefaultConv(pkg *Package, t types.Type, pv *Element) types.Type

func DerefType added in v1.9.9

func DerefType(typ types.Type) (types.Type, bool)

func HasAutoProperty added in v1.8.6

func HasAutoProperty(typ types.Type) bool

HasAutoProperty checks if specified type is a function without parameters or not.

func InitBuiltin added in v1.7.6

func InitBuiltin(pkg *Package, builtin *types.Package, conf *Config)

func InitThisGopPkg added in v1.14.2

func InitThisGopPkg(pkg *types.Package)

InitThisGopPkg initializes a Go+ package.

func InsertStmtFront added in v1.7.4

func InsertStmtFront(body *ast.BlockStmt, stmt ast.Stmt)

func IsCSignature added in v1.10.11

func IsCSignature(sig *types.Signature) bool

IsCSignature checks a prototype is C function or not.

func IsFunc added in v1.8.6

func IsFunc(t types.Type) bool

IsFunc returns if specified type is a function or not.

func IsMethodRecv added in v1.11.30

func IsMethodRecv(recv *types.Var) bool

func IsTypeEx added in v1.12.7

func IsTypeEx(t types.Type) (ok bool)

IsTypeEx returns if t is a gox extended type or not.

func Lookup added in v1.10.10

func Lookup(scope *types.Scope, name string) (obj types.Object)

func LookupParent added in v1.10.9

func LookupParent(scope *types.Scope, name string, pos token.Pos) (at *types.Scope, obj types.Object)

func NewArray added in v0.3.0

func NewArray(elem types.Type, len int64) types.Type

NewArray returns a new array type for the given element type and length. A negative length indicates an unknown length.

func NewCSignature added in v1.10.11

func NewCSignature(params, results *types.Tuple, variadic bool) *types.Signature

NewCSignature creates prototype of a C function.

func NewChan added in v0.3.0

func NewChan(dir types.ChanDir, elem types.Type) types.Type

NewChan returns a new channel type for the given direction and element type.

func NewInstruction added in v0.7.6

func NewInstruction(pos token.Pos, pkg *types.Package, name string, instr Instruction) *types.TypeName

func NewMap added in v0.3.0

func NewMap(key, elem types.Type) types.Type

NewMap returns a new map for the given key and element types.

func NewOverloadFunc added in v0.3.0

func NewOverloadFunc(pos token.Pos, pkg *types.Package, name string, funcs ...types.Object) *types.Func

NewOverloadFunc creates an overload func.

func NewOverloadMethod added in v1.0.2

func NewOverloadMethod(typ *types.Named, pos token.Pos, pkg *types.Package, name string, methods ...types.Object) *types.Func

NewOverloadMethod creates an overload method.

func NewOverloadNamed added in v1.14.0

func NewOverloadNamed(pos token.Pos, pkg *types.Package, name string, typs ...*types.Named) *types.TypeName

func NewPointer added in v0.3.0

func NewPointer(elem types.Type) types.Type

NewPointer returns a new pointer type for the given element (base) type.

func NewPosNode added in v1.13.0

func NewPosNode(pos token.Pos, end ...token.Pos) ast.Node

func NewSignature added in v0.3.0

func NewSignature(recv *types.Var, params, results *types.Tuple, variadic bool) *types.Signature

NewSignature returns a new function type for the given receiver, parameters, and results, either of which may be nil. If variadic is set, the function is variadic, it must have at least one parameter, and the last parameter must be of unnamed slice type.

func NewSlice added in v0.3.0

func NewSlice(elem types.Type) types.Type

NewSlice returns a new slice type for the given element type.

func NewSubst added in v1.11.3

func NewSubst(pos token.Pos, pkg *types.Package, name string, real types.Object) *types.Var

func NewTemplateRecvMethod added in v1.7.0

func NewTemplateRecvMethod(typ *types.Named, pos token.Pos, pkg *types.Package, name string, fn types.Object) *types.Func

NewTemplateRecvMethod - https://github.com/goplus/gop/issues/811

func SetDebug added in v0.2.7

func SetDebug(dbgFlags int)

func TypeAST added in v1.9.13

func TypeAST(pkg *Package, typ types.Type) ast.Expr

TypeAST returns the AST of specified typ.

func WriteFile deprecated

func WriteFile(file string, pkg *Package, fname ...string) (err error)

WriteFile writes a file named fname. If fname is not provided, it writes the default (NOT current) file.

Deprecated: Use pkg.WriteTo instead.

func WriteTo deprecated

func WriteTo(dst io.Writer, pkg *Package, fname ...string) (err error)

WriteTo writes a file named fname to dst. If fname is not provided, it writes the default (NOT current) file.

Deprecated: Use pkg.WriteTo instead.

Types

type BitField added in v1.9.10

type BitField struct {
	Name    string // bit field name
	FldName string // real field name
	Off     int
	Bits    int
	Pos     token.Pos
}

type BitFields added in v1.9.10

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

func NewBitFields added in v1.9.10

func NewBitFields(flds []*BitField) *BitFields

func (*BitFields) At added in v1.10.3

func (p *BitFields) At(i int) *BitField

func (*BitFields) FieldRef added in v1.9.10

func (p *BitFields) FieldRef(cb *CodeBuilder, t *types.Named, name string, src ast.Node) MemberKind

func (*BitFields) FindField added in v1.9.10

func (p *BitFields) FindField(
	cb *CodeBuilder, t *types.Named, name string, arg *Element, src ast.Node) MemberKind

func (*BitFields) Len added in v1.10.3

func (p *BitFields) Len() int

type CodeBuilder added in v0.2.0

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

CodeBuilder type

func (*CodeBuilder) AliasType added in v0.8.27

func (p *CodeBuilder) AliasType(name string, typ types.Type, src ...ast.Node) *types.Named

AliasType func

func (*CodeBuilder) ArrayLit added in v0.6.0

func (p *CodeBuilder) ArrayLit(typ types.Type, arity int, keyVal ...bool) *CodeBuilder

ArrayLit func

func (*CodeBuilder) ArrayLitEx added in v1.11.38

func (p *CodeBuilder) ArrayLitEx(typ types.Type, arity int, keyVal bool, src ...ast.Node) *CodeBuilder

ArrayLitEx func

func (*CodeBuilder) Assign added in v0.2.0

func (p *CodeBuilder) Assign(lhs int, rhs ...int) *CodeBuilder

Assign func

func (*CodeBuilder) AssignOp added in v0.8.82

func (p *CodeBuilder) AssignOp(op token.Token, src ...ast.Node) *CodeBuilder

AssignOp func

func (*CodeBuilder) AssignWith added in v0.9.20

func (p *CodeBuilder) AssignWith(lhs, rhs int, src ...ast.Node) *CodeBuilder

AssignWith func

func (*CodeBuilder) BackupComments added in v1.9.7

func (p *CodeBuilder) BackupComments() (*ast.CommentGroup, bool)

func (*CodeBuilder) BinaryOp added in v0.2.0

func (p *CodeBuilder) BinaryOp(op token.Token, src ...ast.Node) *CodeBuilder

BinaryOp func

func (*CodeBuilder) Block added in v1.4.5

func (p *CodeBuilder) Block(src ...ast.Node) *CodeBuilder

Block starts a block statement.

func (*CodeBuilder) Break added in v0.8.4

func (p *CodeBuilder) Break(l *Label) *CodeBuilder

Break func

func (*CodeBuilder) Call added in v0.2.0

func (p *CodeBuilder) Call(n int, ellipsis ...bool) *CodeBuilder

Call func

func (*CodeBuilder) CallInlineClosureStart added in v0.8.14

func (p *CodeBuilder) CallInlineClosureStart(sig *types.Signature, arity int, ellipsis bool) *CodeBuilder

CallInlineClosureStart func

func (*CodeBuilder) CallWith added in v0.9.20

func (p *CodeBuilder) CallWith(n int, flags InstrFlags, src ...ast.Node) *CodeBuilder

CallWith always panics on error, while CallWithEx returns err if match function call failed.

func (*CodeBuilder) CallWithEx added in v1.14.12

func (p *CodeBuilder) CallWithEx(n int, flags InstrFlags, src ...ast.Node) error

CallWith always panics on error, while CallWithEx returns err if match function call failed. If an error ocurs, CallWithEx pops all function arguments from the CodeBuilder stack. In most case, you should call CallWith instead of CallWithEx.

func (*CodeBuilder) Case added in v0.6.3

func (p *CodeBuilder) Case(n int, src ...ast.Node) *CodeBuilder

Case starts case body of a switch..case statement.

func (*CodeBuilder) CommCase added in v0.9.3

func (p *CodeBuilder) CommCase(n int, src ...ast.Node) *CodeBuilder

CommCase starts case body of a select..case statement.

func (*CodeBuilder) Comments added in v0.9.6

func (p *CodeBuilder) Comments() *ast.CommentGroup

Comments returns the comments of next statement.

func (*CodeBuilder) CompareNil added in v0.8.15

func (p *CodeBuilder) CompareNil(op token.Token, src ...ast.Node) *CodeBuilder

CompareNil func

func (*CodeBuilder) Continue added in v0.8.4

func (p *CodeBuilder) Continue(l *Label) *CodeBuilder

Continue func

func (*CodeBuilder) Debug added in v0.9.15

func (p *CodeBuilder) Debug(dbg func(cb *CodeBuilder)) *CodeBuilder

Debug func

func (*CodeBuilder) Defer added in v0.2.0

func (p *CodeBuilder) Defer() *CodeBuilder

Defer func

func (*CodeBuilder) DefineVarStart added in v0.5.0

func (p *CodeBuilder) DefineVarStart(pos token.Pos, names ...string) *CodeBuilder

DefineVarStart func

func (*CodeBuilder) Elem added in v0.8.50

func (p *CodeBuilder) Elem(src ...ast.Node) *CodeBuilder

Elem func

func (*CodeBuilder) ElemRef added in v0.8.50

func (p *CodeBuilder) ElemRef(src ...ast.Node) *CodeBuilder

ElemRef func

func (*CodeBuilder) Else added in v0.6.3

func (p *CodeBuilder) Else(src ...ast.Node) *CodeBuilder

Else starts else body of a if..else statement.

func (*CodeBuilder) End added in v0.2.0

func (p *CodeBuilder) End(src ...ast.Node) *CodeBuilder

End func

func (*CodeBuilder) EndConst added in v0.4.1

func (p *CodeBuilder) EndConst() *Element

func (*CodeBuilder) EndInit added in v0.5.0

func (p *CodeBuilder) EndInit(n int) *CodeBuilder

EndInit func

func (*CodeBuilder) EndStmt added in v0.2.0

func (p *CodeBuilder) EndStmt() *CodeBuilder

EndStmt func

func (*CodeBuilder) Fallthrough added in v0.6.3

func (p *CodeBuilder) Fallthrough() *CodeBuilder

Fallthrough func

func (*CodeBuilder) For added in v0.6.4

func (p *CodeBuilder) For(src ...ast.Node) *CodeBuilder

For func

func (*CodeBuilder) ForRange added in v0.6.4

func (p *CodeBuilder) ForRange(names ...string) *CodeBuilder

ForRange func

func (*CodeBuilder) ForRangeEx added in v1.12.7

func (p *CodeBuilder) ForRangeEx(names []string, src ...ast.Node) *CodeBuilder

ForRangeEx func

func (*CodeBuilder) Func added in v0.9.9

func (p *CodeBuilder) Func() *Func

Func returns current func (nil means in global scope).

func (*CodeBuilder) Get added in v1.0.0

func (p *CodeBuilder) Get(idx int) *Element

Get func

func (*CodeBuilder) Go added in v0.2.0

func (p *CodeBuilder) Go() *CodeBuilder

Go func

func (*CodeBuilder) Goto added in v0.8.4

func (p *CodeBuilder) Goto(l *Label) *CodeBuilder

Goto func

func (*CodeBuilder) If added in v0.6.3

func (p *CodeBuilder) If(src ...ast.Node) *CodeBuilder

Block starts a if statement.

func (*CodeBuilder) InVBlock added in v1.10.9

func (p *CodeBuilder) InVBlock() bool

InVBlock checks if current statement is in vblock or not.

func (*CodeBuilder) IncDec added in v0.8.0

func (p *CodeBuilder) IncDec(op token.Token, src ...ast.Node) *CodeBuilder

IncDec func

func (*CodeBuilder) Index added in v0.8.31

func (p *CodeBuilder) Index(nidx int, twoValue bool, src ...ast.Node) *CodeBuilder

Index func:

  • a[i]
  • fn[T1, T2, ..., Tn]
  • G[T1, T2, ..., Tn]

func (*CodeBuilder) IndexRef added in v0.7.0

func (p *CodeBuilder) IndexRef(nidx int, src ...ast.Node) *CodeBuilder

IndexRef func

func (*CodeBuilder) InternalStack added in v1.2.8

func (p *CodeBuilder) InternalStack() *InternalStack

InternalStack: don't call it (only for internal use)

func (*CodeBuilder) Label added in v0.8.4

func (p *CodeBuilder) Label(l *Label) *CodeBuilder

Label func

func (*CodeBuilder) LookupLabel added in v1.7.8

func (p *CodeBuilder) LookupLabel(name string) (l *Label, ok bool)

LookupLabel func

func (*CodeBuilder) MapLit added in v0.6.0

func (p *CodeBuilder) MapLit(typ types.Type, arity int, src ...ast.Node) *CodeBuilder

MapLit func

func (*CodeBuilder) Member added in v0.9.15

func (p *CodeBuilder) Member(name string, flag MemberFlag, src ...ast.Node) (kind MemberKind, err error)

Member access member by its name. src should point to the full source node `x.sel`

func (*CodeBuilder) MemberRef added in v0.8.31

func (p *CodeBuilder) MemberRef(name string, src ...ast.Node) *CodeBuilder

MemberRef func

func (*CodeBuilder) MemberVal added in v0.3.5

func (p *CodeBuilder) MemberVal(name string, src ...ast.Node) *CodeBuilder

MemberVal func

func (*CodeBuilder) NewAutoVar added in v0.5.0

func (p *CodeBuilder) NewAutoVar(pos token.Pos, name string, pv **types.Var) *CodeBuilder

NewAutoVar func

func (*CodeBuilder) NewClosure added in v0.2.0

func (p *CodeBuilder) NewClosure(params, results *Tuple, variadic bool) *Func

NewClosure func

func (*CodeBuilder) NewClosureWith added in v0.2.8

func (p *CodeBuilder) NewClosureWith(sig *types.Signature) *Func

NewClosureWith func

func (*CodeBuilder) NewConstStart added in v0.6.0

func (p *CodeBuilder) NewConstStart(typ types.Type, names ...string) *CodeBuilder

NewConstStart func

func (*CodeBuilder) NewLabel added in v1.7.8

func (p *CodeBuilder) NewLabel(pos token.Pos, name string) *Label

func (*CodeBuilder) NewType added in v0.8.27

func (p *CodeBuilder) NewType(name string, src ...ast.Node) *TypeDecl

NewType func

func (*CodeBuilder) NewTypeDecls added in v1.13.0

func (p *CodeBuilder) NewTypeDecls() (ret *TypeDefs, defineHere func())

NewTypeDecls starts a type declaration block but delay to define it.

func (*CodeBuilder) NewTypeDefs added in v1.13.0

func (p *CodeBuilder) NewTypeDefs() *TypeDefs

NewTypeDefs starts a type declaration block.

func (*CodeBuilder) NewVar added in v0.2.0

func (p *CodeBuilder) NewVar(typ types.Type, names ...string) *CodeBuilder

NewVar func

func (*CodeBuilder) NewVarStart added in v0.5.0

func (p *CodeBuilder) NewVarStart(typ types.Type, names ...string) *CodeBuilder

NewVarStart func

func (*CodeBuilder) None added in v0.6.1

func (p *CodeBuilder) None() *CodeBuilder

None func

func (*CodeBuilder) Pkg added in v0.2.7

func (p *CodeBuilder) Pkg() *Package

Pkg returns the package instance.

func (*CodeBuilder) Post added in v0.6.4

func (p *CodeBuilder) Post() *CodeBuilder

Post func

func (*CodeBuilder) RangeAssignThen added in v0.6.4

func (p *CodeBuilder) RangeAssignThen(pos token.Pos) *CodeBuilder

RangeAssignThen func

func (*CodeBuilder) ResetInit added in v0.9.12

func (p *CodeBuilder) ResetInit()

ResetInit resets the variable init state of CodeBuilder.

func (*CodeBuilder) ResetStmt added in v0.9.11

func (p *CodeBuilder) ResetStmt()

ResetStmt resets the statement state of CodeBuilder.

func (*CodeBuilder) Return added in v0.3.7

func (p *CodeBuilder) Return(n int, src ...ast.Node) *CodeBuilder

Return func

func (*CodeBuilder) ReturnErr added in v0.8.24

func (p *CodeBuilder) ReturnErr(outer bool) *CodeBuilder

ReturnErr func

func (*CodeBuilder) Scope added in v0.5.3

func (p *CodeBuilder) Scope() *types.Scope

Scope returns current scope.

func (*CodeBuilder) Select added in v0.9.3

func (p *CodeBuilder) Select(src ...ast.Node) *CodeBuilder

Select starts a select statement.

func (*CodeBuilder) Send added in v0.8.4

func (p *CodeBuilder) Send() *CodeBuilder

Send func

func (*CodeBuilder) SetBodyHandler added in v1.7.4

func (p *CodeBuilder) SetBodyHandler(handle func(body *ast.BlockStmt, kind int)) *CodeBuilder

func (*CodeBuilder) SetComments added in v0.9.5

func (p *CodeBuilder) SetComments(comments *ast.CommentGroup, once bool) *CodeBuilder

SetComments sets comments to next statement.

func (*CodeBuilder) Slice added in v0.8.31

func (p *CodeBuilder) Slice(slice3 bool, src ...ast.Node) *CodeBuilder

Slice func

func (*CodeBuilder) SliceLit added in v0.6.0

func (p *CodeBuilder) SliceLit(typ types.Type, arity int, keyVal ...bool) *CodeBuilder

SliceLit func

func (*CodeBuilder) SliceLitEx added in v1.11.38

func (p *CodeBuilder) SliceLitEx(typ types.Type, arity int, keyVal bool, src ...ast.Node) *CodeBuilder

SliceLitEx func

func (*CodeBuilder) Star added in v0.8.5

func (p *CodeBuilder) Star(src ...ast.Node) *CodeBuilder

Star func

func (*CodeBuilder) StructLit added in v0.8.26

func (p *CodeBuilder) StructLit(typ types.Type, arity int, keyVal bool, src ...ast.Node) *CodeBuilder

StructLit func

func (*CodeBuilder) Switch added in v0.6.3

func (p *CodeBuilder) Switch(src ...ast.Node) *CodeBuilder

Switch starts a switch statement.

func (*CodeBuilder) Then added in v0.6.3

func (p *CodeBuilder) Then(src ...ast.Node) *CodeBuilder

Then starts body of a if/switch/for statement.

func (*CodeBuilder) Typ added in v0.7.6

func (p *CodeBuilder) Typ(typ types.Type, src ...ast.Node) *CodeBuilder

Typ func

func (*CodeBuilder) TypeAssert added in v0.9.2

func (p *CodeBuilder) TypeAssert(typ types.Type, twoValue bool, src ...ast.Node) *CodeBuilder

TypeAssert func

func (*CodeBuilder) TypeAssertThen added in v0.9.2

func (p *CodeBuilder) TypeAssertThen() *CodeBuilder

TypeAssertThen starts body of a type switch statement.

func (*CodeBuilder) TypeCase added in v0.9.2

func (p *CodeBuilder) TypeCase(n int, src ...ast.Node) *CodeBuilder

TypeCase starts case body of a type switch statement.

func (*CodeBuilder) TypeSwitch added in v0.9.2

func (p *CodeBuilder) TypeSwitch(name string, src ...ast.Node) *CodeBuilder

TypeSwitch starts a type switch statement.

<pre> typeSwitch(name) init; expr typeAssertThen type1, type2, ... typeN typeCase(N)

...
end

type1, type2, ... typeM typeCase(M)

...
end

end </pre>

func (*CodeBuilder) UnaryOp added in v0.2.0

func (p *CodeBuilder) UnaryOp(op token.Token, params ...interface{}) *CodeBuilder

UnaryOp:

  • cb.UnaryOp(op token.Token)
  • cb.UnaryOp(op token.Token, twoValue bool)
  • cb.UnaryOp(op token.Token, twoValue bool, src ast.Node)

func (*CodeBuilder) UntypedBigInt added in v1.0.0

func (p *CodeBuilder) UntypedBigInt(v *big.Int, src ...ast.Node) *CodeBuilder

UntypedBigInt func

func (*CodeBuilder) UntypedBigRat added in v1.0.0

func (p *CodeBuilder) UntypedBigRat(v *big.Rat, src ...ast.Node) *CodeBuilder

UntypedBigRat func

func (*CodeBuilder) VBlock added in v1.10.9

func (p *CodeBuilder) VBlock() *CodeBuilder

VBlock starts a vblock statement.

func (*CodeBuilder) Val added in v0.2.0

func (p *CodeBuilder) Val(v interface{}, src ...ast.Node) *CodeBuilder

Val func

func (*CodeBuilder) VarRef added in v0.2.0

func (p *CodeBuilder) VarRef(ref interface{}, src ...ast.Node) *CodeBuilder

VarRef func: p.VarRef(nil) means underscore (_)

func (*CodeBuilder) VarVal added in v1.11.39

func (p *CodeBuilder) VarVal(name string, src ...ast.Node) *CodeBuilder

func (*CodeBuilder) ZeroLit added in v0.7.2

func (p *CodeBuilder) ZeroLit(typ types.Type) *CodeBuilder

ZeroLit func

type CodeError added in v0.9.15

type CodeError struct {
	Fset dbgPositioner
	Pos  token.Pos
	Msg  string
}

func (*CodeError) Error added in v0.9.15

func (p *CodeError) Error() string

type Config added in v0.2.0

type Config struct {
	// Types provides type information for the package (optional).
	Types *types.Package

	// Fset provides source position information for syntax trees and types (optional).
	// If Fset is nil, Load will use a new fileset, but preserve Fset's value.
	Fset *token.FileSet

	// HandleErr is called to handle errors (optional).
	HandleErr func(err error)

	// NodeInterpreter is to interpret an ast.Node (optional).
	NodeInterpreter NodeInterpreter

	// LoadNamed is called to load a delay-loaded named type (optional).
	LoadNamed LoadNamedFunc

	// An Importer resolves import paths to Packages (optional).
	Importer types.Importer

	// DefaultGoFile specifies default file name. It can be empty.
	DefaultGoFile string

	// PkgPathIox specifies package path of github.com/goplus/gop/builtin/iox
	PkgPathIox string

	// NewBuiltin is to create the builin package (optional).
	NewBuiltin func(pkg *Package, conf *Config) *types.Package

	// CanImplicitCast checkes can cast V to T implicitly (optional).
	CanImplicitCast func(pkg *Package, V, T types.Type, pv *Element) bool

	// untyped bigint, untyped bigrat, untyped bigfloat (optional).
	UntypedBigInt, UntypedBigRat, UntypedBigFloat *types.Named

	// A Recorder records selected objects such as methods, etc (optional).
	Recorder Recorder

	// (internal) only for testing
	DbgPositioner dbgPositioner

	// NoSkipConstant is to disable optimization of skipping constant (optional).
	NoSkipConstant bool
}

Config type

type ConstDefs added in v1.10.2

type ConstDefs struct {
	F F
	// contains filtered or unexported fields
}

ConstDefs represents a const declaration block.

func (*ConstDefs) New added in v1.10.2

func (p *ConstDefs) New(fn F, iotav int, pos token.Pos, typ types.Type, names ...string) *ConstDefs

New creates constants with specified `typ` (can be nil) and `names`. The values of the constants are given by the callback `fn`.

func (*ConstDefs) NewAt added in v1.12.2

func (p *ConstDefs) NewAt(at ValueAt, fn F, iotav int, pos token.Pos, typ types.Type, names ...string) *ConstDefs

NewAt creates constants with specified `typ` (can be nil) and `names`. The values of the constants are given by the callback `fn`.

func (*ConstDefs) NewPos added in v1.12.2

func (p *ConstDefs) NewPos() ValueAt

func (*ConstDefs) Next added in v1.10.2

func (p *ConstDefs) Next(iotav int, pos token.Pos, names ...string) *ConstDefs

Next creates constants with specified `names`. The values of the constants are given by the callback `fn` which is specified by the last call to `New`.

func (*ConstDefs) NextAt added in v1.12.2

func (p *ConstDefs) NextAt(at ValueAt, fn F, iotav int, pos token.Pos, names ...string) *ConstDefs

NextAt creates constants with specified `names`. The values of the constants are given by the callback `fn`.

func (*ConstDefs) SetComments added in v1.12.2

func (p *ConstDefs) SetComments(doc *ast.CommentGroup) *ConstDefs

SetComments sets associated documentation.

type Contract added in v0.3.0

type Contract interface {
	Match(pkg *Package, t types.Type) bool
	String() string
}

type Element added in v0.7.6

type Element = internal.Elem

func CastFromBool added in v1.10.1

func CastFromBool(cb *CodeBuilder, typ types.Type, v *Element) (ret *Element, ok bool)

CastFromBool tries to cast a bool expression into integer. typ must be an integer type.

type F added in v1.12.2

type F = func(cb *CodeBuilder) int

F represents an initialization callback for constants/variables.

type File added in v1.11.0

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

func (*File) CheckGopDeps added in v1.14.10

func (p *File) CheckGopDeps(this *Package) (flags int)

CheckGopDeps checks dependencies of Go+ modules. The return flags can be FlagDepModGop and FlagDepModX.

func (*File) Name added in v1.11.0

func (p *File) Name() string

Name returns the name of this file.

type Func added in v0.2.0

type Func struct {
	*types.Func
	// contains filtered or unexported fields
}

Func type

func (*Func) Ancestor added in v1.7.2

func (p *Func) Ancestor() *Func

Ancestor returns ancestor of a closure function. It returns itself if the specified func is a normal function.

func (*Func) BodyStart added in v0.2.0

func (p *Func) BodyStart(pkg *Package, src ...ast.Node) *CodeBuilder

BodyStart func

func (*Func) Comments added in v1.11.39

func (p *Func) Comments() *ast.CommentGroup

Comments returns associated documentation.

func (*Func) End added in v0.2.0

func (p *Func) End(cb *CodeBuilder, src ast.Node)

End is for internal use.

func (*Func) Obj added in v1.11.39

func (p *Func) Obj() types.Object

Obj returns this function object.

func (*Func) SetComments added in v1.7.14

func (p *Func) SetComments(pkg *Package, doc *ast.CommentGroup) *Func

SetComments sets associated documentation.

type ImportError added in v1.11.10

type ImportError struct {
	Fset dbgPositioner
	Pos  token.Pos
	Path string
	Err  error
}

func (*ImportError) Error added in v1.11.10

func (p *ImportError) Error() string

func (*ImportError) Unwrap added in v1.11.10

func (p *ImportError) Unwrap() error

type InstrFlags added in v0.8.9

type InstrFlags token.Pos
const (
	InstrFlagEllipsis InstrFlags = 1 << iota
	InstrFlagTwoValue
)

type Instruction added in v0.7.6

type Instruction interface {
	Call(pkg *Package, args []*Element, flags InstrFlags, src ast.Node) (ret *Element, err error)
}

type InternalStack added in v1.2.8

type InternalStack = internal.Stack

type Label added in v1.7.8

type Label struct {
	types.Label
	// contains filtered or unexported fields
}

type LoadNamedFunc added in v1.0.10

type LoadNamedFunc = func(at *Package, typ *types.Named)

type MatchError added in v0.9.20

type MatchError struct {
	Fset  dbgPositioner
	Src   ast.Node
	Arg   types.Type
	Param types.Type
	At    interface{}
	// contains filtered or unexported fields
}

func (*MatchError) Error added in v0.9.20

func (p *MatchError) Error() string

func (*MatchError) Message added in v1.13.0

func (p *MatchError) Message(fileLine string) string

func (*MatchError) Pos added in v1.13.0

func (p *MatchError) Pos() token.Pos

type MemberFlag added in v1.8.2

type MemberFlag int
const (
	MemberFlagVal MemberFlag = iota
	MemberFlagMethodAlias
	MemberFlagAutoProperty
	MemberFlagRef MemberFlag = -1
)

type MemberKind added in v0.9.15

type MemberKind int
const (
	MemberInvalid MemberKind = iota
	MemberMethod
	MemberAutoProperty
	MemberField
)

type NodeInterpreter added in v0.9.16

type NodeInterpreter interface {
	// LoadExpr is called to load an expr code.
	LoadExpr(expr ast.Node) string
}

type ObjectDocs added in v1.12.7

type ObjectDocs = map[types.Object]*ast.CommentGroup

ObjectDocs maps an object to its document.

type OverloadType added in v1.14.2

type OverloadType interface {
	At(i int) types.Object
	Len() int
}

Go+ overload extended types

type Package

type Package struct {
	PkgRef
	Docs ObjectDocs
	Fset *token.FileSet
	// contains filtered or unexported fields
}

Package type

func NewPackage added in v0.2.0

func NewPackage(pkgPath, name string, conf *Config) *Package

NewPackage creates a new package.

func (*Package) ASTFile added in v1.11.2

func (p *Package) ASTFile(fname ...string) *ast.File

ASTFile returns AST of a file by its fname. If fname is not provided, it returns AST of the default (NOT current) file.

func (*Package) AliasType deprecated added in v0.8.27

func (p *Package) AliasType(name string, typ types.Type, src ...ast.Node) *types.Named

AliasType gives a specified type with a new name.

Deprecated: use NewTypeDefs instead.

func (*Package) Builtin added in v0.3.0

func (p *Package) Builtin() PkgRef

Builtin returns the buitlin package.

func (*Package) CB added in v0.5.2

func (p *Package) CB() *CodeBuilder

CB returns the code builder.

func (*Package) CommentedASTFile added in v1.11.2

func (p *Package) CommentedASTFile(fname ...string) *printer.CommentedNodes

CommentedASTFile returns commented AST of a file by its fname. If fname is not provided, it returns AST of the default (NOT current) file.

func (*Package) ConstStart added in v0.4.1

func (p *Package) ConstStart() *CodeBuilder

ConstStart starts a constant expression.

func (*Package) CurFile added in v1.11.0

func (p *Package) CurFile() *File

CurFile returns the current file.

func (*Package) ExportFields added in v1.11.20

func (p *Package) ExportFields(t *types.Named)

func (*Package) File added in v1.11.0

func (p *Package) File(fname ...string) (file *File, ok bool)

File returns a file by its name. If `fname` is not provided, it returns the default (NOT current) file.

func (*Package) ForEachFile added in v1.11.0

func (p *Package) ForEachFile(doSth func(fname string, file *File))

ForEachFile walks all files to `doSth`.

func (*Package) ForceImport added in v1.14.0

func (p *Package) ForceImport(pkgPath string, src ...ast.Node)

ForceImport always imports a package (i.e. `import _ pkgPath`).

func (*Package) Import added in v0.2.0

func (p *Package) Import(pkgPath string, src ...ast.Node) PkgRef

Import imports a package by pkgPath. It will panic if pkgPath not found.

func (*Package) Instantiate added in v1.14.0

func (p *Package) Instantiate(orig types.Type, targs []types.Type, src ...ast.Node) types.Type

func (*Package) MethodToFunc added in v1.14.1

func (pkg *Package) MethodToFunc(typ types.Type, name string, src ...ast.Node) (ret *Element, err error)

MethodToFunc:

(T).method
(*T).method

func (*Package) NewAutoParam added in v0.6.5

func (p *Package) NewAutoParam(name string) *Param

NewAutoParam returns a new variable representing a function result parameter with auto type.

func (*Package) NewAutoParamEx added in v1.11.7

func (p *Package) NewAutoParamEx(pos token.Pos, name string) *Param

NewAutoParamEx returns a new variable representing a function result parameter with auto type.

func (*Package) NewConstDefs added in v1.10.2

func (p *Package) NewConstDefs(scope *types.Scope) *ConstDefs

NewConstDefs starts a constant declaration block.

func (*Package) NewConstStart deprecated added in v0.6.0

func (p *Package) NewConstStart(scope *types.Scope, pos token.Pos, typ types.Type, names ...string) *CodeBuilder

NewConstStart creates constants with names.

Deprecated: Use NewConstDefs instead.

func (*Package) NewFunc added in v0.2.0

func (p *Package) NewFunc(recv *Param, name string, params, results *Tuple, variadic bool) *Func

NewFunc func

func (*Package) NewFuncDecl added in v1.9.9

func (p *Package) NewFuncDecl(pos token.Pos, name string, sig *types.Signature) *Func

func (*Package) NewFuncWith added in v0.2.1

func (p *Package) NewFuncWith(
	pos token.Pos, name string, sig *types.Signature, recvTypePos func() token.Pos) (*Func, error)

NewFuncWith func

func (*Package) NewParam added in v0.2.0

func (p *Package) NewParam(pos token.Pos, name string, typ types.Type) *Param

NewParam returns a new variable representing a function parameter.

func (*Package) NewType deprecated added in v0.8.27

func (p *Package) NewType(name string, src ...ast.Node) *TypeDecl

NewType creates a new type (which need to call InitType later).

Deprecated: use NewTypeDefs instead.

func (*Package) NewTypeDefs added in v1.12.2

func (p *Package) NewTypeDefs() *TypeDefs

NewTypeDefs starts a type declaration block.

func (*Package) NewVar deprecated added in v0.2.0

func (p *Package) NewVar(pos token.Pos, typ types.Type, names ...string) *VarDecl

NewVar starts a var declaration block and creates uninitialized variables with specified `typ` (can be nil) and `names`.

Deprecated: This is a shortcut for creating variables. `NewVarDefs` is more powerful and more recommended.

func (*Package) NewVarDefs added in v1.10.2

func (p *Package) NewVarDefs(scope *types.Scope) *VarDefs

NewVarDefs starts a var declaration block.

func (*Package) NewVarEx deprecated added in v1.4.0

func (p *Package) NewVarEx(scope *types.Scope, pos token.Pos, typ types.Type, names ...string) *VarDecl

NewVarEx starts a var declaration block and creates uninitialized variables with specified `typ` (can be nil) and `names`.

Deprecated: This is a shortcut for creating variables. `NewVarDefs` is more powerful and more recommended.

func (*Package) NewVarStart deprecated added in v0.6.0

func (p *Package) NewVarStart(pos token.Pos, typ types.Type, names ...string) *CodeBuilder

NewVarStart creates variables with specified `typ` (can be nil) and `names` and starts to initialize them. You should call `CodeBuilder.EndInit` to end initialization.

Deprecated: This is a shortcut for creating variables. `NewVarDefs` is more powerful and more recommended.

func (*Package) Offsetsof added in v1.10.3

func (p *Package) Offsetsof(fields []*types.Var) []int64

func (*Package) RestoreCurFile added in v1.11.0

func (p *Package) RestoreCurFile(file *File) (old *File)

RestoreCurFile sets current file to an `old` file that was returned by `SetCurFile`.

func (*Package) SetCurFile added in v1.11.0

func (p *Package) SetCurFile(fname string, createIfNotExists bool) (old *File, err error)

SetCurFile sets new current file to write. If createIfNotExists is true, then create a new file named `fname` if it not exists. It returns an `old` file to restore in the future (by calling `RestoreCurFile`).

func (*Package) SetRedeclarable added in v1.12.0

func (p *Package) SetRedeclarable(allowRedecl bool)

SetRedeclarable sets to allow redeclaration of variables/functions or not.

func (*Package) SetVFields added in v1.9.10

func (p *Package) SetVFields(t *types.Named, vft VFields)

func (*Package) Sizeof added in v1.9.10

func (p *Package) Sizeof(typ types.Type) int64

Sizeof returns sizeof typ in bytes.

func (*Package) TryImport added in v1.12.7

func (p *Package) TryImport(pkgPath string) PkgRef

TryImport imports a package by pkgPath. It returns nil if pkgPath not found.

func (*Package) Unsafe added in v1.14.11

func (p *Package) Unsafe() PkgRef

Builtin returns the unsafe package.

func (*Package) VFields added in v1.9.12

func (p *Package) VFields(t *types.Named) (vft VFields, ok bool)

func (*Package) WriteFile added in v1.11.2

func (p *Package) WriteFile(file string, fname ...string) (err error)

WriteFile writes a file named fname. If fname is not provided, it writes the default (NOT current) file.

func (*Package) WriteTo added in v1.11.2

func (p *Package) WriteTo(dst io.Writer, fname ...string) (err error)

WriteTo writes a file named fname to dst. If fname is not provided, it writes the default (NOT current) file.

type Param added in v0.2.0

type Param = types.Var

A Param represents a function parameters and results.

type PkgRef added in v0.2.0

type PkgRef struct {
	// Types provides type information for the package.
	// The NeedTypes LoadMode bit sets this field for packages matching the
	// patterns; type information for dependencies may be missing or incomplete,
	// unless NeedDeps and NeedImports are also set.
	Types *types.Package
}

A PkgRef describes a Go package imported by others.

func (PkgRef) EnsureImported deprecated added in v0.8.71

func (p PkgRef) EnsureImported()

Deprecated: EnsureImported is nothing to do now.

func (PkgRef) MarkForceUsed added in v1.1.1

func (p PkgRef) MarkForceUsed(pkg *Package)

MarkForceUsed marks to import a package always (i.e. `import _ pkgPath`).

func (PkgRef) Path added in v1.9.0

func (p PkgRef) Path() string

Path returns the package path.

func (PkgRef) Ref added in v0.2.0

func (p PkgRef) Ref(name string) Ref

Ref returns the object in this package with the given name if such an object exists; otherwise it panics.

func (PkgRef) TryRef added in v1.7.6

func (p PkgRef) TryRef(name string) Ref

TryRef returns the object in this package with the given name if such an object exists; otherwise it returns nil.

type Recorder added in v1.12.7

type Recorder interface {
	// Member maps identifiers to the objects they denote.
	Member(id ast.Node, obj types.Object)
	// Call maps func to the the objects they denote.
	Call(fn ast.Node, obj types.Object)
}

Recorder represents a gox event recorder.

type Ref added in v0.2.0

type Ref = types.Object

Ref type

type SubstType deprecated added in v1.11.3

type SubstType = TySubst

Deprecated: use TySubst instead of SubstType.

type TemplateFunc added in v0.3.0

type TemplateFunc struct {
	*types.Func
	// contains filtered or unexported fields
}

TemplateFunc: template function

func NewTemplateFunc added in v0.3.0

func NewTemplateFunc(pos token.Pos, pkg *types.Package, name string, tsig *TemplateSignature) *TemplateFunc

NewTemplateFunc creates a template function.

func (*TemplateFunc) Type added in v0.3.0

func (p *TemplateFunc) Type() types.Type

NewTemplateFunc return the type of specified template function.

type TemplateParamType added in v0.3.0

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

func NewTemplateParamType added in v0.3.0

func NewTemplateParamType(idx int, name string, contract Contract) *TemplateParamType

func (*TemplateParamType) String added in v0.3.0

func (p *TemplateParamType) String() string

func (*TemplateParamType) Underlying added in v0.3.0

func (p *TemplateParamType) Underlying() types.Type

type TemplateSignature added in v0.3.0

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

TemplateSignature: type of template function

func NewTemplateSignature added in v0.3.0

func NewTemplateSignature(
	templateParams []*TemplateParamType,
	recv *types.Var, params, results *types.Tuple, variadic bool, tok ...token.Token) *TemplateSignature

NewTemplateSignature creates type of a template function.

func (*TemplateSignature) String added in v0.3.0

func (p *TemplateSignature) String() string

func (*TemplateSignature) Underlying added in v0.3.0

func (p *TemplateSignature) Underlying() types.Type

type Term added in v1.11.32

type Term = types.Term

type Tuple added in v0.2.0

type Tuple = types.Tuple

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 NewTuple added in v0.2.0

func NewTuple(x ...*Param) *Tuple

NewTuple returns a new tuple for the given parameters.

type TyFuncEx added in v1.11.39

type TyFuncEx interface {
	types.Type
	// contains filtered or unexported methods
}

TyFuncEx is a FuncEx type.

func CheckFuncEx added in v1.11.39

func CheckFuncEx(sig *types.Signature) (ext TyFuncEx, ok bool)

CheckFuncEx returns if specified function is a FuncEx or not.

type TyInstruction added in v1.14.0

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

func (*TyInstruction) String added in v1.14.0

func (p *TyInstruction) String() string

func (*TyInstruction) Underlying added in v1.14.0

func (p *TyInstruction) Underlying() types.Type

type TyOverloadFunc added in v1.11.39

type TyOverloadFunc struct {
	Funcs []types.Object
}

TyOverloadFunc: overload function type

func (*TyOverloadFunc) At added in v1.14.0

func (p *TyOverloadFunc) At(i int) types.Object

func (*TyOverloadFunc) Len added in v1.14.0

func (p *TyOverloadFunc) Len() int

func (*TyOverloadFunc) String added in v1.11.39

func (p *TyOverloadFunc) String() string

func (*TyOverloadFunc) Underlying added in v1.11.39

func (p *TyOverloadFunc) Underlying() types.Type

type TyOverloadMethod added in v1.11.39

type TyOverloadMethod struct {
	Methods []types.Object
}

TyOverloadMethod: overload function type

func (*TyOverloadMethod) At added in v1.14.0

func (p *TyOverloadMethod) At(i int) types.Object

func (*TyOverloadMethod) Len added in v1.14.0

func (p *TyOverloadMethod) Len() int

func (*TyOverloadMethod) String added in v1.11.39

func (p *TyOverloadMethod) String() string

func (*TyOverloadMethod) Underlying added in v1.11.39

func (p *TyOverloadMethod) Underlying() types.Type

type TyOverloadNamed added in v1.14.0

type TyOverloadNamed struct {
	Types []*types.Named
	Obj   *types.TypeName
}

func CheckOverloadNamed added in v1.14.0

func CheckOverloadNamed(typ types.Type) (on *TyOverloadNamed, ok bool)

CheckOverloadNamed returns if specified type is a TyOverloadNamed or not.

func (*TyOverloadNamed) At added in v1.14.0

func (p *TyOverloadNamed) At(i int) types.Object

func (*TyOverloadNamed) Len added in v1.14.0

func (p *TyOverloadNamed) Len() int

func (*TyOverloadNamed) String added in v1.14.0

func (p *TyOverloadNamed) String() string

func (*TyOverloadNamed) Underlying added in v1.14.0

func (p *TyOverloadNamed) Underlying() types.Type

type TyState added in v1.11.3

type TyState int
const (
	TyStateUninited TyState = iota
	TyStateInited
	TyStateDeleted
)

type TySubst added in v1.14.0

type TySubst struct {
	Real types.Object
}

func (*TySubst) Obj added in v1.14.0

func (p *TySubst) Obj() types.Object

func (*TySubst) String added in v1.14.0

func (p *TySubst) String() string

func (*TySubst) Underlying added in v1.14.0

func (p *TySubst) Underlying() types.Type

type TyTemplateRecvMethod added in v1.11.39

type TyTemplateRecvMethod struct {
	Func types.Object
}

func (*TyTemplateRecvMethod) Obj added in v1.14.0

func (*TyTemplateRecvMethod) String added in v1.11.39

func (p *TyTemplateRecvMethod) String() string

func (*TyTemplateRecvMethod) Underlying added in v1.11.39

func (p *TyTemplateRecvMethod) Underlying() types.Type

type TyTypeEx added in v1.14.0

type TyTypeEx interface {
	types.Type
	// contains filtered or unexported methods
}

TyTypeEx is a TypeEx type.

type TypeDecl added in v0.8.27

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

TypeDecl type

func (*TypeDecl) Delete added in v1.11.1

func (p *TypeDecl) Delete()

Delete deletes this type. NOTE: It panics if you call InitType after Delete.

func (*TypeDecl) InitType added in v0.8.27

func (p *TypeDecl) InitType(pkg *Package, typ types.Type, tparams ...*TypeParam) *types.Named

InitType initializes a uncompleted type.

func (*TypeDecl) Inited added in v1.10.0

func (p *TypeDecl) Inited() bool

Inited checkes if InitType is called or not. Will panic if this type is deleted (please use State to check).

func (*TypeDecl) SetComments added in v1.7.15

func (p *TypeDecl) SetComments(pkg *Package, doc *ast.CommentGroup) *TypeDecl

SetComments sets associated documentation.

func (*TypeDecl) State added in v1.11.3

func (p *TypeDecl) State() TyState

State checkes state of this type. If Delete is called, it returns TyStateDeleted. If InitType is called (but not deleted), it returns TyStateInited. Otherwise it returns TyStateUninited.

func (*TypeDecl) Type added in v0.8.28

func (p *TypeDecl) Type() *types.Named

Type returns the type.

type TypeDefs added in v1.12.2

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

TypeDefs represents a type declaration block.

func (*TypeDefs) AliasType added in v1.12.2

func (p *TypeDefs) AliasType(name string, typ types.Type, src ...ast.Node) *TypeDecl

AliasType gives a specified type with a new name.

func (*TypeDefs) Complete added in v1.12.2

func (p *TypeDefs) Complete()

Complete checks type declarations & marks completed.

func (*TypeDefs) NewType added in v1.12.2

func (p *TypeDefs) NewType(name string, src ...ast.Node) *TypeDecl

NewType creates a new type (which need to call InitType later).

func (*TypeDefs) Pkg added in v1.12.2

func (p *TypeDefs) Pkg() *Package

Pkg returns the package instance.

func (*TypeDefs) SetComments added in v1.12.2

func (p *TypeDefs) SetComments(doc *ast.CommentGroup) *TypeDefs

SetComments sets associated documentation.

type TypeParam added in v1.11.32

type TypeParam = types.TypeParam

type TypeParamList added in v1.11.32

type TypeParamList = types.TypeParamList

type TypeType added in v0.7.6

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

func NewTypeType added in v0.7.6

func NewTypeType(typ types.Type) *TypeType

func (*TypeType) Pointer added in v1.11.30

func (p *TypeType) Pointer() *TypeType

func (*TypeType) String added in v0.7.6

func (p *TypeType) String() string

func (*TypeType) Type added in v0.7.6

func (p *TypeType) Type() types.Type

func (*TypeType) Underlying added in v0.7.6

func (p *TypeType) Underlying() types.Type

type Union added in v1.11.32

type Union = types.Union

type UnionField added in v1.9.10

type UnionField struct {
	Name string
	Off  int
	Type types.Type
	Pos  token.Pos
}

type UnionFields added in v1.9.10

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

func NewUnionFields added in v1.9.10

func NewUnionFields(flds []*UnionField) *UnionFields

func (*UnionFields) At added in v1.9.13

func (p *UnionFields) At(i int) *UnionField

func (*UnionFields) FieldRef added in v1.9.10

func (p *UnionFields) FieldRef(cb *CodeBuilder, tfld *types.Named, name string, src ast.Node) MemberKind

func (*UnionFields) FindField added in v1.9.10

func (p *UnionFields) FindField(
	cb *CodeBuilder, tfld *types.Named, name string, arg *Element, src ast.Node) MemberKind

func (*UnionFields) Len added in v1.9.13

func (p *UnionFields) Len() int

type VFields added in v1.9.10

type VFields interface {
	FindField(cb *CodeBuilder, t *types.Named, name string, arg *Element, src ast.Node) MemberKind
	FieldRef(cb *CodeBuilder, t *types.Named, name string, src ast.Node) MemberKind
}

type ValueAt added in v1.12.2

type ValueAt struct {
	*ast.ValueSpec
	// contains filtered or unexported fields
}

type ValueDecl added in v0.5.0

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

ValueDecl type

func (*ValueDecl) End added in v0.5.0

func (p *ValueDecl) End(cb *CodeBuilder, src ast.Node)

End is provided for internal usage. Don't call it at any time. Please use (*CodeBuilder).EndInit instead.

func (*ValueDecl) InitStart added in v0.5.0

func (p *ValueDecl) InitStart(pkg *Package) *CodeBuilder

InitStart initializes a uninitialized variable or constant.

func (*ValueDecl) Inited added in v1.10.11

func (p *ValueDecl) Inited() bool

Inited checkes if `InitStart` is called or not.

func (*ValueDecl) Ref added in v1.10.2

func (p *ValueDecl) Ref(name string) Ref

type VarDecl added in v0.2.0

type VarDecl = ValueDecl

VarDecl type

type VarDefs added in v1.10.2

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

VarDefs represents a var declaration block.

func (*VarDefs) Delete added in v1.10.11

func (p *VarDefs) Delete(name string) error

Delete deletes an uninitialized variable who was created by `New`. If the variable is initialized, it fails to delete and returns `syscall.EACCES`. If the variable is not found, it returns `syscall.ENOENT`.

func (*VarDefs) New added in v1.10.2

func (p *VarDefs) New(pos token.Pos, typ types.Type, names ...string) *VarDecl

New creates uninitialized variables with specified `typ` (can be nil) and `names`.

func (*VarDefs) NewAndInit added in v1.10.2

func (p *VarDefs) NewAndInit(fn F, pos token.Pos, typ types.Type, names ...string) *VarDefs

NewAndInit creates variables with specified `typ` (can be nil) and `names`, and initializes them by `fn`.

func (*VarDefs) NewAt added in v1.12.2

func (p *VarDefs) NewAt(at ValueAt, pos token.Pos, typ types.Type, names ...string) *VarDecl

NewAt creates uninitialized variables with specified `typ` (can be nil) and `names`.

func (*VarDefs) NewPos added in v1.12.2

func (p *VarDefs) NewPos() ValueAt

func (*VarDefs) SetComments added in v1.12.2

func (p *VarDefs) SetComments(doc *ast.CommentGroup) *VarDefs

SetComments sets associated documentation.

Directories

Path Synopsis
cmd
bar
foo
go/format
Package format implements standard formatting of Go source.
Package format implements standard formatting of Go source.
go/printer
Package printer implements printing of AST nodes.
Package printer implements printing of AST nodes.
iox
tutorial

Jump to

Keyboard shortcuts

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