guru

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const HasAlias = true

Variables

This section is empty.

Functions

func FindPackageMember

func FindPackageMember(ctxt *build.Context, fset *token.FileSet, srcdir, pkg, member string) (token.Token, token.Pos, error)

FindPackageMember returns the type and position of the declaration of pkg.member by loading and parsing the files of that package. srcdir is the directory in which the import appears.

func GuessImportPath

func GuessImportPath(filename string, buildContext *build.Context) (srcdir, importPath string, err error)

GuessImportPath finds the package containing filename, and returns its source directory (an element of $GOPATH) and its import path relative to it.

TODO(adonovan): what about _test.go files that are not part of the package?

func PackageForQualIdent

func PackageForQualIdent(path []ast.Node, id *ast.Ident) string

PackageForQualIdent returns the package p if id is X in a qualified identifier p.X; it returns "" otherwise.

Precondition: id is path[0], and the parser did not resolve id to a local object. For speed, PackageForQualIdent assumes that p is a package iff it is the basename of an import path (and not, say, a package-level decl in another file or a predeclared identifier).

func Run

func Run(mode string, q *Query) error

Run runs an guru query and populates its Fset and Result.

Types

type Query

type Query struct {
	Pos   string         // query position
	Build *build.Context // package loading configuration

	// pointer analysis options
	Scope      []string  // main packages in (*loader.Config).FromArgs syntax
	PTALog     io.Writer // (optional) pointer-analysis log file
	Reflection bool      // model reflection soundly (currently slow).

	// result-printing function, safe for concurrent use
	Output func(*token.FileSet, QueryResult)
}

A Query specifies a single guru query.

type QueryResult

type QueryResult interface {
	// JSON returns the QueryResult in JSON form.
	JSON(fset *token.FileSet) []byte

	// PrintPlain prints the QueryResult in plain text form.
	// The implementation calls printfFunc to print each line of output.
	PrintPlain(printf printfFunc)

	Result(fset *token.FileSet) interface{}
}

A QueryResult is an item of output. Each query produces a stream of query results, calling Query.Output for each one.

Jump to

Keyboard shortcuts

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