Browse Source

Added all variables
Refactored

Casper Thule 3 years ago
parent
commit
13cd66384a

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

@@ -5,40 +5,50 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CustomControlR
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DoStep
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StepSize
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
 
-class ControlConditionSwitch<CharSequence> extends InOutRulesConditionSwitch {
+class ControlConditionSwitch extends InOutRulesConditionSwitch {
 
 	new(String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars) {
 		super(adaptationName, scalars, "");
 	}
-	
+
+	override String caseControlRuleBlock(ControlRuleBlock obj) {
+		var cpp = "";
+		for (crtlRule : obj.eAllContents.toIterable.filter(ControlRule)) {
+			cpp += doSwitch(crtlRule);
+		}
+
+		return cpp;
+	}
+
 	override String caseCustomControlRule(CustomControlRule object) {
 		var String returnVal = "";
-		
-		for(ruleStm : object.controlRulestatements)
-		{
-			returnVal += doSwitch(ruleStm);	
+
+		for (ruleStm : object.controlRulestatements) {
+			returnVal += doSwitch(ruleStm);
 		}
-		
+
 		var functionPrefix = "void ";
 		var functionNameArgs = "executeInternalControlFlow(double h, double dt)"
-		functionSignatures.add(functionPrefix+functionNameArgs+";");
+		functionSignatures.add(functionPrefix + functionNameArgs + ";");
 		return '''
 		«functionPrefix+this.adaptationName»::«functionNameArgs»
 		{
 			«returnVal»
 		}''';
 	}
-	
-	override String caseDoStep(DoStep object){
+
+	override String caseDoStep(DoStep object) {
 		return '''this->doStep(«object.fmu.name»,«doSwitch(object.h)»,«doSwitch(object.t)»);''';
 	}
-	
-	override String caseStepSize(StepSize object){
-			return '''h''';
+
+	override String caseStepSize(StepSize object) {
+		return '''h''';
 	}
-	
-	override String caseCurrentTime(CurrentTime object){
+
+	override String caseCurrentTime(CurrentTime object) {
 		return '''dt''';
 	}
 }

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

@@ -0,0 +1,13 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+public class Conversions {
+	public static String fmiTypeToCppType(SVType t)
+	{
+		switch (t) {
+		case Real:
+			return "double";
+		default:
+			return t.toString().toLowerCase();
+		}
+	}
+}

+ 129 - 64
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -14,13 +14,14 @@ 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 {
 
 	var ModelDescriptionCreator mdCreator = new ModelDescriptionCreator()
 	var SwitchTest = new Visitor();
-	var InRulesConditionSwitch inrules;
-	var LinkedHashMap<String, Pair<String, Integer>> scalars = newLinkedHashMap();
+
 	private var IFileSystemAccess2 fsa;
 
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
@@ -36,64 +37,60 @@ class CppGenerator extends SemanticAdaptationGenerator {
 // TODO: Add initial value to inputs in the model description file
 	def void compile(SemanticAdaptation adaptation) {
 		for (type : adaptation.elements.filter(Adaptation)) {
-			var fmus = newArrayList();		
-			
-			// Extract all the scalar values from the model description file
+			var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
+			var ArrayList<String> fmus = newArrayList();
+			var LinkedHashMap<String, ScalarVariable> sVars = newLinkedHashMap();
+			var String genSource = "";
+						
+			// Load Model Description file
 			for (fmu : type.inner.eAllContents.toIterable.filter(InnerFMU)) {
-				//TODO: Merge this with ModelDescriptionCreator
+				// TODO: Merge this with ModelDescriptionCreator
 				var md = new ModelDescription(fmu.name, new File(fmu.path.replace('\"', '')));
 				fmus.add(fmu.name);
-				this.scalars.putAll(md.scalars);
-			}
-			
-			// Create Defines for the scalar values
-			var defines = newArrayList();
-			for(scalar : this.scalars.entrySet){
-				val pair = scalar.value;
-				defines.add("#define " + pair.key + " " + pair.value);
-			}
-			
-			var String generatedDefines = defines.join("\n");
-			fsa.generateFile("defines.cpp", generatedDefines);
-			
-			var String generatedCpp;
-			
-			// Generate the In Rules
-			this.inrules = new InRulesConditionSwitch(type.name, scalars);
-			for (inRules : adaptation.eAllContents.toIterable.filter(InRulesBlock)) {
-				for (dataRule : inRules.eAllContents.toIterable.filter(DataRule)) {
-					this.inrules.incrementCount;
-					generatedCpp+=this.inrules.doSwitch(dataRule);
-				}
-			}
-			
-			// Generate the Out Rules
-			var outrules = new OutRulesConditionSwitch(type.name, scalars);
-			for(outRules : adaptation.eAllContents.toIterable.filter(OutRulesBlock)){
-				for(dataRule : outRules.eAllContents.toIterable.filter(DataRule)){
-					outrules.incrementCount;
-					generatedCpp+=outrules.doSwitch(dataRule);
-				}
-			}
-			
+				svDefs.putAll(md.svDef);
+				sVars.putAll(md.sv);
+			}			
+
+			// Compile the in rules
+			val inRuleResult = compileInRuleBlock(adaptation.eAllContents.toIterable.filter(InRulesBlock), svDefs,
+				type.name);
+			genSource += inRuleResult.generatedCpp;
+
+			// Compile the out rules
+			val outRuleResult = compileOutRuleBlock(adaptation.eAllContents.toIterable.filter(OutRulesBlock), svDefs,
+				type.name);
+			genSource += outRuleResult.generatedCpp;
+
 			// Generate the Control Rules
-			var controlrule = new ControlConditionSwitch(type.name,	 scalars);
-			for(controlRule : adaptation.eAllContents.toIterable.filter(ControlRuleBlock)){
-				for(crtlRule : controlRule.eAllContents.toIterable.filter(ControlRule)){
-					generatedCpp += controlrule.doSwitch(crtlRule);
-				}
-			}
+			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;				
+
+			// Generate the source file for the SA
+			fsa.generateFile(type.name + ".cpp", genSource);
 
-			// Generate the cpp file for the SA
-			fsa.generateFile(type.name+".cpp", generatedCpp);
+			// Compile defines for the scalar variables
+			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 h file for the SA
-			var String header = 
-			'''
-			class «type.name» : SemanticAdaptation<«type.name»>{
+ 			// Generate the header file for the SA
+			fsa.generateFile(type.name + ".h", genDef + header);
+		}
+	}
+
+	def String compileHeader(String name, InOutRulesBlockResult inRulesResult, InOutRulesBlockResult outRulesResult,
+		RulesBlockResult crtlRulesResult, ArrayList<String> fmus, LinkedHashMap<String, ScalarVariable> sVars) {
+		return '''
+			class «name» : SemanticAdaptation<«name»>{
 				public:
-					«type.name»();
-					virtual ~«type.name»();
+					«name»();
+					virtual ~«name»();
 					
 					void setFmiValue(int id, int value);
 					void setFmiValue(int id, bool value);
@@ -103,33 +100,101 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					bool getFmiValueBoolean(int id);
 					double getFmiValueDouble(int id);
 				private:
-					shared_ptr<std::list<Rule<«type.name»>>>createInputRules();
-					shared_ptr<std::list<Rule<«type.name»>>> createOutputRules();
+					shared_ptr<std::list<Rule<«name»>>>createInputRules();
+					shared_ptr<std::list<Rule<«name»>>> createOutputRules();
 					
 					/*in rules*/
-					«inrules.functionSignatures.join("\n")»
+					«inRulesResult.functionSignatures.join("\n")»
 					
 					/*out rules*/
-					«outrules.functionSignatures.join("\n")»
+					«outRulesResult.functionSignatures.join("\n")»
 					
-					«controlrule.functionSignatures.join("\n")»
+					«crtlRulesResult.functionSignatures.join("\n")»
 					
 					«FOR fmu : fmus»
 						shared_ptr<Fmu> «fmu»;
 					«ENDFOR»
 					
-					«FOR sv : scalars.entrySet»
-						
+					«FOR sv : sVars.entrySet»
+						«Conversions.fmiTypeToCppType(sv.value.type)» «sv.value.name»;
+						«IF sv.value.causality == SVCausality.input»
+							bool isSet«sv.value.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»;
 					«ENDFOR»
 			}
+		''';
+	}
+
+	def compileConstructor(String name, InOutRulesBlockResult outRuleResult, InOutRulesBlockResult inRuleResult,
+		LinkedHashMap<String, ScalarVariable> sVars) {
+		return 
 			'''
-			fsa.generateFile(type.name+".h", header);
-			
+				«name»::«name»() : 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»
+				}
+			''';
+	}
+
+	def RulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String name,
+		LinkedHashMap<String, Pair<String, Integer>> svDefs) {
+		var cpp = "";
+		val visitor = new ControlConditionSwitch(name, svDefs);
+		for (crtlRule : crtlRuleBlocks) {
+			cpp += visitor.doSwitch(crtlRule);
 		}
 
+		return new RulesBlockResult(cpp, visitor.functionSignatures);
+	}
+
+	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);
 	}
 
-	def CharSequence compile(Adaptation adaptation) {
-		return '''compiling «adaptation.toString»''';
+	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);
+	}
+
+	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)
+		}
+		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);
+		}
+		return defines;
 	}
 }

+ 17 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesBlockResult.java

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

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

@@ -19,12 +19,18 @@ import org.eclipse.emf.ecore.EObject
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Multi
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IntLiteral
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Neg
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Literal
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
 
 abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String> {
 
+	protected var LinkedHashMap<String, Pair<SVType, Object>> globalVars = newLinkedHashMap();
+	private var Pair<SVType, Object> lastVal;
 	protected final String adaptationName;
 	protected final LinkedHashMap<String, Pair<String, Integer>> scalars;
-	protected Integer count = 0;
+	private Integer count = 0;
 	private final String functionPrefix;
 	protected List<String> functionSignatures = newArrayList();
 	protected String externalVariableOwner;
@@ -49,44 +55,67 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 		this.count++;
 	}
 
-	override String caseBoolLiteral(BoolLiteral object) {
-		return '''«object.value»''';
+	override String caseOutRulesBlock(OutRulesBlock object) {
+		var cpp = ""
+		for (gVar : object.globalOutVars) {
+			doSwitch(gVar)
+		}
+		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+			this.incrementCount;
+			cpp += doSwitch(dataRule);
+		}
+		return cpp;
 	}
 
-	override String caseRealLiteral(RealLiteral object) {
+	override String caseInRulesBlock(InRulesBlock object) {
+		var cpp = ""
+		for (gVar : object.globalInVars) {
+			doSwitch(gVar)
+		}
+		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+			this.incrementCount;
+			cpp += doSwitch(dataRule);
+		}
+		return cpp;
+	}
+
+	override String caseBoolLiteral(BoolLiteral object) {
 		return '''«object.value»''';
 	}
 
 	override String caseRuleCondition(RuleCondition object) {
-		val functionSignature = createFunctionSignature("condition","bool");
-		'''«functionSignature»{
-			return «doSwitch(object.condition)»;
-		}''';
+		val functionSignature = createFunctionSignature("condition", "bool");
+		'''
+			«functionSignature»{
+				return «doSwitch(object.condition)»;
+			}
+		''';
 	}
 
 	override String caseStateTransitionFunction(StateTransitionFunction object) {
-		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»
-		}
+		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 String caseDataRule(DataRule object) {
-		return '''			
+		return '''
 			«doSwitch(object.condition)»
-				«doSwitch(object.statetransitionfunction)»
-				«doSwitch(object.outputfunction)»
+			«doSwitch(object.statetransitionfunction)»
+			«doSwitch(object.outputfunction)»
 		'''
 	}
 
@@ -95,7 +124,7 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 	}
 
 	override String caseIf(If object) {
-		'''
+		return '''
 			if(«doSwitch(object.ifcondition)»){
 				«FOR stm : object.ifstatements»
 					«doSwitch(stm)»
@@ -143,15 +172,42 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 	}
 
 	override String caseCompositeOutputFunction(CompositeOutputFunction object) {
-		val functionSig = createFunctionSignature("flush","void");
+		val functionSig = createFunctionSignature("flush", "void");
 		val returnVal = '''
 			«functionSig»{
 				«FOR stm : object.statements»
 					«doSwitch(stm)»
 				«ENDFOR»
-				}
+			}
 		''';
 		return returnVal;
 	}
 
+	public def getVars() { return this.globalVars; }
+
+	override String caseDeclaration(Declaration object) {
+		var returnVal = "";
+
+		for (decl : object.declarations) {
+			returnVal += doSwitch(decl.expr);
+			globalVars.put(decl.name, lastVal);
+		}
+		return returnVal;
+	}
+
+	override String caseRealLiteral(RealLiteral object) {
+		lastVal = convertType(SVType.Real, object);
+		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: {
+			}
+		}
+	}
+
 }

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

@@ -4,7 +4,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 import java.util.LinkedHashMap
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
 
-class InRulesConditionSwitch<CharSequence> extends InOutRulesConditionSwitch {
+class InRulesConditionSwitch extends InOutRulesConditionSwitch {
 
 	private Boolean inOutput = false;
 
@@ -21,7 +21,7 @@ class InRulesConditionSwitch<CharSequence> extends InOutRulesConditionSwitch {
 
 	override String caseAssignment(Assignment object) {
 		if (inOutput) {	'''
-		setValue(«object.lvalue.owner.name»,«scalars.get(object.lvalue.owner.name+object.lvalue.ref.name).key»,«doSwitch(object.expr)»);
+			setValue(«object.lvalue.owner.name»,«scalars.get(object.lvalue.owner.name+object.lvalue.ref.name).key»,«doSwitch(object.expr)»);
 		''';
 		} else {
 			super.caseAssignment(object);

+ 25 - 16
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend

@@ -19,8 +19,8 @@ import javax.lang.model.element.Element
 class ModelDescription {
 	private final Document md;
 	private final String name;
-	private var LinkedHashMap<String,Pair<String,Integer>> scalarDefinitions = newLinkedHashMap();
-	private var LinkedHashMap<String,SVType> scalarWithTypes = newLinkedHashMap();
+	private var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
+	private var LinkedHashMap<String, ScalarVariable> svs = newLinkedHashMap();
 
 	new(String name, File path) {
 		this.name = name;
@@ -51,27 +51,36 @@ class ModelDescription {
 		for (var int i = 0; i < nl.length; i++) {
 			val node = nl.item(i);
 			val nodeName = node.attributes.getNamedItem("name").nodeValue;
+			val valueRef = node.attributes.getNamedItem("valueReference").nodeValue;
 			val name = this.name + nodeName;
-			val define = name.toUpperCase; 
-			this.scalarDefinitions.put(name,define -> i+1);
-			
-			for(var j = 0; j < node.childNodes.length; j++)
-			{
+			val define = name.toUpperCase;
+			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);
+			for (var j = 0; j < node.childNodes.length; j++) {
 				val subNode = node.childNodes.item(j);
-				if(subNode.nodeType == Node.ELEMENT_NODE)
-				{
-					val type = SVType.valueOf(subNode.nodeName);
-					this.scalarWithTypes.put(nodeName, type);
+				if (subNode.nodeType == Node.ELEMENT_NODE) {
+					val startAttribute = subNode.attributes.getNamedItem("start");
+					if (startAttribute !== null) {
+						sv.start = startAttribute.nodeValue;
+					}
+					sv.type = SVType.valueOf(subNode.nodeName);
+
+					this.svs.put(nodeName, sv);
+
 				}
 			}
 		}
 	}
-	
-	public def getName(){
+
+	public def getName() {
 		return this.name;
 	}
-	
-	public def getScalars() {
-		return this.scalarDefinitions;
+
+	public def getSvDef() {
+		return this.svDefs;
 	}
+
+	public def getSv() { return this.svs; }
 }

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

@@ -0,0 +1,12 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.List;
+
+public class RulesBlockResult {
+	public final String generatedCpp;
+	public final List<String> functionSignatures;
+	public RulesBlockResult(String generatedCpp, List<String> functionSignatures) {
+		this.generatedCpp = generatedCpp;
+		this.functionSignatures = functionSignatures;
+	}
+}

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

@@ -1,91 +1,102 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-import java.util.Optional;
-
-public class ScalarVariable {
-	private String name;
-	private String valueReference;
-	private String description;
-	private String variability;
-	private SVCausality causality;
-	private String initial;
-	private SVType type;
-	private String start;
-	private ScalarVariable(){
-		
-	}
-	public static ScalarVariable Create(){
-		return new ScalarVariable();
-	}
-	public String getName() {
-		return name;
-	}
-
-	public ScalarVariable setName(String name) {
-		this.name = name;
-		return this;
-	}
-
-	public String getValueReference() {
-		return valueReference;
-	}
-
-	public ScalarVariable setValueReference(String valueReference) {
-		this.valueReference = valueReference;
-		return this;
-	}
-
-	public String getVariability() {
-		return variability;
-	}
-
-	public ScalarVariable setVariability(String variability) {
-		this.variability = variability;
-		return this;
-	}
-
-	public SVCausality getCausality() {
-		return causality;
-	}
-
-	public ScalarVariable setCausality(SVCausality causality) {
-		this.causality = causality;
-		return this;
-	}
-
-	public String getInitial() {
-		return initial;
-	}
-
-	public ScalarVariable setInitial(String initial) {
-		this.initial = initial;
-		return this;
-	}
-
-	public SVType getType() {
-		return type;
-	}
-
-	public ScalarVariable setType(SVType type) {
-		this.type = type;
-		return this;
-	}
-
-	public String getStart() {
-		return start;
-	}
-
-	public ScalarVariable setStart(String start) {
-		this.start = start;
-		return this;
-	}
-
-	public String getDescription() {
-		return description;
-	}
-
-	public ScalarVariable setDescription(String description) {
-		this.description = description;
-		return this;
-	}
-}
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.Optional;
+
+public class ScalarVariable {
+	private String owner;
+	private String name;
+	private String valueReference;
+	private String description;
+	private String variability;
+	private SVCausality causality;
+	private String initial;
+	private SVType type;
+	private String start;
+
+	private ScalarVariable() {
+
+	}
+
+	public static ScalarVariable Create() {
+		return new ScalarVariable();
+	}
+
+	public ScalarVariable setOwner(String owner) {
+		this.owner = owner;
+		return this;
+	}
+
+	public String getOwner(){return this.owner;}
+
+	public String getName() {
+		return name;
+	}
+
+	public ScalarVariable setName(String name) {
+		this.name = name;
+		return this;
+	}
+
+	public String getValueReference() {
+		return valueReference;
+	}
+
+	public ScalarVariable setValueReference(String valueReference) {
+		this.valueReference = valueReference;
+		return this;
+	}
+
+	public String getVariability() {
+		return variability;
+	}
+
+	public ScalarVariable setVariability(String variability) {
+		this.variability = variability;
+		return this;
+	}
+
+	public SVCausality getCausality() {
+		return causality;
+	}
+
+	public ScalarVariable setCausality(SVCausality causality) {
+		this.causality = causality;
+		return this;
+	}
+
+	public String getInitial() {
+		return initial;
+	}
+
+	public ScalarVariable setInitial(String initial) {
+		this.initial = initial;
+		return this;
+	}
+
+	public SVType getType() {
+		return type;
+	}
+
+	public ScalarVariable setType(SVType type) {
+		this.type = type;
+		return this;
+	}
+
+	public String getStart() {
+		return start;
+	}
+
+	public ScalarVariable setStart(String start) {
+		this.start = start;
+		return this;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public ScalarVariable setDescription(String description) {
+		this.description = description;
+		return this;
+	}
+}