Browse Source

Compiling lazy sa - not checked for correctness

Casper Thule 7 years ago
parent
commit
b88a460678
12 changed files with 177 additions and 72 deletions
  1. 4 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  2. BIN
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/Controller.fmu
  3. 36 8
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/lazy_canonical.sa
  4. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InputOutputType.java
  5. 5 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/ReturnInformation.java
  6. 7 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/exceptions/TypeException.java
  7. 52 29
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend
  8. 15 12
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend
  9. 1 16
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend
  10. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend
  11. 30 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InOutRulesConditionSwitch.xtend
  12. 25 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/StaticGenerators.xtend

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

@@ -46,7 +46,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	}
 	
 	@Test def lazy_sa_canonical() {
-		__parseNoErrors('test_input/single_folder_spec/lazy/lazy.sa', 'generated', "lazy");
+		__parseNoErrors('test_input/single_folder_spec/lazy/lazy_canonical.sa', 'generated', "lazy");
 	}
 
 	def __parseNoErrorsWithValidation(String directory, String filename) {
@@ -154,6 +154,9 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		
 		BuildUtilities.writeToFile(new File(saRootDir,"CMakeLists.txt"), StaticGenerators.generateCMakeLists(projectName, "framework"));
 		
+		val cMakeToolChain = StaticGenerators.generateToolChainCmake();
+		BuildUtilities.writeToFile(new File(saRootDir, "msys-toolchain.cmake"), cMakeToolChain);
+		
 		(new BuildUtilities()).copyNativeLibFiles(saFrameworkPath);
 		System.out.println("Stored framework at: " + saFrameworkPath);
 		

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/Controller.fmu


+ 36 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/lazy_canonical.sa

@@ -6,13 +6,13 @@ at "./path/to/LazySA.fmu"
 	with input ports obj_detected, passenger_up, passenger_down, passenger_stop, driver_up, driver_down, driver_stop
 	with output ports up, down, stop
 
-input ports obj_detected -> controller.obj_detected,
-			passenger_up -> controller.passenger_up,
-			passenger_down -> controller.passenger_down,
-			passenger_stop -> controller.passenger_stop,
-			driver_up -> controller.driver_up,
-			driver_down -> controller.driver_down,
-			driver_stop -> controller.driver_stop
+input ports obj_detected,
+			passenger_up,
+			passenger_down,
+			passenger_stop,
+			driver_up,
+			driver_down,
+			driver_stop
 
 output ports up, down, stop
 
@@ -80,10 +80,38 @@ in var
 	stored_sa_driver_stop := INIT_DRIVER_STOP;
 
 in rules {
-	true 
+	true -> {
+		stored_sa_obj_detected := lazy_sa.obj_detected;
+		stored_sa_passenger_up := lazy_sa.passenger_up;
+		stored_sa_passenger_down := lazy_sa.passenger_down;
+		stored_sa_passenger_stop := lazy_sa.passenger_stop;
+		stored_sa_driver_up := lazy_sa.driver_up;
+		stored_sa_driver_down := lazy_sa.driver_down;
+		stored_sa_driver_stop := lazy_sa.driver_stop;
+	} --> {
+		controller.obj_detected := stored_sa_obj_detected;
+		controller.passenger_up := stored_sa_passenger_up;
+		controller.passenger_down := stored_sa_passenger_down;
+		controller.passenger_stop := stored_sa_passenger_stop;
+		controller.driver_up := stored_sa_driver_up;
+		controller.driver_down := stored_sa_driver_down;
+		controller.driver_stop := stored_sa_driver_stop;
+	};
 }
 	
 out var
 	stored_sa_up := INIT_UP,
 	stored_sa_down := INIT_DOWN,
 	stored_sa_stop := INIT_STOP;
+out rules {
+	true -> {
+		stored_sa_up := controller.up;
+		stored_sa_down := controller.down;
+		stored_sa_stop := controller.stop;
+	} --> {
+		up := stored_sa_up;
+		down := stored_sa_down;
+		stop := stored_sa_stop;
+	};
+	
+}

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

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

+ 5 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/ReturnInformation.java

@@ -84,10 +84,9 @@ public class ReturnInformation {
 	}
 
 	/*
-	 * This method automatically extracts information that should be passed on
+	 * This method automatically extracts type information
 	 */
 	public ReturnInformation(ReturnInformation information) throws InvalidConversionException {
-
 		this.conGlobVar = information.conGlobVar;
 		if (information.typeIsSet)
 			this.setType(information.type);
@@ -95,6 +94,10 @@ public class ReturnInformation {
 
 	}
 
+	/*
+	 * This method automatically extracts and compares type information
+	 */
+	
 	public ReturnInformation(ReturnInformation information, ReturnInformation information2) throws Exception {
 		if (information.conGlobVar != null) {
 			if (information2.conGlobVar != null) {

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

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

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

@@ -1,37 +1,62 @@
 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.GlobalInOutVariable
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 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 be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DoStepFun
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StepSize
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Variable
+import java.util.LinkedHashMap
 
-class ControlConditionSwitch extends InOutRulesConditionSwitch {
+class ControlConditionSwitch extends RulesConditionSwitch {
 
-	new(String adaptationClassName, 
-		String adaptationName, 
-		LinkedHashMap<String,SAScalarVariable> SASVs
+	new(
+		String adaptationClassName,
+		String adaptationName,
+		LinkedHashMap<String, SAScalarVariable> SASVs,
+		LinkedHashMap<String, GlobalInOutVariable> params
 	) {
-		super(adaptationClassName, adaptationName, "", null, SASVs, newLinkedHashMap());
+		super(adaptationClassName, adaptationName, "", null, SASVs, params);
 	}
 
-	override ReturnInformation caseControlRuleBlock(ControlRuleBlock obj) {
+	override ReturnInformation caseVariable(Variable object) {
 		var retVal = new ReturnInformation();
 
-		for (crtlRule : obj.eAllContents.toIterable.filter(ControlRule)) {
-			retVal.appendCode(doSwitch(crtlRule).code);
+		// H and t are protected variables.
+		if ((object.owner === null || object.owner.name == this.adaptationName) &&
+			(object.ref.name == "H" || object.ref.name == "t")) {
+			retVal.type = SVType.Real;
+			retVal.forceType = true;
+			retVal.code = object.ref.name;
+		} else {
+			retVal = super.caseVariable(object);
 		}
 
 		return retVal;
 	}
 
-	override ReturnInformation caseCustomControlRule(CustomControlRule object) {	
+	override ReturnInformation caseControlRuleBlock(ControlRuleBlock object) {
+		this.globalDeclaration = true;
+
+		var retVal = new ReturnInformation();
+
+		// Get the global variables added to globalVars
+		for (gVar : object.globalCtrlVars) {
+			constructorInitialization += doSwitch(gVar).code;
+		}
+
+		this.globalDeclaration = false;
+		retVal.appendCode(doSwitch(object.rule).code);
+
+		return retVal;
+	}
+
+	override ReturnInformation caseCustomControlRule(CustomControlRule object) {
 		var retVal = new ReturnInformation();
 
 		var String tempDoSwitchCode = "";
@@ -39,23 +64,21 @@ class ControlConditionSwitch extends InOutRulesConditionSwitch {
 			tempDoSwitchCode += doSwitch(ruleStm).code;
 		}
 		tempDoSwitchCode += System.lineSeparator() + '''return «doSwitch(object.returnstatement).code»;
-			''';
-		
+		''';
+
 		var functionPrefix = "double ";
-		var functionNameArgs = "executeInternalControlFlow(double h, double dt)"
+		var functionNameArgs = "executeInternalControlFlow(double H, double t)"
 		functionSignatures.add(functionPrefix + functionNameArgs);
-		retVal.code = 
-			'''
-				«functionPrefix+this.adaptationClassName»::«functionNameArgs»
-				{
-					«tempDoSwitchCode»
-				}
-			''';
+		retVal.code = '''
+			«functionPrefix+this.adaptationClassName»::«functionNameArgs»
+			{
+				«tempDoSwitchCode»
+			}
+		''';
 		return retVal;
 	}
 
-	override ReturnInformation caseDoStepFun(DoStepFun object)
-	{
+	override ReturnInformation caseDoStepFun(DoStepFun object) {
 		var retVal = new ReturnInformation();
 		retVal.code = '''this->do_step(«object.fmu.name»,«doSwitch(object.h).code»,«doSwitch(object.t).code»);''';
 		retVal.type = SVType.Integer;
@@ -70,13 +93,13 @@ class ControlConditionSwitch extends InOutRulesConditionSwitch {
 
 	override ReturnInformation caseStepSize(StepSize object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''h''';
+		retVal.code = '''H''';
 		return retVal;
 	}
 
 	override ReturnInformation caseCurrentTime(CurrentTime object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''dt''';
+		retVal.code = '''t''';
 		return retVal;
 	}
 }

+ 15 - 12
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -14,7 +14,6 @@ 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
@@ -30,6 +29,7 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
 import java.util.List
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ParamDeclarations
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.InputOutputRuleType
 
 class CppGenerator extends SemanticAdaptationGenerator {
 	private var IFileSystemAccess2 fsa;
@@ -113,18 +113,18 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			// Compile the transparent in mappings
 
 			// Compile the in rules
-			val inRuleResult = compileInOutRuleBlocks(InputOutputType.Input, adaptation.eAllContents.toIterable.filter(
+			val inRuleResult = compileInOutRuleBlocks(InputOutputRuleType.Input, adaptation.eAllContents.toIterable.filter(
 				InRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs,
 				params);
 
 			// Compile the out rules
-			val outRuleResult = compileInOutRuleBlocks(InputOutputType.Output, adaptation.eAllContents.toIterable.
+			val outRuleResult = compileInOutRuleBlocks(InputOutputRuleType.Output, adaptation.eAllContents.toIterable.
 				filter(OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables,
 				SASVs, params);
 
 			// Compile the Control Rules
 			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
-				adapClassName, adapInteralRefName, SASVs);
+				adapClassName, adapInteralRefName, SASVs, params);
 
 			/*
 			 * Compile the constructor, destructor and initialize functions
@@ -136,7 +136,8 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				md.guid,
 				paramsConstructorSource,
 				inRuleResult.constructorInitialization,
-				outRuleResult.constructorInitialization
+				outRuleResult.constructorInitialization,
+				crtlRuleResult.constructorInitialization
 			);
 
 			/*
@@ -170,6 +171,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			allGVars.putAll(params);
 			allGVars.putAll(outRuleResult.gVars);
 			allGVars.putAll(inRuleResult.gVars);
+			allGVars.putAll(crtlRuleResult.gVars);
 
 			// Compile the header file
 			val headerFile = compileHeader(
@@ -337,7 +339,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * Compiles the source file constructor, destructor and the initialize function
 	 */
 	def String compileDeAndConstructorAndInitialize(String adapClassName, String fmuName, String fmuTypeName,
-		String guid, String paramsCons, String inCons, String outCons) {
+		String guid, String paramsCons, String inCons, String outCons, String crtlCons) {
 		return '''
 			«adapClassName»::«adapClassName»(shared_ptr<std::string> fmiInstanceName,shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions) : 
 				SemanticAdaptation(fmiInstanceName, resourceLocation, createInputRules(),createOutputRules(), functions)
@@ -346,6 +348,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				«paramsCons»
 				«inCons»
 				«outCons»
+				«crtlCons»
 			}
 			
 			void «adapClassName»::initialize()
@@ -471,15 +474,15 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * Compiles the source file function executeInternalControlFlow.
 	 * 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, SAScalarVariable> SASVs) {
+	def InOutRulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String adaptationClassName,
+		String adaptationName, LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params) {
 		var cpp = "";
-		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, SASVs);
+		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, SASVs, params);
 		for (crtlRule : crtlRuleBlocks) {
 			cpp += visitor.doSwitch(crtlRule).code;
 		}
 
-		return new RulesBlockResult(cpp, visitor.functionSignatures);
+		return new InOutRulesBlockResult(cpp, visitor.functionSignatures, visitor.globalVars, visitor.constructorInitialization);
 	}
 
 	def String SplitAtSpaceAndRemoveFirst(String content) {
@@ -495,12 +498,12 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * Calculates necessary information on global in/out variables necessary for generation of the header file.
 	 * Calculates necessary information on function signatures necessary for generation of the header file.
 	 */
-	def InOutRulesBlockResult compileInOutRuleBlocks(InputOutputType ioType, Iterable<InOutRules> rulesBlocks,
+	def InOutRulesBlockResult compileInOutRuleBlocks(InputOutputRuleType ioType, Iterable<InOutRules> rulesBlocks,
 		String adaptationClassName, String adaptationName,
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
 		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params) {
 
-		val visitor = if (ioType == InputOutputType.Input)
+		val visitor = if (ioType == InputOutputRuleType.Input)
 				new InRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params)
 			else
 				new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params);

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

@@ -8,7 +8,7 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
 
-class InRulesConditionSwitch extends InOutRulesConditionSwitch {
+class InRulesConditionSwitch extends RulesConditionSwitch {
 
 	private Boolean inOutputFunction = false;
 
@@ -25,11 +25,6 @@ class InRulesConditionSwitch extends InOutRulesConditionSwitch {
 		val ReturnInformation retVal = super.caseCompositeOutputFunction(object);
 		this.inOutputFunction = false;
 		return retVal;
-	
-//		this.inOutputFunction = true;
-//		val returnVal = super.caseCompositeOutputFunction(object);
-//		this.inOutputFunction = false;
-//		return returnVal;
 	}
 
 	override ReturnInformation caseAssignment(Assignment object) {
@@ -46,16 +41,6 @@ class InRulesConditionSwitch extends InOutRulesConditionSwitch {
 		{
 			return super.caseAssignment(object);
 		}
-	
-
-
-//		// We need to record the assignments such that we can get the correct variability and such later on. In this case we are in input		
-//		if (inOutputFunction) {	'''
-//			setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr)»);
-//		''';
-//		} else {
-//			super.caseAssignment(object);
-//		}
 	}
 
 }

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

@@ -7,7 +7,7 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 import java.util.LinkedHashMap
 
-public class OutRulesConditionSwitch extends InOutRulesConditionSwitch {
+public class OutRulesConditionSwitch extends RulesConditionSwitch {
 	new(String adaptationClassName, String adaptationName,
 		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
 		LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params) {

+ 30 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InOutRulesConditionSwitch.xtend

@@ -31,8 +31,11 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.IsSet
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Div
 import org.eclipse.emf.common.util.EList
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InOutRules
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Min
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.TypeException
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Minus
 
-abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
+abstract class RulesConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
 	// Global in and out variables
 	protected var LinkedHashMap<String, GlobalInOutVariable> gVars = newLinkedHashMap();
 
@@ -314,6 +317,7 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<Return
 		return retVal;
 	}
 
+
 	override ReturnInformation caseVariable(Variable object) {
 
 		var retVal = new ReturnInformation();
@@ -359,7 +363,7 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<Return
 			var String code = "";
 
 			if (globalDeclaration) {
-				// This is an in var or out var declaration	
+				// This is an in var, out var or crtl var declaration	
 				code = '''
 					this->«decl.name» = «doSwitchRes.code»;
 				'''
@@ -409,4 +413,28 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<Return
 		return retInfo;
 	}
 
+	override ReturnInformation caseMin(Min object)
+	{
+		var retInfo = new ReturnInformation();
+		var doSwitchResCode = newArrayList();
+		for (expr : object.args) {
+			val doSwitchRes_ = this.doSwitch(expr);
+			doSwitchResCode.add(doSwitchRes_.code);
+			retInfo = new ReturnInformation(retInfo, doSwitchRes_);
+		} 
+		retInfo.code = 
+		'''
+		min(«doSwitchResCode.join(",")»)
+		'''
+		return retInfo;
+	}
+	
+	override ReturnInformation caseMinus(Minus object){
+		val doSwitchLeft = doSwitch(object.left);
+		val doSwitchRight = doSwitch(object.right);
+		var retVal = new ReturnInformation(doSwitchLeft, doSwitchRight);
+		retVal.code = '''«doSwitchLeft.code» - «doSwitchRight.code»''';
+		return retVal;		
+	}
+
 }

+ 25 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/StaticGenerators.xtend

@@ -144,6 +144,31 @@ class StaticGenerators {
 		'''
 	}
 
+	def static String generateToolChainCmake(){
+		'''
+		# the name of the target operating system
+		SET(CMAKE_SYSTEM_NAME Windows)
+		
+		SET(WIN32 true)
+		
+		# which compilers to use for C and C++
+		SET(CMAKE_C_COMPILER /mingw64/bin/gcc)
+		SET(CMAKE_CXX_COMPILER /mingw64/bin/g++)
+		#SET(CMAKE_RC_COMPILER i486-mingw32-windres)
+		
+		# here is the target environment located
+		#SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)
+		
+		# adjust the default behaviour of the FIND_XXX() commands:
+		# search headers and libraries in the target environment, search 
+		# programs in the host environment
+		#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+		#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+		#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+		
+		'''
+	}
+
 	def static String generateCMakeLists(String projectName, String frameworkPath)
 	{
 		'''