Refactor code

Rename Junction to Choice
This commit is contained in:
Rob Bocchino 2024-11-04 19:06:37 -08:00
parent 0bf8f2643d
commit 715be7bcb2
29 changed files with 116 additions and 116 deletions

View File

@ -22,7 +22,7 @@ trait SmTypedElementAnalyzer
def junctionTypedElement(
sma: StateMachineAnalysis,
te: StateMachineTypedElement.Junction
te: StateMachineTypedElement.Choice
): Result = default(sma)
def stateEntryTypedElement(
@ -50,7 +50,7 @@ trait SmTypedElementAnalyzer
): Result = te match {
case it: StateMachineTypedElement.InitialTransition =>
initialTransitionTypedElement(sma, it)
case j: StateMachineTypedElement.Junction =>
case j: StateMachineTypedElement.Choice =>
junctionTypedElement(sma, j)
case se: StateMachineTypedElement.StateEntry =>
stateEntryTypedElement(sma, se)
@ -60,12 +60,12 @@ trait SmTypedElementAnalyzer
stateTransitionTypedElement(sma, st)
}
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
sma: StateMachineAnalysis,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = visitTypedElement(
sma,
StateMachineTypedElement.Junction(aNode)
StateMachineTypedElement.Choice(aNode)
)
override def specStateEntryAnnotatedNode(

View File

@ -36,7 +36,7 @@ trait StateMachineUseAnalyzer
): Result = default(sma)
/** A use of a state definition or junction definition */
def stateOrJunctionUse(
def stateOrChoiceUse(
sma: StateMachineAnalysis,
node: AstNode[Ast.QualIdent],
use: Name.Qualified
@ -46,9 +46,9 @@ trait StateMachineUseAnalyzer
// Implementation using StateMachineAnalysisVisitor
// ----------------------------------------------------------------------
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
sma: StateMachineAnalysis,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val data = aNode._2.data
for {
@ -97,7 +97,7 @@ trait StateMachineUseAnalyzer
): Result =
for {
sma <- actions(sma, e.actions)
sma <- qualIdentNode(stateOrJunctionUse)(sma, e.target)
sma <- qualIdentNode(stateOrChoiceUse)(sma, e.target)
}
yield sma

View File

@ -32,7 +32,7 @@ trait TransitionExprAnalyzer
/** The pair of transition expressions in a junction */
def junctionTransitionExprPair(
sma: StateMachineAnalysis,
junction: StateMachineSymbol.Junction,
junction: StateMachineSymbol.Choice,
ifExprNode: AstNode[Ast.TransitionExpr],
elseExprNode: AstNode[Ast.TransitionExpr]
): Result = for {
@ -43,7 +43,7 @@ trait TransitionExprAnalyzer
/** A transition expression in a junction */
def junctionTransitionExpr(
sma: StateMachineAnalysis,
junction: StateMachineSymbol.Junction,
junction: StateMachineSymbol.Choice,
exprNode: AstNode[Ast.TransitionExpr]
): Result = default(sma)
@ -51,14 +51,14 @@ trait TransitionExprAnalyzer
// Implementation using StateMachineAnalysisVisitor
// ----------------------------------------------------------------------
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
sma: StateMachineAnalysis,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val data = aNode._2.data
junctionTransitionExprPair(
sma,
StateMachineSymbol.Junction(aNode),
StateMachineSymbol.Choice(aNode),
data.ifTransition,
data.elseTransition
)

View File

@ -140,8 +140,8 @@ object CheckInitialTransitions
else Left(destSymbol :: errorSymbols)
// Recursively check junction targets
visitedSymbols <- destSymbol match {
// Junction: check it
case StateMachineSymbol.Junction(aNode) =>
// Choice: check it
case StateMachineSymbol.Choice(aNode) =>
for {
// Recursively check the if transition
visitedSymbols <- {

View File

@ -21,7 +21,7 @@ object CheckStateMachineSemantics {
sma <- CheckTransitionGraph.defStateMachineAnnotatedNode(sma, aNode)
sma <- CheckTypedElements.defStateMachineAnnotatedNode(sma, aNode)
sma <- ComputeFlattenedStateTransitionMap.defStateMachineAnnotatedNode(sma, aNode)
sma <- ComputeFlattenedJunctionTransitionMap.defStateMachineAnnotatedNode(sma, aNode)
sma <- ComputeFlattenedChoiceTransitionMap.defStateMachineAnnotatedNode(sma, aNode)
}
yield sma
// External state machine: do nothing

View File

@ -34,7 +34,7 @@ object CheckStateMachineUses extends StateMachineUseAnalyzer {
use: Name.Unqualified
): Result = helpers.visitIdentNode (StateMachineNameGroup.Signal) (sma, node)
override def stateOrJunctionUse(
override def stateOrChoiceUse(
sma: StateMachineAnalysis,
node: AstNode[Ast.QualIdent],
use: Name.Qualified

View File

@ -4,13 +4,13 @@ import fpp.compiler.ast._
import fpp.compiler.util._
/** Checks for junction cycles */
object CheckJunctionCycles {
object CheckChoiceCycles {
def stateMachineAnalysis(sma: StateMachineAnalysis): Result.Result[Unit] = {
val nodes = sma.transitionGraph.arcMap.keys.toList
for {
_ <- Result.foldLeft (nodes) (State(sma)) {
case (s, TransitionGraph.Node(StateOrJunction.Junction(j))) =>
case (s, TransitionGraph.Node(StateOrChoice.Choice(j))) =>
visit(s.clearPath, j)
case (s, _) => Right(s)
}
@ -19,14 +19,14 @@ object CheckJunctionCycles {
private case class State(
sma: StateMachineAnalysis,
visited: Set[StateMachineSymbol.Junction] = Set(),
pathSet: Set[StateMachineSymbol.Junction] = Set(),
visited: Set[StateMachineSymbol.Choice] = Set(),
pathSet: Set[StateMachineSymbol.Choice] = Set(),
pathList: List[TransitionGraph.Arc] = Nil
) {
def clearPath: State = this.copy(pathSet = Set(), pathList = Nil)
}
private def visit(s: State, j: StateMachineSymbol.Junction):
private def visit(s: State, j: StateMachineSymbol.Choice):
Result.Result[State] =
if s.pathSet.contains(j)
then {
@ -35,17 +35,17 @@ object CheckJunctionCycles {
"encountered a junction cycle:" ::
s.pathList.reverse.map(_.showTransition)
).mkString("\n ")
Left(SemanticError.StateMachine.JunctionCycle(loc, msg))
Left(SemanticError.StateMachine.ChoiceCycle(loc, msg))
}
else {
val s1 = s.copy(pathSet = s.pathSet + j)
val soj = StateOrJunction.Junction(j)
val soj = StateOrChoice.Choice(j)
val node = TransitionGraph.Node(soj)
val nodes = s.sma.transitionGraph.arcMap(node).toList
for {
s <- Result.foldLeft (nodes) (s1) (
(s, a) => a.getEndNode.soj match {
case StateOrJunction.Junction(j1) => {
case StateOrChoice.Choice(j1) => {
val s2 = s.copy(pathList = a :: s.pathList)
visit(s2, j1)
}

View File

@ -13,7 +13,7 @@ object CheckTransitionGraph {
for {
sma <- ConstructTransitionGraph.defStateMachineAnnotatedNode(sma, aNode)
_ <- CheckTGReachability.stateMachineAnalysis(sma)
_ <- CheckJunctionCycles.stateMachineAnalysis(sma)
_ <- CheckChoiceCycles.stateMachineAnalysis(sma)
}
yield sma.copy(
reverseTransitionGraph = sma.transitionGraph.getReverseGraph

View File

@ -11,7 +11,7 @@ object ConstructTransitionGraph extends TransitionExprAnalyzer {
aNode: Ast.Annotated[AstNode[Ast.DefState]]
) = {
val sym = StateMachineSymbol.State(aNode)
val soj = StateOrJunction.State(sym)
val soj = StateOrChoice.State(sym)
val node = TransitionGraph.Node(soj)
val transitionGraph = sma.transitionGraph.addNode(node)
super.defStateAnnotatedNode(
@ -20,15 +20,15 @@ object ConstructTransitionGraph extends TransitionExprAnalyzer {
)
}
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
sma: StateMachineAnalysis,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val sym = StateMachineSymbol.Junction(aNode)
val soj = StateOrJunction.Junction(sym)
val sym = StateMachineSymbol.Choice(aNode)
val soj = StateOrChoice.Choice(sym)
val node = TransitionGraph.Node(soj)
val transitionGraph = sma.transitionGraph.addNode(node)
super.defJunctionAnnotatedNode(
super.defChoiceAnnotatedNode(
sma.copy(transitionGraph = transitionGraph),
aNode
)
@ -68,11 +68,11 @@ object ConstructTransitionGraph extends TransitionExprAnalyzer {
override def junctionTransitionExpr(
sma: StateMachineAnalysis,
junction: StateMachineSymbol.Junction,
junction: StateMachineSymbol.Choice,
exprNode: AstNode[Ast.TransitionExpr]
): Result = {
val endNode = getNodeFromExpr(sma, exprNode)
val arc = TransitionGraph.Arc.Junction(junction, exprNode, endNode)
val arc = TransitionGraph.Arc.Choice(junction, exprNode, endNode)
val transitionGraph = sma.transitionGraph.addArc(arc)
Right(sma.copy(transitionGraph = transitionGraph))
}
@ -84,9 +84,9 @@ object ConstructTransitionGraph extends TransitionExprAnalyzer {
val sym = sma.useDefMap(exprNode.data.target.id)
val soj = sym match {
case state: StateMachineSymbol.State =>
StateOrJunction.State(state)
case junction: StateMachineSymbol.Junction =>
StateOrJunction.Junction(junction)
StateOrChoice.State(state)
case junction: StateMachineSymbol.Choice =>
StateOrChoice.Choice(junction)
case _ => throw new InternalError("transition should go to state or junction")
}
TransitionGraph.Node(soj)

View File

@ -18,7 +18,7 @@ object CheckActionAndGuardTypes
override def junctionTypedElement(
sma: StateMachineAnalysis,
te: StateMachineTypedElement.Junction
te: StateMachineTypedElement.Choice
): Result = {
val data = te.aNode._2.data
for {

View File

@ -16,10 +16,10 @@ object ComputeTypeOptionMap
override def junctionTypedElement(
sma: StateMachineAnalysis,
te: StateMachineTypedElement.Junction
te: StateMachineTypedElement.Choice
): Result = {
val sym = StateMachineSymbol.Junction(te.aNode)
val soj = StateOrJunction.Junction(sym)
val sym = StateMachineSymbol.Choice(te.aNode)
val soj = StateOrChoice.Choice(sym)
val node = TransitionGraph.Node(soj)
val arcs = sma.reverseTransitionGraph.arcMap(node).toList
arcs match {
@ -39,7 +39,7 @@ object ComputeTypeOptionMap
val te2 = arc.getTypedElement
for {
sma2 <- visitTypedElement(sma1, te2)
to2 <- sma2.commonTypeAtJunction(te, te1, to1, te2)
to2 <- sma2.commonTypeAtChoice(te, te1, to1, te2)
}
yield (sma2, te2, to2)
}

View File

@ -4,25 +4,25 @@ import fpp.compiler.ast._
import fpp.compiler.util._
/** Compute the flattened junction transition map */
object ComputeFlattenedJunctionTransitionMap
object ComputeFlattenedChoiceTransitionMap
extends TransitionExprAnalyzer
{
override def junctionTransitionExpr(
sma: StateMachineAnalysis,
junction: StateMachineSymbol.Junction,
junction: StateMachineSymbol.Choice,
exprNode: AstNode[Ast.TransitionExpr]
): Result = {
val transition = {
val actions = exprNode.data.actions.map(sma.getActionSymbol)
val target = sma.getStateOrJunction(exprNode.data.target)
val target = sma.getStateOrChoice(exprNode.data.target)
val transition0 = Transition.External(actions, target)
val source = StateOrJunction.Junction(junction)
val source = StateOrChoice.Choice(junction)
val cft = ConstructFlattenedTransition(sma, source)
cft.transition(transition0)
}
val fjtm = sma.flattenedJunctionTransitionMap + (exprNode -> transition)
Right(sma.copy(flattenedJunctionTransitionMap = fjtm))
val fjtm = sma.flattenedChoiceTransitionMap + (exprNode -> transition)
Right(sma.copy(flattenedChoiceTransitionMap = fjtm))
}
}

View File

@ -35,7 +35,7 @@ object ComputeFlattenedStateTransitionMap
val transition = sts.transitionOrDo match {
case Ast.TransitionOrDo.Transition(transition) =>
val actions = transition.data.actions.map(sma.getActionSymbol)
val target = sma.getStateOrJunction(transition.data.target)
val target = sma.getStateOrChoice(transition.data.target)
Transition.External(actions, target)
case Ast.TransitionOrDo.Do(actions) =>
Transition.Internal(actions.map(sma.getActionSymbol))
@ -49,7 +49,7 @@ object ComputeFlattenedStateTransitionMap
val fstm = stm.foldLeft (sma.flattenedStateTransitionMap) {
case (fstm, (s, gt)) => {
val state = StateMachineSymbol.State(aNode)
val soj = StateOrJunction.State(state)
val soj = StateOrChoice.State(state)
val cft = ConstructFlattenedTransition(sma, soj)
val transition = cft.transition(gt.transition)
val gt1 = Transition.Guarded(gt.guardOpt, transition)

View File

@ -6,7 +6,7 @@ import fpp.compiler.util._
/** Construct a flattened transition */
case class ConstructFlattenedTransition(
sma: StateMachineAnalysis,
source: StateOrJunction
source: StateOrChoice
) {
/** The interface method */
@ -33,17 +33,17 @@ case class ConstructFlattenedTransition(
}
// Get the parent state list of a source state or junction
private def getSourceParentStateList(soj: StateOrJunction):
private def getSourceParentStateList(soj: StateOrChoice):
List[StateMachineSymbol.State] = {
val start = soj match {
case StateOrJunction.State(state) => List(state)
case StateOrJunction.Junction(_) => Nil
case StateOrChoice.State(state) => List(state)
case StateOrChoice.Choice(_) => Nil
}
sma.getParentStateList(soj.getSymbol, start)
}
// Get the parent state list of a target state or junction
private def getTargetParentStateList(soj: StateOrJunction):
private def getTargetParentStateList(soj: StateOrChoice):
List[StateMachineSymbol.State] = sma.getParentStateList(soj.getSymbol)
// Delete the longest common prefix of two lists

View File

@ -19,10 +19,10 @@ object EnterStateMachineSymbols
aNode: Ast.Annotated[AstNode[Ast.DefGuard]]
) = visitNode(sma, aNode, StateMachineSymbol.Guard(_), List(StateMachineNameGroup.Guard))
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
sma: StateMachineAnalysis,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
) = visitNode(sma, aNode, StateMachineSymbol.Junction(_), List(StateMachineNameGroup.State))
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = visitNode(sma, aNode, StateMachineSymbol.Choice(_), List(StateMachineNameGroup.State))
override def defSignalAnnotatedNode(
sma: StateMachineAnalysis,

View File

@ -32,7 +32,7 @@ case class StateMachineAnalysis(
/** The flattened state transtiion map */
flattenedStateTransitionMap: StateMachineAnalysis.SignalStateTransitionMap = Map(),
/** The flattened junction transtiion map */
flattenedJunctionTransitionMap: StateMachineAnalysis.TransitionExprMap = Map()
flattenedChoiceTransitionMap: StateMachineAnalysis.TransitionExprMap = Map()
) {
/** Gets the list of parent states, highest first */
@ -55,8 +55,8 @@ case class StateMachineAnalysis(
val getQualifiedName = Analysis.getQualifiedNameFromMap (parentStateMap)
/** Gets the common type of two typed elements at a junction */
def commonTypeAtJunction(
te: StateMachineTypedElement.Junction,
def commonTypeAtChoice(
te: StateMachineTypedElement.Choice,
te1: StateMachineTypedElement,
to1: Option[Type],
te2: StateMachineTypedElement
@ -65,7 +65,7 @@ case class StateMachineAnalysis(
TypeOption.commonType(to1, to2) match {
case Some(to) => Right(to)
case None => Left(
SemanticError.StateMachine.JunctionTypeMismatch(
SemanticError.StateMachine.ChoiceTypeMismatch(
Locations.get(te.getNodeId),
Locations.get(te1.getNodeId),
TypeOption.show(to1),
@ -129,11 +129,11 @@ case class StateMachineAnalysis(
}
// Get a state or junction from a qualified identifier node
def getStateOrJunction(soj: AstNode[Ast.QualIdent]):
StateOrJunction =
def getStateOrChoice(soj: AstNode[Ast.QualIdent]):
StateOrChoice =
useDefMap(soj.id) match {
case state: StateMachineSymbol.State => StateOrJunction.State(state)
case junction: StateMachineSymbol.Junction => StateOrJunction.Junction(junction)
case state: StateMachineSymbol.State => StateOrChoice.State(state)
case junction: StateMachineSymbol.Choice => StateOrChoice.Choice(junction)
case _ => throw new InternalError("expected state or junction")
}

View File

@ -18,7 +18,7 @@ object StateMachineSymbol {
override def getUnqualifiedName = node._2.data.name
}
final case class Junction(node: Ast.Annotated[AstNode[Ast.DefJunction]]) extends StateMachineSymbol {
final case class Choice(node: Ast.Annotated[AstNode[Ast.DefChoice]]) extends StateMachineSymbol {
override def getNodeId = node._2.id
override def getUnqualifiedName = node._2.data.name
}

View File

@ -39,8 +39,8 @@ object StateMachineTypedElement {
def showKind = "state transition"
}
final case class Junction(
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
final case class Choice(
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) extends StateMachineTypedElement {
def getNodeId = aNode._2.id
def showKind = "junction"

View File

@ -4,21 +4,21 @@ import fpp.compiler.ast._
import fpp.compiler.util._
/** An FPP state or junction */
sealed trait StateOrJunction {
sealed trait StateOrChoice {
def getSymbol: StateMachineSymbol
def getName: String
}
object StateOrJunction {
object StateOrChoice {
final case class State(symbol: StateMachineSymbol.State)
extends StateOrJunction {
extends StateOrChoice {
def getSymbol = symbol
def getName = s"state ${symbol.getUnqualifiedName}"
}
final case class Junction(symbol: StateMachineSymbol.Junction)
extends StateOrJunction {
final case class Choice(symbol: StateMachineSymbol.Choice)
extends StateOrChoice {
def getSymbol = symbol
def getName = s"junction ${symbol.getUnqualifiedName}"
}

View File

@ -6,7 +6,7 @@ import fpp.compiler.util._
/** An FPP state machine transition */
sealed trait Transition {
def getActions: List[StateMachineSymbol.Action]
def getTargetOpt: Option[StateOrJunction]
def getTargetOpt: Option[StateOrChoice]
}
object Transition {
@ -14,7 +14,7 @@ object Transition {
/** An external transition */
final case class External(
actions: List[StateMachineSymbol.Action],
target: StateOrJunction
target: StateOrChoice
) extends Transition {
def getActions = actions
def getTargetOpt = Some(target)

View File

@ -47,7 +47,7 @@ object TransitionGraph {
type ArcMap = Map[Node, Set[Arc]]
case class Node(soj: StateOrJunction)
case class Node(soj: StateOrChoice)
sealed trait Arc {
def getStartNode: Node
@ -62,7 +62,7 @@ object TransitionGraph {
aNode: Ast.Annotated[AstNode[Ast.SpecInitialTransition]],
endNode: Node
) extends Arc {
def getStartNode = Node(StateOrJunction.State(startState))
def getStartNode = Node(StateOrChoice.State(startState))
def getEndNode = endNode
def getTypedElement = StateMachineTypedElement.InitialTransition(aNode)
def showKind = "initial transition"
@ -77,7 +77,7 @@ object TransitionGraph {
aNode: Ast.Annotated[AstNode[Ast.SpecStateTransition]],
endNode: Node
) extends Arc {
def getStartNode = Node(StateOrJunction.State(startState))
def getStartNode = Node(StateOrChoice.State(startState))
def getEndNode = endNode
def getTypedElement = StateMachineTypedElement.StateTransition(aNode)
def showKind = "state transition"
@ -87,14 +87,14 @@ object TransitionGraph {
s"$showKind at ${loc.file}:${loc.pos} to $endName"
}
}
case class Junction(
startJunction: StateMachineSymbol.Junction,
case class Choice(
startChoice: StateMachineSymbol.Choice,
aNode: AstNode[Ast.TransitionExpr],
endNode: Node
) extends Arc {
def getStartNode = Node(StateOrJunction.Junction(startJunction))
def getStartNode = Node(StateOrChoice.Choice(startChoice))
def getEndNode = endNode
def getTypedElement = StateMachineTypedElement.Junction(startJunction.node)
def getTypedElement = StateMachineTypedElement.Choice(startChoice.node)
def showKind = "junction transition"
def showTransition = {
val loc = Locations.get(aNode.id)

View File

@ -164,7 +164,7 @@ object Ast {
sealed trait Node
final case class DefAction(node: AstNode[Ast.DefAction]) extends Node
final case class DefGuard(node: AstNode[Ast.DefGuard]) extends Node
final case class DefJunction(node: AstNode[Ast.DefJunction]) extends Node
final case class DefChoice(node: AstNode[Ast.DefChoice]) extends Node
final case class DefSignal(node: AstNode[Ast.DefSignal]) extends Node
final case class DefState(node: AstNode[Ast.DefState]) extends Node
final case class SpecInitialTransition(node: AstNode[Ast.SpecInitialTransition]) extends Node
@ -182,8 +182,8 @@ object Ast {
typeName: Option[AstNode[TypeName]]
)
/** Junction definition */
final case class DefJunction(
/** Choice definition */
final case class DefChoice(
name: Ident,
guard: AstNode[Ident],
ifTransition: AstNode[TransitionExpr],
@ -212,7 +212,7 @@ object Ast {
final case class StateMember(node: Annotated[StateMember.Node])
object StateMember {
sealed trait Node
final case class DefJunction(node: AstNode[Ast.DefJunction]) extends Node
final case class DefChoice(node: AstNode[Ast.DefChoice]) extends Node
final case class DefState(node: AstNode[Ast.DefState]) extends Node
final case class SpecInitialTransition(node: AstNode[Ast.SpecInitialTransition]) extends Node
final case class SpecStateEntry(node: AstNode[Ast.SpecStateEntry]) extends Node

View File

@ -25,7 +25,7 @@ trait AstVisitor {
def defGuardAnnotatedNode(in: In, node: Ast.Annotated[AstNode[Ast.DefGuard]]): Out = default(in)
def defJunctionAnnotatedNode(in: In, node: Ast.Annotated[AstNode[Ast.DefJunction]]): Out = default(in)
def defChoiceAnnotatedNode(in: In, node: Ast.Annotated[AstNode[Ast.DefChoice]]): Out = default(in)
def defModuleAnnotatedNode(in: In, node: Ast.Annotated[AstNode[Ast.DefModule]]): Out = default(in)
@ -192,7 +192,7 @@ trait AstVisitor {
node match {
case Ast.StateMachineMember.DefAction(node1) => defActionAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.DefGuard(node1) => defGuardAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.DefJunction(node1) => defJunctionAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.DefChoice(node1) => defChoiceAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.DefSignal(node1) => defSignalAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.DefState(node1) => defStateAnnotatedNode(in, (pre, node1, post))
case Ast.StateMachineMember.SpecInitialTransition(node1) => specInitialTransitionAnnotatedNode(in, (pre, node1, post))
@ -202,7 +202,7 @@ trait AstVisitor {
final def matchStateMember(in: In, member: Ast.StateMember): Out = {
val (pre, node, post) = member.node
node match {
case Ast.StateMember.DefJunction(node1) => defJunctionAnnotatedNode(in, (pre, node1, post))
case Ast.StateMember.DefChoice(node1) => defChoiceAnnotatedNode(in, (pre, node1, post))
case Ast.StateMember.DefState(node1) => defStateAnnotatedNode(in, (pre, node1, post))
case Ast.StateMember.SpecInitialTransition(node1) => specInitialTransitionAnnotatedNode(in, (pre, node1, post))
case Ast.StateMember.SpecStateEntry(node1) => specStateEntryAnnotatedNode(in, (pre, node1, post))

View File

@ -122,9 +122,9 @@ object AstWriter extends AstVisitor with LineUtils {
).map(indentIn)
}
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
in: In,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val (_, node, _) = aNode
val data = node.data

View File

@ -149,8 +149,8 @@ abstract class StateMachineCppWriterUtils(
{
val functionName = getEnterFunctionName(sym)
val typeOpt = sym match {
case StateMachineSymbol.Junction(aNode) =>
val te = StateMachineTypedElement.Junction(aNode)
case StateMachineSymbol.Choice(aNode) =>
val te = StateMachineTypedElement.Choice(aNode)
sma.typeOptionMap(te)
case _ => None
}

View File

@ -11,20 +11,20 @@ case class StateMachineEntryFns(
def write = defStateMachineAnnotatedNode(Nil, aNode)
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
mm: List[CppDoc.Class.Member],
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val data = aNode._2.data
val junctionSym = StateMachineSymbol.Junction(aNode)
val junctionSym = StateMachineSymbol.Choice(aNode)
val junctionName = writeSmSymbolName(junctionSym)
val te = StateMachineTypedElement.Junction(aNode)
val te = StateMachineTypedElement.Choice(aNode)
val typeOpt = sma.typeOptionMap(te)
val valueArgOpt = typeOpt.map(_ => valueParamName)
val guardSym = sma.getGuardSymbol(data.guard)
val writeJunctionTransition = writeTransition (signalParamName) (valueArgOpt)
val ifTransition = sma.flattenedJunctionTransitionMap(data.ifTransition)
val elseTransition = sma.flattenedJunctionTransitionMap(data.elseTransition)
val writeChoiceTransition = writeTransition (signalParamName) (valueArgOpt)
val ifTransition = sma.flattenedChoiceTransitionMap(data.ifTransition)
val elseTransition = sma.flattenedChoiceTransitionMap(data.elseTransition)
val member = functionClassMember(
Some(s"Enter choice $junctionName"),
getEnterFunctionName(junctionSym),
@ -32,8 +32,8 @@ case class StateMachineEntryFns(
CppDoc.Type("void"),
wrapInIfElse(
writeGuardCall (signalParamName) (valueArgOpt) (guardSym),
writeJunctionTransition (ifTransition),
writeJunctionTransition (elseTransition)
writeChoiceTransition (ifTransition),
writeChoiceTransition (elseTransition)
)
)
member :: mm

View File

@ -202,9 +202,9 @@ object FppWriter extends AstVisitor with LineUtils {
joinOpt (data.typeName) (": ") (typeNameNode)
}
override def defJunctionAnnotatedNode(
override def defChoiceAnnotatedNode(
in: In,
aNode: Ast.Annotated[AstNode[Ast.DefJunction]]
aNode: Ast.Annotated[AstNode[Ast.DefChoice]]
) = {
val (_, node, _) = aNode
val data = node.data

View File

@ -147,11 +147,11 @@ object Parser extends Parsers {
}
}
def defJunction: Parser[Ast.DefJunction] = {
def defChoice: Parser[Ast.DefChoice] = {
(choice ~> ident) ~! (lbrace ~> ifToken ~> node(ident)) ~! node(transitionExpr) ~!
(elseToken ~> node(transitionExpr)) <~! rbrace ^^ {
case ident ~ guard ~ ifTransition ~ elseTransition =>
Ast.DefJunction(ident, guard, ifTransition, elseTransition)
Ast.DefChoice(ident, guard, ifTransition, elseTransition)
}
}
@ -697,7 +697,7 @@ object Parser extends Parsers {
node(defSignal) ^^ { case n => Ast.StateMachineMember.DefSignal(n) } |
node(defAction) ^^ { case n => Ast.StateMachineMember.DefAction(n) } |
node(defGuard) ^^ { case n => Ast.StateMachineMember.DefGuard(n) } |
node(defJunction) ^^ { case n => Ast.StateMachineMember.DefJunction(n) } |
node(defChoice) ^^ { case n => Ast.StateMachineMember.DefChoice(n) } |
failure("state machine member expected")
}
@ -705,7 +705,7 @@ object Parser extends Parsers {
annotatedElementSequence(stateMachineMemberNode, semi, Ast.StateMachineMember(_))
def stateMemberNode: Parser[Ast.StateMember.Node] = {
node(defJunction) ^^ { case n => Ast.StateMember.DefJunction(n) } |
node(defChoice) ^^ { case n => Ast.StateMember.DefChoice(n) } |
node(defState) ^^ { case n => Ast.StateMember.DefState(n) } |
node(specStateEntry) ^^ { case n => Ast.StateMember.SpecStateEntry(n) } |
node(specStateExit) ^^ { case n => Ast.StateMember.SpecStateExit(n) } |

View File

@ -264,9 +264,9 @@ sealed trait Error {
System.err.println("target is defined here:")
System.err.println(loc)
})
case SemanticError.StateMachine.JunctionCycle(loc, msg) =>
case SemanticError.StateMachine.ChoiceCycle(loc, msg) =>
Error.print (Some(loc)) (msg)
case SemanticError.StateMachine.JunctionTypeMismatch(
case SemanticError.StateMachine.ChoiceTypeMismatch(
loc, toLoc1, to1, toLoc2, to2
) =>
Error.print (Some(loc)) (s"type mismatch at junction")
@ -611,13 +611,13 @@ object SemanticError {
msg: String,
destLoc: Option[Location] = None
) extends Error
/** Junction cycle */
final case class JunctionCycle(
/** Choice cycle */
final case class ChoiceCycle(
loc: Location,
msg: String
) extends Error
/** Junction type mismatch */
final case class JunctionTypeMismatch(
/** Choice type mismatch */
final case class ChoiceTypeMismatch(
loc: Location,
toLoc1: Location,
to1: String,