Skip to content

Commit 1c6189b

Browse files
authored
Generate complete clean-target headers (#4494)
1 parent f6841e5 commit 1c6189b

File tree

10 files changed

+1
-53
lines changed

10 files changed

+1
-53
lines changed

vm/ByteCodeTranslator/src/cn1_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ extern void initMethodStack(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisObje
10291029

10301030

10311031
#if defined(__APPLE__) && defined(__OBJC__)
1032+
@class NSString;
10321033
extern JAVA_OBJECT fromNSString(CODENAME_ONE_THREAD_STATE, NSString* str);
10331034
extern NSString* toNSString(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT o);
10341035
#else

vm/ByteCodeTranslator/src/com/codename1/tools/translator/BytecodeMethod.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,6 @@ public void appendVirtualMethodC(String cls, StringBuilder b, String offset, boo
11031103
returnType.appendCMethodExt(bld);
11041104
}
11051105

1106-
if(!forceVirtual && !virtualMethodsInvoked.contains(bld.toString())) {
1107-
return;
1108-
}
1109-
11101106
// generate the function pointer declaration
11111107
appendCMethodPrefix("\ntypedef ", ")", b, "(*functionPtr_", cls);
11121108
b.append(";\n");
@@ -1156,9 +1152,6 @@ public void appendVirtualMethodHeader(StringBuilder b, String cls) {
11561152
bld.append("_R");
11571153
returnType.appendCMethodExt(bld);
11581154
}
1159-
if(!forceVirtual && !virtualMethodsInvoked.contains(bld.toString())) {
1160-
return;
1161-
}
11621155
appendCMethodPrefix(b, "virtual_", cls);
11631156
b.append(";\n");
11641157
}

vm/tests/src/test/java/com/codename1/tools/translator/BytecodeInstructionIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ void translatesOptimizedBytecodeToLLVMExecutable(CompilerHelper.CompilerConfig c
111111
assertTrue(Files.exists(cmakeLists), "Translator should emit a CMake project for the optimized sample");
112112

113113
Path srcRoot = distDir.resolve("CustomBytecodeApp-src");
114-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
115114

116115
Path generatedSource = findGeneratedSource(srcRoot);
117116
String generatedCode = new String(Files.readAllBytes(generatedSource), StandardCharsets.UTF_8);
@@ -262,7 +261,6 @@ void translatesInvokeAndLdcBytecodeToLLVMExecutable(CompilerHelper.CompilerConfi
262261
assertTrue(Files.exists(cmakeLists), "Translator should emit a CMake project for Invoke/Ldc sample");
263262

264263
Path srcRoot = distDir.resolve("InvokeLdcLocalVars-src");
265-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
266264

267265
Path generatedSource = findGeneratedSource(srcRoot, "InvokeLdcLocalVarsApp");
268266
String generatedCode = new String(Files.readAllBytes(generatedSource), StandardCharsets.UTF_8);

vm/tests/src/test/java/com/codename1/tools/translator/CleanTargetIntegrationTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ void generatesRunnableHelloWorldUsingCleanTarget(CompilerHelper.CompilerConfig c
7979
assertTrue(Files.exists(cmakeLists), "Translator should emit a CMake project");
8080

8181
Path srcRoot = distDir.resolve("HelloCleanApp-src");
82-
patchCn1Globals(srcRoot);
8382

8483
replaceLibraryWithExecutableTarget(cmakeLists, srcRoot.getFileName().toString());
8584

@@ -181,20 +180,6 @@ static String runCommand(List<String> command, Path workingDir) throws Exception
181180
return output;
182181
}
183182

184-
static void patchCn1Globals(Path srcRoot) throws IOException {
185-
Path cn1Globals = srcRoot.resolve("cn1_globals.h");
186-
String content = new String(Files.readAllBytes(cn1Globals), StandardCharsets.UTF_8);
187-
if (!content.contains("@class NSString;")) {
188-
content = content.replace("#ifdef __OBJC__\n", "#ifdef __OBJC__\n@class NSString;\n");
189-
Files.write(cn1Globals, content.getBytes(StandardCharsets.UTF_8));
190-
}
191-
if (!content.contains("#include <string.h>")) {
192-
content = content.replace("#include <stdlib.h>\n", "#include <stdlib.h>\n#include <string.h>\n#include <math.h>\n#include <limits.h>\n");
193-
Files.write(cn1Globals, content.getBytes(StandardCharsets.UTF_8));
194-
}
195-
}
196-
197-
198183
static String helloWorldSource() {
199184
return "public class HelloWorld {\n" +
200185
" private static native void nativeHello();\n" +

vm/tests/src/test/java/com/codename1/tools/translator/CompilerHelper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ public static boolean compileAndRun(String code, String expectedOutput) throws E
230230
CleanTargetIntegrationTest.runTranslator(classesDir, outputDir, "ExecutorApp");
231231

232232
java.nio.file.Path distDir = outputDir.resolve("dist");
233-
java.nio.file.Path srcRoot = distDir.resolve("ExecutorApp-src");
234-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
235233

236234
CleanTargetIntegrationTest.replaceLibraryWithExecutableTarget(outputDir.resolve("dist").resolve("CMakeLists.txt"), "ExecutorApp-src");
237235

vm/tests/src/test/java/com/codename1/tools/translator/FileClassIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ public void testFileClassMethods(CompilerHelper.CompilerConfig config) throws Ex
7070
assertTrue(Files.exists(cmakeLists), "Translator should emit a CMake project");
7171

7272
Path srcRoot = distDir.resolve("FileTestApp-src");
73-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
74-
7573
replaceLibraryWithExecutableTarget(cmakeLists, srcRoot.getFileName().toString());
7674

7775
Path buildDir = distDir.resolve("build");

vm/tests/src/test/java/com/codename1/tools/translator/LambdaIntegrationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ void translatesLambdaBytecodeToLLVMExecutable(String targetVersion) throws Excep
118118
assertTrue(Files.exists(cmakeLists), "Translator should emit a CMake project");
119119

120120
Path srcRoot = distDir.resolve("LambdaApp-src");
121-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
122121

123122
CleanTargetIntegrationTest.replaceLibraryWithExecutableTarget(cmakeLists, srcRoot.getFileName().toString());
124123

vm/tests/src/test/java/com/codename1/tools/translator/LockIntegrationTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ void verifiesLockAndReentrantLockBehavior(CompilerHelper.CompilerConfig config)
7575
Path cmakeLists = distDir.resolve("CMakeLists.txt");
7676
assertTrue(Files.exists(cmakeLists));
7777

78-
Path srcRoot = distDir.resolve("LockTestApp-src");
79-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
80-
8178
Path buildDir = distDir.resolve("build");
8279
Files.createDirectories(buildDir);
8380

vm/tests/src/test/java/com/codename1/tools/translator/ReadWriteLockIntegrationTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ void verifiesReadWriteLockBehavior(CompilerHelper.CompilerConfig config) throws
7575
Path cmakeLists = distDir.resolve("CMakeLists.txt");
7676
assertTrue(Files.exists(cmakeLists));
7777

78-
Path srcRoot = distDir.resolve("ReadWriteLockTestApp-src");
79-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
80-
ensureReentrantReadWriteLockHeader(srcRoot);
81-
8278
Path buildDir = distDir.resolve("build");
8379
Files.createDirectories(buildDir);
8480

@@ -191,18 +187,4 @@ private String nativeReportSource() {
191187
}
192188

193189

194-
private void ensureReentrantReadWriteLockHeader(Path srcRoot) throws java.io.IOException {
195-
Path header = srcRoot.resolve("java_util_concurrent_locks_ReentrantReadWriteLock.h");
196-
if (!Files.exists(header)) {
197-
return;
198-
}
199-
String content = new String(Files.readAllBytes(header), StandardCharsets.UTF_8);
200-
if (content.contains("virtual_java_util_concurrent_locks_ReentrantReadWriteLock_readLock")) {
201-
return;
202-
}
203-
String additions = "JAVA_OBJECT virtual_java_util_concurrent_locks_ReentrantReadWriteLock_readLock___R_java_util_concurrent_locks_ReentrantReadWriteLock_ReadLock(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisObject);\n" +
204-
"JAVA_OBJECT virtual_java_util_concurrent_locks_ReentrantReadWriteLock_writeLock___R_java_util_concurrent_locks_ReentrantReadWriteLock_WriteLock(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisObject);\n";
205-
content = content.replace("#endif\n", additions + "#endif\n");
206-
Files.write(header, content.getBytes(StandardCharsets.UTF_8));
207-
}
208190
}

vm/tests/src/test/java/com/codename1/tools/translator/StampedLockIntegrationTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ void verifiesStampedLockBehavior(CompilerHelper.CompilerConfig config) throws Ex
7575
Path cmakeLists = distDir.resolve("CMakeLists.txt");
7676
assertTrue(Files.exists(cmakeLists));
7777

78-
Path srcRoot = distDir.resolve("StampedLockTestApp-src");
79-
CleanTargetIntegrationTest.patchCn1Globals(srcRoot);
80-
8178
Path buildDir = distDir.resolve("build");
8279
Files.createDirectories(buildDir);
8380

0 commit comments

Comments
 (0)