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 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 IsStateSource(source 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 TypeText(u *ast.Usage) string
- func VertexDecls(stateMachineDecl ast.Node, scope *symbols.Scope) (map[ast.Node]bool, error)
- func VertexKind(decl ast.Node) string
- type Accept
- type ActionEdge
- type ActionGraph
- 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 Footprint
- type If
- type LibraryStateTypes
- type Loop
- type ObjectFlow
- type PinBinding
- type Place
- type Return
- 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) IsInitial(state *ast.StateNode) bool
- 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 StateTypeResolver
- type StateTypeWithholder
- type Statement
- type Subflow
- type Transition
- type TransitionSourceError
- type Unsupported
Constants ¶
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 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 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.
Functions ¶
func ActionEndpointAccepted ¶ added in v0.3.0
ActionEndpointAccepted reports whether an action endpoint names a lowered node or one of the implicit start/done markers.
func ActionNodes ¶ added in v0.3.0
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 ¶ added in v0.6.0
BlockNodes returns the action nodes the blocks among stmts declare, in declaration order: the nodes a body's performance runs as subperformances.
func BodyStatementMembers ¶ added in v0.2.0
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 ¶ added in v0.6.0
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 ¶ added in v0.5.0
DeclaresNodeFeature reports whether an action member is a parameter or attribute.
func DescribeMember ¶ added in v0.7.0
DescribeMember names a state machine member in modelling terms, for a message about content that cannot be lowered where it was written.
func EndpointRef ¶ added in v0.8.0
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 ¶ added in v0.8.0
EndpointText renders an endpoint as written (`c::c1`, `c.c1`), for a message about it.
func EntryTransitionCarries ¶ added in v0.7.0
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 ¶ added in v0.7.0
ImplicitSource returns the body member a transition written without a source leaves, or ErrNoTransitionSource when no member precedes it in members.
func IsCaseNode ¶ added in v0.6.0
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 ¶ added in v0.7.0
IsEntryTransition reports whether the member a sourceless transition leaves is the entry action of its body, whatever else the transition was written with.
func IsStateSource ¶ added in v0.7.0
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 PerformsSteps ¶ added in v0.6.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.8.0
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 TypeText ¶ added in v0.8.0
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.
Types ¶
type Accept ¶
type Accept struct {
ParamName string
SignalType *ast.QualifiedName
ViaPort string
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 ¶ added in v0.3.0
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.
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
// InitialNode (required)
Initial ast.Node
// 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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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).
func ToActionInterface ¶ added in v0.8.0
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) Footprints ¶ added in v0.8.0
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.
type Assign ¶
type Assign struct {
Target string
// 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 ¶ added in v0.4.0
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
}
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 ¶ added in v0.8.0
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
// 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.
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
}
Effect is a statement acting on the world outside the body — perform, accept, terminate — 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 )
func (EffectKind) String ¶
func (k EffectKind) String() string
type EndpointResolver ¶ added in v0.4.1
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 ¶ added in v0.8.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
func (e *EntryTransitionShapeError) Error() string
type EntryTransitionTargetError ¶ added in v0.7.0
EntryTransitionTargetError marks a transition out of the entry action whose Target is a vertex but not a state.
func (*EntryTransitionTargetError) Error ¶ added in v0.7.0
func (e *EntryTransitionTargetError) Error() string
type Feature ¶ added in v0.5.0
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 Footprint ¶ added in v0.8.0
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.
func (Footprint) Dependent ¶ added in v0.8.0
Dependent reports whether the two moves may not commute: a data race, both touching the bus (a send meeting an accept, two accepts competing for one message, two sends ordering it), both queuing a completion, convergence on one join or merge, or a dynamic target.
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 LibraryStateTypes ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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
// 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 ¶ added in v0.5.0
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
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 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 RunToCompletionRedefinition ¶ added in v0.8.0
type RunToCompletionRedefinition struct {
// Feature is isRunToCompletion or runToCompletionScope.
Feature string
// Decl is the redefining declaration.
Decl *ast.Usage
// Owner describes the state or definition whose body declares it.
Owner string
// Written is the value as written.
Written string
// Unverified marks a value lowering cannot decide rather than one it read
// as departing from the default.
Unverified bool
}
RunToCompletionRedefinition reports a redefinition of isRunToCompletion or runToCompletionScope the executor cannot honor: a value other than the library default, or an expression lowering cannot decide restates it.
func (*RunToCompletionRedefinition) Error ¶ added in v0.8.0
func (e *RunToCompletionRedefinition) Error() string
func (*RunToCompletionRedefinition) Unwrap ¶ added in v0.8.0
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
IsVia bool
// Receiver is the name addressed by a routed send, empty when omitted.
Receiver string
ReceiverPath bool
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 ¶ added in v0.8.0
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
}
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, scope *symbols.Scope) []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.
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 {
// 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
// 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
// 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 ¶ added in v0.4.0
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 ¶ added in v0.8.0
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 ¶ added in v0.3.0
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 ¶ added in v0.8.0
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) IsInitial ¶ added in v0.1.1
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) StartOf ¶ added in v0.7.0
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 ¶ added in v0.8.0
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 ¶ added in v0.7.0
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 ¶ added in v0.8.0
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 StateTypeResolver ¶ added in v0.4.1
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 ¶ added in v0.6.0
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.
type Subflow ¶ added in v0.4.0
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 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 or *ast.PseudostateNode
Trigger ast.Node // TimeEvent, ChangeEvent, SignalEvent, CallEvent, nil = completion
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
// 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
}
Transition represents a state transition (lowered from TransitionEdge or TransitionMember).
type TransitionSourceError ¶ added in v0.7.0
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 ¶ added in v0.7.0
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.
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
- run_to_completion.go
- scope.go
- state_behavior.go
- state_footprint.go
- state_graph.go
- state_inheritance.go
- state_types.go
- transition_source.go
- vertices.go