macro

package
v0.0.0-...-e03b1fb Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStop = errors.New("macro exit")

Functions

func Main

func Main(macros Macros)

func NewErrorCallback

func NewErrorCallback(fset *token.FileSet) func(pos token.Pos, err error)

Types

type Context

type Context struct {
	*astutil.Cursor
	Pre     bool
	Delayed Delayed
	Report  func(Report)

	// AST
	File    *ast.File
	FileSet *token.FileSet

	// Types
	Package    *types.Package
	TypesInfo  *types.Info
	TypesSizes types.Sizes

	Pragmas pragma.Pragmas
}

func (Context) AddDecls

func (c Context) AddDecls(decls ...ast.Decl)

func (Context) AddImports

func (c Context) AddImports(importSpec ...*ast.ImportSpec)

func (Context) Reportf

func (c Context) Reportf(pos token.Pos, format string, args ...interface{})

type Delayed

type Delayed map[string]map[string]struct{}

type Handler

type Handler interface {
	Handle(cursor Context, node ast.Node) error
}

func OnlyFunction

func OnlyFunction(name string, cb func(ctx Context, call *ast.CallExpr) error) Handler

type HandlerFunc

type HandlerFunc func(cursor Context, node ast.Node) error

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(cursor Context, node ast.Node) error

type Macros

type Macros map[string]Handler

func (Macros) AddHandler

func (m Macros) AddHandler(name string, h Handler)

func (Macros) Get

func (m Macros) Get(names ...string) (result map[string]Handler)

type Report

type Report struct {
	Pos     token.Pos
	Message string
}

type Rewriter

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

func NewRewriter

func NewRewriter(fset *token.FileSet) Rewriter

func (Rewriter) Report

func (r Rewriter) Report(pos token.Pos, args ...interface{})

func (Rewriter) Reportf

func (r Rewriter) Reportf(pos token.Pos, f string, args ...interface{})

func (Rewriter) Rewrite

func (r Rewriter) Rewrite(handler Handler, context Context, node ast.Node) ast.Node

Jump to

Keyboard shortcuts

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