|
@@ -41,7 +41,10 @@ class FlowOptimizer {
|
|
|
|
|
|
// first replace all 'if true' steps by then step.
|
|
|
flow.replaceTrueIfs
|
|
|
-
|
|
|
+
|
|
|
+ // we don't need empty functions
|
|
|
+ flow.eliminateEmptySequences
|
|
|
+
|
|
|
// perform inlining
|
|
|
if (_inlineReactions) {
|
|
|
flow.inlineReactionChecks
|
|
@@ -69,11 +72,29 @@ class FlowOptimizer {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // REPLACE TRUE IF STEPS
|
|
|
+ /** Replaces all true if steps by then step. */
|
|
|
def replaceTrueIfs(ExecutionFlow flow) {
|
|
|
flow.eAllContents.filter(typeof(If)).filter( i | i.check.alwaysTrue ).forEach( i | i.substituteBy(i.thenStep) );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /** Determines and removes all empty sequences that are not part of a parent step from the model */
|
|
|
+ def eliminateEmptySequences(ExecutionFlow flow) {
|
|
|
+ var allReactSequences = flow.states.map( state | state.reactSequence )
|
|
|
+ var emptySeqences = flow.eAllContents.filter(typeof(Sequence)).filter( s | s.empty ).toList
|
|
|
+ emptySeqences.removeAll(allReactSequences)
|
|
|
+
|
|
|
+ emptySeqences.forEach( s | {
|
|
|
+ val callList = s.caller.toList.clone
|
|
|
+ callList.forEach( c | { c.eContainer.substituteCall(c, null)
|
|
|
+
|
|
|
+ callList.forEach[ call | call.step = null]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def substituteBy(Step orig, Step substitute) {
|
|
|
orig.eContainer.substitute(orig, substitute)
|
|
|
}
|
|
@@ -210,7 +231,10 @@ class FlowOptimizer {
|
|
|
|
|
|
def dispatch boolean substituteCall(Sequence owner, Call call, Step step) {
|
|
|
if ( owner.steps.contains(call) ) {
|
|
|
- owner.steps.set(owner.steps.indexOf(call), step)
|
|
|
+ if ( step != null )
|
|
|
+ owner.steps.set(owner.steps.indexOf(call), step)
|
|
|
+ else
|
|
|
+ owner.steps.remove(owner.steps.indexOf(call))
|
|
|
return true
|
|
|
}
|
|
|
|