Commit 1a23c777 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'FixDynamics' into 'master'

Fix dynamics

See merge request !52
parents 156ed959 f45bbd06
Pipeline #422049 failed with stage
in 12 minutes and 24 seconds
......@@ -85,6 +85,10 @@ public class Method {
instructions.add(instruction);
}
public void addInstruction(int index, Instruction instruction) {
instructions.add(index, instruction);
}
public void addInstructions(List<Instruction> instructions) {
this.instructions.addAll(instructions);
}
......
......@@ -161,9 +161,25 @@ public class ComponentConverter {
bluePrint.addMethod(update);
}
addOthersToExecuteMethod(bluePrint);
return bluePrint;
}
private static void addOthersToExecuteMethod(EMAMBluePrintCPP bluePrint) {
Optional<Method> executeOpt = bluePrint.getMethod("execute");
if (executeOpt.isPresent()) {
Method exMethod = executeOpt.get();
if (bluePrint.getMethod("next").isPresent()) {
exMethod.addInstruction(0, new TargetCodeInstruction("next();\n"));
}
if (bluePrint.getMethod("dynamic").isPresent()) {
exMethod.addInstruction(0, new TargetCodeInstruction("dynamic();\n"));
}
}
}
public static void addVariables(EMAComponentInstanceSymbol componentSymbol, EMAMBluePrintCPP bluePrint) {
//add parameters as variables
for (EMAVariable variable : componentSymbol.getParameters()) {
......
......@@ -13,6 +13,7 @@ import de.monticore.lang.monticar.generator.cpp.GeneralHelperMethods;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.instruction.ExecuteDynamicConnects;
import de.monticore.lang.monticar.generator.cpp.loopSolver.CPPEquationSystemHelper;
import de.monticore.lang.monticar.generator.cpp.loopSolver.EquationSystemComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.loopSolver.RHSComponentInstanceSymbol;
......@@ -88,6 +89,9 @@ public class ComponentConverterMethodGeneration {
} else
generateExecuteMethodInner(exMethod, componentSymbol, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
// Add other instructions
fixExecuteDynamicConnects(exMethod);
// rearrange execute to be last
bluePrint.getMethods().remove(exMethod);
bluePrint.addMethod(exMethod);
......@@ -95,6 +99,27 @@ public class ComponentConverterMethodGeneration {
return exMethod;
}
private static void fixExecuteDynamicConnects(Method exMethod) {
List<Instruction> instructions = exMethod.getInstructions();
List<Integer> idx = new ArrayList<>();
for(int i = 1; i < instructions.size(); ++i){
if((instructions.get(i-1) instanceof ExecuteDynamicConnects) && (instructions.get(i) instanceof ExecuteDynamicConnects)){
ExecuteDynamicConnects a = (ExecuteDynamicConnects) instructions.get(i-1);
ExecuteDynamicConnects b = (ExecuteDynamicConnects) instructions.get(i);
if(a.getBeforeComponentName().equals(b.getBeforeComponentName())){
idx.add(i);
}
}
}
Collections.sort(idx, Collections.reverseOrder());
for(int i : idx){
instructions.remove(i);
}
exMethod.setInstructions(instructions);
}
private static void generateExecuteForRHSComponent(RHSComponentInstanceSymbol componentSymbol, EMAMBluePrintCPP bluePrint, GeneratorCPP generatorCPP, List<String> includeStrings, Method exMethod) {
SemiExplicitForm semiExplicitForm = componentSymbol.getSemiExplicitForm();
addRHSOutputCalls(componentSymbol, exMethod, bluePrint, generatorCPP);
......
Markdown is supported
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