analysisutil

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: MIT Imports: 6 Imported by: 92

README

analysisutil

godoc.org

Utilities for x/tools/go/analysis package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Called

func Called(instr ssa.Instruction, recv ssa.Value, f *types.Func) bool

Called returns true when f is called in the instr. If recv is not nil, Called also checks the receiver.

func CalledFrom

func CalledFrom(b *ssa.BasicBlock, i int, receiver types.Type, methods ...*types.Func) (called, ok bool)

CalledFrom checks whether receiver's method is called in an instruction which belogns to after i-th instructions, or in succsor blocks of b. The first result is above value. The second result is whether type of i-th instruction does not much receiver or matches with ignore cases.

func File

func File(pass *analysis.Pass, pos token.Pos) *ast.File

File finds *ast.File in pass.Files by pos.

func HasField added in v0.0.2

func HasField(s *types.Struct, f *types.Var) bool

HasField returns whether the struct has the field.

func IfInstr

func IfInstr(b *ssa.BasicBlock) *ssa.If

IfInstr returns *ssa.If which is contained in the block b. If the block b has not any if instruction, IfInstr returns nil.

func ImplementsError

func ImplementsError(t types.Type) bool

ImplementsError return whether t implements error interface.

func Interfaces

func Interfaces(pkg *types.Package) map[string]*types.Interface

Interfaces returns a map of interfaces which are declared in the package.

func LookupFromImports

func LookupFromImports(imports []*types.Package, path, name string) types.Object

LookupFromImports finds an object from import paths.

func MethodOf

func MethodOf(typ types.Type, name string) *types.Func

MethodOf returns a method which has given name in the type.

func ObjectOf

func ObjectOf(pass *analysis.Pass, pkg, name string) types.Object

ObjectOf returns types.Object by given name in the package.

func Phi

func Phi(b *ssa.BasicBlock) (phis []*ssa.Phi)

Phi returns phi values which are contained in the block b.

func RemoveVendor

func RemoveVendor(path string) string

RemoVendor removes vendoring infomation from import path.

func Returns

func Returns(v ssa.Value) []*ssa.Return

Returns returns a slice of *ssa.Return in the function.

func Structs added in v0.0.2

func Structs(pkg *types.Package) map[string]*types.Struct

Structs returns a map of structs which are declared in the package.

func TypeOf

func TypeOf(pass *analysis.Pass, pkg, name string) types.Type

TypeOf returns types.Type by given name in the package. TypeOf accepts pointer types such as *T.

func TypesInfo added in v0.0.3

func TypesInfo(info ...*types.Info) *types.Info

Types

type CalledChecker

type CalledChecker struct {
	Ignore func(instr ssa.Instruction) bool
}

CalledChecker checks a function is called. See From and Func.

func (*CalledChecker) From

func (c *CalledChecker) From(b *ssa.BasicBlock, i int, receiver types.Type, methods ...*types.Func) (called, ok bool)

From checks whether receiver's method is called in an instruction which belogns to after i-th instructions, or in succsor blocks of b. The first result is above value. The second result is whether type of i-th instruction does not much receiver or matches with ignore cases.

func (*CalledChecker) Func

func (c *CalledChecker) Func(instr ssa.Instruction, recv ssa.Value, f *types.Func) bool

Func returns true when f is called in the instr. If recv is not nil, Called also checks the receiver.

Jump to

Keyboard shortcuts

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