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

Fixed: BooleanValueExpressions "true" and "false" are not handled

parent 354018ef
......@@ -22,8 +22,8 @@
<Common-MontiCar.version>0.0.11-SNAPSHOT</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.11-SNAPSHOT</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.11-SNAPSHOT</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.11-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.11-SNAPSHOT</Embedded-MontiArc-Math.version>
<Math.version>0.0.12-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.12-SNAPSHOT</Embedded-MontiArc-Math.version>
<tagging.version>0.0.1</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -55,6 +55,8 @@ public class MathFunctionFixer {
notHandled = false;
} else if (((MathValueExpressionSymbol) mathExpressionSymbol).isNameExpression()) {
notHandled = false;
} else if (((MathValueExpressionSymbol)mathExpressionSymbol).isBooleanExpression()){
notHandled = false;
}
} else if (mathExpressionSymbol.getExpressionID() == MathChainedExpression.ID) {
fixMathFunctions((MathChainedExpression) mathExpressionSymbol, bluePrintCPP);
......
......@@ -59,6 +59,8 @@ public class ExecuteMethodGeneratorHandler {
return generateExecuteCode((MathNameExpressionSymbol) mathValueExpressionSymbol, includeStrings);
} else if (mathValueExpressionSymbol.isNumberExpression()) {
return generateExecuteCode((MathNumberExpressionSymbol) mathValueExpressionSymbol, includeStrings);
}else if(mathValueExpressionSymbol.isBooleanExpression()) {
return generateExecuteCode((MathBooleanExpressionSymbol)mathValueExpressionSymbol,includeStrings);
} else if (mathValueExpressionSymbol.isAssignmentDeclarationExpression()) {
return generateExecuteCodeDeclaration((MathValueSymbol) mathValueExpressionSymbol, includeStrings);
} else {
......@@ -151,6 +153,8 @@ public class ExecuteMethodGeneratorHandler {
return result;
}
private static String handleRationalType(MathValueType mathValueType) {
if (mathValueType.getDimensions().size() == 0) {
return "double";
......@@ -215,6 +219,10 @@ public class ExecuteMethodGeneratorHandler {
return mathNumberExpressionSymbol.getTextualRepresentation();
}
public static String generateExecuteCode(MathBooleanExpressionSymbol mathBooleanExpressionSymbol, List<String> includeStrings) {
return mathBooleanExpressionSymbol.getTextualRepresentation();
}
public static String generateExecuteCode(MathAssignmentExpressionSymbol mathAssignmentExpressionSymbol, List<String> includeStrings) {
Log.info(mathAssignmentExpressionSymbol.getTextualRepresentation(), "mathAssignmentExpressionSymbol:");
......
......@@ -24,6 +24,20 @@ import static org.junit.Assert.assertNotNull;
public class GenerationTest extends AbstractSymtabTest {
@Test
public void testBooleanVariableComp() throws IOException{
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.booleanVariableComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testBooleanVariableComp");
generatorCPP.useArmadilloBackend();
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "testBooleanVariableComp/";
testFilesAreEqual(files, restPath);
}
@Test
public void testBasicConstantAssignment() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
......
#ifndef HELPERA_H
#define HELPERA_H
#include <iostream>
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
using namespace arma;
class HelperA{
public:
static mat getEigenVectors(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenVectors;
}
static vec getEigenValues(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenValues;
}
static mat getKMeansClusters(mat A, int k){
mat clusters;
kmeans(clusters,A.t(),k,random_subset,20,true);
/*printf("cluster centroid calculation done\n");
std::ofstream myfile;
myfile.open("data after cluster.txt");
myfile << A;
myfile.close();
std::ofstream myfile2;
myfile2.open("cluster centroids.txt");
myfile2 << clusters;
myfile2.close();*/
mat indexedData=getKMeansClustersIndexData(A.t(), clusters);
/*std::ofstream myfile3;
myfile3.open("data after index.txt");
myfile3 << indexedData;
myfile3.close();
*/
return indexedData;
}
static mat getKMeansClustersIndexData(mat A, mat centroids){
mat result=mat(A.n_cols, 1);
for(int i=0;i<A.n_cols;++i){
result(i, 0) = getIndexForClusterCentroids(A, i, centroids);
}
return result;
}
static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){
int index=1;
double lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);
for(int i=1;i<centroids.n_cols;++i){
double curDistance=getEuclideanDistance(A, colIndex, centroids, i);
if(curDistance<lowestDistance){
lowestDistance=curDistance;
index=i+1;
}
}
return index;
}
static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){
double distance=0;
for(int i=0;i<A.n_rows;++i){
double elementA=A(i,colIndexA);
double elementB=B(i,colIndexB);
double diff=elementA-elementB;
distance+=diff*diff;
}
return sqrt(distance);
}
static mat getSqrtMat(mat A){
cx_mat result=sqrtmat(A);
return real(result);
}
static mat getSqrtMatDiag(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = sqrt(curVal);
}
return A;
}
static mat invertDiagMatrix(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = 1/curVal;
}
return A;
}
};
#endif
#ifndef TEST_BOOLEANVARIABLECOMP
#define TEST_BOOLEANVARIABLECOMP
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_booleanVariableComp{
public:
double bool3;
double bool4;
void init()
{
bool3=true;
bool4=false;
}
void execute()
{
bool bool1 = true;
bool bool2 = false;
}
};
#endif
package test;
component BooleanVariableComp{
implementation Math{
B bool1 = true;
B bool2 = false;
static B bool3 = true;
static B bool4 = false;
}
}
\ 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