Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
val kotlinVersion = "2.1.10"

dependencies {
classpath("com.android.tools.build:gradle:7.3.1")
classpath("com.android.tools.build:gradle:8.0.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.github.xpenatan.jparser.example.testlib.CallbackClass;
import com.github.xpenatan.jparser.example.testlib.CallbackClassManual;
import com.github.xpenatan.jparser.example.testlib.DefaultCallbackClass;
import com.github.xpenatan.jparser.example.testlib.IDLArrayTestObjectClass;
import com.github.xpenatan.jparser.example.testlib.TestAttributeArrayClass;
import com.github.xpenatan.jparser.example.testlib.TestCallbackClass;
import com.github.xpenatan.jparser.example.testlib.TestConstructorClass;
import com.github.xpenatan.jparser.example.testlib.TestEnumClassWithinClass;
import com.github.xpenatan.jparser.example.testlib.TestEnumLib;
import com.github.xpenatan.jparser.example.testlib.TestMethodClass;
import com.github.xpenatan.jparser.example.testlib.TestObjectClass;
import com.github.xpenatan.jparser.example.testlib.TestObjectClassArray;
import com.github.xpenatan.jparser.example.testlib.core.enums.TestEnumWithinClass;
import com.github.xpenatan.jparser.example.testlib.core.op.TestOperatorClass;
import com.github.xpenatan.jparser.example.testlib.core.sub.TestNamespaceClass;
Expand Down Expand Up @@ -195,8 +196,19 @@ private static boolean testStaticAttributeClass() {
}

private static boolean testAttributeArrayClass() {


try {
TestAttributeArrayClass attributeArrayClass = new TestAttributeArrayClass();
TestObjectClass valueObjectArray1 = attributeArrayClass.get_valueObjectArray(0);
valueObjectArray1.set_intValue01(11);
TestObjectClass valueObjectArray2 = attributeArrayClass.get_valueObjectArray(0);
int value = valueObjectArray2.get_intValue01();
if(!(value == 11)) {
throw new RuntimeException("testAttributeArrayClass !(value == 11)");
}
} catch(Throwable e) {
e.printStackTrace();
return false;
}
return true;
}

Expand All @@ -219,7 +231,7 @@ private static boolean testMethodClass() {
}
{
TestMethodClass test = new TestMethodClass();
TestObjectClassArray array = new TestObjectClassArray(2);
IDLArrayTestObjectClass array = new IDLArrayTestObjectClass(2);
TestObjectClass obj1 = new TestObjectClass();
TestObjectClass obj2 = new TestObjectClass();
obj1.set_floatValue01(20.5f);
Expand All @@ -229,7 +241,7 @@ private static boolean testMethodClass() {
array.setValue(0, obj1);
array.setValue(1, obj2);
try {
TestMethodClass.native_setMethod07(test.getNativeData().getCPointer(), array.getPointer());
test.setMethod07(array);
{
float intValue01 = obj1.get_intValue01();
if(!(intValue01 == 20)) {
Expand Down
6 changes: 3 additions & 3 deletions example/lib/lib-build/src/main/cpp/TestLib.idl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface TestObjectClass {
attribute float floatValue01;
};

interface TestObjectClassArray {
void TestObjectClassArray(long size);
interface IDLArrayTestObjectClass {
void IDLArrayTestObjectClass(long size);
void resize(long size);
void clear();
TestObjectClass getValue(long index);
Expand Down Expand Up @@ -93,7 +93,7 @@ interface TestMethodClass {
void setMethod04(long intValue01, long[] intArray, float[] floatArray);
void setMethod05([Const] DOMString strValue01);
void setMethod06([Const] TestObjectClass pointerObject01, TestObjectClass pointerObject02, [Const, Ref] TestObjectClass refObject01, [Ref] TestObjectClass refObject02);
void setMethod07(TestObjectClass pointerObjectArray);
void setMethod07(TestObjectClass[] pointerObjectArray);
void setMethod08(long long longLongValue01);

long getIntValue01();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/lib-build/src/main/cpp/custom/CustomCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ using TestEnumWithinClass = TestEnumClass::TestEnumWithinClass;
using TestEnumClassWithinClass = TestEnumClass::TestEnumClassWithinClass;
using TestEnumInNamespace = TestEnumNamespace::TestEnumInNamespace;

using TestObjectClassArray = IDLArray<TestObjectClass*>;
using IDLArrayTestObjectClass = IDLArray<TestObjectClass*>;
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class TestMethodClass {
this->refObject01 = refObject01;
this->refObject02 = refObject02;
};
void setMethod07(TestObjectClass* pointerObjectArray) {
this->pointerObjectArray = ((TestObjectClass** )pointerObjectArray);
void setMethod07(TestObjectClass** pointerObjectArray) {
this->pointerObjectArray = pointerObjectArray;
// this->pointerObjectArray = &pointerObjectArray[0];
// this->pointerObjectArray = &(*array[0]);

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
android.useAndroidX=true
version=1.0.0-b7
version=1.0.0-b8
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public void run () {
}

private void printFileLineNumber (String line) {
line = fixErrorPath(line, ": error");
line = fixErrorPath(line, ": warning ");
line = fixErrorPath(line, ": note: ");
System.err.println(line);
}
});
Expand All @@ -72,4 +75,16 @@ private void printFileLineNumber (String line) {
return false;
}
}

private static String fixErrorPath(String line, String verification) {
if(line.contains(verification)) {
String[] lineSplit = line.split(verification);
String leftSide = lineSplit[0];
String rightSide = lineSplit[1];
leftSide = leftSide.replace("\\", "/").replace("/", File.separator);
String fixed = leftSide.replace("(", ":").replace(")", ":");
line = fixed + verification + rightSide;
}
return line;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ private static String getParams(NodeList<Parameter> parameters, ArrayList<IDLPar
Parameter parameter = parameters.get(i);
IDLParameter idlParameter = idParameters.get(i);
Type type = parameter.getType();
String paramName = getParam(idlParameter.idlFile, type, idlParameter.name, idlParameter.getCPPType(), idlParameter.isAny, idlParameter.isRef, idlParameter.isValue, idlParameter.isArray);
String paramName = getParam(idlParameter, type);
if(i > 0) {
param += ", ";
}
Expand All @@ -789,21 +789,34 @@ private static String getParams(NodeList<Parameter> parameters, ArrayList<IDLPar
return param;
}

private static String getParam(IDLFile idlFile, Type type, String paramName, String classType, boolean isAny, boolean isRef, boolean isValue, boolean isArray) {
private static String getParam(IDLParameter idlParameter, Type type) {
IDLFile idlFile = idlParameter.idlFile;
String paramName = idlParameter.name;
String cppType = idlParameter.getCPPType();
String classType = cppType;
boolean isAny = idlParameter.isAny;
boolean isRef = idlParameter.isRef;
boolean isValue = idlParameter.isValue;
boolean isArray = idlParameter.isArray;
boolean isObject = type.isClassOrInterfaceType();

if(isObject && !classType.equals("char*")) {
String idlArrayOrNull = IDLHelper.getIDLArrayOrNull(classType);
String idlArrayOrNull = IDLHelper.getIDLArrayClassOrNull(classType);
if(idlArrayOrNull != null) {
classType = idlArrayOrNull;
}

paramName += "_addr";
IDLClass paramClass = idlFile.getClass(classType);
String cArray = IDLHelper.getCArray(classType);
if(isArray && cArray != null) {
paramName = "(" + cArray + ")" + paramName;
if(isArray) {
String idlType = cppType.replace("[]", "*");
if(idlParameter.idlClassOrEnum != null && !isRef) {
// Is a class object and pointer of pointer
idlType += "*";
}
paramName = "(" + idlType + ")" + paramName;
}
else {
IDLClass paramClass = idlFile.getClass(classType);
if(paramClass != null) {
classType = paramClass.getCPPName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@ public static boolean isString(ClassOrInterfaceType classOrInterfaceType) {
return classOrInterfaceType.getNameAsString().equals("String");
}

public static String getCArray(String type) {
if(type.equals("IDLBoolArray")) {
return "bool *";
}
else if(type.equals("IDLIntArray")) {
return "int *";
}
else if(type.equals("IDLLongArray")) {
return "long long *";
}
else if(type.equals("IDLFloatArray")) {
return "float *";
}
else if(type.equals("IDLDoubleArray")) {
return "double *";
}
else if(type.equals("IDLByteArray")) {
return "char *";
}
return null;
}

public static boolean isString(Type type) {
return type.toString().equals("String");
}
Expand Down Expand Up @@ -104,6 +82,12 @@ else if(idlType.equals("DOMString")) {
else if(idlType.equals("octet")) {
type = "unsigned char";
}
else if(idlType.contains("boolean")) {
type = idlType.replace("boolean", "bool");
}
else if(idlType.contains("byte")) {
type = idlType.replace("byte", "char");
}
else {
type = idlType;
}
Expand Down Expand Up @@ -155,15 +139,15 @@ else if(idlType.equals("octet")) {
type = type + "[]";
}
if(useIDLArray) {
String idlArrayOrNull = getIDLArrayOrNull(type);
String idlArrayOrNull = getIDLArrayClassOrNull(type);
if(idlArrayOrNull != null) {
type = idlArrayOrNull;
}
}
return type;
}

public static String getIDLArrayOrNull(String type) {
public static String getIDLArrayClassOrNull(String type) {
// Convert array to IDL object arrays
if(type.equals("int[]")) {
type = "IDLIntArray";
Expand All @@ -183,8 +167,10 @@ else if(type.equals("boolean[]")) {
else if(type.equals("double[]")) {
type = "IDLDoubleArray";
}
else {
return null;
else if(type.endsWith("[]")) {
type = type.replace("[]", "");
type = "IDLArray" + type;
return type;
}

return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public String getCPPType() {
if(idlClassOrEnum != null && idlClassOrEnum.isClass()) {
IDLClass aClass = idlClassOrEnum.asClass();
fullType = aClass.getCPPName();
if(isArray && !fullType.endsWith("[]")) {
fullType += "[]";
}
}
return IDLHelper.getCPPReturnType(fullType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static void configClassType(IDLReader idlReader, ArrayList<IDLClassOrEnu
}
for(IDLMethod method : idlClass.methods) {
for(IDLParameter parameter : method.parameters) {
String idlType = parameter.idlType;
String idlType = parameter.idlType.replace("[]", "");
IDLClassOrEnum childClassOrEnum = idlReader.getClassOrEnum(idlType);
parameter.idlClassOrEnum = childClassOrEnum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public class IDLMethodParser {

public static final String NATIVE_METHOD = "internal_native_";

static final String NULL_POINTER_EXCEPTION = "throw new RuntimeException(\"Pointer is null\");";

static final String GET_OBJECT_TEMPLATE =
"{\n" +
" long pointer = [METHOD];\n" +
" if(pointer == 0) return null;\n" +
" if(pointer == 0) " + NULL_POINTER_EXCEPTION + "\n" +
" if([TYPE]_TEMP_GEN_[NUM] == null) [TYPE]_TEMP_GEN_[NUM] = new [TYPE]((byte)1, (char)1);\n" +
" [TYPE]_TEMP_GEN_[NUM].getNativeData().reset(pointer, false);\n" +
" return [TYPE]_TEMP_GEN_[NUM];\n" +
Expand All @@ -50,7 +52,7 @@ public class IDLMethodParser {
static final String GET_NEW_OBJECT_TEMPLATE =
"{\n" +
" long pointer = [METHOD];\n" +
" if(pointer == 0) return null;\n" +
" if(pointer == 0) " + NULL_POINTER_EXCEPTION + "\n" +
" [TYPE] [TYPE]_NEW = new [TYPE]((byte)1, (char)1);\n" +
" [TYPE]_NEW.getNativeData().reset(pointer, [MEM_OWNED]);\n" +
" return [TYPE]_NEW;\n" +
Expand Down Expand Up @@ -223,6 +225,8 @@ public static MethodCallExpr createCaller(MethodDeclaration nativeMethodDeclarat
}

public static void setupCallerParam(NativeMethodData paramData, MethodCallExpr caller, NodeList<Parameter> methodParameters, ArrayList<IDLParameter> idlParameters) {
boolean isAttribute = idlParameters == null;

if(!paramData.isStatic) {
caller.addArgument("(long)" + IDLDefaultCodeParser.CPOINTER_METHOD);
}
Expand All @@ -242,7 +246,8 @@ public static void setupCallerParam(NativeMethodData paramData, MethodCallExpr c
//TODO create IDLParameter when is comming from attribute
isArray = idlParameter.isArray;
}
if(isArray && IDLHelper.getCArray(type.asClassOrInterfaceType().getNameAsString()) != null) {
if(isArray && !isAttribute) {
// Only methods parameter array needs to call getPointer()
String methodCall = paramName + "." + IDLDefaultCodeParser.CPOINTER_ARRAY_METHOD;
paramName = "(long)(" + variableName + " != null ? " + methodCall + " : 0)";
}
Expand Down