mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-08 16:04:10 -08:00
Missing native methods are reported through diagnostics. Better
rendering of problem stack trace.
This commit is contained in:
parent
9154f4eff9
commit
d55bd862d0
|
@ -59,7 +59,7 @@ public final class TeaVMProblemRenderer {
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sb.append("\n at ");
|
sb.append("\n at ");
|
||||||
renderCallLocation(location.getMethod(), location.getSourceLocation(), sb);
|
renderCallLocation(location.getMethod(), location.getSourceLocation(), sb);
|
||||||
if (location.getMethod() != null) {
|
if (location.getMethod() != null) {
|
||||||
CallGraphNode node = cg.getNode(location.getMethod());
|
CallGraphNode node = cg.getNode(location.getMethod());
|
||||||
|
@ -69,7 +69,7 @@ public final class TeaVMProblemRenderer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CallSite callSite = callSites.next();
|
CallSite callSite = callSites.next();
|
||||||
sb.append("\n at ");
|
sb.append("\n at ");
|
||||||
renderCallLocation(callSite.getCaller().getMethod(), callSite.getLocation(), sb);
|
renderCallLocation(callSite.getCaller().getMethod(), callSite.getLocation(), sb);
|
||||||
node = callSite.getCaller();
|
node = callSite.getCaller();
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,10 @@ public final class TeaVMProblemRenderer {
|
||||||
|
|
||||||
private static void renderCallLocation(MethodReference method, InstructionLocation location, StringBuilder sb) {
|
private static void renderCallLocation(MethodReference method, InstructionLocation location, StringBuilder sb) {
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
sb.append(method);
|
sb.append(method.getClassName() + "." + method.getName());
|
||||||
} else {
|
} else {
|
||||||
sb.append("unknown method");
|
sb.append("unknown method");
|
||||||
}
|
}
|
||||||
sb.append(' ');
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
sb.append("(");
|
sb.append("(");
|
||||||
String fileName = location.getFileName();
|
String fileName = location.getFileName();
|
||||||
|
|
|
@ -26,9 +26,12 @@ import org.teavm.diagnostics.AccumulationDiagnostics;
|
||||||
import org.teavm.diagnostics.ProblemProvider;
|
import org.teavm.diagnostics.ProblemProvider;
|
||||||
import org.teavm.javascript.*;
|
import org.teavm.javascript.*;
|
||||||
import org.teavm.javascript.ast.ClassNode;
|
import org.teavm.javascript.ast.ClassNode;
|
||||||
|
import org.teavm.javascript.ni.GeneratedBy;
|
||||||
import org.teavm.javascript.ni.Generator;
|
import org.teavm.javascript.ni.Generator;
|
||||||
|
import org.teavm.javascript.ni.InjectedBy;
|
||||||
import org.teavm.javascript.ni.Injector;
|
import org.teavm.javascript.ni.Injector;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
|
import org.teavm.model.instructions.*;
|
||||||
import org.teavm.model.util.*;
|
import org.teavm.model.util.*;
|
||||||
import org.teavm.optimization.*;
|
import org.teavm.optimization.*;
|
||||||
import org.teavm.vm.spi.RendererListener;
|
import org.teavm.vm.spi.RendererListener;
|
||||||
|
@ -537,6 +540,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
ClassHolder cls = classes.get(className);
|
ClassHolder cls = classes.get(className);
|
||||||
for (MethodHolder method : cls.getMethods()) {
|
for (MethodHolder method : cls.getMethods()) {
|
||||||
processMethod(method);
|
processMethod(method);
|
||||||
|
preprocessNativeMethod(method);
|
||||||
if (bytecodeLogging) {
|
if (bytecodeLogging) {
|
||||||
logMethodBytecode(bytecodeLogger, method);
|
logMethodBytecode(bytecodeLogger, method);
|
||||||
}
|
}
|
||||||
|
@ -550,6 +554,46 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
return classNodes;
|
return classNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void preprocessNativeMethod(MethodHolder method) {
|
||||||
|
if (!method.getModifiers().contains(ElementModifier.NATIVE) ||
|
||||||
|
methodGenerators.get(method.getReference()) != null ||
|
||||||
|
methodInjectors.get(method.getReference()) != null ||
|
||||||
|
method.getAnnotations().get(GeneratedBy.class.getName()) != null ||
|
||||||
|
method.getAnnotations().get(InjectedBy.class.getName()) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
method.getModifiers().remove(ElementModifier.NATIVE);
|
||||||
|
|
||||||
|
Program program = new Program();
|
||||||
|
method.setProgram(program);
|
||||||
|
BasicBlock block = program.createBasicBlock();
|
||||||
|
Variable exceptionVar = program.createVariable();
|
||||||
|
ConstructInstruction newExceptionInsn = new ConstructInstruction();
|
||||||
|
newExceptionInsn.setType(NoSuchMethodError.class.getName());
|
||||||
|
newExceptionInsn.setReceiver(exceptionVar);
|
||||||
|
block.getInstructions().add(newExceptionInsn);
|
||||||
|
|
||||||
|
Variable constVar = program.createVariable();
|
||||||
|
StringConstantInstruction constInsn = new StringConstantInstruction();
|
||||||
|
constInsn.setConstant("Native method implementation not found: " + method.getReference());
|
||||||
|
constInsn.setReceiver(constVar);
|
||||||
|
block.getInstructions().add(constInsn);
|
||||||
|
|
||||||
|
InvokeInstruction initExceptionInsn = new InvokeInstruction();
|
||||||
|
initExceptionInsn.setInstance(exceptionVar);
|
||||||
|
initExceptionInsn.setMethod(new MethodReference(NoSuchMethodError.class, "<init>", String.class, void.class));
|
||||||
|
initExceptionInsn.setType(InvocationType.SPECIAL);
|
||||||
|
initExceptionInsn.getArguments().add(constVar);
|
||||||
|
block.getInstructions().add(initExceptionInsn);
|
||||||
|
|
||||||
|
RaiseInstruction raiseInsn = new RaiseInstruction();
|
||||||
|
raiseInsn.setException(exceptionVar);
|
||||||
|
block.getInstructions().add(raiseInsn);
|
||||||
|
|
||||||
|
diagnostics.error(new CallLocation(method.getReference()), "Native method {{m0}} has no implementation",
|
||||||
|
method.getReference());
|
||||||
|
}
|
||||||
|
|
||||||
private void processMethod(MethodHolder method) {
|
private void processMethod(MethodHolder method) {
|
||||||
if (method.getProgram() == null) {
|
if (method.getProgram() == null) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user