golang

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package golang implements a golang backend for Go+ to generate Go code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayType

func ArrayType(p *Builder, typ reflect.Type) *ast.ArrayType

ArrayType instr

func BigFloatConst

func BigFloatConst(p *Builder, v *big.Float) ast.Expr

BigFloatConst instr

func BigIntConst

func BigIntConst(p *Builder, v *big.Int) ast.Expr

BigIntConst instr

func BigRatConst

func BigRatConst(p *Builder, v *big.Rat) ast.Expr

BigRatConst instr

func BinaryOp

func BinaryOp(tok token.Token, x, y ast.Expr) ast.Expr

BinaryOp instr

func ChanType added in v0.7.13

func ChanType(p *Builder, typ reflect.Type) *ast.ChanType

ChanType instr

func Comment

func Comment(text string) *ast.CommentGroup

Comment instr

func ComplexConst

func ComplexConst(v complex128) ast.Expr

ComplexConst instr

func Const

func Const(p *Builder, val interface{}) ast.Expr

Const instr

func Field

func Field(p *Builder, name string, typ reflect.Type, tag string, ellipsis bool) *ast.Field

Field instr

func FloatConst

func FloatConst(v float64) *ast.BasicLit

FloatConst instr

func FuncType

func FuncType(p *Builder, typ reflect.Type) *ast.FuncType

FuncType instr

func Goto

func Goto(p *Builder, l *Label) *ast.BranchStmt

Goto instr

func GotoIf

func GotoIf(p *Builder, cond ast.Expr, l *Label) *ast.IfStmt

GotoIf instr

func Ident

func Ident(name string) *ast.Ident

Ident - ast.Ident

func ImagConst

func ImagConst(v float64) *ast.BasicLit

ImagConst instr

func Index

func Index(p *Builder) *ast.IndexExpr

Index instr

func IndexWith

func IndexWith(p *Builder, idx int) *ast.IndexExpr

IndexWith instr

func IntConst

func IntConst(v int64) *ast.BasicLit

IntConst - ast.BasicLit

func InterfaceType

func InterfaceType(p *Builder, typ reflect.Type) *ast.InterfaceType

InterfaceType instr

func MapType

func MapType(p *Builder, typ reflect.Type) *ast.MapType

MapType instr

func Methods

func Methods(p *Builder, typ reflect.Type) []*ast.Field

Methods instr

func NewGopkgType

func NewGopkgType(p *Builder, pkgPath, typName string) ast.Expr

NewGopkgType instr

func PtrType

func PtrType(p *Builder, typElem reflect.Type) ast.Expr

PtrType instr

func SliceIndex

func SliceIndex(p *Builder, idx int) ast.Expr

SliceIndex instr

func StringConst

func StringConst(v string) *ast.BasicLit

StringConst - ast.BasicLit

func StructType added in v0.7.7

func StructType(p *Builder, typ reflect.Type) ast.Expr

StructType instr

func Type

func Type(p *Builder, typ reflect.Type, actualTypes ...bool) ast.Expr

Type instr

func TypeCast

func TypeCast(p *Builder, x ast.Expr, from, to reflect.Type) *ast.CallExpr

TypeCast instr

func UintConst

func UintConst(v uint64) *ast.BasicLit

UintConst instr

func Zero

func Zero(p *Builder, typ reflect.Type) ast.Expr

Zero instr

Types

type Builder

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

Builder is a class that generates go code.

func NewBuilder

func NewBuilder(pkgName string, code *Code, fset *token.FileSet) *Builder

NewBuilder creates a new Code Builder instance.

func (*Builder) Addr added in v0.7.12

func (p *Builder) Addr(idx int32) *Builder

Addr instr

func (*Builder) AddrField added in v0.7.7

func (p *Builder) AddrField(typ reflect.Type, index []int) *Builder

AddrField instr

func (*Builder) AddrGoVar

func (p *Builder) AddrGoVar(addr exec.GoVarAddr) *Builder

AddrGoVar instr

