stmtlookup

package
v1.165.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package stmtlookup reads which statements a script's call can run when the source says so (#2615, #2623): a lookup into literals (spec[3], where spec is one value of a dict of constant lists) is each value it can pick, and a statements argument built as a list, a list comprehension or a name bound to either is the statements it holds. The flow diagram and an application's diagram read what a call writes through it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Candidates

func Candidates(sc Resolver, e syntax.Expr) ([]syntax.Expr, bool)

Candidates is every expression e can evaluate to, when the source says so (#2623): a lookup into a literal -- {...}[k], [...][i], or a name bound to one and then indexed, as spec[3] where spec = {...}[kind] -- is each value the lookup can return, the value a constant key names or every value when the key is computed. Anything that is not a lookup is itself. ok is false when a lookup's container is not a literal the source holds, a constant key names nothing in it, or there are more than maxCandidates.

func Grown added in v1.165.0

func Grown(body []syntax.Stmt) map[string][]syntax.Expr

Grown is ListsBound narrowed to the names the body grows (appends to, extends, or adds to with +=): the lists built in more than one step.

func ListsBound

func ListsBound(body []syntax.Stmt) map[string][]syntax.Expr

ListsBound is each list a function body builds under a plain name, by the name: every list literal, list comprehension or other value assigned to it, and every element appended and list extended or added to it (#2699). A name the body only appends to holds, first, what it was bound to before the body ran (a parameter), as the name itself read in the enclosing scope.

func LoadLibraries added in v1.165.0

func LoadLibraries(file *syntax.File, libs Libraries) map[string]Loaded

LoadLibraries reads every name file loads from a library libs holds. A load of a library libs does not hold, or whose source does not parse, binds nothing.

func LoopElements added in v1.165.0

func LoopElements(vars, iterable syntax.Expr) map[string]syntax.Expr

LoopElements is what each variable of a loop over iterable stands for: an element of what it is drawn from, as a lookup with a key known only when the script runs, which Candidates reads as every element (#2699). A single variable over a list, a tuple or d.values() is one element; the second of two over d.items() or enumerate(list) is one value. Any other loop binds nothing.

func Opaque added in v1.165.0

func Opaque(name string) *syntax.Ident

Opaque is a name standing for a value only known when the script runs.

func Statements

func Statements(sc Resolver, e syntax.Expr, bound map[string][]syntax.Expr) ([]syntax.Expr, bool)

Statements is what a statements argument holds, when the source says: a list literal's elements, a list comprehension's element (one statement repeated per row, #2623), or what a name is bound to in the function the call is written in (bound) or else in sc. ok is false when the statements are assembled at run time.

func Substitute added in v1.165.0

func Substitute(sc Resolver, e syntax.Expr) syntax.Expr

Substitute is e with every local name it holds replaced by what sc binds it to, recursively, so the result reads the same in any scope: a module name and a builtin stay, a local the source binds becomes its expression, and a local it does not becomes Opaque. It is how a caller's argument is carried into the function it is passed to (#2699).

Types

type Foreign added in v1.165.0

type Foreign interface {
	// Global is a module name's constant text, or else the expression the
	// module binds it to.
	Global(id *syntax.Ident) (constant string, expr syntax.Expr, ok bool)
}

Foreign is a Resolver for a module other than the one a statement is read in: a library's. Substitute replaces its module names by what they are, since the same names in the reading script are other variables.

type Funcs added in v1.165.0

type Funcs interface {
	Func(name string) (def *syntax.DefStmt, outer Resolver)
}

Funcs is a Resolver that also names the functions the source defines, so a statement list a helper returns is read from its return statements. outer is the scope the function's module names are read in: nil for the script's own, a library's for a function the script loads.

type Libraries added in v1.165.0

type Libraries map[scriptlib.Ref]string

Libraries is the source of each library version a script loads, by the reference its load names (#2699). A statement a script runs is often a constant a library defines, or the value a library's function returns; with the library's source a name the script loads reads as what the library binds it to, at the version the load names, rather than as a value only known when the script runs.

func (Libraries) Named added in v1.165.0

func (l Libraries) Named() map[string]string

Named is each library's source by its reference's text.

type Loaded added in v1.165.0

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

Loaded is one name a script loads: the library and the name it binds there. The zero Loaded is a name loaded from no library read.

func (Loaded) Constant added in v1.165.0

func (n Loaded) Constant() (string, bool)

Constant is a loaded name's text when the library binds it to a constant.

func (Loaded) Def added in v1.165.0

func (n Loaded) Def() (*syntax.DefStmt, Resolver)

Def is the function a loaded name is in its library, with the scope its body is read in; nil for a name that is no function.

func (Loaded) Expr added in v1.165.0

func (n Loaded) Expr() syntax.Expr

Expr is what the library binds a loaded name to, scope free; nil for none.

type Resolver

type Resolver interface {
	// Bound is the expression a name was last assigned, nil for none.
	Bound(id *syntax.Ident) syntax.Expr
	// Known is a local's value when the analyzer knows it.
	Known(id *syntax.Ident) (string, bool)
}

Resolver reads the names a lookup is followed through, in the scope a call was written in.

Jump to

Keyboard shortcuts

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