lexical

package
Version: v0.0.0-...-2824937 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT, BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package lexical computes the structure of the lexical environment, including the definition of and references to all universal, package-level, file-level and function-local entities. It does not record qualified identifiers, labels, struct fields, or methods.

It is intended for renaming and refactoring tools, which need a more precise understanding of identifier resolution than is available from the output of the type-checker alone.

THIS INTERFACE IS EXPERIMENTAL AND MAY CHANGE OR BE REMOVED IN FUTURE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

A Block is a level of the lexical environment, a tree of blocks. It maps names to objects.

func (*Block) Depth

func (b *Block) Depth() int

Depth returns the depth of this block in the block tree. The universal block has depth 1, a package block 2, a file block 3, etc.

func (*Block) Lookup

func (b *Block) Lookup(name string) (types.Object, *Block)

Lookup returns the definition of name in the environment specified by b, and the Block that defines it, which may be an ancestor.

func (*Block) String

func (b *Block) String() string

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

An Environment is a snapshot of a Block taken at a certain lexical position. It may contain bindings for fewer names than the (completed) block, or different bindings for names that are re-defined later in the block.

For example, the lexical Block for the function f below contains a binding for the local var x, but the Environments captured by at the two print(x) calls differ: the first contains this binding, the second does not. The first Environment contains a different binding for x: the string var defined in the package block, an ancestor.

var x string
func f() {
	print(x)
	x := 1
	print(x)
}

func (Environment) Block

func (env Environment) Block() *Block

Block returns the block of which this environment is a partial view.

func (Environment) Lookup

func (env Environment) Lookup(name string) (types.Object, *Block)

Lookup returns the definition of name in the environment specified by env, and the Block that defines it, which may be an ancestor.

func (Environment) String

func (env Environment) String() string

type Info

type Info struct {
	Defs         map[types.Object]*Block      // maps each object to its defining lexical block
	Refs         map[types.Object][]Reference // maps each object to the set of references to it
	Blocks       map[ast.Node]*Block          // maps declaring syntax to block; nil => universe
	PackageBlock *Block                       // the package-level lexical block
}

An Info contains the lexical reference structure of a package.

func Structure

func Structure(fset *token.FileSet, pkg *types.Package, info *types.Info, files []*ast.File) *Info

Structure computes the structure of the lexical environment of the package specified by (pkg, info, files).

The info.{Types,Defs,Uses,Implicits} maps must have been populated by the type-checker

fset is used for logging.

type Reference

type Reference struct {
	Id  *ast.Ident
	Env Environment
}

A Reference provides the lexical environment for a given reference to an object in lexical scope.

Source Files

Jump to

Keyboard shortcuts

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