diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java index e2613aee8..3f3a0d5fe 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java @@ -180,7 +180,7 @@ public class RuntimeRenderer { return false; } MethodReader method = cls.getMethod(STRING_INTERN_METHOD); - return method != null && method.getProgram() != null; + return method != null && method.hasModifier(ElementModifier.NATIVE); } private void renderRuntimeObjcls() throws IOException { diff --git a/core/src/main/java/org/teavm/model/PreOptimizingClassHolderSource.java b/core/src/main/java/org/teavm/model/PreOptimizingClassHolderSource.java index 0cbca685c..6b0852601 100644 --- a/core/src/main/java/org/teavm/model/PreOptimizingClassHolderSource.java +++ b/core/src/main/java/org/teavm/model/PreOptimizingClassHolderSource.java @@ -49,8 +49,10 @@ public class PreOptimizingClassHolderSource implements ClassHolderSource { return cls; } for (MethodHolder method : cls.getMethods()) { - new GlobalValueNumbering(true).optimize(method.getProgram()); - new UnusedVariableElimination().optimize(method, method.getProgram()); + if (method.getProgram() != null) { + new GlobalValueNumbering(true).optimize(method.getProgram()); + new UnusedVariableElimination().optimize(method, method.getProgram()); + } } return cls; } diff --git a/core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java b/core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java index 6d5b6d1b1..40a079964 100644 --- a/core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java +++ b/core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java @@ -129,7 +129,9 @@ public class ClassRefsRenamer extends AbstractInstructionVisitor { renamedMethod.setLevel(method.getLevel()); renamedMethod.setProgram(method.getProgram()); rename(method.getAnnotations(), renamedMethod.getAnnotations()); - rename(renamedMethod.getProgram()); + if (renamedMethod.getProgram() != null) { + rename(renamedMethod.getProgram()); + } renamedMethod.setTypeParameters(rename(method.getTypeParameters())); GenericValueType genericResultType = method.getGenericResultType(); diff --git a/core/src/main/java/org/teavm/parsing/Parser.java b/core/src/main/java/org/teavm/parsing/Parser.java index 527b96c0d..a2d7b6218 100644 --- a/core/src/main/java/org/teavm/parsing/Parser.java +++ b/core/src/main/java/org/teavm/parsing/Parser.java @@ -79,23 +79,27 @@ public class Parser { ValueType[] signature = MethodDescriptor.parseSignature(node.desc); MethodHolder method = new MethodHolder(referenceCache.getCached(new MethodDescriptor(node.name, signature))); parseModifiers(node.access, method, DECL_METHOD); - - ProgramParser programParser = new ProgramParser(referenceCache); - programParser.setFileName(fileName); - Program program = programParser.parse(node); - new UnreachableBasicBlockEliminator().optimize(program); - PhiUpdater phiUpdater = new PhiUpdater(); - Variable[] argumentMapping = applySignature(program, method.getParameterTypes()); - phiUpdater.updatePhis(program, argumentMapping); - method.setProgram(program); - applyDebugNames(program, phiUpdater, programParser, argumentMapping); - parseAnnotations(method.getAnnotations(), node.visibleAnnotations, node.invisibleAnnotations); - applyDebugNames(program, phiUpdater, programParser, - applySignature(program, method.getDescriptor().getParameterTypes())); - while (program.variableCount() <= method.parameterCount()) { - program.createVariable(); + + if (node.instructions.size() > 0) { + ProgramParser programParser = new ProgramParser(referenceCache); + programParser.setFileName(fileName); + Program program = programParser.parse(node); + new UnreachableBasicBlockEliminator().optimize(program); + PhiUpdater phiUpdater = new PhiUpdater(); + Variable[] argumentMapping = applySignature(program, method.getParameterTypes()); + phiUpdater.updatePhis(program, argumentMapping); + method.setProgram(program); + applyDebugNames(program, phiUpdater, programParser, argumentMapping); + + applyDebugNames(program, phiUpdater, programParser, + applySignature(program, method.getDescriptor().getParameterTypes())); + + while (program.variableCount() <= method.parameterCount()) { + program.createVariable(); + } } + if (node.annotationDefault != null) { method.setAnnotationDefault(parseAnnotationValue(node.annotationDefault)); }