Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
0e5aa961
Commit
0e5aa961
authored
Jul 12, 2018
by
Christoph Richter
Browse files
Fixed generation of MathMatrixVectorExpressionSymbol (gitlab
#14
)
parent
f8903b14
Pipeline
#62239
passed with stage
in 2 minutes and 37 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/MathBackend.java
View file @
0e5aa961
...
...
@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator;
import
de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol
;
/**
* @author Sascha Schneiders
...
...
@@ -52,4 +53,6 @@ public interface MathBackend {
String
getWholeNumberMatrixTypeName
();
String
getWholeNumberCubeTypeName
();
String
getMathMatrixColonVectorString
(
MathMatrixVectorExpressionSymbol
mathMatrixArithmeticExpressionSymbol
);
}
src/main/java/de/monticore/lang/monticar/generator/cpp/ArmadilloBackend.java
View file @
0e5aa961
...
...
@@ -2,9 +2,9 @@ package de.monticore.lang.monticar.generator.cpp;
import
de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol
;
import
de.monticore.lang.monticar.generator.MathBackend
;
import
de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator
;
import
de.monticore.lang.monticar.generator.cpp.converter.MathConverter
;
import
de.se_rwth.commons.logging.Log
;
import
java.util.ArrayList
;
...
...
@@ -134,4 +134,14 @@ public class ArmadilloBackend implements MathBackend {
public
String
getWholeNumberCubeTypeName
()
{
return
"icube"
;
}
@Override
public
String
getMathMatrixColonVectorString
(
MathMatrixVectorExpressionSymbol
symbol
)
{
String
start
=
ExecuteMethodGenerator
.
generateExecuteCode
(
symbol
.
getStart
(),
new
ArrayList
<>());
String
delta
=
"1"
;
if
(
symbol
.
getStep
().
isPresent
())
delta
=
ExecuteMethodGenerator
.
generateExecuteCode
(
symbol
.
getStep
().
get
(),
new
ArrayList
<>());
String
end
=
ExecuteMethodGenerator
.
generateExecuteCode
(
symbol
.
getEnd
(),
new
ArrayList
<>());
return
String
.
format
(
"regspace<rowvec>(%s, %s, %s)"
,
start
,
delta
,
end
);
}
}
src/main/java/de/monticore/lang/monticar/generator/cpp/LinalgBackend.java
View file @
0e5aa961
...
...
@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.cpp;
import
de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol
;
import
de.monticore.lang.monticar.generator.MathBackend
;
import
de.se_rwth.commons.logging.Log
;
...
...
@@ -124,4 +125,10 @@ public class LinalgBackend implements MathBackend {
Log
.
error
(
"Not supported yet"
);
return
null
;
}
@Override
public
String
getMathMatrixColonVectorString
(
MathMatrixVectorExpressionSymbol
mathMatrixArithmeticExpressionSymbol
)
{
Log
.
error
(
"Not supported yet"
);
return
null
;
}
}
src/main/java/de/monticore/lang/monticar/generator/cpp/OctaveBackend.java
View file @
0e5aa961
...
...
@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.cpp;
import
de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.expression.MathExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol
;
import
de.monticore.lang.monticar.generator.MathBackend
;
import
de.se_rwth.commons.logging.Log
;
...
...
@@ -126,4 +127,10 @@ public class OctaveBackend implements MathBackend {
Log
.
warn
(
"Octave does not support whole number matrices. Using real matrix instead!"
);
return
getCubeTypeName
();
}
@Override
public
String
getMathMatrixColonVectorString
(
MathMatrixVectorExpressionSymbol
mathMatrixArithmeticExpressionSymbol
)
{
Log
.
warn
(
"Not supported."
,
mathMatrixArithmeticExpressionSymbol
.
getSourcePosition
());
return
null
;
}
}
src/main/java/de/monticore/lang/monticar/generator/cpp/converter/ExecuteMethodGeneratorMatrixExpressionHandler.java
View file @
0e5aa961
...
...
@@ -231,10 +231,12 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
result
=
generateExecuteCode
((
MathMatrixNameExpressionSymbol
)
mathMatrixExpressionSymbol
,
includeStrings
);
}
else
if
(
mathMatrixExpressionSymbol
.
isValueExpression
())
{
result
=
generateExecuteCode
((
MathMatrixArithmeticValueSymbol
)
mathMatrixExpressionSymbol
,
includeStrings
);
}
else
if
(
mathMatrixExpressionSymbol
.
isMatrixVectorExpression
())
{
result
=
generateExecuteCode
((
MathMatrixVectorExpressionSymbol
)
mathMatrixExpressionSymbol
,
includeStrings
);
}
else
{
Log
.
info
(
mathMatrixExpressionSymbol
.
getTextualRepresentation
(),
"Symbol:"
);
Log
.
info
(
mathMatrixExpressionSymbol
.
getClass
().
getName
(),
"Symbol Name:"
);
Log
.
debug
(
"0xMAMAEXSY
"
,
"
Case not handled"
);
Log
.
error
(
"0xMAMAEXSY
:
Case not handled"
);
}
return
result
;
}
...
...
@@ -253,4 +255,8 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
}
return
result
;
}
public
static
String
generateExecuteCode
(
MathMatrixVectorExpressionSymbol
symbol
,
List
<
String
>
includeStrings
)
{
return
MathConverter
.
curBackend
.
getMathMatrixColonVectorString
(
symbol
);
}
}
src/test/java/de/monticore/lang/monticar/generator/cpp/armadillo/BasicMathGenerationArmadilloTest.java
View file @
0e5aa961
...
...
@@ -144,4 +144,18 @@ public class BasicMathGenerationArmadilloTest extends AbstractSymtabTest {
String
restPath
=
"armadillo/testMath/l0/"
;
testFilesAreEqual
(
files
,
restPath
);
}
@Test
public
void
vectorColonExpressionTest
()
throws
IOException
{
TaggingResolver
symtab
=
createSymTabAndTaggingResolver
(
"src/test/resources"
);
ExpandedComponentInstanceSymbol
componentSymbol
=
symtab
.<
ExpandedComponentInstanceSymbol
>
resolve
(
"test.math.vectorColonExpressionTest"
,
ExpandedComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentSymbol
);
GeneratorCPP
generatorCPP
=
new
GeneratorCPP
();
generatorCPP
.
useArmadilloBackend
();
generatorCPP
.
setGenerationTargetPath
(
"./target/generated-sources-cpp/armadillo/testMath/l0"
);
List
<
File
>
files
=
generatorCPP
.
generateFiles
(
symtab
,
componentSymbol
,
symtab
);
String
restPath
=
"armadillo/testMath/l0/"
;
testFilesAreEqual
(
files
,
restPath
);
}
}
src/test/resources/results/armadillo/testMath/l0/test_math_vectorColonExpressionTest.h
0 → 100644
View file @
0e5aa961
#ifndef TEST_MATH_VECTORCOLONEXPRESSIONTEST
#define TEST_MATH_VECTORCOLONEXPRESSIONTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include
"armadillo.h"
using
namespace
arma
;
class
test_math_vectorColonExpressionTest
{
public:
void
init
()
{
}
void
execute
()
{
rowvec
A
=
regspace
<
rowvec
>
(
1
,
1
,
10
);
rowvec
B
=
regspace
<
rowvec
>
(
1
,
2
,
10
);
}
};
#endif
src/test/resources/test/math/VectorColonExpressionTest.emam
0 → 100644
View file @
0e5aa961
package
test
.
math
;
component
VectorColonExpressionTest
{
implementation
Math
{
Q
^{
1
,
10
}
A
=
1
:
10
;
Q
^{
1
,
5
}
B
=
1
:
2
:
10
;
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment