Commit 81df71af authored by Nils Kaminski's avatar Nils Kaminski
Browse files

Fix execution order

parent 73f061c3
......@@ -47,6 +47,9 @@ public class ImplementExecutionOrder {
protected static Map<EMAComponentInstanceSymbol, Collection<EMAConnectorInstanceSymbol>> instanceConnectorsMap = new HashMap<>();
protected static Map<EMAConnectorInstanceSymbol, EMAPortInstanceSymbol> connectorInstanceSourcePortInstance = new HashMap<>();
protected static Map<EMAConnectorInstanceSymbol, EMAPortInstanceSymbol> connectorInstanceTargetPortInstance = new HashMap<>();
protected static Map<EMAPortInstanceSymbol, Collection<EMAConnectorInstanceSymbol>> sourcePortConnectorsList = new HashMap<>();
/**
* This function initializes the execution order process. This means the dependencies map will cleared,
......@@ -60,6 +63,8 @@ public class ImplementExecutionOrder {
instanceConnectorsMap.clear();
connectorInstanceSourcePortInstance.clear();
connectorInstanceTargetPortInstance.clear();
sourcePortConnectorsList.clear();
s = 0;
b = 0;
......@@ -415,6 +420,11 @@ public class ImplementExecutionOrder {
* @return Target port of c
*/
public static EMAPortInstanceSymbol connectorTargetPort(EMAComponentInstanceSymbol inst, EMAConnectorInstanceSymbol c) {
if(connectorInstanceTargetPortInstance.containsKey(c)){
return connectorInstanceTargetPortInstance.get(c);
}
Iterator<String> parts = Splitters.DOT.split(c.getTarget()).iterator();
Optional<String> instance = Optional.empty();
Optional<String> instancePort;
......@@ -438,10 +448,12 @@ public class ImplementExecutionOrder {
}
if (port.isPresent()) {
connectorInstanceTargetPortInstance.put(c, port.get());
return port.get();
}
if (c.getTargetPort() != null) {
connectorInstanceTargetPortInstance.put(c,c.getTargetPort());
return c.getTargetPort();
}
Log.info(c.getEnclosingScope().toString(), "Scope:");
......@@ -479,6 +491,17 @@ public class ImplementExecutionOrder {
}else{
result = inst.getConnectorInstances();
}
for (EMAConnectorInstanceSymbol con :result) {
EMAPortInstanceSymbol source = connectorSourcePort(inst, con);
if(!sourcePortConnectorsList.containsKey(source)){
sourcePortConnectorsList.put(source, new ArrayList<>());
}
if(!sourcePortConnectorsList.get(source).contains(con)) {
sourcePortConnectorsList.get(source).add(con);
}
}
instanceConnectorsMap.put(inst, result);
return result;
}
......@@ -486,12 +509,34 @@ public class ImplementExecutionOrder {
public static Collection<EMAConnectorInstanceSymbol> getAllConnectorsWithSourceIn(EMAComponentInstanceSymbol inst, Collection<EMAPortInstanceSymbol> sources){
Collection<EMAConnectorInstanceSymbol> result;
List<EMAConnectorInstanceSymbol> result = new ArrayList<>();
if(!instanceConnectorsMap.containsKey(inst)){
getAllConnectors(inst);
}
for(EMAPortInstanceSymbol s : sources){
if(sourcePortConnectorsList.containsKey(s)){
result.addAll(sourcePortConnectorsList.get(s));
}
}
if(!result.isEmpty()) {
Collections.sort(result, (a, b) -> a.getSourcePosition().compareTo(b.getSourcePosition()));
}
// result = getAllConnectors(inst).stream()
// .filter(c -> sources.contains(connectorSourcePort(inst, c)))
// .collect(Collectors.toList());
return getAllConnectors(inst).stream()
.filter(c -> sources.contains(connectorSourcePort(inst, c)))
.collect(Collectors.toList());
// System.out.println(result);
return result;
// //OLD:
// Collection<EMAConnectorInstanceSymbol> result;
//
// return getAllConnectors(inst).stream()
// .filter(c -> sources.contains(connectorSourcePort(inst, c)))
// .collect(Collectors.toList());
}
}
......
......@@ -28,11 +28,11 @@ public class ImplementExecutionOrderTest extends AbstractSymtabTest {
EMAComponentInstanceSymbol inst = symTab.<EMAComponentInstanceSymbol>resolve(
"fas.demo_fas_Fkt_m.velocityControl", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(inst);
System.out.println("Before inst: " + inst);
// System.out.println("Before inst: " + inst);
List<EMAComponentInstanceSymbol> exOrder = ImplementExecutionOrder.exOrder(symTab, inst);
System.out.println("After inst: " + inst);
// System.out.println("After inst: " + inst);
assertEquals(13, exOrder.size());
System.out.println(exOrder);
// System.out.println(exOrder);
assertEquals(exOrder.get(0).getName(), "sat1");
assertEquals(symTab.getTags(exOrder.get(0), TagExecutionOrderSymbol.KIND).toString(), "[TagExecutionOrder = 0:0]");
assertEquals(exOrder.get(1).getName(), "look1");
......
......@@ -12,6 +12,8 @@ import org.junit.runners.MethodSorters;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import static org.junit.Assert.assertNotNull;
......@@ -35,8 +37,12 @@ public class DynamicPortConnectDynamicInstanceTest extends AbstractSymtabTest {
}
@Test
@Ignore
public void Test_04_Big() throws IOException {
Instant start = Instant.now();
test("instanceRequest.testBig", "./target/generated-sources-cpp/dynamics/instances/test04");
Instant end = Instant.now();
Log.info("TestBig time: "+Duration.between(start, end), "Test_04_Big");
}
protected void test(String instName, String target){
......
......@@ -2,8 +2,8 @@ package instanceRequest;
dynamic component TestBig{
port
dynamic in B a[0:1024],
dynamic out B b[0:1024];
dynamic in B a[0:128],
dynamic out B b[0:128];
component PassThrough {
ports
......@@ -13,7 +13,7 @@ dynamic component TestBig{
connect in1 -> out1;
}
instance PassThrough pt[0:1024];
instance PassThrough pt[0:256];
@ a::connect && b::connect {
connect a[?] -> pt[?].in1;
......
......@@ -6,13 +6,11 @@ component Not {
out B b,
out B c;
connect false -> c;
@ p.b::value([false, true, false, true]){
instance Bla bla;
connect bla.b -> b;
@ a::value([false, true, false, true]){
connect true -> b;
}
@ a::value(true){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment