Skip to content

Commit

Permalink
fix parsing long long
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Aug 30, 2024
1 parent e83190b commit a3598fd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions example/lib/lib-build/src/main/cpp/TestLib.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -106,6 +107,7 @@ interface TestMethodClass {
[Const, Ref] TestObjectClass getRefObject01();
[Ref] TestObjectClass getRefObject02();
[Value] TestObjectClass getValueObject();
long long getLongLongValue01();
};

[NoDelete]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class TestMethodClass {
float floatValue01;
float floatValue02;
bool boolValue01;
long long longLongValue01;
string strValue01;
const TestObjectClass* pointerObject01;
TestObjectClass* pointerObject02;
Expand Down Expand Up @@ -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; };
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a3598fd

Please sign in to comment.