[SystemCSim] null-check condition content before adding to graph content

Signed-off-by: Reiser Sebastian <Sebastian.Reiser@de.bosch.com>
Signed-off-by: Reiser Sebastian <Sebastian.Reiser@de.bosch.com
diff --git a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/stimuli/StimulusBaseTransformer.xtend b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/stimuli/StimulusBaseTransformer.xtend
index e08c0ac..bcd5021 100644
--- a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/stimuli/StimulusBaseTransformer.xtend
+++ b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/stimuli/StimulusBaseTransformer.xtend
@@ -22,16 +22,16 @@
 abstract class StimulusBaseTransformer extends BaseTransformer {
 	
 	
-	def getName(Stimulus stimulus){
-		return stimulus.name
+	def getName(Stimulus stim){
+		return stim.name
 	}
 
-	def getModulePath(Stimulus stimulus) {
-		return AmaltheaTransformer.getModulePath() + "/stimuliModel/" + getName(stimulus)
+	def getModulePath(Stimulus stim) {
+		return AmaltheaTransformer.getModulePath() + "/stimuliModel/" + getName(stim)
 	}
 
-	def getFunctionDef(Stimulus stimulus) {
-		return "get_" + stimulus.name + "()"
+	def getFunctionDef(Stimulus stim) {
+		return "get_" + stim.name + "()"
 	}
 		
 
diff --git a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/IActivityGraphItemContainerTransformer.xtend b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/IActivityGraphItemContainerTransformer.xtend
index ff20768..0fdc9bc 100644
--- a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/IActivityGraphItemContainerTransformer.xtend
+++ b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/IActivityGraphItemContainerTransformer.xtend
@@ -61,8 +61,10 @@
 		}
 		
 		def addAll(ModeConditionBuffer other){
-			activityItemIncludes.addAll(other.includes)
-			activityItemCalls.addAll(other.conditions)
+			if (other !== null){
+				activityItemIncludes.addAll(other.includes)
+				activityItemCalls.addAll(0, other.conditions) //prepend conditions for readability
+			}
 		}
 		
 		def LinkedHashSet<String> getIncludes(){
diff --git a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/ModeSwitchEntryTransformer.xtend b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/ModeSwitchEntryTransformer.xtend
index 8402106..16c378f 100644
--- a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/ModeSwitchEntryTransformer.xtend
+++ b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/ModeSwitchEntryTransformer.xtend
@@ -15,8 +15,10 @@
 
 package org.eclipse.app4mc.amlt2systemc.m2t.transformers.sw
 
+import com.google.inject.Inject
 import org.eclipse.app4mc.amalthea.model.ModeSwitchDefault
 import org.eclipse.app4mc.amalthea.model.ModeSwitchEntry
+import org.eclipse.app4mc.amlt2systemc.m2t.transformers.common.ModeConditionTransformer
 
 /** Target code example
  * 
@@ -36,6 +38,8 @@
 
 class ModeSwitchEntryTransformer extends IActivityGraphItemContainerTransformer {
 	
+	@Inject ModeConditionTransformer modeConditionTransformer
+	
 	static var modeDefaultCnt = 0;
 	
 	private static def getName(ModeSwitchEntry modeSwitchEntry){
@@ -48,8 +52,10 @@
 
 	def void transform(ModeSwitchEntry modeSwitchEntry, ActivityGraphBuffer content) {
 		val name =  getName(modeSwitchEntry)
-		content.addBody("ModeSwitchEntry " + name + "(\"" + name + "\");\n")	
+		content.addBody("ModeSwitchEntry " + name + "(\"" + name + "\");\n")
+		val modeConditioContents = modeConditionTransformer.transformCondition(modeSwitchEntry.condition, name, false);
 		val activityGraphContents = transformItems( modeSwitchEntry, name, content.module, content.parentIsPointer)
+		activityGraphContents.addAll(modeConditioContents) //merge condition and activity graph content before adding
 		content.getIncludes().addAll(activityGraphContents.getIncludes())
 		content.getSource().addAll(activityGraphContents.getSource())
 		content.addBody(content.instanceName + ".addEntry(" + name  + ");")
diff --git a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/RunnableTransformer.xtend b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/RunnableTransformer.xtend
index 9ca7827..5f283f6 100644
--- a/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/RunnableTransformer.xtend
+++ b/simulation_generator/app4mc.sim/plugins/org.eclipse.app4mc.amlt2systemc.m2t/src/org/eclipse/app4mc/amlt2systemc/m2t/transformers/sw/RunnableTransformer.xtend
@@ -20,7 +20,6 @@
 import org.eclipse.app4mc.amalthea.model.Runnable
 import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit
 import org.eclipse.app4mc.amlt2systemc.m2t.transformers.common.ModeConditionTransformer
-import org.eclipse.app4mc.amlt2systemc.m2t.transformers.common.ModeConditionTransformer.ModeConditionBuffer
 import org.eclipse.app4mc.transformation.util.OutputBuffer
 
 @Singleton
@@ -50,7 +49,11 @@
 		// write header file
 		outputBuffer.appendTo("INC", it.module, toH(runnable))
 		// write implementation file
-		outputBuffer.appendTo("SRC", it.module, toCpp(runnable))
+		val graphContent = transformItems(runnable.activityGraph, getName(runnable), getModuleName(runnable), true)
+		val conditionContent = 
+			modeConditionTransformer.transformCondition(runnable.executionCondition, getName(runnable), true)
+		graphContent.addAll(conditionContent)
+		outputBuffer.appendTo("SRC", it.module, toCpp(runnable, graphContent))
 	}
 
 	private def String toH(Runnable runnable) '''
@@ -58,13 +61,7 @@
 		std::shared_ptr<Runnable> «getFunctionDef(runnable)»;
 	'''
 
-	private def String toCpp(Runnable runnable) '''
-		«val runnableName = getName(runnable)»
-		«val graphContent = transformItems(runnable.activityGraph, runnableName, getModuleName(runnable), true)»
-		«val conditionContent = 
-			modeConditionTransformer.transformCondition(runnable.executionCondition, getName(runnable), true)»
-		«val tmp = graphContent.includes.addAll(conditionContent.includes)»
-	
+	private def String toCpp(Runnable runnable, ActivityGraphBuffer graphContent) '''
 		#include <systemc>
 		#include "APP4MCsim.h"
 		#include "«getModuleName(runnable)».h"	
@@ -72,19 +69,18 @@
 			«include»
 		«ENDFOR»
 		
-		std::shared_ptr<Runnable> «runnableName» = nullptr;
+		std::shared_ptr<Runnable> «getName(runnable)» = nullptr;
 		
 		std::shared_ptr<Runnable>  «getFunctionDef(runnable)» {
 		
-			if («runnableName» == nullptr) {
+			if («getName(runnable)» == nullptr) {
 				//initialize
-				«runnableName» = std::make_shared<Runnable>("«runnableName»");
-				«ModeConditionBuffer.getConditionSource(conditionContent)»
+				«getName(runnable)» = std::make_shared<Runnable>("«getName(runnable)»");
 				«FOR source : graphContent.getSource()»
 					«source»
 				«ENDFOR»
 			}
-			return «runnableName»;
+			return «getName(runnable)»;
 		}
 		
 	'''