Commit abfd7197 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Refactoring

parent ede6d907
Pipeline #56835 passed with stage
in 2 minutes and 17 seconds
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc.types.EMAVariable;
import de.monticore.lang.math._symboltable.*;
import de.monticore.lang.math._symboltable.expression.*;
import de.monticore.lang.math._symboltable.matrix.*;
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticValueSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixExpressionSymbol;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.*;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.instruction.ConstantConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.symbols.MathChainedExpression;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import de.monticore.lang.monticar.generator.optimization.MathOptimizer;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -173,65 +170,11 @@ public class ComponentConverter {
public static void generateInitNonStaticVariable(Method method, Variable v, BluePrintCPP bluePrint) {
Log.info("v: " + v.getName(), "generateInitNonStaticVariable");
if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getMatrixTypeName())) {
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else
method.addInstruction(new TargetCodeInstruction(MathConverter.getMatrixInitLine(v, bluePrint)));
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getRowVectorTypeName())) {
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else
method.addInstruction(new TargetCodeInstruction(MathConverter.getRowVectorInitLine(v, bluePrint)));
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getColumnVectorTypeName())) {
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else
method.addInstruction(new TargetCodeInstruction(MathConverter.getColumnVectorInitLine(v, bluePrint)));
} else if (v.getVariableType().getTypeNameTargetLanguage().equals("double")) {
//TODO: check backend for typeNameTargetLanguage? and handle additional types here
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + v.getNameTargetLanguageFormat() + " = " + v.getNameTargetLanguageFormat() + ";\n"));
method.addParameter(v);
}
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getCubeTypeName())) {
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else
method.addInstruction(new TargetCodeInstruction(MathConverter.getCubeTypeInitLine(v, bluePrint)));
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberMatrixTypeName())){
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else {
method.addInstruction(new TargetCodeInstruction(MathConverter.getWholeNumberMatrixInitLine(v, bluePrint)));
}
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberRowVectorTypeName())){
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else {
method.addInstruction(new TargetCodeInstruction(MathConverter.getWholeNumberRowVectorInitLine(v, bluePrint)));
}
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberColumnVectorTypeName())){
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else {
method.addInstruction(new TargetCodeInstruction(MathConverter.getWholeNumberColumnVectorInitLine(v, bluePrint)));
}
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberCubeTypeName())){
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
} else {
method.addInstruction(new TargetCodeInstruction(MathConverter.getWholeNumberCubeInitLine(v, bluePrint)));
}
if(v.isParameterVariable()){
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
}else {
method.addInstruction(new TargetCodeInstruction(MathConverter.getInitLine(v,bluePrint)));
}
}
......
......@@ -97,35 +97,19 @@ public class ExecuteMethodGeneratorHandler {
public static String addInitializationString(MathValueSymbol mathValueSymbol, String typeString, List<String> includeStrings) {
ASTElementType type = mathValueSymbol.getType().getType();
String matString;
String colvecString;
String cubeString;
if(type.isRational()){
matString = MathConverter.curBackend.getMatrixTypeName();
colvecString = MathConverter.curBackend.getColumnVectorTypeName();
cubeString = MathConverter.curBackend.getCubeTypeName();
}else if(type.isWholeNumber()){
matString = MathConverter.curBackend.getWholeNumberMatrixTypeName();
colvecString = MathConverter.curBackend.getWholeNumberColumnVectorTypeName();
cubeString = MathConverter.curBackend.getWholeNumberCubeTypeName();
}else{
Log.error("Initialization not handled!");
return "";
}
String result = "";
List<MathExpressionSymbol> dims = mathValueSymbol.getType().getDimensions();
if (dims.size() == 1) {
if (typeString.equals(colvecString)) {
if (typeString.equals(TypeConverter.getColvecAccessString(type))) {
result = "=" + TypeConverter.getDimensionString(TypeConverter.getColvecAccessString(type),dims,includeStrings);
}
} else if (dims.size() == 2) {
if (typeString.equals(matString)) {
if (typeString.equals(TypeConverter.getMatAccessString(type))) {
result = "=" + TypeConverter.getDimensionString(TypeConverter.getMatAccessString(type),dims,includeStrings);
}
} else if (dims.size() == 3) {
if (typeString.equals(cubeString)) {
if (typeString.equals(TypeConverter.getCubeAccessString(type))) {
result = "=" + TypeConverter.getDimensionString(TypeConverter.getCubeAccessString(type),dims,includeStrings);
}
}
......
......@@ -144,4 +144,37 @@ public class MathConverter {
public static String getWholeNumberCubeInitLine(Variable v, BluePrintCPP bluePrint) {
return String.format("%s = %s(%s, %s, %s);\n", MathInformationRegister.getVariableInitName(v, bluePrint), curBackend.getWholeNumberCubeTypeName(), v.getDimensionalInformation().get(0), v.getDimensionalInformation().get(1), v.getDimensionalInformation().get(2));
}
public static String getInitLine(Variable v,BluePrintCPP bluePrint) {
String tmpInst = null;
if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getMatrixTypeName())) {
tmpInst = MathConverter.getMatrixInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getRowVectorTypeName())) {
tmpInst = MathConverter.getRowVectorInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getColumnVectorTypeName())) {
tmpInst = MathConverter.getColumnVectorInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getCubeTypeName())) {
tmpInst = MathConverter.getCubeTypeInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberMatrixTypeName())) {
tmpInst = MathConverter.getWholeNumberMatrixInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberRowVectorTypeName())) {
tmpInst = MathConverter.getWholeNumberRowVectorInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberColumnVectorTypeName())) {
tmpInst = MathConverter.getWholeNumberColumnVectorInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals(MathConverter.curBackend.getWholeNumberCubeTypeName())) {
tmpInst = MathConverter.getWholeNumberCubeInitLine(v, bluePrint);
} else if (v.getVariableType().getTypeNameTargetLanguage().equals("double")) {
tmpInst = "";
} else if (v.getVariableType().getTypeNameTargetLanguage().equals("bool")) {
tmpInst = "";
} else if (v.getVariableType().getTypeNameTargetLanguage().equals("int")) {
tmpInst = "";
}
if(tmpInst == null) {
Log.error("0x3b097: Type not supported");
}
return tmpInst;
}
}
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