Unverified Commit 6570b6cf authored by sschneiders's avatar sschneiders Committed by GitHub
Browse files

Merge pull request #23 from EmbeddedMontiArc/strepkov-model-test

Strepkov model test
parents a0d0a19f 9b31f6cc
......@@ -8,22 +8,22 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.0.4</version>
<version>0.0.6-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.3-SNAPSHOT</monticore.version>
<monticore.version>4.5.4-SNAPSHOT</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<SIUnit.version>0.0.7</SIUnit.version>
<Common-MontiCar.version>0.0.7</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.7</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.7</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.7</Math.version>
<Embedded-MontiArc-Math.version>0.0.7</Embedded-MontiArc-Math.version>
<SIUnit.version>0.0.10-SNAPSHOT</SIUnit.version>
<Common-MontiCar.version>0.0.10-SNAPSHOT</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.10-SNAPSHOT</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.10-SNAPSHOT</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.10-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.10-SNAPSHOT</Embedded-MontiArc-Math.version>
<tagging.version>0.0.1</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......@@ -51,6 +51,12 @@
</properties>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>de.monticore.lang</groupId>
<artifactId>Tagging</artifactId>
......
......@@ -29,6 +29,7 @@ public class Variable {
Optional<String> constantValue = Optional.empty();
List<String> additionalInformation = new ArrayList<>();
List<String> dimensionalInformation = new ArrayList<>();
List<String> properties = new ArrayList<>();
Optional<String> customTypeName = Optional.empty();
public Variable() {
......@@ -206,6 +207,18 @@ public class Variable {
return parameterVariable;
}
public List<String> getProperties() {
return properties;
}
public void addProperties(List<String> properties) {
this.properties.addAll(properties);
}
public void addProperty(String property) {
this.properties.add(property);
}
public void setIsParameterVariable(boolean parameterVariable) {
this.parameterVariable = parameterVariable;
}
......
......@@ -86,6 +86,13 @@ public class ArmadilloHelperSource {
"cx_mat result=sqrtmat(A);\n" +
"return real(result);\n" +
"}\n" +
"static mat invertDiagMatrix(mat A){\n" +
"for(int i=0;i<A.n_rows;++i){\n" +
" double curVal = A(i,i);\n" +
" A(i,i) = 1/curVal;\n" +
"}\n" +
"return A;\n" +
"}\n" +
"};\n" +
"#endif\n";
}
......@@ -12,10 +12,8 @@ import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
......@@ -134,6 +132,7 @@ public class GeneratorCPP implements Generator {
return fileContents;
}
//TODO add incremental generation based on described concept
public List<File> generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol,
Scope symtab) throws IOException {
List<FileContent> fileContents = generateStrings(taggingResolver, componentSymbol, symtab);
......@@ -161,15 +160,26 @@ public class GeneratorCPP implements Generator {
public File generateFile(FileContent fileContent) throws IOException {
File f = new File(getGenerationTargetPath() + fileContent.getFileName());
Log.info(f.getName(), "FileCreation:");
boolean contentEqual = false;
//Actually slower than just saving and overwriting the file
/*if (f.exists()) {
String storedFileContent = new String(Files.readAllBytes(f.toPath()));
if (storedFileContent.equals(fileContent.getFileContent())) {
contentEqual = true;
}
} else*/
if (!f.exists()) {
f.getParentFile().mkdirs();
if (!f.createNewFile()) {
Log.error("File could not be created");
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(f));
bufferedWriter.write(fileContent.getFileContent(), 0, fileContent.getFileContent().length());
bufferedWriter.close();
if (!contentEqual) {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(f));
bufferedWriter.write(fileContent.getFileContent(), 0, fileContent.getFileContent().length());
bufferedWriter.close();
}
return f;
}
......
......@@ -23,6 +23,7 @@ public class MathCommandRegisterCPP extends MathCommandRegister {
registerMathCommand(new MathEigvecCommand());
registerMathCommand(new MathGcdCommand());
registerMathCommand(new MathInvCommand());
registerMathCommand(new MathInvDiagCommand());
registerMathCommand(new MathAbsCommand());
registerMathCommand(new MathAcosCommand());
registerMathCommand(new MathAcoshCommand());
......
......@@ -17,7 +17,9 @@ import de.se_rwth.commons.logging.Log;
public class MathFunctionFixer {
public static void fixMathFunctions(MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
boolean notHandled = true;
if (mathExpressionSymbol.isAssignmentExpression()) {
if (mathExpressionSymbol == null) {
notHandled = false;
} else if (mathExpressionSymbol.isAssignmentExpression()) {
fixMathFunctions((MathAssignmentExpressionSymbol) mathExpressionSymbol, bluePrintCPP);
notHandled = false;
} else if (mathExpressionSymbol.isMatrixExpression()) {
......@@ -156,8 +158,8 @@ public class MathFunctionFixer {
} else {
MathCommand mathCommand = bluePrintCPP.getMathCommandRegister().getMathCommand(mathExpressionSymbol.getNameToAccess());
if (mathCommand != null) {
if(MathConverter.curBackend.getBackendName().equals("OctaveBackend"))
bluePrintCPP.addAdditionalIncludeString("Helper");
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend"))
bluePrintCPP.addAdditionalIncludeString("Helper");
mathCommand.convert(mathExpressionSymbol, bluePrintCPP);
}
if (fixForLoopAccess(mathExpressionSymbol, variable, bluePrintCPP)) {
......
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.stream._symboltable.NamedStreamSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.streamunits._ast.ASTComponentStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTNamedStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTPrecisionNumber;
import de.monticore.lang.monticar.streamunits._ast.ASTStreamInstruction;
import de.monticore.lang.monticar.streamunits._symboltable.ComponentStreamUnitsSymbol;
import de.monticore.lang.monticar.streamunits._symboltable.NamedStreamUnitsSymbol;
/**
* @author Sascha Schneiders
......
......@@ -22,9 +22,9 @@ import de.monticore.lang.monticar.streamunits._ast.ASTStreamValue;
import de.monticore.lang.monticar.streamunits._symboltable.ComponentStreamUnitsSymbol;
import de.monticore.lang.monticar.streamunits._symboltable.NamedStreamUnitsSymbol;
import de.monticore.lang.monticar.streamunits._visitor.StreamUnitsVisitor;
import de.monticore.lang.numberunit._ast.ASTUnitNumber;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import siunit.monticoresiunit.si._ast.ASTUnitNumber;
import java.io.InputStream;
import java.util.ArrayList;
......
package de.monticore.lang.monticar.generator.cpp.commands;
import de.monticore.lang.math.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.OctaveHelper;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sascha Schneiders
*/
public class MathInvDiagCommand extends MathCommand {
public MathInvDiagCommand() {
setMathCommandName("invdiag");
}
@Override
public void convert(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
String backendName = MathConverter.curBackend.getBackendName();
if (backendName.equals("OctaveBackend")) {
//convertUsingOctaveBackend(mathExpressionSymbol, bluePrint);
Log.error("OctaveBackend does not support command invdiag yet");
} else if (backendName.equals("ArmadilloBackend")) {
convertUsingArmadilloBackend(mathExpressionSymbol, bluePrint);
}
}
public void convertUsingOctaveBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
//OctaveHelper.getCallOctaveFunction(mathExpressionSymbol, "sum","Double", valueListString));
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression(OctaveHelper.getCallBuiltInFunction(mathExpressionSymbol, "Finv", "Matrix", valueListString, "FirstResult", false, 1));
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
((BluePrintCPP) bluePrint).addAdditionalIncludeString("octave/builtin-defun-decls");
}
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
//OctaveHelper.getCallOctaveFunction(mathExpressionSymbol, "sum","Double", valueListString));
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("HelperA::invertDiagMatrix"+valueListString);
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
((BluePrintCPP) bluePrint).addAdditionalIncludeString("HelperA");
}
}
......@@ -66,7 +66,7 @@ public class ComponentConverter {
public static void addVariables(ExpandedComponentInstanceSymbol componentSymbol, BluePrintCPP bluePrint) {
//add parameters as variables
for (EMAVariable variable : componentSymbol.getParameters()) {
System.out.println("EMAVAR: " + variable.getName() + " " + variable.getType().toString());
Log.debug("EMAVAR: " + variable.getName() + " " + variable.getType().toString(), "ComponentConverter");
Variable var = new Variable();
var.setName(variable.getName());
var.setTypeNameMontiCar(variable.getType());
......@@ -106,7 +106,7 @@ public class ComponentConverter {
for (ExpandedComponentInstanceSymbol subComponent : componentSymbol.getSubComponents()) {
String parameterString = "";
for (ASTExpression var : subComponent.getArguments()) {
System.out.println(var.toString());
Log.debug(var.toString(),"ComponentConverter");
parameterString += getExpressionParameterConversion(var);
}
String result = "";
......
......@@ -23,6 +23,8 @@ import java.util.List;
* @author Sascha Schneiders
*/
public class ComponentConverterMethodGeneration {
public static int currentGenerationIndex = 0;
public static void generateExecuteMethod(ExpandedComponentInstanceSymbol componentSymbol, BluePrintCPP bluePrint, MathStatementsSymbol mathStatementsSymbol, GeneratorCPP generatorCPP, List<String> includeStrings) {
Method method = new Method("execute", "void");
......@@ -60,25 +62,57 @@ public class ComponentConverterMethodGeneration {
}
}
if (mathStatementsSymbol != null) {
// add math implementation instructions to method
List<MathExpressionSymbol> newMathExpressionSymbols = new ArrayList<>();
MathOptimizer.currentBluePrint = bluePrint;
int counter = 0;
handleMathStatementGeneration(method, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
}
bluePrint.addMethod(method);
}
private static List<MathExpressionSymbol> visitedMathExpressionSymbols = new ArrayList<>();
private static boolean swapNextInstructions = false;
for (MathExpressionSymbol mathExpressionSymbol : mathStatementsSymbol.getMathExpressionSymbols()) {
private static void handleMathStatementGeneration(Method method, BluePrintCPP bluePrint, MathStatementsSymbol mathStatementsSymbol, GeneratorCPP generatorCPP, List<String> includeStrings) {
// add math implementation instructions to method
List<MathExpressionSymbol> newMathExpressionSymbols = new ArrayList<>();
MathOptimizer.currentBluePrint = bluePrint;
int counter = 0;
visitedMathExpressionSymbols.clear();
//int lastIndex = 0;
for (currentGenerationIndex = 0; currentGenerationIndex < mathStatementsSymbol.getMathExpressionSymbols().size(); ++currentGenerationIndex) {
int beginIndex = currentGenerationIndex;
MathExpressionSymbol mathExpressionSymbol = mathStatementsSymbol.getMathExpressionSymbols().get(currentGenerationIndex);
if (!visitedMathExpressionSymbols.contains(mathExpressionSymbol)) {
if (generatorCPP.useAlgebraicOptimizations()) {
List<MathExpressionSymbol> precedingExpressions = new ArrayList<>();
for (int i = 0; i < counter; ++i)
precedingExpressions.add(mathStatementsSymbol.getMathExpressionSymbols().get(i));
newMathExpressionSymbols.add(MathOptimizer.applyOptimizations(mathExpressionSymbol, precedingExpressions));
if (mathExpressionSymbol != visitedMathExpressionSymbols)
newMathExpressionSymbols.add(MathOptimizer.applyOptimizations(mathExpressionSymbol, precedingExpressions, mathStatementsSymbol));
++counter;
}
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrint);
String result = ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, includeStrings);
TargetCodeMathInstruction instruction = new TargetCodeMathInstruction(result, mathExpressionSymbol);
method.addInstruction(instruction);
generateInstruction(method, mathExpressionSymbol, bluePrint, includeStrings);
//lastIndex = currentGenerationIndex;
}
handleInstructionReOrdering(method, beginIndex);
}
bluePrint.addMethod(method);
}
private static void generateInstruction(Method method, MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrint, List<String> includeStrings/*, int lastIndex*/) {
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrint);
String result = ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, includeStrings);
TargetCodeMathInstruction instruction = new TargetCodeMathInstruction(result, mathExpressionSymbol);
method.addInstruction(instruction);
visitedMathExpressionSymbols.add(mathExpressionSymbol);
//Log.debug("lastIndex: " + lastIndex + " current: " + currentGenerationIndex, "ComponentConverterMethodGeneration");
}
private static void handleInstructionReOrdering(Method method, int beginIndex) {
if (swapNextInstructions) {
swapNextInstructions = false;
//Log.error("ad");
Instruction lastInstruction = method.getInstructions().get(currentGenerationIndex);
method.getInstructions().remove(currentGenerationIndex);
method.addInstruction(lastInstruction);
}
if (beginIndex != currentGenerationIndex) swapNextInstructions = true;
}
}
......@@ -23,7 +23,9 @@ public class ExecuteMethodGenerator {
/*if (mathExpressionSymbol.isAssignmentDeclarationExpression()) {
return generateExecuteCode((MathValueSymbol) mathExpressionSymbol, includeStrings);
} */
if (mathExpressionSymbol.isAssignmentExpression()) {
if (mathExpressionSymbol == null) {
} else if (mathExpressionSymbol.isAssignmentExpression()) {
result = ExecuteMethodGeneratorHandler.generateExecuteCode((MathAssignmentExpressionSymbol) mathExpressionSymbol, includeStrings);
} else if (mathExpressionSymbol.isCompareExpression()) {
result = ExecuteMethodGeneratorHandler.generateExecuteCode((MathCompareExpressionSymbol) mathExpressionSymbol, includeStrings);
......
......@@ -8,8 +8,8 @@ import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.OctaveBackend;
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import de.monticore.lang.numberunit._ast.ASTUnitNumber;
import de.se_rwth.commons.logging.Log;
import siunit.monticoresiunit.si._ast.ASTUnitNumber;
/**
* @author Sascha Schneiders
......@@ -65,10 +65,10 @@ public class MathConverter {
String result = "";
int column = 0;
for (MathMatrixAccessOperatorSymbol symbol : mathExpressionSymbol.getVectors()) {
System.out.println(symbol.getTextualRepresentation());
Log.debug(symbol.getTextualRepresentation(),"Symbol:");
int row = 0;
for (MathMatrixAccessSymbol symbolAccess : symbol.getMathMatrixAccessSymbols()) {
System.out.println(symbolAccess.getTextualRepresentation());
Log.debug("symbolAccess: "+symbolAccess.getTextualRepresentation(),"MathConverter");
result += matrixName + "(" + column + "," + row + ") = ";
result += symbolAccess.getTextualRepresentation();
result += ";\n";
......
......@@ -3,8 +3,14 @@ package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConstantPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.math.math._ast.ASTAssignmentType;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import de.monticore.lang.monticar.types2._ast.ASTType;
import de.se_rwth.commons.logging.Log;
import javax.sound.sampled.Port;
/**
* @author Sascha Schneiders
......@@ -42,48 +48,59 @@ public class PortConverter {
if (variable != null&&variable.isArray())
return variable;
*/
Variable variable = new Variable();
String name = "";
String typeNameMontiCar = portSymbol.getTypeReference().getName();
addVariableProperties(portSymbol, variable);
handlePortDirection(portSymbol, variable);
name += handlePortName(portSymbol, variable, connectName);
if (portSymbol.isIncoming())
variable.setName(name);
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
bluePrint.getMathInformationRegister().addVariable(variable);
{
variable.setInputVariable(true);
} else
return variable;
}
{
private static void handlePortDirection(PortSymbol portSymbol, Variable variable) {
if (portSymbol.isIncoming()) {
variable.setInputVariable(true);
} else {
variable.setInputVariable(false);
}
if (portSymbol.isConstant())
}
{
private static String handlePortName(PortSymbol portSymbol, Variable variable, String connectName) {
String name = "";
if (portSymbol.isConstant()) {
//name += "Constant" + ++counterConstantPorts;
name += connectName;
variable.setIsConstantVariable(true);
variable.setConstantValue(((ConstantPortSymbol) portSymbol).getConstantValue().getValueAsString());
// Log.error("0xCOPOSHNOBECRASAAVA Constant Port should not be created as a variable");
} else
{
} else {
//Log.info(portSymbol.getName(),"PORTNAME:");
name += connectName;
}
variable.setName(name);
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
bluePrint.getMathInformationRegister().addVariable(variable);
return variable;
return name;
}
private static void addVariableProperties(PortSymbol portSymbol, Variable variable) {
if (portSymbol.getTypeReference().getReferencedSymbol() instanceof MCASTTypeSymbolReference) {
MCASTTypeSymbolReference typeSymbolReference = (MCASTTypeSymbolReference) portSymbol.getTypeReference().getReferencedSymbol();
ASTType astType = typeSymbolReference.getAstType();
if (astType instanceof ASTAssignmentType) {
ASTAssignmentType astAssignmentType = (ASTAssignmentType) astType;
//if (astAssignmentType.getMatrixProperty().size() > 0) Log.error(astType.toString());
variable.addProperties(astAssignmentType.getMatrixProperty());
}
}
}
public static String getPortNameWithoutArrayBracketPart(String name) {
String nameWithOutArrayBracketPart = name;
......
package de.monticore.lang.monticar.generator.optimization;
import de.monticore.lang.math.math._symboltable.MathAssignmentOperator;
import de.monticore.lang.math.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.math.math._symboltable.expression.MathArithmeticExpressionSymbol;
import de.monticore.lang.math.math._symboltable.expression.MathAssignmentExpressionSymbol;
import de.monticore.lang.math.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math.math._symboltable.expression.MathNameExpressionSymbol;
import de.monticore.lang.math.math._symboltable.matrix.MathMatrixExpressionSymbol;
import de.monticore.lang.math.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverterMethodGeneration;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Sascha Schneiders
*/
public class MathAssignmentPartResultReuse implements MathOptimizationRule {
MathStatementsSymbol currentMathStatementsSymbol = null;
List<MathExpressionSymbol> encounteredSymbolInstances = new ArrayList<>();
Map<MathExpressionSymbol, String> symbolMap = new HashMap();
int currentId = 0;
MathExpressionSymbol startMathExpressionSymbol = null;
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
if (mathExpressionSymbol == null) {
} else if (mathExpressionSymbol.isAssignmentExpression()) {
optimize((MathAssignmentExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else if (mathExpressionSymbol.isArithmeticExpression()) {
optimize((MathArithmeticExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else if (mathExpressionSymbol.isMatrixExpression()) {
optimize((MathMatrixExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else {
Log.debug(mathExpressionSymbol.getClass().getName() + " " + mathExpressionSymbol.getTextualRepresentation(), "Symbol not handled");
}
}
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions, MathStatementsSymbol mathStatementsSymbol) {
currentMathStatementsSymbol = mathStatementsSymbol;
encounteredSymbolInstances.clear();
symbolMap.clear();
startMathExpressionSymbol = mathExpressionSymbol;
optimize(mathExpressionSymbol, precedingExpressions);
}
public void optimize(MathAssignmentExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
optimize(mathExpressionSymbol.getExpressionSymbol(), precedingExpressions);
}
public void optimize(MathArithmeticExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {