Documentation
¶
Overview ¶
Package free defines utilities for computing the free variables of a syntax tree without type information. This is inherently heuristic because of the T{f: x} ambiguity, in which f may or may not be a lexical reference depending on whether T is a struct type.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Names ¶
Names computes an approximation to the set of free names of the AST at node n based solely on syntax.
In the absence of composite literals, the set of free names is exact. Composite literals introduce an ambiguity that can only be resolved with type information: whether F is a field name or a value in `T{F: ...}`. If includeComplitIdents is true, this function conservatively assumes T is not a struct type, so freeishNames overapproximates: the resulting set may contain spurious entries that are not free lexical references but are references to struct fields. If includeComplitIdents is false, this function assumes that T *is* a struct type, so freeishNames underapproximates: the resulting set may omit names that are free lexical references.
TODO(adonovan): includeComplitIdents is a crude hammer: the caller may have partial or heuristic information about whether a given T is struct type. Replace includeComplitIdents with a hook to query the caller.
The code is based on go/parser.resolveFile, but heavily simplified. Crucial differences are:
- Instead of resolving names to their objects, this function merely records whether they are free.
- Labels are ignored: they do not refer to values.
- This is never called on ImportSpecs, so the function panics if it sees one.
Types ¶
This section is empty.