Browse Source

Almost working for rate.sa as well. Need to fix sourcedependency. A canonical version has been hand-made, as the canonicalgenerator was not able to handle it.
Fixed an issue in canonicalgenerator where CurrentTime was not used.

Refactored.

Casper Thule 6 years ago
parent
commit
1ba0f28d3d
17 changed files with 741 additions and 563 deletions
  1. 8 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  2. 0 25
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/loop/modelDescription.xml
  3. BIN
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/LoopSA.fmu
  4. 36 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/rate.sa
  5. 46 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/rate_canonical.sa
  6. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InputOutputRuleType.java
  7. 3 6
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InOutRulesBlockResult.java
  8. 7 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/RuleType.java
  9. 42 33
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend
  10. 459 415
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend
  11. 0 7
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/GeneralConditionSwitch.xtend
  12. 28 10
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend
  13. 20 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend
  14. 78 60
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend
  15. 2 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/rate.sa
  16. 6 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationGeneratorTest.xtend
  17. 5 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/generator/SemanticAdaptationCanonicalGenerator.xtend

+ 8 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -53,6 +53,14 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Test def loop() {
 		__parseNoErrors('test_input/single_folder_spec/loop/loop_canonical.sa', 'generated', "loop");
 	}
+	
+	@Test def rate() {
+		__parseNoErrors('test_input/single_folder_spec/rate/rate.sa', 'generated', "rate");
+	}
+	
+	@Test def rate_canonical() {
+		__parseNoErrors('test_input/single_folder_spec/rate/rate_canonical.sa', 'generated', "rate_canonical");
+	}
 
 	def __parseNoErrorsWithValidation(String directory, String filename) {
 		val model = __parse(filename);

+ 0 - 25
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/loop/modelDescription.xml

@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?><fmiModelDescription fmiVersion="2.0" guid="570bcfd2-d87a-4ab7-8d34-25bd0df92501" modelName="WindowSA" variableNamingConvention="flat">
-    <ModelVariables>
-        <ScalarVariable causality="input" name="reaction_force" valueReference="0" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="input" name="displacement" valueReference="1" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="input" name="speed" valueReference="2" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="output" name="disp" valueReference="3" variability="continuous">
-            <Real/>
-        </ScalarVariable>
-        <ScalarVariable causality="output" name="tau" valueReference="4" variability="continuous">
-            <Real/>
-        </ScalarVariable>
-    </ModelVariables>
-    <ModelStructure>
-        <Outputs>
-            <Unknown dependencies="" index="4"/>
-            <Unknown dependencies="" index="5"/>
-        </Outputs>
-    </ModelStructure>
-</fmiModelDescription>

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/LoopSA.fmu


+ 36 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/rate.sa

@@ -0,0 +1,36 @@
+semantic adaptation reactive moore RateSA rate_sa
+at "./path/to/RateSA.fmu"
+
+	for inner fmu LoopSA loop_sa
+		at "./test_input/single_folder_spec/rate/LoopSA.fmu"
+		with input ports displacement (rad), speed (rad/s)
+		with output ports tau (N.m)
+	
+input ports speed
+output ports tau <- loop_sa.tau
+
+param 	RATE := 10;
+
+control var previous_speed := 0;
+control rules {
+	var micro_step := H/RATE;
+	var inner_time := t;
+	
+	for (var iter in 0 .. RATE) { 
+		do_step(loop_sa,inner_time,micro_step);
+		inner_time := inner_time + micro_step;	
+	}
+	
+	previous_speed := current_speed;
+	return H;
+}
+
+in var current_speed := 0;
+in rules {
+	true -> {
+		current_speed := speed;
+	} --> {
+		loop_sa.speed := previous_speed + (current_speed - previous_speed)*(dt + h);
+	};
+}
+

+ 46 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/rate_canonical.sa

@@ -0,0 +1,46 @@
+semantic adaptation reactive moore RateSA rate_sa
+at "./path/to/RateSA.fmu"
+
+	for inner fmu LoopSA loop_sa
+		at "./test_input/single_folder_spec/rate/LoopSA.fmu"
+		with input ports displacement (rad), speed (rad/s)
+		with output ports tau (N.m)
+	
+input ports speed
+output ports tau
+
+param 	RATE := 10,
+		INIT_LOOP_SA_TAU := 0.0;
+
+control var previous_speed := 0;
+control rules {
+	var micro_step := H/RATE;
+	var inner_time := t;
+	
+	for (var iter in 0 .. RATE) { 
+		do_step(loop_sa,inner_time,micro_step);
+		inner_time := inner_time + micro_step;	
+	}
+	
+	previous_speed := current_speed;
+	return H;
+}
+
+in var current_speed := 0;
+in rules {
+	true -> {
+		current_speed := speed;
+	} --> {
+		loop_sa.speed := previous_speed + (current_speed - previous_speed)*(dt + h);
+	};
+}
+
+out var stored_loop_sa_tau := INIT_LOOP_SA_TAU;
+out rules {
+	true -> {
+		stored_loop_sa_tau := loop_sa.tau;
+	} --> {
+		rate_sa.tau := stored_loop_sa_tau;
+	};
+}
+

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InputOutputRuleType.java

@@ -1,6 +1,6 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
-public enum InputOutputRuleType {
+public enum IORuleType {
 	Input,
 	Output
 }

+ 3 - 6
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InOutRulesBlockResult.java

@@ -6,14 +6,11 @@ import java.util.List;
 import org.eclipse.xtext.xbase.lib.Pair;
 
 public class InOutRulesBlockResult extends RulesBlockResult {
-	public final LinkedHashMap<String, GlobalInOutVariable> gVars;
-	public final String constructorInitialization;
+	//public final LinkedHashMap<String, GlobalInOutVariable> gVars;
+	//public final String constructorInitialization;
 
-	public InOutRulesBlockResult(String generatedCpp, List<String> functionSignatures,
-			LinkedHashMap<String, GlobalInOutVariable> gVars, String constructorInitialization)
+	public InOutRulesBlockResult(String generatedCpp, List<String> functionSignatures)
 	{
 		super(generatedCpp, functionSignatures);
-		this.gVars = gVars;
-		this.constructorInitialization = constructorInitialization;
 	}
 }

+ 7 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/RuleType.java

@@ -0,0 +1,7 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
+
+public enum RuleType {
+	Input,
+	Output,
+	Control
+}

+ 42 - 33
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend

@@ -29,13 +29,15 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
 		LinkedHashMap<String, SAScalarVariable> SASVs,
 		LinkedHashMap<String, GlobalInOutVariable> params,
-		LinkedHashMap<String, GlobalInOutVariable> outVars
+		LinkedHashMap<String, GlobalInOutVariable> inVars,
+		LinkedHashMap<String, GlobalInOutVariable> outVars,
+		LinkedHashMap<String, GlobalInOutVariable> crtlVars
 	) {
-		super(adaptationClassName, adaptationName, "", mSVars, SASVs, params, outVars);
+		super(adaptationClassName, adaptationName, "", mSVars, SASVs, params, inVars, outVars, crtlVars);
 	}
 
 	override ReturnInformation caseAssignment(Assignment object) {
-		
+
 		if (object.lvalue.owner !== null) {
 			var retVal = new ReturnInformation();
 			retVal.code = '''setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr).code»)'''
@@ -48,30 +50,37 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 	override ReturnInformation caseVariable(Variable object) {
 		var retVal = new ReturnInformation();
 
-		// H and t are protected variables.
-		if ((object.owner === null || object.owner.name == this.adaptationName) &&
-			(object.ref.name == "H" || object.ref.name == "t")) {
-			retVal.type = SVType.Real;
-			retVal.forceType = true;
-			retVal.code = object.ref.name;
-		} else {
-			retVal = super.caseVariable(object);
-		}
-
+		// H and t are protected variables and are handles by caseStepSize and caseCurrentTime respectively.
+//		if ((object.owner === null || object.owner.name == this.adaptationName) &&
+//			(object.ref.name == "H" || object.ref.name == "t")) {
+//			retVal.type = SVType.Real;
+//			retVal.forceType = true;
+//			retVal.code = object.ref.name;
+//		} else {
+		retVal = super.caseVariable(object);
+//		}
 		return retVal;
 	}
 
-	override ReturnInformation caseControlRuleBlock(ControlRuleBlock object) {
-		this.globalDeclaration = true;
-
-		var retVal = new ReturnInformation();
-
-		// Get the global variables added to globalVars
-		for (gVar : object.globalCtrlVars) {
-			constructorInitialization += doSwitch(gVar).code;
+	public def LinkedHashMap<String, GlobalInOutVariable> getGlobalVars(ControlRuleBlock object) {
+		if (object.globalCtrlVars !== null) {
+			this.globalDeclaration = true;
+			for (gVar : object.globalCtrlVars)
+				doSwitch(gVar);
+			this.globalDeclaration = false;
 		}
+		return this.gVars;
+	}
 
-		this.globalDeclaration = false;
+	override ReturnInformation caseControlRuleBlock(ControlRuleBlock object) {
+		var retVal = new ReturnInformation();
+//
+//		// Get the global variables added to globalVars
+//		this.globalDeclaration = true;
+//		for (gVar : object.globalCtrlVars) {
+//			constructorInitialization += doSwitch(gVar).code;
+//		}
+//		this.globalDeclaration = false;
 		retVal.appendCode(doSwitch(object.rule).code);
 
 		return retVal;
@@ -115,16 +124,18 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 	override ReturnInformation caseStepSize(StepSize object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''H''';
+		retVal.type = SVType.Real;
+		retVal.forceType = true;
 		return retVal;
 	}
 
 	override ReturnInformation caseCurrentTime(CurrentTime object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''t''';
+		retVal.type = SVType.Real;
+		retVal.forceType = true;
 		return retVal;
 	}
-	
-	
 
 	override ReturnInformation caseSaveState(SaveState object) {
 		var retVal = new ReturnInformation();
@@ -132,22 +143,20 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 		saveState(«object.fmu.name»)''')
 		return retVal;
 	}
-	
-	override ReturnInformation caseClose(Close object)
-	{
+
+	override ReturnInformation caseClose(Close object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''is_close(«object.args.map[e | doSwitch(e).code].join(", ")»)''';		
+		retVal.code = '''is_close(«object.args.map[e | doSwitch(e).code].join(", ")»)''';
 		return retVal;
 	}
-	
-	override ReturnInformation caseBreakStatement(BreakStatement object){
+
+	override ReturnInformation caseBreakStatement(BreakStatement object) {
 		var retVal = new ReturnInformation();
 		retVal.appendCode('''break''')
 		return retVal;
 	}
-	
-	override ReturnInformation caseRollback(Rollback object)
-	{
+
+	override ReturnInformation caseRollback(Rollback object) {
 		var retVal = new ReturnInformation();
 		retVal.appendCode('''rollback(«object.fmu.name»)''')
 		return retVal;

+ 459 - 415
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -29,8 +29,11 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
 import java.util.List
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ParamDeclarations
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.InputOutputRuleType
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.InnerFMUData
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.IORuleType
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.RuleType
+import org.eclipse.emf.ecore.EObject
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
 
 class CppGenerator extends SemanticAdaptationGenerator {
 	private var IFileSystemAccess2 fsa;
@@ -56,14 +59,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			val adapExternalName = adap.type.name;
 
 			// List of FMUs with a pairing between its name and its type.name.
-			//var ArrayList<Pair<String, String>> fmus = newArrayList();
 			var ArrayList<InnerFMUData> innerFMUsData = newArrayList();
 
-			// TODO: Currently only 1 inner fmu is supported
 			val innerFmus = adap.inner.eAllContents.toList.filter(InnerFMU);
-//			if (innerFmus.size > 1) {
-//				throw new IncorrectAmountOfElementsException("Only one InnerFmu is supported.")
-//			}
+
 			if (innerFmus.isEmpty) {
 				throw new IncorrectAmountOfElementsException("The adaptation does not contain any InnerFMUs.")
 			}
@@ -78,14 +77,14 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			/*
 			 * Loading the FMU defined in InnerFMU, the related model description file and its scalar variables.
 			 */
-			// TODO: Add support for multiple inner fmus
+			// TODO: Add support for multiple inner fmus. Only partially supported
 			var ModelDescription md;
 			for (fmu : adap.inner.eAllContents.toList.filter(InnerFMU)) {
 				val fmuFile = new File(fmu.path.replace('\"', ''));
 				this.resourcePaths.add(fmuFile);
 				md = new ModelDescription(fmu.name, fmu.type.name, fmuFile);
 				innerFMUsData.add(new InnerFMUData(fmu.name, fmu.type.name, md.guid));
-				//fmus.add(fmu.name -> fmu.type.name);
+				// fmus.add(fmu.name -> fmu.type.name);
 				val LinkedHashMap<String, MappedScalarVariable> mSV = newLinkedHashMap();
 				for (sv : md.sv.values) {
 					var mappedSv = new MappedScalarVariable(sv);
@@ -104,274 +103,286 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 			/*
 			 * This map contains all the ScalarVariables for the semantic adaptation. 
-			 * The are not populated yet, but they will be during the compilation of the in and out rule blocks. 
+			 * Some of them are not populated yet, but they will be during the compilation of the in and out rule blocks. 
 			 */
 			var LinkedHashMap<String, SAScalarVariable> SASVs = calcSASVsFromInportsOutports(adapInteralRefName,
-				adap.inports, adap.outports)
+				adap.inports, adap.outports, mappedScalarVariables)
+				
+			
+			//val outPortsWithSrcDep = adap.outports.filter[x|x.sourcedependency !== null];
 
 			// C++ defines for accessing semantic adaptation scalar variables 
 			val String SADefines = calcSADefines(SASVs.values);
 
-			// Compile the transparent in mappings
+			// The three rule blocks
+			val inRuleBlock = adap.in;
+			val outRuleBlock = adap.out;
+			val crtlRuleBlock = adap.control;
 
+			// Get the control vars, in vars, and out vars				
+			val inVars = if(inRuleBlock !== null) compileRuleBlockVars(inRuleBlock.globalInVars, params);
+			val outVars = if(outRuleBlock !== null) compileRuleBlockVars(outRuleBlock.globalOutVars, params);
+			val crtlVars = if(crtlRuleBlock !== null) compileRuleBlockVars(crtlRuleBlock.globalCtrlVars, params);
+
+//			
 			// Compile the in rules
-			val inRuleResult = compileInOutRuleBlocks(InputOutputRuleType.Input, adaptation.eAllContents.toIterable.filter(
+			val inRuleResult = compileInOutRuleBlocks(IORuleType.Input, adaptation.eAllContents.toIterable.filter(
 				InRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs,
-				params);
+				params, inVars.value, outVars.value, crtlVars.value);
 
 			// Compile the out rules
-			val outRuleResult = compileInOutRuleBlocks(InputOutputRuleType.Output, adaptation.eAllContents.toIterable.
-				filter(OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables,
-				SASVs, params);
+			val outRuleResult = compileInOutRuleBlocks(IORuleType.Output, adaptation.eAllContents.toIterable.filter(
+				OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs,
+				params, inVars.value, outVars.value, crtlVars.value);
 
 			// Compile the Control Rules. These might use the out vars, so pass these along.
 			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
-				adapClassName, adapInteralRefName, mappedScalarVariables, SASVs, params, outRuleResult.gVars);
+				adapClassName, adapInteralRefName, mappedScalarVariables, SASVs, params, inVars.value, outVars.value,
+				crtlVars.value);
+
+				/*
+				 * Compile the constructor, destructor and initialize functions
+				 */
+				val String deAndConstructorAndInitializeSource = compileDeAndConstructorAndInitialize(
+					adapClassName,
+					innerFMUsData,
+					md.guid,
+					paramsConstructorSource,
+					inVars.key,
+					outVars.key,
+					crtlVars.key
+				);
 
-			/*
-			 * Compile the constructor, destructor and initialize functions
-			 */
-			val String deAndConstructorAndInitializeSource = compileDeAndConstructorAndInitialize(
-				adapClassName,
-				innerFMUsData,
-				md.guid,
-				paramsConstructorSource,
-				inRuleResult.constructorInitialization,
-				outRuleResult.constructorInitialization,
-				crtlRuleResult.constructorInitialization
-			);
+				/*
+				 * Compile getRuleThis function
+				 */
+				val String getRuleThisSource = compileGetRuleThis(adapClassName);
+
+				/*
+				 * The in and out rules have populated the semantic adaptation scalar variables we can generate the getFmiValue* and setFmiValue functions.
+				 */
+				val String getFuncsSource = compileGetFmiValueFunctions(adapClassName, SASVs);
+				val String setFuncsSource = compileSetFmiValueFunctions(adapClassName, SASVs);
+
+				// Compile the source file
+				val String sourceInclude = '''#include "«adapClassName».h"''';
+				val sourceFile = compileSource(
+					sourceInclude,
+					deAndConstructorAndInitializeSource,
+					getRuleThisSource,
+					getFuncsSource,
+					setFuncsSource,
+					inRuleResult.generatedCpp,
+					outRuleResult.generatedCpp,
+					crtlRuleResult.generatedCpp
+				);
+				fsa.generateFile(adapClassName + ".cpp", sourceFile);
+
+				// Merge the global variables for use in compiling the header file.
+				// TODO: Check for duplicates
+				var LinkedHashMap<String, GlobalInOutVariable> allGVars = newLinkedHashMap();
+				allGVars.putAll(params);
+				allGVars.putAll(inVars.value);
+				allGVars.putAll(outVars.value);
+				allGVars.putAll(crtlVars.value);
+				
+				// Compile the header file
+				val headerFile = compileHeader(
+					adapClassName,
+					fmusDefines,
+					SADefines,
+					inRuleResult.functionSignatures,
+					outRuleResult.functionSignatures,
+					crtlRuleResult.functionSignatures,
+					allGVars,
+					innerFMUsData,
+					SASVs.values.map[CalcSVar()].toList
+				);
+				fsa.generateFile(adapClassName + ".h", headerFile);
 
-			/*
-			 * Compile getRuleThis function
-			 */
-			val String getRuleThisSource = compileGetRuleThis(adapClassName);
+				// Compile the model description file
+				val modelDescCreator = new ModelDescriptionCreator(adapExternalName);
+				val modelDescription = modelDescCreator.generateModelDescription(SASVs.values);
+				fsa.generateFile("modelDescription.xml", modelDescription);
 
-			/*
-			 * The in and out rules have populated the semantic adaptation scalar variables we can generate the getFmiValue* and setFmiValue functions.
-			 */
-			val String getFuncsSource = compileGetFmiValueFunctions(adapClassName, SASVs);
-			val String setFuncsSource = compileSetFmiValueFunctions(adapClassName, SASVs);
-
-			// Compile the source file
-			val String sourceInclude = '''#include "«adapClassName».h"''';
-			val sourceFile = compileSource(
-				sourceInclude,
-				deAndConstructorAndInitializeSource,
-				getRuleThisSource,
-				getFuncsSource,
-				setFuncsSource,
-				inRuleResult.generatedCpp,
-				outRuleResult.generatedCpp,
-				crtlRuleResult.generatedCpp
-			);
-			fsa.generateFile(adapClassName + ".cpp", sourceFile);
-
-			// Merge the global variables for use in compiling the header file.
-			// TODO: Check for duplicates
-			var LinkedHashMap<String, GlobalInOutVariable> allGVars = newLinkedHashMap();
-			allGVars.putAll(params);
-			allGVars.putAll(outRuleResult.gVars);
-			allGVars.putAll(inRuleResult.gVars);
-			allGVars.putAll(crtlRuleResult.gVars);
-
-			// Compile the header file
-			val headerFile = compileHeader(
-				adapClassName,
-				fmusDefines,
-				SADefines,
-				inRuleResult.functionSignatures,
-				outRuleResult.functionSignatures,
-				crtlRuleResult.functionSignatures,
-				allGVars,
-				innerFMUsData,
-				SASVs.values.map[CalcSVar()].toList
-			);
-			fsa.generateFile(adapClassName + ".h", headerFile);
-
-			// Compile the model description file
-			val modelDescCreator = new ModelDescriptionCreator(adapExternalName);
-			val modelDescription = modelDescCreator.generateModelDescription(SASVs.values);
-			fsa.generateFile("modelDescription.xml", modelDescription);
-
-			// Compile the fmu.cpp file
-			val fmuCppFile = StaticGenerators.GenFmuCppFile(adapClassName);
-			fsa.generateFile("Fmu.cpp", fmuCppFile);
+				// Compile the fmu.cpp file
+				val fmuCppFile = StaticGenerators.GenFmuCppFile(adapClassName);
+				fsa.generateFile("Fmu.cpp", fmuCppFile);
 
+			}
 		}
-	}
 
-	def String compileParams(LinkedHashMap<String, GlobalInOutVariable> gVars, EList<ParamDeclarations> params) {
-		val paramsConditionSwitch = new ParamConditionSwitch(gVars);
-		var String paramsConstructorSource = "";
-		for (paramDecl : params) {
-			val doSwitchRes = paramsConditionSwitch.doSwitch(paramDecl);
-			paramsConstructorSource += doSwitchRes.code;
+		def String compileParams(LinkedHashMap<String, GlobalInOutVariable> gVars, EList<ParamDeclarations> params) {
+			val paramsConditionSwitch = new ParamConditionSwitch(gVars);
+			var String paramsConstructorSource = "";
+			for (paramDecl : params) {
+				val doSwitchRes = paramsConditionSwitch.doSwitch(paramDecl);
+				paramsConstructorSource += doSwitchRes.code;
+			}
+			return paramsConstructorSource;
 		}
-		return paramsConstructorSource;
-	}
 
-	def calcSADefines(Collection<SAScalarVariable> variables) {
-		var ArrayList<String> defines = newArrayList();
+		def calcSADefines(Collection<SAScalarVariable> variables) {
+			var ArrayList<String> defines = newArrayList();
 
-		for (SASV : variables) {
-			defines.add("#define " + SASV.defineName + " " + SASV.valueReference);
-		}
+			for (SASV : variables) {
+				defines.add("#define " + SASV.defineName + " " + SASV.valueReference);
+			}
 
-		return defines.join("\n");
-	}
+			return defines.join("\n");
+		}
 
-	def calcDefines(LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> map) {
-		var ArrayList<String> defines = newArrayList();
+		def calcDefines(LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> map) {
+			var ArrayList<String> defines = newArrayList();
 
-		for (fmuEntries : map.entrySet) {
-			for (MappedScalarVariable mSV : fmuEntries.value.values) {
-				defines.add("#define " + mSV.define + " " + mSV.valueReference);
+			for (fmuEntries : map.entrySet) {
+				for (MappedScalarVariable mSV : fmuEntries.value.values) {
+					defines.add("#define " + mSV.define + " " + mSV.valueReference);
+				}
 			}
-		}
 
-		return defines.join("\n");
-	}
+			return defines.join("\n");
+		}
 
-	// Compiles the final source file
-	def String compileSource(String include, String constructor, String getRuleThis, String getFunctions,
-		String setFunctions, String inFunctions, String outFunctions, String controlFunction) {
-		return '''
-			«include»
-			
-			namespace adaptation 
-			{
-				«constructor»
-				
-				«getRuleThis»
-				
-				«getFunctions»
+		// Compiles the final source file
+		def String compileSource(String include, String constructor, String getRuleThis, String getFunctions,
+			String setFunctions, String inFunctions, String outFunctions, String controlFunction) {
+			return '''
+				«include»
 				
-				«setFunctions»
-				
-				«inFunctions»
+				namespace adaptation 
+				{
+					«constructor»
+					
+					«getRuleThis»
+					
+					«getFunctions»
+					
+					«setFunctions»
+					
+					«inFunctions»
+					
+					«controlFunction»
+					
+					«outFunctions»
 				
-				«controlFunction»
+				}
 				
-				«outFunctions»
-			
-			}
-			
-		'''
-	}
+			'''
+		}
 
-	/*
-	 * Compiles the header file split into two: The first part contains the includes and using namespace definitions and start the ,
-	 * the second part contains the class
-	 */
-	def String compileHeader(String adapClassName, String fmusDefines, String SADefines, List<String> inRulesFuncSig,
-		List<String> outRulesFuncSig, List<String> crtlRulesFuncSig,
-		LinkedHashMap<String, GlobalInOutVariable> globalVariables, ArrayList<InnerFMUData> fmus,
-		Collection<ScalarVariable> sVars) {
-		return '''
-			
-				#ifndef SRC_«adapClassName.toUpperCase»_H
-				#define SRC_«adapClassName.toUpperCase»_H
-			
-				#include "SemanticAdaptation.h"
-				#include <memory>
-				#include "Fmu.h"
+		/*
+		 * Compiles the header file split into two: The first part contains the includes and using namespace definitions and start the ,
+		 * the second part contains the class
+		 */
+		def String compileHeader(String adapClassName, String fmusDefines, String SADefines,
+			List<String> inRulesFuncSig, List<String> outRulesFuncSig, List<String> crtlRulesFuncSig,
+			LinkedHashMap<String, GlobalInOutVariable> globalVariables, ArrayList<InnerFMUData> fmus,
+			Collection<ScalarVariable> sVars) {
+			return '''
 				
-				using namespace std;
-				using namespace fmi2;
+					#ifndef SRC_«adapClassName.toUpperCase»_H
+					#define SRC_«adapClassName.toUpperCase»_H
 				
-				namespace adaptation
-				{
+					#include "SemanticAdaptation.h"
+					#include <memory>
+					#include "Fmu.h"
 					
-					«fmusDefines»
+					using namespace std;
+					using namespace fmi2;
 					
-					«SADefines»
-				
-					class «adapClassName» : public SemanticAdaptation<«adapClassName»>, public enable_shared_from_this<«adapClassName»>
+					namespace adaptation
 					{
-						public:
-							«adapClassName»(shared_ptr<std::string> fmiInstanceName, shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions);
-							void initialize();
-							virtual ~«adapClassName»();
-							
-							void setFmiValue(fmi2ValueReference id, int value);
-							void setFmiValue(fmi2ValueReference id, bool value);
-							void setFmiValue(fmi2ValueReference id, double value);
-							void setFmiValue(fmi2ValueReference id, string value);
 						
-							int getFmiValueInteger(fmi2ValueReference id);
-							bool getFmiValueBoolean(fmi2ValueReference id);
-							double getFmiValueReal(fmi2ValueReference id);
-							string getFmiValueString(fmi2ValueReference id);
-							
-						private:
-							
-							«adapClassName»* getRuleThis();
-							
-							/*in rules*/
-							«inRulesFuncSig.map[x | x+";"].join("\n")»
-							
-							/*out rules*/
-							«outRulesFuncSig.map[x | x+";"].join("\n")»
-							
-							«crtlRulesFuncSig.map[x | x+";"].join("\n")»
-							
-							«FOR fmu : fmus»
-								shared_ptr<FmuComponent> «fmu.name»;
-							«ENDFOR»
-							
-							«FOR sv : sVars»
-								«Conversions.fmiTypeToCppType(sv.type)» «sv.name»;
-								«IF sv.causality == SVCausality.input»
-									bool isSet«sv.name»;
-								«ENDIF»
-							«ENDFOR»
+						«fmusDefines»
+						
+						«SADefines»
+					
+						class «adapClassName» : public SemanticAdaptation<«adapClassName»>, public enable_shared_from_this<«adapClassName»>
+						{
+							public:
+								«adapClassName»(shared_ptr<std::string> fmiInstanceName, shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions);
+								void initialize();
+								virtual ~«adapClassName»();
+								
+								void setFmiValue(fmi2ValueReference id, int value);
+								void setFmiValue(fmi2ValueReference id, bool value);
+								void setFmiValue(fmi2ValueReference id, double value);
+								void setFmiValue(fmi2ValueReference id, string value);
 							
-							«FOR v : globalVariables.entrySet»
-								«Conversions.fmiTypeToCppType(v.value.type)» «v.key»;
-							«ENDFOR»
-					};
-				}
-				
-				#endif
-		''';
-	}
+								int getFmiValueInteger(fmi2ValueReference id);
+								bool getFmiValueBoolean(fmi2ValueReference id);
+								double getFmiValueReal(fmi2ValueReference id);
+								string getFmiValueString(fmi2ValueReference id);
+								
+							private:
+								
+								«adapClassName»* getRuleThis();
+								
+								/*in rules*/
+								«inRulesFuncSig.map[x | x+";"].join("\n")»
+								
+								/*out rules*/
+								«outRulesFuncSig.map[x | x+";"].join("\n")»
+								
+								«crtlRulesFuncSig.map[x | x+";"].join("\n")»
+								
+								«FOR fmu : fmus»
+									shared_ptr<FmuComponent> «fmu.name»;
+								«ENDFOR»
+								
+								«FOR sv : sVars»
+									«Conversions.fmiTypeToCppType(sv.type)» «sv.name»;
+									«IF sv.causality == SVCausality.input»
+										bool isSet«sv.name»;
+									«ENDIF»
+								«ENDFOR»
+								
+								«FOR v : globalVariables.entrySet»
+									«Conversions.fmiTypeToCppType(v.value.type)» «v.key»;
+								«ENDFOR»
+						};
+					}
+					
+					#endif
+			''';
+		}
+
+		/*
+		 * Compiles the source file constructor, destructor and the initialize function
+		 */
+		def String compileDeAndConstructorAndInitialize(String adapClassName, ArrayList<InnerFMUData> fmus, String guid,
+			String paramsCons, String inCons, String outCons, String crtlCons) {
 
-	/*
-	 * Compiles the source file constructor, destructor and the initialize function
-	 */
-	def String compileDeAndConstructorAndInitialize(String adapClassName, ArrayList<InnerFMUData> fmus,
-		String guid, String paramsCons, String inCons, String outCons, String crtlCons) {
-			
 			var ArrayList<String> initialisations = newArrayList();
-			for( fmu : fmus)
-			{
+			for (fmu : fmus) {
 				initialisations.add('''
-				auto path = make_shared<string>(*resourceLocation);
-				path->append(string("«fmu.typeName».fmu"));
-				auto «fmu.name»Fmu = make_shared<fmi2::Fmu>(*path);
-				«fmu.name»Fmu->initialize();
-				this->«fmu.name» = «fmu.name»Fmu->instantiate("«fmu.name»",fmi2CoSimulation, "«fmu.guid»", true, true, shared_from_this());
-				
-				if(this->«fmu.name»->component == NULL)
-					this->lastErrorState = fmi2Fatal;
-				this->instances->push_back(this->«fmu.name»);
+					auto path = make_shared<string>(*resourceLocation);
+					path->append(string("«fmu.typeName».fmu"));
+					auto «fmu.name»Fmu = make_shared<fmi2::Fmu>(*path);
+					«fmu.name»Fmu->initialize();
+					this->«fmu.name» = «fmu.name»Fmu->instantiate("«fmu.name»",fmi2CoSimulation, "«fmu.guid»", true, true, shared_from_this());
+					
+					if(this->«fmu.name»->component == NULL)
+						this->lastErrorState = fmi2Fatal;
+					this->instances->push_back(this->«fmu.name»);
 				''');
 			}
-		return '''
-			«adapClassName»::«adapClassName»(shared_ptr<std::string> fmiInstanceName,shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions) : 
-				SemanticAdaptation(fmiInstanceName, resourceLocation, createInputRules(),createOutputRules(), functions)
-			{
+			return '''
+				«adapClassName»::«adapClassName»(shared_ptr<std::string> fmiInstanceName,shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions) : 
+					SemanticAdaptation(fmiInstanceName, resourceLocation, createInputRules(),createOutputRules(), functions)
+				{
+					
+					«paramsCons»
+					«inCons»
+					«outCons»
+					«crtlCons»
+				}
 				
-				«paramsCons»
-				«inCons»
-				«outCons»
-				«crtlCons»
-			}
-			
-			void «adapClassName»::initialize()
-			{
-				«initialisations.join("\r\n")»
-«««				«FOR fmu : fmus»
+				void «adapClassName»::initialize()
+				{
+					«initialisations.join("\r\n")»
+				«««				«FOR fmu : fmus»
 «««				auto path = make_shared<string>(*resourceLocation);
 «««				path->append(string("«fmu.value».fmu"));
 «««				auto «fmu.key»Fmu = make_shared<fmi2::Fmu>(*path);
@@ -385,222 +396,255 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			}
 			
 			«adapClassName»::~«adapClassName»()
-			{
-			}
-		''';
-	}
+				{
+				}
+			''';
+		}
 
-	/*
-	 * Compiles the source file function getRuleThis
-	 */
-	def String compileGetRuleThis(String adaptationName) {
-		return '''
-			«adaptationName»* «adaptationName»::getRuleThis()
-			{
-				return this;
-			}
-		'''
-	}
+		/*
+		 * Compiles the source file function getRuleThis
+		 */
+		def String compileGetRuleThis(String adaptationName) {
+			return '''
+				«adaptationName»* «adaptationName»::getRuleThis()
+				{
+					return this;
+				}
+			'''
+		}
 
-	/*
-	 * Compiles the source file functions getFmiValue<double, int, string, bool>
-	 */
-	def String compileGetFmiValueFunctions(String adaptationName, LinkedHashMap<String, SAScalarVariable> variables) {
-		var ArrayList<String> cpp = newArrayList();
-		var List<ScalarVariable> convertedSASVs = variables.values.map[CalcSVar()].toList;
-		var convertedSASVsOrdered = convertedSASVs.filter[causality === SVCausality.output].groupBy[type];
-
-		for (SVType type : SVType.values) {
-			val functionSignature = '''«Conversions.fmiTypeToCppType(type)» «adaptationName»::getFmiValue«type.toString»(fmi2ValueReference id)''';
-			val functionReturn = '''return «Conversions.fmiTypeToCppDefaultValue(type)»''';
-			if (convertedSASVsOrdered.containsKey(type)) {
-				cpp.add(
-					'''
-						«functionSignature»
-						{
-							switch (id)
+		/*
+		 * Compiles the source file functions getFmiValue<double, int, string, bool>
+		 */
+		def String compileGetFmiValueFunctions(String adaptationName,
+			LinkedHashMap<String, SAScalarVariable> variables) {
+			var ArrayList<String> cpp = newArrayList();
+			var List<ScalarVariable> convertedSASVs = variables.values.map[CalcSVar()].toList;
+			var convertedSASVsOrdered = convertedSASVs.filter[causality === SVCausality.output].groupBy[type];
+
+			for (SVType type : SVType.values) {
+				val functionSignature = '''«Conversions.fmiTypeToCppType(type)» «adaptationName»::getFmiValue«type.toString»(fmi2ValueReference id)''';
+				val functionReturn = '''return «Conversions.fmiTypeToCppDefaultValue(type)»''';
+				if (convertedSASVsOrdered.containsKey(type)) {
+					cpp.add(
+						'''
+							«functionSignature»
 							{
-								«FOR svInner : convertedSASVsOrdered.get(type)»
-									case «variables.get(svInner.name).defineName»:
+								switch (id)
+								{
+									«FOR svInner : convertedSASVsOrdered.get(type)»
+										case «variables.get(svInner.name).defineName»:
+										{
+											return this->«svInner.name»;
+										}
+									«ENDFOR»
+									default:
 									{
-										return this->«svInner.name»;
+										«functionReturn»;
 									}
-								«ENDFOR»
-								default:
-								{
-									«functionReturn»;
 								}
+								
 							}
-							
-						}
-					'''
-				);
-			} else {
+						'''
+					);
+				} else {
+					cpp.add(
+						'''
+							«functionSignature»
+							{
+								«functionReturn»;
+							}
+						'''
+					);
+				}
+			}
+
+			return cpp.join("\n");
+		}
+
+		/*
+		 * Compiles the source file functions setFmiValue<double, int, string, bool>*
+		 */
+		def String compileSetFmiValueFunctions(String adapClassName,
+			LinkedHashMap<String, SAScalarVariable> variables) {
+			var ArrayList<String> cpp = newArrayList();
+			var List<ScalarVariable> convertedSASVs = variables.values.map[CalcSVar()].filter [
+				causality === SVCausality.input
+			].toList;
+			var convertedSASVsOrdered = convertedSASVs.groupBy[type];
+
+			for (SVType type : SVType.values) {
 				cpp.add(
 					'''
-						«functionSignature»
+						void «adapClassName»::setFmiValue(fmi2ValueReference id, «Conversions.fmiTypeToCppType(type)» value)
 						{
-							«functionReturn»;
+							«IF convertedSASVsOrdered.containsKey(type)»
+								switch (id)	
+									{
+										«FOR svInner : convertedSASVsOrdered.get(type)»
+											case «variables.get(svInner.name).defineName»:
+											{
+												this->«svInner.name» = value;
+												this->isSet«svInner.name» = true;
+												break;
+											}
+										«ENDFOR»
+										default:
+										{
+										}
+									}
+							«ENDIF»
 						}
 					'''
 				);
+
 			}
-		}
 
-		return cpp.join("\n");
-	}
+			return cpp.join("\n");
+		}
 
-	/*
-	 * Compiles the source file functions setFmiValue<double, int, string, bool>*
-	 */
-	def String compileSetFmiValueFunctions(String adapClassName, LinkedHashMap<String, SAScalarVariable> variables) {
-		var ArrayList<String> cpp = newArrayList();
-		var List<ScalarVariable> convertedSASVs = variables.values.map[CalcSVar()].filter [
-			causality === SVCausality.input
-		].toList;
-		var convertedSASVsOrdered = convertedSASVs.groupBy[type];
-
-		for (SVType type : SVType.values) {
-			cpp.add(
-				'''
-					void «adapClassName»::setFmiValue(fmi2ValueReference id, «Conversions.fmiTypeToCppType(type)» value)
-					{
-						«IF convertedSASVsOrdered.containsKey(type)»
-							switch (id)	
-								{
-									«FOR svInner : convertedSASVsOrdered.get(type)»
-										case «variables.get(svInner.name).defineName»:
-										{
-											this->«svInner.name» = value;
-											this->isSet«svInner.name» = true;
-											break;
-										}
-									«ENDFOR»
-									default:
-									{
-									}
-								}
-						«ENDIF»
-					}
-				'''
-			);
+		/*
+		 * Compiles the source file function executeInternalControlFlow.
+		 * Calculates necessary information on function signatures necessary for generation of the header file.
+		 */
+		def InOutRulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks,
+			String adaptationClassName, String adaptationName,
+			LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
+			LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params,
+			LinkedHashMap<String, GlobalInOutVariable> inVars, LinkedHashMap<String, GlobalInOutVariable> outVars,
+			LinkedHashMap<String, GlobalInOutVariable> crtlVars) {
+			var cpp = "";
+			val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, inVars,
+				outVars, crtlVars);
+			for (crtlRule : crtlRuleBlocks) {
+				cpp += visitor.doSwitch(crtlRule).code;
+			}
 
+			return new InOutRulesBlockResult(cpp, visitor.functionSignatures);
 		}
 
-		return cpp.join("\n");
-	}
-
-	/*
-	 * Compiles the source file function executeInternalControlFlow.
-	 * Calculates necessary information on function signatures necessary for generation of the header file.
-	 */
-	def InOutRulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String adaptationClassName,
-		String adaptationName, LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars, 
-		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params, LinkedHashMap<String, GlobalInOutVariable> outVars) {
-		var cpp = "";
-		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, outVars);
-		for (crtlRule : crtlRuleBlocks) {
-			cpp += visitor.doSwitch(crtlRule).code;
+		def String SplitAtSpaceAndRemoveFirst(String content) {
+			content.substring(content.indexOf(" ") + 1, content.length);
 		}
 
-		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.globalVars, visitor.constructorInitialization);
-	}
+		def String removeEmptyArgumentParenthesis(String content) {
+			return content.substring(0, content.length - 2);
+		}
 
-	def String SplitAtSpaceAndRemoveFirst(String content) {
-		content.substring(content.indexOf(" ") + 1, content.length);
-	}
+		/*
+		 * Calculates necessary information on global in/out variables
+		 */
+		def Pair<String, LinkedHashMap<String, GlobalInOutVariable>> compileRuleBlockVars(
+			EList<Declaration> gVars, 
+			LinkedHashMap<String, GlobalInOutVariable> params) {
 
-	def String removeEmptyArgumentParenthesis(String content) {
-		return content.substring(0, content.length - 2);
-	}
+			val visitor = new RulesConditionSwitch("", "", "", null, null, params, null,
+				null, null)
+			return visitor.getGlobalVars(gVars);
+		}
 
-	/*
-	 * Compiles the source file functions <in/out>_rule_<condition, body, flush>.
-	 * Calculates necessary information on global in/out variables necessary for generation of the header file.
-	 * Calculates necessary information on function signatures necessary for generation of the header file.
-	 */
-	def InOutRulesBlockResult compileInOutRuleBlocks(InputOutputRuleType ioType, Iterable<InOutRules> rulesBlocks,
-		String adaptationClassName, String adaptationName,
-		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
-		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params) {
-
-		val visitor = if (ioType == InputOutputRuleType.Input)
-				new InRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params)
-			else
-				new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params);
-
-		val functionName = "create" + ioType + "Rules()";
-		var String cpp = "";
-		val ruleBlock = rulesBlocks.head;
-		if (ruleBlock !== null) {
-			cpp += visitor.doSwitch(ruleBlock).code;
-			if (!visitor.functionSignatures.empty) {
-				var ArrayList<String> createRulesFunction = newArrayList();
-				for (var int i = 0; i < (visitor.functionSignatures.length); i += 3) {
-					createRulesFunction.add( 
+		/*
+		 * Compiles the source file functions <in/out>_rule_<condition, body, flush>.
+		 * Calculates necessary information on function signatures necessary for generation of the header file.
+		 */
+		def InOutRulesBlockResult compileInOutRuleBlocks(IORuleType ioType, 
+			Iterable<InOutRules> rulesBlocks,
+			String adaptationClassName, 
+			String adaptationName,
+			LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
+			LinkedHashMap<String, SAScalarVariable> SASVs, 
+			LinkedHashMap<String, GlobalInOutVariable> params,
+			LinkedHashMap<String, GlobalInOutVariable> inVars, 
+			LinkedHashMap<String, GlobalInOutVariable> outVars,
+			LinkedHashMap<String, GlobalInOutVariable> crtlVars) {
+
+			val visitor = if (ioType == IORuleType.Input)
+					new InRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, inVars,
+						outVars, crtlVars)
+				else
+					new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, inVars,
+						outVars, crtlVars);
+			//
+			val functionName = "create" + ioType + "Rules()";
+			var String cpp = "";
+			val ruleBlock = rulesBlocks.head;
+			if (ruleBlock !== null) {
+				cpp += visitor.doSwitch(ruleBlock).code;
+				if (!visitor.functionSignatures.empty) {
+					var ArrayList<String> createRulesFunction = newArrayList();
+					for (var int i = 0; i < (visitor.functionSignatures.length); i += 3) {
+						createRulesFunction.add( 
 					'''
-						list->push_back(
-							(Rule<«adaptationClassName»>){
-								&«adaptationClassName»::«visitor.functionSignatures.get(i).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
-								&«adaptationClassName»::«visitor.functionSignatures.get(i+1).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
-								&«adaptationClassName»::«visitor.functionSignatures.get(i+2).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»
-							});
+							list->push_back(
+								(Rule<«adaptationClassName»>){
+									&«adaptationClassName»::«visitor.functionSignatures.get(i).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
+									&«adaptationClassName»::«visitor.functionSignatures.get(i+1).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
+									&«adaptationClassName»::«visitor.functionSignatures.get(i+2).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»
+								});
+							
+						''');
+					}
+					val functionPrefix = '''shared_ptr<list<Rule<«adaptationClassName»>>>''';
+					visitor.functionSignatures.add(functionPrefix + " " + functionName)
+					cpp += '''
+						«functionPrefix» «adaptationClassName»::«functionName»
+						{
+							auto list = make_shared<std::list<Rule<«adaptationClassName»>>>();
+							
+							«createRulesFunction.join("\n")»
+							
+							return list;
+							
+						}
 						
-					''');
+					'''
 				}
-				val functionPrefix = '''shared_ptr<list<Rule<«adaptationClassName»>>>''';
-				visitor.functionSignatures.add(functionPrefix + " " + functionName)
-				cpp += '''
-					«functionPrefix» «adaptationClassName»::«functionName»
-					{
-						auto list = make_shared<std::list<Rule<«adaptationClassName»>>>();
-						
-						«createRulesFunction.join("\n")»
-						
-						return list;
-						
-					}
-					
-				'''
 			}
+			return new InOutRulesBlockResult(cpp, visitor.functionSignatures);
 		}
-		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.getGlobalVars,
-			visitor.constructorInitialization);
-	}
 
-	/*
-	 * Calculates the semantic adaptation scalar variables via input ports and output ports.
-	 * Note: These a not fully populated yet as the in rules and out rules must be compiled first. 
-	 */
-	def LinkedHashMap<String, SAScalarVariable> calcSASVsFromInportsOutports(String definePrefix, EList<Port> inports,
-		EList<Port> outports) {
-		var LinkedHashMap<String, SAScalarVariable> saSVs = newLinkedHashMap();
-
-		var int valueReference = 0;
-		for (inport : inports) {
-			var saSV = new SAScalarVariable();
-			saSV.SetPartOfMD(true);
-			saSV.valueReference = valueReference++;
-			saSV.name = inport.name;
-			saSV.defineName = (definePrefix + inport.name).toUpperCase
-			saSV.causality = SVCausality.input;
-			saSVs.put(saSV.name, saSV);
-		}
+		/*
+		 * Calculates the semantic adaptation scalar variables via input ports and output ports.
+		 * Note: These a not fully populated yet as the in rules and out rules must be compiled first. 
+		 */
+		def LinkedHashMap<String, SAScalarVariable> calcSASVsFromInportsOutports(String definePrefix,
+			EList<Port> inports, EList<Port> outports,
+			LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVs) {
+			var LinkedHashMap<String, SAScalarVariable> saSVs = newLinkedHashMap();
+
+			var int valueReference = 0;
+			for (inport : inports) {
+				var saSV = new SAScalarVariable();
+				saSV.SetPartOfMD(true);
+				saSV.valueReference = valueReference++;
+				saSV.name = inport.name;
+				saSV.defineName = (definePrefix + inport.name).toUpperCase
+				saSV.causality = SVCausality.input;
+				saSVs.put(saSV.name, saSV);
+			}
 
-		for (outport : outports) {
-			var saSV = new SAScalarVariable();
-			saSV.SetPartOfMD(true);
-			saSV.valueReference = valueReference++;
-			saSV.defineName = (definePrefix + outport.name).toUpperCase
-			saSV.name = outport.name;
-			saSV.causality = SVCausality.output;
-			saSVs.put(saSV.name, saSV);
-		}
+			for (outport : outports) {
+				var saSV = new SAScalarVariable();
+				if (outport.sourcedependency !== null) {
+					saSV.type = mSVs.get(outport.sourcedependency.owner.name).get(outport.sourcedependency.port.name).
+						mappedSv.type;
+					saSV.variability = mSVs.get(outport.sourcedependency.owner.name).get(
+						outport.sourcedependency.port.name).mappedSv.variability;
 
-		return saSVs;
-	}
+				}
+				saSV.SetPartOfMD(true);
+				saSV.valueReference = valueReference++;
+				saSV.defineName = (definePrefix + outport.name).toUpperCase
+				saSV.name = outport.name;
+				saSV.causality = SVCausality.output;
+				saSVs.put(saSV.name, saSV);
+			}
 
-	def List<File> getResourcePaths() {
-		return resourcePaths;
+			return saSVs;
+		}
+
+		def List<File> getResourcePaths() {
+			return resourcePaths;
+		}
 	}
-}
+	

+ 0 - 7
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/GeneralConditionSwitch.xtend

@@ -11,13 +11,6 @@ import org.eclipse.emf.ecore.EObject
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IntLiteral
 
 class GeneralConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
-	override ReturnInformation caseParamDeclarations(ParamDeclarations object) {
-		for (SingleParamDeclaration declaration : object.declarations) {
-			doSwitch(declaration);
-		}
-		return new ReturnInformation();
-	}
-
 	override ReturnInformation caseIntLiteral(IntLiteral object){
 		var retInfo = new ReturnInformation();
 		retInfo.type = SVType.Integer;

+ 28 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend

@@ -7,20 +7,41 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutpu
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
 
 class InRulesConditionSwitch extends RulesConditionSwitch {
 
 	private Boolean inOutputFunction = false;
 
-	new(String adaptationClassName, String adaptationName, LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars, LinkedHashMap<String,SAScalarVariable> SASVs
-		,LinkedHashMap<String, GlobalInOutVariable> params
+	new(
+		String adaptationClassName,
+		String adaptationName,
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
+		LinkedHashMap<String, SAScalarVariable> SASVs,
+		LinkedHashMap<String, GlobalInOutVariable> params,
+		LinkedHashMap<String, GlobalInOutVariable> inVars,
+		LinkedHashMap<String, GlobalInOutVariable> outVars,
+		LinkedHashMap<String, GlobalInOutVariable> crtlVars
 	) {
-		super(adaptationClassName, adaptationName, "in_rule_", mSVars, SASVs, params, null);
+		super(adaptationClassName, adaptationName, "in_rule_", mSVars, SASVs, params, inVars, outVars, crtlVars);
 	}
 
+	public def LinkedHashMap<String, GlobalInOutVariable> getGlobalVars(InRulesBlock object) {
+		if (object.globalInVars !== null) {
+			this.globalDeclaration = true;
+			for (gVar : object.globalInVars)
+				doSwitch(gVar);
+			this.globalDeclaration = false;
+		}
+		return this.gVars;
+	}
+
+	override ReturnInformation caseInRulesBlock(InRulesBlock object) {
+		return this.doSwitch(object.globalInVars, object);
+	}
 
 	override ReturnInformation caseCompositeOutputFunction(CompositeOutputFunction object) {
-		
+
 		this.inOutputFunction = true;
 		val ReturnInformation retVal = super.caseCompositeOutputFunction(object);
 		this.inOutputFunction = false;
@@ -29,14 +50,11 @@ class InRulesConditionSwitch extends RulesConditionSwitch {
 
 	override ReturnInformation caseAssignment(Assignment object) {
 		var retVal = new ReturnInformation();
-				
+
 		if (inOutputFunction) {
-			retVal.code = 	
-				'''setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr).code»)''';
+			retVal.code = '''setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr).code»)''';
 			return retVal;
-		}
-		else
-		{
+		} else {
 			return super.caseAssignment(object);
 		}
 	}

+ 20 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend

@@ -6,12 +6,30 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
 
 public class OutRulesConditionSwitch extends RulesConditionSwitch {
 	new(String adaptationClassName, String adaptationName,
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
-		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params) {
-		super(adaptationClassName, adaptationName, "out_rule_", mSVars, SASVs, params, null);
+		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params,
+		LinkedHashMap<String, GlobalInOutVariable> inVars, LinkedHashMap<String, GlobalInOutVariable> outVars,
+		LinkedHashMap<String, GlobalInOutVariable> crtlVars) {
+		super(adaptationClassName, adaptationName, "out_rule_", mSVars, SASVs, params, inVars, outVars, crtlVars);
+	}
+
+	public def LinkedHashMap<String, GlobalInOutVariable> getGlobalVars(OutRulesBlock object) {
+		if (object.globalOutVars !== null) {
+			this.globalDeclaration = true;
+			for (gVar : object.globalOutVars)
+				doSwitch(gVar);
+			this.globalDeclaration = false;
+		}
+		return this.gVars;
+	}
+
+	override ReturnInformation caseOutRulesBlock(OutRulesBlock object) {
+
+		return this.doSwitch(object.globalOutVars, object);
 	}
 
 	override ReturnInformation casePort(Port object) {
@@ -20,8 +38,6 @@ public class OutRulesConditionSwitch extends RulesConditionSwitch {
 		val type = mSVars.get(this.externalVariableOwner).get(object.name).mappedSv.type;
 		val define = mSVars.get(this.externalVariableOwner).get(object.name).define;
 		retVal.code = '''getValue«Conversions.fmiTypeToCppTypeCapitalized(type)»(«this.externalVariableOwner»,«define»)''';
-		this.externalVariableOwnerIsSet = false;
-
 		return retVal;
 	}
 

+ 78 - 60
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend

@@ -41,11 +41,11 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Range
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Close
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BreakStatement
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Var
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 
-abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
-	// Global in and out variables
-	protected var LinkedHashMap<String, GlobalInOutVariable> gVars = newLinkedHashMap();
-
+ class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
 	// Global params
 	protected var LinkedHashMap<String, GlobalInOutVariable> params;
 
@@ -62,23 +62,26 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 
 	/*
 	 * Intermediate variable used for referencing external FMU.
-	 * It is necessary because of parsing error
+	 * Currently only used by OutRulesConditionSwitch. 
 	 */
 	protected String externalVariableOwner;
-	protected boolean externalVariableOwnerIsSet = false;
 
 	protected final LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars;
 	protected final LinkedHashMap<String, SAScalarVariable> SASVs;
-	
+
+	// Global in and out variables
+	protected var LinkedHashMap<String, GlobalInOutVariable> gVars = newLinkedHashMap();
+	LinkedHashMap<String, GlobalInOutVariable> inVars;
 	LinkedHashMap<String, GlobalInOutVariable> outVars;
+	LinkedHashMap<String, GlobalInOutVariable> crtlVars;
 
 	protected boolean inRuleCondition;
 	protected boolean inRuleTransition;
 	protected boolean inRuleOutput;
 	protected boolean inControlRule;
 
-	// This is used for storing initialization information for global declarations.
-	protected String constructorInitialization = "";
+	
+	
 	// Flag to signal whether the declarations to be processed are global or local.
 	protected boolean globalDeclaration = false;
 	// Add scope information to this.
@@ -86,8 +89,6 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 
 	protected String forLoopIterVar;
 	protected boolean forLoopIterVarIsSet = false;
-	
-	
 
 	new(
 		String adaptationClassName,
@@ -96,7 +97,9 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
 		LinkedHashMap<String, SAScalarVariable> SASVs,
 		LinkedHashMap<String, GlobalInOutVariable> params,
-		LinkedHashMap<String, GlobalInOutVariable> outVars
+		LinkedHashMap<String, GlobalInOutVariable> inVars,
+		LinkedHashMap<String, GlobalInOutVariable> outVars,
+		LinkedHashMap<String, GlobalInOutVariable> crtlVars
 	) {
 		this.params = params;
 		this.SASVs = SASVs;
@@ -105,6 +108,8 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 		this.functionPrefix = functionPrefix;
 		this.mSVars = mSVars;
 		this.outVars = outVars;
+		this.inVars = inVars;
+		this.crtlVars = crtlVars;
 	}
 
 	/*
@@ -153,18 +158,30 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 	/*
 	 * COMPILATION FUNCTIONS
 	 */
-	protected def ReturnInformation doSwitch(EList<Declaration> gVars, InOutRules object) {
-
-		this.globalDeclaration = true;
-
-		var retVal = new ReturnInformation();
-
+	
+	public def Pair<String, LinkedHashMap<String, GlobalInOutVariable>> getGlobalVars(EList<Declaration> gVars)
+	{
+		
+		var String constructorInitialisation= "";
+		
 		// Get the global variables added to globalVars
+		this.globalDeclaration = true;
 		for (gVar : gVars) {
-			constructorInitialization += doSwitch(gVar).code;
+			constructorInitialisation += doSwitch(gVar).code;
 		}
-
 		this.globalDeclaration = false;
+		return constructorInitialisation -> this.gVars;
+	}
+	
+	protected def ReturnInformation doSwitch(EList<Declaration> gVars, InOutRules object) {
+		var retVal = new ReturnInformation();
+
+//		// Get the global variables added to globalVars
+//		this.globalDeclaration = true;
+//		for (gVar : gVars) {
+//			constructorInitialization += doSwitch(gVar).code;
+//		}
+//		this.globalDeclaration = false;
 
 		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
 			this.incrementCount;
@@ -174,15 +191,6 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 		return retVal;
 	}
 
-	override ReturnInformation caseInRulesBlock(InRulesBlock object) {
-		return this.doSwitch(object.globalInVars, object);
-	}
-
-	override ReturnInformation caseOutRulesBlock(OutRulesBlock object) {
-
-		return this.doSwitch(object.globalOutVars, object);
-	}
-
 	override ReturnInformation caseDataRule(DataRule object) {
 		var retVal = new ReturnInformation();
 		inRuleCondition = true;
@@ -253,14 +261,13 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 				«ENDFOR»
 			}
 		''';
-		if(object.elsestatements.length > 0)
-		{
+		if (object.elsestatements.length > 0) {
 			retVal.appendCode('''
-			else {
-				«FOR stm : object.elsestatements»
-					«doSwitch(stm).code»;
-				«ENDFOR»
-			}
+				else {
+					«FOR stm : object.elsestatements»
+						«doSwitch(stm).code»;
+					«ENDFOR»
+				}
 			''')
 		}
 
@@ -297,10 +304,8 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 			calcConSaSvData(lValSwitch.conSaSv, rValSwitch);
 		}
 
+		retVal.code = '''«lValSwitch.code» = «rValSwitch.code»''';
 
-			retVal.code = '''«lValSwitch.code» = «rValSwitch.code»''';
-
-		
 		return retVal;
 	}
 
@@ -359,34 +364,34 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 
 		if (object.owner === null || object.owner.name == this.adaptationName) {
 
-			if (SASVs.containsKey(object.ref.name) || gVars.containsKey(object.ref.name) ||
-				params.containsKey(object.ref.name) || outVars.containsKey(object.ref.name)) {
+			if ((SASVs !== null && SASVs.containsKey(object.ref.name)) || 
+				params.containsKey(object.ref.name) || 
+				(outVars !== null && outVars.containsKey(object.ref.name)) ||
+				(inVars !== null && inVars.containsKey(object.ref.name)) ||
+				(crtlVars !== null && crtlVars.containsKey(object.ref.name))) {
 
 				retVal.code = '''this->«object.ref.name»''';
 
-				if (SASVs.containsKey(object.ref.name)) {
+				if (SASVs !== null && SASVs.containsKey(object.ref.name)) {
 					retVal.conSaSv = SASVs.get(object.ref.name);
-				} else if (gVars.containsKey(object.ref.name)) {
-					retVal.conGlobVar = gVars.get(object.ref.name);
+				} else if (crtlVars !== null && crtlVars.containsKey(object.ref.name)) {
+					retVal.conGlobVar = crtlVars.get(object.ref.name);
 				} else if (params.containsKey(object.ref.name)) {
 					retVal.conGlobVar = params.get(object.ref.name);
-				}
-				else if (outVars.containsKey(object.ref.name)){
+				} else if (outVars !== null && outVars.containsKey(object.ref.name)) {
 					retVal.conGlobVar = outVars.get(object.ref.name);
+				} else if (inVars !== null && inVars.containsKey(object.ref.name)) {
+					retVal.conGlobVar = inVars.get(object.ref.name);
 				}
 			} else if (localDeclarations.containsKey(object.ref.name)) {
 				retVal.code = '''«object.ref.name»'''
 				retVal.type = localDeclarations.get(object.ref.name);
-			}
-			else 
-			{
+			} else {
 				throw new Exception("Variable not found: " + object.ref.name);
 			}
 
 		} else {
-			// This has to be converted to an setValue using the FMU component. 
 			this.externalVariableOwner = object.owner.name;
-			this.externalVariableOwnerIsSet = true;
 			retVal.code = '''«doSwitch(object.ref).code»''';
 		}
 		return retVal;
@@ -399,6 +404,11 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 		return retVal;
 	}
 
+	override ReturnInformation caseVar(Var object) {
+		var retVal = new ReturnInformation();
+		return retVal;
+	}
+
 	override ReturnInformation caseDeclaration(Declaration object) {
 		var retVal = new ReturnInformation();
 
@@ -481,6 +491,14 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 		return retVal;
 	}
 
+	override ReturnInformation casePlus(Plus object) {
+		val doSwitchLeft = doSwitch(object.left);
+		val doSwitchRight = doSwitch(object.right);
+		var retVal = new ReturnInformation(doSwitchLeft, doSwitchRight);
+		retVal.code = '''«doSwitchLeft.code» + «doSwitchRight.code»''';
+		return retVal;
+	}
+
 	override ReturnInformation caseFor(For object) {
 		{
 			var retVal = new ReturnInformation();
@@ -490,23 +508,23 @@ abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInfor
 			forLoopIterVarIsSet = true;
 			val iterable = doSwitch(object.iterable);
 			retVal.appendCode('''
-			for (int «forLoopIterVar» = «iterable.code»){
-				«FOR stm : object.statements»
-					«val result = doSwitch(stm)»		
-					«result.code»«if (!result.isExpression) ";"»
-				«ENDFOR»
-			}
+				for (int «forLoopIterVar» = «iterable.code»){
+					«FOR stm : object.statements»
+						«val result = doSwitch(stm)»		
+						«result.code»«if (!result.isExpression) ";"»
+					«ENDFOR»
+				}
 			''')
 			forLoopIterVarIsSet = false;
 			return retVal;
 		}
 	}
-	
-	override ReturnInformation caseRange(Range object){
+
+	override ReturnInformation caseRange(Range object) {
 		var retVal = new ReturnInformation();
 		val left = doSwitch(object.left);
 		val right = doSwitch(object.right);
-			retVal.appendCode('''«left.code»; «forLoopIterVar»<=«right.code»; «forLoopIterVar»++''')
+		retVal.appendCode('''«left.code»; «forLoopIterVar»<=«right.code»; «forLoopIterVar»++''')
 		return retVal;
 	}
 

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/rate.sa

@@ -13,7 +13,8 @@ param 	RATE := 10;
 
 control var previous_speed := 0;
 control rules {
-	var micro_step := H/RATE;
+	var micro_step := 0.0;
+	micro_step := H/RATE;
 	var inner_time := t;
 	
 	for (var iter in 0 .. RATE) { 

+ 6 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationGeneratorTest.xtend

@@ -26,6 +26,7 @@ import org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result
 import org.junit.Assert
 import org.junit.Test
 import org.junit.runner.RunWith
+import org.junit.Ignore
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
@@ -217,6 +218,11 @@ class SemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationTest{
 			override accept(Result t) { }
 		}) }
 	
+	@Ignore
+		@Test def rate_SA_parseNoExceptions() { __generate('input/power_window_case_study/rate.sa', new IAcceptor<CompilationTestHelper.Result>(){
+			override accept(Result t) { }
+		}) }
+	
 	def void __generate(String filename, IAcceptor<CompilationTestHelper.Result> acceptor) {
 		//readFile(filename).assertCompilesTo('oracles/power_window_case_study/lazy.BASE.sa')
 		

+ 5 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/generator/SemanticAdaptationCanonicalGenerator.xtend

@@ -53,6 +53,7 @@ import org.eclipse.xtext.EcoreUtil2
 import org.eclipse.xtext.generator.AbstractGenerator
 import org.eclipse.xtext.generator.IFileSystemAccess2
 import org.eclipse.xtext.generator.IGeneratorContext
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
 
 /**
  * Generates code from your model files on save.
@@ -1082,7 +1083,10 @@ class SemanticAdaptationCanonicalGenerator extends AbstractGenerator {
 			} else {
 				return "Real"
 			}
-		} else {
+		} else if (expression instanceof CurrentTime) {
+			return "Real"
+		}
+		else {
 			throw new Exception("Initial value for declaration " + declarationName + " must be literal or var ref for now. Got instead " + expression + ". If you want complex expressions, give it an explicit type.")
 		}
 		return null