Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions mdl/executor/cmd_microflows_builder_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
// Destination: prefer the first statement's own @anchor(to: ...) if it
// has one; otherwise fall back to trueBranchAnchor.To.
flow := newHorizontalFlowWithCase(splitID, actID, "true")
applyUserAnchors(flow, trueBranchAnchor, trueBranchAnchor)
if thisAnchor != nil && thisAnchor.To != ast.AnchorSideUnset {
flow.DestinationConnectionIndex = int(thisAnchor.To)
}
applyUserAnchors(flow, trueBranchAnchor, branchDestinationAnchor(trueBranchAnchor, thisAnchor))
fb.flows = append(fb.flows, flow)
} else {
flow := newHorizontalFlow(lastThenID, actID)
Expand Down Expand Up @@ -178,10 +175,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
// First statement in ELSE - connect from split going down (false path).
// Same compositional rule as the THEN branch.
flow := newDownwardFlowWithCase(splitID, actID, "false")
applyUserAnchors(flow, falseBranchAnchor, falseBranchAnchor)
if thisAnchor != nil && thisAnchor.To != ast.AnchorSideUnset {
flow.DestinationConnectionIndex = int(thisAnchor.To)
}
applyUserAnchors(flow, falseBranchAnchor, branchDestinationAnchor(falseBranchAnchor, thisAnchor))
fb.flows = append(fb.flows, flow)
} else {
flow := newHorizontalFlow(lastElseID, actID)
Expand Down Expand Up @@ -237,10 +231,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
if lastThenID == "" {
// First statement in THEN - connect from split going down with "true" case
flow := newDownwardFlowWithCase(splitID, actID, "true")
applyUserAnchors(flow, trueBranchAnchor, trueBranchAnchor)
if thisAnchor != nil && thisAnchor.To != ast.AnchorSideUnset {
flow.DestinationConnectionIndex = int(thisAnchor.To)
}
applyUserAnchors(flow, trueBranchAnchor, branchDestinationAnchor(trueBranchAnchor, thisAnchor))
fb.flows = append(fb.flows, flow)
} else {
flow := newHorizontalFlow(lastThenID, actID)
Expand Down
14 changes: 14 additions & 0 deletions mdl/executor/cmd_microflows_builder_flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ func applyUserAnchors(flow *microflows.SequenceFlow, origin *ast.FlowAnchors, de
}
}

func branchDestinationAnchor(branchAnchor, stmtAnchor *ast.FlowAnchors) *ast.FlowAnchors {
if stmtAnchor != nil && stmtAnchor.To != ast.AnchorSideUnset {
return stmtAnchor
}
return branchAnchor
}

func pendingFlowAnchors(previousAnchor, pendingAnchor, stmtAnchor *ast.FlowAnchors) (*ast.FlowAnchors, *ast.FlowAnchors) {
if pendingAnchor == nil {
return previousAnchor, stmtAnchor
}
return pendingAnchor, branchDestinationAnchor(pendingAnchor, stmtAnchor)
}

// lastStmtIsReturn reports whether execution of a body is guaranteed to terminate
// (via RETURN or RAISE ERROR) on every path — i.e. control can never fall off the
// end of the body into the parent flow.
Expand Down
11 changes: 2 additions & 9 deletions mdl/executor/cmd_microflows_builder_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,8 @@ func (fb *flowBuilder) buildFlowGraph(stmts []ast.MicroflowStatement, returns *a
// both From (origin side on the split) and To (the side of the
// continuing activity), unless the incoming statement explicitly
// overrides its own To.
originAnchor := fb.previousStmtAnchor
destAnchor := stmtAnchor
if pendingFlowAnchor != nil {
originAnchor = pendingFlowAnchor
if destAnchor == nil || destAnchor.To == ast.AnchorSideUnset {
destAnchor = pendingFlowAnchor
}
pendingFlowAnchor = nil
}
originAnchor, destAnchor := pendingFlowAnchors(fb.previousStmtAnchor, pendingFlowAnchor, stmtAnchor)
pendingFlowAnchor = nil
applyUserAnchors(flow, originAnchor, destAnchor)
fb.flows = append(fb.flows, flow)
fb.previousStmtAnchor = stmtAnchor
Expand Down