Browse Source

Updated example to match CPP

Casper Thule 7 years ago
parent
commit
907c87a7ee

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


+ 43 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Conversions.java

@@ -1,13 +1,53 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
 
+import javax.management.InvalidAttributeValueException;
+import javax.naming.directory.InvalidAttributeIdentifierException;
+
 public class Conversions {
-	public static String fmiTypeToCppType(SVType t)
-	{
+	public static String fmiTypeToCppType(SVType t) throws InvalidConversionException {
 		switch (t) {
 		case Real:
 			return "double";
+		case Int:
+			return "int";
+		case Bool:
+			return "bool";
+		case String:
+			return "String";
+		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 Int:
+			return "Integer";
+		case Bool:
+			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 Int:
+			return "0";
+		case Bool:
+			return "false";
+		case String:
+			return "\"\"";
 		default:
-			return t.toString().toLowerCase();
+			throw new InvalidConversionException("The value type: " + t + " is invalid.");
 		}
 	}
+	
+	
 }

+ 212 - 58
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -2,20 +2,18 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
 
 import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DataRule
+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 be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
 import java.io.File
+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 be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InOutRules
-import java.util.ArrayList
 
 class CppGenerator extends SemanticAdaptationGenerator {
 
@@ -26,30 +24,34 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
 		this.fsa = fsa;
-		for (type : resource.allContents.toIterable.filter(SemanticAdaptation)) {
+		for (SemanticAdaptation type : resource.allContents.toIterable.filter(SemanticAdaptation)) {
 			type.compile;
-			mdCreator.name = type.name;
-			fsa.generateFile("modelDescription.xml", mdCreator.modelDescription);
+
 		}
 	}
 
 // TODO: Verify adaptation.name is not a C++ keyword
 // TODO: Add initial value to inputs in the model description file
 	def void compile(SemanticAdaptation adaptation) {
-		for (type : adaptation.elements.filter(Adaptation)) {
+		for (Adaptation type : adaptation.elements.filter(Adaptation)) {
+
 			var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
-			var ArrayList<String> fmus = newArrayList();
+			var ArrayList<Pair<String,String>> fmus = newArrayList();
 			var LinkedHashMap<String, ScalarVariable> sVars = newLinkedHashMap();
 			var String genSource = "";
-						
+			var ModelDescription md;
 			// Load Model Description file
 			for (fmu : type.inner.eAllContents.toIterable.filter(InnerFMU)) {
 				// TODO: Merge this with ModelDescriptionCreator
-				var md = new ModelDescription(fmu.name, new File(fmu.path.replace('\"', '')));
-				fmus.add(fmu.name);
+				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);
-			}			
+
+				mdCreator.name = type.name;
+				mdCreator.CalcContent(md);
+				fsa.generateFile("modelDescription.xml", mdCreator.modelDescription);
+			}
 
 			// Compile the in rules
 			val inRuleResult = compileInRuleBlock(adaptation.eAllContents.toIterable.filter(InRulesBlock), svDefs,
@@ -65,11 +67,20 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
 				type.name, svDefs);
 			genSource += crtlRuleResult.generatedCpp;
-			
+
 			// Compile the includes and constructor 
-			val String include = '''#include «type.name».h''';			
-			val String constructor = compileConstructor(type.name, outRuleResult, inRuleResult, sVars);
-			genSource = include + constructor + genSource;				
+			val String include = '''#include "«type.name».h"''';
+			val String constructor = compileConstructor(type.name, outRuleResult, inRuleResult, sVars, fmus.head.key, md.guid);
+			val String getRuleThis = compileGetRuleThis(type.name);
+			genSource = include + "\n\n" + constructor + "\n\n" + getRuleThis + "\n\n" + genSource;
+
+			// Compile the get functions
+			val String getFuncs = compileGetFmuValue(type.name, sVars, svDefs);
+			genSource += "\n" + getFuncs;
+
+			// Compile the set functions
+			val String setFuncs = compileSetFmuValue(type.name, sVars, svDefs);
+			genSource += "\n" + setFuncs;
 
 			// Generate the source file for the SA
 			fsa.generateFile(type.name + ".cpp", genSource);
@@ -78,16 +89,23 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			var genDef = calcDefines(svDefs).join("\n");
 			// Compile the class definition file for the SA
 			val String header = compileHeader(type.name, inRuleResult, outRuleResult, crtlRuleResult, fmus, sVars);
-			
- 			// Generate the header file for the SA
-			fsa.generateFile(type.name + ".h", genDef + header);
+
+			// Generate the header file for the SA
+			fsa.generateFile(type.name + ".h", genDef + "\n\n" + header);
 		}
 	}
 
 	def String compileHeader(String name, InOutRulesBlockResult inRulesResult, InOutRulesBlockResult outRulesResult,
-		RulesBlockResult crtlRulesResult, ArrayList<String> fmus, LinkedHashMap<String, ScalarVariable> sVars) {
+		RulesBlockResult crtlRulesResult, ArrayList<Pair<String,String>> fmus, LinkedHashMap<String, ScalarVariable> sVars) {
 		return '''
-			class «name» : SemanticAdaptation<«name»>{
+			#include "SemanticAdaptation.h"
+			#include <memory>
+			#include "Fmu.h"
+			
+			using namespace std;
+			using namespace "Fmu.h"
+			
+			class «name» : public SemanticAdaptation<«name»>{
 				public:
 					«name»();
 					virtual ~«name»();
@@ -100,8 +118,8 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					bool getFmiValueBoolean(int id);
 					double getFmiValueDouble(int id);
 				private:
-					shared_ptr<std::list<Rule<«name»>>>createInputRules();
-					shared_ptr<std::list<Rule<«name»>>> createOutputRules();
+					
+					«name»* getRuleThis();
 					
 					/*in rules*/
 					«inRulesResult.functionSignatures.join("\n")»
@@ -112,7 +130,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					«crtlRulesResult.functionSignatures.join("\n")»
 					
 					«FOR fmu : fmus»
-						shared_ptr<Fmu> «fmu»;
+						shared_ptr<Fmu> «fmu.key»;
 					«ENDFOR»
 					
 					«FOR sv : sVars.entrySet»
@@ -134,26 +152,130 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	}
 
 	def compileConstructor(String name, InOutRulesBlockResult outRuleResult, InOutRulesBlockResult inRuleResult,
-		LinkedHashMap<String, ScalarVariable> sVars) {
+		LinkedHashMap<String, ScalarVariable> sVars, String fmu, String guid) {
+		return '''
+			«name»::«name»(shared_ptr<std::string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
+			{
+				«FOR v : outRuleResult.globalVars.entrySet»
+					«(v.key)» = «v.value.value»;
+				«ENDFOR»
+				
+				«FOR v : inRuleResult.globalVars.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>("«fmu».fmu"))->c_str();
+				auto «fmu»Fmu = make_shared<fmi2::Fmu>(path);
+				«fmu»Fmu->initialize();
+				this->«fmu» = «fmu»Fmu->instantiate("«fmu»",fmi2CoSimulation, "«guid»", true, true, make_shared<Callback>()); 
+			}
+		''';
+	}
+
+	def compileGetRuleThis(String name)
+	{
 		return 
 			'''
-				«name»::«name»() : SemanticAdaptation(createInputRules(),createOutputRules())
+				«name»* «name»::getRuleThis()
 				{
-					«FOR v : outRuleResult.globalVars.entrySet»
-						«(v.key)» = «v.value.value»;
-					«ENDFOR»
-					
-					«FOR v : inRuleResult.globalVars.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»
+					return this;
 				}
-			''';
+			'''
+	}
+
+	def compileGetFmuValueCppFuncSig(String adaptationName, SVType type) {
+		return '''«Conversions.fmiTypeToCppType(type)»  «adaptationName»::getFmiValue«Conversions.fmiTypeToCppTypeName(type)»(int id)''';
+	}
+
+	def compileGetFmuValueCppFuncReturn(SVType type) {
+		return '''return «Conversions.fmiTypeToCppDefaultValue(type)»''';
+	}
+
+	def compileGetFmuValue(String adaptationName, LinkedHashMap<String, ScalarVariable> sVars, LinkedHashMap<String, Pair<String, Integer>> sVarDefs) {
+		var ArrayList<String> cpp = newArrayList();
+		var sVarsOrdered = sVars.entrySet.filter[value.causality === SVCausality.output].groupBy[value.type];
+
+		for (SVType type : SVType.values) {
+			if (sVarsOrdered.containsKey(type)) {
+				cpp.add(
+					'''
+						«compileGetFmuValueCppFuncSig(adaptationName,type)»
+						{
+							switch (id)
+							{
+								«FOR svInner : sVarsOrdered.get(type)»
+									case «sVarDefs.get(svInner.value.owner + svInner.value.name).key»:
+									{
+										return this->«svInner.key»;
+									}
+								«ENDFOR»
+								default:
+								{
+									«compileGetFmuValueCppFuncReturn(type)»;
+								}
+							}
+							
+						}
+					'''
+				);
+			} else {
+				cpp.add(
+					'''
+						«compileGetFmuValueCppFuncSig(adaptationName,type)»
+						{
+							«compileGetFmuValueCppFuncReturn(type)»;
+						}
+					'''
+				);
+			}
+		}
+
+		return cpp.join("\n");
+	}
+
+	def compileSetFmuValueCppFuncSig(String adaptationName, SVType type) {
+		return '''«Conversions.fmiTypeToCppType(type)»  «adaptationName»::getFmiValue«Conversions.fmiTypeToCppTypeName(type)»(int id)''';
+	}
+
+	def compileSetFmuValue(String adaptationName, LinkedHashMap<String, ScalarVariable> sVars, LinkedHashMap<String, Pair<String, Integer>> sVarDefs) {
+		var ArrayList<String> cpp = newArrayList();
+		var sVarsOrdered = sVars.entrySet.filter[value.causality === SVCausality.input].groupBy[value.type];
+
+		for (SVType type : SVType.values) {
+
+			cpp.add(
+				'''
+					void «adaptationName»::setFmiValue(int id, «Conversions.fmiTypeToCppType(type)» value)
+					{
+						«IF sVarsOrdered.containsKey(type)»
+							switch (id)	
+								{
+									«FOR svInner : sVarsOrdered.get(type)»
+										case «sVarDefs.get(svInner.value.owner + svInner.value.name).key»:
+										{
+											this->«svInner.key» = value;
+											this->isSet«svInner.key» = true;
+											break;
+										}
+									«ENDFOR»
+									default:
+									{
+									}
+								}
+						«ENDIF»
+					}
+				'''
+			);
+
+		}
+
+		return cpp.join("\n");
 	}
 
 	def RulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String name,
@@ -170,31 +292,63 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	def InOutRulesBlockResult compileOutRuleBlock(Iterable<OutRulesBlock> rulesBlocks,
 		LinkedHashMap<String, Pair<String, Integer>> svDefs, String name) {
 		return compileInOutRuleBlocks(new OutRulesConditionSwitch(name, svDefs), rulesBlocks.map[x|x as InOutRules],
-			svDefs, name);
+			svDefs, name, "createOutputRules");
 	}
 
 	def InOutRulesBlockResult compileInRuleBlock(Iterable<InRulesBlock> rulesBlocks,
 		LinkedHashMap<String, Pair<String, Integer>> svDefs, String name) {
 		return compileInOutRuleBlocks(new InRulesConditionSwitch(name, svDefs), rulesBlocks.map[x|x as InOutRules],
-			svDefs, name);
+			svDefs, name, "createInputRules");
 	}
 
 	def InOutRulesBlockResult compileInOutRuleBlocks(InOutRulesConditionSwitch visitor,
-		Iterable<InOutRules> rulesBlocks, LinkedHashMap<String, Pair<String, Integer>> svDefs, String name) {
-		var String cpp = "";
-		for (ruleBlock : rulesBlocks) {
-			cpp += visitor.doSwitch(ruleBlock)
+		Iterable<InOutRules> rulesBlocks, LinkedHashMap<String, Pair<String, Integer>> svDefs, String name,
+		String functionName) {
+			var String cpp = "";
+			val ruleBlock = rulesBlocks.head;
+			if (ruleBlock !== null) {
+				cpp += visitor.doSwitch(ruleBlock);
+				if (!visitor.functionSignatures.empty) {
+					var ArrayList<String> createRulesFunction = newArrayList();
+					for (var int i = 0; i < (visitor.functionSignatures.length); i += 3) {
+						createRulesFunction.add( 
+					'''
+							list->push_back(
+								(Rule<«name»>){
+									&«name»::«visitor.functionSignatures.get(i)»,
+									&«name»::«visitor.functionSignatures.get(i+1)»
+									&«name»::«visitor.functionSignatures.get(i+2)»
+								});
+							
+						''');
+					}
+					val functionPrefix = '''shared_ptr<list<Rule<«name»>>>''';
+					visitor.functionSignatures.add(functionPrefix + " " + functionName + ";")
+					cpp += '''
+						«functionPrefix» «name»::«functionName»()
+						{
+							auto list = make_shared<list<Rule<«name»>>>()
+							
+							«createRulesFunction.join("\n")»
+							
+							return list;
+							
+						}
+						
+					'''
+				}
+			}
+			return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.globalVars);
 		}
