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
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')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend11
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend10
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend58
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java2
6 files changed, 54 insertions, 33 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
index 6ff717e2d..2791ee88a 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
@@ -19,6 +19,7 @@ import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
@@ -158,16 +159,16 @@ class ActorClassGen extends GenericActorClassGenerator {
virtual void destroy();
«IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachineConstants»
+ «xpac.graphContainer.genStateMachineConstants»
- «xpac.genStateMachineMethods(false)»
+ «xpac.graphContainer.genStateMachineMethods(false)»
«IF ac.commType == ComponentCommunicationType::DATA_DRIVEN»
void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data);
«ENDIF»
«IF ac.commType == ComponentCommunicationType::ASYNCHRONOUS || ac.commType == ComponentCommunicationType::DATA_DRIVEN»
virtual void receive(const etRuntime::Message* msg);
«ENDIF»
- «ELSEIF xpac.stateMachine.empty»
+ «ELSEIF FsmGenExtensions.isEmpty(xpac.graphContainer.graph)»
««« no state machine in the super classes
//--------------------- no state machine
virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
@@ -347,7 +348,7 @@ class ActorClassGen extends GenericActorClassGenerator {
«operationsImplementation(ac.operations, ac.name)»
«IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachineMethods(true)»
+ «xpac.graphContainer.genStateMachineMethods(true)»
«IF ac.commType == ComponentCommunicationType::DATA_DRIVEN»
void «ac.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) {
handleSystemEvent(ifitem, evt, generic_data);
@@ -362,7 +363,7 @@ class ActorClassGen extends GenericActorClassGenerator {
«ENDIF»
}
«ENDIF»
- «ELSEIF xpac.stateMachine.empty»
+ «ELSEIF FsmGenExtensions.isEmpty(xpac.graphContainer.graph)»
««« no state machine in the super classes
//--------------------- no state machine
void «ac.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data) {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
index c788cd293..45ffd82ba 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
@@ -24,7 +24,7 @@ import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.etphys.eTPhys.NodeRef
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.IDiagnostician
+import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.DataType
import org.eclipse.etrice.core.room.EnumLiteral
@@ -50,7 +50,7 @@ class CppExtensions implements ILanguageExtension {
@Inject extension RoomExtensions
override String getTypedDataDefinition(EObject msg) {
- generateArglistAndTypedData((msg as Message).data).get(1)
+ generateArglistAndTypedData((msg as Message).data).get(TypedDataKind.DECLARATION_AND_INITIALIZATION.ordinal)
}
def String getCppHeaderFileName(RoomClass rc) { rc.name + ".h" }
@@ -219,9 +219,9 @@ class CppExtensions implements ILanguageExtension {
}
var deRef = if(!data.refType.ref) '*' else ''
- val typedData = '''«typeExpr» «data.name» = «deRef»(static_cast<«castExpr»>(generic_data__et));''' + NEWLINE
- val dataArg = ''', «data.name»'''
- val typedArgList = ''', «typeExpr» «data.name»'''
+ val dataArg = ''', «GENERIC_DATA_NAME»'''
+ val typedData = '''«typeExpr» «GENERIC_DATA_NAME» = «deRef»(static_cast<«castExpr»>(generic_data__et));''' + NEWLINE
+ val typedArgList = ''', «typeExpr» «GENERIC_DATA_NAME»'''
return #[dataArg, typedData, typedArgList]
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
index 105f639fc..c629ccef3 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
@@ -16,13 +16,13 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.List
import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger
+import org.eclipse.etrice.core.genmodel.fsm.ILogger
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.ComplexType
import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.core.room.util.RoomHelpers
@Singleton
class DataClassGen {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
index 38f0da881..16f5e98f1 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
@@ -16,7 +16,7 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.List
import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger
+import org.eclipse.etrice.core.genmodel.fsm.ILogger
import org.eclipse.etrice.core.room.CommunicationType
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.Message
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)
+ }
+ }
+
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
index e813049dd..3d065a596 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
@@ -13,7 +13,7 @@
package org.eclipse.etrice.generator.cpp.gen;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger;
+import org.eclipse.etrice.core.genmodel.fsm.ILogger;
import com.google.inject.Inject;

Back to the top