Commit cbdcb45e authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated to deal with changed methods in the languagescommon project

parent 8e2325eb
......@@ -7,6 +7,7 @@ import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.streamunits._ast.ASTComponentStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTNamedStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTPrecisionNumber;
import de.monticore.lang.monticar.streamunits._ast.ASTStreamInstruction;
import de.monticore.lang.monticar.streamunits._symboltable.ComponentStreamUnitsSymbol;
import de.monticore.lang.monticar.streamunits._symboltable.NamedStreamUnitsSymbol;
......@@ -22,7 +23,7 @@ public class TestConverter {
fileContentString += getDefaultContent(symbol);
ASTComponentStreamUnits ast = (ASTComponentStreamUnits) symbol.getAstNode().get();
int executionCounter = 0;
int executionAmount = ast.getNamedStreamUnitss().get(0).getStream().getPrecisionNumbers().size();
int executionAmount = ast.getNamedStreamUnitss().get(0).getStream().getStreamInstructions().size();
while (executionCounter < executionAmount) {
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
fileContentString += getFileContentStringFor(instanceSymbol, astNamedStreamUnit, executionCounter);
......@@ -31,20 +32,23 @@ public class TestConverter {
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
String portName = astNamedStreamUnit.getName();
if (!instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
ASTPrecisionNumber precisionNumber = astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter);
if (precisionNumber.getPrecision().isPresent()) {
fileContentString += "if(testInstance." + portName + ">" +"("+ precisionNumber.getUnitNumber().getNumber().get()+"-"+precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() +")";
fileContentString += "&& testInstance." + portName + "<" +"("+ precisionNumber.getUnitNumber().getNumber().get()+"+"+precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() +")";
fileContentString += "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
} else {
fileContentString += "if(testInstance." + portName + "!=" + precisionNumber.getUnitNumber().getNumber().get() + "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
if (astNamedStreamUnit.getStream().getStreamInstructions().size() > 0) {
ASTStreamInstruction streamInstruction = astNamedStreamUnit.getStream().getStreamInstructions().get(executionCounter);
if (streamInstruction.getStreamValue().isPresent() && streamInstruction.getStreamValue().get().getPrecisionNumber().isPresent()) {
ASTPrecisionNumber precisionNumber = streamInstruction.getStreamValue().get().getPrecisionNumber().get();
if (precisionNumber.getPrecision().isPresent()) {
fileContentString += "if(testInstance." + portName + ">" + "(" + precisionNumber.getUnitNumber().getNumber().get() + "-" + precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() + ")";
fileContentString += "&& testInstance." + portName + "<" + "(" + precisionNumber.getUnitNumber().getNumber().get() + "+" + precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() + ")";
fileContentString += "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
} else {
fileContentString += "if(testInstance." + portName + "!=" + precisionNumber.getUnitNumber().getNumber().get() + "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
}
}
}
}
......@@ -82,8 +86,11 @@ public class TestConverter {
String fileContentString = "";
String portName = astNamedStreamUnit.getName();
if (instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
fileContentString += "testInstance." + portName + "=" + astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter).getUnitNumber().getNumber().get() + ";";
if (astNamedStreamUnit.getStream().getStreamInstructions().size() > 0) {
ASTStreamInstruction streamInstruction = astNamedStreamUnit.getStream().getStreamInstructions().get(executionCounter);
if (streamInstruction.getStreamValue().isPresent() && streamInstruction.getStreamValue().get().getPrecisionNumber().isPresent())
fileContentString += "testInstance." + portName + "=" + streamInstruction.
getStreamValue().get().getPrecisionNumber().get().getUnitNumber().getNumber().get() + ";";
}
}
return fileContentString;
......
......@@ -452,7 +452,7 @@ public class GenerationTest extends AbstractSymtabTest {
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testing");
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String restPath = "test/";
String restPath = "testing/";
testFilesAreEqual(files, restPath);
}
}
#ifndef HELPER_H
#define HELPER_H
#define _GLIBCXX_USE_CXX11_ABI 0
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#include <stdarg.h>
#include <initializer_list>
class Helper
{
public:
static void init()
{
string_vector argv(2);
argv(0) = "embedded";
argv(1) = "-q";
octave_main(2, argv.c_str_vec(), 1);
//octave_debug=1;
//feval ("pkg", ovl ("load", "all"), 0);
}
static octave_value_list convertToOctaveValueList(double a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(double a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(std::initializer_list<double> args)
{
octave_value_list in;
int counter = 0;
for(double element : args) {
in(counter) = octave_value(element);
++counter;
}
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list callOctaveFunction(octave_value_list in, std::string functionName,int argsOut)
{
/*octave_idx_type n = 2;
octave_value_list in;
for(octave_idx_type i = 0; i < n; i++)
in(i) = octave_value(5 * (i + 2));
octave_value_list out = feval("gcd", in, 1);
if(!error_state && out.length() > 0)
std::cout << "GCD of [" << in(0).int_value() << ", " << in(1).int_value() << "] is " << out(0).int_value()
<< std::endl;
else
std::cout << "invalid\n";
clean_up_and_exit(0);*/
/* if(functionName=="eigs")
return feval(functionName, in, 2);
else if(functionName=="kmeans")
return feval(functionName, in, 2);
*/
return feval(functionName, in, argsOut);
}
static int callOctaveFunctionIntFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionIntFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).int_value();
}
static double callOctaveFunctionDoubleFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionDoubleFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).double_value();
}
static Matrix callOctaveFunctionMatrixFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
printf("pre Call %s\n", functionName.c_str());
try {
in=octave_value_list();
octave_value_list list = callOctaveFunction(in, functionName,argsOut);
printf("post Call %s\n", functionName.c_str());
return list(0).array_value().as_column();
} catch(const std::exception& e) {
printf("%s\n", e.what());
}
return ColumnVector();
}
static RowVector callOctaveFunctionRowVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).array_value().as_row();
}
static int callOctaveFunctionIntSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).int_value();
}
static double callOctaveFunctionDoubleSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).double_value();
}
static Matrix callOctaveFunctionMatrixSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_column();
}
static RowVector callOctaveFunctionRowVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_row();
}
static Matrix getMatrixFromOctaveListFirstResult(octave_value_list list){
return list(0).matrix_value();
}
static RowVector getRowVectorFromOctaveListFirstResult(octave_value_list list){
return list(0).array_value().as_row();
}
static ColumnVector getColumnVectorFromOctaveListFirstResult(octave_value_list list){
return list(0).array_value().as_column();
}
static double getDoubleFromOctaveListFirstResult(octave_value_list list){
return list(0).double_value();
}
static int getIntFromOctaveListFirstResult(octave_value_list list){
return list(0).int_value();
}
};
#endif // HELPER_H
\ No newline at end of file
#ifndef TESTING_FORLOOPIFINSTANCE
#define TESTING_FORLOOPIFINSTANCE
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
#include "testing_forLoopIfInstance_forLoopIf.h"
class testing_forLoopIfInstance{
public:
double result;
testing_forLoopIfInstance_forLoopIf forLoopIf;
void init()
{
forLoopIf.init();
}
void execute()
{
forLoopIf.execute();
result = forLoopIf.result;
}
};
#endif
#ifndef TESTING_FORLOOPIFINSTANCE_FORLOOPIF
#define TESTING_FORLOOPIFINSTANCE_FORLOOPIF
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_forLoopIfInstance_forLoopIf{
public:
double result;
void init()
{
}
void execute()
{
for( auto i=1/1 ;i<=8/1 ;i+=1/1 ){
result = result+counter;
}
if((counter < 0/1 )){
result = 0/1 ;
}
else if((counter < 100/1 )){
result = counter;
}
else {
result = 100/1 ;
}
}
};
#endif
......@@ -29,6 +29,7 @@ component SteeringAngleCalculator{
if (globalOrientation > M_PI) {
globalOrientation -= 2 * M_PI;
}
end
Q orientedDistance = distance;
Q angleTowardsTrajectory = atan(orientedDistance / 2);
......
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