Commit 8988bd32 authored by Christoph Richter's avatar Christoph Richter
Browse files

TypeConverter, ExecuteMethodGeneratorHandler: Added column vector support for...

TypeConverter, ExecuteMethodGeneratorHandler: Added column vector support for dimension equals 1 (fixes #52)
parent 51ff8dd8
......@@ -91,7 +91,13 @@ public class ExecuteMethodGeneratorHandler {
public static String addInitializationString(MathValueSymbol mathValueSymbol, String typeString, List<String> includeStrings) {
String result = "";
List<MathExpressionSymbol> dims = mathValueSymbol.getType().getDimensions();
if (dims.size() == 2) {
if (dims.size() == 1) {
MathExpressionSymbol rows = dims.get(0);
if (typeString.equals(MathConverter.curBackend.getColumnVectorTypeName())) {
result = "=" + MathConverter.curBackend.getColumnVectorTypeName() + "(" + ExecuteMethodGenerator.
generateExecuteCode(rows, includeStrings) + ")";
}
} else if (dims.size() == 2) {
MathExpressionSymbol rows = dims.get(0);
MathExpressionSymbol cols = dims.get(1);
......@@ -132,9 +138,11 @@ public class ExecuteMethodGeneratorHandler {
}
private static String handleRationalType(MathValueType mathValueType) {
if (mathValueType.getDimensions().size() == 0)
if (mathValueType.getDimensions().size() == 0) {
return "double";
else if (mathValueType.getDimensions().size() == 2) {
} else if (mathValueType.getDimensions().size() == 1) {
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:");
if (mathValueType.getDimensions().get(0).getTextualRepresentation().equals("1")) {
return MathConverter.curBackend.getRowVectorTypeName();
......@@ -149,9 +157,11 @@ public class ExecuteMethodGeneratorHandler {
}
private static String handleWholeNumberType(MathValueType mathValueType) {
if (mathValueType.getDimensions().size() == 0)
if (mathValueType.getDimensions().size() == 0) {
return "int";
else if (mathValueType.getDimensions().size() == 2) {
} else if (mathValueType.getDimensions().size() == 1) {
return MathConverter.curBackend.getColumnVectorTypeName();
} else if (mathValueType.getDimensions().size() == 2) {
//TODO handle just like RationalMatrix right now
Log.info("Dim1:" + mathValueType.getDimensions().get(0).getTextualRepresentation() + "Dim2: " + mathValueType.getDimensions().get(1).getTextualRepresentation(), "DIMS:");
if (mathValueType.getDimensions().get(0).getTextualRepresentation().equals("1")) {
......@@ -198,8 +208,8 @@ public class ExecuteMethodGeneratorHandler {
if (MathCommandRegisterCPP.containsCommandExpression(mathAssignmentExpressionSymbol.getExpressionSymbol(), input)) {
result += input;
} else {
if(!StringValueListExtractorUtil.containsPortName(input))
result += StringIndexHelper.modifyContentBetweenBracketsByAdding(input, "-1");
if (!StringValueListExtractorUtil.containsPortName(input))
result += StringIndexHelper.modifyContentBetweenBracketsByAdding(input, "-1");
else
result += input;
}
......
......@@ -51,6 +51,8 @@ public class TypeConverter {
return "int";//use int for now add range check if bigger number is required
}
return "double";
} else if (mathValueType.getDimensions().size() == 1) {
return MathConverter.curBackend.getColumnVectorTypeName();
} else if (mathValueType.getDimensions().size() == 2) {
return MathConverter.curBackend.getMatrixTypeName();
}
......
......@@ -3,7 +3,6 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.AbstractSymtabTest;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import org.junit.Test;
import java.io.File;
......@@ -96,4 +95,18 @@ public class BasicMathGenerationTest extends AbstractSymtabTest {
String restPath = "testMath/l0/";
testFilesAreEqual(files, restPath);
}
@Test
public void testTypeDimensionsTest() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.math.typeDimensionsTest", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testMath/l0");
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String restPath = "testMath/l0/";
testFilesAreEqual(files, restPath);
}
}
#ifndef TEST_MATH_TYPEDIMENSIONSTEST
#define TEST_MATH_TYPEDIMENSIONSTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_math_typeDimensionsTest{
public:
void init()
{
}
void execute()
{
double value;
colvec vec3=colvec(3);
mat mat33=mat(3,3);
}
};
#endif
// purpose of this test model is to test if the correct data types for scalars, vectors, matrices and cubes are
// generated. Also checks if the empty initialization is correct.
package test.math;
component TypeDimensionsTest{
implementation Math{
// scalar
Q value;
// vector
Q^{3} vec3;
// matrix
Q^{3, 3} mat33;
}
}
\ 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