Browse Source

remove in bindings

Cláudio Gomes 3 years ago
parent
commit
254c93209b

+ 11 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationGeneratorTest.xtend

@@ -47,8 +47,8 @@ class SemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationTest{
 			override accept(Result t) {
 				var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
 				sa.inports.filter[p | p.name=="innerFMU1__input_port2"].head.type == "Bool"
-				sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.owner.name == "innerFMU2"
-				sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.port.name == "input_port3"
+				//sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.owner.name == "innerFMU2"
+				//sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.port.name == "input_port3"
 			}
 		}) }
 	
@@ -87,6 +87,15 @@ class SemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationTest{
 			}
 		}) }
 	
+	
+	@Test def test_removeInBindings_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
+			override accept(Result t) {
+				var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
+				sa.inports.forall[p | p.targetdependency === null]
+			}
+		}) }
+	
+	
 	@Test def window_SA_parseNoExceptions() { __generate('input/power_window_case_study/window_sa.BASE.sa', new IAcceptor<CompilationTestHelper.Result>(){
 			override accept(Result t) { }
 		}) }

+ 26 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/generator/SemanticAdaptationCanonicalGenerator.xtend

@@ -231,9 +231,23 @@ class SemanticAdaptationCanonicalGenerator extends AbstractGenerator {
 		
 		addInRules_External2Internal_Assignments(sa, internalPort2ExternalPortBindings)
 		
+		removeInBindings(internalPort2ExternalPortBindings, sa)
+		
 		Log.pop("Canonicalize")
 	}
 	
+	def removeInBindings(HashMap<Port, Port> internalPort2ExternalPortBindings, Adaptation sa) {
+		Log.push("removeInBindings")
+		
+		for (internalPort : internalPort2ExternalPortBindings.keySet){
+			val externalPort = internalPort2ExternalPortBindings.get(internalPort)
+			Log.println("Removing binding " + externalPort.name + "->" + internalPort.name)
+			externalPort.targetdependency = null
+		}
+		
+		Log.pop("removeInBindings")
+	}
+	
 	def findAllExternalPort2InputPort_Bindings(Adaptation sa) {
 		Log.push("findAllExternalPort2InputPort_Bindings")
 		
@@ -242,7 +256,7 @@ class SemanticAdaptationCanonicalGenerator extends AbstractGenerator {
 		for (port : getAllInnerFMUInputPortDeclarations(sa)){
 			var parentFMU = port.eContainer as InnerFMU
 			Log.println("Checking if port " + parentFMU.name + "." + port.name + " is bound to an external port.")
-			val externalPort = findExternalPortByName(sa, createExternalPortNameFromInternalPort(parentFMU.name,port.name))
+			val externalPort = findExternalPortByTargetDependency(sa, port)
 			if (externalPort !== null){
 				Log.println("Port " + parentFMU.name + "." + port.name + " is bound to an external port: " + externalPort.name)
 				internalPort2ExternalPortBindings.put(port, externalPort)
@@ -829,6 +843,17 @@ class SemanticAdaptationCanonicalGenerator extends AbstractGenerator {
 		return null
 	}
 	
+	
+	def findExternalPortByTargetDependency(Adaptation sa, Port targetDependency) {
+		for (externalInputPort : sa.inports){
+			if (externalInputPort.targetdependency !== null && externalInputPort.targetdependency.port == targetDependency){
+				return externalInputPort
+			}
+		}
+		return null
+	}
+	
+	
 	def hasIncomingConnection(Port port, Adaptation adaptation) {
 		
 		var result = false