analysisinternal

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package analysisinternal exposes internal-only fields from go/analysis.

Index

Constants

This section is empty.

Variables

View Source
var (
	GetTypeErrors func(p interface{}) []types.Error
	SetTypeErrors func(p interface{}, errors []types.Error)
)

Functions

func FindBestMatch

func FindBestMatch(pattern string, idents []*ast.Ident) ast.Expr

FindBestMatch employs fuzzy matching to evaluate the similarity of each given identifier to the given pattern. We return the identifier whose name is most similar to the pattern.

func FindMatchingIdents

func FindMatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, pkg *types.Package) map[types.Type][]*ast.Ident

FindMatchingIdents finds all identifiers in 'node' that match any of the given types. 'pos' represents the position at which the identifiers may be inserted. 'pos' must be within the scope of each of identifier we select. Otherwise, we will insert a variable at 'pos' that is unrecognized.

func IsZeroValue

func IsZeroValue(expr ast.Expr) bool

IsZeroValue checks whether the given expression is a 'zero value' (as determined by output of analysisinternal.ZeroValue)

func StmtToInsertVarBefore

func StmtToInsertVarBefore(path []ast.Node) ast.Stmt

StmtToInsertVarBefore returns the ast.Stmt before which we can safely insert a new variable. Some examples:

Basic Example: z := 1 y := z + x If x is undeclared, then this function would return `y := z + x`, so that we can insert `x := ` on the line before `y := z + x`.

If stmt example: if z == 1 { } else if z == y {} If y is undeclared, then this function would return `if z == 1 {`, because we cannot insert a statement between an if and an else if statement. As a result, we need to find the top of the if chain to insert `y := ` before.

func TypeErrorEndPos

func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos

func TypeExpr

func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Type) ast.Expr

func WalkASTWithParent

func WalkASTWithParent(n ast.Node, f func(n ast.Node, parent ast.Node) bool)

WalkASTWithParent walks the AST rooted at n. The semantics are similar to ast.Inspect except it does not call f(nil).

func ZeroValue

func ZeroValue(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Type) ast.Expr

Types

type TypeErrorPass

type TypeErrorPass string
const (
	NoNewVars      TypeErrorPass = "nonewvars"
	NoResultValues TypeErrorPass = "noresultvalues"
	UndeclaredName TypeErrorPass = "undeclaredname"
)

Jump to

Keyboard shortcuts

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