Documentation ¶
Overview ¶
Package astutils provides a set of utility functions to build ASTs
Index ¶
- func ArgsFromFields(l []*ast.Field) (result []ast.Expr)
- func CopyFields(l []*ast.Field, prefix string) (result []*ast.Field)
- func NewBinExp(op token.Token, lhs, rhs ast.Expr) (r *ast.BinaryExpr)
- func NewCall(pkg, funcName string, args []ast.Expr) (r *ast.CallExpr)
- func NewCallAnonymous(params []*ast.Field, body *ast.BlockStmt, args []ast.Expr) (r *ast.CallExpr)
- func NewCallArgs(args ...ast.Expr) (r []ast.Expr)
- func NewCallAsStmt(pkg, funcName string, args []ast.Expr) *ast.ExprStmt
- func NewCallExpr(function *ast.Expr, params []ast.Expr) *ast.CallExpr
- func NewDeferStmt(functionCall *ast.CallExpr) *ast.DeferStmt
- func NewFuncDecl(name string, formalParams *ast.FieldList, body *ast.BlockStmt) *ast.FuncDecl
- func NewID(id string) (r *ast.Ident)
- func NewIf(cond ast.Expr, body ast.BlockStmt, opts ...IfOption) *ast.IfStmt
- func NewStmtBlock(stmts ...ast.Stmt) (r *ast.BlockStmt)
- func NewStringLit(v string) *ast.BasicLit
- type IfOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgsFromFields ¶
ArgsFromFields creates a list of arguments ([]ast.Expr) from a list of fields @ensures len(l)<=len(result)
func CopyFields ¶
CopyFields creates a copy of the given field slice. New field names are prefixed by the givin prefix @ensures len(l) == len(result)
func NewCallAnonymous ¶
NewCallAnonymous yields an anonymous call @ensures r != nil
func NewCallArgs ¶
NewCallArgs yields a slice of expressions that can be used as arguments in a function call @ensures len(args) == len(r)
func NewCallAsStmt ¶
NewCallAsStmt yields a function call as a statement AST
func NewCallExpr ¶
NewCallExpr yields a new function call expression
func NewDeferStmt ¶
NewDeferStmt yields a new defer statement
func NewFuncDecl ¶
NewFuncDecl yilds a new function declaration
func NewStmtBlock ¶
NewStmtBlock yields a slice of statements @ensures len(r.List) == len(stmts)
func NewStringLit ¶
NewStringLit yields an string literal AST