Commit 56b859ce authored by Christoph Richter's avatar Christoph Richter
Browse files

TypeConverter: Added cube type support (armadillo only) (#37)

parent 8988bd32
......@@ -3,7 +3,10 @@ package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.math.math._symboltable.MathForLoopHeadSymbol;
import de.monticore.lang.math.math._symboltable.expression.*;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.*;
import de.monticore.lang.monticar.generator.cpp.MathCommandRegisterCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.OctaveHelper;
import de.monticore.lang.monticar.generator.cpp.StringValueListExtractorUtil;
import de.monticore.lang.monticar.generator.cpp.symbols.MathChainedExpression;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.se_rwth.commons.logging.Log;
......@@ -106,6 +109,17 @@ public class ExecuteMethodGeneratorHandler {
generateExecuteCode(rows, includeStrings) + "," + ExecuteMethodGenerator.
generateExecuteCode(cols, includeStrings) + ")";
}
} else if (dims.size() == 3) {
MathExpressionSymbol rows = dims.get(0);
MathExpressionSymbol cols = dims.get(1);
MathExpressionSymbol slices = dims.get(2);
if (typeString.equals(MathConverter.curBackend.getCubeTypeName())) {
result = "=" + MathConverter.curBackend.getCubeTypeName() + "(" + ExecuteMethodGenerator.
generateExecuteCode(rows, includeStrings) + "," + ExecuteMethodGenerator.
generateExecuteCode(cols, includeStrings) + "," + ExecuteMethodGenerator.
generateExecuteCode(slices, includeStrings) + ")";
}
}
return result;
}
......@@ -141,6 +155,7 @@ public class ExecuteMethodGeneratorHandler {
if (mathValueType.getDimensions().size() == 0) {
return "double";
} else if (mathValueType.getDimensions().size() == 1) {
Log.info("Dim1:" + mathValueType.getDimensions().get(0).getTextualRepresentation(), "DIMS:");
return MathConverter.curBackend.getColumnVectorTypeName();
} else if (mathValueType.getDimensions().size() == 2) {
Log.info("Dim1:" + mathValueType.getDimensions().get(0).getTextualRepresentation() + "Dim2: " + mathValueType.getDimensions().get(1).getTextualRepresentation(), "DIMS:");
......@@ -150,6 +165,9 @@ public class ExecuteMethodGeneratorHandler {
return MathConverter.curBackend.getColumnVectorTypeName();
}
return MathConverter.curBackend.getMatrixTypeName();//TODO improve in future
} else if (mathValueType.getDimensions().size() == 3) {
Log.info("Dim1:" + mathValueType.getDimensions().get(0).getTextualRepresentation() + "Dim2: " + mathValueType.getDimensions().get(1).getTextualRepresentation() + "Dim3: " + mathValueType.getDimensions().get(2).getTextualRepresentation(), "DIMS:");
return MathConverter.curBackend.getCubeTypeName();
} else {
Log.error("0xGEEXCOMAVAT Type conversion Case not handled!");
}
......@@ -170,6 +188,8 @@ public class ExecuteMethodGeneratorHandler {
return MathConverter.curBackend.getColumnVectorTypeName();
}
return MathConverter.curBackend.getMatrixTypeName();//TODO improve in future
} else if (mathValueType.getDimensions().size() == 3) {
return MathConverter.curBackend.getCubeTypeName();
} else {
Log.error("0xGEEXCOMAVAT Type conversion Case not handled!");
}
......
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.math.math._symboltable.expression.*;
import de.monticore.lang.math.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math.math._symboltable.matrix.*;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.MathBackend;
import de.monticore.lang.monticar.generator.TargetCodeInstruction;
import de.monticore.lang.monticar.generator.Variable;
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;
......@@ -124,9 +125,7 @@ public class MathConverter {
}
}
public static String getCubeTypeInitLine(Variable variable, BluePrintCPP bluePrintCPP) {
//TODO implement me
return null;
public static String getCubeTypeInitLine(Variable v, BluePrintCPP bluePrint) {
return String.format("%s = %s(%s, %s, %s);\n", MathInformationRegister.getVariableInitName(v, bluePrint), curBackend.getCubeTypeName(), v.getDimensionalInformation().get(0), v.getDimensionalInformation().get(1), v.getDimensionalInformation().get(2));
}
}
......@@ -20,12 +20,7 @@ import de.monticore.lang.monticar.types2._ast.ASTElementType;
import de.monticore.lang.monticar.types2._ast.ASTType;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;
/**
* This is used to convert port types to their cpp equivalent
......@@ -55,6 +50,8 @@ public class TypeConverter {
return MathConverter.curBackend.getColumnVectorTypeName();
} else if (mathValueType.getDimensions().size() == 2) {
return MathConverter.curBackend.getMatrixTypeName();
} else if (mathValueType.getDimensions().size() == 3) {
return MathConverter.curBackend.getCubeTypeName();
}
Log.error("TypeConverter Case not handled!");
return null;
......@@ -129,7 +126,9 @@ public class TypeConverter {
public static VariableType getRealVariableType(ASTCommonMatrixType astCommonMatrixType) {
VariableType variableType;
List<ASTCommonDimensionElement> dimensionElements = astCommonMatrixType.getCommonDimension().getCommonDimensionElements();
if (dimensionElements.size() == 2) {
if (dimensionElements.size() == 1) {
variableType = new VariableType("CommonColumnVectorType", MathConverter.curBackend.getColumnVectorTypeName(), MathConverter.curBackend.getIncludeHeaderName());
} else if (dimensionElements.size() == 2) {
if (isVectorDimension(dimensionElements.get(0)))
variableType = new VariableType("CommonRowVectorType", MathConverter.curBackend.getRowVectorTypeName(), MathConverter.curBackend.getIncludeHeaderName());
else if (isVectorDimension(dimensionElements.get(1))) {
......@@ -138,6 +137,8 @@ public class TypeConverter {
variableType = new VariableType("CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
}
} else if (dimensionElements.size() == 3) {
variableType = new VariableType("CommonCubeType", MathConverter.curBackend.getCubeTypeName(), MathConverter.curBackend.getIncludeHeaderName());
} else {
variableType = new VariableType("CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
}
......@@ -244,24 +245,24 @@ public class TypeConverter {
}
}
public static String getTypeNameMontiCar(ASTElementType elementType){
String result=null;
if(elementType.isIsRational()){
public static String getTypeNameMontiCar(ASTElementType elementType) {
String result = null;
if (elementType.isIsRational()) {
result = "Q";
}else if(elementType.isIsBoolean()){
} else if (elementType.isIsBoolean()) {
result = "B";
}else if(elementType.isIsComplex()){
} else if (elementType.isIsComplex()) {
result = "C";
}else if(elementType.isIsWholeNumberNumber()){
} else if (elementType.isIsWholeNumberNumber()) {
result = "Z";
}else if(elementType.isIsNatural()){
} else if (elementType.isIsNatural()) {
result = "N";
} else{
} else {
Log.error("Case not handled!");
}
return result;
}
public static VariableType getVariableTypeForTargetLanguageTypeName(String targetLanguageTypeName) {
VariableType type = new VariableType();
type.setTypeNameTargetLanguage(targetLanguageTypeName);
......
......@@ -15,6 +15,7 @@ void execute()
double value;
colvec vec3=colvec(3);
mat mat33=mat(3,3);
cube cub333=cube(3,3,3);
}
};
......
......@@ -15,5 +15,8 @@ component TypeDimensionsTest{
// matrix
Q^{3, 3} mat33;
// cube
Q^{3, 3, 3} cub333;
}
}
\ 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