Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2017-11-06 10:37:41 +0000
committerHenrik Rentz-Reichert2017-11-07 06:58:06 +0000
commit48d51b2b32f759e255f0cca154d2757c95d15e19 (patch)
treef1455e17e092e88c01feac4b6cf7f5ec2d2896ff /plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
parentb09856b29bfcaea08e9e57b14da3744c0a201867 (diff)
downloadorg.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.gz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.xz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.zip
Bug 511330 - [core.genmodel.fsm] introduce simplified generator model
for state machines * manually merged newfsmgen to newfsmgen_finalize because no rebase was possible due to structural changes * rebased on master * switch to Oxygen and Xtend 2.12 Change-Id: If9a8c7421f07fb8e8fa824b7bc6761b9142b7eaf
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend58
1 files changed, 39 insertions, 19 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
index 514cd75db..5af70d5a6 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
@@ -13,29 +13,26 @@
package org.eclipse.etrice.generator.cpp.gen
-import com.google.inject.Inject
import com.google.inject.Singleton
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.ExpandedModelComponent
+import java.util.Comparator
+import org.eclipse.etrice.core.fsm.fSM.State
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
-import org.eclipse.etrice.generator.generic.RoomExtensions
+
+import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*
@Singleton
class StateMachineGen extends GenericStateMachineGenerator {
- @Inject extension RoomExtensions
-
- override genExtra(ExpandedModelComponent xpac, boolean generateImplementation) {
- val states = newArrayList
- var ac = xpac.modelComponent
- val clsName = xpac.modelComponent.componentName
+ val nodeComparator = new NodeComparator
+
+ override genExtra(GraphContainer gc, boolean generateImplementation) {
+ var ac = gc.component
+ val clsName = ac.componentName
+ val orderedStateNodes = gc.graph.allStateNodes.toList.sortWith(nodeComparator)
-// it is crucial that we obey the order that is used for state IDs
-// that means we have to collect base classes first and each base class list with leaf states last
- while (ac!=null) {
- states.addAll(0, ac.allBaseStates.leafStatesLast)
- ac = ac.base
- }
if(generateImplementation)
'''
«IF Main::settings.generateMSCInstrumentation || Main::settings.generateWithVerboseOutput»
@@ -43,12 +40,12 @@ class StateMachineGen extends GenericStateMachineGenerator {
const String «clsName»::s_stateStrings[] = {
"<no state>",
"<top>",
- «FOR state : states SEPARATOR ","»
- "«state.genStatePathName»"
+ «FOR state : orderedStateNodes SEPARATOR ","»
+ "«(state.stateGraphNode as State).genStatePathName»"
«ENDFOR»
};
«ENDIF»
- const int «clsName»::s_numberOfStates = «2+states.size»;
+ const int «clsName»::s_numberOfStates = «2+orderedStateNodes.size»;
void «clsName»::setState(int new_state) {
«IF Main::settings.generateMSCInstrumentation»
@@ -69,7 +66,7 @@ class StateMachineGen extends GenericStateMachineGenerator {
«ENDIF»
static const int s_numberOfStates;
- int history[«2+states.size»];
+ int history[«2+orderedStateNodes.size»];
void setState(int new_state);
'''
@@ -83,4 +80,27 @@ class StateMachineGen extends GenericStateMachineGenerator {
"etBool"
}
+ private static class NodeComparator implements Comparator<Node> {
+
+ // it is crucial that we obey the order that is used for state IDs
+ // that means we have to collect base classes first and each base class list with leaf states last
+ override int compare(Node o1, Node o2) {
+ if (o1.inheritanceLevel==o2.inheritanceLevel) {
+ if (o1.isLeaf && o2.isLeaf) {
+ return 0
+ }
+ if (o1.isLeaf) {
+ return 1
+ }
+ if (o2.isLeaf) {
+ return -1
+ }
+ return 0
+ }
+ else {
+ return Integer.compare(o1.inheritanceLevel, o1.inheritanceLevel)
+ }
+ }
+
+ }
}

Back to the top