Commit 8e33c348 authored by Nils Kaminski's avatar Nils Kaminski
Browse files

Fix resolving dynamic instance (port) and condition for execute

parent 030981dc
Pipeline #81493 failed
......@@ -11,6 +11,7 @@ public class ExecuteInstruction implements Instruction {
BluePrint bluePrint;
String threadName = null;
boolean canBeThreaded = false;
boolean dynamic = false;
public static int threadCounter = 0;
public ExecuteInstruction(String componentName, BluePrint bluePrint, boolean canBeThreaded) {
......@@ -57,6 +58,12 @@ public class ExecuteInstruction implements Instruction {
return result;
}
if(dynamic){
return String.format("if(true){ executeDynamicConnects(&%s); %s.execute();}\n",
componentName, componentName);
}
return componentName + ".execute();\n";
}
......@@ -69,4 +76,12 @@ public class ExecuteInstruction implements Instruction {
public boolean isExecuteInstruction() {
return true;
}
public boolean isDynamic() {
return dynamic;
}
public void setDynamic(boolean dynamic) {
this.dynamic = dynamic;
}
}
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.ConnectInstruction;
import de.monticore.lang.monticar.generator.ExecuteInstruction;
import de.monticore.lang.monticar.generator.Instruction;
......@@ -60,6 +61,10 @@ public class ExecutionOrderFixer {
for (EMAComponentInstanceSymbol subComponent : instanceSymbol.getSubComponents()) {
if (!listContainsExecuteInstruction(newList, subComponent.getName())) {
ExecuteInstruction executeInstruction = (ExecuteInstruction) getExecuteInstruction(subComponent.getName(), bluePrintCPP, threadableComponents, generatorCPP);
if(subComponent instanceof EMADynamicComponentInstanceSymbol) {
executeInstruction.setDynamic(((EMADynamicComponentInstanceSymbol) subComponent).isDynamicInstance());
}
int insertionIndex = getIndexOfLastConnectInstruction(newList, subComponent.getName());
newList.add(insertionIndex, executeInstruction);
}
......@@ -98,7 +103,8 @@ public class ExecutionOrderFixer {
}
String name = GeneralHelperMethods.getTargetLanguageComponentName(nameToAdd);
Log.info(name, "Adding ExecuteInstruction:");
return new ExecuteInstruction(name, bluePrintCPP, canBeThreaded);
ExecuteInstruction exI = new ExecuteInstruction(name, bluePrintCPP, canBeThreaded);
return exI;
}
public static Instruction getExecuteInstruction(EMAComponentInstanceSymbol componentInstanceSymbol, BluePrintCPP bluePrintCPP, List<EMAComponentInstanceSymbol> threadableComponents) {
......
......@@ -27,6 +27,8 @@ public class EventDynamicConnectConverter {
event.getCondition().getConnectPortNames(names);
java.util.Collections.sort(names);
List<String> newInstances = getNewInstances(event);
Map<String,List<String>> newPortsInstances = getNewPortsOfInstances(event);
generateConnectMethod(names, componentSymbol, bluePrint);
......@@ -96,6 +98,22 @@ public class EventDynamicConnectConverter {
dynamic.get().addInstruction(new TargetCodeInstruction(eventBodyName+"();\n"));
}
protected static List<String> getNewInstances(EMADynamicEventHandlerInstanceSymbol event){
Set<String> insts = new HashSet<>();
for(EMADynamicConnectorInstanceSymbol connector : event.getConnectorsDynamic()){
Optional<String> comp = connector.getSourceComponentName();
if(connector.isDynamicSourceNewComponent() && comp.isPresent()){
insts.add(EMAPortSymbol.getNameWithoutArrayBracketPart(comp.get()));
}
comp = connector.getTargetComponentName();
if(connector.isDynamicTargetNewComponent() && comp.isPresent()){
insts.add(EMAPortSymbol.getNameWithoutArrayBracketPart(comp.get()));
}
}
return new ArrayList<>(insts);
}
protected static Map<String, List<String>> getNewPortsOfInstances(EMADynamicEventHandlerInstanceSymbol event){
Map<String,List<String>> newPorts = new HashMap<>();
for(EMADynamicConnectorInstanceSymbol connector : event.getConnectorsDynamic()){
......@@ -157,7 +175,6 @@ public class EventDynamicConnectConverter {
}
}
protected static void generateConnects(EMADynamicEventHandlerInstanceSymbol event, Method body, BluePrintCPP bluePrint, Method executeMethod){
for(EMADynamicConnectorInstanceSymbol connector : event.getConnectorsDynamic()){
......@@ -230,7 +247,6 @@ public class EventDynamicConnectConverter {
}
}
protected static String generateConnectNameForNewPort(String allName, Optional<String> componenName, String portName){
String result = "";
if(componenName.isPresent()){
......@@ -245,7 +261,6 @@ public class EventDynamicConnectConverter {
return result;
}
protected static String convertName(String name){
return name.replace("[", "_").replace("]", "_");
}
......
......@@ -347,7 +347,7 @@ public class ImplementExecutionOrder {
Iterator<String> parts = Splitters.DOT.split(c.getSource()).iterator();
Optional<String> instance = Optional.empty();
Optional<String> instancePort;
Optional<EMAPortInstanceSymbol> port;
Optional<EMAPortInstanceSymbol> port = Optional.empty();
if (parts.hasNext()) {
instance = Optional.of(parts.next());
}
......@@ -355,8 +355,14 @@ public class ImplementExecutionOrder {
instancePort = Optional.of(parts.next());
instance = Optional.of(Names.FirstLowerCase(instance.get()));
EMAComponentInstanceSymbol inst2 = inst.getSubComponent(instance.get()).get();
port = inst2.getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
// Old:
// EMAComponentInstanceSymbol inst2 = inst.getSubComponent(instance.get()).get();
// port = inst2.getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
Optional<EMAComponentInstanceSymbol> inst2 = inst.getSubComponent(instance.get());
if(inst2.isPresent()) {
port = inst2.get().getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
}
} else {
instancePort = instance;
......@@ -387,7 +393,7 @@ public class ImplementExecutionOrder {
Iterator<String> parts = Splitters.DOT.split(c.getTarget()).iterator();
Optional<String> instance = Optional.empty();
Optional<String> instancePort;
Optional<EMAPortInstanceSymbol> port;
Optional<EMAPortInstanceSymbol> port = Optional.empty();
if (parts.hasNext()) {
instance = Optional.of(parts.next());
}
......@@ -398,8 +404,14 @@ public class ImplementExecutionOrder {
for(ExpandedComponentInstanceSymbol symbol:inst.getSubComponents()){
Log.info(symbol.toString(),"found:");
}*/
EMAComponentInstanceSymbol inst2 = inst.getSubComponent(instance.get()).get();
port = inst2.getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
//Old:
// EMAComponentInstanceSymbol inst2 = inst.getSubComponent(instance.get()).get();
// port = inst2.getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
Optional<EMAComponentInstanceSymbol> inst2 = inst.getSubComponent(instance.get());
if(inst2.isPresent()) {
port = inst2.get().getSpannedScope().<EMAPortInstanceSymbol>resolve(instancePort.get(), EMAPortInstanceSymbol.KIND);
}
} else {
instancePort = instance;
......
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