Commit 2c6454b8 authored by Christoph Richter's avatar Christoph Richter
Browse files

Enhanced substitution of variables

parent c5486ebe
Pipeline #65077 failed with stage
in 23 seconds
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.optimization;
import de.monticore.lang.math._symboltable.expression.*;
import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessOperatorSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.Variable;
......@@ -258,11 +259,43 @@ public class MathInformationRegister {
targetExpr.setMathMatrixAccessOperatorSymbol(targetAccessOperator);
result = targetExpr;
} else {
result = nonAtomarExpression;
// try to resolve access
MathExpressionSymbol accessOperator = resolveMathExpressionToAtomarExpression(sourceExpr.getMathMatrixAccessOperatorSymbol(), atomarValueName);
targetExpr = sourceExpr;
targetExpr.setMathMatrixAccessOperatorSymbol((MathMatrixAccessOperatorSymbol) accessOperator);
result = targetExpr;
}
} else if (nonAtomarExpression instanceof IMathNamedExpression) {
// substitute value expr by assigned expr
result = getSubstituteByName(((IMathNamedExpression) nonAtomarExpression).getNameToAccess(), nonAtomarExpression, atomarValueName);
} else if (nonAtomarExpression instanceof MathMatrixAccessOperatorSymbol) {
MathMatrixAccessOperatorSymbol sourceExpr = (MathMatrixAccessOperatorSymbol) nonAtomarExpression;
MathMatrixAccessOperatorSymbol targetExpression = new MathMatrixAccessOperatorSymbol();
targetExpression.setMathMatrixAccessSymbols(new ArrayList<>());
boolean hasResult = true;
for (int i = 0; i < sourceExpr.getMathMatrixAccessSymbols().size(); i++) {
MathMatrixAccessSymbol newAccess;
if (sourceExpr.getMathMatrixAccessSymbol(i).isPresent()) {
MathExpressionSymbol newAccessExpr = resolveMathExpressionToAtomarExpression(sourceExpr.getMathMatrixAccessSymbol(i).get(), atomarValueName);
newAccess = new MathMatrixAccessSymbol();
newAccess.setMathExpressionSymbol(newAccessExpr);
} else {
newAccess = null;
hasResult = false;
break;
}
targetExpression.addMathMatrixAccessSymbol(newAccess);
}
if (!hasResult)
result = sourceExpr;
else
result = targetExpression;
} else if (nonAtomarExpression instanceof MathMatrixAccessSymbol) {
MathMatrixAccessSymbol source = (MathMatrixAccessSymbol) nonAtomarExpression;
MathMatrixAccessSymbol target = new MathMatrixAccessSymbol();
MathExpressionSymbol mathExpr = resolveMathExpressionToAtomarExpression(source.getMathExpressionSymbol().get(), atomarValueName);
target.setMathExpressionSymbol(mathExpr);
result = target;
} else {
result = nonAtomarExpression;
}
......
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