Commit d3a600d6 authored by Nils Kaminski's avatar Nils Kaminski
Browse files

correct execution order for dynamic connect(s) with new components

parent 30aee062
......@@ -54,7 +54,7 @@ public class ExecuteInstruction implements Instruction {
String inst = componentName.substring(0, componentName.indexOf("["));
String id = componentName.substring(componentName.indexOf("[")+1, componentName.lastIndexOf("]"));
return String.format("if(_%s_connected[%s]){%s}", inst, id, exec);
return String.format("if(_%s_connected[%s]){ executeDynamicConnects(&(%s)); %s}", inst, id,componentName, exec);
}
return exec;
......
......@@ -167,8 +167,12 @@ public class ExecutionOrderFixer {
boolean add = bluePrintCPP.getOriginalSymbol().isSubComponent(instanceSymbol.getFullName());
if (add) {
ExecuteInstruction executeInstruction = (ExecuteInstruction) getExecuteInstruction(instanceSymbol, bluePrintCPP, threadableSubComponents);
if (!newList.contains(executeInstruction))
if (!newList.contains(executeInstruction)) {
if(instanceSymbol instanceof EMADynamicComponentInstanceSymbol){
executeInstruction.setDynamic(((EMADynamicComponentInstanceSymbol) instanceSymbol).isDynamicInstance());
}
newList.add(executeInstruction);
}
}
}
for (EMAComponentInstanceSymbol subComponent : bluePrintCPP.getOriginalSymbol().getSubComponents()) {
......@@ -185,7 +189,6 @@ public class ExecutionOrderFixer {
return newList;
}
public static void fixExecuteDynamicConnects(List<Instruction> newList){
List<Integer> idx = new ArrayList<>();
......@@ -207,7 +210,6 @@ public class ExecutionOrderFixer {
}
private static int getIndexOfLastConnectInstruction(List<Instruction> instructions, String componentInstanceName) {
int result = -1;
for (int i = 0, len = instructions.size(); i < len; i++) {
......
......@@ -11,6 +11,7 @@ import de.monticore.lang.monticar.generator.cpp.GeneralHelperMethods;
import de.monticore.lang.monticar.generator.cpp.instruction.EventConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.instruction.ExecuteDynamicConnects;
import de.se_rwth.commons.logging.Log;
import javafx.util.Pair;
import java.util.*;
......@@ -50,6 +51,8 @@ public class EventDynamicConnectConverter {
generateConnects(event, body, bluePrint, executeMethod);
// generateDummyConnects(event, componentSymbol, executeMethod, bluePrint);
body.addInstruction(new TargetCodeInstruction("}\n"));
bluePrint.addMethod(body);
return true;
......@@ -236,7 +239,7 @@ public class EventDynamicConnectConverter {
before = Optional.of("&"+before.get());
}
body.addInstruction(new TargetCodeInstruction(String.format(
"__dynamic_%s_connect.push_back({%s, &%s, &%s});\n", vt.get().getTypeNameTargetLanguage(), before.get(), sourceName, targetName
"__dynamic_%s_connect.push_back({%s, &(%s), &(%s)});\n", vt.get().getTypeNameTargetLanguage(), before.get(), sourceName, targetName
)));
......@@ -290,10 +293,11 @@ public class EventDynamicConnectConverter {
String inst = EMAPortSymbol.getNameWithoutArrayBracketPart(componentName);
return String.format("(%s["+DYNINSTANCEID+"].%s)", inst, inst, GeneralHelperMethods.getTargetLanguageVariableInstanceName(portName));
return String.format("%s["+DYNINSTANCEID+"].%s", inst, inst, GeneralHelperMethods.getTargetLanguageVariableInstanceName(portName));
}
protected static String convertName(String name){
return name.replace("[", "_").replace("]", "_");
}
......
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicPortInstanceSymbol;
......@@ -77,6 +78,28 @@ public class PortConverter {
return variable;
}
public static Variable convertPortNameToVariable(String portName, EMAComponentInstanceSymbol instance, BluePrintCPP bluePrintCPP){
String fullName = portName;
if(portName.contains(".")){
instance = instance.getSubComponent(portName.substring(0, portName.indexOf("."))).orElse(null);
portName = portName.substring(portName.indexOf(".")+1);
}
if(instance == null){
Log.error("Can't find instance for port: "+portName);
return null;
}
Optional<EMAPortInstanceSymbol> port = instance.getPortInstance(portName);
if(!port.isPresent()){
Log.error("Can't find port: "+portName);
return null;
}
return convertPortSymbolToVariable(port.get(), fullName, bluePrintCPP);
}
private static void handlePortDirection(EMAPortInstanceSymbol portSymbol, Variable variable) {
if (portSymbol.isIncoming()) {
variable.setInputVariable(true);
......@@ -153,4 +176,6 @@ public class PortConverter {
}
return nameWithOutArrayBracketPart;
}
}
......@@ -20,6 +20,11 @@ public class DynamicPortConnectDynamicInstanceTest extends AbstractSymtabTest {
test("instanceRequest.test1", "./target/generated-sources-cpp/dynamics/DynamicPortConnectDynamicInstanceTest_Test_00_Test1");
}
@Test
public void Test_02_Test2() throws IOException {
test("instanceRequest.test2", "./target/generated-sources-cpp/dynamics/DynamicPortConnectDynamicInstanceTest_Test_02_Test2");
}
protected void test(String instName, String target){
try {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/dynamics");
......
package instanceRequest;
dynamic component Test2{
port
dynamic in B a[2:6],
dynamic out B b[2:4];
component PassThrough {
ports
in B in1,
out B out1;
connect in1 -> out1;
}
instance PassThrough ptA[2:3];
instance PassThrough ptB[2:4];
instance PassThrough ptC[0:1];
connect a[2] -> ptB[2].in1;
connect ptB[2].out1 -> ptA[2].in1;
connect ptA[2].out1 -> b[2];
connect a[1] -> ptB[1].in1;
connect ptB[1].out1 -> ptA[1].in1;
connect ptA[1].out1 -> b[1];
@ a::connect && b::connect {
connect a[?] -> ptB[?].in1;
connect ptB[?].out1 -> ptA[?].in1;
connect ptA[?].out1 -> b[?];
}
}
\ No newline at end of file
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