Documentation
¶
Index ¶
- Constants
- func VertexInScope(scope *symbols.Scope, qn *ast.QualifiedName) (ast.Node, bool)
- type Diagnostic
- type MemberLookup
- type Reference
- type Resolver
- func (r *Resolver) AdmittedChildrenOf(scope *symbols.Scope, fqn string, children []*symbols.Symbol) []*symbols.Symbol
- func (r *Resolver) AdmittedTopLevel(doc string, bindings []symbols.RootBinding) []*symbols.Symbol
- func (r *Resolver) AliasNamesNothing(sym *symbols.Symbol) bool
- func (r *Resolver) AliasedElement(sym *symbols.Symbol) *symbols.Symbol
- func (r *Resolver) Endpoint(scope *symbols.Scope, qn *ast.QualifiedName) (ast.Node, bool)
- func (r *Resolver) EndpointSymbol(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
- func (r *Resolver) ImportTarget(scope *symbols.Scope, imp *ast.Import) (*symbols.Symbol, bool)
- func (r *Resolver) ImportedElements(scope *symbols.Scope, imp *ast.Import) []*symbols.Symbol
- func (r *Resolver) InCondition(f func())
- func (r *Resolver) Index() *symbols.Index
- func (r *Resolver) IsBaseThat(sym *symbols.Symbol) bool
- func (r *Resolver) LookupName(scope *symbols.Scope, name string) (*symbols.Symbol, bool)
- func (r *Resolver) LookupNameExcluding(scope *symbols.Scope, name string, decl ast.Node) (*symbols.Symbol, bool)
- func (r *Resolver) MachineStateVertex(scope *symbols.Scope, qn *ast.QualifiedName, sym *symbols.Symbol) bool
- func (r *Resolver) MetadataBodyOwner(scope *symbols.Scope) *symbols.Symbol
- func (r *Resolver) PartAlias(qn *ast.QualifiedName, i int) (*symbols.Symbol, bool)
- func (r *Resolver) PartSymbol(qn *ast.QualifiedName, i int) (*symbols.Symbol, bool)
- func (r *Resolver) ReferringNamespaceFQN(scope *symbols.Scope) string
- func (r *Resolver) ResolveAliasTarget(sym *symbols.Symbol) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveDocument(name string, root *ast.RootNamespace)
- func (r *Resolver) ResolveEndpoint(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveName(scope *symbols.Scope, name string, at ast.Node) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveQualified(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveReference(ref Reference) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveReferenceTarget(scope *symbols.Scope, decl ast.Node, target ast.Node) (*symbols.Symbol, bool)
- func (r *Resolver) ResolveTarget(scope *symbols.Scope, target ast.Node) (*symbols.Symbol, bool)
- func (r *Resolver) SetModel(model MemberLookup)
Constants ¶
const CodeNameConflict = "name-conflict"
CodeNameConflict marks a name declared twice in one namespace, counting the members it inherits (SysML 7.6.1, KerML 7.3.2.1).
const CodeNotAVertex = "not-a-vertex"
CodeNotAVertex marks an endpoint naming an element no transition can start or end at (SysML 7.19.2).
Variables ¶
This section is empty.
Functions ¶
func VertexInScope ¶
VertexInScope finds the vertex an endpoint names from the scope tree alone, innermost scope first, for a machine lowered without a resolver over its document (lower.ToStateGraph): no index is consulted, so nothing outside the scopes the endpoint was written in can answer it.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Span source.Span
Message string
// Code names the kind of problem; empty leaves it to the message.
Code string
// Fixes are the unambiguous edits resolving the diagnostic, offered by an
// editor as quick fixes.
Fixes []quickfix.Fix
// Warning reports a well-formedness rule the reference states as a warning:
// the model still resolves, so validation continues past it.
Warning bool
}
Diagnostic is a name-resolution problem tied to a source span.
type MemberLookup ¶
type MemberLookup interface {
// LookupMember searches for a member by name in sym's scope and inherited scopes.
LookupMember(sym *symbols.Symbol, name string) (*symbols.Symbol, bool)
// LookupContributedMember searches the inherited scopes only, skipping
// what sym itself declares.
LookupContributedMember(sym *symbols.Symbol, name string) (*symbols.Symbol, bool)
}
MemberLookup interface abstracts semantic model for inheritance-aware member resolution. Implemented by *semantics.Model.
type Reference ¶
type Reference struct {
Scope *symbols.Scope
QN *ast.QualifiedName
// Referrer owns the reference subsetting QN is the target of, if any.
Referrer ast.Node
// Chain is set when QN is the member of a feature chain, whose segments are
// members of the operand rather than of Scope (SysML 7.6.6).
Chain *ast.FeatureChainExpr
// Redefines is set when QN is the target of a redefinition, which names a
// feature of Scope's generals rather than a member of Scope itself.
Redefines bool
// Condition is set when QN is a name inside an element-filter condition, which
// its own namespace's filters do not restrict (see InCondition).
Condition bool
}
Reference describes one occurrence of a name to resolve on its own, outside a document walk: which scope it is written in, the declaration that refers to it when it is a reference subsetting's target, and the feature chain it is the member segment of. Used by the editor layer, which resolves a single name under the cursor and must reach the same symbol the document walk did.
func References ¶
func References(root *ast.RootNamespace, rootScope *symbols.Scope) []Reference
References walks a document's scope tree and AST, gathering every QualifiedName reference with the scope it resolves in. It mirrors document.go's traversal: a form handled there but not here is a reference a consumer walking the document — the editor's navigation and highlighting — cannot find.
type Resolver ¶
type Resolver struct {
Diagnostics []Diagnostic
// contains filtered or unexported fields
}
Resolver performs lazy name resolution over a symbol index, memoizing results keyed by the reference AST node and collecting diagnostics.
func (*Resolver) AdmittedChildrenOf ¶
func (r *Resolver) AdmittedChildrenOf(scope *symbols.Scope, fqn string, children []*symbols.Symbol) []*symbols.Symbol
AdmittedChildrenOf keeps the members of the namespace fqn that a lookup made in scope can reach, so an enumeration of a namespace (completion) offers only names resolution then admits.
func (*Resolver) AdmittedTopLevel ¶
AdmittedTopLevel keeps the root-level names a lookup made in doc reaches, so an enumeration of them (completion) offers only names resolution then admits: a name another document's import borrowed, or one this document's import filter rejects, is no member of this document's root namespace.
func (*Resolver) AliasNamesNothing ¶ added in v0.2.0
AliasNamesNothing reports whether the name an alias binds reaches no element, because the alias's own target reference is unresolved (KerML 8.2.3.2). A cyclic alias is excluded: its target reference does name an element.
func (*Resolver) AliasedElement ¶ added in v0.2.0
AliasedElement is the element a name bound to sym reaches: an alias names an existing element rather than being one (KerML 8.2.3.2). An alias whose target is unresolvable stays itself, so its own diagnostic still fires.
func (*Resolver) Endpoint ¶
Endpoint returns the declaration an endpoint names, which lowering builds its edges from (lower.Endpoints); the lookup itself reports nothing, since this tier reports an endpoint naming no vertex when it resolves the document.
func (*Resolver) EndpointSymbol ¶ added in v0.2.0
func (r *Resolver) EndpointSymbol(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
EndpointSymbol returns the resolved symbol for a transition endpoint.
func (*Resolver) ImportTarget ¶ added in v0.2.0
ImportTarget is the namespace or membership an import names, as the import itself reaches it.
func (*Resolver) ImportedElements ¶
ImportedElements enumerates the elements imp surfaces into scope, with the same admission a lookup through imp makes: the import's filter clause and the `filter` members of the declaring namespace (see importAdmits).
func (*Resolver) InCondition ¶
func (r *Resolver) InCondition(f func())
InCondition runs the resolution of a filter condition's own names, which its namespace's filters do not restrict: a condition naming a metadata type the namespace imports would otherwise be filtered by itself (KerML 8.2.4). Nothing resolved meanwhile is memoized, so the bypass reaches no other lookup.
func (*Resolver) IsBaseThat ¶ added in v0.2.0
IsBaseThat reports whether sym is the implicit `that` feature of the base usage: it names the object featuring a usage's values, so it is reachable in any usage body and its declared type Anything is not what a chain reads.
func (*Resolver) LookupName ¶
LookupName resolves an unqualified reference from scope the way a written one resolves — the enclosing scope chain, inherited members, imports, then the global index — but records no diagnostic when it finds nothing.
It is what an evaluator asks: the names it looks up are not all references the source wrote down (a value bound at run time is looked up the same way), and a miss is for the evaluator to report against the value it was reading.
func (*Resolver) LookupNameExcluding ¶
func (r *Resolver) LookupNameExcluding(scope *symbols.Scope, name string, decl ast.Node) (*symbols.Symbol, bool)
LookupNameExcluding resolves name from scope as LookupName does, with decl's own binding hidden: what the name resolves to where decl does not declare it.
func (*Resolver) MachineStateVertex ¶ added in v0.2.0
func (r *Resolver) MachineStateVertex(scope *symbols.Scope, qn *ast.QualifiedName, sym *symbols.Symbol) bool
MachineStateVertex reports whether sym is a vertex of the state machine enclosing scope, using the same inherited-member predicate as endpoint resolution.
func (*Resolver) MetadataBodyOwner ¶ added in v0.2.0
MetadataBodyOwner returns the metadata definition whose features an annotation body's declarations implicitly redefine (KerML 7.4.7), or nil for a scope that is not an annotation body or whose metaclass does not resolve.
func (*Resolver) PartAlias ¶ added in v0.2.0
PartAlias returns the alias membership the i-th segment of qn was written as, where the name it wrote is an alias of the element PartSymbol reports.
func (*Resolver) PartSymbol ¶
PartSymbol returns the symbol the i-th segment of qn resolved to during a previous resolution by this resolver. Callers that need intermediate resolutions of a qualified name (a hover over `A::B` in `A::B::C`, say) read them here.
func (*Resolver) ReferringNamespaceFQN ¶
ReferringNamespaceFQN returns the fully-qualified name of the namespace a reference made in scope belongs to, or "" for one made outside any namespace. It is the context a qualified lookup is answered in: a name a private wildcard import brought into a namespace is a member of it but visible only from within (KerML 8.2.3.3), so `Mid::Hidden` resolves inside Mid and nowhere else.
func (*Resolver) ResolveAliasTarget ¶
ResolveAliasTarget follows an alias symbol to its ultimate non-alias target. Non-alias symbols resolve to themselves. Cycles yield (nil, false).
func (*Resolver) ResolveDocument ¶
func (r *Resolver) ResolveDocument(name string, root *ast.RootNamespace)
ResolveDocument walks the document's references and resolves each, recording diagnostics on the Resolver. name identifies the document in the index.
func (*Resolver) ResolveEndpoint ¶
func (r *Resolver) ResolveEndpoint(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
ResolveEndpoint resolves the vertex a transition endpoint names, reporting one that names nothing or no vertex. A nil name is the sourceless form: legal.
func (*Resolver) ResolveName ¶
func (r *Resolver) ResolveName(scope *symbols.Scope, name string, at ast.Node) (*symbols.Symbol, bool)
ResolveName resolves a single-segment (unqualified) reference from the given scope. The at node keys the memo table.
func (*Resolver) ResolveQualified ¶
func (r *Resolver) ResolveQualified(scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
ResolveQualified resolves a qualified-name reference against the given scope. scope may be nil to resolve purely from the global index / document root. Later tasks implement the walk; this skeleton reports unresolved.
func (*Resolver) ResolveReference ¶
ResolveReference resolves a single name occurrence, honoring both the reference-subsetting and feature-chain rules.
func (*Resolver) ResolveReferenceTarget ¶
func (r *Resolver) ResolveReferenceTarget(scope *symbols.Scope, decl ast.Node, target ast.Node) (*symbols.Symbol, bool)
ResolveReferenceTarget resolves the target of a reference subsetting owned by decl, which is declared in scope.
func (*Resolver) ResolveTarget ¶
ResolveTarget resolves a relationship target to the feature it names. A target is either a qualified name (`references takePicture`) or a feature chain (`perform providePower.generateTorque`), and the chain's segments are members of the previous segment rather than of the enclosing scope (SysML 7.6.6).
Unlike resolveFeatureChain, this reports nothing: the target of a declared relationship is already resolved — and diagnosed — while walking the document, and this is the query side of that result.
func (*Resolver) SetModel ¶
func (r *Resolver) SetModel(model MemberLookup)
SetModel attaches a semantic model for inheritance-aware member resolution. Must be called before resolving feature chains if inherited members are needed.