mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
metaprogramming: fix crashing instead of fair error reporting
This commit is contained in:
parent
389f689dab
commit
bdbce01b9a
|
@ -119,7 +119,7 @@ public class CompositeMethodGenerator {
|
|||
}
|
||||
|
||||
CompositeMethodGenerator(VariableContext varContext, Program program) {
|
||||
this.diagnostics = MetaprogrammingImpl.agent.getDiagnostics();
|
||||
this.diagnostics = MetaprogrammingImpl.createDiagnostics();
|
||||
this.program = program;
|
||||
this.varContext = varContext;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene
|
|||
@Override
|
||||
public void started(DependencyAgent agent) {
|
||||
proxyClassLoader = new MetaprogrammingClassLoader(agent.getClassLoader());
|
||||
describer = new MethodDescriber(agent.getDiagnostics(), agent.getClassSource());
|
||||
describer = new MethodDescriber(MetaprogrammingImpl.createDiagnostics(), agent.getClassSource());
|
||||
|
||||
MetaprogrammingImpl.classLoader = proxyClassLoader;
|
||||
MetaprogrammingImpl.classSource = agent.getClassSource();
|
||||
|
|
|
@ -73,6 +73,7 @@ public final class MetaprogrammingImpl {
|
|||
static CompositeMethodGenerator generator;
|
||||
static ValueType returnType;
|
||||
static boolean unsupportedCase;
|
||||
static boolean error;
|
||||
|
||||
private MetaprogrammingImpl() {
|
||||
}
|
||||
|
@ -405,6 +406,7 @@ public final class MetaprogrammingImpl {
|
|||
public void error(SourceLocation location, String error, Object... params) {
|
||||
convertParams(params);
|
||||
agent.getDiagnostics().error(convertLocation(location), error, params);
|
||||
MetaprogrammingImpl.error = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -438,4 +440,19 @@ public final class MetaprogrammingImpl {
|
|||
: new CallLocation(method.getReference());
|
||||
}
|
||||
};
|
||||
|
||||
public static org.teavm.diagnostics.Diagnostics createDiagnostics() {
|
||||
return new org.teavm.diagnostics.Diagnostics() {
|
||||
@Override
|
||||
public void error(CallLocation location, String error, Object... params) {
|
||||
MetaprogrammingImpl.error = true;
|
||||
agent.getDiagnostics().error(location, error, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(CallLocation location, String error, Object... params) {
|
||||
agent.getDiagnostics().warning(location, error, params);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ class UsageGenerator {
|
|||
String suffix = getSuffix();
|
||||
implRef = buildMethodReference(suffix);
|
||||
MetaprogrammingImpl.templateMethod = model.getMetaMethod();
|
||||
VariableContext varContext = new TopLevelVariableContext(diagnostics);
|
||||
VariableContext varContext = new TopLevelVariableContext(MetaprogrammingImpl.createDiagnostics());
|
||||
MetaprogrammingImpl.generator = new CompositeMethodGenerator(varContext);
|
||||
MetaprogrammingImpl.varContext = varContext;
|
||||
MetaprogrammingImpl.returnType = model.getMethod().getReturnType();
|
||||
|
@ -154,6 +154,7 @@ class UsageGenerator {
|
|||
}
|
||||
|
||||
MetaprogrammingImpl.unsupportedCase = false;
|
||||
MetaprogrammingImpl.error = false;
|
||||
|
||||
try {
|
||||
proxyMethod.invoke(null, proxyArgs);
|
||||
|
@ -162,10 +163,11 @@ class UsageGenerator {
|
|||
e.printStackTrace(new PrintWriter(writer));
|
||||
diagnostics.error(location, "Error calling proxy method {{m0}}: " + writer.toString(),
|
||||
model.getMetaMethod());
|
||||
MetaprogrammingImpl.error = true;
|
||||
}
|
||||
|
||||
MetaprogrammingImpl.close();
|
||||
if (MetaprogrammingImpl.unsupportedCase) {
|
||||
if (MetaprogrammingImpl.unsupportedCase || MetaprogrammingImpl.error) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user