func (*Builder) AddrIndex added in v0.7.4

func (p *Builder) AddrIndex(idx int) *Builder

AddrIndex instr

func (*Builder) AddrOp

func (p *Builder) AddrOp(kind exec.Kind, op exec.AddrOperator) *Builder

AddrOp instr

func (*Builder) AddrVar

func (p *Builder) AddrVar(v exec.Var) *Builder

AddrVar instr

func (*Builder) Append

func (p *Builder) Append(typ reflect.Type, arity int) *Builder

Append instr

func (*Builder) BuiltinOp

func (p *Builder) BuiltinOp(kind exec.Kind, op exec.Operator) *Builder

BuiltinOp instr

func (*Builder) Call

func (p *Builder) Call(narg int, ellipsis bool, args ...ast.Expr) *Builder

Call instr

func (*Builder) CallFunc

func (p *Builder) CallFunc(fun *FuncInfo, nexpr int) *Builder

CallFunc instr

func (*Builder) CallFuncv

func (p *Builder) CallFuncv(fun *FuncInfo, nexpr, arity int) *Builder

CallFuncv instr

func (*Builder) CallGoFunc

func (p *Builder) CallGoFunc(fun exec.GoFuncAddr, nexpr int) *Builder

CallGoFunc instr

func (*Builder) CallGoFuncv

func (p *Builder) CallGoFuncv(fun exec.GoFuncvAddr, nexpr, arity int) *Builder

CallGoFuncv instr

func (*Builder) CaseNE

func (p *Builder) CaseNE(l *Label, arity int) *Builder

CaseNE instr

func (*Builder) Closure

func (p *Builder) Closure(fun *FuncInfo) *Builder

Closure instr

func (*Builder) Default

func (p *Builder) Default() *Builder

Default instr

func (*Builder) Defer added in v0.7.3

func (p *Builder) Defer() *Builder

Defer instr

func (*Builder) DefineBlock added in v0.7.3

func (p *Builder) DefineBlock() *Builder

DefineBlock starts a new block.

func (*Builder) DefineFunc

func (p *Builder) DefineFunc(fun exec.FuncInfo) *Builder

DefineFunc instr

func (*Builder) DefineType added in v0.7.8

func (p *Builder) DefineType(typ reflect.Type, name string) *Builder

DefineVar defines types.

func (*Builder) DefineVar

func (p *Builder) DefineVar(vars ...exec.Var) *Builder

DefineVar defines variables.

func (*Builder) EndBlock added in v0.7.3

func (p *Builder) EndBlock() *Builder

EndBlock ends a block.

func (*Builder) EndComprehension

func (p *Builder) EndComprehension(c *Comprehension) *Builder

EndComprehension instr

func (*Builder) EndForPhrase

func (p *Builder) EndForPhrase(f *ForPhrase) *Builder

EndForPhrase instr

func (*Builder) EndFunc

func (p *Builder) EndFunc(fun *FuncInfo) *Builder

EndFunc instr

func (*Builder) EndStmt

func (p *Builder) EndStmt(stmt, start interface{}) *Builder

EndStmt receives a `EndStmt` event.

func (*Builder) ErrWrap

func (p *Builder) ErrWrap(nret int, retErr exec.Var, frame *errors.Frame, narg int) *Builder

ErrWrap instr

func (*Builder) FilterForPhrase

func (p *Builder) FilterForPhrase(f *ForPhrase) *Builder

FilterForPhrase instr

func (*Builder) ForPhrase

func (p *Builder) ForPhrase(f *ForPhrase, key, val *Var, hasExecCtx ...bool) *Builder

ForPhrase instr

func (*Builder) Go added in v0.7.5

func (p *Builder) Go() *Builder

Go instr

func (*Builder) GoBuiltin

func (p *Builder) GoBuiltin(typ reflect.Type, op exec.GoBuiltin) *Builder

GoBuiltin instr

func (*Builder) GoSymIdent

func (p *Builder) GoSymIdent(pkgPath, name string) ast.Expr

