astutils

package
v0.0.0-...-bb13fef Latest Latest
Warning

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

Go to latest
Published: May 18, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package astutils provides a set of utility functions to build ASTs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsFromFields

func ArgsFromFields(l []*ast.Field) (result []ast.Expr)

ArgsFromFields creates a list of arguments ([]ast.Expr) from a list of fields @ensures len(l)<=len(result)

func CopyFields

func CopyFields(l []*ast.Field, prefix string) (result []*ast.Field)

CopyFields creates a copy of the given field slice. New field names are prefixed by the givin prefix @ensures len(l) == len(result)

func NewBinExp

func NewBinExp(op token.Token, lhs, rhs ast.Expr) (r *ast.BinaryExpr)

NewBinExp yields a binary expression AST @ensures r != nil

func NewCall

func NewCall(pkg, funcName string, args []ast.Expr) (r *ast.CallExpr)

NewCall yields a function call AST @ensures r != nil

func NewCallAnonymous

func NewCallAnonymous(params []*ast.Field, body *ast.BlockStmt, args []ast.Expr) (r *ast.CallExpr)

NewCallAnonymous yields an anonymous call @ensures r != nil

func NewCallArgs

func NewCallArgs(args ...ast.Expr) (r []ast.Expr)

NewCallArgs yields a slice of expressions that can be used as arguments in a function call @ensures len(args) == len(r)

func NewCallAsStmt

func NewCallAsStmt(pkg, funcName string, args []ast.Expr) *ast.ExprStmt

NewCallAsStmt yields a function call as a statement AST

func NewCallExpr

func NewCallExpr(function *ast.Expr, params []ast.Expr) *ast.CallExpr

NewCallExpr yields a new function call expression

func NewDeferStmt

func NewDeferStmt(functionCall *ast.CallExpr) *ast.DeferStmt

NewDeferStmt yields a new defer statement

func NewFuncDecl

func NewFuncDecl(name string, formalParams *ast.FieldList, body *ast.BlockStmt) *ast.FuncDecl

NewFuncDecl yilds a new function declaration

func NewID

func NewID(id string) (r *ast.Ident)

NewID yields an identifier node @requires id != "" @ensures r != nil && r.Name == id

func NewIf

func NewIf(cond ast.Expr, body ast.BlockStmt, opts ...IfOption) *ast.IfStmt

NewIf yields an if AST

func NewStmtBlock

func NewStmtBlock(stmts ...ast.Stmt) (r *ast.BlockStmt)

NewStmtBlock yields a slice of statements @ensures len(r.List) == len(stmts)

func NewStringLit

func NewStringLit(v string) *ast.BasicLit

NewStringLit yields an string literal AST

Types

type IfOption

type IfOption func(*ast.IfStmt)

IfOption is the type representing an option for building an IF AST

func WithElse

func WithElse(block ast.Stmt) IfOption

WithElse is an IfOption to add an Else branch to the IF

func WithInit

func WithInit(init ast.Stmt) IfOption

WithInit is an IfOption to add an Init expression to the IF

Jump to

Keyboard shortcuts

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