Documentation
¶
Overview ¶
Package lower provides AST → execution IR lowering. Converts declarative members (TransitionMember, EntryMember) to operational graphs (nodes + edges) that executors consume.
Index ¶
- Constants
- Variables
- func AcceptedNames(trigger ast.Node) []string
- func ActionEndpointAccepted(nodes []ast.Node, hasInitial bool, ref ast.Node, source bool) bool
- func ActionNodes(actionDecl ast.Node, scope *symbols.Scope) (nodes []ast.Node, hasInitial bool, err error)
- func BehaviorMembers(decl ast.Node) ([]ast.Node, error)
- func BlockNodes(stmts []Statement) []ast.Node
- func BodyStatementMembers(members []ast.Node) []ast.Node
- func CaseFlowStart(graph *ActionGraph) (ast.Node, error)
- func DeclaresNodeFeature(m *ast.Usage) bool
- func DescribeMember(member ast.Node) string
- func EndpointRef(target ast.Node) ast.Node
- func EndpointText(target ast.Node) string
- func EntryTransitionCarries(transition *ast.TransitionMember) string
- func FeaturePath(node ast.Node) string
- func ImplicitSource(members []ast.Node, transition *ast.TransitionMember) (ast.Node, error)
- func IsCaseNode(u *ast.Usage) bool
- func IsEntryTransition(source ast.Node) bool
- func IsResult(stmt Statement) bool
- func IsStateSource(source ast.Node) bool
- func IsTerminateUsage(node ast.Node) bool
- func PerformsSteps(decl ast.Node) bool
- func Returns(stmts []Statement) bool
- func SendPayload(m *ast.SendStatement) ast.Node
- func SendPayloadParameter(m *ast.SendStatement) *ast.Usage
- func SendTarget(node ast.Node) (string, bool)
- func StartFlow(graph *ActionGraph)
- func StatesBehaviorBody(members []ast.Node) bool
- func TransitionGroups(source ast.Node, transitions []*Transition) [][]int
- func TriggerKey(trans *Transition) string
- func TriggerName(trigger ast.Node) string
- func TypeText(u *ast.Usage) string
- func VertexDecls(stateMachineDecl ast.Node, scope *symbols.Scope) (map[ast.Node]bool, error)
- func VertexKind(decl ast.Node) string
- func ViaPortPath(node ast.Node) (path string, self bool)
- func WeightInRange(w float64) bool
- type Accept
- type ActionEdge
- type ActionGraph
- func BlockFlows(stmts []Statement) []*ActionGraph
- func NestedFlow(in *ActionGraph, node, next ast.Node) *ActionGraph
- func ToActionGraph(actionDecl ast.Node, scope *symbols.Scope) (*ActionGraph, error)
- func ToActionGraphWith(actionDecl ast.Node, scope *symbols.Scope, resolver *resolve.Resolver) (*ActionGraph, error)
- func ToActionInterface(actionDecl ast.Node, scope *symbols.Scope) (*ActionGraph, error)
- func (g *ActionGraph) DocOf(decl ast.Node) string
- func (g *ActionGraph) Footprints() map[ast.Node]Footprint
- func (g *ActionGraph) Incoming(node ast.Node) []ActionEdge
- func (g *ActionGraph) Inherited() []Inherited
- func (g *ActionGraph) StartUsage(node ast.Node) (Effect, bool)
- func (g *ActionGraph) TerminateUsage(node ast.Node) (Effect, bool)
- type Assign
- type AssignTarget
- type Attribute
- type Binding
- type BindingEnd
- type Block
- type Channel
- type ClassifierBehavior
- type ClassifierBehaviorKind
- type Connection
- type ConnectionOwner
- type Declare
- type DeclareUsage
- type Effect
- type EffectKind
- type EndpointResolver
- type EntryTransition
- type EntryTransitionShapeError
- type EntryTransitionTargetError
- type Feature
- type FlowKind
- type Footprint
- type ForkPlan
- type If
- type Inherited
- type Integrator
- type JoinPlan
- type LibraryStateTypes
- type Loop
- type ObjectFlow
- type PinBinding
- type Place
- type Probability
- type ProbabilityError
- type Return
- type RunToCompletion
- type RunToCompletionRedefinition
- type Send
- type StartShotResolver
- type StateBehavior
- type StateBehaviors
- type StateGraph
- func (g *StateGraph) AttributeScope(attr Attribute) *symbols.Scope
- func (g *StateGraph) BehaviorFootprints() map[ast.Node]Footprint
- func (g *StateGraph) Completes(state *ast.StateNode) bool
- func (g *StateGraph) DeclOf(state *ast.StateNode) ast.Node
- func (g *StateGraph) DocOf(decl ast.Node) string
- func (g *StateGraph) EntryOwner(owner ast.Node) ast.Node
- func (g *StateGraph) ForkStarted(region *ast.StateRegion) bool
- func (g *StateGraph) Inherited() []Inherited
- func (g *StateGraph) IsInitial(state *ast.StateNode) bool
- func (g *StateGraph) RunToCompletionOf(state *ast.StateNode) RunToCompletion
- func (g *StateGraph) StartOf(owner ast.Node) []*EntryTransition
- func (g *StateGraph) TransitionFootprints() map[*Transition]Footprint
- func (g *StateGraph) UnconditionalStart(owner ast.Node) *ast.StateNode
- type StateRedefinitionResolver
- type StateSpaceDynamics
- type StateSpaceKind
- type StateSpaceModel
- type StateTypeResolver
- type StateTypeWithholder
- type Statement
- type Subflow
- type TerminateTarget
- type Transition
- type TransitionSourceError
- type Unsupported
- type ZeroCrossing
Constants ¶
const ( ProbabilityFQN = semantics.ProbabilityFQN ProbabilityFeature = semantics.ProbabilityFeature )
ProbabilityFQN names the OpenSysML metadata type by which a model weights the successions out of a decision node; ProbabilityFeature is the weight it binds.
const ( ContinuousDynamicsFQN = "StateSpaceRepresentation::ContinuousStateSpaceDynamics" DiscreteDynamicsFQN = "StateSpaceRepresentation::DiscreteStateSpaceDynamics" ZeroCrossingEventFQN = "StateSpaceRepresentation::ZeroCrossingEventDef" IntegrateFQN = "StateSpaceRepresentation::Integrate" EulerFQN = "StateSpaceIntegration::Euler" RK4FQN = "StateSpaceIntegration::RK4" FixedStepDynamicsFQN = "StateSpaceIntegration::FixedStepDynamics" )
The library declarations state-space dynamics are lowered against, by qualified name.
const ( StateSpaceFeature = "stateSpace" InputFeature = "input" OutputFeature = "output" TimeStepFeature = "timeStep" StopTimeFeature = "stopTime" TimeFeature = "time" GuardFeature = "guard" TerminalFeature = "terminal" GetDerivativeCalc = "getDerivative" GetDifferenceCalc = "getDifference" GetOutputCalc = "getOutput" GetNextStateCalc = "getNextState" IntegrateCalc = "integrate" )
The protocol's member names, as StateSpaceRepresentation declares them.
const EntryTransitionShapeFormat = "transition out of the entry action carries %s: a transition out of the entry action " +
"chooses the state its body starts in by its guard alone, `entry; if c then s;` or `entry; then s;` (SysML v2 7.18.3)"
EntryTransitionShapeFormat reports a transition out of the entry action written with a trigger or an effect, which chooses a starting state by its guard alone.
const EntryTransitionTargetFormat = "transition out of the entry action reaches %s, " +
"which is not a state to start in (SysML v2 7.18.3)"
EntryTransitionTargetFormat reports a transition out of the entry action whose target is a vertex the body cannot start in.
const NoTransitionSourceMessage = "transition without a source has no member before it to leave: " +
"it leaves the state declared before it in the same body (SysML v2 7.18.3), and none precedes it"
NoTransitionSourceMessage reports the sourceless shorthand with no member before it to leave, shared by the check reporting it and the lowering backstopping it.
const NotAVertexFormat = "transition endpoint %s names a %s that is not a vertex of this state machine"
NotAVertexFormat reports an endpoint naming an element outside the machine's vertices, shared by the check reporting it and the lowering backstopping it.
const ProbabilityTolerance = 1e-6
ProbabilityTolerance is how far the constant weights out of one decision may sum from 1.0 and still be taken as summing to it.
const StateActionFQN = "States::StateAction"
StateActionFQN names the library state every state specializes, whose content (self, substates, transitions) a consumer of the graph carries natively.
const TransitionSourceMarkerFormat = transitionSourceLeavesFormat +
"which is not a state of this state machine (SysML v2 7.18.3): write `transition first <state> … then …;` to leave one"
TransitionSourceMarkerFormat reports the shorthand whose nearest preceding member is a `first start then s;` succession or a `done;` marker, not a state.
const TransitionSourceNotVertexFormat = transitionSourceLeavesFormat +
"which is not a state of this state machine (SysML v2 7.18.3)"
TransitionSourceNotVertexFormat reports the shorthand whose nearest preceding member is not a state, shared the same way.
const TransitionSourcePseudostateFormat = transitionSourceLeavesFormat +
"which is a pseudostate rather than a state (SysML v2 7.18.3): write `transition first %s … then …;` to leave it"
TransitionSourcePseudostateFormat reports the shorthand whose nearest preceding member is a pseudostate, which only a transition naming it as `first` leaves.
const TransitionSourceRegionFormat = transitionSourceLeavesFormat +
"which is an orthogonal region of a parallel state rather than a state of this state machine (SysML v2 7.18.3)"
TransitionSourceRegionFormat reports the shorthand whose nearest preceding member is an orthogonal region of a parallel state, which no transition leaves.
Variables ¶
var ErrNoTransitionSource = errors.New(NoTransitionSourceMessage)
ErrNoTransitionSource marks a transition written without a source that no member precedes in its body.
var ErrProbability = errors.New("invalid Probability metadata")
ErrProbability is the typed error every ill-formed use of Probability wraps.
var ErrRecursiveStateTyping = errors.New("recursive state typing")
ErrRecursiveStateTyping reports a state definition whose content contains a state typed by that same definition, which has no finite materialization.
var ErrStatementOutsideFlow = errors.New("has no position in the token flow")
ErrStatementOutsideFlow reports a statement written among an action's own members that no succession binds, so it holds no position in the token flow.
var ErrUnsupportedStateContent = errors.New("unsupported state machine content")
ErrUnsupportedStateContent reports content of a state machine that lowering cannot represent, rather than dropping it.
var ErrUnsupportedStateSpace = errors.New("unsupported state-space dynamics")
ErrUnsupportedStateSpace reports a state-space action whose shape the runner cannot execute: a protocol member it does not provide, or one it cannot integrate.
Functions ¶
func AcceptedNames ¶
AcceptedNames lists the names a classified trigger binds when it fires: the payload an accept declares, or a call trigger's parameters, in order.
func ActionEndpointAccepted ¶
ActionEndpointAccepted reports whether an action endpoint names a lowered node or one of the implicit start/done markers.
func ActionNodes ¶
func ActionNodes(actionDecl ast.Node, scope *symbols.Scope) (nodes []ast.Node, hasInitial bool, err error)
ActionNodes returns the nodes accepted by action lowering and whether the action has an initial node after interpreting `first <node>`.
func BehaviorMembers ¶
BehaviorMembers are the members of a behavior declaration, and an error for a node that declares no behavior.
func BlockNodes ¶
BlockNodes returns the action nodes the blocks among stmts declare, in declaration order: the nodes a body's performance runs as subperformances.
func BodyStatementMembers ¶
BodyStatementMembers returns the members of a node body that state work to perform, in declaration order: what a body declares (a parameter, a doc comment) is a feature of the node, not a step of the flow through it.
func CaseFlowStart ¶
func CaseFlowStart(graph *ActionGraph) (ast.Node, error)
CaseFlowStart finds the step a flow starts at where no `first` or start node states one: the single step no succession leads to. Two such steps leave the start unstated, and none is a cycle; either is reported.
func DeclaresNodeFeature ¶
DeclaresNodeFeature reports whether an action member is a parameter or attribute.
func DescribeMember ¶
DescribeMember names a state machine member in modelling terms, for a message about content that cannot be lowered where it was written.
func EndpointRef ¶
EndpointRef is the node a connector end names a vertex with: a qualified name or a feature chain, unwrapped from a feature reference; nil for anything else.
func EndpointText ¶
EndpointText renders an endpoint as written (`c::c1`, `c.c1`), for a message about it.
func EntryTransitionCarries ¶
func EntryTransitionCarries(transition *ast.TransitionMember) string
EntryTransitionCarries names what a transition out of the entry action was written with beyond its guard: "a trigger", "an effect" or both.
func FeaturePath ¶
FeaturePath renders the feature a node names as a dotted path, so a nested port keeps every segment it was written with. It returns "" for a node that names no feature.
func ImplicitSource ¶
ImplicitSource returns the body member a transition written without a source leaves, or ErrNoTransitionSource when no member precedes it in members.
func IsCaseNode ¶
IsCaseNode reports whether a usage is a case nested in a body as a step of it: an analysis usage (SysML v2 §7.22) or a verification usage (§7.23), performed as the calculation it is. Its own body is the case's, run by the case, so the flow it is a node of lowers none of it.
func IsEntryTransition ¶
IsEntryTransition reports whether the member a sourceless transition leaves is the entry action of its body, whatever else the transition was written with.
func IsResult ¶
IsResult reports a statement that returns a value on some path through it: a `return`, or control flow with one inside. The results end a lowered body.
func IsStateSource ¶
IsStateSource reports whether a vertex the shorthand found before it is one it may leave: SysML v2 7.18.3 names the previous state usage, which a pseudostate, a one-ended `first s;` marker and a `done;` marker are not.
func IsTerminateUsage ¶
IsTerminateUsage reports a terminate action usage (`action stop terminate;`), which a state body declares as a vertex a transition may end at.
func PerformsSteps ¶
PerformsSteps reports whether decl is a behavior whose body performs the action nodes among its members as steps: an analysis case (SysML v2 §7.22) or a verification case (§7.23), each a calculation and an action. A calc's body reads them as declarations only.
func Returns ¶
Returns reports whether the statements return a value on some path, so a calculation whose body only computes can be told from one that has no result.
func SendPayload ¶
func SendPayload(m *ast.SendStatement) ast.Node
SendPayload returns the message a send with no argument carries: the value its body binds the payload parameter to (`send { in :>> payload = s; }`).
func SendPayloadParameter ¶
func SendPayloadParameter(m *ast.SendStatement) *ast.Usage
SendPayloadParameter returns the body feature redefining SendAction::payload: by name in a `:>>` clause, else by position as the first parameter of an argument-less send.
func SendTarget ¶
SendTarget renders a send's target and reports whether it is a feature chain (`alpha.inPort`) rather than a name in a namespace (`R`, `P::R`).
func StartFlow ¶
func StartFlow(graph *ActionGraph)
StartFlow gives a flow performed whole — a case body's, a state behavior's, an action's — that no `first` starts its one unpreceded step to begin at; where none is found the graph keeps no start, and running it reports why.
func StatesBehaviorBody ¶
StatesBehaviorBody reports whether members state a behavior body rather than only annotating the declaration or binding the behavior's parameters (`exhibit m { in x = y; }`, `exhibit m : M { doc /* … */ }`).
func TransitionGroups ¶
func TransitionGroups(source ast.Node, transitions []*Transition) [][]int
TransitionGroups returns the positions of the transitions out of source that compete for one event: every branch out of a pseudostate, and for a state the completion transitions and the transitions of each trigger spelling, each group in declaration order.
func TriggerKey ¶
func TriggerKey(trans *Transition) string
TriggerKey is the key of the event a transition reacts to: the transitions out of one state sharing it compete for the same occurrences and are checked for their weights as one group; "" keys the completion group. The lowered transition's resolved GroupKey is returned when set.
func TriggerName ¶
TriggerName describes a transition's trigger for a diagnostic and a choice line, as the runtime spells it: the signal or operation accepted, or the event's kind alone.
func TypeText ¶
TypeText spells the type a usage declares with `:` as the notation writes it (each segment quoted when it must be), or "" without one.
func VertexDecls ¶
VertexDecls returns every declaration a transition of this state machine may name as an endpoint, collected by the pass a lowered graph's vertices are collected by, so a checker reads the same ownership the executor does. scope is the scope the machine's body was declared in.
func VertexKind ¶
VertexKind names what an endpoint reached in modelling terms, for a message a modeller reads.
func ViaPortPath ¶
ViaPortPath renders the port a `via` names as the connector ends of the sender's owner write it, and reports whether it was written from `this`: `this.p` is the sender's own port p, whatever the behavior binds `p` to.
func WeightInRange ¶
WeightInRange reports whether a drawn or constant weight is a probability.
Types ¶
type Accept ¶
type Accept struct {
ParamName string
SignalType *ast.QualifiedName
ViaPort string
ViaSelf bool // ViaPort was written from `this`, as Send.ViaSelf
SubsetsEvent ast.Node
Trigger ast.Node
// Scope is the scope the accept was declared in, in which SignalType resolves.
Scope *symbols.Scope
}
Accept is a lowered accept parameter: `action r accept msg : Warning;`. SignalType is the parameter's declared type name as written, nil when it was declared without one, in which case the node accepts a message of any type.
ViaPort is the port named by `accept msg : Warning via p`, empty when the accept named none. A port-routed message is only offered to an accept on the port it arrived at, so the two forms do not consume each other's messages.
SubsetsEvent is the event feature the payload subsets (`accept :> shutDown`), as written, nil for none: the accept waits for that one event.
Trigger is the time or change event of `accept at t` / `accept after d` / `accept when c`, nil when the accept waits for a message instead.
type ActionEdge ¶
type ActionEdge struct {
Source ast.Node
Target ast.Node
Guard ast.Node
Decl ast.Node
Probability *Probability
Name string
}
ActionEdge is one succession out of a node: the node it leaves, the target it reaches, the guard it carries and its declaration (nil when implicit). No two edges of a graph compare equal. Probability is the weight its `@Probability` states, nil for an unweighted succession. Name is the name the succession was declared with, "" for an anonymous one.
type ActionGraph ¶
type ActionGraph struct {
// Scope is the scope the action's body was declared in, in which every
// expression written directly among its members resolves its names. A nested
// node or a body-local block carries its own scope instead.
Scope *symbols.Scope
// Attributes are the attribute defaults the action declares, in order.
Attributes []Attribute
// Nodes in the graph (InitialNode, FinalNode, ExecutionNode, etc.)
Nodes []ast.Node
// Edges: source node → successions in declaration order.
Edges map[ast.Node][]ActionEdge
// DataFlows: source node → list of object flows
DataFlows map[ast.Node][]ObjectFlow
// Bodies: node → the statements that node executes, in declaration order
Bodies map[ast.Node][]Statement
// Features: node → the parameters and attributes the node declares itself,
// in declaration order; each performance of the node holds its own values.
Features map[ast.Node][]Feature
// Scopes: node → the namespace the node owns, which its features resolve in.
Scopes map[ast.Node]*symbols.Scope
// Bindings are the bindings with an end at a node's pin (`bind add.a = x;`).
Bindings []PinBinding
// Accepts: node → the message that node waits for
Accepts map[ast.Node]Accept
// Subflows: node → the flow the node's own members state, present only for a
// node that states one. Its subactions are subperformances of the node, so it
// completes only when that flow does (action_subflow.go).
Subflows map[ast.Node]*Subflow
// Enclosing and EnclosingNode are the graph and node a nested flow runs under,
// whose pins a write under the flow streams from; nil for the outermost flow.
Enclosing *ActionGraph
EnclosingNode ast.Node
// InitialNode (required)
Initial ast.Node
// Invalid is the error a stated body's flow failed to lower with,
// reported at initialize().
Invalid error
// FinalNodes (may be multiple)
Finals []ast.Node
// Connections are the connectors declared in the action body, which is how
// a `send ... via <port>` finds the ports it reaches.
Connections []Connection
// StatementRuns marks the nodes of a block's own flow that stand for a run of
// statements rather than for an action node (block_graph.go). Such a node is
// keyed by the first statement of the run, whose name names no step.
StatementRuns map[ast.Node]bool
// BlockNodes lists, per node, the action nodes its body's blocks (an `if` branch,
// a loop body) declare, in declaration order: subperformances reached by name from it.
BlockNodes map[ast.Node][]ast.Node
// contains filtered or unexported fields
}
ActionGraph is the execution IR for actions. Nodes represent control flow points, edges represent flow paths.
func BlockFlows ¶
func BlockFlows(stmts []Statement) []*ActionGraph
BlockFlows returns the flows the blocks among stmts state, those of nested blocks stating none of their own included.
func NestedFlow ¶
func NestedFlow(in *ActionGraph, node, next ast.Node) *ActionGraph
NestedFlow returns the flow next is a node of among those a performance of node, a node of in, holds as its own: the flow node owns, or a block flow of its body. nil when next is no such node.
func ToActionGraph ¶
ToActionGraph converts an action AST (Usage or Definition) to an ActionGraph. scope is the scope the action's body was declared in — the scope the action itself owns — which every expression the graph carries is evaluated in. Returns error if graph is malformed (e.g., no initial node, dangling edges). Without the name-resolution tier's resolver a Probability annotation cannot be told from any other metadata, so none is read; a caller holding one uses ToActionGraphWith.
func ToActionGraphWith ¶
func ToActionGraphWith(actionDecl ast.Node, scope *symbols.Scope, resolver *resolve.Resolver) (*ActionGraph, error)
ToActionGraphWith is ToActionGraph reading the metadata the resolver identifies: a succession's `@Probability { p = ...; }` becomes its edge's weight.
func ToActionInterface ¶
ToActionInterface lowers only the attributes an action declares, for a performance that runs no body of it: an external tool's. Its flow is empty whatever the body states.
func (*ActionGraph) DocOf ¶
func (g *ActionGraph) DocOf(decl ast.Node) string
DocOf is the document a declaration of the graph was written in: the general's where inherited, else the action's own; "" outside any document.
func (*ActionGraph) Footprints ¶
func (g *ActionGraph) Footprints() map[ast.Node]Footprint
Footprints is node → what advancing a token through the node may read, write, send, accept and converge on, for the model checker's independence relation. It is computed from the lowered graph on first use and shared by every caller.
func (*ActionGraph) Incoming ¶ added in v0.9.2
func (g *ActionGraph) Incoming(node ast.Node) []ActionEdge
Incoming returns the successions into node, in the declaration order of the nodes they leave. The result is shared: callers must not modify it.
func (*ActionGraph) Inherited ¶
func (g *ActionGraph) Inherited() []Inherited
Inherited lists the declarations the action's content came from besides its own — the actions it specializes, then those its subflows specialize — each once.
func (*ActionGraph) StartUsage ¶
func (g *ActionGraph) StartUsage(node ast.Node) (Effect, bool)
StartUsage returns the start a performed action node stands for (`perform obj.beh.start;`), the last of its body; false for a node that performs otherwise.
func (*ActionGraph) TerminateUsage ¶
func (g *ActionGraph) TerminateUsage(node ast.Node) (Effect, bool)
TerminateUsage returns the terminate a terminate action usage stands for, the last of its node's body after the statements it declares; false for a node that is none.
type Assign ¶
type Assign struct {
Target string
// Qualified marks a namespace-qualified target (`Scope::azimuth`): it names
// the feature on the object its qualifier names, no host binding applies.
Qualified bool
// Owner is the qualifier's symbol (`Probe` in `Probe::count`) and Feature the
// feature it names; both are set only when Qualified is.
Owner *symbols.Symbol
Feature *symbols.Symbol
// Chain is the chained target the assignment writes through (`s.reading`),
// nil when the target was a plain name the body's host binds.
Chain *AssignTarget
Value ast.Node
Node ast.Node // the statement itself, for diagnostics
Scope *symbols.Scope // the scope the statement was declared in
}
Assign is a lowered assignment: `assign <Target> := <Value>`. Target is the feature written — the target's last segment — empty when the target names no feature.
type AssignTarget ¶
type AssignTarget struct {
// Base is the expression the chain starts from, evaluated in the statement's
// own scope.
Base ast.Node
// Steps are the features walked from Base to the object written, in order.
Steps []string
// Text is the target as written (`a.b.c`), for diagnostics.
Text string
}
AssignTarget is a chained assignment target: `assign a.b.c := v` walks `b` from `a` and writes `c` on the object it reaches.
type Attribute ¶
type Attribute struct {
Name string
// Direction is the parameter direction written, DirNone for a plain attribute.
Direction ast.FeatureDirection
IsResult bool // a `return` parameter, what the behavior yields
// Type is the declared type as written (`Natural`, `Vehicle::Mode`), "" without one.
Type string
Value ast.Node
Node ast.Node // the declaration itself, for diagnostics
// Scope is the scope the declaration was written in, in which its default
// resolves; nil where the owner's own scope resolves it.
Scope *symbols.Scope
// Optional reports an effective multiplicity with lower bound 0 (`x : Integer[0..1]`):
// the feature may hold no value at all. The run resolves it, as it does Scope.
Optional bool
}
Attribute is a lowered attribute default written among a behavior's members (`attribute h : LengthValue = 500.0 [m];`), whose Value resolves in the graph's own scope.
type Binding ¶
type Binding struct {
Ends [2]BindingEnd
Scope *symbols.Scope
Decl *ast.Usage
// Multiplicity is the connector's own as written (`binding [1] bind …`), nil when none.
Multiplicity *ast.Multiplicity
}
Binding is a lowered binding connector with its two endpoint expressions and the scope in which those expressions were declared.
type BindingEnd ¶
type BindingEnd struct {
Path string
Expr ast.Node
Multiplicity *ast.Multiplicity
}
BindingEnd is one binding endpoint. Path is the runtime lvalue path; Expr retains the lossless expression for diagnostics and calc evaluation; Multiplicity is the end multiplicity as written (`bind [0..1] a = b`), nil when none.
type Block ¶
type Block struct {
Statements []Statement
Node ast.Node // the loop or branch the block belongs to
// Scope is the block's own scope, which its declarations, and a loop's
// condition, resolve in.
Scope *symbols.Scope
// Graph is the block's own token flow, present where a member of the block is
// an action node rather than a statement — a nested action declaration, a
// `perform` — which only a flow of its own executes with the succession
// semantics it has (block_graph.go). Statements is empty for such a block: the
// statements are the bodies of the flow's nodes.
Graph *ActionGraph
// Own marks the flow a case body states of its own (case_body.go), which runs
// in the body's frame rather than a block's so its results read what it left.
Own bool
// Stated marks Graph as the token flow the body's successions and control
// nodes state; unset, Graph runs the body's steps in declaration order.
Stated bool
}
Block is a lowered body-local statement list: the body of a loop or of one branch of a conditional. It is a namespace of its own (symbols/builder.go), so the names its Declare statements introduce do not leak out of it.
type Channel ¶
Channel is one message a move sends or waits for: the signal type as written ("" for any) and the port it travels through ("" for none).
type ClassifierBehavior ¶
type ClassifierBehavior struct {
Kind ClassifierBehaviorKind
// Name is the name the behavior answers to on the object, which is the
// effective name of the declaration binding it.
Name string
// Decl is the `exhibit`/`perform` declaration itself.
Decl *ast.Usage
// StatesBody reports whether Decl states the behavior's body. A declaration
// that states none names the element that holds one instead.
StatesBody bool
// NamesBehavior reports whether Decl names the element holding the body: the
// reference form (`perform a;`, `exhibit m;`), a `references`/`::>` clause
// or a typing. A declaration naming none is the body itself
// (SysML v2 §8.3.16, eventOccurrence; §8.3.17, performedAction/exhibitedState).
NamesBehavior bool
// Arguments are the values the declaration binds to the behavior's
// parameters (`exhibit m { in controller = vehicleController; }`), in
// declaration order.
Arguments []Attribute
}
ClassifierBehavior is a behavior every object of a type runs because the type exhibits or performs it: the declaration that binds it, whether that declaration states a body of its own or names an element holding one, and the values it binds to the behavior's parameters.
func ClassifierBehaviorOf ¶
func ClassifierBehaviorOf(member ast.Node) (ClassifierBehavior, bool)
ClassifierBehaviorOf reports the behavior a type's member binds to every object of that type, and false for a member that binds none: a state or action a type merely owns is not one its objects run.
func ClassifierBehaviorsOf ¶
func ClassifierBehaviorsOf(members []ast.Node) []ClassifierBehavior
ClassifierBehaviorsOf reports the behaviors the given members bind, in declaration order.
func StartableBehaviorOf ¶
func StartableBehaviorOf(member ast.Node) (ClassifierBehavior, bool)
StartableBehaviorOf reports the behavior a type's member holds for its objects to start: one the type exhibits or performs, or an action or state usage it merely declares (`action beh : Beh;`), which an object runs once a `perform obj.beh.start` starts it and not before.
type ClassifierBehaviorKind ¶
type ClassifierBehaviorKind int
ClassifierBehaviorKind is how a type binds a behavior to its objects.
const ( // ExhibitedState is a state machine the type exhibits: `exhibit state m { … }`, // `exhibit state m : M;`, `exhibit m;` (SysML v2 §7.16.6, Part::exhibitedStates). ExhibitedState ClassifierBehaviorKind = iota // PerformedAction is an action the type performs: `perform action a { … }`, // `perform action a : A;`, `perform a;` (Part::performedActions). PerformedAction )
func (ClassifierBehaviorKind) String ¶
func (k ClassifierBehaviorKind) String() string
String names the kind in diagnostics.
type Connection ¶
type Connection struct {
Ends []string
Variation string // variation point the connection is a variant of, empty when it is not
Variant string // name of the variant declaring it, empty when it is not one
Owner ConnectionOwner // what declares it, whose selection governs a variant's connection
Scope *symbols.Scope // scope the end paths resolve in, nil when unknown
}
Connection is a lowered connector: the ends it joins, by the name each end resolves to. A `connect a to b` has two ends; a multi-end `connect` has more, and every end is reachable from every other.
A connection a `variant interface` declares joins its ends only where that variant is the one selected, so it carries the variation it belongs to, its own name, and what owns it: routing must ask what that owner bound the variation to before delivering through it (SysML v2 §7.20).
An end keeps the whole path it was written as (`sensor.out`, `p.q`), so a nested port is joined as itself and not as a same-named port elsewhere; Scope is where those paths resolve, which is what routing asks to learn the direction an end's flow features carry.
func ToObjectConnections ¶
func ToObjectConnections(decl ast.Node, scope *symbols.Scope) []Connection
ToObjectConnections lowers the connectors declared in the body of a type an object is of. A `send … via p` of a behavior an object performs routes through the object's connections as well as through the behavior's own, and it is that object's selection that realizes a variant's connection among them.
type ConnectionOwner ¶
type ConnectionOwner int
ConnectionOwner is what a lowered connection belongs to, which decides whose selection governs it when it is a variant's: a behavior activation, or the object performing the behavior.
const ( // OwnerBehavior marks a connection declared in the behavior's own body. OwnerBehavior ConnectionOwner = iota // OwnerObject marks a connection declared in the body of a type an object // performing the behavior is of. OwnerObject )
type Declare ¶
type Declare struct {
Name string
Value ast.Node
Node ast.Node // the declaration itself, for diagnostics
Scope *symbols.Scope // the scope the declaration was written in
}
Declare is a lowered declaration in a body-local block: `attribute i = 0;` written inside a loop or an `if` branch. The name it declares is a member of that block, so the executor binds it in the block's own frame and discards it when the block exits. Value is nil when the declaration carried none.
type DeclareUsage ¶
type DeclareUsage struct {
Name string
Node *ast.Usage // the declaration itself, for diagnostics
Scope *symbols.Scope // the scope the usage was declared in
}
DeclareUsage is a calc usage declared in a body-local block: `calc p : Pair { in k = h; }` written inside a loop or an `if` branch. It states no step of the computation; it declares the usage and marks where it becomes reachable, so the statements after it read its outputs from one evaluation of its body per execution of the block.
type Effect ¶
type Effect struct {
Kind EffectKind
Node ast.Node
Scope *symbols.Scope // the scope the statement was declared in
// Terminates says what a terminate ends; Target is the action node it names
// (TerminateNode), TargetExpr the target as written, nil for none. For a
// start, Target is the behavior started (`obj.beh`) and TargetExpr its `start`.
Terminates TerminateTarget
Target ast.Node
TargetExpr ast.Node
}
Effect is a statement acting on the world outside the body — perform, accept, terminate, start — lowered so a host rejecting it (a calculation) can say so.
type EffectKind ¶
type EffectKind int
EffectKind names a statement that acts on the world outside the body it stands in.
const ( EffectPerform EffectKind = iota EffectAccept EffectTerminate // EffectStart is `perform obj.beh.start;`: the behavior the chain names begins on // its object and runs on its own, the statement done once it has started. EffectStart )
func (EffectKind) String ¶
func (k EffectKind) String() string
type EndpointResolver ¶
type EndpointResolver interface {
// Endpoint returns the declaration an endpoint names, written in scope, and
// whether it names a vertex at all. target is a name or a feature chain (`c.c1`).
Endpoint(scope *symbols.Scope, target ast.Node) (decl ast.Node, ok bool)
}
EndpointResolver resolves the vertex a transition endpoint names, implemented by the name-resolution tier (*resolve.Resolver) so lowering matches no names itself.
func NewLibraryStateTypes ¶
func NewLibraryStateTypes(resolver *resolve.Resolver) EndpointResolver
NewLibraryStateTypes is the LibraryStateTypes over resolver, nil without one: lowering then names its endpoints from the scope tree alone.
type EntryTransition ¶
type EntryTransition struct {
// Decl is the member as written: a TransitionMember, a SuccessionEdge, a
// succession usage or a `first start then s;` marker.
Decl ast.Node
// Guard is nil for an unconditional entry transition.
Guard ast.Node
Target *ast.StateNode
// Scope is the scope Guard resolves in.
Scope *symbols.Scope
}
EntryTransition is a transition out of a body's entry action, naming a state the body starts in: `entry; then s;` always, `entry; if c then s;` when c holds (SysML v2 7.18.3 EntryTransitionMember). A body's alternatives are kept in declaration order, the order the guards are tried in.
type EntryTransitionShapeError ¶
type EntryTransitionShapeError struct {
Transition *ast.TransitionMember
}
EntryTransitionShapeError marks a transition out of the entry action written with a trigger or an effect.
func (*EntryTransitionShapeError) Error ¶
func (e *EntryTransitionShapeError) Error() string
type EntryTransitionTargetError ¶
EntryTransitionTargetError marks a transition out of the entry action whose Target is a vertex but not a state.
func (*EntryTransitionTargetError) Error ¶
func (e *EntryTransitionTargetError) Error() string
type Feature ¶
type Feature struct {
Name string
Direction ast.FeatureDirection
IsResult bool // a `return` parameter, what the node stands for read as a value
Value ast.Node
Node ast.Node // the declaration, for diagnostics
Scope *symbols.Scope
}
Feature is one parameter or attribute an action node declares itself. Value is its declared value (nil when none), resolving in Scope, the node's scope.
type FlowKind ¶
type FlowKind int
FlowKind is how a data flow carries its values: streaming, as a `flow` is unless designated otherwise (Flows::Flow), or as a succession flow (Flows::SuccessionFlow).
const ( // FlowStreaming delivers each value the source pin takes to the target's ongoing // performances, or ahead of its next one while none is under way. FlowStreaming FlowKind = iota // FlowSuccession delivers the value the source pin holds once the source // completes, and the target begins no sooner. FlowSuccession )
type Footprint ¶
type Footprint struct {
Reads []Place
Writes []Place
Sends []Channel
Accepts []Channel
Control []ast.Node
Completion bool
Dynamic bool
}
Footprint is what one atomic move (one token advancing one node, one transition firing) may touch. Control lists the joins and merges it arrives at; Completion marks a move that may queue a completion event; Dynamic an unresolved target.
type ForkPlan ¶
type ForkPlan struct {
Owner *ast.StateNode
Branches map[*ast.StateRegion]*Transition
}
ForkPlan is where a fork's branches lead: one per orthogonal region of Owner, each region starting at its branch's target after the branch's effect.
type If ¶
type If struct {
Condition ast.Node
Then Block
Else *Block
Node ast.Node // the conditional itself, for diagnostics
Scope *symbols.Scope // the scope the conditional, and so its condition, was declared in
}
If is a lowered conditional. The condition is evaluated in the enclosing body, outside both branches. Else is nil when the conditional declared none.
type Inherited ¶
Inherited is a declaration a graph took content from besides the one lowered (a definition typing or specializing it or a state of it); Body is its body's scope.
type Integrator ¶
type Integrator int
Integrator is a fixed-step integration scheme the runtime provides for Integrate.
const ( // IntegratorUnstated leaves the scheme to the run's default. IntegratorUnstated Integrator = iota IntegratorEuler IntegratorRK4 )
func (Integrator) String ¶
func (i Integrator) String() string
String names the integrator as the library does.
type JoinPlan ¶
type JoinPlan struct {
Owner *ast.StateNode
Regions map[*Transition]*ast.StateRegion
}
JoinPlan is where a join's incoming segments come from: Regions maps each to the orthogonal region of Owner it leaves, Owner being the innermost state all the sources lie below, nil when only the machine's own regions do.
type LibraryStateTypes ¶
LibraryStateTypes lowers a state machine through the name-resolution tier, so a definition in another document contributes, withholding States::StateAction's content.
func (*LibraryStateTypes) StartShot ¶
func (s *LibraryStateTypes) StartShot(decl ast.Node) bool
StartShot reports the library StateAction's own `start`, the shot every state inherits: a declaration elsewhere under that name is no start shot.
func (*LibraryStateTypes) WithholdsStateType ¶
func (s *LibraryStateTypes) WithholdsStateType(decl ast.Node) bool
WithholdsStateType reports the library's StateAction, whose content lowering must not take: TypeDecl still resolves it, so lowering looks no further.
type Loop ¶
type Loop struct {
Kind ast.LoopKind
Condition ast.Node // nil for `for`, and for a `loop` written without `until`
// Until is the condition a `while` loop's `until` clause tests after each
// iteration (`while c { … } until d;`), nil when it carries none.
Until ast.Node
Variable string // `for` only: the name each element is bound to
Collection ast.Node // `for` only: the collection iterated over
Body Block
Node ast.Node // the loop itself, for diagnostics
// Scope is the scope the loop was declared in, which its collection resolves
// in; its condition resolves in Body.Scope, which the body declares into.
Scope *symbols.Scope
}
Loop is a lowered loop statement. Kind says when the condition is tested: before each iteration (`while`), after each iteration (`loop … until`), or not at all, iteration being driven by a collection (`for`).
Condition and Collection stay expressions because their values are only known at execution time. The iteration count is bounded by the executor's step budget, so a loop that never terminates fails the run rather than hanging it.
type ObjectFlow ¶
type ObjectFlow struct {
// Name is the flow's own name, when it was declared with one
// (`flow generateToAmplify from a.out to b.in;`), and "" for the anonymous
// form and for a flow the notation writes as an edge.
Name string
SourcePin string
TargetPin string
Target ast.Node
// Kind is how the flow carries its values, as its declaration designated.
Kind FlowKind
// Decl is the declaration the flow was written as, for a consumer that
// reports where it comes from.
Decl ast.Node
}
ObjectFlow represents a data flow edge between pins.
type PinBinding ¶
type PinBinding struct {
Node ast.Node
Path []ast.Node
Pin string
Other ast.Node
OtherNode ast.Node
OtherPath []ast.Node
OtherPin string
// OtherChain is the chain the other end walks to the object whose feature
// OtherFeature it names (`holder.inner.mark`); nil for a node's pin or a plain name.
OtherChain *AssignTarget
OtherFeature string
// OtherOwner is the qualifier's symbol when the other end was qualified
// (`Bench::level`), and OtherFeatureSym the feature it names.
OtherOwner *symbols.Symbol
OtherFeatureSym *symbols.Symbol
Scope *symbols.Scope // the scope the binding was written in
Decl *ast.Usage
// FromValue marks the binding a pin's own value states (`inout n = ticks;`): the
// value is the pin's initial value alone when no feature around the node holds it.
FromValue bool
}
PinBinding is a binding connector with an end at pin Pin of Node — or, where Path is set, of the node Path reaches under it through the flows each owns (`leg.inner.v`: Node leg, Path [inner], Pin v). Other is the other end as written; OtherNode, OtherPath and OtherPin name the node pin it addresses, if any.
type Place ¶
Place is one feature a move reads or writes: the declaration the name resolves to (nil when unresolved) and the name; Local marks a pin, held per performance. State marks the activity of a state, which a transition reads and writes.
func (Place) Conflicts ¶
Conflicts reports whether the two places may name one value: places resolving to one declaration do under any of its names (a short name, a redefined name), as do same-named places, except two distinct pins, which each performance holds its own of; the activity of a state meets only itself.
type Probability ¶
type Probability struct {
Expr ast.Node
// Node is the annotation, for the span a message about the weight points at.
Node ast.Node
}
Probability is the weight a succession's `@Probability { p = ...; }` states for its branch: the expression bound to p, read where the succession's guard is.
func (*Probability) Constant ¶
func (p *Probability) Constant() (float64, bool)
Constant is the weight when its expression is a number computed from literals alone (0.7, 1 - 0.3); a weight computed from features is known only when drawn.
func (*Probability) Span ¶
func (p *Probability) Span() source.Span
Span is where the annotation is written.
type ProbabilityError ¶
ProbabilityError reports Probability metadata the lowering cannot give a meaning: at what node, and why.
func (*ProbabilityError) Error ¶
func (e *ProbabilityError) Error() string
func (*ProbabilityError) Is ¶
func (e *ProbabilityError) Is(target error) bool
Is makes every ProbabilityError match ErrProbability.
func (*ProbabilityError) Span ¶
func (e *ProbabilityError) Span() source.Span
Span is where the offending annotation or succession is written.
type Return ¶
type Return struct {
Value ast.Node
Node ast.Node // the return itself, for diagnostics
Scope *symbols.Scope // the scope the returned expression was written in
}
Return is a lowered `return`: the value the enclosing behavior computes, possibly from inside a block. Value is nil when it named no expression.
type RunToCompletion ¶
type RunToCompletion struct {
// Value is the isRunToCompletion expression, nil for the default true.
Value ast.Node
// ValueScope resolves names in Value.
ValueScope *symbols.Scope
// ValueOwner owns Value's state data; nil denotes the machine.
ValueOwner *ast.StateNode
// Scope is the state named by runToCompletionScope; nil denotes the machine.
Scope *ast.StateNode
}
RunToCompletion is the effective run-to-completion configuration of a body.
type RunToCompletionRedefinition ¶
type RunToCompletionRedefinition struct {
// Feature is the redefined run-to-completion feature.
Feature string
// Decl is the redefinition declaration.
Decl *ast.Usage
// Owner describes the body containing the declaration.
Owner string
// Written is the value as written.
Written string
// NotAncestor reports a resolved state outside the current state ancestry.
NotAncestor bool
}
RunToCompletionRedefinition reports a redefinition of runToCompletionScope the graph cannot resolve to this machine or an enclosing state.
func (*RunToCompletionRedefinition) Error ¶
func (e *RunToCompletionRedefinition) Error() string
func (*RunToCompletionRedefinition) Unwrap ¶
func (e *RunToCompletionRedefinition) Unwrap() error
Unwrap makes the refusal match ErrUnsupportedStateContent, the error every other state content lowering cannot represent reports.
type Send ¶
type Send struct {
Message ast.Node
Target string
TargetSym *symbols.Symbol
// TargetPath records that Target is a feature chain (`a.b`) reaching through
// the sender's features, rather than a name in a namespace (`R`, `P::R`).
TargetPath bool
// TargetExpr is the receiver expression of an addressed send as written; the
// runtime evaluates it to objects where Target carries no name or path.
TargetExpr ast.Node
IsVia bool
// ViaSelf records a via path written from `this`, whose root is a feature of
// the sender even where the behavior binds that name to another object.
ViaSelf bool
// Receiver is the name addressed by a routed send, empty when omitted.
Receiver string
ReceiverPath bool
// ReceiverExpr is the `to` expression of a routed send, likewise evaluated to
// objects where Receiver carries no name the sender resolves.
ReceiverExpr ast.Node
Scope *symbols.Scope // the scope the statement was declared in
}
Send is a lowered send statement. Message stays an expression because its value is only known at execution time.
Target is the name the send addressed, empty for a broadcast. IsVia records that the name is a port of the sender rather than a receiver, in which case it is the whole path the port was written as and the message goes to whatever the graph's Connections join that port to.
TargetSym is the feature a via target resolves to where it was written, so routing matches the feature the name denotes rather than the name alone: a port a behavior declares under a connected port's name shadows that port. It is nil where the scope tree alone does not resolve the path.
type StartShotResolver ¶
StartShotResolver identifies the library's inherited `start` shot, the one declaration a `first start then s;` may leave from without naming a vertex.
type StateBehavior ¶
type StateBehavior struct {
// Node is the behavior's declaration, unwrapped of the membership the parser
// puts it in, and is what a diagnostic about it names.
Node ast.Node
// Name is the name the behavior was declared with, "" for an anonymous one.
Name string
// Body are the behavior's statements in declaration order. An inline action
// body is one block, since it is a namespace of its own; every other form
// lowers to the one statement it states.
Body []Statement
// Nodes are the action nodes the blocks of Body declare, in declaration order,
// each of which performs as a subperformance of the behavior's.
Nodes []ast.Node
// Scope is the scope the behavior was declared in, which its own statements
// and the action name it performs resolve in.
Scope *symbols.Scope
// Owner is the state whose attributes the behavior reads and writes: the
// state it belongs to, or the source of the transition it is an effect of.
Owner *ast.StateNode
// Block is the transition whose body the behavior is one step of, shared by
// the steps of that body and by no other: a `terminate` in one ends them all.
// Every other behavior is a performance of its own and has none (nil).
Block ast.Node
}
StateBehavior is one behavior a state machine performs: an entry, do or exit behavior of a state, or one effect of a transition. Every form it may be written in — an inline action body, an assignment, a send, a performed action — is lowered into the statements the runtime executes.
func LowerBehaviors ¶
func LowerBehaviors(actions []ast.Node, block ast.Node, scope *symbols.Scope, resolver *resolve.Resolver) []StateBehavior
LowerBehaviors lowers the actions of an entry, do or exit member, or the effects of a transition, in the scope they were declared in; block is the transition whose body they are the steps of, nil for any other. resolver is the name-resolution tier's, by which a body's Probability metadata is read (ToActionGraphWith).
type StateBehaviors ¶
type StateBehaviors struct {
Entry []StateBehavior
Do []StateBehavior
Exit []StateBehavior
}
StateBehaviors are the lowered entry, do and exit behaviors of one state, each in declaration order.
type StateGraph ¶
type StateGraph struct {
// RunToCompletion contains effective RTC values for each state and the
// machine under the nil key.
RunToCompletion map[*ast.StateNode]RunToCompletion
// Scope is the scope the machine's own body was declared in, in which the
// expressions written directly among its members resolve their names.
Scope *symbols.Scope
// Attributes are the attributes the machine declares, in declaration order.
Attributes []Attribute
// StateScopes: state → the scope that state's body was declared in, which is
// what the names in its entry, do and exit behaviors resolve against.
StateScopes map[*ast.StateNode]*symbols.Scope
// Behaviors: state → its lowered entry, do and exit behaviors. The executor
// runs these rather than the state's AST members, so an inline action body is
// executable statements by the time it is reached.
Behaviors map[*ast.StateNode]*StateBehaviors
// HiddenStates are graph-only composite owners synthesized for parallel
// regions. They execute behaviors but are not user-visible state visits.
HiddenStates map[*ast.StateNode]bool
// HiddenRegionOf: graph-only owner → the region it stands for, so a walk up
// the parent chain crosses it without losing which region a state is in.
HiddenRegionOf map[*ast.StateNode]*ast.StateRegion
// RegionState: synthesized region → the graph-only owner standing for it,
// which holds the attributes the region's body declares.
RegionState map[*ast.StateRegion]*ast.StateNode
// Machine is the graph-only root state for the machine's own entry, do and
// exit behaviors. A parallel machine's regions are TopRegions instead.
Machine *ast.StateNode
// States in the machine (flat list, includes nested)
States []*ast.StateNode
// Pseudostates of the machine in declaration order. Not keyed by name:
// sibling regions may declare same-named pseudostates.
Pseudostates []*ast.PseudostateNode
// PseudostateOwner: pseudostate -> the composite state that declares it,
// absent for one declared directly in the machine. A history pseudostate
// restores the configuration of its owner, so the owner must survive lowering.
PseudostateOwner map[*ast.PseudostateNode]*ast.StateNode
// Terminates are the machine's terminate action usages (`action stop terminate;`)
// in declaration order: a transition ending at one ends the machine's performance.
Terminates []*ast.Usage
// TerminateOwner: terminate action usage -> the composite state that declares
// it, absent for one declared directly in the machine.
TerminateOwner map[*ast.Usage]*ast.StateNode
// Transitions: source node (StateNode or PseudostateNode) → list of transitions
Transitions map[ast.Node][]*Transition
// CompositeStates: state → regions
CompositeStates map[*ast.StateNode][]*ast.StateRegion
// CompositeStateOrder preserves declaration order for deterministic runtime
// selection of an active composite owner.
CompositeStateOrder []*ast.StateNode
// RegionInitials: region → initial state
RegionInitials map[*ast.StateRegion]*ast.StateNode
// ParentState: child → parent
ParentState map[*ast.StateNode]*ast.StateNode
// RegionOwner: region → owning composite state
RegionOwner map[*ast.StateRegion]*ast.StateNode
// Deferred: state → the triggers it defers while active, normalized the same
// way transition triggers are.
Deferred map[*ast.StateNode][]ast.Node
// TopRegions are the machine's own orthogonal regions, in declaration order.
// The order is observable: it is the order regions are entered and exited in.
TopRegions []*ast.StateRegion
// RegionOf: state → the region that declares it (fork/join need the region a
// target belongs to)
RegionOf map[*ast.StateNode]*ast.StateRegion
// InitialState (required for simple machines, nil for multi-region)
Initial *ast.StateNode
// EntryTransitions: the body a transition out of the entry action is written
// in (a state, a region, nil for the machine's own body) → those transitions in
// declaration order; the first whose guard holds names the state it starts in.
EntryTransitions map[ast.Node][]*EntryTransition
// ForkPlans: fork → where its branches lead, checked when the graph is built.
ForkPlans map[*ast.PseudostateNode]*ForkPlan
// ForkEntered: region → the forks whose branches enter it, in declaration
// order. A region only forks enter needs no entry transition of its own.
ForkEntered map[*ast.StateRegion][]*ast.PseudostateNode
// JoinPlans: join → where its segments come from, checked when the graph is built.
JoinPlans map[*ast.PseudostateNode]*JoinPlan
// Connections are the connectors declared in the state machine body, which
// is how a `send ... via <port>` in an entry/do/exit/effect action finds the
// ports it reaches.
Connections []Connection
// StateAttributes: state → the attributes it owns, its own and those it
// inherits from the definition typing it. Each state owns its values, so two
// usages of one definition hold two sets of them.
StateAttributes map[*ast.StateNode][]Attribute
// contains filtered or unexported fields
}
StateGraph is the execution IR for state machines.
func ToStateGraph ¶
ToStateGraph converts a state machine AST (Usage or Definition) to a StateGraph. scope is the scope the machine's body was declared in — the scope the machine itself owns — from which the scope of every state and transition it carries is derived. Its endpoints resolve against the machine's own symbols; a caller holding the name-resolution tier's uses ToStateGraphWithEndpoints instead.
func ToStateGraphWithEndpoints ¶
func ToStateGraphWithEndpoints(stateMachineDecl ast.Node, scope *symbols.Scope, endpoints EndpointResolver) (*StateGraph, error)
ToStateGraphWithEndpoints lowers a state machine, building its transitions from the endpoints the name-resolution tier already resolved.
func (*StateGraph) AttributeScope ¶
func (g *StateGraph) AttributeScope(attr Attribute) *symbols.Scope
AttributeScope is the scope an attribute's value resolves in, which is the body declaring it rather than the machine's when the machine inherits it.
func (*StateGraph) BehaviorFootprints ¶
func (g *StateGraph) BehaviorFootprints() map[ast.Node]Footprint
BehaviorFootprints is entry, do or exit behavior (its Node) → what running it touches, computed on first use as TransitionFootprints is.
func (*StateGraph) Completes ¶
func (g *StateGraph) Completes(state *ast.StateNode) bool
Completes reports whether entering state completes the region it belongs to: it is the `done` end shot of the state or machine whose body names it.
func (*StateGraph) DeclOf ¶
func (g *StateGraph) DeclOf(state *ast.StateNode) ast.Node
DeclOf is the declaration state was lowered from: the node the scope tree is keyed by, or the state itself when it was written as one.
func (*StateGraph) DocOf ¶
func (g *StateGraph) DocOf(decl ast.Node) string
DocOf is the document a declaration of the graph was written in: the general's where inherited, else the machine's own; "" outside any document.
func (*StateGraph) EntryOwner ¶
func (g *StateGraph) EntryOwner(owner ast.Node) ast.Node
EntryOwner is the body owner's entry transitions are written in, as EntryTransitions keys it: the region a state of a parallel state stands for, else owner itself.
func (*StateGraph) ForkStarted ¶
func (g *StateGraph) ForkStarted(region *ast.StateRegion) bool
ForkStarted reports whether a fork enters region, so it may start there without an entry transition of its own.
func (*StateGraph) Inherited ¶
func (g *StateGraph) Inherited() []Inherited
Inherited lists the declarations the machine's content was materialized from besides its own, each once, in the order lowering first reached them.
func (*StateGraph) IsInitial ¶
func (g *StateGraph) IsInitial(state *ast.StateNode) bool
IsInitial reports whether the machine may start in state: some entry transition of its body names it. Whether it starts there unconditionally is UnconditionalStart's.
func (*StateGraph) RunToCompletionOf ¶
func (g *StateGraph) RunToCompletionOf(state *ast.StateNode) RunToCompletion
RunToCompletionOf returns the effective configuration for state, or the machine when state is nil.
func (*StateGraph) StartOf ¶
func (g *StateGraph) StartOf(owner ast.Node) []*EntryTransition
StartOf returns the transitions out of a body's entry action in declaration order: owner is the state whose body it is, the region, or nil for the machine's own body. A state standing for a region of a parallel state starts where that region's entry transitions say.
func (*StateGraph) TransitionFootprints ¶
func (g *StateGraph) TransitionFootprints() map[*Transition]Footprint
TransitionFootprints is transition out of a state → what firing it may touch, its route through pseudostates followed along every branch. It is computed from the lowered graph on first use and shared by every caller.
func (*StateGraph) UnconditionalStart ¶
func (g *StateGraph) UnconditionalStart(owner ast.Node) *ast.StateNode
UnconditionalStart is the state a body starts in whatever its guards say: its first entry transition's target when unguarded, else nil. owner is as for StartOf.
type StateRedefinitionResolver ¶
type StateRedefinitionResolver interface {
RedefinitionTarget(scope *symbols.Scope, decl ast.Node, target ast.Node) (*symbols.Symbol, bool)
LibraryFeature(sym *symbols.Symbol) bool
}
StateRedefinitionResolver resolves the feature a redefinition written in a state body targets, an alias followed to what it names, and tells the library's own declarations from a model's spelled like them.
type StateSpaceDynamics ¶
type StateSpaceDynamics struct {
Kind StateSpaceKind
// Action is the action lowered; Scope its body scope, where its features resolve.
Action *symbols.Symbol
Scope *symbols.Scope
// State, Input and Output are the protocol's stateSpace, input and output
// features as the action holds them, the nearest declaration of each.
State, Input, Output *symbols.Symbol
// TimeStep and StopTime are the features stating the step and the instant the
// run stops at, nil where the action declares none; Time, when declared,
// receives the clock's instant at each step.
TimeStep, StopTime, Time *symbols.Symbol
// Derivative is the model's getDerivative (continuous), Difference its
// getDifference (discrete), OutputCalc its getOutput; each concrete.
Derivative, Difference, OutputCalc *symbols.Symbol
// NextState is a getNextState the model bodies itself, which the runner calls
// in place of the library's; nil when the library's runs natively.
NextState *symbols.Symbol
// Integrator is the scheme the model binds to the library's integrate, unstated
// when it leaves the run's default; IntegratorType is that scheme's declaration.
Integrator Integrator
IntegratorType *symbols.Symbol
// Crossings are the zero-crossing events the dynamics raise, in declaration order.
Crossings []ZeroCrossing
}
StateSpaceDynamics is the lowering of an action specializing the library's StateSpaceDynamics: the calcs the model provides for the protocol, how the next state is reached, the features a step reads and writes, and the zero crossings it watches.
func ToStateSpaceDynamics ¶
func ToStateSpaceDynamics(action *symbols.Symbol, scope *symbols.Scope, model StateSpaceModel) (*StateSpaceDynamics, error)
ToStateSpaceDynamics lowers an action specializing one of the library's dynamics into what the runner steps: a member the protocol needs that the model leaves abstract, or an integrator the runtime does not provide, is an ErrUnsupportedStateSpace.
type StateSpaceKind ¶
type StateSpaceKind int
StateSpaceKind tells continuous dynamics, stepped by integrating a derivative, from discrete ones, stepped by adding a difference.
const ( // NotStateSpace is an action specializing neither dynamics. NotStateSpace StateSpaceKind = iota ContinuousDynamics DiscreteDynamics )
func StateSpaceKindOf ¶
func StateSpaceKindOf(action *symbols.Symbol, model StateSpaceModel) StateSpaceKind
StateSpaceKindOf classifies an action: the dynamics it specializes, if either.
func (StateSpaceKind) String ¶
func (k StateSpaceKind) String() string
String names the kind as the library does.
type StateSpaceModel ¶
type StateSpaceModel interface {
// LibrarySymbol is the library declaration of this qualified name, nil when unloaded.
LibrarySymbol(fqn string) *symbols.Symbol
// Specializes reports whether sym is general or transitively specializes it.
Specializes(sym, general *symbols.Symbol) bool
// MembersOf lists sym's effective members, inherited ones masked by its redefinitions.
MembersOf(sym *symbols.Symbol) []*symbols.Symbol
// FeatureTypes lists the types a feature has, declared or along its redefinitions.
FeatureTypes(sym *symbols.Symbol) []*symbols.Symbol
// ParameterDefault is the value a feature states along its redefinitions, with its scope.
ParameterDefault(sym *symbols.Symbol) (ast.Node, *symbols.Scope)
// LibraryDeclared reports a declaration of a library document, not the model's.
LibraryDeclared(sym *symbols.Symbol) bool
}
StateSpaceModel answers the semantic questions lowering state-space dynamics asks, so an inherited or redefined protocol member is found where it was declared.
type StateTypeResolver ¶
type StateTypeResolver interface {
TypeDecl(scope *symbols.Scope, qn *ast.QualifiedName) (ast.Node, *symbols.Scope, bool)
}
StateTypeResolver resolves the declaration a type name reaches and its body scope. Lowering falls back to the scope tree only without one or for a name it cannot resolve.
type StateTypeWithholder ¶
StateTypeWithholder names resolved declarations whose content lowering must not take. A withheld type is settled: it is never looked up again through the scope tree.
type Statement ¶
type Statement interface {
// contains filtered or unexported methods
}
Statement is one lowered statement in an action node's body. Statements are kept in declaration order so the executor never walks the node's members again to find them.
func CalcBody ¶
CalcBody lowers the computation a calculation or case body states, in declaration order and in the scope it was written in. A member stating no computation — an input parameter, documentation, a nested definition — is skipped. A result the body declares names the value answered with, not a step, so it runs after the steps; a `return` inside a branch or loop stops the body there. owner is the declaration whose body members are: a case's body whose members include action nodes performs them as its steps, lowered as one Block over the flow they state (caseSteps); a calc's does not. Without a resolver the flow's `@Probability` annotations go unread, as in ToActionGraph; a caller holding one uses CalcBodyWith.
type Subflow ¶
type Subflow struct {
Graph *ActionGraph
Err error
}
Subflow is the flow a nested action node's own members state. Graph is nil when those members state a flow that could not be built, which Err says; the executor reports it at initialize() rather than treating the node as a leaf.
type TerminateTarget ¶
type TerminateTarget int
TerminateTarget is what a terminate names, settled where it was written.
const ( // TerminateContaining is a terminate naming nothing: the containing performance ends. TerminateContaining TerminateTarget = iota // TerminateEnclosing is a terminate action usage: the performance its node is a step of ends. TerminateEnclosing // TerminateNode names an action usage (Effect.Target): a node of an enclosing flow, // or else the action occurrence the name denotes, evaluated as TerminateOccurrence is. TerminateNode // TerminateOccurrence names an occurrence by an expression the executor evaluates. TerminateOccurrence )
type Transition ¶
type Transition struct {
// Name is the transition's own name, when it was written with one
// (`transition maintain first idle then busy`), and "" when it was not.
Name string
// Decl is the declaration the transition was written as, for a consumer that
// reports where it comes from.
Decl ast.Node
Source ast.Node // *ast.StateNode or *ast.PseudostateNode
Target ast.Node // *ast.StateNode, *ast.PseudostateNode or a terminate action *ast.Usage
// Owner is the state whose body declares the transition, nil for the machine body.
Owner *ast.StateNode
Trigger ast.Node // TimeEvent, ChangeEvent, SignalEvent, CallEvent, nil = completion
// Accepted names what the trigger binds when the transition fires — an accept's
// payload, a call's parameters — in declaration order; nil binds nothing.
Accepted []string
Guard ast.Node // guard expression, nil = no guard
// Effect are the transition's effect behaviors, lowered the same way a state's
// entry, do and exit behaviors are.
Effect []StateBehavior
// Via is the port the accepted occurrence must arrive at
// (`accept Ping via commPort`), and "" when the trigger names no port, in
// which case an occurrence reaching the machine by any route fires it.
Via string
// ViaSelf records a via path written from `this`, whose root is a feature of
// the performer however the machine's data would resolve the name.
ViaSelf bool
// Scope is the scope the transition was declared in, in which the expressions
// its trigger carries — a time event's duration, a change event's condition —
// resolve their names.
Scope *symbols.Scope
// BodyScope is the scope the transition's guard and effect resolve in. It is
// Scope, except for a call trigger, whose parameters are visible to the guard
// and effect and nowhere else (`accept setSpeed(v) if v > 0`).
BodyScope *symbols.Scope
// Probability is the weight `@Probability { p = ...; }` states for the
// transition, read where its guard is; nil when the transition is unweighted.
Probability *Probability
// GroupKey is the resolved trigger spelling this transition competes under:
// TriggerKey returns it when set, else computes the un-resolved spelling.
GroupKey string
}
Transition represents a state transition (lowered from TransitionEdge or TransitionMember).
type TransitionSourceError ¶
TransitionSourceError marks a sourceless transition whose preceding member, Source, is not a state of the machine; Region records that it is a region of a parallel state.
func (*TransitionSourceError) Error ¶
func (e *TransitionSourceError) Error() string
type Unsupported ¶
type Unsupported struct {
Description string
Node ast.Node
Scope *symbols.Scope // the scope the member was declared in
}
Unsupported is a body member the lowering layer recognizes but cannot yet turn into an executable statement. It is lowered rather than dropped so that reaching it fails the execution with a diagnostic instead of silently producing a wrong answer. Description names the construct.
type ZeroCrossing ¶
type ZeroCrossing struct {
Name string
// Event is the event occurrence usage; EventType the ZeroCrossingEventDef
// specialization typing it, which the raised event carries.
Event *symbols.Symbol
EventType *symbols.Symbol
Guard ast.Node
// GuardScope is where the guard was written, its names resolving there.
GuardScope *symbols.Scope
// Terminal is the expression stating whether the crossing ends the run, nil for never.
Terminal ast.Node
TerminalScope *symbols.Scope
}
ZeroCrossing is one event occurrence among the dynamics' zeroCrossingEvents: its guard, whose sign change raises the event, and whether that ends the run.
Source Files
¶
- action_graph.go
- action_nodes.go
- action_subflow.go
- binding.go
- block_graph.go
- calc_body.go
- case_body.go
- classifier_behavior.go
- connection.go
- endpoints.go
- entry_transition.go
- footprint.go
- fork_plan.go
- join_check.go
- probability.go
- run_to_completion.go
- scope.go
- state_behavior.go
- state_footprint.go
- state_graph.go
- state_inheritance.go
- state_space.go
- state_types.go
- transition_source.go
- vertices.go