diff --git a/.run/jParser_example_app-test_desktop [run-app-desktop].run.xml b/.run/jParser_example_app-test_desktop [run-app-desktop].run.xml
new file mode 100644
index 0000000..19a4475
--- /dev/null
+++ b/.run/jParser_example_app-test_desktop [run-app-desktop].run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/jParser_example_app_desktop [run-app-desktop].run.xml b/.run/jParser_example_app_desktop [run-app-desktop].run.xml
new file mode 100644
index 0000000..57fc755
--- /dev/null
+++ b/.run/jParser_example_app_desktop [run-app-desktop].run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/jParser_example_app_teavm [run-app-teavm].run.xml b/.run/jParser_example_app_teavm [run-app-teavm].run.xml
new file mode 100644
index 0000000..6a3559a
--- /dev/null
+++ b/.run/jParser_example_app_teavm [run-app-teavm].run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/jParser_example_lib-test_lib-build [build_project_all].run.xml b/.run/jParser_example_lib-test_lib-build [build_project_all].run.xml
new file mode 100644
index 0000000..e47fc93
--- /dev/null
+++ b/.run/jParser_example_lib-test_lib-build [build_project_all].run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/jParser_example_lib_lib-build [build_project_all].run.xml b/.run/jParser_example_lib_lib-build [build_project_all].run.xml
new file mode 100644
index 0000000..ed10b5e
--- /dev/null
+++ b/.run/jParser_example_lib_lib-build [build_project_all].run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/example/app-test/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTestLib.java b/example/app-test/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTestLib.java
index f1046cf..b74d0cc 100644
--- a/example/app-test/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTestLib.java
+++ b/example/app-test/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTestLib.java
@@ -2,7 +2,6 @@
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.utils.ScreenUtils;
-import lib.emscripten.TestLibLoader;
import lib.test.ArrayArgumentTest;
import lib.test.ArrayClass;
import lib.test.Child1;
@@ -17,6 +16,7 @@
import lib.test.StoreArray;
import lib.test.StringUser;
import lib.test.StructInArray;
+import lib.test.TestLibLoader;
import lib.test.TypeTestClass;
import lib.test.VoidPointerUser;
import lib.test.idl.helper.IDLByteArray;
diff --git a/example/lib-test/lib-base/src/main/java/lib/emscripten/TestLibLoader.java b/example/lib-test/lib-base/src/main/java/lib/test/TestLibLoader.java
similarity index 98%
rename from example/lib-test/lib-base/src/main/java/lib/emscripten/TestLibLoader.java
rename to example/lib-test/lib-base/src/main/java/lib/test/TestLibLoader.java
index 2094a3c..6ddda5d 100644
--- a/example/lib-test/lib-base/src/main/java/lib/emscripten/TestLibLoader.java
+++ b/example/lib-test/lib-base/src/main/java/lib/test/TestLibLoader.java
@@ -1,4 +1,4 @@
-package lib.emscripten;
+package lib.test;
import com.github.xpenatan.jparser.loader.JParserLibraryLoader;
diff --git a/example/lib/lib-build/src/main/cpp/exampleLib.idl b/example/lib/lib-build/src/main/cpp/exampleLib.idl
index bd40c5f..b6affe2 100644
--- a/example/lib/lib-build/src/main/cpp/exampleLib.idl
+++ b/example/lib/lib-build/src/main/cpp/exampleLib.idl
@@ -125,6 +125,5 @@ enum EnumClassWithinClass {
};
enum EnumInNamespace {
-// [-NAMESPACE]
- "EnumNamespace::e_namespace_val"
+ "EnumInNamespace::e_namespace_val"
};
\ No newline at end of file
diff --git a/jParser/base/src/main/resources/IDLHelper.h b/jParser/base/src/main/resources/IDLHelper.h
index db54303..aa1f43b 100644
--- a/jParser/base/src/main/resources/IDLHelper.h
+++ b/jParser/base/src/main/resources/IDLHelper.h
@@ -1,52 +1,25 @@
#pragma once
#include
+#include
#include // NULL
#include // intptr_t
-typedef std::string IDLString;
-typedef std::string_view IDLStringView;
-
-class IDLBoolArray {
+template
+class IDLArray {
private:
int size;
- public:
- bool * data;
- IDLBoolArray(int size) { data = NULL; resize(size); }
- ~IDLBoolArray() { if(data != NULL) { deleteData(); } }
- void resize(int newSize) {
- if(this->data != NULL) {
- deleteData();
- }
- bool * newData = new bool[newSize];
- this->data = newData;
- size = newSize;
- clear();
- }
- void clear() {
- for(int i = 0; i < size; i++) {
- data[i] = 0;
- }
- }
- void deleteData() { delete data; }
- bool getValue(int index) { return data[index]; }
- void setValue(int index, bool value) { data[index] = value; }
- intptr_t getPointer() { return (intptr_t)data; }
- int getSize() { return size; }
-};
+ T* data;
-class IDLIntArray {
- private:
- int size;
+ void deleteData() { delete[] data; data = NULL; }
public:
- int * data;
- IDLIntArray(int size) { data = NULL; resize(size); }
- ~IDLIntArray() { if(data != NULL) { deleteData(); } }
+ IDLArray(int size) { data = NULL; resize(size); }
+ ~IDLArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
- int * newData = new int[newSize];
+ T * newData = new T[newSize];
this->data = newData;
size = newSize;
clear();
@@ -56,93 +29,29 @@ class IDLIntArray {
data[i] = 0;
}
}
- void deleteData() { delete data; }
- int getValue(int index) { return data[index]; }
- void setValue(int index, int value) { data[index] = value; }
- intptr_t getPointer() { return (intptr_t)data; }
- int getSize() { return size; }
-};
-
-class IDLFloatArray {
- private:
- int size;
- public:
- float * data;
- IDLFloatArray(int size) { data = NULL; resize(size); }
- ~IDLFloatArray() { if(data != NULL) { deleteData(); } }
- void resize(int newSize) {
- if(this->data != NULL) {
- deleteData();
- }
- float * newData = new float[newSize];
- this->data = newData;
- size = newSize;
- clear();
- }
- void clear() {
- for(int i = 0; i < size; i++) {
- data[i] = 0;
+ void copy(IDLArray& src, int srcPos, int destPos, int length) {
+ T* dest = data;
+ int srcP = srcPos;
+ int destP = destPos;
+ int count = 0;
+ while(count < length) {
+ T srcByte = src.getValue(srcP);
+ srcP++;
+ dest[destP] = srcByte;
+ destP++;
+ count++;
}
}
- void deleteData() { delete data; }
- float getValue(int index) { return data[index]; }
- void setValue(int index, float value) { data[index] = value; }
- intptr_t getPointer() { return (intptr_t)data; }
+ T getValue(int index) { return data[index]; }
+ void setValue(int index, T value) { data[index] = value; }
int getSize() { return size; }
-};
-
-class IDLDoubleArray {
- private:
- int size;
- public:
- double * data;
- IDLDoubleArray(int size) { data = NULL; resize(size); }
- ~IDLDoubleArray() { if(data != NULL) { deleteData(); } }
- void resize(int newSize) {
- if(this->data != NULL) {
- deleteData();
- }
- double * newData = new double[newSize];
- this->data = newData;
- size = newSize;
- clear();
- }
- void clear() {
- for(int i = 0; i < size; i++) {
- data[i] = 0;
- }
- }
- void deleteData() { delete data; }
- double getValue(int index) { return data[index]; }
- void setValue(int index, double value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
- int getSize() { return size; }
};
-class IDLByteArray {
- private:
- int size;
- public:
- char * data;
- IDLByteArray(int size) { data = NULL; resize(size); }
- ~IDLByteArray() { if(data != NULL) { deleteData(); } }
- void resize(int newSize) {
- if(this->data != NULL) {
- deleteData();
- }
- char * newData = new char[newSize];
- this->data = newData;
- size = newSize;
- clear();
- }
- void clear() {
- for(int i = 0; i < size; i++) {
- data[i] = 0;
- }
- }
- void deleteData() { delete data; }
- char getValue(int index) { return data[index]; }
- void setValue(int index, char value) { data[index] = value; }
- intptr_t getPointer() { return (intptr_t)data; }
- int getSize() { return size; }
-};
\ No newline at end of file
+typedef std::string IDLString;
+typedef std::string_view IDLStringView;
+typedef IDLArray IDLBoolArray;
+typedef IDLArray IDLIntArray;
+typedef IDLArray IDLFloatArray;
+typedef IDLArray IDLDoubleArray;
+typedef IDLArray IDLByteArray;
\ No newline at end of file
diff --git a/jParser/base/src/main/resources/IDLHelper.idl b/jParser/base/src/main/resources/IDLHelper.idl
index c3fdfa2..a0676fa 100644
--- a/jParser/base/src/main/resources/IDLHelper.idl
+++ b/jParser/base/src/main/resources/IDLHelper.idl
@@ -21,44 +21,54 @@ interface IDLStringView {
interface IDLBoolArray {
void IDLBoolArray(long size);
void resize(long size);
+ void clear();
boolean getValue(long index);
void setValue(long index, boolean value);
- long getPointer();
long getSize();
+ long getPointer();
+ void copy([Ref] IDLBoolArray src, long srcOffset, long destOffset, long length);
};
interface IDLIntArray {
void IDLIntArray(long size);
void resize(long size);
+ void clear();
long getValue(long index);
void setValue(long index, long value);
- long getPointer();
long getSize();
+ long getPointer();
+ void copy([Ref] IDLIntArray src, long srcOffset, long destOffset, long length);
};
interface IDLFloatArray {
void IDLFloatArray(long size);
void resize(long size);
+ void clear();
float getValue(long index);
void setValue(long index, float value);
- long getPointer();
long getSize();
+ long getPointer();
+ void copy([Ref] IDLFloatArray src, long srcOffset, long destOffset, long length);
};
interface IDLDoubleArray {
void IDLDoubleArray(long size);
void resize(long size);
+ void clear();
double getValue(long index);
void setValue(long index, double value);
- long getPointer();
long getSize();
+ long getPointer();
+ void copy([Ref] IDLDoubleArray src, long srcOffset, long destOffset, long length);
};
interface IDLByteArray {
void IDLByteArray(long size);
void resize(long size);
+ void clear();
byte getValue(long index);
void setValue(long index, byte value);
- long getPointer();
long getSize();
+ long getPointer();
+ void copy([Ref] IDLByteArray src, long srcOffset, long destOffset, long length);
};
\ No newline at end of file
diff --git a/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java
index 088b5fd..0b8fc26 100644
--- a/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java
+++ b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java
@@ -417,8 +417,7 @@ private static String getParams(NodeList parameters, ArrayList 0) {
param += ", ";
}
@@ -427,12 +426,13 @@ private static String getParams(NodeList parameters, ArrayList idlParameters) {
MethodDeclaration nativeMethodDeclaration = generateNativeMethod(isReturnValue, methodDeclaration, methodName);
if(!JParserHelper.containsMethod(classDeclaration, nativeMethodDeclaration)) {
//Add native method if it does not exist
@@ -168,20 +168,20 @@ public static MethodDeclaration prepareNativeMethod(boolean isStatic, boolean is
if(methodReturnType.isVoidType()) {
// void types just call the method.
- IDLMethodParser.setupCallerParam(isStatic, false, caller, methodDeclaration);
+ IDLMethodParser.setupCallerParam(isStatic, false, caller, methodDeclaration.getParameters(), idlParameters);
BlockStmt blockStmt = methodDeclaration.getBody().get();
blockStmt.addStatement(caller);
}
else if(methodReturnType.isClassOrInterfaceType()) {
// Class object needs to generate some additional code.
// Needs to obtain the pointer and return a temp object.
- BlockStmt blockStmt = IDLMethodParser.generateTempObjects(isReturnValue, classDeclaration, methodDeclaration, nativeMethodDeclaration, caller, operator);
+ BlockStmt blockStmt = IDLMethodParser.generateTempObjects(isReturnValue, classDeclaration, methodDeclaration, nativeMethodDeclaration, caller, operator, idlParameters);
methodDeclaration.setBody(blockStmt);
}
else {
// Should be a primitive return type.
ReturnStmt returnStmt = IDLMethodParser.getReturnStmt(methodDeclaration);
- IDLMethodParser.setupCallerParam(isStatic, false, caller, methodDeclaration);
+ IDLMethodParser.setupCallerParam(isStatic, false, caller, methodDeclaration.getParameters(), idlParameters);
returnStmt.setExpression(caller);
}
return nativeMethodDeclaration;
@@ -196,24 +196,27 @@ public static MethodCallExpr createCaller(MethodDeclaration nativeMethodDeclarat
return caller;
}
- public static void setupCallerParam(boolean isStatic, boolean isReturnValue, MethodCallExpr caller, MethodDeclaration methodDeclaration) {
- NodeList methodParameters = methodDeclaration.getParameters();
- setupCallerParam(isStatic, isReturnValue, caller, methodParameters);
- }
-
- public static void setupCallerParam(boolean isStatic, boolean isReturnValue, MethodCallExpr caller, NodeList methodParameters) {
+ public static void setupCallerParam(boolean isStatic, boolean isReturnValue, MethodCallExpr caller, NodeList methodParameters, ArrayList idlParameters) {
if(!isStatic) {
caller.addArgument(IDLDefaultCodeParser.CPOINTER_METHOD);
}
-
for(int i = 0; i < methodParameters.size(); i++) {
Parameter parameter = methodParameters.get(i);
+ IDLParameter idlParameter = null;
+ if(idlParameters != null) {
+ idlParameter = idlParameters.get(i);
+ }
Type type = parameter.getType();
SimpleName name = parameter.getName();
String variableName = name.getIdentifier();
String paramName = parameter.getNameAsString();
if(type.isClassOrInterfaceType()) {
- if(IDLHelper.getCArray(type.asClassOrInterfaceType().getNameAsString()) != null) {
+ boolean isArray = true;
+ if(idlParameter != null) {
+ //TODO create IDLParameter when is comming from attribute
+ isArray = idlParameter.isArray;
+ }
+ if(isArray && IDLHelper.getCArray(type.asClassOrInterfaceType().getNameAsString()) != null) {
String methodCall = paramName + ".getPointer()";
paramName = "(" + variableName + " != null ? " + methodCall + " : 0)";
}
@@ -231,7 +234,7 @@ else if(type.isArrayType()) {
}
}
- public static BlockStmt generateTempObjects(boolean isReturnValue, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration methodDeclaration, MethodDeclaration nativeMethodDeclaration, MethodCallExpr caller, String operator) {
+ private static BlockStmt generateTempObjects(boolean isReturnValue, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration methodDeclaration, MethodDeclaration nativeMethodDeclaration, MethodCallExpr caller, String operator, ArrayList idlParameters) {
Type methodReturnType = methodDeclaration.getType();
String className = classDeclaration.getNameAsString();
String returnTypeName = methodReturnType.toString();
@@ -250,7 +253,7 @@ public static BlockStmt generateTempObjects(boolean isReturnValue, ClassOrInterf
fieldName = generateFieldName(classDeclaration, returnTypeName, isStatic);
}
- IDLMethodParser.setupCallerParam(isStatic, isReturnValue, caller, methodDeclaration);
+ IDLMethodParser.setupCallerParam(isStatic, isReturnValue, caller, methodDeclaration.getParameters(), idlParameters);
String methodCaller = caller.toString();