Documentation ¶
Overview ¶
Package golang implements a golang backend for Go+ to generate Go code.
Index ¶
- func ArrayType(p *Builder, typ reflect.Type) *ast.ArrayType
- func BigFloatConst(p *Builder, v *big.Float) ast.Expr
- func BigIntConst(p *Builder, v *big.Int) ast.Expr
- func BigRatConst(p *Builder, v *big.Rat) ast.Expr
- func BinaryOp(tok token.Token, x, y ast.Expr) ast.Expr
- func ChanType(p *Builder, typ reflect.Type) *ast.ChanType
- func Comment(text string) *ast.CommentGroup
- func ComplexConst(v complex128) ast.Expr
- func Const(p *Builder, val interface{}) ast.Expr
- func Field(p *Builder, name string, typ reflect.Type, tag string, ellipsis bool) *ast.Field
- func FloatConst(v float64) *ast.BasicLit
- func FuncType(p *Builder, typ reflect.Type) *ast.FuncType
- func Goto(p *Builder, l *Label) *ast.BranchStmt
- func GotoIf(p *Builder, cond ast.Expr, l *Label) *ast.IfStmt
- func Ident(name string) *ast.Ident
- func ImagConst(v float64) *ast.BasicLit
- func Index(p *Builder) *ast.IndexExpr
- func IndexWith(p *Builder, idx int) *ast.IndexExpr
- func IntConst(v int64) *ast.BasicLit
- func InterfaceType(p *Builder, typ reflect.Type) *ast.InterfaceType
- func MapType(p *Builder, typ reflect.Type) *ast.MapType
- func Methods(p *Builder, typ reflect.Type) []*ast.Field
- func NewGopkgType(p *Builder, pkgPath, typName string) ast.Expr
- func PtrType(p *Builder, typElem reflect.Type) ast.Expr
- func SliceIndex(p *Builder, idx int) ast.Expr
- func StringConst(v string) *ast.BasicLit
- func StructType(p *Builder, typ reflect.Type) ast.Expr
- func Type(p *Builder, typ reflect.Type, actualTypes ...bool) ast.Expr
- func TypeCast(p *Builder, x ast.Expr, from, to reflect.Type) *ast.CallExpr
- func UintConst(v uint64) *ast.BasicLit
- func Zero(p *Builder, typ reflect.Type) ast.Expr
- type Builder
- func (p *Builder) Addr(idx int32) *Builder
- func (p *Builder) AddrField(typ reflect.Type, index []int) *Builder
- func (p *Builder) AddrGoVar(addr exec.GoVarAddr) *Builder
- func (p *Builder) AddrIndex(idx int) *Builder
- func (p *Builder) AddrOp(kind exec.Kind, op exec.AddrOperator) *Builder
- func (p *Builder) AddrVar(v exec.Var) *Builder
- func (p *Builder) Append(typ reflect.Type, arity int) *Builder
- func (p *Builder) BuiltinOp(kind exec.Kind, op exec.Operator) *Builder
- func (p *Builder) Call(narg int, ellipsis bool, args ...ast.Expr) *Builder
- func (p *Builder) CallFunc(fun *FuncInfo, nexpr int) *Builder
- func (p *Builder) CallFuncv(fun *FuncInfo, nexpr, arity int) *Builder
- func (p *Builder) CallGoFunc(fun exec.GoFuncAddr, nexpr int) *Builder
- func (p *Builder) CallGoFuncv(fun exec.GoFuncvAddr, nexpr, arity int) *Builder
- func (p *Builder) CaseNE(l *Label, arity int) *Builder
- func (p *Builder) Closure(fun *FuncInfo) *Builder
- func (p *Builder) Default() *Builder
- func (p *Builder) Defer() *Builder
- func (p *Builder) DefineBlock() *Builder
- func (p *Builder) DefineFunc(fun exec.FuncInfo) *Builder
- func (p *Builder) DefineType(typ reflect.Type, name string) *Builder
- func (p *Builder) DefineVar(vars ...exec.Var) *Builder
- func (p *Builder) EndBlock() *Builder
- func (p *Builder) EndComprehension(c *Comprehension) *Builder
- func (p *Builder) EndForPhrase(f *ForPhrase) *Builder
- func (p *Builder) EndFunc(fun *FuncInfo) *Builder
- func (p *Builder) EndStmt(stmt, start interface{}) *Builder
- func (p *Builder) ErrWrap(nret int, retErr exec.Var, frame *errors.Frame, narg int) *Builder
- func (p *Builder) FilterForPhrase(f *ForPhrase) *Builder
- func (p *Builder) ForPhrase(f *ForPhrase, key, val *Var, hasExecCtx ...bool) *Builder
- func (p *Builder) Go() *Builder
- func (p *Builder) GoBuiltin(typ reflect.Type, op exec.GoBuiltin) *Builder
- func (p *Builder) GoSymIdent(pkgPath, name string) ast.Expr
- func (p *Builder) Ident(name string) *Builder
- func (p *Builder) Import(pkgPath string) string
- func (p *Builder) InCurrentCtx(v exec.Var) bool
- func (p *Builder) Index(idx int) *Builder
- func (p *Builder) Interface() exec.Builder
- func (p *Builder) Jmp(l *Label) *Builder
- func (p *Builder) JmpIf(jc exec.JmpCondFlag, l *Label) *Builder
- func (p *Builder) Label(l *Label) *Builder
- func (p *Builder) ListComprehension(c *Comprehension) *Builder
- func (p *Builder) Load(idx int32) *Builder
- func (p *Builder) LoadField(typ reflect.Type, index []int) *Builder
- func (p *Builder) LoadGoVar(addr exec.GoVarAddr) *Builder
- func (p *Builder) LoadVar(v exec.Var) *Builder
- func (p *Builder) Make(typ reflect.Type, arity int) *Builder
- func (p *Builder) MakeArray(typ reflect.Type, arity int) *Builder
- func (p *Builder) MakeMap(typ reflect.Type, arity int) *Builder
- func (p *Builder) MapComprehension(c *Comprehension) *Builder
- func (p *Builder) MapIndex() *Builder
- func (p *Builder) New(typ reflect.Type) *Builder
- func (p *Builder) Pop(n int) *Builder
- func (p *Builder) Push(val interface{}) *Builder
- func (p *Builder) Recv() *Builder
- func (p *Builder) Reserve() exec.Reserved
- func (p *Builder) ReserveOpLsh() exec.Reserved
- func (p *Builder) ReservedAsOpLsh(r exec.Reserved, kind exec.Kind, op exec.Operator)
- func (p *Builder) ReservedAsPush(r exec.Reserved, v interface{})
- func (p *Builder) Resolve() *Code
- func (p *Builder) Return(n int32) *Builder
- func (p *Builder) Send() *Builder
- func (p *Builder) SetIndex(idx int) *Builder
- func (p *Builder) SetMapIndex() *Builder
- func (p *Builder) Slice(i, j int) *Builder
- func (p *Builder) Slice3(i, j, k int) *Builder
- func (p *Builder) StartStmt(stmt interface{}) interface{}
- func (p *Builder) Store(idx int32) *Builder
- func (p *Builder) StoreField(typ reflect.Type, index []int) *Builder
- func (p *Builder) StoreGoVar(addr exec.GoVarAddr) *Builder
- func (p *Builder) StoreVar(v exec.Var) *Builder
- func (p *Builder) Struct(typ reflect.Type, arity int) *Builder
- func (p *Builder) TypeCast(from, to reflect.Type) *Builder
- func (p *Builder) WrapIfErr(nret int, l *Label) *Builder
- func (p *Builder) Zero(typ reflect.Type) *Builder
- type Code
- type Comprehension
- type ForPhrase
- type FuncInfo
- func (p *FuncInfo) Args(in ...reflect.Type) exec.FuncInfo
- func (p *FuncInfo) IsUnnamedOut() bool
- func (p *FuncInfo) IsVariadic() bool
- func (p *FuncInfo) Name() string
- func (p *FuncInfo) NumIn() int
- func (p *FuncInfo) NumOut() int
- func (p *FuncInfo) Out(i int) exec.Var
- func (p *FuncInfo) Return(out ...exec.Var) exec.FuncInfo
- func (p *FuncInfo) Type() reflect.Type
- func (p *FuncInfo) Vargs(in ...reflect.Type) exec.FuncInfo
- type GoType
- type Label
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InterfaceType ¶
func InterfaceType(p *Builder, typ reflect.Type) *ast.InterfaceType
InterfaceType instr
func NewGopkgType ¶
NewGopkgType instr
func StructType ¶ added in v0.7.7
StructType instr
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a class that generates go code.
func NewBuilder ¶
NewBuilder creates a new Code Builder instance.
func (*Builder) CallGoFunc ¶
CallGoFunc instr
func (*Builder) CallGoFuncv ¶
CallGoFuncv instr
func (*Builder) DefineBlock ¶ added in v0.7.3
DefineBlock starts a new block.
func (*Builder) DefineFunc ¶
DefineFunc instr
func (*Builder) DefineType ¶ added in v0.7.8
DefineVar defines types.
func (*Builder) EndComprehension ¶
func (p *Builder) EndComprehension(c *Comprehension) *Builder
EndComprehension instr
func (*Builder) EndForPhrase ¶
EndForPhrase instr
func (*Builder) FilterForPhrase ¶
FilterForPhrase instr
func (*Builder) GoSymIdent ¶
GoSymIdent - ast.Ident or ast.SelectorExpr
func (*Builder) InCurrentCtx ¶
InCurrentCtx returns if a variable is in current context or not.
func (*Builder) Interface ¶
func (p *Builder) Interface() exec.Builder
Interface converts *Builder to exec.Builder interface.
func (*Builder) ListComprehension ¶
func (p *Builder) ListComprehension(c *Comprehension) *Builder
ListComprehension instr
func (*Builder) MapComprehension ¶
func (p *Builder) MapComprehension(c *Comprehension) *Builder
MapComprehension instr
func (*Builder) Reserve ¶
func (p *Builder) Reserve() exec.Reserved
Reserve reserves an instruction.
func (*Builder) ReserveOpLsh ¶ added in v0.7.19
func (p *Builder) ReserveOpLsh() exec.Reserved
ReserveOpLsh reserves an instruction.
func (*Builder) ReservedAsOpLsh ¶ added in v0.7.19
func (p *Builder) ReservedAsOpLsh(r exec.Reserved, kind exec.Kind, op exec.Operator)
ReservedAsOpLsh sets Reserved as GoBuiltin
func (*Builder) ReservedAsPush ¶
func (p *Builder) ReservedAsPush(r exec.Reserved, v interface{})
ReservedAsPush sets Reserved as Push(v)
func (*Builder) StartStmt ¶
func (p *Builder) StartStmt(stmt interface{}) interface{}
StartStmt receives a `StartStmt` event.
func (*Builder) StoreField ¶ added in v0.7.7
StoreField instr
func (*Builder) StoreGoVar ¶
StoreGoVar instr
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
A Code represents generated go code.
type Comprehension ¶
Comprehension represents a list/map comprehension.
func NewComprehension ¶
func NewComprehension(out reflect.Type) *Comprehension
NewComprehension creates a new Comprehension instance.
type ForPhrase ¶
type ForPhrase struct {
Key, Value *Var // Key, Value may be nil
X, Cond ast.Expr
TypeIn reflect.Type
// contains filtered or unexported fields
}
ForPhrase represents a for range phrase.
func NewForPhrase ¶
NewForPhrase creates a new ForPhrase instance.
type FuncInfo ¶
type FuncInfo struct {
// contains filtered or unexported fields
}
FuncInfo represents a Go+ function information.
func (*FuncInfo) IsUnnamedOut ¶
IsUnnamedOut returns if function results unnamed or not.
func (*FuncInfo) IsVariadic ¶
IsVariadic returns if this function is variadic or not.
func (*FuncInfo) Out ¶
Out returns the type of a function type's i'th output parameter. It panics if i is not in the range [0, NumOut()).
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label represents a label.
type Var ¶
type Var struct {
// contains filtered or unexported fields
}
Var represents a variable.
func (*Var) IsUnnamedOut ¶
IsUnnamedOut returns if variable unnamed or not.
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
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. |