GoSymIdent - ast.Ident or ast.SelectorExpr

func (*Builder) Ident

func (p *Builder) Ident(name string) *Builder

Ident instr

func (*Builder) Import

func (p *Builder) Import(pkgPath string) string

Import imports a package by pkgPath.

func (*Builder) InCurrentCtx

func (p *Builder) InCurrentCtx(v exec.Var) bool

InCurrentCtx returns if a variable is in current context or not.

func (*Builder) Index

func (p *Builder) Index(idx int) *Builder

Index instr

func (*Builder) Interface

func (p *Builder) Interface() exec.Builder

Interface converts *Builder to exec.Builder interface.

func (*Builder) Jmp

func (p *Builder) Jmp(l *Label) *Builder

Jmp instr

func (*Builder) JmpIf

func (p *Builder) JmpIf(jc exec.JmpCondFlag, l *Label) *Builder

JmpIf instr

func (*Builder) Label

func (p *Builder) Label(l *Label) *Builder

Label defines a label to jmp here.

func (*Builder) ListComprehension

func (p *Builder) ListComprehension(c *Comprehension) *Builder

ListComprehension instr

func (*Builder) Load

func (p *Builder) Load(idx int32) *Builder

Load instr

func (*Builder) LoadField added in v0.7.7

func (p *Builder) LoadField(typ reflect.Type, index []int) *Builder

LoadField instr

func (*Builder) LoadGoVar

func (p *Builder) LoadGoVar(addr exec.GoVarAddr) *Builder

LoadGoVar instr

func (*Builder) LoadVar

func (p *Builder) LoadVar(v exec.Var) *Builder

LoadVar instr

func (*Builder) Make

func (p *Builder) Make(typ reflect.Type, arity int) *Builder

Make instr

func (*Builder) MakeArray

func (p *Builder) MakeArray(typ reflect.Type, arity int) *Builder

MakeArray instr

func (*Builder) MakeMap

func (p *Builder) MakeMap(typ reflect.Type, arity int) *Builder

MakeMap instr

func (*Builder) MapComprehension

func (p *Builder) MapComprehension(c *Comprehension) *Builder

MapComprehension instr

func (*Builder) MapIndex

func (p *Builder) MapIndex() *Builder

MapIndex instr

func (*Builder) New added in v0.7.5

func (p *Builder) New(typ reflect.Type) *Builder

New instr

func (*Builder) Pop

func (p *Builder) Pop(n int) *Builder

Pop instr

func (*Builder) Push

func (p *Builder) Push(val interface{}) *Builder

Push instr

func (*Builder) Recv added in v0.7.13

func (p *Builder) Recv() *Builder

Recv 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) Resolve

func (p *Builder) Resolve() *Code

Resolve resolves all unresolved labels/functions/consts/etc.

func (*Builder) Return

func (p *Builder) Return(n int32) *Builder

Return instr

func (*Builder) Send added in v0.7.13

func (p *Builder) Send() *Builder

Send instr

func (*Builder) SetIndex

func (p *Builder) SetIndex(idx int) *Builder

SetIndex instr

func (*Builder) SetMapIndex

func (p *Builder) SetMapIndex() *Builder

SetMapIndex instr

func (*Builder) Slice

func (p *Builder) Slice(i, j int) *Builder

Slice instr

func (*Builder) Slice3

func (p *Builder) Slice3(i, j, k int) *Builder

Slice3 instr

func (*Builder) StartStmt

func (p *Builder) StartStmt(stmt interface{}) interface{}

StartStmt receives a `StartStmt` event.

func (*Builder) Store

func (p *Builder) Store(idx int32) *Builder

Store instr

func (*Builder) StoreField added in v0.7.7

func (p *Builder) StoreField(typ reflect.Type, index []int) *Builder

StoreField instr

func (*Builder) StoreGoVar

func (p *Builder) StoreGoVar(addr exec.GoVarAddr) *Builder

StoreGoVar instr

