summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Karlitschek2012-10-24 06:39:07 (EDT)
committer Peter Karlitschek2012-12-05 04:10:53 (EST)
commit3eb18cbda66432fa65ce7d6b82f75ce96c8e86b7 (patch)
tree241e8d161a3f550836d1aa4859b5ac3a6489cab0
parent01772687c54228db7fa1cbd631dd85539a9761a2 (diff)
downloadorg.eclipse.etrice-3eb18cbda66432fa65ce7d6b82f75ce96c8e86b7.zip
org.eclipse.etrice-3eb18cbda66432fa65ce7d6b82f75ce96c8e86b7.tar.gz
org.eclipse.etrice-3eb18cbda66432fa65ce7d6b82f75ce96c8e86b7.tar.bz2
-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/ConfigGenAddon.xtend121
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend177
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java31
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend27
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend55
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend108
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend63
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java8
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java314
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java6
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend146
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java630
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp15
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp2
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.cpp6
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.h1
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp44
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.h18
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etDatatypes.h2
22 files changed, 1336 insertions, 453 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 94a3621..e0375c5 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
@@ -13,6 +13,8 @@ import org.eclipse.etrice.generator.base.AbstractGenerator
import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.cpp.gen.Initialization
+import org.eclipse.etrice.generator.cpp.gen.StateMachineGen
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
@@ -23,7 +25,7 @@ class ActorClassGen extends GenericActorClassGenerator {
@Inject JavaIoFileSystemAccess fileAccess
@Inject extension CppExtensions
@Inject extension RoomExtensions
-
+ @Inject extension Initialization
@Inject extension ProcedureHelpers
@Inject extension StateMachineGen
@Inject ILogger logger
@@ -126,10 +128,7 @@ class ActorClassGen extends GenericActorClassGenerator {
«ENDIF»
virtual void destroy();
«IF ac.hasNonEmptyStateMachine»
-««« «xpac.genStateMachine()»
- //--------------------- dummy instead of state machine gen
- virtual void receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* data){};
- virtual void executeInitTransition(){};
+ «xpac.genStateMachineMethodDeclarations()»
«ELSEIF !xpac.hasStateMachine()»
public:
//--------------------- no state machine
@@ -230,7 +229,7 @@ class ActorClassGen extends GenericActorClassGenerator {
}
«IF ac.hasNonEmptyStateMachine»
-««« «xpac.genStateMachine()»
+ «xpac.genStateMachine(false)»
«ELSEIF !xpac.hasStateMachine()»
//--------------------- no state machine
void «ac.name»::receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* data) {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend
new file mode 100644
index 0000000..c3f1c64
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import java.util.List
+import org.eclipse.etrice.core.config.AttrInstanceConfig
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.generator.generic.ConfigExtension
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+
+class ConfigGenAddon {
+
+ @Inject extension CppExtensions stdExt
+ @Inject extension TypeHelpers typeHelpers
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension ConfigExtension configExt
+
+ // For SubSystemClassGen
+
+ def public applyInstanceConfig(String instance, String className, List<AttrInstanceConfig> attrConfigs){'''
+ «FOR attrConfig : attrConfigs»
+ «var a = attrConfig.attribute»
+ «var aType = a.refType.type»
+ «IF aType.primitive»
+ «var values = attrConfig.value?.values»
+ «IF values == null»
+ «ELSEIF a.size == 0 || aType.characterType»
+ «instance».«a.name.invokeSetter(className, (aType as PrimitiveType).toValueLiteral(values.get(0)))»;
+ «ELSEIF a.size == values.size»
+ «instance».«a.name.invokeSetter(className, "new "+aType.typeName+"[]"+(aType as PrimitiveType).toArrayValueLiteral(values))»;
+ «ELSE»
+ {
+ «aType.typeName»[] array = «instance».«a.name.invokeGetter(className)»;
+ for (int i=0;i<«a.size»;i++){
+ array[i] = «(aType as PrimitiveType).toValueLiteral(values.get(0))»;
+ }
+ }
+ «ENDIF»
+ «ELSEIF aType.dataClass»
+ «(instance+"."+a.name.invokeGetter(className)).applyInstanceConfig(aType.typeName, attrConfig.attributes)»
+ «ENDIF»
+ «ENDFOR»
+ '''}
+
+ // For ActorClassGen
+
+ def public genDynConfigGetterSetter(ActorClass ac){'''
+ «FOR a : ac.getDynConfigAttributes(true, false)»
+ public «a.refType.type.typeName»«IF a.size>0»[]«ENDIF» get«a.name.toFirstUpper»(){
+ if(lock_«a.name» == null)
+ return «a.name»;
+ else
+ synchronized(lock_«a.name»){
+ return «a.name»;
+ }
+ }
+ public void set«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){
+ if(lock_«a.name» == null)
+ this.«a.name» = «a.name»;
+ else
+ synchronized(lock_«a.name»){
+ this.«a.name» = «a.name»;
+ }
+ }
+ public DynConfigLock get«a.name.toFirstUpper»Lock(){
+ return lock_«a.name»;
+ }
+ «ENDFOR»
+ «FOR a : ac.getDynConfigAttributes(false, true)»
+ public void setAndWrite«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){
+ set«a.name.toFirstUpper»(«a.name»);
+ variableService.write(this.getInstancePath()+"/«a.name»", «a.name»);
+ }
+ «ENDFOR»
+ '''}
+
+ def public genMinMaxConstants(ActorClass ac){
+ var attrConfigs = ac.allAttrConfigFlat.filter(c | c.min != null || c.max != null)
+ '''
+ «IF !attrConfigs.empty»
+ //--------------------- attribute specifications
+ «ENDIF»
+
+ «FOR c : attrConfigs»
+ «var aType = (c.attribute.refType.type as PrimitiveType)»
+ «IF c.min != null»
+ public static «aType.minMaxType» MIN«c.getPath(false, false, true, true).toPath("_")» = «aType.toValueLiteral(c.min.value)»;
+ «ENDIF»
+ «IF c.max != null»
+ public static «aType.minMaxType» MAX«c.getPath(false, false, true, true).toPath("_")» = «aType.toValueLiteral(c.max.value)»;
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+ def private getMinMaxType(PrimitiveType type){
+ switch(type.typeName){
+ case "byte":
+ return "int"
+ case "short":
+ return "int"
+ case "float":
+ return "double"
+ }
+ return type.typeName
+ }
+} \ No newline at end of file
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 08395be..947ad0b 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
@@ -15,33 +15,35 @@
*/
-package org.eclipse.etrice.generator.cpp.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.RoomClass
-import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.generator.generic.ILanguageExtension
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
import java.util.List
-import org.eclipse.xtext.util.Pair
-import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician
+import org.eclipse.etrice.core.room.DataType
+import org.eclipse.etrice.core.room.ExternalType
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.core.room.VarDecl
+import org.eclipse.etrice.core.room.DataClass
import org.eclipse.etrice.generator.generic.ConfigExtension
+import org.eclipse.etrice.generator.generic.ILanguageExtension
import org.eclipse.etrice.generator.generic.TypeHelpers
-import org.eclipse.etrice.core.room.ComplexType
-
+import org.eclipse.xtext.util.Pair
@Singleton
class CppExtensions implements ILanguageExtension {
- @Inject AbstractTransitionChainGenerator chainGenerator
@Inject ILanguageExtension languageExt
+ @Inject IDiagnostician diagnostician
@Inject extension ConfigExtension
@Inject extension TypeHelpers
override String getTypedDataDefinition(Message m) {
- return chainGenerator.generateTypedData(m.data)
+ generateArglistAndTypedData(m.data).get(1)
}
@@ -133,39 +135,118 @@ class CppExtensions implements ILanguageExtension {
}
- def attributeConstructorInitList(List<Attribute> attribs, boolean useClassDefaultsOnly) {
- '''
- // initialize attributes
- «FOR a : attribs»
- «var value = a.initValue»
- «IF value!=null»
- «IF !a.isArray»
- «a.name» ( «value» ),
- «ELSE»
- «a.name» ( {
- «FOR i : 0 .. a.size»
- value,
- «ENDFOR»
- } )
- «ENDIF»
- «ELSEIF a.refType.type instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
- «IF a.size==0»
- «IF a.refType.isRef»
- «a.name» ( «languageExt.nullPointer()» ),
- «ELSE»
- «a.name» ( «a.refType.type.defaultValue» ),
- «ENDIF»
- «ELSE»
- «a.name» ( new «a.refType.type.typeName»[«a.size»] ),
- «IF !useClassDefaultsOnly»
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«a.refType.type.defaultValue»«ENDIF»;
- }
- «ENDIF»
- «ENDIF»
- «ENDIF»
- «ENDFOR»
- '''
- }
+// def attributeConstructorInitList(List<Attribute> attribs, boolean useClassDefaultsOnly) {
+// '''
+// // initialize attributes
+// «FOR a : attribs»
+// «var value = a.initValue»
+// «IF value!=null»
+// «IF !a.isArray»
+// «a.name» ( «value» ),
+// «ELSE»
+// «a.name» ( {
+// «FOR i : 0 .. a.size»
+// value,
+// «ENDFOR»
+// } )
+// «ENDIF»
+// «ELSEIF a.refType.type instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
+// «IF a.size==0»
+// «IF a.refType.isRef»
+// «a.name» ( «languageExt.nullPointer()» ),
+// «ELSE»
+// «a.name» ( «a.refType.type.defaultValue» ),
+// «ENDIF»
+// «ELSE»
+// «a.name» ( new «a.refType.type.typeName»[«a.size»] ),
+// «IF !useClassDefaultsOnly»
+// for (int i=0;i<«a.size»;i++){
+// «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«a.refType.type.defaultValue»«ENDIF»;
+// }
+// «ENDIF»
+// «ENDIF»
+// «ENDIF»
+// «ENDFOR»
+// '''
+// }
+ override String toValueLiteral(PrimitiveType type, String value){
+ throw new UnsupportedOperationException("TODO Config for Cpp");
+ }
+
+ override String defaultValue(DataType dt) {
+ if (dt instanceof PrimitiveType) {
+ return (dt as PrimitiveType).getDefaultValueLiteral
+ }
+ else if (dt instanceof ExternalType) {
+ diagnostician.error("cannot initialize external type "+dt.name, dt.eContainer, dt.eContainingFeature)
+ return "cannot instantiate external data type "+dt.name
+ }
+ else {
+ val dc = dt as DataClass
+
+ '''
+ {
+ «FOR att : dc.attributes SEPARATOR ","»
+ «att.refType.type.initializationWithDefaultValues(att.size)»
+ «ENDFOR»
+ }
+ '''
+ }
+ }
+
+ override initializationWithDefaultValues(DataType dt, int size) {
+ val dv = dt.defaultValue
+ if (size>1) {
+ var res = "{"
+ var i = 0
+ while (i<size) {
+ res = res + dv
+ i = i+1
+ if (i<size)
+ res = res + ","
+ }
+ res+"}"
+ }
+ else
+ dv
+ }
+
+ override generateArglistAndTypedData(VarDecl data) {
+ if (data==null)
+ return newArrayList("", "", "")
+
+ var typeName = if (data.getRefType().getType() instanceof PrimitiveType)
+ (data.getRefType().getType() as PrimitiveType).getTargetName()
+ else
+ data.getRefType().getType().getName()
+
+ var castTypeName = if (data.getRefType().getType() instanceof PrimitiveType) {
+ val ct = (data.getRefType().getType() as PrimitiveType).getCastName()
+ if (ct!=null && !ct.isEmpty())
+ ct
+ else
+ typeName
+ }
+ else
+ typeName
+ castTypeName = castTypeName+"*"
+
+ if (data.getRefType().isRef()) {
+ typeName = typeName+"*"
+ castTypeName = castTypeName+"*"
+ }
+ if (!(data.getRefType().getType() instanceof PrimitiveType)) {
+ typeName = typeName+"*"
+ castTypeName = castTypeName+"*"
+ }
+
+ val typedData = typeName+" "+data.getName() + " = *(("+castTypeName+") generic_data);\n"
+
+ val dataArg = ", "+data.getName()
+ val typedArgList = ", "+typeName+" "+data.getName()
+
+ return newArrayList(dataArg, typedData, typedArgList);
+ }
+
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java
deleted file mode 100644
index 68c2f48..0000000
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.eclipse.etrice.generator.cpp.gen;
-
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
-
-public class CppLanguageGenerator extends AbstractTransitionChainGenerator {
-
- @Override
- public String[] generateArglistAndTypedData(VarDecl data) {
- if (data==null)
- return new String[] {"", "", ""};
-
- String typeName = data.getRefType().getType().getName();
- String castTypeName = typeName;
- if (data.getRefType().getType() instanceof PrimitiveType) {
- typeName = ((PrimitiveType)data.getRefType().getType()).getTargetName();
- String ct = ((PrimitiveType)data.getRefType().getType()).getCastName();
- if (ct!=null && !ct.isEmpty())
- castTypeName = ct;
- }
-
- // TODO: reinterpret_cast
- String typedData = typeName+" "+data.getName() + " = ("+castTypeName+") generic_data;\n";
- String dataArg = ", "+data.getName();
- String typedArgList = ", "+typeName+" "+data.getName();
-
- return new String[]{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 c3cad8f..d94ef0c 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
@@ -1,21 +1,21 @@
-package org.eclipse.etrice.generator.cpp.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import java.util.List
-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.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.etrice.generator.generic.TypeHelpers
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+package org.eclipse.etrice.generator.cpp.gen
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
import org.eclipse.etrice.core.genmodel.base.ILogger
import org.eclipse.etrice.core.genmodel.etricegen.Root
-
+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.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.generator.cpp.gen.Initialization
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
@@ -27,6 +27,7 @@ class DataClassGen {
@Inject extension RoomExtensions roomExt
@Inject extension ProcedureHelpers helpers
@Inject extension TypeHelpers typeHelpers
+ @Inject extension Initialization
@Inject ILogger logger
def doGenerate(Root root) {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend
new file mode 100644
index 0000000..4e0be55
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend
@@ -0,0 +1,55 @@
+package org.eclipse.etrice.generator.cpp.gen
+
+import org.eclipse.etrice.core.room.Attribute
+import java.util.List
+import com.google.inject.Inject
+import org.eclipse.etrice.generator.generic.ConfigExtension
+import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.core.room.ComplexType
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import com.google.inject.Singleton
+
+@Singleton
+class Initialization {
+
+ @Inject extension ConfigExtension
+ @Inject extension TypeHelpers
+ @Inject ILanguageExtension languageExt
+
+ def attributeInitialization(List<Attribute> attribs, boolean useClassDefaultsOnly) {
+ '''
+ // initialize attributes
+ «FOR a : attribs»
+ «var aType = a.refType.type»
+ «var value = a.initValueLiteral»
+ «IF value!=null»
+ «IF a.size == 0 || aType.characterType»
+ «a.name» = «value»;
+ «ELSEIF value.startsWith("{")»
+ «a.name» = new «aType.typeName»[] «value»;
+ «ELSE»
+ «a.name» = new «aType.typeName»[«a.size»];
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «value»;
+ }
+ «ENDIF»
+ «ELSEIF aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
+ «IF a.size==0»
+ «IF a.refType.isRef»
+ «a.name» = «languageExt.nullPointer()»;
+ «ELSE»
+ «a.name» = «languageExt.defaultValue(aType)»;
+ «ENDIF»
+ «ELSE»
+ «a.name» = new «aType.typeName»[«a.size»];
+ «IF !useClassDefaultsOnly»
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«languageExt.defaultValue(aType)»«ENDIF»;
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+} \ No newline at end of file
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 e28d2aa..4e182a2 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
@@ -1,46 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
package org.eclipse.etrice.generator.cpp.gen
import com.google.inject.Inject
import com.google.inject.Singleton
+import java.util.ArrayList
+import org.eclipse.xtext.util.Pair
+import static org.eclipse.xtext.util.Tuples.*
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
-import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
+import org.eclipse.etrice.generator.generic.RoomExtensions
@Singleton
class StateMachineGen extends GenericStateMachineGenerator {
@Inject extension RoomExtensions
-
- def genHeaderConstants(ExpandedActorClass xpac) {
-
- }
+ @Inject ProtocolClassGen cppProtGen
- def genDataMembers(ExpandedActorClass xpac) {
+ override genExtraDecl(ExpandedActorClass xpac) {
val ac = xpac.actorClass
'''
- /* state machine variables */
- int m_state;
- int m_history[«ac.name.toUpperCase»_HISTORY_SIZE];
+ protected:
+ static std::string s_stateStrings[];
+
+««« TODOHRR: history defined in ActorClassBase, init in constructor
+««« history = new int[5];
+««« for (int i = 0; i < history.length; i++) {
+««« history[i] = NO_STATE;
+««« }
+ int history[];
+
+ private:
+ void setState(int new_state);
'''}
- def genInitialization(ExpandedActorClass xpac) {
- val ac = xpac.actorClass
- '''
- m_state = STATE_TOP;
- {
- int i;
- for (i=0; i<«ac.name.toUpperCase»_HISTORY_SIZE; ++i)
- m_history[i] = NO_STATE;
- }
- executeInitTransition();
- '''}
override genExtra(ExpandedActorClass xpac) {
val ac = xpac.actorClass
'''
- // state names
- protected:
- static std::string stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStatesLeavesLast() SEPARATOR ","»"«state.getStatePathName()»"
+ std::string «ac.name»::s_stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStatesLeavesLast() SEPARATOR ","»"«state.getStatePathName()»"
«ENDFOR»};
««« TODOHRR: history defined in ActorClassBase, init in constructor
@@ -48,18 +55,55 @@ class StateMachineGen extends GenericStateMachineGenerator {
««« for (int i = 0; i < history.length; i++) {
««« history[i] = NO_STATE;
««« }
- // history
- protected:
- int history[] = {NO_STATE,NO_STATE«FOR state : ac.getAllBaseStates()»,NO_STATE«ENDFOR»};
-
- private:
- void setState(int new_state) {
- DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
- if (stateStrings[new_state]!="Idle") {
+
+ void «ac.name»::setState(int new_state) {
+ DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);
+ if (s_stateStrings[new_state]!="Idle") {
««« TODOTS: model switch for activation
- std::cout << getInstancePath() << " -> " << stateStrings[new_state] << std::endl;
+ std::cout << getInstancePath() << " -> " << s_stateStrings[new_state] << std::endl;
}
m_state = new_state;
}
'''}
+
+ override genTriggerConstants(ExpandedActorClass xpac) {
+ val triggers = if (langExt.usesInheritance)
+ xpac.getOwnTriggers() else xpac.triggers
+
+ val list = new ArrayList<Pair<String, String>>()
+ list.add(pair("POLLING", "0"));
+ for (mif : triggers) {
+ list.add(pair(xpac.getTriggerCodeName(mif), "IFITEM_"+mif.from.name+" + EVT_SHIFT*"+cppProtGen.getMessageID(mif)))
+ }
+
+ return langExt.genEnumeration("triggers", list)
+ }
+
+ override constRef(String classname) {
+ return "const " + classname + "&"
+ }
+
+ override pointer(String classname) {
+ return classname + "*"
+ }
+
+ override scopePrefix(String classname) {
+ return classname + "::"
+ }
+
+ override addressOp(String classname) {
+ return "&" + classname
+ }
+
+ override constPointer(String classname) {
+ return "const " + classname + "*"
+ }
+
+ override boolType() {
+ return "bool"
+ }
+
+
+
+
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
index 6dcfcc4..86a9328 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
@@ -12,6 +12,7 @@ import org.eclipse.etrice.generator.generic.ConfigExtension
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.generator.cpp.gen.ConfigGenAddon
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import static extension org.eclipse.etrice.generator.base.Indexed.*
@@ -27,6 +28,7 @@ class SubSystemClassGen {
@Inject extension ConfigExtension
@Inject extension ProcedureHelpers
@Inject extension TypeHelpers
+ @Inject ConfigGenAddon configAddon
@Inject ILogger logger
def doGenerate(Root root) {
@@ -184,54 +186,19 @@ class SubSystemClassGen {
);
«ENDFOR»
- // apply instance attribute configurations
- «FOR ai : comp.allContainedInstances»
- «var attrConfigs = ai.configAttributes»
- «var portConfigs = ai.getConfigPorts»
- «IF !attrConfigs.empty || !portConfigs.empty»
- {
- «var aiName = "inst"»
- «ai.actorClass.name» «aiName» = («ai.actorClass.name») m_instances[«comp.allContainedInstances.indexOf(ai)»];
- «FOR attrConfig : attrConfigs»
- «var a = attrConfig.attribute»
- «var value = attrConfig.value.stringValue(a)»
- «IF !a.isArray»
- «aiName».«a.name.invokeSetter(ai.actorClass.name, value)»;
- «ELSEIF value.startsWith("{")»
- «aiName».«a.name.invokeSetter(ai.actorClass.name, "new "+a.refType.type.typeName+"[]"+value)»;
- «ELSE»
- {
- «a.refType.type.typeName»[] array = «aiName».«a.name.invokeGetter(ai.actorClass.name)»;
- for (int i=0;i<«a.size»;i++){
- array[i] = «value»;
- }
- }
- «ENDIF»
- «ENDFOR»
- «FOR portConfig : portConfigs»
- «var item = portConfig.item»
- «FOR attrConfig : portConfig.attributes»
- «var a = attrConfig.attribute»
- «var value = attrConfig.value.stringValue(a)»
- «var refToItem = aiName+"."+item.name.invokeGetter(item.portClassName)»
- «IF !a.isArray»
- «refToItem».«a.name.invokeSetter(item.portClassName, value)»;
- «ELSEIF value.startsWith("{")»
- «refToItem».«a.name.invokeSetter(ai.actorClass.name, "new "+a.refType.type.typeName+"[]"+value)»;
- «ELSE»
- {
- «a.refType.type.typeName»[] array = «refToItem».«a.name.invokeGetter(ai.actorClass.name)»;
- for (int i=0;i<«a.size»;i++){
- array[i] = «value»;
- }
- }
- «ENDIF»
- «ENDFOR»
- «ENDFOR»
- }
- «ENDIF»
- «ENDFOR»
-
+ // apply instance attribute configurations
+ «FOR ai : comp.allContainedInstances»
+ «IF !(ai.configAttributes.empty && ai.getConfigPorts.empty)»
+ {
+ «ai.actorClass.name» inst = («ai.actorClass.name») instances[«comp.allContainedInstances.indexOf(ai)»];
+ «configAddon.applyInstanceConfig("inst", ai.actorClass.name, ai.configAttributes)»
+ «FOR portConfig : ai.configPorts»
+ «configAddon.applyInstanceConfig(("inst."+portConfig.item.name.invokeGetter(ai.actorClass.name)), portConfig.item.portClassName, portConfig.attributes)»
+ «ENDFOR»
+ }
+ «ENDIF»
+ «ENDFOR»
+
//----------------------------------------------------------------------------------------------
// addresses for the subsystem system port
//----------------------------------------------------------------------------------------------
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
index 2cf5769..7973fcc 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
@@ -16,13 +16,11 @@ import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.GeneratorBaseModule;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.cpp.Main;
-import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
-import org.eclipse.etrice.generator.cpp.gen.CppLanguageGenerator;
import org.eclipse.etrice.generator.cpp.gen.CppTranslationProvider;
import org.eclipse.etrice.generator.cpp.gen.MainGen;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.xtext.generator.IGenerator;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
import com.google.inject.Binder;
@@ -37,9 +35,11 @@ public class GeneratorModule extends GeneratorBaseModule {
// bind language specific code to generic Interfaces
binder.bind(ILanguageExtension.class).to(CppExtensions.class);
- binder.bind(AbstractTransitionChainGenerator.class).to(CppLanguageGenerator.class);
binder.bind(ITranslationProvider.class).to(CppTranslationProvider.class);
+
+
+
}
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
index b16cdf8..67c61c9 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
@@ -4,29 +4,35 @@ import com.google.common.base.Objects;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician;
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.DataType;
+import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.RoomClass;
import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
import org.eclipse.etrice.generator.generic.ConfigExtension;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.TypeHelpers;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.util.Pair;
-import org.eclipse.xtext.xbase.lib.IntegerRange;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
@Singleton
@SuppressWarnings("all")
public class CppExtensions implements ILanguageExtension {
@Inject
- private AbstractTransitionChainGenerator chainGenerator;
+ private ILanguageExtension languageExt;
@Inject
- private ILanguageExtension languageExt;
+ private IDiagnostician diagnostician;
@Inject
private ConfigExtension _configExtension;
@@ -36,7 +42,9 @@ public class CppExtensions implements ILanguageExtension {
public String getTypedDataDefinition(final Message m) {
VarDecl _data = m.getData();
- return this.chainGenerator.generateTypedData(_data);
+ String[] _generateArglistAndTypedData = this.generateArglistAndTypedData(_data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(1);
+ return _get;
}
public String getCppHeaderFileName(final RoomClass rc) {
@@ -215,141 +223,183 @@ public class CppExtensions implements ILanguageExtension {
return _plus_1;
}
- public CharSequence attributeConstructorInitList(final List<Attribute> attribs, final boolean useClassDefaultsOnly) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("// initialize attributes");
- _builder.newLine();
- {
- for(final Attribute a : attribs) {
- String value = this._configExtension.getInitValue(a);
- _builder.newLineIfNotEmpty();
+ public String toValueLiteral(final PrimitiveType type, final String value) {
+ UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("TODO Config for Cpp");
+ throw _unsupportedOperationException;
+ }
+
+ public String defaultValue(final DataType dt) {
+ String _xifexpression = null;
+ if ((dt instanceof PrimitiveType)) {
+ return ((PrimitiveType) dt).getDefaultValueLiteral();
+ } else {
+ String _xifexpression_1 = null;
+ if ((dt instanceof ExternalType)) {
+ String _name = dt.getName();
+ String _plus = ("cannot initialize external type " + _name);
+ EObject _eContainer = dt.eContainer();
+ EStructuralFeature _eContainingFeature = dt.eContainingFeature();
+ this.diagnostician.error(_plus, _eContainer, _eContainingFeature);
+ String _name_1 = dt.getName();
+ return ("cannot instantiate external data type " + _name_1);
+ } else {
+ String _xblockexpression = null;
{
- boolean _notEquals = (!Objects.equal(value, null));
- if (_notEquals) {
- {
- boolean _isArray = this._configExtension.isArray(a);
- boolean _not = (!_isArray);
- if (_not) {
- String _name = a.getName();
- _builder.append(_name, "");
- _builder.append(" ( ");
- _builder.append(value, "");
- _builder.append(" ),");
- _builder.newLineIfNotEmpty();
+ final DataClass dc = ((DataClass) dt);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ boolean _hasElements = false;
+ for(final Attribute att : _attributes) {
+ if (!_hasElements) {
+ _hasElements = true;
} else {
- String _name_1 = a.getName();
- _builder.append(_name_1, "");
- _builder.append(" ( {");
- _builder.newLineIfNotEmpty();
- {
- int _size = a.getSize();
- IntegerRange _upTo = new IntegerRange(0, _size);
- for(final Integer i : _upTo) {
- _builder.append("value,");
- _builder.newLine();
- }
- }
- _builder.append("} )");
- _builder.newLine();
+ _builder.appendImmediate(",", " ");
}
+ _builder.append("\t");
+ RefableType _refType = att.getRefType();
+ DataType _type = _refType.getType();
+ int _size = att.getSize();
+ String _initializationWithDefaultValues = this.initializationWithDefaultValues(_type, _size);
+ _builder.append(_initializationWithDefaultValues, " ");
+ _builder.newLineIfNotEmpty();
}
- } else {
- boolean _or = false;
- boolean _or_1 = false;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- if ((_type instanceof ComplexType)) {
- _or_1 = true;
- } else {
- int _size_1 = a.getSize();
- boolean _greaterThan = (_size_1 > 1);
- _or_1 = ((_type instanceof ComplexType) || _greaterThan);
- }
- if (_or_1) {
- _or = true;
- } else {
- boolean _not_1 = (!useClassDefaultsOnly);
- _or = (_or_1 || _not_1);
- }
- if (_or) {
- {
- int _size_2 = a.getSize();
- boolean _equals = (_size_2 == 0);
- if (_equals) {
- {
- RefableType _refType_1 = a.getRefType();
- boolean _isRef = _refType_1.isRef();
- if (_isRef) {
- String _name_2 = a.getName();
- _builder.append(_name_2, "");
- _builder.append(" ( ");
- String _nullPointer = this.languageExt.nullPointer();
- _builder.append(_nullPointer, "");
- _builder.append(" ),");
- _builder.newLineIfNotEmpty();
- } else {
- String _name_3 = a.getName();
- _builder.append(_name_3, "");
- _builder.append(" ( ");
- RefableType _refType_2 = a.getRefType();
- DataType _type_1 = _refType_2.getType();
- String _defaultValue = this._typeHelpers.defaultValue(_type_1);
- _builder.append(_defaultValue, "");
- _builder.append(" ),");
- _builder.newLineIfNotEmpty();
- }
- }
- } else {
- String _name_4 = a.getName();
- _builder.append(_name_4, "");
- _builder.append(" ( new ");
- RefableType _refType_3 = a.getRefType();
- DataType _type_2 = _refType_3.getType();
- String _typeName = this._typeHelpers.typeName(_type_2);
- _builder.append(_typeName, "");
- _builder.append("[");
- int _size_3 = a.getSize();
- _builder.append(_size_3, "");
- _builder.append("] ),");
- _builder.newLineIfNotEmpty();
- {
- boolean _not_2 = (!useClassDefaultsOnly);
- if (_not_2) {
- _builder.append("for (int i=0;i<");
- int _size_4 = a.getSize();
- _builder.append(_size_4, "");
- _builder.append(";i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_5 = a.getName();
- _builder.append(_name_5, " ");
- _builder.append("[i] = ");
- {
- RefableType _refType_4 = a.getRefType();
- boolean _isRef_1 = _refType_4.isRef();
- if (_isRef_1) {
- String _nullPointer_1 = this.languageExt.nullPointer();
- _builder.append(_nullPointer_1, " ");
- } else {
- RefableType _refType_5 = a.getRefType();
- DataType _type_3 = _refType_5.getType();
- String _defaultValue_1 = this._typeHelpers.defaultValue(_type_3);
- _builder.append(_defaultValue_1, " ");
- }
- }
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder.toString());
+ }
+ _xifexpression_1 = _xblockexpression;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ return _xifexpression;
+ }
+
+ public String initializationWithDefaultValues(final DataType dt, final int size) {
+ String _xblockexpression = null;
+ {
+ final String dv = this.defaultValue(dt);
+ String _xifexpression = null;
+ boolean _greaterThan = (size > 1);
+ if (_greaterThan) {
+ String _xblockexpression_1 = null;
+ {
+ String res = "{";
+ int i = 0;
+ boolean _lessThan = (i < size);
+ boolean _while = _lessThan;
+ while (_while) {
+ {
+ String _plus = (res + dv);
+ res = _plus;
+ int _plus_1 = (i + 1);
+ i = _plus_1;
+ boolean _lessThan_1 = (i < size);
+ if (_lessThan_1) {
+ String _plus_2 = (res + ",");
+ res = _plus_2;
}
}
+ boolean _lessThan_1 = (i < size);
+ _while = _lessThan_1;
}
+ String _plus = (res + "}");
+ _xblockexpression_1 = (_plus);
}
+ _xifexpression = _xblockexpression_1;
+ } else {
+ _xifexpression = dv;
}
+ _xblockexpression = (_xifexpression);
}
- return _builder;
+ return _xblockexpression;
+ }
+
+ public String[] generateArglistAndTypedData(final VarDecl data) {
+ boolean _equals = Objects.equal(data, null);
+ if (_equals) {
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
+ }
+ String _xifexpression = null;
+ RefableType _refType = data.getRefType();
+ DataType _type = _refType.getType();
+ if ((_type instanceof PrimitiveType)) {
+ RefableType _refType_1 = data.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _targetName = ((PrimitiveType) _type_1).getTargetName();
+ _xifexpression = _targetName;
+ } else {
+ RefableType _refType_2 = data.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _name = _type_2.getName();
+ _xifexpression = _name;
+ }
+ String typeName = _xifexpression;
+ String _xifexpression_1 = null;
+ RefableType _refType_3 = data.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ if ((_type_3 instanceof PrimitiveType)) {
+ String _xblockexpression = null;
+ {
+ RefableType _refType_4 = data.getRefType();
+ DataType _type_4 = _refType_4.getType();
+ final String ct = ((PrimitiveType) _type_4).getCastName();
+ String _xifexpression_2 = null;
+ boolean _and = false;
+ boolean _notEquals = (!Objects.equal(ct, null));
+ if (!_notEquals) {
+ _and = false;
+ } else {
+ boolean _isEmpty = ct.isEmpty();
+ boolean _not = (!_isEmpty);
+ _and = (_notEquals && _not);
+ }
+ if (_and) {
+ _xifexpression_2 = ct;
+ } else {
+ _xifexpression_2 = typeName;
+ }
+ _xblockexpression = (_xifexpression_2);
+ }
+ _xifexpression_1 = _xblockexpression;
+ } else {
+ _xifexpression_1 = typeName;
+ }
+ String castTypeName = _xifexpression_1;
+ String _plus = (castTypeName + "*");
+ castTypeName = _plus;
+ RefableType _refType_4 = data.getRefType();
+ boolean _isRef = _refType_4.isRef();
+ if (_isRef) {
+ String _plus_1 = (typeName + "*");
+ typeName = _plus_1;
+ String _plus_2 = (castTypeName + "*");
+ castTypeName = _plus_2;
+ }
+ RefableType _refType_5 = data.getRefType();
+ DataType _type_4 = _refType_5.getType();
+ boolean _not = (!(_type_4 instanceof PrimitiveType));
+ if (_not) {
+ String _plus_3 = (typeName + "*");
+ typeName = _plus_3;
+ String _plus_4 = (castTypeName + "*");
+ castTypeName = _plus_4;
+ }
+ String _plus_5 = (typeName + " ");
+ String _name_1 = data.getName();
+ String _plus_6 = (_plus_5 + _name_1);
+ String _plus_7 = (_plus_6 + " = *((");
+ String _plus_8 = (_plus_7 + castTypeName);
+ final String typedData = (_plus_8 + ") generic_data);\n");
+ String _name_2 = data.getName();
+ final String dataArg = (", " + _name_2);
+ String _plus_9 = (", " + typeName);
+ String _plus_10 = (_plus_9 + " ");
+ String _name_3 = data.getName();
+ final String typedArgList = (_plus_10 + _name_3);
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class));
}
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
index 9318fee..2450aa0 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
@@ -18,6 +18,7 @@ import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.cpp.gen.Initialization;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
import org.eclipse.etrice.generator.generic.TypeHelpers;
@@ -45,6 +46,9 @@ public class DataClassGen {
private TypeHelpers typeHelpers;
@Inject
+ private Initialization _initialization;
+
+ @Inject
private ILogger logger;
public void doGenerate(final Root root) {
@@ -338,7 +342,7 @@ public class DataClassGen {
_builder.newLine();
_builder.append("\t");
EList<Attribute> _attributes = dc.getAttributes();
- CharSequence _attributeInitialization = this.helpers.attributeInitialization(_attributes, false);
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, false);
_builder.append(_attributeInitialization, " ");
_builder.newLineIfNotEmpty();
{
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
index 3a69c58..8c0e384 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
@@ -78,7 +78,7 @@ class GenericStateMachineGenerator {
return langExt.genEnumeration("chain_ids", list)
}
- def private genTriggerConstants(ExpandedActorClass xpac) {
+ def genTriggerConstants(ExpandedActorClass xpac) {
val triggers = if (langExt.usesInheritance)
xpac.getOwnTriggers() else xpac.triggers
@@ -92,13 +92,16 @@ class GenericStateMachineGenerator {
}
def genStateMachine(ExpandedActorClass xpac) {
+ xpac.genStateMachine(true)
+ }
+ def genStateMachine(ExpandedActorClass xpac, boolean shallGenerateOneFile) {
val ac = xpac.actorClass
val async = ac.commType==ActorCommunicationType::ASYNCHRONOUS
val eventDriven = ac.commType==ActorCommunicationType::EVENT_DRIVEN
val handleEvents = async || eventDriven
'''
-
+ «IF shallGenerateOneFile»
/* state IDs */
«xpac.genStateIdConstants»
@@ -107,6 +110,7 @@ class GenericStateMachineGenerator {
/* triggers */
«xpac.genTriggerConstants»
+ «ENDIF»
«genExtra(xpac)»
@@ -122,7 +126,7 @@ class GenericStateMachineGenerator {
«IF (!langExt.usesInheritance || xpac.isOwnObject(tr)) && tr.hasActionCode()»
«var start = xpac.getChain(tr).transition»
«var hasArgs = start instanceof NonInitialTransition && !(start instanceof GuardedTransition)»
- «langExt.accessLevelProtected»void «tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, hasArgs)»«IF hasArgs»InterfaceItemBase ifitem«transitionChainGenerator.generateArgumentList(xpac, tr)»«ENDIF») {
+ «langExt.accessLevelProtected»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»«tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, hasArgs)»«IF hasArgs»«"InterfaceItemBase".constPointer» ifitem«transitionChainGenerator.generateArgumentList(xpac, tr)»«ENDIF») {
«AbstractGenerator::getInstance().getTranslatedCode(tr.action)»
}
«ENDIF»
@@ -135,7 +139,7 @@ class GenericStateMachineGenerator {
* @param to - the final parent state
* @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
*/
- «langExt.accessLevelPrivate»void exitTo(«langExt.selfPointer(ac.name, true)»int current, int to, boolean handler) {
+ «langExt.accessLevelPrivate»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»exitTo(«langExt.selfPointer(ac.name, true)»int current, int to, «boolType» handler) {
while (current!=to) {
switch (current) {
«FOR state : xpac.stateMachine.getBaseStateList()»
@@ -156,7 +160,7 @@ class GenericStateMachineGenerator {
* @param generic_data - the generic data pointer
* @return the ID of the final state
*/
- «langExt.accessLevelPrivate»int executeTransitionChain(«langExt.selfPointer(ac.name, true)»int chain«IF handleEvents», InterfaceItemBase ifitem, «langExt.voidPointer» generic_data«ENDIF») {
+ «langExt.accessLevelPrivate»int «IF !shallGenerateOneFile»«ac.name»::«ENDIF»executeTransitionChain(«langExt.selfPointer(ac.name, true)»int chain«IF handleEvents», «"InterfaceItemBase".constPointer» ifitem, «langExt.voidPointer» generic_data«ENDIF») {
switch (chain) {
«var allchains = xpac.getTransitionChains()»
«FOR tc : allchains»
@@ -175,7 +179,7 @@ class GenericStateMachineGenerator {
* @param handler - entry code is executed if not handler
* @return - the ID of the final leaf state
*/
- «langExt.accessLevelPrivate»int enterHistory(«langExt.selfPointer(ac.name, true)»int state, boolean handler, boolean skip_entry) {
+ «langExt.accessLevelPrivate»int «IF !shallGenerateOneFile»«ac.name»::«ENDIF»enterHistory(«langExt.selfPointer(ac.name, true)»int state, «boolType» handler, «boolType» skip_entry) {
while («langExt.booleanConstant(true)») {
switch (state) {
«FOR state : xpac.stateMachine.getBaseStateList()»
@@ -211,7 +215,7 @@ class GenericStateMachineGenerator {
//return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
}
- «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void executeInitTransition(«langExt.selfPointer(ac.name, false)») {
+ «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»executeInitTransition(«langExt.selfPointer(ac.name, false)») {
«var initt = xpac.stateMachine.getInitTransition()»
int chain = «xpac.getChain(initt).getChainId()»;
int next = executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», «langExt.nullPointer», «langExt.nullPointer»«ENDIF»);
@@ -220,7 +224,7 @@ class GenericStateMachineGenerator {
}
/* receiveEvent contains the main implementation of the FSM */
- «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»InterfaceItemBase ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF») {
+ «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»«"InterfaceItemBase".constRef» ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF») {
«IF async»
int trigger = (ifitem==«langExt.nullPointer»)? POLLING : «IF langExt.usesInheritance»ifitem.getLocalId()«ELSE»ifitem->localId«ENDIF» + EVT_SHIFT*evt;
«ELSEIF eventDriven»
@@ -228,8 +232,8 @@ class GenericStateMachineGenerator {
«ENDIF»
int chain = NOT_CAUGHT;
int catching_state = NO_STATE;
- boolean is_handler = «langExt.booleanConstant(false)»;
- boolean skip_entry = «langExt.booleanConstant(false)»;
+ «boolType» is_handler = «langExt.booleanConstant(false)»;
+ «boolType» skip_entry = «langExt.booleanConstant(false)»;
«IF handleEvents»
if (!handleSystemEvent(ifitem, evt, generic_data)) {
@@ -239,8 +243,8 @@ class GenericStateMachineGenerator {
«genStateSwitch(xpac)»
«ENDIF»
if (chain != NOT_CAUGHT) {
- exitTo(«langExt.selfPointer(true)»«langExt.memberAccess»state, catching_state, is_handler);
- int next = executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», ifitem, generic_data«ENDIF»);
+ exitTo(getState(), catching_state, is_handler);
+ int next = executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», «addressOp("ifitem")», generic_data«ENDIF»);
next = enterHistory(«langExt.selfPointer(true)»next, is_handler, skip_entry);
setState(«langExt.selfPointer(true)»next);
}
@@ -256,7 +260,7 @@ class GenericStateMachineGenerator {
var eventDriven = xpac.actorClass.commType==ActorCommunicationType::EVENT_DRIVEN
var dataDriven = xpac.actorClass.commType==ActorCommunicationType::DATA_DRIVEN
'''
- switch («langExt.memberAccess»state) {
+ switch (getState()) {
«FOR state : xpac.stateMachine.getLeafStateList()»
case «state.getStateId()»:
«IF async»
@@ -329,6 +333,7 @@ class GenericStateMachineGenerator {
'''
}
def genExtra(ExpandedActorClass xpac) {''''''}
+ def genExtraDecl(ExpandedActorClass xpac) {''''''}
def private dispatch guard(TriggeredTransition tt, String trigger, ExpandedActorClass ac) {
var tr = tt.triggers.findFirst(e|ac.isMatching(e, trigger))
@@ -355,6 +360,11 @@ class GenericStateMachineGenerator {
'''}
def private genActionCodeMethods(ExpandedActorClass xpac, State state) {
+ genActionCodeMethods(xpac, state, true);
+ }
+
+ def private genActionCodeMethods(ExpandedActorClass xpac, State state, boolean generateImplementation) {
+ val ac = xpac.actorClass
val selfPtr = langExt.selfPointer(xpac.actorClass.name, false)
val entryOp = state.getEntryCodeOperationName()
val exitOp = state.getExitCodeOperationName()
@@ -386,21 +396,125 @@ class GenericStateMachineGenerator {
}
'''
«IF !entry.empty»
- «langExt.accessLevelProtected»void «entryOp»(«selfPtr») {
+ «IF generateImplementation»
+ «langExt.accessLevelProtected»void «scopePrefix(ac.name)»«entryOp»(«selfPtr») {
«entry»
}
+ «ELSE»
+ «langExt.accessLevelProtected»void «entryOp»(«selfPtr»);
+ «ENDIF»
«ENDIF»
«IF !exit.empty»
- «langExt.accessLevelProtected»void «exitOp»(«selfPtr») {
+ «IF generateImplementation»
+ «langExt.accessLevelProtected»void «scopePrefix(ac.name)»«exitOp»(«selfPtr») {
«exit»
}
+ «ELSE»
+ «langExt.accessLevelProtected»void «exitOp»(«selfPtr»);
+ «ENDIF»
«ENDIF»
«IF !docode.empty»
- «langExt.accessLevelProtected» void «doOp»(«selfPtr») {
+ «IF generateImplementation»
+ «langExt.accessLevelProtected» void «scopePrefix(ac.name)»«doOp»(«selfPtr») {
«docode»
}
+ «ELSE»
+ «langExt.accessLevelProtected»void «doOp»(«selfPtr»);
+ «ENDIF»
«ENDIF»
'''
}
+ def constRef(String classname) {
+ return classname
+ }
+
+ def addressOp(String classname) {
+ return classname
+ }
+ def constPointer(String classname) {
+ return classname
+ }
+
+ def pointer(String classname) {
+ return classname
+ }
+ def scopePrefix(String classname) {
+ return ""
+ }
+ def boolType() {
+ return "boolean"
+ }
+
+ def genStateMachineMethodDeclarations(ExpandedActorClass xpac)
+ {
+ val ac = xpac.actorClass
+ val async = ac.commType==ActorCommunicationType::ASYNCHRONOUS
+ val eventDriven = ac.commType==ActorCommunicationType::EVENT_DRIVEN
+ val handleEvents = async || eventDriven
+
+ '''
+
+ /* state IDs */
+ «xpac.genStateIdConstants»
+
+ /* transition chains */
+ «xpac.genTransitionChainConstants»
+
+ /* triggers */
+ «xpac.genTriggerConstants»
+
+ «genExtraDecl(xpac)»
+
+ /* Entry and Exit Codes */
+ «FOR state : xpac.stateMachine.getStateList()»
+ «IF !langExt.usesInheritance || xpac.isOwnObject(state)»
+ «xpac.genActionCodeMethods(state, false)»
+ «ENDIF»
+ «ENDFOR»
+
+ /* Action Codes */
+ «FOR tr : xpac.stateMachine.getTransitionList()»
+ «IF (!langExt.usesInheritance || xpac.isOwnObject(tr)) && tr.hasActionCode()»
+ «var start = xpac.getChain(tr).transition»
+ «var hasArgs = start instanceof NonInitialTransition && !(start instanceof GuardedTransition)»
+ «langExt.accessLevelProtected»void «tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, hasArgs)»«IF hasArgs»«constPointer("etRuntime::InterfaceItemBase")» ifitem«transitionChainGenerator.generateArgumentList(xpac, tr)»«ENDIF»);
+ «ENDIF»
+ «ENDFOR»
+
+ private:
+ /**
+ * calls exit codes while exiting from the current state to one of its
+ * parent states while remembering the history
+ * @param current - the current state
+ * @param to - the final parent state
+ * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
+ */
+ void exitTo(«langExt.selfPointer(ac.name, true)»int current, int to, «boolType» handler);
+
+ /**
+ * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
+ * matching the trigger of this chain. The ID of the final state is returned
+ * @param chain - the chain ID
+ * @param generic_data - the generic data pointer
+ * @return the ID of the final state
+ */
+ int executeTransitionChain(«langExt.selfPointer(ac.name, true)»int chain«IF handleEvents», «constPointer("etRuntime::InterfaceItemBase")» ifitem, «langExt.voidPointer» generic_data«ENDIF»);
+
+ /**
+ * calls entry codes while entering a state's history. The ID of the final leaf state is returned
+ * @param state - the state which is entered
+ * @param handler - entry code is executed if not handler
+ * @return - the ID of the final leaf state
+ */
+ int enterHistory(«langExt.selfPointer(ac.name, true)»int state, «boolType» handler, «boolType» skip_entry);
+
+ public:
+
+ void executeInitTransition(«langExt.selfPointer(ac.name, false)»);
+
+ /* receiveEvent contains the main implementation of the FSM */
+ void receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»const etRuntime::InterfaceItemBase& ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF»);
+ '''
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
index cdef502..e0d1281 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
@@ -137,7 +137,7 @@ public class GenericStateMachineGenerator {
return this.langExt.genEnumeration("chain_ids", list);
}
- private String genTriggerConstants(final ExpandedActorClass xpac) {
+ public String genTriggerConstants(final ExpandedActorClass xpac) {
EList<MessageFromIf> _xifexpression = null;
boolean _usesInheritance = this.langExt.usesInheritance();
if (_usesInheritance) {
@@ -167,6 +167,11 @@ public class GenericStateMachineGenerator {
}
public CharSequence genStateMachine(final ExpandedActorClass xpac) {
+ CharSequence _genStateMachine = this.genStateMachine(xpac, true);
+ return _genStateMachine;
+ }
+
+ public CharSequence genStateMachine(final ExpandedActorClass xpac, final boolean shallGenerateOneFile) {
CharSequence _xblockexpression = null;
{
final ActorClass ac = xpac.getActorClass();
@@ -182,24 +187,27 @@ public class GenericStateMachineGenerator {
}
final boolean handleEvents = _or;
StringConcatenation _builder = new StringConcatenation();
- _builder.newLine();
- _builder.append("/* state IDs */");
- _builder.newLine();
- String _genStateIdConstants = this.genStateIdConstants(xpac);
- _builder.append(_genStateIdConstants, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/* transition chains */");
- _builder.newLine();
- String _genTransitionChainConstants = this.genTransitionChainConstants(xpac);
- _builder.append(_genTransitionChainConstants, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/* triggers */");
- _builder.newLine();
- String _genTriggerConstants = this.genTriggerConstants(xpac);
- _builder.append(_genTriggerConstants, "");
- _builder.newLineIfNotEmpty();
+ {
+ if (shallGenerateOneFile) {
+ _builder.append("/* state IDs */");
+ _builder.newLine();
+ String _genStateIdConstants = this.genStateIdConstants(xpac);
+ _builder.append(_genStateIdConstants, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* transition chains */");
+ _builder.newLine();
+ String _genTransitionChainConstants = this.genTransitionChainConstants(xpac);
+ _builder.append(_genTransitionChainConstants, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* triggers */");
+ _builder.newLine();
+ String _genTriggerConstants = this.genTriggerConstants(xpac);
+ _builder.append(_genTriggerConstants, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
_builder.newLine();
CharSequence _genExtra = this.genExtra(xpac);
_builder.append(_genExtra, "");
@@ -269,15 +277,25 @@ public class GenericStateMachineGenerator {
String _accessLevelProtected = this.langExt.accessLevelProtected();
_builder.append(_accessLevelProtected, "");
_builder.append("void ");
+ {
+ boolean _not_3 = (!shallGenerateOneFile);
+ if (_not_3) {
+ String _name = ac.getName();
+ _builder.append(_name, "");
+ _builder.append("::");
+ }
+ }
String _actionCodeOperationName = CodegenHelpers.getActionCodeOperationName(tr);
_builder.append(_actionCodeOperationName, "");
_builder.append("(");
- String _name = ac.getName();
- String _selfPointer = this.langExt.selfPointer(_name, hasArgs);
+ String _name_1 = ac.getName();
+ String _selfPointer = this.langExt.selfPointer(_name_1, hasArgs);
_builder.append(_selfPointer, "");
{
if (hasArgs) {
- _builder.append("InterfaceItemBase ifitem");
+ String _constPointer = this.constPointer("InterfaceItemBase");
+ _builder.append(_constPointer, "");
+ _builder.append(" ifitem");
String _generateArgumentList = this.transitionChainGenerator.generateArgumentList(xpac, tr);
_builder.append(_generateArgumentList, "");
}
@@ -319,11 +337,23 @@ public class GenericStateMachineGenerator {
_builder.newLine();
String _accessLevelPrivate = this.langExt.accessLevelPrivate();
_builder.append(_accessLevelPrivate, "");
- _builder.append("void exitTo(");
- String _name_1 = ac.getName();
- String _selfPointer_1 = this.langExt.selfPointer(_name_1, true);
+ _builder.append("void ");
+ {
+ boolean _not_4 = (!shallGenerateOneFile);
+ if (_not_4) {
+ String _name_2 = ac.getName();
+ _builder.append(_name_2, "");
+ _builder.append("::");
+ }
+ }
+ _builder.append("exitTo(");
+ String _name_3 = ac.getName();
+ String _selfPointer_1 = this.langExt.selfPointer(_name_3, true);
_builder.append(_selfPointer_1, "");
- _builder.append("int current, int to, boolean handler) {");
+ _builder.append("int current, int to, ");
+ String _boolType = this.boolType();
+ _builder.append(_boolType, "");
+ _builder.append(" handler) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("while (current!=to) {");
@@ -412,14 +442,26 @@ public class GenericStateMachineGenerator {
_builder.newLine();
String _accessLevelPrivate_1 = this.langExt.accessLevelPrivate();
_builder.append(_accessLevelPrivate_1, "");
- _builder.append("int executeTransitionChain(");
- String _name_2 = ac.getName();
- String _selfPointer_3 = this.langExt.selfPointer(_name_2, true);
+ _builder.append("int ");
+ {
+ boolean _not_5 = (!shallGenerateOneFile);
+ if (_not_5) {
+ String _name_4 = ac.getName();
+ _builder.append(_name_4, "");
+ _builder.append("::");
+ }
+ }
+ _builder.append("executeTransitionChain(");
+ String _name_5 = ac.getName();
+ String _selfPointer_3 = this.langExt.selfPointer(_name_5, true);
_builder.append(_selfPointer_3, "");
_builder.append("int chain");
{
if (handleEvents) {
- _builder.append(", InterfaceItemBase ifitem, ");
+ _builder.append(", ");
+ String _constPointer_1 = this.constPointer("InterfaceItemBase");
+ _builder.append(_constPointer_1, "");
+ _builder.append(" ifitem, ");
String _voidPointer = this.langExt.voidPointer();
_builder.append(_voidPointer, "");
_builder.append(" generic_data");
@@ -482,11 +524,26 @@ public class GenericStateMachineGenerator {
_builder.newLine();
String _accessLevelPrivate_2 = this.langExt.accessLevelPrivate();
_builder.append(_accessLevelPrivate_2, "");
- _builder.append("int enterHistory(");
- String _name_3 = ac.getName();
- String _selfPointer_4 = this.langExt.selfPointer(_name_3, true);
+ _builder.append("int ");
+ {
+ boolean _not_6 = (!shallGenerateOneFile);
+ if (_not_6) {
+ String _name_6 = ac.getName();
+ _builder.append(_name_6, "");
+ _builder.append("::");
+ }
+ }
+ _builder.append("enterHistory(");
+ String _name_7 = ac.getName();
+ String _selfPointer_4 = this.langExt.selfPointer(_name_7, true);
_builder.append(_selfPointer_4, "");
- _builder.append("int state, boolean handler, boolean skip_entry) {");
+ _builder.append("int state, ");
+ String _boolType_1 = this.boolType();
+ _builder.append(_boolType_1, "");
+ _builder.append(" handler, ");
+ String _boolType_2 = this.boolType();
+ _builder.append(_boolType_2, "");
+ _builder.append(" skip_entry) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("while (");
@@ -674,9 +731,18 @@ public class GenericStateMachineGenerator {
_builder.append(_accessLevelPrivate_3, "");
}
}
- _builder.append("void executeInitTransition(");
- String _name_4 = ac.getName();
- String _selfPointer_7 = this.langExt.selfPointer(_name_4, false);
+ _builder.append("void ");
+ {
+ boolean _not_7 = (!shallGenerateOneFile);
+ if (_not_7) {
+ String _name_8 = ac.getName();
+ _builder.append(_name_8, "");
+ _builder.append("::");
+ }
+ }
+ _builder.append("executeInitTransition(");
+ String _name_9 = ac.getName();
+ String _selfPointer_7 = this.langExt.selfPointer(_name_9, false);
_builder.append(_selfPointer_7, "");
_builder.append(") {");
_builder.newLineIfNotEmpty();
@@ -741,13 +807,24 @@ public class GenericStateMachineGenerator {
_builder.append(_accessLevelPrivate_4, "");
}
}
- _builder.append("void receiveEvent(");
- String _name_5 = ac.getName();
- String _selfPointer_11 = this.langExt.selfPointer(_name_5, handleEvents);
+ _builder.append("void ");
+ {
+ boolean _not_8 = (!shallGenerateOneFile);
+ if (_not_8) {
+ String _name_10 = ac.getName();
+ _builder.append(_name_10, "");
+ _builder.append("::");
+ }
+ }
+ _builder.append("receiveEvent(");
+ String _name_11 = ac.getName();
+ String _selfPointer_11 = this.langExt.selfPointer(_name_11, handleEvents);
_builder.append(_selfPointer_11, "");
{
if (handleEvents) {
- _builder.append("InterfaceItemBase ifitem, int evt, ");
+ String _constRef = this.constRef("InterfaceItemBase");
+ _builder.append(_constRef, "");
+ _builder.append(" ifitem, int evt, ");
String _voidPointer_1 = this.langExt.voidPointer();
_builder.append(_voidPointer_1, "");
_builder.append(" generic_data");
@@ -796,13 +873,17 @@ public class GenericStateMachineGenerator {
_builder.append("int catching_state = NO_STATE;");
_builder.newLine();
_builder.append("\t");
- _builder.append("boolean is_handler = ");
+ String _boolType_3 = this.boolType();
+ _builder.append(_boolType_3, " ");
+ _builder.append(" is_handler = ");
String _booleanConstant_4 = this.langExt.booleanConstant(false);
_builder.append(_booleanConstant_4, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
- _builder.append("boolean skip_entry = ");
+ String _boolType_4 = this.boolType();
+ _builder.append(_boolType_4, " ");
+ _builder.append(" skip_entry = ");
String _booleanConstant_5 = this.langExt.booleanConstant(false);
_builder.append(_booleanConstant_5, " ");
_builder.append(";");
@@ -833,35 +914,33 @@ public class GenericStateMachineGenerator {
_builder.append("if (chain != NOT_CAUGHT) {");
_builder.newLine();
_builder.append("\t\t");
- _builder.append("exitTo(");
- String _selfPointer_12 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_12, " ");
- String _memberAccess_5 = this.langExt.memberAccess();
- _builder.append(_memberAccess_5, " ");
- _builder.append("state, catching_state, is_handler);");
- _builder.newLineIfNotEmpty();
+ _builder.append("exitTo(getState(), catching_state, is_handler);");
+ _builder.newLine();
_builder.append("\t\t");
_builder.append("int next = executeTransitionChain(");
- String _selfPointer_13 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_13, " ");
+ String _selfPointer_12 = this.langExt.selfPointer(true);
+ _builder.append(_selfPointer_12, " ");
_builder.append("chain");
{
if (handleEvents) {
- _builder.append(", ifitem, generic_data");
+ _builder.append(", ");
+ String _addressOp = this.addressOp("ifitem");
+ _builder.append(_addressOp, " ");
+ _builder.append(", generic_data");
}
}
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("next = enterHistory(");
- String _selfPointer_14 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_14, " ");
+ String _selfPointer_13 = this.langExt.selfPointer(true);
+ _builder.append(_selfPointer_13, " ");
_builder.append("next, is_handler, skip_entry);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("setState(");
- String _selfPointer_15 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_15, " ");
+ String _selfPointer_14 = this.langExt.selfPointer(true);
+ _builder.append(_selfPointer_14, " ");
_builder.append("next);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
@@ -895,11 +974,8 @@ public class GenericStateMachineGenerator {
ActorCommunicationType _commType_2 = _actorClass_2.getCommType();
boolean dataDriven = Objects.equal(_commType_2, ActorCommunicationType.DATA_DRIVEN);
StringConcatenation _builder = new StringConcatenation();
- _builder.append("switch (");
- String _memberAccess = this.langExt.memberAccess();
- _builder.append(_memberAccess, "");
- _builder.append("state) {");
- _builder.newLineIfNotEmpty();
+ _builder.append("switch (getState()) {");
+ _builder.newLine();
{
StateGraph _stateMachine = xpac.getStateMachine();
List<State> _leafStateList = this._roomExtensions.getLeafStateList(_stateMachine);
@@ -1183,6 +1259,11 @@ public class GenericStateMachineGenerator {
return _builder;
}
+ public CharSequence genExtraDecl(final ExpandedActorClass xpac) {
+ StringConcatenation _builder = new StringConcatenation();
+ return _builder;
+ }
+
private CharSequence _guard(final TriggeredTransition tt, final String trigger, final ExpandedActorClass ac) {
CharSequence _xblockexpression = null;
{
@@ -1246,8 +1327,14 @@ public class GenericStateMachineGenerator {
}
private CharSequence genActionCodeMethods(final ExpandedActorClass xpac, final State state) {
+ CharSequence _genActionCodeMethods = this.genActionCodeMethods(xpac, state, true);
+ return _genActionCodeMethods;
+ }
+
+ private CharSequence genActionCodeMethods(final ExpandedActorClass xpac, final State state, final boolean generateImplementation) {
CharSequence _xblockexpression = null;
{
+ final ActorClass ac = xpac.getActorClass();
ActorClass _actorClass = xpac.getActorClass();
String _name = _actorClass.getName();
final String selfPtr = this.langExt.selfPointer(_name, false);
@@ -1317,57 +1404,105 @@ public class GenericStateMachineGenerator {
boolean _isEmpty = entry.isEmpty();
boolean _not_3 = (!_isEmpty);
if (_not_3) {
- String _accessLevelProtected = this.langExt.accessLevelProtected();
- _builder.append(_accessLevelProtected, "");
- _builder.append("void ");
- _builder.append(entryOp, "");
- _builder.append("(");
- _builder.append(selfPtr, "");
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append(entry, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
+ {
+ if (generateImplementation) {
+ String _accessLevelProtected = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected, "");
+ _builder.append("void ");
+ String _name_1 = ac.getName();
+ String _scopePrefix = this.scopePrefix(_name_1);
+ _builder.append(_scopePrefix, "");
+ _builder.append(entryOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append(entry, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ String _accessLevelProtected_1 = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected_1, "");
+ _builder.append("void ");
+ _builder.append(entryOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
}
}
{
boolean _isEmpty_1 = exit.isEmpty();
boolean _not_4 = (!_isEmpty_1);
if (_not_4) {
- String _accessLevelProtected_1 = this.langExt.accessLevelProtected();
- _builder.append(_accessLevelProtected_1, "");
- _builder.append("void ");
- _builder.append(exitOp, "");
- _builder.append("(");
- _builder.append(selfPtr, "");
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append(exit, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
+ {
+ if (generateImplementation) {
+ String _accessLevelProtected_2 = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected_2, "");
+ _builder.append("void ");
+ String _name_2 = ac.getName();
+ String _scopePrefix_1 = this.scopePrefix(_name_2);
+ _builder.append(_scopePrefix_1, "");
+ _builder.append(exitOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append(exit, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ String _accessLevelProtected_3 = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected_3, "");
+ _builder.append("void ");
+ _builder.append(exitOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
}
}
{
boolean _isEmpty_2 = docode.isEmpty();
boolean _not_5 = (!_isEmpty_2);
if (_not_5) {
- String _accessLevelProtected_2 = this.langExt.accessLevelProtected();
- _builder.append(_accessLevelProtected_2, "");
- _builder.append(" void ");
- _builder.append(doOp, "");
- _builder.append("(");
- _builder.append(selfPtr, "");
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append(docode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
+ {
+ if (generateImplementation) {
+ String _accessLevelProtected_4 = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected_4, "");
+ _builder.append(" void ");
+ String _name_3 = ac.getName();
+ String _scopePrefix_2 = this.scopePrefix(_name_3);
+ _builder.append(_scopePrefix_2, "");
+ _builder.append(doOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append(docode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ String _accessLevelProtected_5 = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected_5, "");
+ _builder.append("void ");
+ _builder.append(doOp, "");
+ _builder.append("(");
+ _builder.append(selfPtr, "");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
}
}
_xblockexpression = (_builder);
@@ -1375,6 +1510,299 @@ public class GenericStateMachineGenerator {
return _xblockexpression;
}
+ public String constRef(final String classname) {
+ return classname;
+ }
+
+ public String addressOp(final String classname) {
+ return classname;
+ }
+
+ public String constPointer(final String classname) {
+ return classname;
+ }
+
+ public String pointer(final String classname) {
+ return classname;
+ }
+
+ public String scopePrefix(final String classname) {
+ return "";
+ }
+
+ public String boolType() {
+ return "boolean";
+ }
+
+ public CharSequence genStateMachineMethodDeclarations(final ExpandedActorClass xpac) {
+ CharSequence _xblockexpression = null;
+ {
+ final ActorClass ac = xpac.getActorClass();
+ ActorCommunicationType _commType = ac.getCommType();
+ final boolean async = Objects.equal(_commType, ActorCommunicationType.ASYNCHRONOUS);
+ ActorCommunicationType _commType_1 = ac.getCommType();
+ final boolean eventDriven = Objects.equal(_commType_1, ActorCommunicationType.EVENT_DRIVEN);
+ boolean _or = false;
+ if (async) {
+ _or = true;
+ } else {
+ _or = (async || eventDriven);
+ }
+ final boolean handleEvents = _or;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.newLine();
+ _builder.append("/* state IDs */");
+ _builder.newLine();
+ String _genStateIdConstants = this.genStateIdConstants(xpac);
+ _builder.append(_genStateIdConstants, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* transition chains */");
+ _builder.newLine();
+ String _genTransitionChainConstants = this.genTransitionChainConstants(xpac);
+ _builder.append(_genTransitionChainConstants, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* triggers */");
+ _builder.newLine();
+ String _genTriggerConstants = this.genTriggerConstants(xpac);
+ _builder.append(_genTriggerConstants, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _genExtraDecl = this.genExtraDecl(xpac);
+ _builder.append(_genExtraDecl, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* Entry and Exit Codes */");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine = xpac.getStateMachine();
+ List<State> _stateList = this._roomExtensions.getStateList(_stateMachine);
+ for(final State state : _stateList) {
+ {
+ boolean _or_1 = false;
+ boolean _usesInheritance = this.langExt.usesInheritance();
+ boolean _not = (!_usesInheritance);
+ if (_not) {
+ _or_1 = true;
+ } else {
+ boolean _isOwnObject = xpac.isOwnObject(state);
+ _or_1 = (_not || _isOwnObject);
+ }
+ if (_or_1) {
+ CharSequence _genActionCodeMethods = this.genActionCodeMethods(xpac, state, false);
+ _builder.append(_genActionCodeMethods, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("/* Action Codes */");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_1 = xpac.getStateMachine();
+ List<Transition> _transitionList = this._roomExtensions.getTransitionList(_stateMachine_1);
+ for(final Transition tr : _transitionList) {
+ {
+ boolean _and = false;
+ boolean _or_2 = false;
+ boolean _usesInheritance_1 = this.langExt.usesInheritance();
+ boolean _not_1 = (!_usesInheritance_1);
+ if (_not_1) {
+ _or_2 = true;
+ } else {
+ boolean _isOwnObject_1 = xpac.isOwnObject(tr);
+ _or_2 = (_not_1 || _isOwnObject_1);
+ }
+ if (!_or_2) {
+ _and = false;
+ } else {
+ boolean _hasActionCode = this._roomExtensions.hasActionCode(tr);
+ _and = (_or_2 && _hasActionCode);
+ }
+ if (_and) {
+ TransitionChain _chain = xpac.getChain(tr);
+ Transition start = _chain.getTransition();
+ _builder.newLineIfNotEmpty();
+ boolean _and_1 = false;
+ if (!(start instanceof NonInitialTransition)) {
+ _and_1 = false;
+ } else {
+ boolean _not_2 = (!(start instanceof GuardedTransition));
+ _and_1 = ((start instanceof NonInitialTransition) && _not_2);
+ }
+ boolean hasArgs = _and_1;
+ _builder.newLineIfNotEmpty();
+ String _accessLevelProtected = this.langExt.accessLevelProtected();
+ _builder.append(_accessLevelProtected, "");
+ _builder.append("void ");
+ String _actionCodeOperationName = CodegenHelpers.getActionCodeOperationName(tr);
+ _builder.append(_actionCodeOperationName, "");
+ _builder.append("(");
+ String _name = ac.getName();
+ String _selfPointer = this.langExt.selfPointer(_name, hasArgs);
+ _builder.append(_selfPointer, "");
+ {
+ if (hasArgs) {
+ String _constPointer = this.constPointer("etRuntime::InterfaceItemBase");
+ _builder.append(_constPointer, "");
+ _builder.append(" ifitem");
+ String _generateArgumentList = this.transitionChainGenerator.generateArgumentList(xpac, tr);
+ _builder.append(_generateArgumentList, "");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("private:");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* calls exit codes while exiting from the current state to one of its");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* parent states while remembering the history");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param current - the current state");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param to - the final parent state");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("void exitTo(");
+ String _name_1 = ac.getName();
+ String _selfPointer_1 = this.langExt.selfPointer(_name_1, true);
+ _builder.append(_selfPointer_1, " ");
+ _builder.append("int current, int to, ");
+ String _boolType = this.boolType();
+ _builder.append(_boolType, " ");
+ _builder.append(" handler);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* calls action, entry and exit codes along a transition chain. The generic data are cast to typed data");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* matching the trigger of this chain. The ID of the final state is returned");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param chain - the chain ID");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param generic_data - the generic data pointer");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @return the ID of the final state");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int executeTransitionChain(");
+ String _name_2 = ac.getName();
+ String _selfPointer_2 = this.langExt.selfPointer(_name_2, true);
+ _builder.append(_selfPointer_2, " ");
+ _builder.append("int chain");
+ {
+ if (handleEvents) {
+ _builder.append(", ");
+ String _constPointer_1 = this.constPointer("etRuntime::InterfaceItemBase");
+ _builder.append(_constPointer_1, " ");
+ _builder.append(" ifitem, ");
+ String _voidPointer = this.langExt.voidPointer();
+ _builder.append(_voidPointer, " ");
+ _builder.append(" generic_data");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* calls entry codes while entering a state\'s history. The ID of the final leaf state is returned");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param state - the state which is entered");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @param handler - entry code is executed if not handler");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("* @return - the ID of the final leaf state");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int enterHistory(");
+ String _name_3 = ac.getName();
+ String _selfPointer_3 = this.langExt.selfPointer(_name_3, true);
+ _builder.append(_selfPointer_3, " ");
+ _builder.append("int state, ");
+ String _boolType_1 = this.boolType();
+ _builder.append(_boolType_1, " ");
+ _builder.append(" handler, ");
+ String _boolType_2 = this.boolType();
+ _builder.append(_boolType_2, " ");
+ _builder.append(" skip_entry);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("void executeInitTransition(");
+ String _name_4 = ac.getName();
+ String _selfPointer_4 = this.langExt.selfPointer(_name_4, false);
+ _builder.append(_selfPointer_4, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* receiveEvent contains the main implementation of the FSM */");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("void receiveEvent(");
+ String _name_5 = ac.getName();
+ String _selfPointer_5 = this.langExt.selfPointer(_name_5, handleEvents);
+ _builder.append(_selfPointer_5, " ");
+ {
+ if (handleEvents) {
+ _builder.append("const etRuntime::InterfaceItemBase& ifitem, int evt, ");
+ String _voidPointer_1 = this.langExt.voidPointer();
+ _builder.append(_voidPointer_1, " ");
+ _builder.append(" generic_data");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
private CharSequence guard(final Transition tt, final String trigger, final ExpandedActorClass ac) {
if (tt instanceof TriggeredTransition) {
return _guard((TriggeredTransition)tt, trigger, ac);
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp
index 2208db4..42099f8 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp
@@ -52,12 +52,12 @@ void MSCLogger::addMessageSyncReturn(std::string source, std::string target,
void MSCLogger::addActorState(std::string actor, std::string state) {
if (filter->applyTo(actor))
- getCommandList().push_back("\t" + filter->reduceString(actor) + " >>> " + state);
+ commandList.push_back("\t" + filter->reduceString(actor) + " >>> " + state);
}
void MSCLogger::createLine(std::string source, std::string mid, std::string target, std::string message) {
if (filter->applyTo(source) && filter->applyTo(target)) {
- getCommandList().push_back( "\t"+filter->reduceString(source)+mid+filter->reduceString(target)+ " " + message);
+ commandList.push_back( "\t"+filter->reduceString(source)+mid+filter->reduceString(target)+ " " + message);
}
}
@@ -67,7 +67,10 @@ void MSCLogger::close() {
//TODO: error handling
// Create file
std::ofstream myfile;
- myfile.open (std::string("tmp/log/" + path + msc_name + ".seq").c_str(), std::ios::out);
+ //TODO: where to create the file
+ // std::string dir = "tmp/log"; doesn't work on windows
+ std::string dir = "";
+ myfile.open (std::string(dir + path + msc_name + ".seq").c_str(), std::ios::out);
if (myfile.is_open()) { /* ok, proceed with output */
saveMSCforTrace2UML(myfile);
myfile.close();
@@ -82,9 +85,9 @@ void MSCLogger::saveMSCforTrace2UML(std::ofstream& out) {
//TODO: errorhandling
out << "#generated MSC for Trace2UML";
out << std::endl ;
- std::list<std::string>::iterator it = getCommandList().begin();
- for ( ; it != getCommandList().end(); ++it) {
- out << *it << std::endl;
+ std::list<std::string>::iterator it = commandList.begin();
+ for ( ; it != commandList.end(); ++it) {
+ out << (*it) << std::endl;
}
// } catch (IOException e) {
// System.err.println("Error: " + e.getMessage());
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h
index 330dc80..51827d9 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h
@@ -38,7 +38,7 @@ public:
//TODO synchronized
void close();
- std::list<std::string> getCommandList() { return commandList; };
+ const std::list<std::string>& getCommandList() { return commandList; };
MSCFilter* getMSCFilter(){ return filter; };
private:
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
index 0f239d3..75fbff2 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
@@ -50,7 +50,7 @@ private:
IRTObject* m_parent;
std::string m_name;
- boolean m_running;
+ bool m_running;
// TODO: add internal message queue for less locks (faster thread internal
// messaging)
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp
index 95814c9..b3805dc 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp
@@ -12,7 +12,7 @@ namespace etRuntime {
ActorClassBase::ActorClassBase(IRTObject* parent, std::string name, Address ownAddr, Address systemPortPeerAddr)
: EventReceiver(parent, name),
IMessageReceiver(),
- m_state(),
+ m_state(0),
m_RTSystemPort(0),
m_className("noname"),
m_ownAddr(ownAddr),
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.cpp
index 7d32bac..c94b814 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.cpp
@@ -76,6 +76,12 @@ void SubSystemClassBase::stop() {
std::cout << "=== done stop actor instances" << std::endl;
}
+void SubSystemClassBase::runOnce() {
+ // run all message services one time
+ RTServices::getInstance().getMsgSvcCtrl().runOnce();
+
+}
+
void SubSystemClassBase::destroy() {
std::cout << "*** MainComponent " << this->getInstancePath() << "::destroy ***" << std::endl;
for (unsigned int i = 0; i < m_instances.size(); i++) {
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.h
index d6b1065..f537bd3 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemClassBase.h
@@ -35,6 +35,7 @@ public:
void start();
void stop();
+ void runOnce();
void destroy();
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp
index 8af196b..90b6425 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp
@@ -6,16 +6,54 @@
*/
#include "SubSystemRunnerBase.h"
+#include "SubSystemClassBase.h"
namespace etRuntime {
SubSystemRunnerBase::SubSystemRunnerBase() {
- // TODO Auto-generated constructor stub
-
}
SubSystemRunnerBase::~SubSystemRunnerBase() {
- // TODO Auto-generated destructor stub
}
+
+void SubSystemRunnerBase::waitMultiThreaded() {
+ // waiting for command line input
+ std::string token = "";
+ std::cout << "type 'quit' to exit" << std::endl;
+ while (token != "quit") {
+ std::getline(std::cin, token);
+ std::cout << "echo: " << token << std::endl;
+ }
+}
+
+void SubSystemRunnerBase::waitAndPollSingleThreaded(SubSystemClassBase& mainComponent) {
+ mainComponent.runOnce();
+
+ std::string token = "";
+ std::cout << "type 'quit' to exit" << std::endl;
+ #ifndef WIN32
+ pollfd cinfd[1];
+ // Theoretically this should always be 0, but one fileno call isn't going to hurt, and if
+ // we try to run somewhere that stdin isn't fd 0 then it will still just work
+ cinfd[0].fd = fileno(stdin);
+ cinfd[0].events = POLLIN;
+ #else
+ HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
+ #endif
+ while (token != "quit")
+ {
+ #ifndef WIN32
+ if (poll(cinfd, 1, 1000))
+ #else
+ // doesn't work as expected:
+ if (WaitForSingleObject(h, 100) == WAIT_OBJECT_0)
+ #endif
+ {
+ std::getline(std::cin, token);
+ std::cout << "echo: " << token << std::endl;
+ }
+ mainComponent.runOnce();
+ }
+}
} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.h
index ffc6d23..d44131a 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.h
@@ -11,9 +11,14 @@
#define SUBSYSTEMRUNNERBASE_H_
#include <iostream>
+#ifdef WIN32
+#include <windows.h>
+#endif
namespace etRuntime {
+class SubSystemClassBase;
+
class SubSystemRunnerBase {
public:
SubSystemRunnerBase();
@@ -23,16 +28,13 @@ public:
* blocks until the String "quit" is entered on the console
*/
protected:
- static void waitForQuit() {
- // waiting for command line input
- std::string token = "";
- std::cout << "type 'quit' to exit" << std::endl;
- while (token != "quit") {
- std::getline(std::cin, token);
- std::cout << "echo: " << token << std::endl;
- }
+ static void waitForQuit(SubSystemClassBase& mainComponent) {
+ waitAndPollSingleThreaded(mainComponent);
}
+private:
+ static void waitMultiThreaded();
+ static void waitAndPollSingleThreaded(SubSystemClassBase& mainComponent);
};
} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etDatatypes.h
index 481139d..67c76ae 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etDatatypes.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etDatatypes.h
@@ -40,7 +40,7 @@ typedef double float64;
/* boolean datatypes and values */
//typedef char bool; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/
-typedef bool boolean;
+//typedef bool boolean;
#ifndef TRUE
#define TRUE 1
#endif