Commit 8e2325eb authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

fixed array start indexing bug when multiple expressions are used

parent 9ddb295e
......@@ -78,7 +78,7 @@ public class MathFunctionFixer {
if (mathMatrixExpressionSymbol.isMatrixAccessExpression()) {
if (mathChainedExpression.getSecondExpressionSymbol().getExpressionID() == MathStringExpression.ID) {
MathStringExpression mathStringExpression = (MathStringExpression) mathChainedExpression.getSecondExpressionSymbol();
if (mathStringExpression.getText().equals("-1"))
if (mathStringExpression.getText().contains("-1"))
return;
}
}
......@@ -194,7 +194,9 @@ public class MathFunctionFixer {
if (mathExpressionSymbol.getMathExpressionSymbol().isPresent()) {
fixMathFunctions(mathExpressionSymbol.getMathExpressionSymbol().get(), bluePrintCPP);
MathExpressionSymbol mathExp = mathExpressionSymbol.getMathExpressionSymbol().get();
mathExpressionSymbol.setMathExpressionSymbol(new MathChainedExpression(mathExp, new MathStringExpression("-1")));
//mathExpressionSymbol.setMathExpressionSymbol(mathExp);
if (!(mathExp instanceof MathChainedExpression))
mathExpressionSymbol.setMathExpressionSymbol(new MathChainedExpression(mathExp, new MathStringExpression("-1")));
/*if (mathExp.getExpressionID() != MathChainedExpression.ID && mathExp.getExpressionID() != MathStringExpression.ID) {
mathExpressionSymbol.setMathExpressionSymbol(new MathChainedExpression(mathExp, new MathStringExpression("-1")));
......
......@@ -442,5 +442,17 @@ public class GenerationTest extends AbstractSymtabTest {
testFilesAreEqual(files, restPath);
}
@Test
public void testForLoopIf() throws IOException {
ConstantPortSymbol.resetLastID();
Scope symtab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("testing.forLoopIfInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testing");
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String restPath = "test/";
testFilesAreEqual(files, restPath);
}
}
......@@ -17,6 +17,9 @@ void execute()
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1]*2/1 ;
}
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1]*3/1 ;
}
}
};
......
......@@ -15,7 +15,10 @@ void init()
void execute()
{
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1-1]*2/1 ;
valOut(i) = val1[i-1]*2/1 ;
}
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1]*3/1 ;
}
}
......
......@@ -4,7 +4,8 @@ component BasicGenericArrayInstance{
ports in Q(-oo:oo) val1[6],
out Q(-oo:oo) valOut[6];
instance BasicGenericArraySize<3> basicGenericArraySize1,basicGenericArraySize2;
instance BasicGenericArraySize<3> basicGenericArraySize1;
instance BasicGenericArraySize<3> basicGenericArraySize2;
connect val1[1:3] -> basicGenericArraySize1.val1[:];
connect val1[4:6] -> basicGenericArraySize2.val1[:];
......
......@@ -6,7 +6,11 @@ component BasicGenericArraySize<N1 n=1>{
implementation Math{
for i=1:n
valOut(i) = val1(i) * 2;
valOut(i) = val1(i) * 2;
end
for i=1:n
valOut(i) = val1(i) * 3;
end
}
}
\ No newline at end of file
package testing;
component ForLoopIf<N1 counter>{
ports out Q(-oo:oo) result;
implementation Math{
for i = 1:1:8
result = result + counter;
end
if counter < 0{
result = 0;
}
elseif counter < 100{
result = counter;
}
else{
result = 100;
}
end
}
}
\ No newline at end of file
package testing;
component ForLoopIfInstance{
ports out Q(-oo:oo) result;
instance ForLoopIf forLoopIf;
connect forLoopIf.result -> result;
}
\ No newline at end of file
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