Commit 6a310ed6 authored by Alexander Ryndin's avatar Alexander Ryndin
Browse files

fixed instructions order

parent b3ae842a
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.ConnectInstruction;
import de.monticore.lang.monticar.generator.ExecuteInstruction;
import de.monticore.lang.monticar.generator.Instruction;
import de.monticore.lang.monticar.generator.Method;
import de.monticore.lang.monticar.generator.TargetCodeInstruction;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.order.ImplementExecutionOrder;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......@@ -46,24 +50,10 @@ public class ExecutionOrderFixer {
for (ExpandedComponentInstanceSymbol subComponent : instanceSymbol.getSubComponents()) {
if (!listContainsExecuteInstruction(newList, subComponent.getName())) {
ExecuteInstruction executeInstruction = (ExecuteInstruction) getExecuteInstruction(subComponent.getName(), bluePrintCPP, threadableComponents, generatorCPP);
newList.add(executeInstruction);
int insertionIndex = getIndexOfLastConnectInstruction(newList, subComponent.getName());
newList.add(insertionIndex, executeInstruction);
}
}
/*int lastDotIndex = instanceSymbol.getFullName().lastIndexOf(".");
if (lastDotIndex != -1) {
String name = instanceSymbol.getFullName().substring(0, lastDotIndex);
//Log.info(name,"Trying to fix name:");
if (parentSymbol.isSubComponent(name)) {
//Log.info(name,"IsSubcomponent ExecuteInstruction:");
String nameToAdd;
if (!listContainsExecuteInstruction(newList, name)) {
//Log.info(name,"Added additional ExecuteInstruction:");
newList.add(getExecuteInstruction(name));
}
}
}*/
}
public static boolean listContainsExecuteInstruction(List<Instruction> list, String name) {
......@@ -150,4 +140,18 @@ public class ExecutionOrderFixer {
}
return newList;
}
private static int getIndexOfLastConnectInstruction(List<Instruction> instructions, String componentInstanceName) {
int result = -1;
for (int i = 0, len = instructions.size(); i < len; i++) {
Instruction instr = instructions.get(i);
if (instr.isConnectInstruction()) {
Variable lhs = ((ConnectInstruction) instr).getVariable1();
if (lhs.getName().startsWith(componentInstanceName) && i > result) {
result = i;
}
}
}
return result + 1;
}
}
......@@ -25,6 +25,11 @@ public class GeneratorCppCliTest extends AbstractSymtabTest {
generateAndCompareMyComponentX(9);
}
@Test
public void testInstructionsOrder3() throws IOException {
generateAndCompareMyComponentX(10);
}
private void generateAndCompareMyComponentX(int x) throws IOException {
generateAndCompare(
String.format("testing.subpackage%1$s.myComponent%1$s", x),
......
......@@ -24,8 +24,8 @@ spectralClusterer[1].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[1].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -24,8 +24,8 @@ spectralClusterer[1].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[1].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -25,8 +25,8 @@ spectralClusterer[1].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
thread1.join();
thread2.join();
......
......@@ -25,8 +25,8 @@ spectralClusterer[1].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
thread1.join();
thread2.join();
......
......@@ -28,10 +28,10 @@ spectralClusterer[2].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -28,10 +28,10 @@ spectralClusterer[2].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -29,10 +29,10 @@ spectralClusterer[2].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
thread1.join();
thread2.join();
......
......@@ -29,10 +29,10 @@ spectralClusterer[2].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgBack;
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgBack;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
thread1.join();
thread2.join();
......
......@@ -32,12 +32,12 @@ spectralClusterer[3].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -32,12 +32,12 @@ spectralClusterer[3].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -33,12 +33,12 @@ spectralClusterer[3].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgRight;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread4( [ this ] {this->spectralClusterer[3].execute();});
thread1.join();
thread2.join();
......
......@@ -33,12 +33,12 @@ spectralClusterer[3].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgRight;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread4( [ this ] {this->spectralClusterer[3].execute();});
thread1.join();
thread2.join();
......
......@@ -36,14 +36,14 @@ spectralClusterer[4].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[4].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -36,14 +36,14 @@ spectralClusterer[4].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[4].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -37,14 +37,14 @@ spectralClusterer[4].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgRight;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread4( [ this ] {this->spectralClusterer[3].execute();});
spectralClusterer[4].imgMatrix = imgFront2;
std::thread thread5( [ this ] {this->spectralClusterer[4].execute();});
thread1.join();
thread2.join();
......
......@@ -37,14 +37,14 @@ spectralClusterer[4].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
std::thread thread1( [ this ] {this->spectralClusterer[0].execute();});
spectralClusterer[1].imgMatrix = imgRight;
std::thread thread2( [ this ] {this->spectralClusterer[1].execute();});
spectralClusterer[2].imgMatrix = imgLeft;
std::thread thread3( [ this ] {this->spectralClusterer[2].execute();});
spectralClusterer[3].imgMatrix = imgBack;
std::thread thread4( [ this ] {this->spectralClusterer[3].execute();});
spectralClusterer[4].imgMatrix = imgFront2;
std::thread thread5( [ this ] {this->spectralClusterer[4].execute();});
thread1.join();
thread2.join();
......
......@@ -40,16 +40,16 @@ spectralClusterer[5].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[5].imgMatrix = imgBack2;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[4].execute();
spectralClusterer[5].imgMatrix = imgBack2;
spectralClusterer[5].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
......@@ -40,16 +40,16 @@ spectralClusterer[5].init();
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[5].imgMatrix = imgBack2;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
spectralClusterer[4].imgMatrix = imgFront2;
spectralClusterer[4].execute();
spectralClusterer[5].imgMatrix = imgBack2;
spectralClusterer[5].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
......
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