...

Package bzlenv

import "github.com/bazelbuild/buildtools/bzlenv"
Overview
Index

Overview ▾

Package bzlenv provides function to create and update a static environment.

func CollectLValues

func CollectLValues(node build.Expr) []*build.Ident

CollectLValues returns the list of identifiers that are assigned (assuming that node is a valid LValue). For example, it returns `a`, `b` and `c` for the input `a, (b, c)`.

func WalkOnceWithEnvironment

func WalkOnceWithEnvironment(node build.Expr, env *Environment, fct func(e *build.Expr, env *Environment))

WalkOnceWithEnvironment calls fct on every child of node, while maintaining the Environment of all available symbols.

type Environment

Environment represents a static environment (e.g. information about all available symbols).

type Environment struct {
    Blocks   []block
    Function *build.DefStmt // enclosing function (or nil on top-level)

    Stack []build.Expr // parents of the current node
    // contains filtered or unexported fields
}

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates a new empty Environment.

func (*Environment) Get

func (e *Environment) Get(name string) *NameInfo

Get resolves the name and resolves information about the binding (or nil if it's not defined).

type NameInfo

NameInfo represents information about a symbol name.

type NameInfo struct {
    ID         int    // unique identifier
    Name       string // name of the variable (not unique)
    Kind       ValueKind
    Definition build.Expr // node that defines the value
}

type ValueKind

ValueKind describes how a binding was declared.

type ValueKind int

List of ValueKind values.

const (
    Builtin   ValueKind = iota // language builtin
    Imported                   // declared with load()
    Global                     // declared with assignment on top-level
    Function                   // declared with a def
    Parameter                  // function parameter
    Local                      // local variable, defined with assignment or as a loop variable
)

func (ValueKind) String

func (k ValueKind) String() string