Browse Source

Fixed issue with source dependencies: output ports tau <- loop_sa.tau
Only implemented for out var!

Added several opeartors
Added some type checks.

Should also fix build error.

Casper Thule 6 years ago
parent
commit
70bf604049
9 changed files with 803 additions and 663 deletions
  1. 2 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/rate/rate_canonical.sa
  2. 27 30
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/ReturnInformation.java
  3. 187 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BasicConditionSwitch.xtend
  4. 25 31
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend
  5. 4 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/Conversions.java
  6. 513 435
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend
  7. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend
  8. 0 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend
  9. 44 161
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend

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

@@ -9,8 +9,7 @@ at "./path/to/RateSA.fmu"
 input ports speed
 output ports tau
 
-param 	RATE := 10,
-		INIT_LOOP_SA_TAU := 0.0;
+param 	RATE := 10;
 
 control var previous_speed := 0;
 control rules {
@@ -35,7 +34,7 @@ in rules {
 	};
 }
 
-out var stored_loop_sa_tau := INIT_LOOP_SA_TAU;
+out var stored_loop_sa_tau := 0.0;
 out rules {
 	true -> {
 		stored_loop_sa_tau := loop_sa.tau;

+ 27 - 30
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/ReturnInformation.java

@@ -29,22 +29,18 @@ public class ReturnInformation {
 	public void setCode(String code) {
 		this.code = code;
 	}
-	
-	public void setIsExpression(boolean isExpression)
-	{
+
+	public void setIsExpression(boolean isExpression) {
 		this.isExpression = isExpression;
 	}
-	
-	public boolean getIsExpression()
-	{
+
+	public boolean getIsExpression() {
 		return this.isExpression;
 	}
 
 	public SVType getType() throws Exception {
-		if(!typeIsSet)
-		{
-			throw new Exception(
-					"Attempt to retrieve unset type for code: " + code);
+		if (!typeIsSet) {
+			throw new Exception("Attempt to retrieve unset type for code: " + code);
 		}
 		return type;
 	}
@@ -74,8 +70,16 @@ public class ReturnInformation {
 		return ConSaSv;
 	}
 
-	public void setConSaSv(SAScalarVariable conSaSv) {
+	public void setConSaSv(SAScalarVariable conSaSv) throws InvalidConversionException {
 		ConSaSv = conSaSv;
+		if (this.typeIsSet && conSaSv.getType().isPresent()) {
+			this.type = Conversions.typeDecider(conSaSv.getType().get(), this.type);
+		} else {
+			if (conSaSv.getType().isPresent()) {
+				this.type = conSaSv.getType().get();
+				this.typeIsSet = true;
+			}
+		}
 	}
 
 	public GlobalInOutVariable getConGlobVar() {
@@ -86,9 +90,7 @@ public class ReturnInformation {
 		this.conGlobVar = conGlobVar;
 		if (this.typeIsSet) {
 			this.type = Conversions.typeDecider(conGlobVar.type, this.type);
-		}
-		else
-		{
+		} else {
 			this.type = conGlobVar.type;
 			this.typeIsSet = true;
 		}
@@ -108,7 +110,7 @@ public class ReturnInformation {
 	/*
 	 * This method automatically extracts and compares type information
 	 */
-	
+
 	public ReturnInformation(ReturnInformation information, ReturnInformation information2) throws Exception {
 		if (information.conGlobVar != null) {
 			if (information2.conGlobVar != null) {
@@ -118,8 +120,8 @@ public class ReturnInformation {
 				// In this case they must have the same type otherwise the
 				// return value is impossible to typecheck.
 				else if (information.conGlobVar.type != information2.conGlobVar.type) {
-					throw new Exception("The two connected global variables: " + information.conGlobVar.name
-							+ " and " + information2.conGlobVar.name + " have different types");
+					throw new Exception("The two connected global variables: " + information.conGlobVar.name + " and "
+							+ information2.conGlobVar.name + " have different types");
 				}
 
 			} else {
@@ -164,21 +166,16 @@ public class ReturnInformation {
 				this.setConSaSv(information2.ConSaSv);
 			}
 		}
-		
-		if(information.forceType && information2.forceType)
-		{
-			if(information.getType() != information2.getType())
-			{
-				throw new Exception(
-						"Two connected return informations with force types contain different types: "
-								+ information.getType() + " and " + information2.getType());
+
+		if (information.forceType && information2.forceType) {
+			if (information.getType() != information2.getType()) {
+				throw new Exception("Two connected return informations with force types contain different types: "
+						+ information.getType() + " and " + information2.getType());
 			}
-		}
-		else if(information.forceType || information2.forceType)
-		{
-			
+		} else if (information.forceType || information2.forceType) {
+
 			this.forceType = true;
-			if(information.forceType)
+			if (information.forceType)
 				this.type = information.type;
 			else
 				this.type = information2.type;

+ 187 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BasicConditionSwitch.xtend

@@ -0,0 +1,187 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
+
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
+import org.eclipse.emf.ecore.EObject
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Multi
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Div
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Neg
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RealLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IntLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Literal
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BoolLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Min
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Minus
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.LessThan
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.TypeException
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Or
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.NotEquals
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.GreaterThanOrEquals
+
+class BasicConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
+
+	private def Object convertTypeToObject(SVType type, Literal object) {
+		switch (type) {
+			case Real: {
+				return (object as RealLiteral).value.doubleValue;
+			}
+			case Integer: {
+				return (object as IntLiteral).value;
+			}
+			case Boolean: {
+				return Boolean.parseBoolean((object as BoolLiteral).value);
+			}
+			default: {
+			}
+		}
+	}
+	
+		override ReturnInformation caseRealLiteral(RealLiteral object) {
+		var retInfo = new ReturnInformation();
+		retInfo.type = SVType.Real;
+		retInfo.value = convertTypeToObject(retInfo.type, object);
+		retInfo.code = '''«object.value»''';
+		return retInfo;
+	}
+
+	override ReturnInformation caseIntLiteral(IntLiteral object) {
+		var retInfo = new ReturnInformation();
+		retInfo.type = SVType.Integer;
+		retInfo.value = convertTypeToObject(retInfo.type, object);
+		retInfo.code = '''«object.value»''';
+		return retInfo;
+	}
+
+	override ReturnInformation caseBoolLiteral(BoolLiteral object) {
+		var retInfo = new ReturnInformation();
+		retInfo.type = SVType.Boolean;
+		retInfo.value = convertTypeToObject(retInfo.type, object);
+		retInfo.code = '''«object.value»''';
+
+		return retInfo;
+	}
+
+	override ReturnInformation defaultCase(EObject object) {
+		var retVal = new ReturnInformation();
+		retVal.code = '''[«object.class»]''';
+		return retVal;
+	}
+
+	override ReturnInformation caseMulti(Multi 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 caseDiv(Div object) {
+		val doSwitchLeft = doSwitch(object.left);
+		val doSwitchRight = doSwitch(object.right);
+		var retVal = new ReturnInformation(doSwitchLeft, doSwitchRight);
+		retVal.code = '''«doSwitchLeft.code» / «doSwitchRight.code»''';
+		retVal.type = SVType.Real;
+		retVal.forceType = true;
+		return retVal;
+	}
+
+	override ReturnInformation caseNeg(Neg object) {
+
+		var doSwitch = doSwitch(object.right);
+		var retVal = new ReturnInformation(doSwitch);
+		retVal.code = doSwitch.code;
+
+		return retVal;
+	}
+	
+		override ReturnInformation caseMin(Min object) {
+		var retInfo = new ReturnInformation();
+		var doSwitchResCode = newArrayList();
+		for (expr : object.args) {
+			val doSwitchRes_ = this.doSwitch(expr);
+			doSwitchResCode.add(doSwitchRes_.code);
+			retInfo = new ReturnInformation(retInfo, doSwitchRes_);
+		}
+		retInfo.code = '''min(«doSwitchResCode.join(",")»)'''
+		return retInfo;
+	}
+
+	override ReturnInformation caseMinus(Minus 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 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 caseGreaterThanOrEquals(GreaterThanOrEquals object)
+	{
+		var ret = new ReturnInformation();
+		val left = doSwitch(object.left);
+		val right = doSwitch(object.right);
+		val code = '''«left.code» >= «right.code»'''
+		if(!Conversions.isTypeANumber(left.type) || !Conversions.isTypeANumber(right.type))
+		{
+			throw new TypeException('''Wrong types at: «code»''');
+		}
+		ret.type = SVType.Boolean;
+		ret.code = code;
+		return ret;
+	}
+	
+	override ReturnInformation caseNotEquals(NotEquals object)
+	{
+		var ret = new ReturnInformation();
+		val left = doSwitch(object.left);
+		val right = doSwitch(object.right);
+		val code = '''«left.code» != «right.code»'''
+		if(left.type !== right.type)
+		{
+			throw new TypeException('''Wrong types at: «code»''');
+		}
+		ret.type = SVType.Boolean;
+		ret.code = code;
+		return ret;
+	}
+	
+	override ReturnInformation caseLessThan(LessThan object)
+	{
+		var ret = new ReturnInformation();
+		val left = doSwitch(object.left);
+		val right = doSwitch(object.right);
+		val code = '''«left.code» < «right.code»'''
+		if(!Conversions.isTypeANumber(left.type) || !Conversions.isTypeANumber(right.type))
+		{
+			throw new TypeException('''Wrong types at: «code»''');
+		}
+		ret.type = SVType.Boolean;
+		ret.code = code;
+		return ret;
+	}
+	
+	override ReturnInformation caseOr(Or object)
+	{
+		var ret = new ReturnInformation();
+		val left = doSwitch(object.left);
+		val right = doSwitch(object.right);
+		val code = '''«left.code» || «right.code»'''
+		if(left.type !== SVType.Boolean || right.type !== SVType.Boolean)
+		{
+			throw new TypeException('''Wrong types at: «code»''');
+		}
+		ret.type = SVType.Boolean;
+		ret.code = code;
+		return ret;
+	}
+
+}

+ 25 - 31
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend

@@ -20,6 +20,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Close
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BreakStatement
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Rollback
 import java.util.List
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.GetNextInternalTimeStep
 
 class ControlConditionSwitch extends RulesConditionSwitch {
 
@@ -49,16 +50,7 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 
 	override ReturnInformation caseVariable(Variable object) {
 		var retVal = new ReturnInformation();
-
-		// 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;
 	}
 
@@ -74,13 +66,7 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 
 	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;
@@ -89,22 +75,23 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 	override ReturnInformation caseCustomControlRule(CustomControlRule object) {
 		var retVal = new ReturnInformation();
 
-		var String tempDoSwitchCode = "";
-		for (ruleStm : object.controlRulestatements) {
-			tempDoSwitchCode += doSwitch(ruleStm).code;
+		val functionPrefix = "double ";
+		val functionNameArgs = "executeInternalControlFlow(double H, double t)"
+		functionSignatures.add(functionPrefix + functionNameArgs);
+				
+		val code = '''
+		«functionPrefix+this.adaptationClassName»::«functionNameArgs» {
+			«FOR ruleStm : object.controlRulestatements»
+			«val result = doSwitch(ruleStm)»
+			«result.code»«if (!result.isExpression) ";"»
+			«ENDFOR»
+			
+			return «doSwitch(object.returnstatement.expr).code»;
 		}
-		tempDoSwitchCode += System.lineSeparator() + '''return «doSwitch(object.returnstatement.expr).code»;
 		''';
 
-		var functionPrefix = "double ";
-		var functionNameArgs = "executeInternalControlFlow(double H, double t)"
-		functionSignatures.add(functionPrefix + functionNameArgs);
-		retVal.code = '''
-			«functionPrefix+this.adaptationClassName»::«functionNameArgs»
-			{
-				«tempDoSwitchCode»
-			}
-		''';
+		
+		retVal.code = code;
 		return retVal;
 	}
 
@@ -139,8 +126,7 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 
 	override ReturnInformation caseSaveState(SaveState object) {
 		var retVal = new ReturnInformation();
-		retVal.appendCode('''
-		saveState(«object.fmu.name»)''')
+		retVal.appendCode('''saveState(«object.fmu.name»)''')
 		return retVal;
 	}
 
@@ -161,4 +147,12 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 		retVal.appendCode('''rollback(«object.fmu.name»)''')
 		return retVal;
 	}
+
+	override ReturnInformation caseGetNextInternalTimeStep(GetNextInternalTimeStep object)
+	{
+		var retVal = new ReturnInformation();
+		retVal.type = SVType.Real;
+		retVal.code = '''getMextTimeStep(«object.fmu.name»)''';
+		return retVal;
+	}
 }

+ 4 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/Conversions.java

@@ -57,7 +57,10 @@ public class Conversions {
 			throw new InvalidConversionException("The value type: " + t + " is invalid.");
 		}
 	}
-
+	public static boolean isTypeANumber(SVType t1)
+	{
+		return t1 == SVType.Real || t1 == SVType.Integer;
+	}
 	public static SVType typeDecider(SVType t1, SVType t2) throws InvalidConversionException {
 		switch (t1) {
 		case Real:

File diff suppressed because it is too large
+ 513 - 435
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend


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

@@ -57,6 +57,6 @@ class InRulesConditionSwitch extends RulesConditionSwitch {
 		} else {
 			return super.caseAssignment(object);
 		}
-	}
+	}	
 
 }

+ 0 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend

@@ -40,5 +40,4 @@ public class OutRulesConditionSwitch extends RulesConditionSwitch {
 		retVal.code = '''getValue«Conversions.fmiTypeToCppTypeCapitalized(type)»(«this.externalVariableOwner»,«define»)''';
 		return retVal;
 	}
-
 }

+ 44 - 161
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend

@@ -44,8 +44,9 @@ 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
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.LessThan
 
- class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
+class RulesConditionSwitch extends BasicConditionSwitch {
 	// Global params
 	protected var LinkedHashMap<String, GlobalInOutVariable> params;
 
@@ -53,10 +54,10 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 
 	protected final String adaptationClassName;
 
-	private Integer count = 0;
+	protected Integer count = 0;
 
 	/** See the method {@link #createFunctionSignature(String, String)} and subclasses */
-	private final String functionPrefix;
+	public final String functionPrefix;
 
 	protected List<String> functionSignatures = newArrayList();
 
@@ -80,8 +81,6 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 	protected boolean inRuleOutput;
 	protected boolean inControlRule;
 
-	
-	
 	// Flag to signal whether the declarations to be processed are global or local.
 	protected boolean globalDeclaration = false;
 	// Add scope information to this.
@@ -101,6 +100,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 		LinkedHashMap<String, GlobalInOutVariable> outVars,
 		LinkedHashMap<String, GlobalInOutVariable> crtlVars
 	) {
+		super();
 		this.params = params;
 		this.SASVs = SASVs;
 		this.adaptationName = adaptationName;
@@ -115,42 +115,19 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 	/*
 	 * UTILITY FUNCTIONS 
 	 */
-	override ReturnInformation defaultCase(EObject object) {
-		var retVal = new ReturnInformation();
-		retVal.code = '''[«object.class»]''';
-		return retVal;
-	}
-
-	private def Object convertTypeToObject(SVType type, Literal object) {
-		switch (type) {
-			case Real: {
-				return (object as RealLiteral).value.doubleValue;
-			}
-			case Integer: {
-				return (object as IntLiteral).value;
-			}
-			case Boolean: {
-				return Boolean.parseBoolean((object as BoolLiteral).value);
-			}
-			default: {
-			}
-		}
-	}
-
-	public def getGlobalVars() { return this.gVars; }
-
-	public def getConstructorInitialization() { return this.constructorInitialization; }
-
 	/**
 	 * This function adds a header style function signature to the list <i>functionsignatures</i> 
 	 * and returns the source style function signature
 	 */
-	protected def String createFunctionSignature(String functionName, String type) {
-		val functionSignature = this.functionPrefix + functionName + this.count + "()";
-		this.functionSignatures.add(type + " " + functionSignature);
+	public def String createFunctionSignature(String functionName, String type, int count,
+		List<String> functionSignatures) {
+		val functionSignature = this.functionPrefix + functionName + count + "()";
+		functionSignatures.add(type + " " + functionSignature);
 		return type + " " + this.adaptationClassName + "::" + functionSignature;
 	}
 
+	public def getDataRuleCount() { return this.count; }
+
 	def void incrementCount() {
 		this.count++;
 	}
@@ -158,31 +135,21 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 	/*
 	 * COMPILATION FUNCTIONS
 	 */
-	
-	public def Pair<String, LinkedHashMap<String, GlobalInOutVariable>> getGlobalVars(EList<Declaration> gVars)
-	{
-		
-		var String constructorInitialisation= "";
-		
+	public def Pair<String, LinkedHashMap<String, GlobalInOutVariable>> getGlobalVars(EList<Declaration> gVars) {
+
 		// Get the global variables added to globalVars
 		this.globalDeclaration = true;
+		val List<String> constructorInits = newArrayList();
 		for (gVar : gVars) {
-			constructorInitialisation += doSwitch(gVar).code;
+			constructorInits.add('''«doSwitch(gVar).code»''');
 		}
 		this.globalDeclaration = false;
-		return constructorInitialisation -> this.gVars;
+		return constructorInits.join(System.lineSeparator) -> 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;
 			retVal.appendCode(doSwitch(dataRule).code);
@@ -214,7 +181,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 	override ReturnInformation caseRuleCondition(RuleCondition object) {
 		var retVal = new ReturnInformation();
 
-		val functionSignature = createFunctionSignature("condition", "bool");
+		val functionSignature = createFunctionSignature("condition", "bool", this.count, this.functionSignatures);
 		retVal.code = '''
 			«functionSignature»{
 				return «doSwitch(object.condition).code»;
@@ -227,7 +194,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 	override ReturnInformation caseStateTransitionFunction(StateTransitionFunction object) {
 		var retVal = new ReturnInformation();
 
-		val functionSig = createFunctionSignature("body", "void");
+		val functionSig = createFunctionSignature("body", "void", this.count, this.functionSignatures);
 		retVal.code = '''
 			«functionSig»{
 				«IF object.expression !== null»
@@ -309,44 +276,30 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 		return retVal;
 	}
 
-	override ReturnInformation caseMulti(Multi 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 caseDiv(Div object) {
-		val doSwitchLeft = doSwitch(object.left);
-		val doSwitchRight = doSwitch(object.right);
-		var retVal = new ReturnInformation(doSwitchLeft, doSwitchRight);
-		retVal.code = '''«doSwitchLeft.code» / «doSwitchRight.code»''';
-		retVal.type = SVType.Real;
-		retVal.forceType = true;
-		return retVal;
-	}
-
-	override ReturnInformation caseNeg(Neg object) {
-
-		var doSwitch = doSwitch(object.right);
-		var retVal = new ReturnInformation(doSwitch);
-		retVal.code = doSwitch.code;
-
-		return retVal;
-	}
-
 	override ReturnInformation caseSingleVarDeclaration(SingleVarDeclaration object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''«object.name»''';
+		var exprRes = doSwitch(object.expr);
+		var String code = "";
+		if (globalDeclaration) {
+			// This is an in var, out var or crtl var declaration
+			code = '''this->«object.name» = «exprRes.code»''';
+			var globVar = new GlobalInOutVariable(object.name, exprRes.type);
+			gVars.put(object.name, globVar)
+		} else {
+			// This is a local declaration.
+			val String type = Conversions.fmiTypeToCppType(exprRes.type)
+			code = '''«type» «object.name» = «exprRes.code»''';
+			this.localDeclarations.put(object.name, exprRes.type);
+		}
+		retVal.code = code;
 		return retVal;
+
 	}
 
 	override ReturnInformation caseCompositeOutputFunction(CompositeOutputFunction object) {
 
 		var retVal = new ReturnInformation();
-		val functionSig = createFunctionSignature("flush", "void");
+		val functionSig = createFunctionSignature("flush", "void", this.count, this.functionSignatures);
 		retVal.code = '''
 			«functionSig»{
 				«FOR stm : object.statements»
@@ -364,8 +317,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 
 		if (object.owner === null || object.owner.name == this.adaptationName) {
 
-			if ((SASVs !== null && SASVs.containsKey(object.ref.name)) || 
-				params.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))) {
@@ -411,29 +363,15 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 
 	override ReturnInformation caseDeclaration(Declaration object) {
 		var retVal = new ReturnInformation();
+		val code = '''
+			«FOR decl : object.declarations»
+				«val res = doSwitch(decl)»
+				«res.code»;
+			«ENDFOR»
+		'''
 
-		for (SingleVarDeclaration decl : object.declarations) {
-			var doSwitchRes = doSwitch(decl.expr);
-			var String code = "";
-
-			if (globalDeclaration) {
-				// This is an in var, out var or crtl var declaration	
-				code = '''
-					this->«decl.name» = «doSwitchRes.code»;
-				'''
-				var globVar = new GlobalInOutVariable(decl.name, doSwitchRes.type);
-
-				gVars.put(decl.name, globVar);
-			} else {
-				// This is a local declaration.
-				val String type = Conversions.fmiTypeToCppType(doSwitchRes.type)
-				code = '''
-					«type» «decl.name» = «doSwitchRes.code»;
-				''';
-				this.localDeclarations.put(decl.name, doSwitchRes.type);
-			}
-			retVal.appendCode = code;
-		}
+		retVal.code = code;
+		retVal.isExpression = true;
 
 		return retVal;
 	}
@@ -444,61 +382,6 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Plus
 		return retInfo;
 	}
 
-	override ReturnInformation caseRealLiteral(RealLiteral object) {
-		var retInfo = new ReturnInformation();
-		retInfo.type = SVType.Real;
-		retInfo.value = convertTypeToObject(retInfo.type, object);
-		retInfo.code = '''«object.value»''';
-		return retInfo;
-	}
-
-	override ReturnInformation caseIntLiteral(IntLiteral object) {
-		var retInfo = new ReturnInformation();
-		retInfo.type = SVType.Integer;
-		retInfo.value = convertTypeToObject(retInfo.type, object);
-		retInfo.code = '''«object.value»''';
-		return retInfo;
-	}
-
-	override ReturnInformation caseBoolLiteral(BoolLiteral object) {
-		var retInfo = new ReturnInformation();
-		retInfo.type = SVType.Boolean;
-		retInfo.value = convertTypeToObject(retInfo.type, object);
-		retInfo.code = '''«object.value»''';
-
-		return retInfo;
-	}
-
-	override ReturnInformation caseMin(Min object) {
-		var retInfo = new ReturnInformation();
-		var doSwitchResCode = newArrayList();
-		for (expr : object.args) {
-			val doSwitchRes_ = this.doSwitch(expr);
-			doSwitchResCode.add(doSwitchRes_.code);
-			retInfo = new ReturnInformation(retInfo, doSwitchRes_);
-		}
-		retInfo.code = '''
-			min({«doSwitchResCode.join(",")»})
-		'''
-		return retInfo;
-	}
-
-	override ReturnInformation caseMinus(Minus 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 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();