Commit 4359da62 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Added support for components with multiple parameters + test

parent 2a1ff273
......@@ -105,8 +105,12 @@ public class ComponentConverter {
for (ExpandedComponentInstanceSymbol subComponent : componentSymbol.getSubComponents()) {
String parameterString = "";
int i = 0;
for (ASTExpression var : subComponent.getArguments()) {
Log.debug(var.toString(),"ComponentConverter");
if(i > 0)
parameterString += ", ";
i++;
parameterString += getExpressionParameterConversion(var);
}
String result = "";
......
......@@ -546,4 +546,20 @@ public class GenerationTest extends AbstractSymtabTest {
Assert.assertNotNull(files);
Assert.assertFalse(files.isEmpty());
}
@Test
public void testParameterInstance() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("testing.parameterInstance",ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testing/Parameter/");
List<File> files = generatorCPP.generateFiles(componentInstanceSymbol, taggingResolver);
testFilesAreEqual(files,"testing/Parameter/");
}
}
#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_PARAMETERINSTANCE
#define TESTING_PARAMETERINSTANCE
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
#include "testing_parameterInstance_singleParameter.h"
#include "testing_parameterInstance_singleParameter2.h"
#include "testing_parameterInstance_multipleParameter.h"
#include "testing_parameterInstance_multipleParameter2.h"
class testing_parameterInstance{
public:
testing_parameterInstance_singleParameter singleParameter;
testing_parameterInstance_singleParameter2 singleParameter2;
testing_parameterInstance_multipleParameter multipleParameter;
testing_parameterInstance_multipleParameter2 multipleParameter2;
void init()
{
singleParameter.init(1.2);
singleParameter2.init(2);
multipleParameter.init(1, 1.4, 2);
multipleParameter2.init(3, 4, 5);
}
void execute()
{
singleParameter.execute();
singleParameter2.execute();
multipleParameter.execute();
multipleParameter2.execute();
}
};
#endif
#ifndef TESTING_PARAMETERINSTANCE_MULTIPLEPARAMETER
#define TESTING_PARAMETERINSTANCE_MULTIPLEPARAMETER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_parameterInstance_multipleParameter{
public:
double param1;
double param2;
double param3;
void init(double param1, double param2, double param3)
{
this->param1 = param1;
this->param2 = param2;
this->param3 = param3;
}
void execute()
{
}
};
#endif
#ifndef TESTING_PARAMETERINSTANCE_MULTIPLEPARAMETER2
#define TESTING_PARAMETERINSTANCE_MULTIPLEPARAMETER2
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_parameterInstance_multipleParameter2{
public:
double param1;
double param2;
double param3;
void init(double param1, double param2, double param3)
{
this->param1 = param1;
this->param2 = param2;
this->param3 = param3;
}
void execute()
{
}
};
#endif
#ifndef TESTING_PARAMETERINSTANCE_SINGLEPARAMETER
#define TESTING_PARAMETERINSTANCE_SINGLEPARAMETER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_parameterInstance_singleParameter{
public:
double param1;
void init(double param1)
{
this->param1 = param1;
}
void execute()
{
}
};
#endif
#ifndef TESTING_PARAMETERINSTANCE_SINGLEPARAMETER2
#define TESTING_PARAMETERINSTANCE_SINGLEPARAMETER2
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_parameterInstance_singleParameter2{
public:
double param1;
void init(double param1)
{
this->param1 = param1;
}
void execute()
{
}
};
#endif
package testing;
component MultipleParameter(Q param1, Q param2, Q param3){
}
\ No newline at end of file
package testing;
component ParameterInstance{
instance SingleParameter(1.2) singleParameter;
instance SingleParameter(2) singleParameter2;
instance MultipleParameter(1,1.4,2) multipleParameter;
instance MultipleParameter(3,4,5) multipleParameter2;
}
\ No newline at end of file
package testing;
component SingleParameter(Q param1){
}
\ No newline at end of file
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