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 ¶
- func Candidates(sc Resolver, e syntax.Expr) ([]syntax.Expr, bool)
- func Grown(body []syntax.Stmt) map[string][]syntax.Expr
- func ListsBound(body []syntax.Stmt) map[string][]syntax.Expr
- func LoadLibraries(file *syntax.File, libs Libraries) map[string]Loaded
- func LoopElements(vars, iterable syntax.Expr) map[string]syntax.Expr
- func Opaque(name string) *syntax.Ident
- func Statements(sc Resolver, e syntax.Expr, bound map[string][]syntax.Expr) ([]syntax.Expr, bool)
- func Substitute(sc Resolver, e syntax.Expr) syntax.Expr
- type Foreign
- type Funcs
- type Libraries
- type Loaded
- type Resolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Candidates ¶
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
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 ¶
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
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
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
Opaque is a name standing for a value only known when the script runs.
func Statements ¶
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
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
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
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.
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
Constant is a loaded name's text when the library binds it to a constant.
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.