Documentation
¶
Overview ¶
Package symbols builds an immutable per-document scope tree and a global qualified-name index over a parsed ast.RootNamespace.
Index ¶
- func DocNameOf(scope *Scope) string
- func FQNOf(sym *Symbol) string
- func HasFQN(sym *Symbol, fqn string) bool
- func IsAbstract(sym *Symbol) bool
- func SameElement(a, b *Symbol) bool
- func SetDocName(scope *Scope, name string)
- 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 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) Declaring(fqn string) *Symbol
- func (idx *Index) DocumentKind(name string) source.Kind
- func (idx *Index) DocumentOfRoot(scope *Scope) string
- func (idx *Index) DocumentRoot(name string) *Scope
- 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) GetFQN(sym *Symbol) string
- func (idx *Index) HiddenFrom(fqn, fromFQN string) bool
- func (idx *Index) InstallLibraryFacts(name string, facts map[string]*LibraryFacts)
- func (idx *Index) Library(sym *Symbol) bool
- func (idx *Index) LookupDirectChildren(prefix string) []*Symbol
- func (idx *Index) LookupDirectChildrenFrom(prefix, fromFQN 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) 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) 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
- type LibraryFacts
- type MetadataBodyResolver
- 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) Define(name string, sym *Symbol)
- func (s *Scope) DefineAnonymous(sym *Symbol)
- func (s *Scope) DocName() string
- 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) 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 ¶
This section is empty.
Functions ¶
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.
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.
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 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 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 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
}
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 )
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 (*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) 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) 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) 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) 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) 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) 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) 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. 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) 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) 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.
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 MetadataBodyResolver ¶ added in v0.4.1
MetadataBodyResolver is the inheritance-aware lookup needed by metadata bodies.
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 require/assume 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.
func (*Scope) AllMembers ¶
AllMembers returns named and anonymous symbols in declaration order, with named members first.
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) 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) ForEachMember ¶ added in v0.2.1
ForEachMember visits named and anonymous symbols in declaration order, with named members first.
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) 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
// EffectiveName reports that Name was taken from the feature this
// declaration references rather than declared (KerML Feature::effectiveName).
EffectiveName bool
// NamingTarget is the reference that named this symbol when EffectiveName
// is set: 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.
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 // 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 )
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.