Browse Source

Refactored big time and fixed type issues

Casper Thule 7 years ago
parent
commit
a989bc4229
41 changed files with 1036 additions and 1133 deletions
  1. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend
  2. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  3. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest2.xtend
  4. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTestKel.xtend
  5. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppModuleTest.xtend
  6. BIN
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu
  7. BIN
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu.bu
  8. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF
  9. 0 91
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ConnectedVariable.java
  10. 0 62
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Conversions.java
  11. 0 6
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InputOutputType.java
  12. 0 26
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MapEntry.java
  13. 0 53
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend
  14. 0 37
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreatorV2.java
  15. 0 55
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SAScalarVariable.java
  16. 0 7
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVVariability.java
  17. 0 22
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Visitor.xtend
  18. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/GlobalInOutVariable.java
  19. 6 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesBlockResult.java
  20. 6 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InputOutputType.java
  21. 4 10
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MappedScalarVariable.java
  22. 26 19
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ReturnInformation.java
  23. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/RulesBlockResult.java
  24. 94 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/SAScalarVariable.java
  25. 9 9
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVCausality.java
  26. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVType.java
  27. 8 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/SVVariability.java
  28. 5 5
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java
  29. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/IncorrectAmountOfElementsException.java
  30. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InvalidConversionException.java
  31. 8 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/exceptions/MissingScalarVariableInformationException.java
  32. 5 29
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ControlConditionSwitch.xtend
  33. 93 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/Conversions.java
  34. 202 165
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend
  35. 472 469
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesConditionSwitch.xtend
  36. 6 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InRulesConditionSwitch.xtend
  37. 12 9
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend
  38. 6 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionBuilder.java
  39. 40 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescriptionCreator.java
  40. 5 11
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/OutRulesConditionSwitch.xtend
  41. 18 25
      ModelicaModels/Window.mo

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend

@@ -3,7 +3,6 @@
  */
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
 import be.uantwerpen.ansymo.semanticadaptation.testframework.XtextParametersRunnerFactory
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
@@ -27,6 +26,7 @@ import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
 import org.junit.runners.Parameterized.Parameters
 import org.junit.Ignore
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 
 @RunWith(typeof(Parameterized))
 @InjectWith(SemanticAdaptationInjectorProvider)

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

@@ -15,7 +15,6 @@ import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.generator.IGeneratorContext
 import org.eclipse.emf.ecore.resource.ResourceSet
@@ -25,6 +24,7 @@ import java.io.PrintWriter
 import java.nio.file.Files
 import java.io.FileWriter
 import org.eclipse.xtext.junit4.ui.AbstractAutoEditTest
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest2.xtend

@@ -15,11 +15,11 @@ import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.generator.IGeneratorContext
 import org.eclipse.emf.ecore.resource.ResourceSet
 import org.junit.Ignore
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTestKel.xtend

@@ -15,11 +15,11 @@ import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.generator.IGeneratorContext
 import org.eclipse.emf.ecore.resource.ResourceSet
 import org.junit.Ignore
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppModuleTest.xtend

@@ -3,7 +3,6 @@
  */
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
 import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
@@ -23,6 +22,7 @@ import org.junit.runner.RunWith
 
 import static org.junit.Assert.assertTrue
 import org.junit.Ignore
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu


BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu.bu


+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF

@@ -16,4 +16,4 @@ Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  org.eclipse.xtext.util
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Import-Package: org.apache.log4j
-Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation

+ 0 - 91
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ConnectedVariable.java

