analysisutil

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: MIT Imports: 7 Imported by: 1

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 BinOp

func BinOp(b *ssa.BasicBlock) (binops []*ssa.BinOp)

BinOp returns binary operator values which are contained in the block b.

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 CalledBeforeAndEqualTo added in v0.0.6

func CalledBeforeAndEqualTo(b *ssa.BasicBlock, receiver ssa.Value, method *types.Func, o types.Object) bool

CalledBeforeAndEqualTo checks like CalledFromBefore and if the result of call is equal to o.

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. CalledFrom uses types.Type and return value of i-th instruction as the receiver and check it.

func CalledFromAfter added in v0.0.6

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

CalledFromAfter checks whether receiver's method is called in instructions which belongs to after i-th instructions, or in succs blocks of b. The second result is whether type of i-th instruction does not much receiver or matches with ignore cases. FromAfter takes receiver as a value of ssa.Value.

func CalledFromBefore added in v0.0.6

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

CalledFromBefore checks whether receiver's method is called in an instruction which belongs to before i-th instructions, or in preds 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

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 PkgUsedInFunc

func PkgUsedInFunc(pass *analysis.Pass, pkgPath string, f *ssa.Function) bool

PkgUsedInFunc returns true when the given f imports the pkg.

func PkgUsedInPass

func PkgUsedInPass(pkgPath string, pass *analysis.Pass) bool

PkgUsedInPass returns true when the given pass imports the pkg.

func RemoveVendor

func RemoveVendor(path string) string

RemoVendor removes vendoring information from import path.

func ReturnReceiverIfCalled added in v0.0.6

func ReturnReceiverIfCalled(instr ssa.Instruction, f *types.Func) ssa.Value

ReturnReceiverIfCalled returns value of the first argment which is probablly the receiver when f is called in the instr. If recv is not nil, Called also checks the receiver.

func Returns

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

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

func Structs

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

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) Before added in v0.0.6

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

Before checks whether receiver's method is called in an instruction which belongs to before i-th instructions, or in preds 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. Before uses types.Type and return value of i-th instruction as the receiver and check it.

func (*CalledChecker) BeforeAndEqualTo added in v0.0.6

func (c *CalledChecker) BeforeAndEqualTo(b *ssa.BasicBlock, receiver ssa.Value, method *types.Func, o types.Object) bool

BeforeAndEqualTo as a method of CalledChecker checks like CalledFromBefore and if the result of call is equal to o.

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 match receiver or matches with ignore cases. This compares a types.Type to the type of return value of i-th instruction and use it as the receiver and check it.

func (*CalledChecker) FromAfter added in v0.0.6

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

FromAfter checks whether receiver's method is called in instructions which belongs to after i-th instructions, or in succs blocks of b. The second result is whether type of i-th instruction does not much receiver or matches with ignore cases. FromAfter takes receiver as a value of ssa.Value.

func (*CalledChecker) FromBefore added in v0.0.6

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

FromBefore checks whether receiver's method is called in instructions which belongs to before i-th instructions, or in preds blocks of b. The second result is whether type of i-th instruction does not much receiver or matches with ignore cases. FromBefore takes receiver as a value of ssa.Value.

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