extend

package
v0.0.0-...-d522da9 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

The extend package contains features for operating on and extending syntax trees.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileScope

type FileScope struct {
	// Root is the root scope.
	Root *Scope
	// Globals is a list of global variables that have been assigned to.
	Globals []*Variable
	// VariableMap maps a NAME token to a Variable.
	VariableMap map[*tree.Token]*Variable
	// ScopeMap maps a Node to the scope that is opened by or is otherwise
	// associated with the node.
	ScopeMap map[tree.Node]*Scope
}

FileScope contains information about the scopes of a file, including variables and their associations with a parse tree.

func BuildFileScope

func BuildFileScope(file *tree.File) *FileScope

BuildFileScope walks the given parse tree, building a tree of scopes and the variables they contain.

type Scope

type Scope struct {
	// Parent is the outer, surrounding scope.
	Parent *Scope
	// Children is a list of inner scopes.
	Children []*Scope
	// Variables is the list of variables declared in the scope.
	Variables []*Variable
	// Node is the tree node that opens or is otherwise associated with the
	// scope. May be nil.
	Node tree.Node
	// Items is a list of NAME tokens and Scopes, ordered semantically.
	Items []interface{}
	// Start indicates the start of the lifetime of the scope. The value has no
	// objective meaning, and should be used only for comparing with other
	// lifetimes within the same generated FileScope.
	Start int
	// End indicates the end of the lifetime of the scope. The value has no
	// objective meaning, and should be used only for comparing with other
	// lifetimes within the same generated FileScope.
	End int
}

Scope contains a list of the variables declared in the scope.

func NewScope

func NewScope(parent *Scope, node tree.Node) *Scope

NewScope creates an inner scope, optionally associating the scope with the node that opens it.

type Variable

type Variable struct {
	// Type is the variable type.
	Type VariableType
	// Name is the name of the variable.
	Name string
	// References is a list of NAME tokens that refer to the entity. When the
	// variable is local, the first value is the declaration of the variable.
	References []*tree.Token
	// Scopes is a list of scopes corresponding to entries in References.
	Scopes []*Scope
	// Positions is a list of positions corresponding to entries in References.
	Positions []int
	// LifeStart indicates the start of the lifetime and visiblity of the
	// variable. The value has no objective meaning, and should be used only for
	// comparing with other lifetimes within the same generated FileScope.
	LifeStart int
	// LifeEnd indicates the end of the lifetime of the variable. The value has
	// no objective meaning, and should be used only for comparing with other
	// lifetimes within the same generated FileScope.
	LifeEnd int
	// ScopeEnd indicates the end of the visibility of the variable. The value
	// has no objective meaning, and should be used only for comparing with
	// other lifetimes within the same generated FileScope.
	ScopeEnd int
}

Variable describes a single named entity within a parse tree.

func (*Variable) VisiblityOverlapsWith

func (v *Variable) VisiblityOverlapsWith(w *Variable) bool

VisiblityOverlapsWith returns whether the visiblity of v overlaps with the visiblity of w.

type VariableType

type VariableType uint8

VariableType indicates the type of Variable.

const (
	InvalidVar VariableType = iota

	LocalVar  // LocalVar indicates a variable local to its scope.
	GlobalVar // GlobalVar indicates a variable defined in the global table.
)

func (VariableType) String

func (t VariableType) String() string

Jump to

Keyboard shortcuts

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