-		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.globalVars);
-	}
 
 	def 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);
+			// 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;
 		}
-		return defines;
 	}
-}
+	

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

@@ -47,7 +47,7 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 	 */
 	protected def String createFunctionSignature(String functionName, String type) {
 		val functionSignature = this.functionPrefix + functionName + this.count + "()";
-		this.functionSignatures.add(type + " " + functionSignature);
+		this.functionSignatures.add(type + " " + functionSignature+";");
 		return type + " " + this.adaptationName + "::" + functionSignature;
 	}
 

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

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

+ 18 - 5
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend

@@ -19,11 +19,15 @@ import javax.lang.model.element.Element
 class ModelDescription {
 	private final Document md;
 	private final String name;
+	private final String type;
 	private var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
 	private var LinkedHashMap<String, ScalarVariable> svs = newLinkedHashMap();
+	private var String guid;
 
-	new(String name, File path) {
+	new(String name, String type, File path) {
 		this.name = name;
+		this.type = type;
+		
 
 		var ZipFile fmu = new ZipFile(path);
 		var Enumeration<? extends ZipEntry> entries = fmu.entries();
@@ -32,20 +36,25 @@ class ModelDescription {
 
 		while (!entryFound && entries.hasMoreElements()) {
 			var ZipEntry entry = entries.nextElement();
-			if (entry.name.equalsIgnoreCase("modelDescription.xml"))
+			if (entry.name.equalsIgnoreCase("modelDescription.xml")) {
 				locatedEntry = entry;
+				entryFound = true;
+
+			}
 		}
 		var DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
 		var DocumentBuilder builder = fac.newDocumentBuilder();
 		val is = fmu.getInputStream(locatedEntry)
 		this.md = builder.parse(is);
 		is.close();
-		calcScalars();
+		calcExtractInformation();
 	}
 
-	private def calcScalars() {
+	private def calcExtractInformation() {
 		val XPathFactory xPathfactory = XPathFactory.newInstance();
 		val XPath xpath = xPathfactory.newXPath();
+		val XPathExpression exprGuid = xpath.compile("/fmiModelDescription/@guid");
+		this.guid = exprGuid.evaluate(this.md);
 		val XPathExpression expr = xpath.compile("/fmiModelDescription/ModelVariables/ScalarVariable");
 		val NodeList nl = expr.evaluate(this.md, XPathConstants.NODESET) as NodeList;
 		for (var int i = 0; i < nl.length; i++) {
@@ -57,7 +66,9 @@ class ModelDescription {
 			this.svDefs.put(name, define -> Integer.parseInt(valueRef));
 			val sv = ScalarVariable.Create().setCausality(
 				SVCausality.valueOf(node.attributes.getNamedItem("causality").nodeValue)).setName(nodeName).setOwner(
-				this.name).setValueReference(valueRef);
+				this.name).setValueReference(valueRef).setIndex((i + 1).toString).setVariability(
+				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) {
@@ -83,4 +94,6 @@ class ModelDescription {
 	}
 
 	public def getSv() { return this.svs; }
+
+	public def getGuid() { return this.guid; }
 }

+ 13 - 45
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend

@@ -25,27 +25,27 @@ public class ModelDescriptionCreator {
 	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");		
+
+	def String getModelDescription() {
+		if (mdName === null) {
+			throw new IllegalStateException("Model Description name is missing");
 		}
 		mdBuilder.CreateTemplate(mdName, UUID.randomUUID().toString);
-		for(sVar : sVars)
-		{
+		for (sVar : sVars) {
 			mdBuilder.addScalarVariable(sVar);
 		}
-		
+
 		return mdBuilder.toString();
 	}
 
-	def void setName(String name){
+	def void setName(String name) {
 		mdName = name;
 	}
-	
-	public def List<ScalarVariable> getScalars(){
+
+	public def List<ScalarVariable> getScalars() {
 		return this.sVars;
 	}
-	
+
 	private def Document getModelDescription(File path) {
 		var ZipFile fmu = new ZipFile(path);
 		var Enumeration<? extends ZipEntry> entries = fmu.entries();
@@ -65,40 +65,8 @@ public class ModelDescriptionCreator {
 		return doc;
 	}
 
-	def void CreateInputsOutput(Adaptation adaptation) {
-		var Map<String, Document> wrappedFMUs = new HashMap<String, Document>();
-
-		var test = adaptation.inner.eAllContents.toIterable.filter(InnerFMU);
-		for (type : test) {
-			var file = new File(type.path.replace('\"', ''));
-			var modelDesc = getModelDescription(file);
-			wrappedFMUs.put(type.name, modelDesc);
-		}
-
-		val XPathFactory xPathfactory = XPathFactory.newInstance();
-		val XPath xpath = xPathfactory.newXPath();
-
-		for (port : adaptation.inports) {
-			for (Map.Entry<String,Document> entry : wrappedFMUs.entrySet()) {
-				// Get the input type
-				val XPathExpression expr = xpath.compile(
-					"/fmiModelDescription/ModelVariables/ScalarVariable[@name='" + port.name + "']/*[1]");
-				val Node nl = expr.evaluate(entry.value, XPathConstants.NODE) as Node;
-				sVars.add(
-					ScalarVariable.Create().setName(port.name).setValueReference(mdBuilder.nextValueReference).setCausality(
-						SVCausality.input).setType(SVType.valueOf(nl.nodeName)));
-			}
-		}
-
-		for (port : adaptation.outports) {
-			for (Map.Entry<String,Document> entry : wrappedFMUs.entrySet()) {
-				val XPathExpression expr = xpath.compile(
-					"/fmiModelDescription/ModelVariables/ScalarVariable[@name='" + port.name + "']/*[1]");
-				val Node nl = expr.evaluate(entry.value, XPathConstants.NODE) as Node;
-				sVars.add(
-					ScalarVariable.Create().setName(port.name).setValueReference(mdBuilder.nextValueReference).setCausality(
-						SVCausality.output).setType(SVType.valueOf(nl.nodeName)));
-			}
-		}
+	def void CalcContent(ModelDescription md) {
+		sVars.addAll(md.getSv().values);
 	}
+
 }

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

@@ -12,6 +12,7 @@ public class ScalarVariable {
 	private String initial;
 	private SVType type;
 	private String start;
+	private String index;
 
 	private ScalarVariable() {
 
@@ -21,6 +22,15 @@ public class ScalarVariable {
 		return new ScalarVariable();
 	}
 
+	public ScalarVariable setIndex(String index){
+		this.index = index;
+		return this;
+	}
+	
+	public String getIndex(){
+		return this.index;
+	}
+	
 	public ScalarVariable setOwner(String owner) {
 		this.owner = owner;
 		return this;

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

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