@@ -1,91 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-public class ConnectedVariable {
-
-	private SVCausality causality;
-	private SVType type;
-	private String name;
-	private String owner;
-	private InputOutputType inOut;
-	private String value;
-	private ConnectedVariable conVar;
-	private MappedScalarVariable mapSV;
-	private ConnectedVariable parent;
-	
-	public ConnectedVariable() {
-		
-	}
-
-	public SVCausality getCausality() {
-		return causality;
-	}
-
-	public void setCausality(SVCausality causality) {
-		this.causality = causality;
-	}
-
-	public SVType getType() {
-		return type;
-	}
-
-	public void setType(SVType type) {
-		this.type = type;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public String getOwner() {
-		return owner;
-	}
-
-	public void setOwner(String owner) {
-		this.owner = owner;
-	}
-
-	public InputOutputType getInOut() {
-		return inOut;
-	}
-
-	public void setInOut(InputOutputType inOut) {
-		this.inOut = inOut;
-	}
-
-	public String getValue() {
-		return value;
-	}
-
-	public void setValue(String value) {
-		this.value = value;
-	}
-
-	public ConnectedVariable getConVar() {
-		return conVar;
-	}
-
-	public void setConVar(ConnectedVariable conVar) {
-		this.conVar = conVar;
-	}
-
-	public MappedScalarVariable getMapSV() {
-		return mapSV;
-	}
-
-	public void setMapSV(MappedScalarVariable mapSV) {
-		this.mapSV = mapSV;
-	}
-
-	public ConnectedVariable getParent() {
-		return parent;
-	}
-
-	public void setParent(ConnectedVariable parent) {
-		this.parent = parent;
-	}
-
-}

+ 0 - 62
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Conversions.java

@@ -1,62 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-public class Conversions {
-	public static String fmiTypeToCppType(SVType t) throws InvalidConversionException {
-		switch (t) {
-		case Real:
-			return "double";
-		case Integer:
-			return "int";
-		case Boolean:
-			return "bool";
-		case String:
-			return "string";
-		default:
-			throw new InvalidConversionException("The value type: " + t + " is invalid.");
-		}
-	}
-	
-	public static SVVariability fmiTypeToVariability(SVType t) throws InvalidConversionException{
-		switch (t) {
-		case Real:
-			return SVVariability.continuous;
-		case Integer:
-		case Boolean:
-		case String:
-			return SVVariability.discrete;
-		default:
-			throw new InvalidConversionException("The value type: " + t + " is invalid.");
-		}
-	}
-
-	public static String fmiTypeToCppTypeName(SVType t) throws InvalidConversionException {
-		switch (t) {
-		case Real:
-			return "Double";
-		case Integer:
-			return "Integer";
-		case Boolean:
-			return "Bool";
-		case String:
-			return "String";
-		default:
-			throw new InvalidConversionException("The value type: " + t + " is invalid.");
-		}
-	}
-
-	public static String fmiTypeToCppDefaultValue(SVType t) throws InvalidConversionException {
-		switch (t) {
-		case Real:
-			return "0.0";
-		case Integer:
-			return "0";
-		case Boolean:
-			return "false";
-		case String:
-			return "\"\"";
-		default:
-			throw new InvalidConversionException("The value type: " + t + " is invalid.");
-		}
-	}
-
-}

+ 0 - 6
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InputOutputType.java

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

+ 0 - 26
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MapEntry.java

@@ -1,26 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-import java.util.Map.Entry;
-
-public class MapEntry<K, V> implements Entry<K, V> {
-    private final K key;
-    private V value;
-    public MapEntry(final K key) {
-        this.key = key;
-    }
-    public MapEntry(final K key, final V value) {
-        this.key = key;
-        this.value = value;
-    }
-    public K getKey() {
-        return key;
-    }
-    public V getValue() {
-        return value;
-    }
-    public V setValue(final V value) {
-        final V oldValue = this.value;
-        this.value = value;
-        return oldValue;
-    }
-}

+ 0 - 53
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend

@@ -1,53 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-import java.util.List;
-import java.util.Vector;
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InnerFMU
-import java.io.File
-import org.w3c.dom.Document
-import java.util.zip.ZipFile
-import java.util.Enumeration
-import java.util.zip.ZipEntry
-import javax.xml.parsers.DocumentBuilderFactory
-import javax.xml.parsers.DocumentBuilder
-import java.util.HashMap
-import java.util.Map
-import javax.xml.xpath.XPathFactory
-import javax.xml.xpath.XPath
-import javax.xml.xpath.XPathExpression
-import org.w3c.dom.Node
-import javax.xml.xpath.XPathConstants
-import java.util.UUID
-
-public class ModelDescriptionCreator {
-	private List<ScalarVariable> sVars = new Vector<ScalarVariable>();
-	private ModelDescriptionBuilder mdBuilder = new ModelDescriptionBuilder();
-	private String mdName;
-	private String guid;
-
-	def String getModelDescription() {
-		if (mdName === null) {
-			throw new IllegalStateException("Model Description name is missing");
-		}
-		mdBuilder.CreateTemplate(mdName, UUID.randomUUID().toString);
-		for (sVar : sVars) {
-			mdBuilder.addScalarVariable(sVar);
-		}
-
-		return mdBuilder.toString();
-	}
-
-	def void setName(String name) {
-		mdName = name;
-	}
-
-	public def List<ScalarVariable> getScalars() {
-		return this.sVars;
-	}
-
-	def void CalcContent(ModelDescription md) {
-		sVars.addAll(md.getSv().values);
-	}
-
-}

+ 0 - 37
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreatorV2.java

@@ -1,37 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
-
-import org.eclipse.xtext.xbase.lib.Pair;
-
-// TODO: Add ports not mentioned in the sa file to the model description
-public class ModelDescriptionCreatorV2 {
-
-	ArrayList<SAScalarVariable> SVs;
-	ArrayList<SAScalarVariable> outputSVs;
-	
-	public ModelDescriptionCreatorV2(String adaptationName,
-			LinkedHashMap<String, Pair<SVType, Object>> globalOutputVars,
-			LinkedHashMap<String, Pair<SVType, Object>> globalInputVars,
-			LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables) {
-		int valueRef = 1;
-		
-		for (Entry<String, Pair<SVType, Object>> outputVar : globalOutputVars.entrySet()) {
-			// Find the corresponding correct SV value
-			MappedScalarVariable foundSV = null;
-			for (Entry<String, LinkedHashMap<String, MappedScalarVariable>> mSV : mappedScalarVariables.entrySet()) {
-				if (mSV.getValue().containsKey(outputVar.getKey())) {
-					foundSV = mSV.getValue().get(outputVar.getKey());
-					break;
-				}
-			}
-			if(foundSV != null)
-			{
-				SAScalarVariable saSV = new SAScalarVariable();
-			}
-		}
-
-	}
-}

+ 0 - 55
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SAScalarVariable.java

@@ -1,55 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-import java.util.Optional;
-
-public class SAScalarVariable {
-
-	public MappedScalarVariable sv = null;
-	public String defineName;
-	public Integer valueReference;
-	private SVCausality causality;
-	private SVType type;
-	private String name;
-	private Optional<SVVariability> variability = Optional.empty();
-	
-	public SAScalarVariable() {
-		// TODO Auto-generated constructor stub
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public SVCausality getCausality() {
-		return causality;
-	}
-
-	public void setCausality(SVCausality causality) {
-		this.causality = causality;
-	}
-
-	public SVType getType() {
-		return type;
-	}
-
-	public void setType(SVType type) {
-		this.type = type;
-	}
-
-	public Optional<SVVariability> getVariability() {
-		return variability;
-	}
-
-	/*
-	 * The variability will only be updated if it is not set.
-	 */
-	public void setVariability(Optional<SVVariability> variability) {
-		if(!this.variability.isPresent())
-		this.variability = variability;
-	}
-
-}

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

@@ -1,7 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-public enum SVVariability {
-	continuous,
-	discrete
-
-}

+ 0 - 22
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Visitor.xtend

@@ -1,22 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
-
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
-import org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter
-import com.google.inject.Inject
-import com.google.inject.Provider
-import org.eclipse.xtext.xbase.interpreter.IEvaluationContext
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Expression
-import org.eclipse.xtext.xbase.interpreter.IEvaluationResult
-
-class Visitor<CharSequence> extends SemanticAdaptationSwitch<String> {
-	
-	override String caseSemanticAdaptation(SemanticAdaptation adaptatoin) {
-		return '''a''';		
-	}
-	
-	override String caseExpression(Expression object){
-		return '''object''';
-	}
-	
-}

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

@@ -1,4 +1,4 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 public class GlobalInOutVariable {
 

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

@@ -1,6 +1,5 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 
@@ -8,10 +7,14 @@ import org.eclipse.xtext.xbase.lib.Pair;
 
 public class InOutRulesBlockResult extends RulesBlockResult {
 	public final LinkedHashMap<String, Pair<SVType, Object>> globalVars;
+	public final LinkedHashMap<String, GlobalInOutVariable> globalVars2;
 
-	public InOutRulesBlockResult(String generatedCpp, List<String> functionSignatures, LinkedHashMap<String, Pair<SVType, Object>> globalVars)
+	public InOutRulesBlockResult(String generatedCpp, List<String> functionSignatures, 
+			LinkedHashMap<String, Pair<SVType, Object>> globalVars, 
+			LinkedHashMap<String, GlobalInOutVariable> globalVars2)
 	{
 		super(generatedCpp, functionSignatures);
 		this.globalVars = globalVars;
+		this.globalVars2 = globalVars2;
 	}
 }

+ 6 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InputOutputType.java

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

+ 4 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MappedScalarVariable.java

@@ -1,9 +1,8 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 public class MappedScalarVariable {
 
 	private String define;
-	private int valueReference;
 	private ScalarVariable mappedSV;
 	public MappedScalarVariable(ScalarVariable sv) {
 		this.mappedSV = sv;
@@ -23,15 +22,10 @@ public class MappedScalarVariable {
 	{
 		return this.define;
 	}
-	
-	public void setValueReference(int valueReference)
-	{
-		this.valueReference = valueReference;
-	}
-	
-	public int getValueReference()
+
+	public String getValueReference()
 	{
-		return this.valueReference;
+		return this.mappedSV.getValueReference();
 	}
 
 }

+ 26 - 19
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ReturnInformation.java

@@ -1,6 +1,7 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.ReturnInformation;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.InvalidConversionException;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.Conversions;
 
 public class ReturnInformation {
 
@@ -31,9 +32,13 @@ public class ReturnInformation {
 		return type;
 	}
 
-	public void setType(SVType type) {
-		this.type = type;
-		this.typeIsSet = true;
+	public void setType(SVType type) throws InvalidConversionException {
+		if (this.typeIsSet) {
+			this.type = Conversions.typeDecider(this.type, type);
+		} else {
+			this.type = type;
+			this.typeIsSet = true;
+		}
 	}
 
 	public Object getValue() {
@@ -60,14 +65,22 @@ public class ReturnInformation {
 		return conGlobVar;
 	}
 
-	public void setConGlobVar(GlobalInOutVariable conGlobVar) {
+	public void setConGlobVar(GlobalInOutVariable conGlobVar) throws InvalidConversionException {
 		this.conGlobVar = conGlobVar;
+		if (this.typeIsSet) {
+			this.type = Conversions.typeDecider(conGlobVar.getType(), this.type);
+		}
+		else
+		{
+			this.type = conGlobVar.getType();
+			this.typeIsSet = true;
+		}
 	}
 
 	/*
 	 * This method automatically extracts information that should be passed on
 	 */
-	ReturnInformation(ReturnInformation information) {
+	public ReturnInformation(ReturnInformation information) throws InvalidConversionException {
 
 		this.conGlobVar = information.conGlobVar;
 		if (information.typeIsSet)
@@ -76,7 +89,7 @@ public class ReturnInformation {
 
 	}
 
-	ReturnInformation(ReturnInformation information, ReturnInformation information2) throws Exception {
+	public ReturnInformation(ReturnInformation information, ReturnInformation information2) throws Exception {
 		if (information.conGlobVar != null) {
 			if (information2.conGlobVar != null) {
 				if (information.conGlobVar == information2.conGlobVar) {
@@ -103,8 +116,7 @@ public class ReturnInformation {
 				this.setType(information.getType());
 			} else {
 				if (information.getType() != information2.getType()) {
-					throw new Exception("Two connected return informations have the wrong type: "
-							+ information.getType() + " and " + information2.getType());
+					this.type = Conversions.typeDecider(information.getType(), information2.getType());
 				} else {
 					this.setType(information.getType());
 				}
@@ -124,20 +136,15 @@ public class ReturnInformation {
 				} else {
 					this.setConSaSv(information.ConSaSv);
 				}
-			}
-			else
-			{
+			} else {
 				this.setConSaSv(information.ConSaSv);
 			}
-		}
-		else
-		{
-			if (information2.ConSaSv != null)
-			{
+		} else {
+			if (information2.ConSaSv != null) {
 				this.setConSaSv(information2.ConSaSv);
 			}
 		}
-		
+
 	}
 
 }

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

@@ -1,4 +1,4 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 import java.util.List;
 

+ 94 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/SAScalarVariable.java

@@ -0,0 +1,94 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
+
+import java.util.ArrayList;
+import java.util.Optional;
+
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.MissingScalarVariableInformationException;
+
+public class SAScalarVariable {
+
+	private String defineName;
+	private Optional<Integer> valueReference = Optional.empty();
+	private Optional<SVCausality> causality = Optional.empty();
+	private Optional<SVType> type = Optional.empty();;
+	private String name;
+	private Optional<SVVariability> variability = Optional.empty();
+
+	public ScalarVariable CalcSVar() throws MissingScalarVariableInformationException {
+
+		ArrayList<String> error = new ArrayList<String>();
+		if (!this.causality.isPresent()) {
+			error.add("Missing causality information");
+		}
+		if (!this.type.isPresent()) {
+			error.add("Missing type information");
+		}
+		if (!this.variability.isPresent()) {
+			error.add("Missing variability information");
+		}
+		if (this.name == null) {
+			error.add("Missing name information");
+		}
+		if (!this.valueReference.isPresent()) {
+			error.add("Missing value reference information");
+		}
+
+		if (error.isEmpty()) {
+			return ScalarVariable.Create().setCausality(this.causality.get()).setVariability(this.variability.get())
+					.setType(this.type.get()).setName(this.name).setValueReference(this.getValueReference().toString());
+		} else {
+			throw new MissingScalarVariableInformationException(String.join(" -- ", error));
+		}
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Optional<SVCausality> getCausality() {
+		return causality;
+	}
+
+	public void setCausality(SVCausality causality) {
+		this.causality = Optional.of(causality);
+	}
+
+	public Optional<SVType> getType() {
+		return type;
+	}
+
+	public void setType(SVType type) {
+		this.type = Optional.of(type);
+	}
+
+	public Optional<SVVariability> getVariability() {
+		return variability;
+	}
+
+	public void setVariability(SVVariability variability) {
+		this.variability = Optional.of(variability);
+	}
+
+	public Integer getValueReference() throws MissingScalarVariableInformationException {
+		if (!this.valueReference.isPresent()) {
+			throw new MissingScalarVariableInformationException("Missing value reference information");
+		}
+		return valueReference.get();
+	}
+
+	public void setValueReference(Integer valueReference) {
+		this.valueReference = Optional.of(valueReference);
+	}
+
+	public String getDefineName() {
+		return defineName;
+	}
+
+	public void setDefineName(String defineName) {
+		this.defineName = defineName;
+	}
+}

+ 9 - 9
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVCausality.java

@@ -1,9 +1,9 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-//Changing these names must be reflected in the ModelDescriptionBuilder as well
-public enum SVCausality {
-	output,
-	local,
-	input,
-	parameter,
-}
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
+
+//Changing these names must be reflected in the ModelDescriptionBuilder as well
+public enum SVCausality {
+	output,
+	local,
+	input,
+	parameter,
+}

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

@@ -1,4 +1,4 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 //Changing these names must be reflected in the ModelDescriptionBuilder as well
 public enum SVType {

+ 8 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/SVVariability.java

@@ -0,0 +1,8 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
+
+public enum SVVariability {
+	continuous,
+	discrete,
+	fixed,
+
+}

+ 5 - 5
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java

@@ -1,11 +1,11 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 public class ScalarVariable {
 	private String owner;
 	private String name;
 	private String valueReference;
 	private String description;
-	private String variability;
+	private SVVariability variability;
 	private SVCausality causality;
 	private String initial;
 	private SVType type;
@@ -58,12 +58,12 @@ public class ScalarVariable {
 		return this;
 	}
 
-	public String getVariability() {
+	public SVVariability getVariability() {
 		return variability;
 	}
 
-	public ScalarVariable setVariability(String variability) {
-		this.variability = variability;
+	public ScalarVariable setVariability(SVVariability svVariability) {
+		this.variability = svVariability;
 		return this;
 	}
 

+ 1 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/IncorrectAmountOfElementsException.java

@@ -1,7 +1,6 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions;
 
 public class IncorrectAmountOfElementsException extends Exception {
-	
 	public IncorrectAmountOfElementsException(String arg0) {
 		super(arg0);
 	}

+ 1 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InvalidConversionException.java

@@ -1,7 +1,6 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions;
 
 public class InvalidConversionException extends Exception {
-
 	// Constructor that accepts a message
 	public InvalidConversionException(String message) {
 		super(message);

+ 8 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/exceptions/MissingScalarVariableInformationException.java

@@ -0,0 +1,8 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions;
+
+public class MissingScalarVariableInformationException extends Exception {
+	public MissingScalarVariableInformationException(String message) {
+		super(message);
+	}
+
+}

+ 5 - 29
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ControlConditionSwitch.xtend

@@ -1,18 +1,19 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CustomControlRule
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DoStep
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StepSize
-import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
 
 class ControlConditionSwitch extends InOutRulesConditionSwitch {
 
 	new(String adaptationClassName, 
 		String adaptationName, 
-		LinkedHashMap<String, Pair<String, Integer>> scalars,
 		LinkedHashMap<String,SAScalarVariable> SASVs
 	) {
 		super(adaptationClassName, adaptationName, "", null, SASVs);
@@ -26,14 +27,6 @@ class ControlConditionSwitch extends InOutRulesConditionSwitch {
 		}
 
 		return retVal;
-		
-		
-//		var cpp = "";
-//		for (crtlRule : obj.eAllContents.toIterable.filter(ControlRule)) {
-//			cpp += doSwitch(crtlRule);
-//		}
-//
-//		return cpp;
 	}
 
 	override ReturnInformation caseCustomControlRule(CustomControlRule object) {
@@ -56,40 +49,23 @@ class ControlConditionSwitch extends InOutRulesConditionSwitch {
 			''';
 
 		return retVal;
-//		var String returnVal = "";
-//
-//		for (ruleStm : object.controlRulestatements) {
-//			returnVal += doSwitch(ruleStm);
-//		}
-
-//		var functionPrefix = "void ";
-//		var functionNameArgs = "executeInternalControlFlow(double h, double dt)"
-//		functionSignatures.add(functionPrefix + functionNameArgs + ";");
-//		return '''
-//		«functionPrefix+this.adaptationName»::«functionNameArgs»
-//		{
-//			«returnVal»
-//		}''';
 	}
 
 	override ReturnInformation caseDoStep(DoStep object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''this->doStep(«object.fmu.name»,«doSwitch(object.h)»,«doSwitch(object.t)»);''';
 		return retVal;
-//		return '''this->doStep(«object.fmu.name»,«doSwitch(object.h)»,«doSwitch(object.t)»);''';
 	}
 
 	override ReturnInformation caseStepSize(StepSize object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''h''';
 		return retVal;
-//		return '''h''';
 	}
 
 	override ReturnInformation caseCurrentTime(CurrentTime object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''dt''';
 		return retVal;
-//		return '''dt''';
 	}
 }

+ 93 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/Conversions.java

@@ -0,0 +1,93 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
+
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVVariability;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.InvalidConversionException;
+
+public class Conversions {
+	public static String fmiTypeToCppType(SVType t) throws InvalidConversionException {
+		switch (t) {
+		case Real:
+			return "double";
+		case Integer:
+			return "int";
+		case Boolean:
+			return "bool";
+		case String:
+			return "string";
+		default:
+			throw new InvalidConversionException("The value type: " + t + " is invalid.");
+		}
+	}
+
+	public static SVVariability fmiTypeToFmiVariability(SVType t) throws InvalidConversionException {
+		switch (t) {
+		case Real:
+			return SVVariability.continuous;
+		case Integer:
+		case Boolean:
+		case String:
+			return SVVariability.discrete;
+		default:
+			throw new InvalidConversionException("The value type: " + t + " is invalid.");
+		}
+	}
+
+	public static String fmiTypeToCppDefaultValue(SVType t) throws InvalidConversionException {
+		switch (t) {
+		case Real:
+			return "0.0";
+		case Integer:
+			return "0";
+		case Boolean:
+			return "false";
+		case String:
+			return "\"\"";
+		default:
+			throw new InvalidConversionException("The value type: " + t + " is invalid.");
+		}
+	}
+
+	public static SVType typeDecider(SVType t1, SVType t2) throws InvalidConversionException {
+		switch (t1) {
+		case Real:
+			switch (t2) {
+			case Real:
+			case Integer:
+				return SVType.Real;
+			default:
+				throw new InvalidConversionException(
+						"The type: " + t1.name() + " is unmergable with " + t2.name() + ".");
+			}
+		case Integer:
+			switch (t2) {
+			case Real:
+				return SVType.Real;
+			case Integer:
+				return SVType.Integer;
+			default:
+				throw new InvalidConversionException(
+						"The type: " + t1.name() + " is unmergable with " + t2.name() + ".");
+			}
+		case Boolean:
+			switch (t2) {
+			case Boolean:
+				return SVType.Boolean;
+			default:
+				throw new InvalidConversionException(
+						"The type: " + t1.name() + " is unmergable with " + t2.name() + ".");
+			}
+		case String:
+			switch (t2) {
+			case String:
+				return SVType.String;
+			default:
+				throw new InvalidConversionException(
+						"The type: " + t1.name() + " is unmergable with " + t2.name() + ".");
+			}
+		default:
+			throw new InvalidConversionException("The type: " + t1 + " is invalid.");
+		}
+	}
+
+}

+ 202 - 165
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -1,27 +1,36 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
 import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationGenerator
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InOutRules
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InnerFMU
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
+import org.eclipse.xtext.generator.IFileSystemAccess2
+
+import org.eclipse.xtext.generator.IGeneratorContext
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
-import java.io.File
+import org.eclipse.emf.ecore.resource.Resource
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
 import java.util.ArrayList
 import java.util.LinkedHashMap
-import org.eclipse.emf.ecore.resource.Resource
-import org.eclipse.xtext.generator.IFileSystemAccess2
-import org.eclipse.xtext.generator.IGeneratorContext
-import java.util.Collection
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.MappedScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InnerFMU
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.IncorrectAmountOfElementsException
+import java.io.File
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.InputOutputType
 import org.eclipse.emf.common.util.EList
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality
+import java.util.Collection
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InOutRules
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.InOutRulesBlockResult
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.RulesBlockResult
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
+import java.util.List
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 
 class CppGenerator extends SemanticAdaptationGenerator {
-
-	var ModelDescriptionCreator mdCreator = new ModelDescriptionCreator()
-
 	private var IFileSystemAccess2 fsa;
 
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
@@ -32,22 +41,25 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		}
 	}
 
-// TODO: Verify adaptation.name is not a C++ keyword
-// TODO: Add initial value to inputs in the model description file
+	// TODO: Verify adaptation.name is not a C++ keyword
 	def void compile(SemanticAdaptation adaptation) {
 		for (Adaptation type : adaptation.elements.filter(Adaptation)) {
+			// Value used for scoping variables in the .sa file
 			val adapInteralRefName = type.name;
+
+			// The CPP class name
 			val adapClassName = type.name.toFirstUpper;
+
+			// This is the external name used in the model description file for the semantic adaptation FMU.
 			val adapExternalName = type.type.name;
-			var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
+
+			// List of FMUs with a pairing between its name and its type.name.
 			var ArrayList<Pair<String, String>> fmus = newArrayList();
-			var LinkedHashMap<String, ScalarVariable> sVars = newLinkedHashMap();
-			var String genSource = "";
-			var ModelDescription md;
-			var LinkedHashMap<String, Collection<ScalarVariable>> scalarVariables = newLinkedHashMap();
-			var LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables = newLinkedHashMap();			
 
-			// Load Model Description file
+			// The scalar variables above with additional data
+			var LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables = newLinkedHashMap();
+
+			// TODO: Currently only 1 inner fmu is supported
 			val innerFmus = type.inner.eAllContents.toList.filter(InnerFMU);
 			if (innerFmus.size > 1) {
 				throw new IncorrectAmountOfElementsException("Only one InnerFmu is supported.")
@@ -56,95 +68,136 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				throw new IncorrectAmountOfElementsException("The adaptation does not contain any InnerFMUs.")
 			}
 
-			var LinkedHashMap<String,SAScalarVariable> SASVs = calcSASVsFromInportsOutports(adapInteralRefName, type.inports, type.outports)
-
+			/*
+			 * Loading the FMU defined in InnerFMU, the related model description file and its scalar variables.
+			 * This is stored in a map of fmuName -> (SVName -> mappedSV)
+			 * where the mappedSV contains the original scalar variable and some extra data such as define name. 
+			 */
+			// TODO: Currently only 1 model description is supported
+			var ModelDescription md;
 			for (fmu : type.inner.eAllContents.toList.filter(InnerFMU)) {
-				// TODO: Merge this with ModelDescriptionCreator
 				md = new ModelDescription(fmu.name, fmu.type.name, new File(fmu.path.replace('\"', '')));
 				fmus.add(fmu.name -> fmu.type.name);
-				svDefs.putAll(md.svDef);
-				sVars.putAll(md.sv);
-				scalarVariables.put(fmu.name, md.sv.values);
-
-				mdCreator.name = adapExternalName;
-				mdCreator.CalcContent(md);
-				fsa.generateFile("modelDescription.xml", mdCreator.modelDescription);
-			}
-
-			/*
-			 * We might have conflicting scalar variables, 
-			 * and therefore the scalar variables cannot be directly mapped to the mdCreator.
-			 * mappedScalarVariables is therefore: HashMap (fmuName -> HashMap(SVName->mappedSV))
-			 */
-			for (mdSv : scalarVariables.entrySet) {
-				val LinkedHashMap<String, MappedScalarVariable> msv = newLinkedHashMap();
-				for (sv : mdSv.value) {
+				val LinkedHashMap<String, MappedScalarVariable> mSV = newLinkedHashMap();
+				for (sv : md.sv.values) {
 					var mappedSv = new MappedScalarVariable(sv);
 					mappedSv.define = (mappedSv.mappedSv.owner + mappedSv.mappedSv.name).toUpperCase;
-					msv.put(mappedSv.mappedSv.name, mappedSv);
+					mSV.put(mappedSv.mappedSv.name, mappedSv);
 				}
-				mappedScalarVariables.put(mdSv.key, msv);
+				mappedScalarVariables.put(fmu.name, mSV);
 			}
-			
+
+			// Defines for accessing FMU scalar variables.
+			val String fmusDefines = calcDefines2(mappedScalarVariables);
+
+			/*
+			 * 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. 
+			 */
+			var LinkedHashMap<String, SAScalarVariable> SASVs = calcSASVsFromInportsOutports(adapInteralRefName,
+				type.inports, type.outports)
+
+			// Generate defines for the scalar variables of the semantic adaptation 
+			val String SADefines = calcSADefines(SASVs.values);
+
 			// Compile the in rules
 			val inRuleResult = compileInOutRuleBlocks(InputOutputType.Input, adaptation.eAllContents.toIterable.filter(
 				InRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs);
-			genSource += inRuleResult.generatedCpp;
 
 			// Compile the out rules
 			val outRuleResult = compileInOutRuleBlocks(InputOutputType.Output, adaptation.eAllContents.toIterable.
-				filter(OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs);
-			genSource += outRuleResult.generatedCpp;
+				filter(OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables,
+				SASVs);
+
+			// Merge the global variables
+			// TODO: Check for duplicates
+			var LinkedHashMap<String, GlobalInOutVariable> globalVariables = newLinkedHashMap();
+			globalVariables.putAll(outRuleResult.globalVars2);
+			globalVariables.putAll(inRuleResult.globalVars2);
+
+			// Compile the Control Rules
+			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
+				adapClassName, adapInteralRefName, SASVs);
 
 			/*
-			 * We now have the explicit input and output values determined in the SA. 
-			 * This along with the model descriptions should be enough to create a model description for the SA FMU. 
+			 * As the in and out rules have populated the semantic adaptation scalar variables we can generate the getFmiValue* and setFmiValue functions.
 			 */
-			// Generate the Control Rules
-			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
-				adapClassName, adapInteralRefName, svDefs, SASVs);
-			genSource += crtlRuleResult.generatedCpp;
-
-			// Compile the source file includes, namespace and constructor 
-			val String include = '''#include "«adapClassName.toFirstLower».h"''';
-			val String constructor = compileDeAndConstructor(adapClassName, outRuleResult, inRuleResult, sVars,
-				fmus.head.key, fmus.head.value, md.guid);
-			val String getRuleThis = compileGetRuleThis(adapClassName);
-
-			// Compile the get functions
-			val String getFuncs = compileGetFmuValue(adapClassName, sVars, svDefs);
-
-			// Compile the set functions
-			val String setFuncs = compileSetFmuValue(adapClassName, sVars, svDefs);
-
-			// Generate the source file for the SA
-			val source = compileSource(
-				include,
-				constructor,
-				getRuleThis,
-				getFuncs,
-				setFuncs,
+			val String getFuncsSource = compileGetFmiValueFunctions(adapClassName, SASVs);
+			val String setFuncsSource = compileSetFmiValueFunctions(adapClassName, SASVs);
+			
+
+			/*
+			 * Compile the de and constructors
+			 */
+			val String deAndConstructorSource = compileDeAndConstructor(adapClassName, globalVariables, fmus.head.key,
+				fmus.head.value, md.guid);
+
+			/*
+			 * Compile getRuleThis function
+			 */
+			val String getRuleThisSource = compileGetRuleThis(adapClassName);
+
+			// Compile the source file
+			val String sourceInclude = '''#include "«adapClassName.toFirstLower».h"''';
+			val sourceFile = compileSource(
+				sourceInclude,
+				deAndConstructorSource,
+				getRuleThisSource,
+				getFuncsSource,
+				setFuncsSource,
 				inRuleResult.generatedCpp,
-				crtlRuleResult.generatedCpp,
-				outRuleResult.generatedCpp
+				outRuleResult.generatedCpp,
+				crtlRuleResult.generatedCpp
+			);
+			fsa.generateFile(adapClassName.toFirstLower + ".cpp", sourceFile);
+
+			// Compile the header file
+			val headerFile = compileHeader(
+				adapClassName,
+				fmusDefines,
+				SADefines,
+				inRuleResult.functionSignatures,
+				outRuleResult.functionSignatures,
+				crtlRuleResult.functionSignatures,
+				globalVariables,
+				fmus,
+				SASVs.values.map[CalcSVar()].toList
 			);
+			fsa.generateFile(adapClassName.toFirstLower + ".h", headerFile);
+
+			// Compile the model description file
+			val modelDescCreator = new ModelDescriptionCreator(adapExternalName);
+			val modelDescription = modelDescCreator.generateModelDescription(SASVs.values);
+			fsa.generateFile("modelDescription.xml", modelDescription);
+
+		}
+	}
+
+	def calcSADefines(Collection<SAScalarVariable> variables) {
+		var ArrayList<String> defines = newArrayList();
+
+		for (SASV : variables) {
+			defines.add("#define " + SASV.defineName + " " + SASV.valueReference);
+		}
 
-			fsa.generateFile(adapClassName.toFirstLower + ".cpp", source);
+		return defines.join("\n");
+	}
 
-			// Compile defines for the scalar variables
-			var genDef = calcDefines(svDefs).join("\n");
-			// Compile the class definition file for the SA
-			val String header = compileHeader(adapClassName, inRuleResult, outRuleResult, crtlRuleResult, fmus, sVars,
-				genDef);
+	def calcDefines2(LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> map) {
+		var ArrayList<String> defines = newArrayList();
 
-			// Generate the header file for the SA
-			fsa.generateFile(adapClassName.toLowerCase + ".h", header);
+		for (fmuEntries : map.entrySet) {
+			for (MappedScalarVariable mSV : fmuEntries.value.values) {
+				defines.add("#define " + mSV.define + " " + mSV.valueReference);
+			}
 		}
+
+		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 controlFunction, String outFunctions) {
+		String setFunctions, String inFunctions, String outFunctions, String controlFunction) {
 		return '''
 			«include»
 			
@@ -173,9 +226,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * 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 adaptationName, InOutRulesBlockResult inRulesResult,
-		InOutRulesBlockResult outRulesResult, RulesBlockResult crtlRulesResult, ArrayList<Pair<String, String>> fmus,
-		LinkedHashMap<String, ScalarVariable> sVars, String defines) {
+	def String compileHeader(String adapClassName, String fmusDefines, String SADefines, List<String> inRulesFuncSig,
+		List<String> outRulesFuncSig, List<String> crtlRulesFuncSig,
+		LinkedHashMap<String, GlobalInOutVariable> globalVariables, ArrayList<Pair<String, String>> fmus,
+		Collection<ScalarVariable> sVars) {
 		return '''
 			#include "SemanticAdaptation.h"
 			#include <memory>
@@ -186,11 +240,15 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			
 			namespace adaptation
 			{
+				
+				«fmusDefines»
+				
+				«SADefines»
 			
-				class «adaptationName» : public SemanticAdaptation<«adaptationName»>{
+				class «adapClassName» : public SemanticAdaptation<«adapClassName»>{
 					public:
-						«adaptationName»(shared_ptr<string> resourceLocation);
-						virtual ~«adaptationName»();
+						«adapClassName»(shared_ptr<string> resourceLocation);
+						virtual ~«adapClassName»();
 						
 						void setFmiValue(fmi2ValueReference id, int value);
 						void setFmiValue(fmi2ValueReference id, bool value);
@@ -201,33 +259,29 @@ class CppGenerator extends SemanticAdaptationGenerator {
 						double getFmiValueDouble(fmi2ValueReference id);
 					private:
 						
-						«adaptationName»* getRuleThis();
+						«adapClassName»* getRuleThis();
 						
 						/*in rules*/
-						«inRulesResult.functionSignatures.join("\n")»
+						«inRulesFuncSig.join("\n")»
 						
 						/*out rules*/
-						«outRulesResult.functionSignatures.join("\n")»
+						«outRulesFuncSig.join("\n")»
 						
-						«crtlRulesResult.functionSignatures.join("\n")»
+						«crtlRulesFuncSig.join("\n")»
 						
 						«FOR fmu : fmus»
 							shared_ptr<FmuComponent> «fmu.key»;
 						«ENDFOR»
 						
-						«FOR sv : sVars.entrySet»
-							«Conversions.fmiTypeToCppType(sv.value.type)» «sv.value.name»;
-							«IF sv.value.causality == SVCausality.input»
-								bool isSet«sv.value.name»;
+						«FOR sv : sVars»
+							«Conversions.fmiTypeToCppType(sv.type)» «sv.name»;
+							«IF sv.causality == SVCausality.input»
+								bool isSet«sv.name»;
 							«ENDIF»
 						«ENDFOR»
 						
-						«FOR v : outRulesResult.globalVars.entrySet»
-							«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
-						«ENDFOR»
-						
-						«FOR v : inRulesResult.globalVars.entrySet»
-							«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
+						«FOR v : globalVariables.entrySet»
+							«Conversions.fmiTypeToCppType(v.value.type)» «v.key»;
 						«ENDFOR»
 				}
 			}
@@ -237,32 +291,21 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	/*
 	 * Compiles the source file constructor and destructor
 	 */
-	def String compileDeAndConstructor(String adaptationName, InOutRulesBlockResult outRuleResult,
-		InOutRulesBlockResult inRuleResult, LinkedHashMap<String, ScalarVariable> sVars, String fmuName,
-		String fmuTypeName, String guid) {
+	def String compileDeAndConstructor(String adapClassName, LinkedHashMap<String, GlobalInOutVariable> globalVariables,
+		String fmuName, String fmuTypeName, String guid) {
 		return '''
-			«adaptationName»::«adaptationName»(shared_ptr<string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
+			«adapClassName»::«adapClassName»(shared_ptr<string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
 			{
-				«FOR v : outRuleResult.globalVars.entrySet»
-					«(v.key)» = «v.value.value»;
-				«ENDFOR»
-				
-				«FOR v : inRuleResult.globalVars.entrySet»
+				«FOR v : globalVariables.entrySet»
 					this->«(v.key)» = «v.value.value»;
 				«ENDFOR»
 				
-				«FOR v : sVars.entrySet»
-					«IF v.value.start !== null»
-						this->«(v.key)» = «v.value.start»;
-					«ENDIF»
-				«ENDFOR»
-				
 				const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("«fmuTypeName».fmu"))->c_str();
 				auto «fmuName»Fmu = make_shared<fmi2::Fmu>(path);
 				«fmuName»Fmu->initialize();
-				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuTypeName»",fmi2CoSimulation, "«guid»", true, true, make_shared<Callback>()); 
+				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuName»",fmi2CoSimulation, "«guid»", true, true, make_shared<Callback>()); 
 			}
-			«adaptationName»::~«adaptationName»()
+			«adapClassName»::~«adapClassName»()
 			{
 			}
 		''';
@@ -283,25 +326,25 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	/*
 	 * Compiles the source file functions getFmiValue<double, int, string, bool>
 	 */
-	def String compileGetFmuValue(String adaptationName, LinkedHashMap<String, ScalarVariable> sVars,
-		LinkedHashMap<String, Pair<String, Integer>> sVarDefs) {
+	def String compileGetFmiValueFunctions(String adaptationName, LinkedHashMap<String, SAScalarVariable> variables) {
 		var ArrayList<String> cpp = newArrayList();
-		var sVarsOrdered = sVars.entrySet.filter[value.causality === SVCausality.output].groupBy[value.type];
+		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 functionSignature = '''«Conversions.fmiTypeToCppType(type)» «adaptationName»::getFmiValue«type.toString»(fmi2ValueReference id)''';
 			val functionReturn = '''return «Conversions.fmiTypeToCppDefaultValue(type)»''';
-			if (sVarsOrdered.containsKey(type)) {
+			if (convertedSASVsOrdered.containsKey(type)) {
 				cpp.add(
 					'''
 						«functionSignature»
 						{
 							switch (id)
 							{
-								«FOR svInner : sVarsOrdered.get(type)»
-									case «sVarDefs.get(svInner.value.owner + svInner.value.name).key»:
+								«FOR svInner : convertedSASVsOrdered.get(type)»
+									case «variables.get(svInner.name).defineName»:
 									{
-										return this->«svInner.key»;
+										return this->«svInner.name»;
 									}
 								«ENDFOR»
 								default:
@@ -331,25 +374,26 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	/*
 	 * Compiles the source file functions setFmiValue<double, int, string, bool>*
 	 */
-	def String compileSetFmuValue(String adaptationName, LinkedHashMap<String, ScalarVariable> sVars,
-		LinkedHashMap<String, Pair<String, Integer>> sVarDefs) {
+	def String compileSetFmiValueFunctions(String adapClassName, LinkedHashMap<String, SAScalarVariable> variables) {
 		var ArrayList<String> cpp = newArrayList();
-		var sVarsOrdered = sVars.entrySet.filter[value.causality === SVCausality.input].groupBy[value.type];
+		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 «adaptationName»::setFmiValue(fmi2ValueReference id, «Conversions.fmiTypeToCppType(type)» value)
+					void «adapClassName»::setFmiValue(fmi2ValueReference id, «Conversions.fmiTypeToCppType(type)» value)
 					{
-						«IF sVarsOrdered.containsKey(type)»
+						«IF convertedSASVsOrdered.containsKey(type)»
 							switch (id)	
 								{
-									«FOR svInner : sVarsOrdered.get(type)»
-										case «sVarDefs.get(svInner.value.owner + svInner.value.name).key»:
+									«FOR svInner : convertedSASVsOrdered.get(type)»
+										case «variables.get(svInner.name).defineName»:
 										{
-											this->«svInner.key» = value;
-											this->isSet«svInner.key» = true;
+											this->«svInner.name» = value;
+											this->isSet«svInner.name» = true;
 											break;
 										}
 									«ENDFOR»
@@ -372,11 +416,11 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * Calculates necessary information on function signatures necessary for generation of the header file.
 	 */
 	def RulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String adaptationClassName,
-		String adaptationName, LinkedHashMap<String, Pair<String, Integer>> svDefs, LinkedHashMap<String, SAScalarVariable> SASVs) {
+		String adaptationName, LinkedHashMap<String, SAScalarVariable> SASVs) {
 		var cpp = "";
-		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, svDefs, SASVs);
+		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, SASVs);
 		for (crtlRule : crtlRuleBlocks) {
-			cpp += visitor.doSwitch(crtlRule);
+			cpp += visitor.doSwitch(crtlRule).code;
 		}
 
 		return new RulesBlockResult(cpp, visitor.functionSignatures);
@@ -393,18 +437,19 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 */
 	def InOutRulesBlockResult compileInOutRuleBlocks(InputOutputType ioType, Iterable<InOutRules> rulesBlocks,
 		String adaptationClassName, String adaptationName,
-		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars, LinkedHashMap<String,SAScalarVariable> SASVs) {
-			
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
+		LinkedHashMap<String, SAScalarVariable> SASVs) {
+
 		val visitor = if (ioType == InputOutputType.Input)
 				new InRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs)
 			else
 				new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs);
-				
+
 		val functionName = "create" + ioType + "Rules()";
 		var String cpp = "";
 		val ruleBlock = rulesBlocks.head;
 		if (ruleBlock !== null) {
-			cpp += visitor.doSwitch(ruleBlock);
+			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) {
@@ -435,25 +480,17 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				'''
 			}
 		}
-		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.globalVars);
+		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.vars, visitor.getGlobalVars);
 	}
 
 	/*
-	 * Calculates defines for accessing scalar variables via value references. 
+	 * 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 ArrayList<String> calcDefines(LinkedHashMap<String, Pair<String, Integer>> svDefs) {
-		// Create Defines for the scalar values
-		var defines = newArrayList();
-		for (scalar : svDefs.entrySet) {
-			val definition = scalar.value;
-			defines.add("#define " + definition.key + " " + definition.value);
-		}
-		return defines;
-	}
-
-	def LinkedHashMap<String, SAScalarVariable> calcSASVsFromInportsOutports(String definePrefix, EList<Port> inports, EList<Port> outports) {
+	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();
@@ -472,7 +509,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			saSV.causality = SVCausality.output;
 			saSVs.put(saSV.name, saSV);
 		}
-		
+
 		return saSVs;
 	}
 }

+ 472 - 469
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesConditionSwitch.xtend

@@ -1,469 +1,472 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
-
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BoolLiteral
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DataRule
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.If
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IntLiteral
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IsSet
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.LValueDeclaration
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Literal
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Multi
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Neg
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RealLiteral
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RuleCondition
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SingleVarDeclaration
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Variable
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
-import java.util.LinkedHashMap
-import java.util.List
-import org.eclipse.emf.ecore.EObject
-import java.util.ArrayList
-import java.util.Optional
-
-abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
-
-	protected var LinkedHashMap<String, Pair<SVType, Object>> globalVars = newLinkedHashMap();
-	protected var LinkedHashMap<String, GlobalInOutVariable> globalVars2 = newLinkedHashMap();
-	private var Pair<SVType, Object> lastVal;
-	protected final String adaptationName;
-	protected final String adaptationClassName;
-	private Integer count = 0;
-	private final String functionPrefix;
-	protected List<String> functionSignatures = newArrayList();
-	protected String externalVariableOwner;
-	protected final LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars;
-	protected ArrayList<ConnectedVariable> conVars = newArrayList();
-	protected final LinkedHashMap<String, SAScalarVariable> SASVs;
-	protected boolean inRuleCondition;
-	protected boolean inRuleTransition;
-	protected boolean inRuleOutput;
-
-	new(
-		String adaptationClassName,
-		String adaptationName,
-		String functionPrefix,
-		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
-		LinkedHashMap<String, SAScalarVariable> SASVs
-	) {
-		this.SASVs = SASVs;
-		this.adaptationName = adaptationName;
-		this.adaptationClassName = adaptationClassName;
-		this.functionPrefix = functionPrefix;
-		this.mSVars = mSVars;
-	}
-
-	/*
-	 * UTILITY FUNCTIONS 
-	 */
-	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 getVars() { return this.globalVars; }
-
-	/**
-	 * 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 + ";");
-		return type + " " + this.adaptationClassName + "::" + functionSignature;
-	}
-
-	def void incrementCount() {
-		this.count++;
-	}
-
-	/*
-	 * COMPILATION FUNCTIONS
-	 */
-	override ReturnInformation caseOutRulesBlock(OutRulesBlock object) {
-		var retVal = new ReturnInformation();
-
-		// Get the global variables added to globalVars
-		for (gVar : object.globalOutVars) {
-			doSwitch(gVar)
-		}
-		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
-			this.incrementCount;
-			retVal.appendCode(doSwitch(dataRule).code);
-		}
-
-		return retVal;
-
-//		var cpp = ""
-//		for (gVar : object.globalOutVars) {
-//			doSwitch(gVar)
-//		}
-//		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
-//			this.incrementCount;
-//			cpp += doSwitch(dataRule);
-//		}
-//		return cpp;
-	}
-
-	override ReturnInformation caseInRulesBlock(InRulesBlock object) {
-
-		var retVal = new ReturnInformation();
-
-		// Get the global variables added to globalVars
-		for (gVar : object.globalInVars) {
-			doSwitch(gVar)
-		}
-
-		for (DataRule dataRule : object.eAllContents.toIterable.filter(DataRule)) {
-			// This is used for naming each datarule
-			this.incrementCount;
-			retVal.appendCode(doSwitch(dataRule).code);
-		}
-
-		return retVal;
-
-//		var cpp = ""
-//		for (gVar : object.globalInVars) {
-//			doSwitch(gVar)
-//		}
-//		for (DataRule dataRule : object.eAllContents.toIterable.filter(DataRule)) {
-//			this.incrementCount;
-//			cpp += doSwitch(dataRule);
-//		}
-//		return cpp;
-	}
-
-	override ReturnInformation caseDataRule(DataRule object) {
-		var retVal = new ReturnInformation();
-		retVal.code = '''«inRuleCondition = true»
-				«doSwitch(object.condition).code»
-				«inRuleCondition = false»
-				«inRuleTransition = true»
-				«doSwitch(object.statetransitionfunction).code»
-				«inRuleTransition = false»
-				«inRuleOutput = true»
-				«doSwitch(object.outputfunction).code»
-				«inRuleOutput = false»
-			'''
-
-		return retVal;
-
-//		return '''
-//			«doSwitch(object.condition)»
-//			«doSwitch(object.statetransitionfunction)»
-//			«doSwitch(object.outputfunction)»
-//		'''
-	}
-
-	override ReturnInformation caseRuleCondition(RuleCondition object) {
-		var retVal = new ReturnInformation();
-
-		val functionSignature = createFunctionSignature("condition", "bool");
-		retVal.code = '''
-			«functionSignature»{
-				return «doSwitch(object.condition).code»;
-			}
-		''';
-
-		return retVal;
-
-//		val functionSignature = createFunctionSignature("condition", "bool");
-//		'''
-//			«functionSignature»{
-//				return «doSwitch(object.condition)»;
-//			}
-//		''';
-	}
-
-	override ReturnInformation caseStateTransitionFunction(StateTransitionFunction object) {
-		var retVal = new ReturnInformation();
-
-		val functionSig = createFunctionSignature("body", "void");
-		retVal.code = '''
-			«functionSig»{
-				«IF object.expression !== null»
-					«doSwitch(object.expression).code»
-				«ENDIF»
-				«IF object.statements !== null»
-					«FOR stm : object.statements»
-						«doSwitch(stm).code»
-					«ENDFOR»
-				«ENDIF»			
-				«IF object.assignment !== null»
-					«doSwitch(object.assignment).code»
-				«ENDIF»
-			}
-		''';
-
-		return retVal;
-
-//		val functionSig = createFunctionSignature("body", "void");
-//		'''
-//			«functionSig»{
-//				«IF object.expression !== null»
-//					«doSwitch(object.expression)»
-//				«ENDIF»
-//				«IF object.statements !== null»
-//					«FOR stm : object.statements»
-//						«doSwitch(stm)»
-//					«ENDFOR»
-//				«ENDIF»			
-//				«IF object.assignment !== null»
-//					«doSwitch(object.assignment)»
-//				«ENDIF»
-//			}
-//		''';
-	}
-
-	override ReturnInformation defaultCase(EObject object) {
-		var retVal = new ReturnInformation();
-		retVal.code = '''[«object.class»]''';
-		return retVal;
-
-//		return '''[«object.class»]''';
-	}
-
-	override ReturnInformation caseIf(If object) {
-		var retVal = new ReturnInformation();
-		retVal.code = '''
-			if(«doSwitch(object.ifcondition)»){
-				«FOR stm : object.ifstatements»
-					«doSwitch(stm).code»
-				«ENDFOR»
-			}
-		''';
-
-		return retVal;
-
-//		return '''
-//			if(«doSwitch(object.ifcondition)»){
-//				«FOR stm : object.ifstatements»
-//					«doSwitch(stm)»
-//				«ENDFOR»
-//			}
-//		''';
-	}
-
-	private def calcConSaSvData(SAScalarVariable SASV, ReturnInformation rI) {
-		if (SASV !== null) {
-			if (rI.typeIsSet) {
-				SASV.type = rI.type;
-				SASV.variability = Optional.of(Conversions.fmiTypeToVariability(rI.type));
-				return;
-			} else if (rI.conGlobVar !== null) {
-				SASV.type = rI.conGlobVar.type;
-				SASV.variability = Optional.of(Conversions.fmiTypeToVariability(rI.conGlobVar.type));
-				return;
-			}
-		}
-		throw new Exception("Not enough information to determine content of the SASV: " + SASV.name);
-
-	}
-
-	override ReturnInformation caseAssignment(Assignment object) {
-		var retVal = new ReturnInformation();
-		var lValSwitch = doSwitch(object.lvalue);
-		var rValSwitch = doSwitch(object.expr);
-
-		// Here we set the information necessary to create a scalar variables in the model description for the SA.
-		if (inRuleTransition) {
-			if (rValSwitch.conSaSv !== null) {
-				calcConSaSvData(rValSwitch.conSaSv, lValSwitch);
-			}
-		} else if (inRuleOutput) {
-			calcConSaSvData(lValSwitch.conSaSv, rValSwitch);
-		}
-
-		retVal.code = '''«lValSwitch.code» = «rValSwitch.code»;''';
-		return retVal;
-
-//		return '''«doSwitch(object.lvalue)» = «doSwitch(object.expr)»;'''
-	}
-
-	override ReturnInformation caseMulti(Multi object) {
-		
-		val doSwitchLeft = doSwitch(object.left);
-		val doSwitchRight =  doSwitch(object.right);
-		var retVal = new ReturnInformation(doSwitchLeft, doSwitchRight);
-		retVal.code = '''«doSwitch(object.left).code» * «doSwitch(object.right).code»''';
-		return retVal;
-
-//		return '''«doSwitch(object.left)» * «doSwitch(object.right)»''';
-	}
-
-	override ReturnInformation caseNeg(Neg object) {
-		
-		var doSwitch = doSwitch(object.right);
-		var retVal = new ReturnInformation(doSwitch);
-		retVal.code = doSwitch.code;
-
-		return retVal;
-
-//		return '''-«doSwitch(object.right)»'''
-	}
-
-	override ReturnInformation caseSingleVarDeclaration(SingleVarDeclaration object) {
-		var retVal = new ReturnInformation();
-		retVal.code = '''«object.name»''';
-		return retVal;
-
-//		var returnVal = '''«object.name»'''
-//		return returnVal;
-	}
-
-	override ReturnInformation caseCompositeOutputFunction(CompositeOutputFunction object) {
-
-		var retVal = new ReturnInformation();
-		val functionSig = createFunctionSignature("flush", "void");
-		retVal.code = '''
-			«functionSig»{
-				«FOR stm : object.statements»
-					«doSwitch(stm).code»
-				«ENDFOR»
-			}
-		''';
-		return retVal;
-
-//		val functionSig = createFunctionSignature("flush", "void");
-//		val returnVal = '''
-//			«functionSig»{
-//				«FOR stm : object.statements»
-//					«doSwitch(stm)»
-//				«ENDFOR»
-//			}
-//		''';
-//		return returnVal;
-	}
-
-	override ReturnInformation caseVariable(Variable object) {
-
-		var retVal = new ReturnInformation();
-
-		if (object.owner === null || object.owner.name == this.adaptationName) {
-			retVal.code = '''this->«object.ref.name»''';
-			if (SASVs.containsKey(object.ref.name)) {
-				retVal.conSaSv = SASVs.get(object.ref.name);
-			} else if (globalVars2.containsKey(object.ref.name)) {
-				retVal.conGlobVar = globalVars2.get(object.ref.name);
-			}
-		} else {
-			// TODO: Extract the correct variable here
-			this.externalVariableOwner = object.owner.name;
-			retVal.code = '''«doSwitch(object.ref).code»''';
-		}
-		return retVal;
-
-//		if (object.owner === null || object.owner.name == this.adaptationName) {
-//			return '''this->«object.ref.name»''';
-//		} else {
-//			this.externalVariableOwner = object.owner.name;
-//			return '''«doSwitch(object.ref)»''';
-//		}
-	}
-
-	override ReturnInformation caseLValueDeclaration(LValueDeclaration object) {
-
-		var retVal = new ReturnInformation();
-		retVal.code = '''«object.name»''';
-		return retVal;
-
-//		return '''«object.name»'''
-	}
-
-	/*
-	 * This is out var and in var declarations.
-	 */
-	override ReturnInformation caseDeclaration(Declaration object) {
-		var retVal2 = new ReturnInformation();
-		for (decl : object.declarations) {
-			var doSwitchRes = doSwitch(decl.expr);
-
-			retVal2.appendCode(doSwitchRes.code);
-
-			var globVar = new GlobalInOutVariable();
-			globVar.name = decl.name;
-			globVar.value = doSwitchRes.value;
-			globVar.type = doSwitchRes.type;
-
-			globalVars2.put(decl.name, globVar);
-		}
-
-		return retVal2;
-
-//		var returnVal = "";
-//
-//		for (decl : object.declarations) {
-//			returnVal += doSwitch(decl.expr);
-//			globalVars.put(decl.name, lastVal);
-//		}
-//		return returnVal;
-	}
-
-	override ReturnInformation caseIsSet(IsSet object) {
-		var retInfo = new ReturnInformation();
-//		retInfo.type = SVType.Real;
-//		retInfo.value = convertTypeToObject(retInfo.type, object);
-		retInfo.code = '''this->isSet«(object.args as Variable).ref.name»''';
-		return retInfo;
-
-//		return '''this->isSet«(object.args as Variable).ref.name»'''
-	}
-
-	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;
-
-//		lastVal = convertType(SVType.Real, object);
-//		return '''«object.value»''';
-	}
-
-	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;
-
-//		return '''«object.value»''';
-	}
-
-	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;
-
-//		return '''«object.value»''';
-	}
-
-//	private def Pair<SVType, Object> convertType(SVType type, Literal object) {
-//		switch (type) {
-//			case Real: {
-//				return type -> (object as RealLiteral).value.doubleValue;
-//			}
-//			default: {
-//			}
-//		}
-//	}
-}
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
+
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
+import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
+import java.util.List
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.MappedScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Literal
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RealLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IntLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BoolLiteral
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DataRule
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RuleCondition
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
+import org.eclipse.emf.ecore.EObject
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Multi
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Neg
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SingleVarDeclaration
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.If
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Variable
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.LValueDeclaration
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IsSet
+
+abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
+
+	protected var LinkedHashMap<String, Pair<SVType, Object>> globalVars = newLinkedHashMap();
+	protected var LinkedHashMap<String, GlobalInOutVariable> globalVars2 = newLinkedHashMap();
+	private var Pair<SVType, Object> lastVal;
+	protected final String adaptationName;
+	protected final String adaptationClassName;
+	private Integer count = 0;
+	private final String functionPrefix;
+	protected List<String> functionSignatures = newArrayList();
+	protected String externalVariableOwner;
+	protected final LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars;
+	protected final LinkedHashMap<String, SAScalarVariable> SASVs;
+	protected boolean inRuleCondition;
+	protected boolean inRuleTransition;
+	protected boolean inRuleOutput;
+
+	new(
+		String adaptationClassName,
+		String adaptationName,
+		String functionPrefix,
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
+		LinkedHashMap<String, SAScalarVariable> SASVs
+	) {
+		this.SASVs = SASVs;
+		this.adaptationName = adaptationName;
+		this.adaptationClassName = adaptationClassName;
+		this.functionPrefix = functionPrefix;
+		this.mSVars = mSVars;
+	}
+
+	/*
+	 * UTILITY FUNCTIONS 
+	 */
+	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 getVars() { return this.globalVars; }
+	
+	public def getGlobalVars() { return this.globalVars2; }
+
+	/**
+	 * 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 + ";");
+		return type + " " + this.adaptationClassName + "::" + functionSignature;
+	}
+
+	def void incrementCount() {
+		this.count++;
+	}
+
+	/*
+	 * COMPILATION FUNCTIONS
+	 */
+	override ReturnInformation caseOutRulesBlock(OutRulesBlock object) {
+		var retVal = new ReturnInformation();
+
+		// Get the global variables added to globalVars
+		for (gVar : object.globalOutVars) {
+			doSwitch(gVar)
+		}
+		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+			this.incrementCount;
+			retVal.appendCode(doSwitch(dataRule).code);
+		}
+
+		return retVal;
+
+//		var cpp = ""
+//		for (gVar : object.globalOutVars) {
+//			doSwitch(gVar)
+//		}
+//		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+//			this.incrementCount;
+//			cpp += doSwitch(dataRule);
+//		}
+//		return cpp;
+	}
+
+	override ReturnInformation caseInRulesBlock(InRulesBlock object) {
+
+		var retVal = new ReturnInformation();
+
+		// Get the global variables added to globalVars
+		for (gVar : object.globalInVars) {
+			doSwitch(gVar)
+		}
+
+		for (DataRule dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+			// This is used for naming each datarule
+			this.incrementCount;
+			retVal.appendCode(doSwitch(dataRule).code);
+		}
+
+		return retVal;
+
+//		var cpp = ""
+//		for (gVar : object.globalInVars) {
+//			doSwitch(gVar)
+//		}
+//		for (DataRule dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+//			this.incrementCount;
+//			cpp += doSwitch(dataRule);
+//		}
+//		return cpp;
+	}
+
+	override ReturnInformation caseDataRule(DataRule object) {
+		var retVal = new ReturnInformation();
+		inRuleCondition = true;
+		val conditionSwitch = doSwitch(object.condition);
+		inRuleCondition = false;
+		inRuleTransition = true;
+		val transitionSwitch = doSwitch(object.statetransitionfunction);
+		inRuleTransition = false;
+		inRuleOutput = true;
+		val outputSwitch = doSwitch(object.outputfunction);
+		inRuleOutput = false;
+		retVal.code = 
+			'''
+				«conditionSwitch.code»
+				«transitionSwitch.code»
+				«outputSwitch.code»
+			'''
+
+		return retVal;
+	}
+
+	override ReturnInformation caseRuleCondition(RuleCondition object) {
+		var retVal = new ReturnInformation();
+
+		val functionSignature = createFunctionSignature("condition", "bool");
+		retVal.code = '''
+			«functionSignature»{
+				return «doSwitch(object.condition).code»;
+			}
+		''';
+
+		return retVal;
+
+//		val functionSignature = createFunctionSignature("condition", "bool");
+//		'''
+//			«functionSignature»{
+//				return «doSwitch(object.condition)»;
+//			}
+//		''';
+	}
+
+	override ReturnInformation caseStateTransitionFunction(StateTransitionFunction object) {
+		var retVal = new ReturnInformation();
+
+		val functionSig = createFunctionSignature("body", "void");
+		retVal.code = '''
+			«functionSig»{
+				«IF object.expression !== null»
+					«doSwitch(object.expression).code»
+				«ENDIF»
+				«IF object.statements !== null»
+					«FOR stm : object.statements»
+						«doSwitch(stm).code»
+					«ENDFOR»
+				«ENDIF»			
+				«IF object.assignment !== null»
+					«doSwitch(object.assignment).code»
+				«ENDIF»
+			}
+		''';
+
+		return retVal;
+
+//		val functionSig = createFunctionSignature("body", "void");
+//		'''
+//			«functionSig»{
+//				«IF object.expression !== null»
+//					«doSwitch(object.expression)»
+//				«ENDIF»
+//				«IF object.statements !== null»
+//					«FOR stm : object.statements»
+//						«doSwitch(stm)»
+//					«ENDFOR»
+//				«ENDIF»			
+//				«IF object.assignment !== null»
+//					«doSwitch(object.assignment)»
+//				«ENDIF»
+//			}
+//		''';
+	}
+
+	override ReturnInformation defaultCase(EObject object) {
+		var retVal = new ReturnInformation();
+		retVal.code = '''[«object.class»]''';
+		return retVal;
+
+//		return '''[«object.class»]''';
+	}
+
+	override ReturnInformation caseIf(If object) {
+		var retVal = new ReturnInformation();
+		retVal.code = '''
+			if(«doSwitch(object.ifcondition).code»){
+				«FOR stm : object.ifstatements»
+					«doSwitch(stm).code»
+				«ENDFOR»
+			}
+		''';
+
+		return retVal;
+
+//		return '''
+//			if(«doSwitch(object.ifcondition)»){
+//				«FOR stm : object.ifstatements»
+//					«doSwitch(stm)»
+//				«ENDFOR»
+//			}
+//		''';
+	}
+
+	private def calcConSaSvData(SAScalarVariable SASV, ReturnInformation rI) {
+		if (SASV !== null) {
+			if (rI.typeIsSet) {
+				SASV.type = rI.type;
+				SASV.variability = Conversions.fmiTypeToFmiVariability(rI.type);
+				return;
+			} else if (rI.conGlobVar !== null) {
+				SASV.type = rI.conGlobVar.type;
+				SASV.variability = Conversions.fmiTypeToFmiVariability(rI.conGlobVar.type);
+				return;
+			}
+		}
+		throw new Exception("Not enough information to determine content of the SASV: " + SASV.name);
+
+	}
+
+	override ReturnInformation caseAssignment(Assignment object) {
+		var retVal = new ReturnInformation();
+		var lValSwitch = doSwitch(object.lvalue);
+		var rValSwitch = doSwitch(object.expr);
+
+		// Here we set the information necessary to create a scalar variables in the model description for the SA.
+		if (inRuleTransition) {
+			if (rValSwitch.conSaSv !== null) {
+				calcConSaSvData(rValSwitch.conSaSv, lValSwitch);
+			}
+		} else if (inRuleOutput) {
+			calcConSaSvData(lValSwitch.conSaSv, rValSwitch);
+		}
+
+		retVal.code = '''«lValSwitch.code» = «rValSwitch.code»;''';
+		return retVal;
+
+//		return '''«doSwitch(object.lvalue)» = «doSwitch(object.expr)»;'''
+	}
+
+	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;
+
+//		return '''«doSwitch(object.left)» * «doSwitch(object.right)»''';
+	}
+
+	override ReturnInformation caseNeg(Neg object) {
+		
+		var doSwitch = doSwitch(object.right);
+		var retVal = new ReturnInformation(doSwitch);
+		retVal.code = doSwitch.code;
+
+		return retVal;
+
+//		return '''-«doSwitch(object.right)»'''
+	}
+
+	override ReturnInformation caseSingleVarDeclaration(SingleVarDeclaration object) {
+		var retVal = new ReturnInformation();
+		retVal.code = '''«object.name»''';
+		return retVal;
+
+//		var returnVal = '''«object.name»'''
+//		return returnVal;
+	}
+
+	override ReturnInformation caseCompositeOutputFunction(CompositeOutputFunction object) {
+
+		var retVal = new ReturnInformation();
+		val functionSig = createFunctionSignature("flush", "void");
+		retVal.code = '''
+			«functionSig»{
+				«FOR stm : object.statements»
+					«doSwitch(stm).code»
+				«ENDFOR»
+			}
+		''';
+		return retVal;
+
+//		val functionSig = createFunctionSignature("flush", "void");
+//		val returnVal = '''
+//			«functionSig»{
+//				«FOR stm : object.statements»
+//					«doSwitch(stm)»
+//				«ENDFOR»
+//			}
+//		''';
+//		return returnVal;
+	}
+
+	override ReturnInformation caseVariable(Variable object) {
+
+		var retVal = new ReturnInformation();
+
+		if (object.owner === null || object.owner.name == this.adaptationName) {
+			retVal.code = '''this->«object.ref.name»''';
+			if (SASVs.containsKey(object.ref.name)) {
+				retVal.conSaSv = SASVs.get(object.ref.name);
+			} else if (globalVars2.containsKey(object.ref.name)) {
+				retVal.conGlobVar = globalVars2.get(object.ref.name);
+			}
+		} else {
+			// TODO: Extract the correct variable here
+			this.externalVariableOwner = object.owner.name;
+			retVal.code = '''«doSwitch(object.ref).code»''';
+		}
+		return retVal;
+
+//		if (object.owner === null || object.owner.name == this.adaptationName) {
+//			return '''this->«object.ref.name»''';
+//		} else {
+//			this.externalVariableOwner = object.owner.name;
+//			return '''«doSwitch(object.ref)»''';
+//		}
+	}
+
+	override ReturnInformation caseLValueDeclaration(LValueDeclaration object) {
+
+		var retVal = new ReturnInformation();
+		retVal.code = '''«object.name»''';
+		return retVal;
+
+//		return '''«object.name»'''
+	}
+
+	/*
+	 * This is out var and in var declarations.
+	 */
+	override ReturnInformation caseDeclaration(Declaration object) {
+		var retVal2 = new ReturnInformation();
+		for (decl : object.declarations) {
+			var doSwitchRes = doSwitch(decl.expr);
+
+			retVal2.appendCode(doSwitchRes.code);
+
+			var globVar = new GlobalInOutVariable();
+			globVar.name = decl.name;
+			globVar.value = doSwitchRes.value;
+			globVar.type = doSwitchRes.type;
+
+			globalVars2.put(decl.name, globVar);
+		}
+
+		return retVal2;
+
+//		var returnVal = "";
+//
+//		for (decl : object.declarations) {
+//			returnVal += doSwitch(decl.expr);
+//			globalVars.put(decl.name, lastVal);
+//		}
+//		return returnVal;
+	}
+
+	override ReturnInformation caseIsSet(IsSet object) {
+		var retInfo = new ReturnInformation();
+//		retInfo.type = SVType.Real;
+//		retInfo.value = convertTypeToObject(retInfo.type, object);
+		retInfo.code = '''this->isSet«(object.args as Variable).ref.name»''';
+		return retInfo;
+
+//		return '''this->isSet«(object.args as Variable).ref.name»'''
+	}
+
+	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;
+
+//		lastVal = convertType(SVType.Real, object);
+//		return '''«object.value»''';
+	}
+
+	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;
+
+//		return '''«object.value»''';
+	}
+
+	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;
+
+//		return '''«object.value»''';
+	}
+
+//	private def Pair<SVType, Object> convertType(SVType type, Literal object) {
+//		switch (type) {
+//			case Real: {
+//				return type -> (object as RealLiteral).value.doubleValue;
+//			}
+//			default: {
+//			}
+//		}
+//	}
+}

+ 6 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InRulesConditionSwitch.xtend

@@ -1,9 +1,11 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
 import java.util.LinkedHashMap
-import java.util.ArrayList
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.MappedScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 
 class InRulesConditionSwitch extends InOutRulesConditionSwitch {
 

+ 12 - 9
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend

@@ -1,20 +1,23 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
-import java.io.File
+import org.w3c.dom.Document
+import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
 import java.util.zip.ZipFile
 import java.util.Enumeration
 import java.util.zip.ZipEntry
-import org.w3c.dom.Document
+import java.io.File
 import javax.xml.parsers.DocumentBuilderFactory
 import javax.xml.parsers.DocumentBuilder
-import javax.xml.xpath.XPathExpression
 import javax.xml.xpath.XPathFactory
 import javax.xml.xpath.XPath
-import javax.xml.soap.Node
+import javax.xml.xpath.XPathExpression
 import javax.xml.xpath.XPathConstants
 import org.w3c.dom.NodeList
-import java.util.LinkedHashMap
-import javax.lang.model.element.Element
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVVariability
+import javax.xml.soap.Node
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 
 class ModelDescription {
 	private final Document md;
@@ -72,8 +75,8 @@ class ModelDescription {
 				.setOwner(this.name)
 				.setValueReference(valueRef)
 				.setIndex((i + 1).toString)
-				.setVariability(node.attributes.getNamedItem("variability").nodeValue);
-
+				.setVariability(SVVariability.valueOf(node.attributes.getNamedItem("variability").nodeValue));
+				
 			for (var j = 0; j < node.childNodes.length; j++) {
 				val subNode = node.childNodes.item(j);
 				if (subNode.nodeType == Node.ELEMENT_NODE) {

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

@@ -1,4 +1,4 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
 
 import java.io.StringWriter;
 
@@ -11,10 +11,13 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.commons.cli.MissingArgumentException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable;
+
 public class ModelDescriptionBuilder {
 	private DocumentBuilderFactory docFactory;
 	private DocumentBuilder docBuilder;
@@ -63,7 +66,7 @@ public class ModelDescriptionBuilder {
 			sv.setAttribute("description", var.getDescription());
 
 		if (var.getVariability() != null)
-			sv.setAttribute("variability", var.getVariability());
+			sv.setAttribute("variability", var.getVariability().name());
 
 		if (var.getCausality() != null) {
 			sv.setAttribute("causality", var.getCausality().name());

+ 40 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescriptionCreator.java

@@ -0,0 +1,40 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
+
+import java.util.Collection;
+import java.util.UUID;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.MissingScalarVariableInformationException;
+
+public class ModelDescriptionCreator {
+	private final ModelDescriptionBuilder mdBuilder;
+	private final String mdName;
+	private final String guid;
+
+	public ModelDescriptionCreator(String name) throws ParserConfigurationException
+	{
+		this.mdName = name;
+		this.guid = UUID.randomUUID().toString();
+		this.mdBuilder = new ModelDescriptionBuilder();
+	}
+	
+	public String generateModelDescription(Collection<SAScalarVariable> SASVs) throws ParserConfigurationException, MissingScalarVariableInformationException {
+		mdBuilder.CreateTemplate(this.getMdName(), this.guid);
+		for (SAScalarVariable sasv : SASVs) {
+			mdBuilder.addScalarVariable(sasv.CalcSVar());
+		}
+
+		return mdBuilder.toString();
+	}
+
+
+	public String getGuid() {
+		return guid;
+	}
+
+	public String getMdName() {
+		return mdName;
+	}
+}

+ 5 - 11
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/OutRulesConditionSwitch.xtend

@@ -1,13 +1,12 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
 
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.MappedScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 
 public class OutRulesConditionSwitch extends InOutRulesConditionSwitch {
-
-
-	private boolean inBody = false;
-
 	new(String adaptationClassName, 
 		String adaptationName,  
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
@@ -23,10 +22,5 @@ public class OutRulesConditionSwitch extends InOutRulesConditionSwitch {
 		retVal.code = '''getValue«type»(«this.externalVariableOwner»,«define»)''';
 		
 		return retVal;
-		
-		
-//		val type = mSVars.get(this.externalVariableOwner).get(object.name).mappedSv.type.toString;
-//		val define = mSVars.get(this.externalVariableOwner).get(object.name).define;
-//		return '''getValue«type»(«this.externalVariableOwner»,«define»)'''
 	}
 }

+ 18 - 25
ModelicaModels/Window.mo

@@ -1,25 +1,18 @@
-model Window
-  //parameter Real J = 0.01;
-  parameter Real r = 0.11;
-  parameter Real b = 10;
-  //parameter Real c = 1e5;
-  input Real omega_input;
-  input Real theta_input;
-  input Real obj_F;
-  output Real tau;
-  output Real x;
-  output Real v;
-  //output Real omega;
-  //output Real theta;
-  output Real friction;
-equation
-//der(theta) = omega;
-//tau = c * (theta_input - theta) ; //- obj_F*r
-  tau = obj_F * r + friction;
-//der(omega) = (tau - friction)/J;
-  x = r * theta_input;
-  v = r * omega_input;
-  friction = b * v;
-  annotation(
-    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
-end Window;
+model Window
+  parameter Real r = 0.11;
+  parameter Real b = 10;
+  input Real speed;
+  input Real displacement;
+  input Real reaction_force;
+  output Real reaction_torque;
+  output Real height;
+  Real v;
+  output Real friction;
+equation
+  reaction_torque = reaction_force * r + friction;
+  height = r * displacement;
+  v = r * speed;
+  friction = b * v;
+  annotation(
+    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
+end Window;