analysisutil

package module
Version: v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 10 Imported by: 50

README

analysisutil

PkgGoDev

Utilities for x/tools/go/analysis package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinOp added in v0.0.4

func BinOp(b *ssa.BasicBlock) []*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 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 Field added in v0.5.0

func Field(t types.Type, name string) (int, *types.Var)

Field returns field of the struct type. If the type is not struct or has not the field, Field returns -1, nil. If the type is a named type or a pointer type, Field calls itself recursively with an underlying type or an element type of pointer.

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 Imported added in v0.0.4

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

Imported returns true when the given pass imports the pkg.

func InspectFuncs added in v0.6.3

func InspectFuncs(funcs []*ssa.Function, f func(i int, instr ssa.Instruction) bool)

InspectFuncs inspects functions.

func InspectInstr added in v0.2.0

func InspectInstr(start *ssa.BasicBlock, i int, f func(i int, instr ssa.Instruction) bool)

InspectInstr inspects from i-th instruction of start block to succsessor blocks.

func Interfaces

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

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

func IsGeneratedFile added in v0.6.0

func IsGeneratedFile(file *ast.File) bool

IsGeneratedFile reports whether the file has been generated automatically. If file is nil, IsGeneratedFile will return false.

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 NotCalledIn added in v0.2.0

func NotCalledIn(f *ssa.Function, receiver types.Type, methods ...*types.Func) []ssa.Instruction

NotCalledIn checks whether receiver's method is called in a function. If there is no methods calling at a path from an instruction which type is receiver to all return instruction, NotCalledIn returns these instructions.

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) []*ssa.Phi

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

func RemoveVendor

func RemoveVendor(path string) string

RemoVendor removes vendoring information from import path.

func ReportWithoutIgnore added in v0.1.0

func ReportWithoutIgnore(pass *analysis.Pass, names ...string) func(analysis.Diagnostic)

ReportWithoutIgnore returns a report function which can set to (analysis.Pass).Report. The report function ignores a diagnostic which annotated by ignore comment as the below.

//lint:ignore Check1[,Check2,...,CheckN] reason

names is a list of checker names. If names was omitted, the report function ignores by pass.Analyzer.Name.

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

func Under added in v0.3.0

func Under(t types.Type) types.Type

Under returns the most bottom underlying type. Deprecated: (types.Type).Underlying returns same value of it.

func Used added in v0.4.0

func Used(v ssa.Value, instrs []ssa.Instruction) ssa.Instruction

Used returns an instruction which uses the value in the instructions.

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, Func also checks the receiver.

func (*CalledChecker) NotIn added in v0.2.0

func (c *CalledChecker) NotIn(f *ssa.Function, receiver types.Type, methods ...*types.Func) []ssa.Instruction

NotIn checks whether receiver's method is called in a function. If there is no methods calling at a path from an instruction which type is receiver to all return instruction, NotIn returns these instructions.

Jump to

Keyboard shortcuts

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