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(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.
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() *Environment
NewEnvironment creates a new empty Environment.
func (e *Environment) Get(name string) *NameInfo
Get resolves the name and resolves information about the binding (or nil if it's not defined).
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 }
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 (k ValueKind) String() string