From a3598fd15020572fe8931a5765afd2e8c88a249f Mon Sep 17 00:00:00 2001 From: Natan Date: Thu, 29 Aug 2024 22:38:56 -0300 Subject: [PATCH] fix parsing long long --- .../xpenatan/jparser/example/app/TestLib.java | 16 +++++++++++++++ .../lib/lib-build/src/main/cpp/TestLib.idl | 2 ++ .../src/main/cpp/source/TestLib/src/TestLib.h | 5 +++++ .../xpenatan/jparser/idl/IDLMethod.java | 20 ++++++++++++++----- .../xpenatan/jparser/idl/IDLParameter.java | 15 +++++++++++--- .../jparser/idl/parser/IDLMethodParser.java | 8 +++++++- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java index 352dd02..6037fb7 100644 --- a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java +++ b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java @@ -245,6 +245,22 @@ private static boolean testMethodClass() { } test.dispose(); } + { + TestMethodClass test = new TestMethodClass(); + try { + long longLongValue01 = 4; + test.setMethod08(longLongValue01); + long retLongLongValue01 = test.getLongLongValue01(); + if(!(longLongValue01 == retLongLongValue01)) { + throw new RuntimeException("longLongValue01 == retLongLongValue01"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } return true; } diff --git a/example/lib/lib-build/src/main/cpp/TestLib.idl b/example/lib/lib-build/src/main/cpp/TestLib.idl index 190a69f..26ca7d6 100644 --- a/example/lib/lib-build/src/main/cpp/TestLib.idl +++ b/example/lib/lib-build/src/main/cpp/TestLib.idl @@ -93,6 +93,7 @@ interface TestMethodClass { void setMethod05([Const] DOMString strValue01); void setMethod06([Const] TestObjectClass pointerObject01, TestObjectClass pointerObject02, [Const, Ref] TestObjectClass refObject01, [Ref] TestObjectClass refObject02); void setMethod07(TestObjectClass pointerObjectArray); + void setMethod08(long long longLongValue01); long getIntValue01(); long getIntValue02(); @@ -106,6 +107,7 @@ interface TestMethodClass { [Const, Ref] TestObjectClass getRefObject01(); [Ref] TestObjectClass getRefObject02(); [Value] TestObjectClass getValueObject(); + long long getLongLongValue01(); }; [NoDelete] diff --git a/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h b/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h index 89964d1..fc0f642 100644 --- a/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h +++ b/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h @@ -124,6 +124,7 @@ class TestMethodClass { float floatValue01; float floatValue02; bool boolValue01; + long long longLongValue01; string strValue01; const TestObjectClass* pointerObject01; TestObjectClass* pointerObject02; @@ -181,6 +182,9 @@ class TestMethodClass { obj2->intValue01 = 40; obj2->floatValue01 = 30.8; }; + void setMethod08(long long longLongValue01) { + this->longLongValue01 = longLongValue01; + }; int getIntValue01() { return intValue01; }; int getIntValue02() { return intValue02; }; @@ -194,6 +198,7 @@ class TestMethodClass { const TestObjectClass& getRefObject01() { return refObject01; }; TestObjectClass& getRefObject02() { return refObject02; }; TestObjectClass getValueObject() { return refObject02; }; + long long getLongLongValue01() { return longLongValue01; }; }; class TestStaticMethodClass { diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java index ebd6d87..7a43945 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java @@ -63,12 +63,22 @@ public void initMethod(String line) { isStaticMethod = true; } - String[] s = leftSide.split(" "); - name = s[s.length-1]; - leftSide = leftSide.replace(name, "").trim(); - returnType = leftSide; + String[] s1 = leftSide.split(" "); + name = s1[s1.length-1]; + + returnType = ""; + int sss = s1.length - 1; + for(int i = 0; i < sss; i++) { + returnType += s1[i]; + if(i < sss-1) { + returnType += " "; + } + } - if(returnType.contains("long")) { + if(returnType.contains("long long")) { + returnType = returnType.replace("long long", "long"); + } + else if(returnType.contains("long")) { returnType = returnType.replace("long", "int"); } if(returnType.equals("DOMString")) { diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java index 2e7871b..b6ad583 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java @@ -56,15 +56,24 @@ public void initParameter(String line) { String[] s1 = tmpLine.split(" "); name = s1[s1.length - 1]; - tmpLine = tmpLine.replace(name, "").trim(); - type = tmpLine; + type = ""; + int sss = s1.length - 1; + for(int i = 0; i < sss; i++) { + type += s1[i]; + if(i < sss-1) { + type += " "; + } + } if(isArray) { type = type + "[]"; } - if(type.contains("long")) { + if(type.contains("long long")) { + type = type.replace("long long", "long"); + } + else if(type.contains("long")) { // long in webidl means int type = type.replace("long", "int"); } diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java index 838afe7..1fe6da7 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java @@ -111,7 +111,13 @@ public static MethodDeclaration generateAndAddMethodOnly(IDLDefaultCodeParser id String paramType = idlParameter.getType(); String paramName = idlParameter.name; paramType = IDLHelper.convertEnumToInt(idlParser.idlReader, paramType); - Parameter parameter = methodDeclaration.addAndGetParameter(paramType, paramName); + Parameter parameter = null; + try { + parameter = methodDeclaration.addAndGetParameter(paramType, paramName); + } + catch(Throwable t) { + t.printStackTrace(); + } Type type = parameter.getType(); JParserHelper.addMissingImportType(jParser, unit, type); }