inst

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddImport

func AddImport(fs *token.FileSet, ast *ast.File, name string, path string) error

func DumpAstFile

func DumpAstFile(fset *token.FileSet, astFile *ast.File, dstFile string) error

DumpAstFile serialized AST to given file

func Run

func Run(iCtx *InstContext, r *PassRegistry, passNames []string) error

Run executes passes with given a list of pass name and instrumentation context.

func RunPass

func RunPass(p InstPass, iCtx *InstContext) error

Types

type InstContext

type InstContext struct {
	File            string
	OriginalContent []byte
	FS              *token.FileSet
	AstFile         *ast.File
	Type            *types.Info
	Metadata        map[string]interface{} // user can set custom metadata come along with instrumentation context
}

InstContext contains all information needed to instrument one single Golang source code.

func NewInstContext

func NewInstContext(goSrcFile string) (*InstContext, error)

NewInstContext creates a InstContext by given Golang source file

func (*InstContext) GetMetadata

func (i *InstContext) GetMetadata(key string) (interface{}, bool)

func (*InstContext) SetMetadata

func (i *InstContext) SetMetadata(key string, value interface{})

type InstPass

type InstPass interface {
	// Deps returns a list of dependent passes
	Deps() []string

	Before(iCtx *InstContext)

	GetPreApply(iCtx *InstContext) func(*astutil.Cursor) bool

	GetPostApply(iCtx *InstContext) func(*astutil.Cursor) bool

	After(iCtx *InstContext)
}

InstPass shapes the pass used for instrumenting a single Golang source code

type InstPassConstructor

type InstPassConstructor func() InstPass

type NoPassError

type NoPassError struct {
	Name string
}

func (*NoPassError) Error

func (e *NoPassError) Error() string

type PassExistedError

type PassExistedError struct {
	Name string
}

func (*PassExistedError) Error

func (e *PassExistedError) Error() string

type PassRegistry

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

PassRegistry records all registered passes

func NewPassRegistry

func NewPassRegistry() *PassRegistry

func (*PassRegistry) GetNewPassInstance

func (r *PassRegistry) GetNewPassInstance(name string) (InstPass, error)

GetPass returns the pass with given name

func (*PassRegistry) HasPass

func (r *PassRegistry) HasPass(name string) bool

HasPass return true if pass registered, false otherwise

func (*PassRegistry) ListOfPassNames

func (r *PassRegistry) ListOfPassNames() []string

func (*PassRegistry) Register

func (r *PassRegistry) Register(name string, passc InstPassConstructor) error

AddPass adds a unique pass into registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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