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 AnnotatesOthers(decl ast.Node) bool
- func DeclIdent(decl ast.Node) (ast.Identification, bool)
- func DocNameOf(scope *Scope) string
- func FQNIs(sym *Symbol, parent, leaf string) bool
- 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 LastSegment(name string) string
- func MetadataAboutRefs(decl ast.Node) []*ast.QualifiedName
- func NameChain(sym *Symbol) []string
- func NeedsTree(sym *Symbol, question string) error
- func SameElement(a, b *Symbol) bool
- func SetDocName(scope *Scope, name string)
- func SpelledName(fqn string, syms []*Symbol) string
- func TextDigest(text []byte) string
- func VisibleAs(v ast.Visibility, inside, inheriting bool) bool
- func VisibleOutside(v ast.Visibility) bool
- type AnnotationFacts
- type AnnotationValueFacts
- type BoundFacts
- type ChainingFeature
- type Changes
- type DimensionFactorFacts
- type DimensionFacts
- type DocumentRecord
- type ElementFilter
- type ElementKey
- type ElementRef
- type ExprWalker
- type FilterOp
- type FilterPredicate
- type FilterUnsupportedKind
- type FilterValue
- type FilterValueKind
- type GatheredEnds
- type GatheredRelationships
- type GatheredSatisfaction
- type ImplicitForm
- type ImplicitRelationship
- type Index
- func (idx *Index) AddDocument(name string, root *ast.RootNamespace)
- func (idx *Index) AddDocumentScope(name string, root *ast.RootNamespace, rs *Scope)
- func (idx *Index) AddDocumentScopeWithKind(name string, root *ast.RootNamespace, rs *Scope, kind source.Kind)
- func (idx *Index) AddDocumentWithKind(name string, root *ast.RootNamespace, kind source.Kind)
- func (idx *Index) AddRecordedDocument(name string, kind source.Kind, rs *Scope, gathered *GatheredRelationships)
- func (idx *Index) Answerers(fqn string) []string
- func (idx *Index) Base() *Index
- func (idx *Index) Declaring(fqn string) *Symbol
- func (idx *Index) Derived(key any, build func() any) any
- 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) EachReexportGate(doc, fqn string, sym *Symbol, from string, ...) (routed, accepted bool)
- func (idx *Index) Element(ref ElementRef) *Symbol
- func (idx *Index) Elements(refs []ElementRef) []*Symbol
- 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) Gathered(doc string) *GatheredRelationships
- func (idx *Index) Generation() uint64
- 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) LookupUnique(name 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) NamespaceAnswerers(prefix string) []string
- func (idx *Index) NamespaceFiltersOf(fqn string) []ElementFilter
- func (idx *Index) Recording(r ReadRecorder) *Index
- 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) RefTo(sym *Symbol) (ref ElementRef, ok bool)
- func (idx *Index) Registered(fn func(fqn string, syms []*Symbol))
- func (idx *Index) RegisteredUnder(fqn string) []*Symbol
- func (idx *Index) RemoveDocument(name string)
- func (idx *Index) SegmentAnswerers(name string) []string
- func (idx *Index) SetNamespaceFilters(fqn, doc string, filters []ElementFilter)
- func (idx *Index) SetReadRecorder(r ReadRecorder)
- func (idx *Index) ShortNamed(name string) bool
- func (idx *Index) TakeChanges() Changes
- func (idx *Index) TopLevelBindings(doc string) []RootBinding
- func (idx *Index) TrackChanges()
- 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 MemberRecord
- type MetadataBodyResolver
- type Modifiers
- type MultiplicityFacts
- type Naming
- type NeedsHydration
- type NodeKind
- type Origin
- type QuantityValue
- type ReadRecorder
- type RelationshipDecl
- type RelationshipFacts
- type RootBinding
- type Scope
- func BodyExprScope(parent *Scope, body *ast.BodyExpr) *Scope
- func Build(root *ast.RootNamespace) *Scope
- func BuildRecorded(rec *DocumentRecord, name string) (*Scope, error)
- func ConstraintBodyScope(parent *Scope, decl ast.Node) *Scope
- func NewScope(parent *Scope, node ast.Node) *Scope
- func TriggerScope(parent *Scope, trans *ast.TransitionMember) *Scope
- func (s *Scope) AddChild(c *Scope)
- func (s *Scope) AllMembers() []*Symbol
- func (s *Scope) Annotated() ast.Node
- 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) Imports() []*ast.Import
- func (s *Scope) LookupLocal(name string) (*Symbol, bool)
- func (s *Scope) LookupLocalAll(name string) []*Symbol
- func (s *Scope) MemberAt(i int32) *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) OwningElement() *Symbol
- func (s *Scope) Parent() *Scope
- func (s *Scope) Recorded() bool
- func (s *Scope) SetOwner(sym *Symbol)
- type ScopeRecord
- type Symbol
- func (s *Symbol) DeclaresDefinition() bool
- func (s *Symbol) DeclaresTransition() bool
- func (s *Symbol) DeclaresUsage() bool
- func (s *Symbol) DefinitionKind() (ast.DefinitionKind, bool)
- func (s *Symbol) EffectiveName() bool
- func (s *Symbol) ImplicitOrdinal() int
- func (s *Symbol) ImplicitWrittenRelationship() bool
- func (s *Symbol) IsFeature() bool
- func (s *Symbol) Keyword() string
- func (s *Symbol) Notation() string
- func (s *Symbol) Origin() Origin
- func (s *Symbol) Owner() *Symbol
- func (s *Symbol) Recorded() bool
- func (s *Symbol) RecordedRelationships(kind ast.RelationshipKind) []ElementRef
- func (s *Symbol) RelationshipDecl() (RelationshipDecl, bool)
- func (s *Symbol) UsageKind() (ast.UsageKind, bool)
- type SymbolKind
- type SymbolRecord
- type UnitFactorFacts
- type UnitFacts
- type WildcardImport
Constants ¶
This section is empty.
Variables ¶
var ErrNeedsHydration = errors.New("symbols: the document must be hydrated to answer")
ErrNeedsHydration reports a question only a document's syntax tree answers, asked of an interface-record symbol: the document has to be hydrated first.
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 AnnotatesOthers ¶ added in v0.10.0
AnnotatesOthers reports whether a metadata usage states what it annotates (`metadata m about p;`, `@M about p;`), rather than annotating its owner.
func DeclIdent ¶
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 FQNIs ¶ added in v0.11.0
FQNIs reports whether FQNOf(sym) is parent::leaf, comparing the owner scope chain against parent segment by segment without building the name.
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 ¶
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 ¶
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 ¶
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 ¶
IsAbstract reports whether sym is declared abstract, reading the installed fact when one memoizes it and the declaration otherwise.
func LastSegment ¶
LastSegment is the simple name a "::"-qualified name ends in, or name itself.
func MetadataAboutRefs ¶ added in v0.10.0
func MetadataAboutRefs(decl ast.Node) []*ast.QualifiedName
MetadataAboutRefs is the names a metadata usage's `about` clause states, in either spelling of the usage; nil for any other declaration.
func NameChain ¶
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 NeedsTree ¶ added in v0.9.2
NeedsTree returns the typed answer for question asked of a recorded symbol, and nil when sym carries its declaration.
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 SpelledName ¶ added in v0.10.0
SpelledName is the name fqn registers a declaration under, which a suggestion table files it by: the declared name of the first of syms registered under fqn as its own, which may hold `::` of its own, else fqn's last segment (as a short name is).
func TextDigest ¶
TextDigest is the digest of a library document's text that LibraryDocument carries.
func VisibleAs ¶
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 ¶
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
Type ElementRef
// Span locates the node stating the annotation in its document.
Span source.Span
Values []AnnotationValueFacts
}
AnnotationFacts is one metadata annotation reduced to names and constants: the fully-qualified name of the metadata type annotating it, the reference that restores that type (zero when none reaches it), and the values the annotation body binds its features to, as written.
func (AnnotationFacts) Clone ¶ added in v0.9.2
func (a AnnotationFacts) Clone() AnnotationFacts
Clone returns a copy sharing no slice with a.
type AnnotationValueFacts ¶
type AnnotationValueFacts struct {
Feature string
Value FilterValue
Values []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. Values lists every value a sequence expression binds (`tags = ("a", "b");`); Value is the one constant when there is exactly one, and unknown otherwise.
type BoundFacts ¶ added in v0.9.2
BoundFacts is one evaluated multiplicity bound. A Named bound is written as a feature name; its value is the feature's in the declaring scope, which a reader that evaluates bounds without a scope does not see.
type ChainingFeature ¶ added in v0.10.0
type ChainingFeature struct {
Relationship *Symbol // the relationship object whose target it is
Node *ast.FeatureChainExpr // the chain written; nil when the owner is recorded
}
ChainingFeature is the feature a relationship's chain target (`:>> a.b`) denotes as a whole: the implicit chaining feature of KerML 8.3.3.3.9, which the relationship object targets and owns. The symbol that carries it is synthesized by the reflective layer and is never registered in a scope or index.
type Changes ¶
type Changes struct {
Names map[string]bool
Namespaces map[string]bool
Docs map[string]bool
// Spellings reports that the set of names the index registers changed: a
// name came or went, or is spelled otherwise. A name registered again under
// the same spelling leaves it unset, whatever symbol it now names.
Spellings bool
}
Changes is what a run of writes to an index changed, at the granularity a ReadRecorder records reads at: names, namespaces and documents. Reads meeting none saw nothing move.
func (Changes) Registered ¶
Registered reports whether the index's own tables changed: every write to them records a namespace or a document, so names alone are a caller's.
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 DocumentRecord ¶ added in v0.9.2
type DocumentRecord struct {
Scopes []ScopeRecord
Symbols []SymbolRecord
// Gathered holds what the workspace-wide audits read from the body.
Gathered *GatheredRelationships
// Nodes is the astcodec table of the import declarations and filter
// conditions the scopes refer to by table index.
Nodes []byte
}
DocumentRecord is the interface record of one document: what another document can observe of it through the language, as a tree-less scope tree whose symbols carry facts in place of declarations, and the imports and filters its namespaces state. Scopes[0] is the document root.
func RecordScope ¶ added in v0.9.2
func RecordScope(root *Scope, keep func(*Symbol) bool, facts func(*Symbol) LibraryFacts) (*DocumentRecord, error)
RecordScope writes the interface record of a loaded scope tree. keep says which members the record carries; facts states what each kept symbol's declaration yields. A kept symbol's scope is recorded with it; a scope no kept symbol owns is not.
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.
func KeyOf ¶
func KeyOf(sym *Symbol) ElementKey
KeyOf is the identity of the element sym declares. A relationship written as notation is identified by its owner and its position among the owner's relationships, so two relationships of one owner stay distinct across Models.
func (ElementKey) String ¶
func (k ElementKey) String() string
String spells the key, distinct for distinct elements, for use in a name.
type ElementRef ¶ added in v0.9.2
ElementRef names an element for a record fact: the fully-qualified name of the nearest enclosing element that name alone declares in its document (the element itself when it does), that document, and one member ordinal per step down from it to an element the name does not reach. Naming the document keeps the reference on its target when another document later declares the same name. A zero ElementRef names nothing; one without a document names whichever declaration the index lists first; one whose document the index no longer holds names the library's declaration, if any: a copy of a library file standing in for the bundled one takes over the references the other library files make into it.
func (ElementRef) Clone ¶ added in v0.9.2
func (r ElementRef) Clone() ElementRef
Clone returns a copy sharing no slice with r.
func (ElementRef) IsZero ¶ added in v0.9.2
func (r ElementRef) IsZero() bool
IsZero reports whether the reference names nothing.
type ExprWalker ¶
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 ¶
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 ¶
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 ¶
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 ¶
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`: metadata of the candidate — an annotation or // its 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
// Type is the element TypeFQN resolved to when the condition was compiled,
// so namesakes of it are told apart; nil when only the name is known.
Type *Symbol
// 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 ¶
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 is a FilterValueInt within int64; BigInt holds one beyond it, with Int zero.
Int int64
BigInt *big.Int
Real float64
// Rat is a FilterValueRational in lowest terms; it is not modified.
Rat *big.Rat
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 // FilterValueRational is an exact Rational, carried in Rat. FilterValueRational )
type GatheredEnds ¶ added in v0.9.2
type GatheredEnds struct {
Sources, Targets []ElementRef
}
GatheredEnds are the two sides of one gathered relationship.
type GatheredRelationships ¶ added in v0.9.2
type GatheredRelationships struct {
// Derivations: Sources are the referents of the `#original` ends of a
// `#derivation` connection, Targets those of its `#derive` ends.
Derivations []GatheredEnds
// Allocations: Sources are what an allocation allocates, Targets where to.
Allocations []GatheredEnds
// Conformances: Sources are the referents of the `#conformsTo` ends of a
// `#conformance` connection, Targets those of its `#conformant` ends.
Conformances []GatheredEnds
Satisfactions []GatheredSatisfaction
// SentSignals are the signal names the body's `send` actions send, sorted.
SentSignals []string
}
GatheredRelationships are the relationships a document's body states that the workspace-wide audits read across documents — what it derives, allocates, satisfies and conforms — held by reference. A recorded document carries them in place of the usages stating them; the audits resolve and judge the ends when they gather, as they do a loaded document's.
func (*GatheredRelationships) Clone ¶ added in v0.9.2
func (g *GatheredRelationships) Clone() *GatheredRelationships
Clone returns a copy sharing no slice with g; nil for nil.
func (*GatheredRelationships) Empty ¶ added in v0.9.2
func (g *GatheredRelationships) Empty() bool
Empty reports whether g states no relationship.
type GatheredSatisfaction ¶ added in v0.9.2
type GatheredSatisfaction struct {
Requirements []ElementRef
Satisfiers []ElementRef
}
GatheredSatisfaction is one `satisfy` that is neither negated nor a verify: the requirements it states satisfied — itself when it declares its requirement, else those it subsets — and what satisfies them — the subjects after `by`, else the feature whose body declares it.
type ImplicitForm ¶ added in v0.11.0
type ImplicitForm uint8
ImplicitForm is the kind of relationship an ImplicitRelationship reflects: a clause written on its owner, or a Membership, Annotation or Import the abstract syntax implies for a declaration the notation writes without one.
const ( // ImplicitWritten reflects a relationship clause written on Owner // (`:> A`, `: T`, `subsets f`, …). ImplicitWritten ImplicitForm = iota // ImplicitMembership reflects the OwningMembership through which Owner, a // namespace, owns Member (KerML 8.3.2.5). ImplicitMembership // ImplicitOwnedAnnotation reflects an Annotation Owner owns as the // annotated element, whose annotating element Member it owns through it // (`#M` prefix metadata, an annotating element in a relationship body). ImplicitOwnedAnnotation // ImplicitAnnotatingRelationship reflects an Annotation the annotating // element Owner owns for its `about` clause naming Member. ImplicitAnnotatingRelationship // ImplicitImport reflects the Import declared by Decl in the namespace Owner. ImplicitImport )
type ImplicitRelationship ¶ added in v0.10.0
type ImplicitRelationship struct {
Owner *Symbol // the element the relationship is written on (owningRelatedElement)
Ordinal int // position among Owner's relationships of the same Form
Kind ast.RelationshipKind // the notation's relationship kind (ImplicitWritten)
Conjugated bool // the `~` of a conjugation or conjugated typing
Node *ast.Relationship // the written edge; nil when Owner is recorded
Form ImplicitForm // what the relationship is
Member *Symbol // the element at the other end of a membership or annotation
Decl ast.Node // the import declaration of an ImplicitImport
}
ImplicitRelationship is a relationship the abstract syntax holds as an element of its own but the notation writes as part of its owner (KerML 8.3.2, 8.3.3). The symbol that carries it is synthesized by the reflective layer and is never registered in a scope or index.
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 ¶
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 ¶
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) AddDocumentScope ¶
func (idx *Index) AddDocumentScope(name string, root *ast.RootNamespace, rs *Scope)
AddDocumentScope is AddDocument over a scope tree already built for root, so the index and its caller share one tree: a symbol found through either is the same.
func (*Index) AddDocumentScopeWithKind ¶ added in v0.10.0
func (idx *Index) AddDocumentScopeWithKind(name string, root *ast.RootNamespace, rs *Scope, kind source.Kind)
AddDocumentScopeWithKind adds an existing scope tree and records its explicit language.
func (*Index) AddDocumentWithKind ¶
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) AddRecordedDocument ¶ added in v0.9.2
func (idx *Index) AddRecordedDocument(name string, kind source.Kind, rs *Scope, gathered *GatheredRelationships)
AddRecordedDocument installs a document from its interface record: the tree-less scope tree BuildRecorded made, indexed as a parsed one is, and the relationships its record gathered from its body. The caller expands wildcard imports afterwards, as after AddDocument.
func (*Index) Answerers ¶ added in v0.9.2
Answerers names the documents whose declarations or imports take part in the index's answer about fqn: those declaring a symbol under it and those whose wildcard imports surface one there, sorted.
func (*Index) Base ¶
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) Derived ¶ added in v0.10.0
Derived returns build's value for key, computed once per frozen index and released with it; on an index still writable it calls build every time.
func (*Index) DocumentKind ¶
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 ¶
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 ¶
Documents returns the names of every document with a root scope, bundled library content included, sorted for deterministic iteration.
func (*Index) EachReexportGate ¶ added in v0.11.0
func (idx *Index) EachReexportGate(doc, fqn string, sym *Symbol, from string, visit func(filters []ElementFilter) bool) (routed, accepted bool)
EachReexportGate visits the routes ReexportGates would return, in order, until visit accepts one, reporting whether any was visited and whether one was accepted.
func (*Index) Element ¶ added in v0.9.2
func (idx *Index) Element(ref ElementRef) *Symbol
Element restores the element a reference names, nil when nothing does.
func (*Index) Elements ¶ added in v0.9.2
func (idx *Index) Elements(refs []ElementRef) []*Symbol
Elements restores the referenced elements, dropping any a reference no longer reaches.
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 ¶
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 ¶
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) Gathered ¶ added in v0.9.2
func (idx *Index) Gathered(doc string) *GatheredRelationships
Gathered returns the relationships doc's record carries, nil for a document whose usages state them.
func (*Index) Generation ¶
Generation counts the writes the index has taken; a value read from it is current while Generation is unchanged.
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 ¶
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 ¶
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 ¶
IsLibraryDocument reports whether the named document holds bundled library content (see MarkLibrary).
func (*Index) LibraryDocumentByDigest ¶
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 ¶
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 ¶
LibraryIdentity digests the library content the index holds — every library document's language, tier and text, whatever name holds it — 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 ¶
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 ¶
LookupDirectChildrenNamed returns the direct children of prefix whose leaf name or short name is name, in LookupDirectChildren order, without a scan.
func (*Index) LookupDirectChildrenNamedFrom ¶
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) LookupUnique ¶ added in v0.11.0
LookupUnique returns the element name denotes: the one registered under it as a fully-qualified name, or the only one whose fully-qualified name ends in `::name`. Nil when nothing, or more than one element, answers.
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 ¶
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 ¶
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) NamespaceAnswerers ¶ added in v0.9.2
NamespaceAnswerers is Answerers over the direct members of the namespace named prefix: the documents that declare or surface one, sorted.
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) Recording ¶ added in v0.9.2
func (idx *Index) Recording(r ReadRecorder) *Index
Recording returns a view of the index whose reads report to r: the same tables, caches and change log as idx, so a batch worker reading the index beside others records what its analysis read without one recorder for all. The view is for reading only; a write to it is a write to idx.
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) RefTo ¶ added in v0.9.2
func (idx *Index) RefTo(sym *Symbol) (ref ElementRef, ok bool)
RefTo names sym for a record fact; ok is false for an element no reference reaches, such as one declared twice in its own document.
func (*Index) Registered ¶
Registered calls fn with every registered fully-qualified name and the symbols under it, in name order.
func (*Index) RegisteredUnder ¶
RegisteredUnder returns every symbol registered under fqn, re-exports included, or nil when the index registers nothing there.
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) SegmentAnswerers ¶ added in v0.9.2
SegmentAnswerers names the documents whose declarations decide ShortNamed(name): those declaring a symbol registered under name that is not its own last segment, sorted.
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) SetReadRecorder ¶
func (idx *Index) SetReadRecorder(r ReadRecorder)
SetReadRecorder installs the recorder the index's reads report to, or none.
func (*Index) ShortNamed ¶
ShortNamed reports whether some registered symbol carries name as its short name: it is registered under a path ending in name that is not its own.
func (*Index) TakeChanges ¶
TakeChanges returns what changed since the last call and starts over. A name registered again exactly as it was (the same symbols, re-exported and hidden alike, claimed by the same documents on the same routes) is left out: a document replaced by one declaring the same names re-registers every re-export its wildcard imports surface, and none of them reads differently.
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) TrackChanges ¶
func (idx *Index) TrackChanges()
TrackChanges starts recording what writes to the index change, for TakeChanges to hand out. An index that is never asked records nothing.
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 ¶
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 ¶
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 ¶
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 []ElementRef
// ImpliedSupers are the entries of Supers the declaration's kind implies
// rather than states: its base definition and the base usage it subsets.
ImpliedSupers []ElementRef
// 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
// Recorded marks the facts of an interface-record symbol, one installed with
// no declaration at all (see DocumentRecord). Every field below is then
// authoritative: a zero value is the answer, not "derive it".
Recorded bool
// Alias is the element an alias symbol's own target names, an alias itself
// in a chain; zero when the target resolves to nothing.
Alias ElementRef
// Redefines are the fully-qualified names of the features the declaration
// redefines by an explicit clause, in declaration order.
Redefines []ElementRef
// References is the fully-qualified name of the feature the declaration
// reference-subsets (`references f`, `perform a`), or "".
References ElementRef
// Direction is the declared feature direction of a usage.
Direction ast.FeatureDirection
// Portion is the `snapshot` or `timeslice` prefix of a usage, or
// PortionNone when the declaration has no portion keyword.
Portion ast.PortionKind
// Modifiers are the declaration's boolean modifiers (`end`, `derived`, ...).
Modifiers Modifiers
// Multiplicity is the declared multiplicity as evaluated, nil when the
// declaration states none.
Multiplicity *MultiplicityFacts
// Annotations is the metadata annotating the element, inline on its own
// declaration, as names and constants.
Annotations []AnnotationFacts
// About are the fully-qualified names of the elements a metadata usage
// annotates through its `about` clause, and Annotation the annotation it
// states on them: its type and the values it binds.
About []ElementRef
Annotation *AnnotationFacts
// Ends are the end features a connector owns, by position: the ends of
// its `connect` clause, then its body's `end` features. A zero entry is
// an end with no symbol of its own (`connect a to b`).
Ends []ElementRef
// RelatedFeatures are the features a connector's ends reference, in end
// order, as derived from the declaration.
RelatedFeatures []ElementRef
// EndPaths are the features each end of a connector object usage names in
// order, outermost first (`connect a.b to c` has [a b] and [c]), in end
// order; an end whose attachment resolves to nothing has an empty path.
EndPaths [][]ElementRef
// MetadataType is the type named by a prefix metadata usage, zero when it
// does not resolve.
MetadataType ElementRef
// Node is the class of declaration the symbol was made from.
Node NodeKind
// Keyword is the keyword the declaration was written with (`part`,
// `feature`, a user-defined keyword), "" when it states none; Notation is
// the declaration's notation as Symbol.Notation reports it.
Keyword string
Notation string
// UsageKind and DefKind are the syntactic kind of a usage or definition.
UsageKind ast.UsageKind
DefKind ast.DefinitionKind
// Relationship is what a keyword-first relationship member declares
// (`specialization S subtype A :> B;`), nil for any other declaration.
Relationship *RelationshipDecl
// Relationships are the relationships the declaration writes, in order,
// each with the fully-qualified name of what it resolved to, or "" for one
// that resolved to nothing.
Relationships []RelationshipFacts
// BaseType is the fully-qualified name of the type a metadata definition's
// own body binds `baseType` to, "" for none (see ModBindsBaseType).
BaseType ElementRef
// Default is the values a feature of a metadata definition declares, one
// per element of a sequence expression, which an annotation of the type that
// leaves the feature unbound takes; nil for none.
Default []FilterValue
}
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".
func (LibraryFacts) Clone ¶ added in v0.9.2
func (f LibraryFacts) Clone() LibraryFacts
Clone returns a copy of f sharing no slice or pointer with it.
type LibraryTier ¶
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 ¶
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 ¶
func (t LibraryTier) Library() bool
Library reports whether the tier is bundled library content of any kind.
func (LibraryTier) Semantic ¶
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 ¶
func (t LibraryTier) String() string
type MemberRecord ¶ added in v0.9.2
MemberRecord is one registration in a scope: Name "" registers the symbol anonymously.
type MetadataBodyResolver ¶
MetadataBodyResolver is the inheritance-aware lookup needed by metadata bodies.
type Modifiers ¶ added in v0.9.2
type Modifiers uint64
Modifiers is the set of boolean modifiers a declaration states, as a recorded fact reads them.
const ( ModEnd Modifiers = 1 << iota ModDerived ModInitial ModReference ModComposite ModPortion ModVariation ModVariant ModIndividual ModConjugated ModResult ModOrdered ModNonunique ModConstant ModVariable ModParallel ModDefault ModNegated ModDeclaresRequirement ModAll ModChain ModEvent // The traits below answer, for a recorded symbol, what the resolver asks // of a declaration (see resolve.DeclarationTraits). ModParameter ModImplicitlyRedefined ModContributesName ModUnresolvedRedefinition ModParameterizedByName ModBindsBaseType ModAcceptPayload // ModNamesNothing marks a derived name its target did not supply: the // symbol binds no name (see resolve.Resolver.BindsName). ModNamesNothing // ModValued marks a usage whose declaration binds it a value (`= v`, `default v`). ModValued // ModMayTimeVary marks a SysML usage whose derived Usage::mayTimeVary holds (SysML v2 §8.3.6.4). ModMayTimeVary // ModAnnotatesOthers marks a metadata usage written with an `about` clause, // whether or not the elements it names resolve (see AnnotatesOthers). ModAnnotatesOthers )
The modifiers a declaration can state (KerML 8.3.3, SysML v2 8.3.9).
type MultiplicityFacts ¶ added in v0.9.2
type MultiplicityFacts struct {
Lower, Upper BoundFacts
}
MultiplicityFacts is a declared multiplicity range as evaluated: a bound is either known, unbounded (`*`), or unknown when it names a value the record cannot carry.
type Naming ¶
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 NeedsHydration ¶ added in v0.9.2
NeedsHydration is ErrNeedsHydration naming the document and the question.
func (*NeedsHydration) Error ¶ added in v0.9.2
func (e *NeedsHydration) Error() string
func (*NeedsHydration) Unwrap ¶ added in v0.9.2
func (e *NeedsHydration) Unwrap() error
Unwrap makes errors.Is(err, ErrNeedsHydration) true.
type NodeKind ¶ added in v0.9.2
type NodeKind uint8
NodeKind classifies the declaring node of a recorded symbol.
func NodeKindOf ¶ added in v0.9.2
NodeKindOf classifies a declaring node.
type Origin ¶
Origin identifies the source declaration behind a derived artifact. Synthetic and cache-restored artifacts use the zero value.
func NodeOrigin ¶
NodeOrigin returns the origin of node in doc.
type QuantityValue ¶
QuantityValue is a constant quantity as the semantic layer represents it; units are resolved there, so the symbol layer carries the value opaquely.
type ReadRecorder ¶
type ReadRecorder interface {
ReadName(fqn string)
ReadNamespace(fqn string)
ReadDocument(name string)
ReadAllNames()
ReadSegment(name string)
}
A ReadRecorder is told what an index read is about — a name looked up, a namespace enumerated or its children read, a document's root or kind, the whole table.
type RelationshipDecl ¶ added in v0.9.2
type RelationshipDecl struct {
Kind ast.RelationshipKind
Conjugated bool
Source ElementRef
Target ElementRef
}
RelationshipDecl is the relationship a keyword-first member declares, which conjugation writes as a form of its own (`conjugation C conjugate A ~ B;`). Source and Target are the ends the member names, zero when one resolved to nothing; a record carries them only.
type RelationshipFacts ¶ added in v0.9.2
type RelationshipFacts struct {
Kind ast.RelationshipKind
Target ElementRef
Conjugated bool
// Chain marks a target written as a feature chain (`subsets a.b`), whose
// recorded reference reaches only the chain's final feature.
Chain bool
// Echo marks the `includes` the parser repeats of a use case's typing
// target (`include use case uc : UC`), which declares no relationship.
Echo bool
// Path is the features a chain target is written as, outermost first;
// empty when a feature of the chain resolves to nothing.
Path []ElementRef
}
RelationshipFacts is one written relationship of a declaration.
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 BuildRecorded ¶ added in v0.9.2
func BuildRecorded(rec *DocumentRecord, name string) (*Scope, error)
BuildRecorded rebuilds the tree-less scope tree of a record, stamped as name's. Every symbol has Decl unset and Facts set, with Recorded true.
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 scope trans's guard, effect and body resolve against: the transition's own scope, which holds the parameters its trigger declares (builder.buildDecl), and parent when the transition has none.
func (*Scope) AllMembers ¶
AllMembers returns named and anonymous symbol registrations in declaration order.
func (*Scope) Annotated ¶ added in v0.9.2
Annotated returns, for the body scope of a prefix metadata annotation, the declaration the annotation is written on; nil for any other scope.
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 ¶
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 ¶
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 ¶
ForEachAnonymousMember visits the members declared without a name in declaration order, without copying them.
func (*Scope) ForEachMember ¶
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) Imports ¶ added in v0.9.2
Imports returns the import declarations the namespace owning this scope states, in declaration order, whether read from its node or its record.
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) MemberAt ¶ added in v0.9.2
MemberAt is the i-th registration of the scope in declaration order, nil when there is none.
func (*Scope) MemberDeclaring ¶
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.
func (*Scope) OwningElement ¶ added in v0.9.2
OwningElement is the element that owns the members of s: the member of the parent scope declaring s's node, or the owner symbol when no member does.
type ScopeRecord ¶ added in v0.9.2
type ScopeRecord struct {
Owner int32 // index into Symbols, -1 for the document root
Members []MemberRecord
Children []int32
Imports []uint64 // node ids of the *ast.Import declarations
Filters []uint64 // node ids of the `filter` conditions
}
ScopeRecord is one namespace of a recorded document.
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
// Implicit is the written relationship this symbol reflects, or nil for
// every ordinary symbol (see ImplicitRelationship).
Implicit *ImplicitRelationship
// Chain is the chain target this symbol denotes as a feature, or nil for
// every ordinary symbol (see ChainingFeature).
Chain *ChainingFeature
}
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 ¶
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 ¶
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) DeclaresDefinition ¶ added in v0.9.2
DeclaresDefinition reports whether the symbol was declared by a definition.
func (*Symbol) DeclaresTransition ¶ added in v0.9.2
DeclaresTransition reports whether the symbol was declared by a transition member (`transition t first a then b;`), from its declaration or its record.
func (*Symbol) DeclaresUsage ¶ added in v0.9.2
DeclaresUsage reports whether the symbol was declared by a usage, from its declaration or its record.
func (*Symbol) DefinitionKind ¶ added in v0.9.2
func (s *Symbol) DefinitionKind() (ast.DefinitionKind, bool)
DefinitionKind is the syntactic kind of the definition declaring the symbol.
func (*Symbol) EffectiveName ¶
EffectiveName reports whether Name was derived from a naming feature rather than declared.
func (*Symbol) ImplicitOrdinal ¶ added in v0.10.0
ImplicitOrdinal is the position sym's written relationship holds among its owner's relationships, or -1 for an ordinary symbol. It keeps two relationships of one recorded owner, which share a declaration span, from ordering equal.
func (*Symbol) ImplicitWrittenRelationship ¶ added in v0.11.0
ImplicitWrittenRelationship reports whether sym reflects a relationship clause written on its owner, rather than an implied membership, annotation or import.
func (*Symbol) Keyword ¶ added in v0.9.2
Keyword is the keyword the symbol's definition or usage was written with.
func (*Symbol) Notation ¶
Notation names a symbol the way the notation declares it — "part def", "state", "render" — rather than by its internal classification.
func (*Symbol) Origin ¶
Origin returns the origin of s, or the zero origin when it is synthetic or nil.
func (*Symbol) Owner ¶
IsFeature reports whether s declares a KerML Feature: by its kind, or by its usage declaration when the kind is unclassified (a named binding). Owner is the element s was declared in, and nil at the root of a document or for a nil symbol.
func (*Symbol) Recorded ¶ added in v0.9.2
Recorded reports whether sym is an interface-record symbol: one installed from a document's record, with no declaration to read. A reader that needs the declaration answers such a symbol with ErrNeedsHydration.
func (*Symbol) RecordedRelationships ¶ added in v0.9.2
func (s *Symbol) RecordedRelationships(kind ast.RelationshipKind) []ElementRef
RecordedRelationships are the relationships a recorded symbol's declaration wrote of one kind, by target name.
func (*Symbol) RelationshipDecl ¶ added in v0.9.2
func (s *Symbol) RelationshipDecl() (RelationshipDecl, bool)
RelationshipDecl is the relationship the symbol's keyword-first member declares, from its declaration or its record; ok is false for any other symbol.
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 // SymbolBindingUsage classifies a binding usage: a BindingConnectorAsUsage // (SysML v2 §8.3.13). SymbolBindingUsage // 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 // SymbolReferenceUsage classifies a usage declared without a kind keyword: // a ReferenceUsage (SysML v2 §7.6.4), which a directed usage always is // (§7.6.3). It is an attribute usage for every purpose but the metaclass it // names. SymbolReferenceUsage )
func (SymbolKind) Family ¶
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) IsAction ¶ added in v0.11.0
func (k SymbolKind) IsAction() bool
IsAction reports whether k classifies an action: an action definition or usage, or a use case definition or usage, which is a case, a calculation and so an action (SysML v2 §7.17, §7.19) and runs as one. An analysis or verification case runs as the calculation it is.
func (SymbolKind) IsAttributeLike ¶ added in v0.9.2
func (k SymbolKind) IsAttributeLike() bool
IsAttributeLike reports whether k classifies a usage carrying attribute features: an attribute usage, or a kindless reference usage, which is an attribute for every purpose but the metaclass it names.
func (SymbolKind) IsDefinition ¶
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 ¶
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 SymbolRecord ¶ added in v0.9.2
type SymbolRecord struct {
Name string
Kind SymbolKind
Visibility ast.Visibility
DeclSpan source.Span
NameSpan source.Span
Scope int32 // index into Scopes, -1 for a leaf
ShortName string
Naming Naming
Facts LibraryFacts
}
SymbolRecord is one symbol of a recorded document.
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.