scope

package
v0.0.0-...-1151cc2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PackageScope

func PackageScope(p *types.Package, typesInfo *types.Info) (Scope, *Info)

PackageScope creates the package scope of pkg.

Types

type DefMap

type DefMap multiMap[token.Pos]

func (DefMap) Add

func (m DefMap) Add(name string, pos ...token.Pos)

func (DefMap) DeleteFunc

func (m DefMap) DeleteFunc(name string, f func(pos token.Pos) bool)

func (DefMap) Lookup

func (m DefMap) Lookup(name string) []token.Pos

func (DefMap) LookupFunc

func (m DefMap) LookupFunc(name string, f func(pos token.Pos) bool) []token.Pos

func (DefMap) Rename

func (m DefMap) Rename(name string, def token.Pos, newName string)

Rename changes the name of a definition defined at the specified position to a new name.

type Info

type Info struct {
	Defs          DefMap
	Uses          UseMap
	DefScopes     map[*ast.Ident]Scope        // Def ID -> Scope
	DefNonObjects map[*ast.Ident]types.Object // Def ID without types.Object -> Object of it's use.
}

type Scope

type Scope interface {
	// Parent returns the parent scope of this scope. Nil if this scope is universe.
	Parent() Scope
	// LookupDef returns the position of definition of name in this scope.
	// If the name is not defined in this scope, ([token.NoPos], false) is returned.
	LookupDef(name string) token.Pos
	// LookupUse returns all the usages of name in this scope.
	// If no usage is found, the result is nil.
	LookupUse(name string) []defUsePos
	// RenameChildren follows the children chain of scopes starting with scope
	// to rename the definition and all usages of name defined at a specified position.
	RenameChildren(name string, def token.Pos, newName string)
	// Scope returns the scope corresponding to s.
	Scope(s *types.Scope) Scope
	// CanDef returns whether a new name can be defined at pos in this scope.
	CanDef(name string, pos token.Pos) bool
	// CanUse returns whether a new name can be used at pos in this scope.
	// Parameter defScope is the scope where the name would be defined.
	CanUse(name string, pos token.Pos, defScope Scope) bool
	// contains filtered or unexported methods
}

Scope is a lexical scope of go source code.

type Use

type Use struct {
	Use      token.Pos
	UseScope Scope
	Def      token.Pos
}

type UseMap

type UseMap multiMap[Use]

func (UseMap) Add

func (m UseMap) Add(name string, obj ...Use)

func (UseMap) Lookup

func (m UseMap) Lookup(name string) []Use

func (UseMap) Rename

func (m UseMap) Rename(name string, def token.Pos, newName string)

Rename updates the mapping of a given name to a new name for all uses defined at the specified position.

Jump to

Keyboard shortcuts

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