Aufgrund einer Wartung wird GitLab am 28.09. zwischen 10:00 und 11:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 28.09. between 10:00 and 11:00 am.

Commit 238086d3 authored by Wei Lu's avatar Wei Lu

Dynamic Interface Autopilot Generation

parent 3aa54423
Pipeline #198342 passed with stages
in 32 minutes and 46 seconds
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp.viewmodel;
import java.util.regex.*;
public final class AutopilotAdapterDataModel extends ViewModelBase {
......@@ -12,6 +13,13 @@ public final class AutopilotAdapterDataModel extends ViewModelBase {
private String outputTypes = "";
private String functionDeclarations = "";
private String functionImplementations = "";
private String structCountFuncDeclarations = "";
private String structNameFuncDeclarations = "";
private String structTypeFuncDeclarations = "";
private String structCountFuncImplementations = "";
private String structNameFuncImplementations = "";
private String structTypeFuncImplementations = "";
public String getMainModelName() {
return mainModelName;
......@@ -40,6 +48,25 @@ public final class AutopilotAdapterDataModel extends ViewModelBase {
public String getFunctionImplementations() {
return functionImplementations;
}
public String getStructCountFuncDeclarations() {
return structCountFuncDeclarations;
}
public String getStructCountFuncImplementations() {
return structCountFuncImplementations;
}
public String getStructNameFuncDeclarations() {
return structNameFuncDeclarations;
}
public String getStructNameFuncImplementations() {
return structNameFuncImplementations;
}
public String getStructTypeFuncDeclarations() {
return structTypeFuncDeclarations;
}
public String getStructTypeFuncImplementations() {
return structTypeFuncImplementations;
}
public void setMainModelName(String mainModelName) {
this.mainModelName = mainModelName;
......@@ -55,28 +82,52 @@ public final class AutopilotAdapterDataModel extends ViewModelBase {
public void addInput(String name, String type){
//Add lines to name and type array
this.inputNames += "\n \"" + name + "\",";
this.inputTypes += "\n \"" + type + "\",";
if (type.equals("Q")|type.equals("Z")|type.equals("CommonMatrixType")) {
this.inputTypes += "\n \"" + type + "\",";
} else {
this.inputTypes += "\n \"struct__" + type + "\",";
}
//this.inputTypes += "\n \"" + type + "\",";
//Add line to function declarations and implementations
String functionHeader = "EXPORT void set_input_" + name;
if (type.equals("Q")){
functionHeader += "(double v)";
this.functionImplementations += functionHeader + " { AUTOPILOT_INSTANCE." + name + " = v; }\n";
this.functionDeclarations += functionHeader + ";\n";
} else if (type.equals("Z")) {
functionHeader += "(int v)";
this.functionImplementations += functionHeader + " { AUTOPILOT_INSTANCE." + name + " = v; }\n";
this.functionDeclarations += functionHeader + ";\n";
} else if (type.equals("CommonMatrixType")) {
functionHeader += "(double *data, int size)";
this.functionImplementations += functionHeader + " { copy_double_array_to_mat( data, size, AUTOPILOT_INSTANCE." + name + "); }\n";
}
this.functionDeclarations += functionHeader + ";\n";
this.functionDeclarations += functionHeader + ";\n";
} else {
String pattern = ".*" + type + ".*\n.*";
boolean isMatch = Pattern.matches(pattern, this.structCountFuncDeclarations);
if (!isMatch) {
this.structCountFuncImplementations += "EXPORT int get_struct_count__" + type + "(){\n return struct_count;\n}\n";
this.structNameFuncImplementations += "EXPORT const char *get_struct_name__" + type + "(int index){\n return struct_names__" + type + ";\n}\n";
this.structTypeFuncImplementations += "EXPORT const char *get_struct_type__" + type + "(int index){\n return struct_types__" + type + ";\n}\n";
this.structCountFuncDeclarations += "EXPORT int get_struct_count__" + type + "();\n";
this.structNameFuncDeclarations += "EXPORT const char *get_struct_name__" + type + "(int index);\n";
this.structTypeFuncDeclarations += "EXPORT const char *get_struct_type__" + type + "(int index);\n";
}
}
}
public void addOutput(String name, String type){
this.outputNames += "\n \"" + name + "\",";
this.outputTypes += "\n \"" + type + "\",";
//this.outputTypes += "\n \"" + type + "\",";
if (type.equals("Q")|type.equals("Z")|type.equals("CommonMatrixType")) {
this.outputTypes += "\n \"" + type + "\",";
} else {
this.outputTypes += "\n \"struct__" + type + "\",";
}
String functionHeader = "";
if (type.equals("Q")){
functionHeader = "EXPORT double get_output_" + name + "()";
......
......@@ -32,24 +32,24 @@ const char *output_types[] = { ${viewModel.outputTypes}
extern "C" {
EXPORT int get_input_count(){
EXPORT int get_count_input(){
return input_count;
}
EXPORT const char *get_input_name(int id){
return input_names[id];
EXPORT const char *get_name_input(int index){
return input_names[index];
}
EXPORT const char *get_input_type(int id){
return input_types[id];
EXPORT const char *get_type_input(int index){
return input_types[index];
}
EXPORT int get_output_count(){
EXPORT int get_count_output(){
return output_count;
}
EXPORT const char *get_output_name(int id){
return output_names[id];
EXPORT const char *get_name_output(int index){
return output_names[index];
}
EXPORT const char *get_output_type(int id){
return output_types[id];
EXPORT const char *get_type_output(int index){
return output_types[index];
}
EXPORT void init(){
......@@ -59,8 +59,8 @@ EXPORT void init(){
EXPORT void execute(){
AUTOPILOT_INSTANCE.execute();
}
${viewModel.functionImplementations}
${viewModel.structCountFuncImplementations}
${viewModel.structNameFuncImplementations}
${viewModel.structTypeFuncImplementations}
}
......@@ -18,17 +18,20 @@
extern "C" {
EXPORT int get_input_count();
EXPORT const char *get_input_name(int id);
EXPORT const char *get_input_type(int id);
EXPORT int get_count_input();
EXPORT const char *get_name_input(int index);
EXPORT const char *get_type_input(int index);
EXPORT int get_output_count();
EXPORT const char *get_output_name(int id);
EXPORT const char *get_output_type(int id);
EXPORT int get_count_output();
EXPORT const char *get_name_output(int index);
EXPORT const char *get_type_output(int index);
EXPORT void init();
EXPORT void execute();
${viewModel.functionDeclarations}
${viewModel.structCountFuncDeclarations}
${viewModel.structNameFuncDeclarations}
${viewModel.structTypeFuncDeclarations}
}
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