gogen

package module
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: Apache-2.0 Imports: 25 Imported by: 16

README

gogen - Code generator for the Go language

Build Status Go Report Card GitHub release Coverage Status GoDoc

gogen is a general-purpose Go code generation toolkit. Like the Go compiler, It can perform type checking of expressions. For example, if you generate an expression like "Hello" + 1, it will report the corresponding error.

Quick start

Create a file named hellogen.go, like below:

package main

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

	"github.com/goplus/gogen"
)

func main() {
	pkg := gogen.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(gogen.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(gogen.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"

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 gogen; DO NOT EDIT.\n\n"
)

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

Functions

func ASTFile deprecated

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

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

func AssignableTo

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 CheckOverloadFunc deprecated

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

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

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

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

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

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

func ConvertibleTo

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

func Default

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

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

func DerefType

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

func HasAutoProperty

func HasAutoProperty(typ types.Type) bool

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

func InferFunc added in v1.15.2

func InferFunc(pkg *Package, fn *Element, sig *types.Signature, targs []types.Type, args []*Element, flags InstrFlags) (types.Type, error)

InferFunc attempts to infer and instantiates the generic function instantiation with given func and args.

func InitBuiltin

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

func InitThisGopPkg

func InitThisGopPkg(pkg *types.Package)

InitThisGopPkg initializes a Go+ package.

func InitThisGopPkgEx added in v1.15.3

func InitThisGopPkgEx(pkg *types.Package, pos map[string]token.Pos)

InitThisGopPkg initializes a Go+ package. pos map overload name to postion.

func InsertStmtFront

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

func IsFunc

func IsFunc(t types.Type) bool

IsFunc returns if specified type is a function or not.

func IsMethodRecv

func IsMethodRecv(recv *types.Var) bool

func IsTypeEx

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

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

func Lookup

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

func LookupParent

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

func NewArray

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 NewChan

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

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

func NewMap

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

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

func NewOverloadFunc

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

NewOverloadFunc creates an overload func.

func NewOverloadMethod

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

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

func NewPointer

func NewPointer(elem types.Type) types.Type

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

func NewPosNode

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

func NewSignature

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

func NewSlice(elem types.Type) types.Type

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

func NewStaticMethod added in v1.15.2

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

func NewSubst

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

TODO(xsw): check only c2go uses this function.

func NewTemplateRecvMethod

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

func SetDebug(dbgFlags int)

func TypeAST

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 CodeBuilder

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

CodeBuilder type

func (*CodeBuilder) AliasType

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

AliasType func

func (*CodeBuilder) ArrayLit

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

ArrayLit func

func (*CodeBuilder) ArrayLitEx

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

ArrayLitEx func

func (*CodeBuilder) Assign

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

Assign func

func (*CodeBuilder) AssignOp

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

AssignOp func

func (*CodeBuilder) AssignWith

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

AssignWith func

func (*CodeBuilder) BackupComments

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

func (*CodeBuilder) BinaryOp

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

BinaryOp func

func (*CodeBuilder) Block

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

Block starts a block statement.

func (*CodeBuilder) Break

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

Break func

func (*CodeBuilder) Call

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

Call func

func (*CodeBuilder) CallInlineClosureStart

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

CallInlineClosureStart func

func (*CodeBuilder) CallWith

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

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

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

Case starts case clause of a switch statement.

func (*CodeBuilder) CommCase

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

CommCase starts case clause of a select statement.

func (*CodeBuilder) CommDefaultThen

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

CommDefaultThen starts default clause of a select statement.

func (*CodeBuilder) Comments

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

Comments returns the comments of next statement.

func (*CodeBuilder) CompareNil

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

CompareNil func

func (*CodeBuilder) Continue

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

Continue func

func (*CodeBuilder) Debug

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

Debug func

func (*CodeBuilder) DefaultThen

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

DefaultThen starts default clause of a switch statement.

func (*CodeBuilder) Defer

func (p *CodeBuilder) Defer() *CodeBuilder

Defer func

func (*CodeBuilder) DefineVarStart

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

DefineVarStart func

func (*CodeBuilder) Elem

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

Elem func

func (*CodeBuilder) ElemRef

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

ElemRef func

func (*CodeBuilder) Else

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

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

func (*CodeBuilder) End

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

End func

func (*CodeBuilder) EndConst

func (p *CodeBuilder) EndConst() *Element

func (*CodeBuilder) EndInit

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

EndInit func

func (*CodeBuilder) EndStmt

func (p *CodeBuilder) EndStmt() *CodeBuilder

EndStmt func

func (*CodeBuilder) Fallthrough

func (p *CodeBuilder) Fallthrough() *CodeBuilder

Fallthrough func

func (*CodeBuilder) For

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

For func

func (*CodeBuilder) ForRange

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

ForRange func

func (*CodeBuilder) ForRangeEx

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

ForRangeEx func

func (*CodeBuilder) Func

func (p *CodeBuilder) Func() *Func

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

func (*CodeBuilder) Get

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

Get func

func (*CodeBuilder) Go

func (p *CodeBuilder) Go() *CodeBuilder

Go func

func (*CodeBuilder) Goto

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

Goto func

func (*CodeBuilder) If

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

Block starts a if statement.

func (*CodeBuilder) InVBlock

func (p *CodeBuilder) InVBlock() bool

InVBlock checks if current statement is in vblock or not.

func (*CodeBuilder) IncDec

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

IncDec func

func (*CodeBuilder) Index

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

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

IndexRef func

func (*CodeBuilder) InternalStack

func (p *CodeBuilder) InternalStack() *InternalStack

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

func (*CodeBuilder) Label

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

Label func

func (*CodeBuilder) LookupLabel

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

LookupLabel func

func (*CodeBuilder) MapLit

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

MapLit func

func (*CodeBuilder) MapLitEx

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

MapLit func

func (*CodeBuilder) Member

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

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

MemberRef func

func (*CodeBuilder) MemberVal

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

MemberVal func

func (*CodeBuilder) NewAutoVar

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

NewAutoVar func

func (*CodeBuilder) NewClosure

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

NewClosure func

func (*CodeBuilder) NewClosureWith

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

NewClosureWith func

func (*CodeBuilder) NewConstStart

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

NewConstStart func

func (*CodeBuilder) NewLabel

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

func (*CodeBuilder) NewType

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

NewType func

func (*CodeBuilder) NewTypeDecls

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

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

func (*CodeBuilder) NewTypeDefs

func (p *CodeBuilder) NewTypeDefs() *TypeDefs

NewTypeDefs starts a type declaration block.

func (*CodeBuilder) NewVar

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

NewVar func

func (*CodeBuilder) NewVarStart

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

NewVarStart func

func (*CodeBuilder) None

func (p *CodeBuilder) None() *CodeBuilder

None func

func (*CodeBuilder) Pkg

func (p *CodeBuilder) Pkg() *Package

Pkg returns the package instance.

func (*CodeBuilder) Post

func (p *CodeBuilder) Post() *CodeBuilder

Post func

func (*CodeBuilder) RangeAssignThen

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

RangeAssignThen func

func (*CodeBuilder) ResetInit

func (p *CodeBuilder) ResetInit()

ResetInit resets the variable init state of CodeBuilder.

func (*CodeBuilder) ResetStmt

func (p *CodeBuilder) ResetStmt()

ResetStmt resets the statement state of CodeBuilder.

func (*CodeBuilder) Return

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

Return func

func (*CodeBuilder) ReturnErr

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

ReturnErr func

func (*CodeBuilder) Scope

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

Scope returns current scope.

func (*CodeBuilder) Select

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

Select starts a select statement.

func (*CodeBuilder) Send

func (p *CodeBuilder) Send() *CodeBuilder

Send func

func (*CodeBuilder) SetBodyHandler

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

func (*CodeBuilder) SetComments

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

SetComments sets comments to next statement.

func (*CodeBuilder) Slice

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

Slice func

func (*CodeBuilder) SliceLit

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

SliceLit func

func (*CodeBuilder) SliceLitEx

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

SliceLitEx func

func (*CodeBuilder) Star

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

Star func

func (*CodeBuilder) StructLit

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

StructLit func

func (*CodeBuilder) Switch

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

Switch starts a switch statement.

func (*CodeBuilder) Then

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

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

func (*CodeBuilder) Typ

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

Typ func

func (*CodeBuilder) TypeAssert

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

TypeAssert func

func (*CodeBuilder) TypeAssertThen

func (p *CodeBuilder) TypeAssertThen() *CodeBuilder

TypeAssertThen starts body of a type switch statement.

func (*CodeBuilder) TypeCase

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

TypeCase starts case body of a type switch statement.

func (*CodeBuilder) TypeDefaultThen

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

TypeDefaultThen starts default clause of a type switch statement.

func (*CodeBuilder) TypeSwitch

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

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

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

UntypedBigInt func

func (*CodeBuilder) UntypedBigRat

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

UntypedBigRat func

func (*CodeBuilder) VBlock

func (p *CodeBuilder) VBlock() *CodeBuilder

VBlock starts a vblock statement.

func (*CodeBuilder) Val

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

Val func

func (*CodeBuilder) VarRef

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

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

func (*CodeBuilder) VarVal

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

func (*CodeBuilder) ZeroLit

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

ZeroLit func

type CodeError

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

func (*CodeError) Error

func (p *CodeError) Error() string

type Config

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

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

ConstDefs represents a const declaration block.

func (*ConstDefs) New

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

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

func (p *ConstDefs) NewPos() ValueAt

func (*ConstDefs) Next

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

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

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

SetComments sets associated documentation.

type Contract

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

type Element

type Element = internal.Elem

func CastFromBool

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

type F = func(cb *CodeBuilder) int

F represents an initialization callback for constants/variables.

type File

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

func (*File) CheckGopDeps

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

func (p *File) Name() string

Name returns the name of this file.

type Func

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

Func type

func (*Func) Ancestor

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

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

BodyStart func

func (*Func) Comments

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

Comments returns associated documentation.

func (*Func) End

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

End is for internal use.

func (*Func) Obj

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

Obj returns this function object.

func (*Func) SetComments

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

SetComments sets associated documentation.

type ImportError

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

func (*ImportError) Error

func (p *ImportError) Error() string

func (*ImportError) Unwrap

func (p *ImportError) Unwrap() error

type InstrFlags

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

type Instruction

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

type InternalStack

type InternalStack = internal.Stack

type Label

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

type LoadNamedFunc

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

type MatchError

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

func (*MatchError) Error

func (p *MatchError) Error() string

func (*MatchError) Message

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

func (*MatchError) Pos

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

type MemberFlag

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

type MemberKind

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

type NodeInterpreter

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

type ObjectDocs

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

ObjectDocs maps an object to its document.

type OverloadType

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

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

NewPackage creates a new package.

func (*Package) ASTFile

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

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

func (p *Package) Builtin() PkgRef

Builtin returns the buitlin package.

func (*Package) CB

func (p *Package) CB() *CodeBuilder

CB returns the code builder.

func (*Package) CommentedASTFile

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

func (p *Package) ConstStart() *CodeBuilder

ConstStart starts a constant expression.

func (*Package) CurFile

func (p *Package) CurFile() *File

CurFile returns the current file.

func (*Package) File

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

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

ForEachFile walks all files to `doSth`.

func (*Package) ForceImport

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

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

func (*Package) Import

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

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

func (*Package) MethodToFunc

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

MethodToFunc:

(T).method
(*T).method

func (*Package) NewAutoParam

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

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

func (*Package) NewAutoParamEx

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

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

NewConstDefs starts a constant declaration block.

func (*Package) NewConstStart deprecated

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

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

NewFunc creates a new function (should have a function body).

func (*Package) NewFuncDecl

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

NewFuncDecl creates a new function without function body (declaration only).

func (*Package) NewFuncWith

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

NewFuncWith creates a new function (should have a function body).

func (*Package) NewParam

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

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

func (p *Package) NewTypeDefs() *TypeDefs

NewTypeDefs starts a type declaration block.

func (*Package) NewVar deprecated

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

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

NewVarDefs starts a var declaration block.

func (*Package) NewVarEx deprecated

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

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

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

func (*Package) RestoreCurFile

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

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

func (*Package) SetCurFile

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

func (p *Package) SetRedeclarable(allowRedecl bool)

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

func (*Package) Sizeof

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

Sizeof returns sizeof typ in bytes.

func (*Package) TryImport

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

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

func (*Package) Unsafe

func (p *Package) Unsafe() PkgRef

Builtin returns the unsafe package.

func (*Package) WriteFile

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

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

type Param = types.Var

A Param represents a function parameters and results.

type PkgRef

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

func (p PkgRef) EnsureImported()

Deprecated: EnsureImported is nothing to do now.

func (PkgRef) MarkForceUsed

func (p PkgRef) MarkForceUsed(pkg *Package)

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

func (PkgRef) Path

func (p PkgRef) Path() string

Path returns the package path.

func (PkgRef) Ref

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

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

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 gogen event recorder.

type Ref

type Ref = types.Object

Ref type

type SubstType deprecated

type SubstType = TySubst

Deprecated: use TySubst instead of SubstType.

type TemplateFunc

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

TemplateFunc: template function

func NewTemplateFunc

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

NewTemplateFunc creates a template function.

func (*TemplateFunc) Type

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

NewTemplateFunc return the type of specified template function.

type TemplateParamType

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

func NewTemplateParamType

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

func (*TemplateParamType) String

func (p *TemplateParamType) String() string

func (*TemplateParamType) Underlying

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

type TemplateSignature

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

TemplateSignature: type of template function

func NewTemplateSignature

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

func (p *TemplateSignature) String() string

func (*TemplateSignature) Underlying

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

type Term

type Term = types.Term

type Tuple

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

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

NewTuple returns a new tuple for the given parameters.

type TyFuncEx

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

TyFuncEx is a FuncEx type.

func CheckFuncEx

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

CheckFuncEx returns if specified function is a FuncEx or not.

type TyInstruction

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

func (*TyInstruction) String

func (p *TyInstruction) String() string

func (*TyInstruction) Underlying

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

type TyOverloadFunc

type TyOverloadFunc struct {
	Funcs []types.Object
}

TyOverloadFunc: overload function type

func (*TyOverloadFunc) At

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

func (*TyOverloadFunc) Len

func (p *TyOverloadFunc) Len() int

func (*TyOverloadFunc) String

func (p *TyOverloadFunc) String() string

func (*TyOverloadFunc) Underlying

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

type TyOverloadMethod

type TyOverloadMethod struct {
	Methods []types.Object
}

TyOverloadMethod: overload function type

func (*TyOverloadMethod) At

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

func (*TyOverloadMethod) Len

func (p *TyOverloadMethod) Len() int

func (*TyOverloadMethod) String

func (p *TyOverloadMethod) String() string

func (*TyOverloadMethod) Underlying

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

type TyOverloadNamed

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

func CheckOverloadNamed

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

CheckOverloadNamed returns if specified type is a TyOverloadNamed or not.

func (*TyOverloadNamed) At

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

func (*TyOverloadNamed) Len

func (p *TyOverloadNamed) Len() int

func (*TyOverloadNamed) String

func (p *TyOverloadNamed) String() string

func (*TyOverloadNamed) Underlying

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

type TyState

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

type TyStaticMethod added in v1.15.2

type TyStaticMethod struct {
	Func types.Object
}

func (*TyStaticMethod) Obj added in v1.15.2

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

func (*TyStaticMethod) String added in v1.15.2

func (p *TyStaticMethod) String() string

func (*TyStaticMethod) Underlying added in v1.15.2

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

type TySubst

type TySubst struct {
	Real types.Object
}

func (*TySubst) Obj

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

func (*TySubst) String

func (p *TySubst) String() string

func (*TySubst) Underlying

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

type TyTemplateRecvMethod

type TyTemplateRecvMethod struct {
	Func types.Object
}

func (*TyTemplateRecvMethod) Obj

func (*TyTemplateRecvMethod) String

func (p *TyTemplateRecvMethod) String() string

func (*TyTemplateRecvMethod) Underlying

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

type TyTypeEx

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

TyTypeEx is a TypeEx type.

type TypeDecl

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

TypeDecl type

func (*TypeDecl) Delete

func (p *TypeDecl) Delete()

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

func (*TypeDecl) InitType

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

InitType initializes a uncompleted type.

func (*TypeDecl) Inited

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

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

SetComments sets associated documentation.

func (*TypeDecl) State

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

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

Type returns the type.

type TypeDefs

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

TypeDefs represents a type declaration block.

func (*TypeDefs) AliasType

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

func (p *TypeDefs) Complete()

Complete checks type declarations & marks completed.

func (*TypeDefs) NewType

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

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

func (*TypeDefs) Pkg

func (p *TypeDefs) Pkg() *Package

Pkg returns the package instance.

func (*TypeDefs) SetComments

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

SetComments sets associated documentation.

type TypeParam

type TypeParam = types.TypeParam

type TypeParamList

type TypeParamList = types.TypeParamList

type TypeType

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

func NewTypeType

func NewTypeType(typ types.Type) *TypeType

func (*TypeType) Pointer

func (p *TypeType) Pointer() *TypeType

func (*TypeType) String

func (p *TypeType) String() string

func (*TypeType) Type

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

func (*TypeType) Underlying

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

type Union

type Union = types.Union

type ValueAt

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

type ValueDecl

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

ValueDecl type

func (*ValueDecl) End

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

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

InitStart initializes a uninitialized variable or constant.

func (*ValueDecl) Inited

func (p *ValueDecl) Inited() bool

Inited checkes if `InitStart` is called or not.

func (*ValueDecl) Ref

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

type VarDecl

type VarDecl = ValueDecl

VarDecl type

type VarDefs

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

VarDefs represents a var declaration block.

func (*VarDefs) Delete

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

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

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

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

func (p *VarDefs) NewPos() ValueAt

func (*VarDefs) SetComments

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

SetComments sets associated documentation.

Directories

Path Synopsis
chore
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