Documentation
¶
Overview ¶
Package symbols builds an immutable per-document scope tree and a global qualified-name index over a parsed ast.RootNamespace.
Index ¶
- Variables
- func DeclIdent(decl ast.Node) (ast.Identification, bool)
- func DocNameOf(scope *Scope) string
- func FQNOf(sym *Symbol) string
- func FirstNamesSource(n *ast.InitialNode) bool
- func HasFQN(sym *Symbol, fqn string) bool
- func InStateMachine(scope *Scope) bool
- func IsAbstract(sym *Symbol) bool
- func NameChain(sym *Symbol) []string
- func SameElement(a, b *Symbol) bool
- func SetDocName(scope *Scope, name string)
- func TextDigest(text []byte) string
- func UsageAnnotatesOthers(u *ast.Usage) bool
- func VisibleAs(v ast.Visibility, inside, inheriting bool) bool
- func VisibleOutside(v ast.Visibility) bool
- type AnnotationFacts
- type AnnotationValueFacts
- type DimensionFactorFacts
- type DimensionFacts
- type ElementFilter
- type ElementKey
- type ExprWalker
- type FilterOp
- type FilterPredicate
- type FilterUnsupportedKind
- type FilterValue
- type FilterValueKind
- type Index
- func (idx *Index) AddDocument(name string, root *ast.RootNamespace)
- func (idx *Index) AddDocumentWithKind(name string, root *ast.RootNamespace, kind source.Kind)
- func (idx *Index) Base() *Index
- func (idx *Index) Declaring(fqn string) *Symbol
- func (idx *Index) DocumentKind(name string) source.Kind
- func (idx *Index) DocumentLibraryTier(name string) LibraryTier
- func (idx *Index) DocumentOfRoot(scope *Scope) string
- func (idx *Index) DocumentRoot(name string) *Scope
- func (idx *Index) Documents() []string
- func (idx *Index) ExpandWildcardImports()
- func (idx *Index) FQNs() []string
- func (idx *Index) FQNsEndingIn(name string, limit int) []string
- func (idx *Index) Freeze()
- func (idx *Index) Frozen() bool
- func (idx *Index) FrozenAboutUsages(name string) ([]*Symbol, bool)
- func (idx *Index) GetFQN(sym *Symbol) string
- func (idx *Index) HasLibrary() bool
- func (idx *Index) HiddenFrom(fqn, fromFQN string) bool
- func (idx *Index) InstallLibraryFacts(name string, facts map[string]*LibraryFacts)
- func (idx *Index) IsLibraryDocument(name string) bool
- func (idx *Index) Library(sym *Symbol) bool
- func (idx *Index) LibraryDocumentByDigest(digest string) (string, LibraryDocument, bool)
- func (idx *Index) LibraryDocumentOf(name string) LibraryDocument
- func (idx *Index) LibraryIdentity() (string, bool)
- func (idx *Index) LibraryTier(sym *Symbol) LibraryTier
- func (idx *Index) LookupDirectChildren(prefix string) []*Symbol
- func (idx *Index) LookupDirectChildrenFrom(prefix, fromFQN string) []*Symbol
- func (idx *Index) LookupDirectChildrenNamed(prefix, name string) []*Symbol
- func (idx *Index) LookupDirectChildrenNamedFrom(prefix, fromFQN, name string) []*Symbol
- func (idx *Index) LookupQualified(fqn string) []*Symbol
- func (idx *Index) LookupQualifiedFrom(fqn, fromFQN string) []*Symbol
- func (idx *Index) MarkLibrary(name string)
- func (idx *Index) MarkLibraryDocument(name string, doc LibraryDocument)
- func (idx *Index) MarkLibraryTier(name string, tier LibraryTier)
- func (idx *Index) NamespaceFiltersOf(fqn string) []ElementFilter
- func (idx *Index) ReexportGates(doc, fqn string, sym *Symbol, from string) [][]ElementFilter
- func (idx *Index) ReexportVisible(doc, fqn string, sym *Symbol) bool
- func (idx *Index) Registered(fn func(fqn string, syms []*Symbol))
- func (idx *Index) RemoveDocument(name string)
- func (idx *Index) SetNamespaceFilters(fqn, doc string, filters []ElementFilter)
- func (idx *Index) TopLevelBindings(doc string) []RootBinding
- func (idx *Index) WildcardImportsOf(fqn string) []WildcardImport
- func (idx *Index) WorkspaceDocuments() []string
- func (idx *Index) WriteSnapshot(w *pack.Writer) error
- type LibraryDocument
- type LibraryFacts
- type LibraryTier
- type MetadataBodyResolver
- type Naming
- type QuantityValue
- type RootBinding
- type Scope
- func (s *Scope) AddChild(c *Scope)
- func (s *Scope) AllMembers() []*Symbol
- func (s *Scope) AnonymousMembers() []*Symbol
- func (s *Scope) BodyLocal() bool
- func (s *Scope) ChildFor(node ast.Node) *Scope
- func (s *Scope) Children() []*Scope
- func (s *Scope) DeclaredAt(span source.Span) *Symbol
- func (s *Scope) DeclaredFrom(offset int) *Symbol
- func (s *Scope) Define(name string, sym *Symbol)
- func (s *Scope) DefineAnonymous(sym *Symbol)
- func (s *Scope) DocName() string
- func (s *Scope) ForEachAnonymousMember(yield func(*Symbol) bool)
- func (s *Scope) ForEachMember(yield func(*Symbol) bool)
- func (s *Scope) HasAnonymousMembers() bool
- func (s *Scope) LookupLocal(name string) (*Symbol, bool)
- func (s *Scope) LookupLocalAll(name string) []*Symbol
- func (s *Scope) MemberDeclaring(decl ast.Node) *Symbol
- func (s *Scope) MemberNames() []string
- func (s *Scope) Members() []*Symbol
- func (s *Scope) Node() ast.Node
- func (s *Scope) Owner() *Symbol
- func (s *Scope) Parent() *Scope
- func (s *Scope) SetOwner(sym *Symbol)
- type Symbol
- type SymbolKind
- type UnitFactorFacts
- type UnitFacts
- type WildcardImport
Constants ¶
This section is empty.
Variables ¶
var ErrNotSnapshottable = errors.New("symbols: only a frozen index with no base can be written as a snapshot")
ErrNotSnapshottable reports an index WriteSnapshot cannot serialise: one still writable, built over another, or with an expansion pending.
Functions ¶
func DeclIdent ¶ added in v0.5.0
func DeclIdent(decl ast.Node) (ast.Identification, bool)
DeclIdent returns the identification a declaration node carries: the long and short names it states, each with the span it was written at.
func DocNameOf ¶
DocNameOf is the document a scope belongs to, read from the name SetDocName stamped on the scope and its symbols. It identifies a scope tree the index does not hold — a document builds its own for the editor — by name rather than by identity, a document declaring nothing but an import included.
func FQNOf ¶
FQNOf returns a symbol's fully-qualified name from its owner scope chain, so a caller holding a symbol but no index can still name it. An unnamed owner contributes no segment: a part nested in an anonymous part of Mid is Mid::inner.
func FirstNamesSource ¶ added in v0.8.0
func FirstNamesSource(n *ast.InitialNode) bool
FirstNamesSource reports whether the name after `first` in n refers to the source of a succession (`first a then b;`, parsed as an InitialNode only in an action body) rather than declaring a start marker (`first a;`).
func HasFQN ¶ added in v0.3.1
HasFQN reports whether sym's fully-qualified name is fqn, without building that name: the segments are compared against the owner chain from the end, skipping unnamed owners as FQNOf does.
func InStateMachine ¶ added in v0.8.0
InStateMachine reports whether an edge written in scope belongs to a state machine, the body a vertex lookup applies to; an action body (a transition's included) or anything else is not one.
func IsAbstract ¶ added in v0.2.0
IsAbstract reports whether sym is declared abstract, reading the installed fact when one memoizes it and the declaration otherwise.
func NameChain ¶ added in v0.8.0
NameChain is the names FQNOf joins, outermost first: a symbol's own name after those of its named owners. Kept apart, they tell `'x::y'` from `x::y`.
func SameElement ¶
SameElement reports whether a and b denote one element, whichever scope tree each was reached through. A nil symbol denotes no element, itself included.
func SetDocName ¶
SetDocName stamps name onto every symbol in the scope tree (members and all descendant scopes), recording which document declares each symbol. Recursion follows the child links, so scopes no symbol owns — loop bodies and body-expression parameters — are stamped too.
func TextDigest ¶ added in v0.5.0
TextDigest is the digest of a library document's text that LibraryDocument carries.
func UsageAnnotatesOthers ¶ added in v0.4.3
UsageAnnotatesOthers reports whether a metadata usage states what it annotates (`metadata m about p;`), rather than annotating its owner.
func VisibleAs ¶ added in v0.2.0
func VisibleAs(v ast.Visibility, inside, inheriting bool) bool
VisibleAs reports whether a membership of the given visibility is visible to a reference made inside its namespace (inside) or from one that specializes it (inheriting), per KerML 8.2.3.5: private only inside, protected also through specialization, public everywhere.
func VisibleOutside ¶ added in v0.2.0
func VisibleOutside(v ast.Visibility) bool
VisibleOutside reports whether a membership may be named through its namespace, which only a public membership may.
Types ¶
type AnnotationFacts ¶
type AnnotationFacts struct {
TypeFQN string
Values []AnnotationValueFacts
}
AnnotationFacts is one metadata annotation reduced to names and constants: the fully-qualified name of the metadata type annotating it, and the values the annotation body binds its features to, as written.
type AnnotationValueFacts ¶
type AnnotationValueFacts struct {
Feature string
Value FilterValue
}
AnnotationValueFacts is one feature binding inside an annotation body (`@Safety{isMandatory = true;}`), holding the value already evaluated, so that a filter condition reading it decides the same way where the declaration it came from is gone.
type DimensionFactorFacts ¶
DimensionFactorFacts is one base quantity of a dimension, named by its qualified name, and its exponent.
type DimensionFacts ¶
type DimensionFacts struct {
Factors []DimensionFactorFacts
}
DimensionFacts is a quantity dimension in the form a library index cache carries: the base quantities it is a product of powers of, each named by its qualified name. No factors is the dimension of a count or of a like ratio.
type ElementFilter ¶
ElementFilter is one element-filter condition, as it applies to the elements an enumeration would surface: the condition of a `filter <expr>;` member of a namespace (KerML 8.2.4 ElementFilterMembership) or of an import's `[...]` clause (`import P::*[@Safety]`, SysML v2 7.4.4).
A condition is a predicate over one candidate element, not a value expression, and evaluating it needs the metadata annotating the candidate — knowledge the symbol layer does not have. So it is carried as parsed: the expression, together with the Scope its names resolve against, which the evaluator in semantics compiles to a predicate over resolved elements.
func ImportFiltersIn ¶
func ImportFiltersIn(scope *Scope) []ElementFilter
ImportFiltersIn returns the filter clauses of the imports the namespace owning scope declares (`import P::*[@Safety]`), in declaration order. It is what a validation pass reads: the conditions an import states are checked where they are written, whichever lookup later applies them.
func NamespaceFiltersIn ¶
func NamespaceFiltersIn(scope *Scope) []ElementFilter
NamespaceFiltersIn returns the filter conditions the namespace owning scope declares. It is what a lookup through an import consults: the namespace's `filter` members restrict its imported memberships, whichever route reaches them (KerML 8.2.4).
Unlike NamespaceFiltersOf, which answers for a namespace registered in the index, this reads the declaration a scope was built from, so it also answers for a `filter` member of a definition or usage body — where the training corpus puts one, in a view definition restricting what its views expose.
func (ElementFilter) IsZero ¶
func (f ElementFilter) IsZero() bool
IsZero reports whether there is no condition to apply.
func (ElementFilter) Same ¶
func (f ElementFilter) Same(g ElementFilter) bool
Same reports whether two filters are the same condition, so that two routes to one re-exported name can be compared. A condition is identified by the declaration it was written in: the expression node and the scope its names resolve against.
func (ElementFilter) String ¶
func (f ElementFilter) String() string
String describes a filter for a snapshot of the index, rendering only whether a condition applies: which elements it selects is asserted over resolution rather than over this text.
type ElementKey ¶
type ElementKey struct {
// contains filtered or unexported fields
}
ElementKey identifies the declaration a symbol was built from, since a document and the global index build their own symbol for one declaration. A symbol with no declaring document — restored from cache — is identified by pointer instead.
type ExprWalker ¶ added in v0.5.1
type ExprWalker struct {
// Body returns the scope a body expression's members and result resolve in.
Body func(parent *Scope, body *ast.BodyExpr) *Scope
// Members is called for each member list reached, with its scope.
Members func(scope *Scope, members []ast.Node)
// Applied, when set, is called for each body expression written as the argument
// of an operation (`xs.{…}`, `xs.?{…}`, `xs->f {…}`), with the operation's scope.
Applied func(scope *Scope, op ast.Node, body *ast.BodyExpr)
}
ExprWalker walks declarations and their expressions down to every member list they own (a declaration's body, a `{ … }` value's members), each with its scope.
func (ExprWalker) Decl ¶ added in v0.5.1
func (w ExprWalker) Decl(scope *Scope, decl ast.Node)
Decl walks the expressions a declaration carries and the member lists it owns, each in the child scope it resolves against.
func (ExprWalker) Expr ¶ added in v0.5.1
func (w ExprWalker) Expr(scope *Scope, e ast.Node)
Expr walks an expression subtree, entering every body expression it holds: the body's members through Members, its result in the scope Body returns.
func (ExprWalker) Trigger ¶ added in v0.5.1
func (w ExprWalker) Trigger(scope *Scope, trigger ast.Node)
Trigger walks the expression a trigger carries: only the payload expressions of time and change events can hold a body expression.
func (ExprWalker) WalkMembers ¶ added in v0.8.0
func (w ExprWalker) WalkMembers(scope *Scope, members []ast.Node)
WalkMembers walks the declaration each member wraps, in scope.
type FilterOp ¶
type FilterOp uint8
FilterOp is the operation a compiled filter predicate node performs.
const ( // FilterUnsupported is a condition, or part of one, outside the subset the // filter evaluator implements. It has no truth value: it is reported, and // never silently taken to be true or false. FilterUnsupported FilterOp = iota FilterAnd FilterOr FilterXor FilterImplies FilterNot // FilterClassify is `@T`: the candidate is annotated by metadata // conforming to TypeFQN. FilterClassify // FilterMetaClassify is `@@T`: the candidate's own metaclass conforms to // TypeFQN. FilterMetaClassify FilterEq FilterNeq FilterLt FilterLe FilterGt FilterGe // FilterConst is a literal, or an element reference used as one (an // enumeration literal), held in Value. FilterConst // FilterFeature is the value the candidate's annotation of TypeFQN binds // Feature to. FilterFeature )
type FilterPredicate ¶
type FilterPredicate struct {
Op FilterOp
Operands []*FilterPredicate
// TypeFQN is the metadata type a classification tests against, or whose
// annotation a feature is read from.
TypeFQN string
// Feature is the annotation feature FilterFeature reads.
Feature string
// Value is the constant FilterConst yields.
Value FilterValue
// Reason says why a FilterUnsupported node cannot be evaluated, phrased for
// a diagnostic message.
Reason string
// UnsupportedKind says whether Reason is a model-level evaluability fault
// or a limitation of the OpenSysML evaluator.
UnsupportedKind FilterUnsupportedKind
// ResultType is the resolved terminal feature for a reference or chain. It
// lets semantic validation determine Boolean-ness without evaluating it.
ResultType *Symbol
// Span locates the part of the condition this node came from.
Span source.Span
}
FilterPredicate is an element-filter condition compiled to the form the evaluator runs: a tree over the candidate element, with every element the condition names resolved to its fully-qualified name. Compiling before evaluating is what lets one condition be evaluated against many candidates, and lets a condition outlive the declaration it was written in.
type FilterUnsupportedKind ¶ added in v0.2.1
type FilterUnsupportedKind uint8
FilterUnsupportedKind distinguishes a specification fault from a limitation of the evaluator for a FilterUnsupported predicate.
const ( // FilterUnsupportedNotEvaluable is a model-level evaluability fault. FilterUnsupportedNotEvaluable FilterUnsupportedKind = iota // FilterUnsupportedEvaluator is a specification-clean evaluator limitation. FilterUnsupportedEvaluator // FilterUnsupportedNotBoolean is an unresolved value whose result cannot be // shown to be Boolean. FilterUnsupportedNotBoolean )
type FilterValue ¶
type FilterValue struct {
Kind FilterValueKind
Bool bool
Int int64
Real float64
Str string
RefFQN string
Quantity QuantityValue
}
FilterValue is a constant a filter predicate yields or compares: a literal, or the element an enumeration-literal reference names.
type FilterValueKind ¶
type FilterValueKind uint8
FilterValueKind discriminates a constant a filter predicate compares.
const ( FilterValueUnknown FilterValueKind = iota FilterValueBool FilterValueInt FilterValueReal FilterValueString // FilterValueRef is a reference to an element used as a value, such as an // enumeration literal, compared by identity of the element it names. FilterValueRef // FilterValueEmpty is the absence of a value — the empty sequence a feature // bound to nothing has. It is a result, unlike FilterValueUnknown, which // says a value could not be determined. FilterValueEmpty // FilterValueInstance is an instance a condition constructs (`new A(…)`). // It is a value, and never a truth value. FilterValueInstance // FilterValueQuantity is a magnitude in a measurement unit (`5 [kg]`), // carried in Quantity. FilterValueQuantity )
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index aggregates symbol information across all documents in a workspace. It owns each document's root scope and a global map from fully-qualified name to the symbol(s) declared under it. Per-document contributions are tracked so a document can be removed or re-added without leaving stale entries — the names it declared and the ones its wildcard imports surfaced alike.
Each table is a layer (see layer.go): an index built with NewOverlay reads through to a frozen index's tables and writes only its own entries, so the standard library is indexed once and shared by every model rather than re-indexed per model.
func NewIndexFromDoc ¶
func NewIndexFromDoc(name string, root *ast.RootNamespace) *Index
NewIndexFromDoc builds an Index containing a single document.
func NewOverlay ¶ added in v0.2.0
NewOverlay returns an index holding everything base holds, whose own writes are its own: documents it adds, the re-exports their imports surface and the ones they invalidate are visible in it alone, and base is left untouched. It panics if base is not frozen, since an index cannot read through to a table still being written.
func ReadSnapshot ¶ added in v0.4.3
ReadSnapshot rebuilds the frozen index WriteSnapshot wrote to r. Nodes, scopes and symbols are allocated up front, then the sections fill them concurrently.
func (*Index) AddDocument ¶
func (idx *Index) AddDocument(name string, root *ast.RootNamespace)
AddDocument builds the scope tree for root and records its symbols under their fully-qualified names. Re-adding the same document name first removes the document's previous contributions, so the index stays exact.
The names the document's wildcard imports surface are added by ExpandWildcardImports, which the caller runs once the documents it wants indexed are in: adding a document cannot know whether the target of an import it states is still to come.
func (*Index) AddDocumentWithKind ¶ added in v0.2.0
AddDocumentWithKind builds the scope tree for root and records its explicit language, which is needed when the document name does not carry an extension.
func (*Index) Base ¶ added in v0.8.0
Base is the frozen index an overlay reads through to, nil for an index that stands alone. Two overlays over one base share its documents and symbols.
func (*Index) Declaring ¶
Declaring returns the symbol fqn declares, and nil when fqn only re-exports a declaration made elsewhere. The lookup is made from fqn itself, so a private member is visible where it is declared.
func (*Index) DocumentKind ¶ added in v0.2.0
DocumentKind returns a document's recorded language, or infers it from its name when the document was added without an explicit language.
func (*Index) DocumentLibraryTier ¶ added in v0.5.0
func (idx *Index) DocumentLibraryTier(name string) LibraryTier
DocumentLibraryTier reports the tier the named document was marked with, TierNone for a workspace document.
func (*Index) DocumentOfRoot ¶
DocumentOfRoot returns the name of the document whose root scope this is, or "" for any other scope.
func (*Index) DocumentRoot ¶
DocumentRoot returns the root scope for the named document, or nil.
func (*Index) Documents ¶ added in v0.4.3
Documents returns the names of every document with a root scope, bundled library content included, sorted for deterministic iteration.
func (*Index) ExpandWildcardImports ¶
func (idx *Index) ExpandWildcardImports()
ExpandWildcardImports adds re-exported symbols for every package with a wildcard import like `import ISQMechanics::*`, making the target's members visible through the importing package's FQN. Call it after the documents to index are in; AddDocument and AddRecords do not expand on their own, while RemoveDocument does, so the index a removal leaves is the one a fresh build over the remaining documents would produce.
Imports chain — KerML imports Kernel::*, which imports Core::*, which imports Root::* — so a single pass would only propagate one level and its result would depend on the order the importing packages happened to be visited in. Passes therefore repeat until nothing new is re-exported, over the importers in name order, which makes the outcome independent of both map iteration order and of whether a document was parsed or restored from cache.
A pass touches only the importers a change since the last expansion can reach: one whose imports changed, one whose import now resolves to a different namespace, and one importing a namespace whose members changed. Calling it when nothing changed costs one resolution of each import and registers nothing, so a caller that expands after every edit pays for the edit rather than for the workspace.
An importer whose imports no longer support what it re-exported has those re-exports dropped before the pass derives again, since a re-export can be reached by more than one route and a cycle of imports would otherwise let one support itself. Dropping propagates: it takes members from a namespace, which is a change the importers of *that* namespace see on the next pass.
func (*Index) FQNsEndingIn ¶
FQNsEndingIn returns up to limit registered fully-qualified names whose last segment is name, in name order. Used to suggest a candidate for a reference whose qualifying namespace is not loaded.
func (*Index) Freeze ¶ added in v0.2.0
func (idx *Index) Freeze()
Freeze settles the index's wildcard imports and bars it from further writes, after which NewOverlay may build indexes over it. Freezing what holds the standard library is what lets every model share one copy of it.
func (*Index) FrozenAboutUsages ¶ added in v0.4.3
FrozenAboutUsages returns the `about` metadata usages the named document declares, read from the cache its frozen index built, and whether the cache covers the document: false for one still writable, whose tree the caller must walk instead.
func (*Index) GetFQN ¶
GetFQN returns the fully-qualified name for a symbol by walking its owner scope chain. Returns the local name if the symbol has no owner scope (root-level symbol).
func (*Index) HasLibrary ¶ added in v0.8.0
HasLibrary reports whether the index holds any bundled library document.
func (*Index) HiddenFrom ¶
HiddenFrom reports whether every symbol registered under fqn is one only a private import surfaced there, seen from the namespace fromFQN. It is the reason LookupQualifiedFrom found nothing, so a caller that falls back to another lookup route — the qualified walk's inheritance-aware member search, which reaches cached symbols through LookupDirectChildren — asks here first and stops, rather than resurfacing a name KerML 8.2.3.3 hides.
func (*Index) InstallLibraryFacts ¶ added in v0.2.0
func (idx *Index) InstallLibraryFacts(name string, facts map[string]*LibraryFacts)
InstallLibraryFacts installs derived facts on the symbols the named document declares, keyed by the fully-qualified name they are declared under. A name the document does not declare is ignored: facts are a memo of that document's own declarations.
func (*Index) IsLibraryDocument ¶ added in v0.5.0
IsLibraryDocument reports whether the named document holds bundled library content (see MarkLibrary).
func (*Index) LibraryDocumentByDigest ¶ added in v0.8.0
func (idx *Index) LibraryDocumentByDigest(digest string) (string, LibraryDocument, bool)
LibraryDocumentByDigest finds the bundled library document whose text has the given digest (see TextDigest): the document a byte-identical text is.
func (*Index) LibraryDocumentOf ¶ added in v0.5.0
func (idx *Index) LibraryDocumentOf(name string) LibraryDocument
LibraryDocumentOf reports what the named document was marked as holding, a LibraryDocument of TierNone for a workspace document.
func (*Index) LibraryIdentity ¶ added in v0.5.0
LibraryIdentity digests the library content the index holds — every library document's name, tier and text — so two indexes that agree on it declare the same library. It is unknown while a library document states no text digest.
func (*Index) LibraryTier ¶ added in v0.5.0
func (idx *Index) LibraryTier(sym *Symbol) LibraryTier
LibraryTier reports the tier of the bundled library content that declares sym, TierNone for a symbol the workspace declares.
func (*Index) LookupDirectChildren ¶
LookupDirectChildren returns all symbols whose FQN is exactly prefix::name (direct children of the given prefix). This supports wildcard imports from packages that don't have populated Scopes.
func (*Index) LookupDirectChildrenFrom ¶
LookupDirectChildrenFrom is LookupDirectChildren as seen from the namespace named by fromFQN ("" meaning from outside): children that only prefix's own private imports brought in are dropped (KerML 8.2.3.3).
func (*Index) LookupDirectChildrenNamed ¶ added in v0.5.1
LookupDirectChildrenNamed returns the direct children of prefix whose leaf name or short name is name, in LookupDirectChildren order, without a scan.
func (*Index) LookupDirectChildrenNamedFrom ¶ added in v0.5.1
LookupDirectChildrenNamedFrom is LookupDirectChildrenNamed with the visibility of LookupDirectChildrenFrom, as seen from fromFQN ("" meaning from outside).
func (*Index) LookupQualified ¶
LookupQualified returns the symbols a qualified reference from outside the naming namespace reaches under the exact fully-qualified name. A namespace's own member shadows one of the same name that a wildcard import re-exported through it, as in SI::min, which is SI's minute and not the imported min function, and a name only a *private* import surfaced is not reachable at all: it is a member of the namespace, but not a visible one (KerML 8.2.3.3).
func (*Index) LookupQualifiedFrom ¶
LookupQualifiedFrom is LookupQualified as seen from the namespace named by fromFQN. A private import is visible inside the namespace that declares it and inside everything nested in it, so a reference made from there — including the target of an alias the namespace declares — still reaches a privately imported name that the same lookup from anywhere else does not (KerML 8.2.3.3).
fromFQN is the FQN of the referring namespace; "" means "from outside", which is what an ordinary qualified reference elsewhere in the workspace gets.
func (*Index) MarkLibrary ¶
MarkLibrary records that the named document holds bundled library content, not the workspace's own, of no stated tier. Call it after the document is added: adding a document removes its previous contributions, and the mark with them. Only what the document declares is marked, not the names it re-exports.
func (*Index) MarkLibraryDocument ¶ added in v0.5.0
func (idx *Index) MarkLibraryDocument(name string, doc LibraryDocument)
MarkLibraryDocument records that the named document holds the described bundled library content; a document of TierNone is unmarked. See MarkLibrary for when to call it.
func (*Index) MarkLibraryTier ¶ added in v0.5.0
func (idx *Index) MarkLibraryTier(name string, tier LibraryTier)
MarkLibraryTier records that the named document holds bundled library content of the given tier and unstated text; TierNone unmarks it. See MarkLibrary for when to call it.
func (*Index) NamespaceFiltersOf ¶
func (idx *Index) NamespaceFiltersOf(fqn string) []ElementFilter
NamespaceFiltersOf returns the filter conditions declared by the namespace registered under fqn, over the documents declaring it in name order.
func (*Index) ReexportGates ¶
func (idx *Index) ReexportGates(doc, fqn string, sym *Symbol, from string) [][]ElementFilter
ReexportGates returns the element-filter conditions the name fqn is subject to when it reaches a lookup as sym, one entry per route that surfaced it: the conditions of the import that surfaced it along that route plus the importing namespace's own `filter` members. A name a namespace declares itself has no route and so no conditions.
The resolver reads them and evaluates them against its semantic model, and admits the element when any route's conditions all hold: a candidate every route rejects is not a member of the namespace it appears under, so no route to it resolves (KerML 8.2.4). A private import's route only answers a lookup made from within the importing namespace, which from names ("" for one made from anywhere else).
func (*Index) ReexportVisible ¶
ReexportVisible reports whether a lookup made in doc reaches sym under the name fqn. A root-level name a wildcard import surfaced is a member of the importing document's own root namespace, so it is not visible in another document (KerML 8.2.3.3); a name under a namespace is visible wherever that namespace is.
func (*Index) Registered ¶ added in v0.8.0
Registered calls fn with every registered fully-qualified name and the symbols under it, in name order.
func (*Index) RemoveDocument ¶
RemoveDocument drops all of the named document's contributions from the global index and forgets its root scope: the names it declared, the wildcard imports it stated, and the re-exports those imports surfaced. A re-export a surviving document also surfaces stays, as does the declaredAt entry a surviving declaration owns.
Removal re-expands what it invalidated before returning, so the index it leaves is the one a fresh build over the remaining documents produces — a caller does not have to know that removing a document can break a chain of imports (A imports B imports C) or make an ambiguous import target resolvable. Unknown names are a no-op.
An index built over a frozen base may remove one of the base's documents too: the removal is recorded in the overlay, which stops answering for what the document contributed while the base keeps it for every other index over it.
func (*Index) SetNamespaceFilters ¶
func (idx *Index) SetNamespaceFilters(fqn, doc string, filters []ElementFilter)
SetNamespaceFilters records the filter conditions doc declares for the namespace registered under fqn. A library restored from an index cache states them this way, having no declaration left to read them from.
func (*Index) TopLevelBindings ¶
func (idx *Index) TopLevelBindings(doc string) []RootBinding
TopLevelBindings returns the names registered at the root of the index as seen from doc ("" meaning from outside every document) and the symbol each names: the library's top-level packages and every document's top-level declarations, less the names only another document's private import surfaced (KerML 8.2.3.3). A caller gating those names by their element filters needs the name, since a borrowed symbol's own name is not the root name it appears under.
func (*Index) WildcardImportsOf ¶
func (idx *Index) WildcardImportsOf(fqn string) []WildcardImport
WildcardImportsOf returns the wildcard-import targets recorded for the namespace registered under fqn ("" for a document root), over the documents declaring it in name order.
func (*Index) WorkspaceDocuments ¶ added in v0.4.2
WorkspaceDocuments returns the names of the documents holding workspace content — every document with a root scope that is not marked as bundled library content — sorted for deterministic iteration.
type LibraryDocument ¶ added in v0.5.0
type LibraryDocument struct {
Tier LibraryTier
Digest string
}
LibraryDocument describes the bundled library content a document holds: the tier of its bundle and a digest of its text, empty when the loader stated none.
type LibraryFacts ¶ added in v0.2.0
type LibraryFacts struct {
// Supers are the fully-qualified names of the semantic direct supertypes,
// in derivation order. Nil when an edge has no qualified name to restore it
// by, which leaves the whole set to be derived from the declaration.
Supers []string
// Unit is the reduction of a measurement unit to base units. Nil for a
// symbol that is not a measurement unit.
Unit *UnitFacts
// Dimension is the quantity dimension a measurement unit measures in. Nil
// when the symbol is not a unit or its dimension is undetermined.
Dimension *DimensionFacts
// Abstract records that the declaration is abstract. False means concrete or
// not recorded, which leaves the declaration to say.
Abstract bool
}
LibraryFacts is the derived analysis of one library symbol: the semantic work whose derivation dominates a cold library load, held so that a later load can install it instead of repeating it.
Every field is a memo of what the symbol's declaration yields, never a replacement for it — a library document is parsed and indexed on every load path, so a field left unset simply means "derive it from the declaration".
type LibraryTier ¶ added in v0.5.0
type LibraryTier uint8
LibraryTier is the part of the bundled library a document belongs to. The Kernel tiers are the metamodel frame every element specializes; the Systems, Domain and OpenSysML tiers declare features with semantics of their own.
const ( // TierNone is the workspace's own content. TierNone LibraryTier = iota // TierLibrary is library content whose place in the bundle is not stated. TierLibrary // TierKernelSemantic is the Kernel Semantic Library (Base, Occurrences, Objects, …). TierKernelSemantic // TierKernelDataType is the Kernel Data Type Library (ScalarValues, Collections, …). TierKernelDataType // TierKernelFunction is the Kernel Function Library. TierKernelFunction // TierSystems is the Systems Library (Items, Parts, Requirements, …). TierSystems // TierDomain is the Domain Libraries (Geometry, Quantities and Units, Metadata, …). TierDomain // TierOpenSysML is this implementation's own library packages. TierOpenSysML )
func (LibraryTier) Frame ¶ added in v0.5.0
func (t LibraryTier) Frame() bool
Frame reports whether the tier frames every element rather than describing the objects a model asks for: the Kernel libraries, and library content of no stated tier, which is held to the same standard.
func (LibraryTier) Library ¶ added in v0.5.0
func (t LibraryTier) Library() bool
Library reports whether the tier is bundled library content of any kind.
func (LibraryTier) Semantic ¶ added in v0.7.0
func (t LibraryTier) Semantic() bool
Semantic reports a tier realized rather than executed as written: the Kernel and Systems libraries, or library content of no stated tier.
func (LibraryTier) String ¶ added in v0.5.0
func (t LibraryTier) String() string
type MetadataBodyResolver ¶ added in v0.4.1
MetadataBodyResolver is the inheritance-aware lookup needed by metadata bodies.
type Naming ¶ added in v0.6.0
type Naming uint8
Naming tells where a symbol's Name comes from.
const ( // NamedByDeclaration: Name is the declared name, or empty. NamedByDeclaration Naming = iota // NamedByReference: Name is the name of the feature the declaration // references (`perform a;`), an ordinary member name that hides nothing. NamedByReference // NamedByRedefinition: Name is the name of the feature the declaration // redefines (`part :>> p;`), which it replaces in its owner. NamedByRedefinition )
type QuantityValue ¶ added in v0.6.0
QuantityValue is a constant quantity as the semantic layer represents it; units are resolved there, so the symbol layer carries the value opaquely.
type RootBinding ¶
RootBinding is a name registered at the index root and the symbol it names.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is a node in the immutable per-document scope tree. It owns the symbols declared directly within a namespace-like construct and links to its parent and child scopes.
func BodyExprScope ¶
BodyExprScope returns the scope holding body's parameters. A body without parameters declares nothing, so its result resolves in parent.
func Build ¶
func Build(root *ast.RootNamespace) *Scope
Build constructs the immutable scope tree for a parsed document.
func ConstraintBodyScope ¶
ConstraintBodyScope returns the scope a nested constraint body resolves against: the one its declarations were built into, or parent for a body declaring none.
func TriggerScope ¶
func TriggerScope(parent *Scope, trans *ast.TransitionMember) *Scope
TriggerScope returns the innermost scope trans's guard and effect resolve against: the one holding the parameters its trigger declares when it declares any, the transition's own scope when it has one, and parent otherwise (builder.buildDecl builds both, with the effect in the innermost).
func (*Scope) AllMembers ¶
AllMembers returns named and anonymous symbol registrations in declaration order.
func (*Scope) AnonymousMembers ¶
AnonymousMembers returns the members declared without a name, in declaration order. One may still have an effective name, taken from a feature it implicitly redefines, which only the semantic model knows (KerML 7.3.4.5).
func (*Scope) BodyLocal ¶
BodyLocal reports whether this scope's names exist only inside the body that declares them, so a subtree search such as a recursive import must skip it.
func (*Scope) ChildFor ¶
ChildFor returns the child scope the given declaration owns, or nil. It is the first such child, as two children of one node are one body scoped twice.
func (*Scope) DeclaredAt ¶ added in v0.8.0
DeclaredAt returns the symbol whose declaration was parsed from exactly span, in this scope or one nested in it, or nil. An anonymous declaration is found as a named one is, so an edit can reach an element no qualified name does.
func (*Scope) DeclaredFrom ¶ added in v0.8.0
DeclaredFrom returns the symbol whose declaration was parsed starting at offset, in this scope or one nested in it, or nil. It relocates a declaration whose extent an edit changed but whose start it left in place.
func (*Scope) Define ¶
Define registers sym under the given name key. Multiple symbols may share a key (duplicate declarations); all are retained in definition order.
func (*Scope) DefineAnonymous ¶
DefineAnonymous adds an anonymous symbol (without name) to this scope.
func (*Scope) ForEachAnonymousMember ¶ added in v0.8.0
ForEachAnonymousMember visits the members declared without a name in declaration order, without copying them.
func (*Scope) ForEachMember ¶ added in v0.2.1
ForEachMember visits named and anonymous symbol registrations in declaration order.
func (*Scope) HasAnonymousMembers ¶
HasAnonymousMembers reports whether any member is declared without a name.
func (*Scope) LookupLocal ¶
LookupLocal returns the first symbol defined under name in this scope only. A declared name wins over an effective one taken from a referenced feature.
func (*Scope) LookupLocalAll ¶
LookupLocalAll returns every symbol defined under name in this scope only.
func (*Scope) MemberDeclaring ¶ added in v0.8.0
MemberDeclaring returns the member of s that decl declared, or nil.
func (*Scope) MemberNames ¶
MemberNames returns the distinct member keys of this scope in declaration order.
func (*Scope) Members ¶
Members returns distinct symbols declared directly in this scope in declaration order, with duplicate keys interleaved as declared. A symbol registered under both its short and primary name appears once.
type Symbol ¶
type Symbol struct {
Name string // the key this Symbol was primarily created for
Kind SymbolKind // classification
Decl ast.Node // the declaring AST node
Visibility ast.Visibility // declared visibility
DeclSpan source.Span // span of the declaration (for diagnostics)
NameSpan source.Span // span of the declared identifier alone (for rename); zero when unknown
Scope *Scope // the child scope this declaration owns, or nil for leaves
OwnerScope *Scope // the enclosing scope this declaration was declared in
// LeadingTrivia is the comment/note trivia attached to the member wrapper
// preceding this declaration (captured before unwrap, since wrappers carry
// the trivia while the unwrapped inner Decl does not). Used for doc hover.
LeadingTrivia []ast.Trivia
DocName string // name of the document that declares this symbol (stamped after Build)
// Facts is the derived analysis installed for a library symbol, a memo of
// work its declaration would otherwise repeat. Nil for everything else.
Facts *LibraryFacts
// ShortName is the short name from Identification (e.g., "kg" for "kilogram").
// Empty if the declaration states none.
ShortName string
// Naming records how the symbol came by its Name: declared, or derived
// from its naming feature (KerML 7.3.4.5 Feature::effectiveName).
Naming Naming
// NamingTarget is the reference that named this symbol when Naming is
// derived: the target of its reference subsetting or redefinition. Resolving
// that reference must not see the name it gave away, or it would resolve to
// the feature that borrowed it (KerML 7.3.4.5).
NamingTarget ast.Node
}
Symbol describes one declared name. The same declaration may be reachable through more than one Symbol only when it declares both a short and a primary name; in that case a single Symbol is registered under both keys.
func LookupBodyLocal ¶ added in v0.2.0
LookupBodyLocal finds the first declaration named name in the supplied body scope or one of its enclosing body-local scopes. It stops at the first non-body-local scope so declarations do not escape their expression body.
func MetadataBodyTarget ¶ added in v0.2.0
func MetadataBodyTarget(lookup MetadataBodyResolver, owner *Symbol, ident ast.Identification) *Symbol
MetadataBodyTarget returns the feature a metadata body declaration implicitly redefines, accepting either its primary or short name.
func PreferDeclared ¶
PreferDeclared drops symbols whose name was borrowed from a referenced feature when the key also has a declared one, which is how a `perform p;` shorthand and a declaration named p coexist in one scope. A `first x` label borrows its name the same way, from the member it starts at.
func (*Symbol) EffectiveName ¶
EffectiveName reports whether Name was derived from a naming feature rather than declared.
type SymbolKind ¶
type SymbolKind int
SymbolKind classifies a declared name.
const ( SymbolUnknown SymbolKind = iota SymbolPackage SymbolNamespace SymbolAlias SymbolDependency SymbolComment SymbolDocumentation SymbolTextualRepresentation SymbolPartDef SymbolAttributeDef SymbolPartUsage SymbolAttributeUsage // Tier A definitions. SymbolItemDef SymbolOccurrenceDef SymbolIndividualDef SymbolMetadataDef SymbolMetaclass // KerML metaclass (similar to metadata def) SymbolEnumerationDef SymbolViewDef SymbolViewpointDef SymbolRenderingDef SymbolConcernDef // Tier B definitions. SymbolConnectionDef SymbolFlowDef SymbolPortDef SymbolInterfaceDef SymbolAllocationDef // Tier C definitions. SymbolActionDef SymbolStateDef SymbolCalcDef SymbolConstraintDef SymbolRequirementDef SymbolCaseDef SymbolAnalysisCaseDef SymbolVerificationCaseDef SymbolUseCaseDef // Tier A usages. SymbolItemUsage SymbolOccurrenceUsage SymbolIndividualUsage SymbolMetadataUsage SymbolEnumerationUsage SymbolViewUsage SymbolViewpointUsage SymbolRenderingUsage SymbolConcernUsage // Tier B usages. SymbolConnectionUsage // SymbolSuccessionUsage classifies a succession usage: a SuccessionAsUsage // (SysML v2 §8.3.13.7), a ConnectorAsUsage that is not a ConnectionUsage. SymbolSuccessionUsage SymbolFlowUsage SymbolPortUsage SymbolInterfaceUsage SymbolAllocationUsage // Tier C usages. SymbolActionUsage SymbolStateUsage SymbolCalcUsage SymbolConstraintUsage SymbolRequirementUsage SymbolCaseUsage SymbolAnalysisCaseUsage SymbolVerificationCaseUsage SymbolUseCaseUsage // SymbolConnectorEnd is an end feature a connector usage declares in its // connect clause (`connect bead references t.bead`). SymbolConnectorEnd // SymbolCrossFeature is the cross feature an end feature declares inline // ahead of its own declaration (`end x1 [0..1] feature x : C1`). SymbolCrossFeature // SymbolKerMLType classifies a KerML type declaration — `class`, // `classifier`, `struct`, `assoc`, `behavior`, `predicate` — which the SysML // definition taxonomy has no counterpart for. SymbolKerMLType // SymbolSatisfyRequirementUsage classifies a `satisfy requirement` usage: a // RequirementUsage specialization (SysML v2 §8.3.19) with its own kind, since // only a satisfy usage may be an assertion of a requirement's satisfaction. SymbolSatisfyRequirementUsage // SymbolRelationship classifies a relationship written keyword-first as a // member of its own (`specialization Gen subtype A specializes B`), whose two // ends are ordered (KerML §7.2). SymbolRelationship // SymbolMultiplicity classifies a named multiplicity member, `multiplicity // exactlyOne [1..1]` or `multiplicity single subsets exactlyOne`. SymbolMultiplicity )
func (SymbolKind) Family ¶ added in v0.8.0
func (k SymbolKind) Family() string
Family names the kind without its def/usage distinction, in the notation's words: SymbolActionDef and SymbolActionUsage are both "action", SymbolUseCaseDef "use case".
func (SymbolKind) IsDefinition ¶ added in v0.5.1
func (k SymbolKind) IsDefinition() bool
IsDefinition reports whether k classifies a definition — a SysML `def` or a KerML classifier — as opposed to a usage or a non-type member.
func (SymbolKind) IsFeature ¶ added in v0.5.1
func (k SymbolKind) IsFeature() bool
IsFeature reports whether k classifies a KerML Feature (KerML 1.0 §8.3.3): a usage of any kind, a connector end or a multiplicity, never a type or a namespace.
func (SymbolKind) String ¶
func (k SymbolKind) String() string
String returns the display name of the kind.
type UnitFactorFacts ¶
UnitFactorFacts is one base unit of a reduced measurement unit, named by its qualified name, and its exponent.
type UnitFacts ¶
type UnitFacts struct {
ScaleNum float64
ScaleDen float64
Factors []UnitFactorFacts
// Irreducible marks a measurement unit whose reduction is not derivable
// from its declaration, so that it is still known to be a unit.
Irreducible bool
}
UnitFacts is a measurement unit reduced to a scale factor over base units, each named by its qualified name, in the form a library index cache carries.
type WildcardImport ¶
type WildcardImport struct {
Target string
Private bool
Filter ElementFilter
}
WildcardImport is one `import X::*` declaration: the target's raw qualified name text, whether the import was declared private, and the filter condition restricting what it brings in (`import X::*[@Safety]`), which is zero for an unfiltered import.