func (*Builder) StoreVar

func (p *Builder) StoreVar(v exec.Var) *Builder

StoreVar instr

func (*Builder) Struct added in v0.7.7

func (p *Builder) Struct(typ reflect.Type, arity int) *Builder

Struct instr

func (*Builder) TypeCast

func (p *Builder) TypeCast(from, to reflect.Type) *Builder

TypeCast instr

func (*Builder) WrapIfErr

func (p *Builder) WrapIfErr(nret int, l *Label) *Builder

WrapIfErr instr

func (*Builder) Zero

func (p *Builder) Zero(typ reflect.Type) *Builder

Zero instr

type Code

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

A Code represents generated go code.

func NewCode

func NewCode() *Code

NewCode returns a new Code object.

func (*Code) Bytes

func (p *Code) Bytes(buf []byte) ([]byte, error)

Bytes returns go source code.

func (*Code) Document

func (p *Code) Document() *ast.File

Document returns the whole ast tree.

func (*Code) Format

func (p *Code) Format(dst io.Writer) error

Format code.

func (*Code) Len

func (p *Code) Len() int

Len returns code length.

func (*Code) String

func (p *Code) String() string

type Comprehension

type Comprehension struct {
	TypeOut reflect.Type
	// contains filtered or unexported fields
}

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

func NewForPhrase(in reflect.Type) *ForPhrase

NewForPhrase creates a new ForPhrase instance.

type FuncInfo

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

FuncInfo represents a Go+ function information.

func NewFunc

func NewFunc(name string, nestDepth uint32, isMethod int) *FuncInfo

NewFunc create a Go+ function.

func (*FuncInfo) Args

func (p *FuncInfo) Args(in ...reflect.Type) exec.FuncInfo

Args sets argument types of a Go+ function.

func (*FuncInfo) IsUnnamedOut

func (p *FuncInfo) IsUnnamedOut() bool

IsUnnamedOut returns if function results unnamed or not.

func (*FuncInfo) IsVariadic

func (p *FuncInfo) IsVariadic() bool

IsVariadic returns if this function is variadic or not.

func (*FuncInfo) Name

func (p *FuncInfo) Name() string

Name returns the function name.

func (*FuncInfo) NumIn

func (p *FuncInfo) NumIn() int

NumIn returns a function's input parameter count.

func (*FuncInfo) NumOut

func (p *FuncInfo) NumOut() int

NumOut returns a function's output parameter count.

func (*FuncInfo) Out

func (p *FuncInfo) Out(i int) exec.Var

Out returns the type of a function type's i'th output parameter. It panics if i is not in the range [0, NumOut()).

func (*FuncInfo) Return

func (p *FuncInfo) Return(out ...exec.Var) exec.FuncInfo

Return sets return types of a Go+ function.

func (*FuncInfo) Type

func (p *FuncInfo) Type() reflect.Type

Type returns type of this function.

func (*FuncInfo) Vargs

func (p *FuncInfo) Vargs(in ...reflect.Type) exec.FuncInfo

Vargs sets argument types of a variadic Go+ function.

type GoType added in v0.7.8

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

func (*GoType) Name added in v0.7.8

func (p *GoType) Name() string

func (*GoType) Type added in v0.7.8

func (p *GoType) Type() reflect.Type

type Label

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

Label represents a label.

func NewLabel

func NewLabel(name string) *Label

NewLabel creates a label object.

func (*Label) Name

func (p *Label) Name() string

Name returns the label name.

type Var

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

Var represents a variable.

func NewVar

func NewVar(typ reflect.Type, name string) *Var

NewVar creates a variable instance.

func (*Var) IsUnnamedOut

func (p *Var) IsUnnamedOut() bool

IsUnnamedOut returns if variable unnamed or not.

func (*Var) Name

func (p *Var) Name() string

Name returns variable's name.

func (*Var) Type

func (p *Var) Type() reflect.Type

Type returns variable's type.

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.

Jump to

Keyboard shortcuts

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