Dependency plugin receives DependencyAgent instead of DependencyChecker

This commit is contained in:
konsoletyper 2014-06-09 21:26:58 +04:00
parent da2a26fb4f
commit c3e30cc295
10 changed files with 46 additions and 55 deletions

View File

@ -19,7 +19,7 @@ import java.io.IOException;
import org.teavm.classlib.impl.unicode.UnicodeHelper;
import org.teavm.classlib.impl.unicode.UnicodeSupport;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyAgent;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.javascript.ni.Generator;
@ -52,7 +52,7 @@ public class CharacterNativeGenerator implements Generator, DependencyPlugin {
}
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "obtainDigitMapping":
case "obtainClasses":

View File

@ -17,7 +17,7 @@ package org.teavm.classlib.java.lang;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyAgent;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.javascript.ni.Generator;
@ -186,7 +186,7 @@ public class ClassNativeGenerator implements Generator, Injector, DependencyPlug
}
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency graph) {
public void methodAchieved(DependencyAgent agent, MethodDependency graph) {
switch (graph.getReference().getName()) {
case "voidClass":
case "booleanClass":
@ -205,7 +205,7 @@ public class ClassNativeGenerator implements Generator, Injector, DependencyPlug
graph.getResult().propagate("java.lang.Class");
break;
case "newInstance":
checker.linkMethod(new MethodReference(InstantiationException.class.getName(), "<init>",
agent.linkMethod(new MethodReference(InstantiationException.class.getName(), "<init>",
ValueType.VOID), graph.getStack()).use();
break;
}

View File

@ -17,16 +17,12 @@ package org.teavm.classlib.java.lang;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.dependency.*;
import org.teavm.javascript.ni.Generator;
import org.teavm.javascript.ni.GeneratorContext;
import org.teavm.javascript.ni.Injector;
import org.teavm.javascript.ni.InjectorContext;
import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
/**
*
@ -62,13 +58,13 @@ public class ObjectNativeGenerator implements Generator, Injector, DependencyPlu
}
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "clone":
method.getVariable(0).connect(method.getResult());
break;
case "getClass":
achieveGetClass(checker, method);
achieveGetClass(agent, method);
break;
case "wrap":
method.getVariable(1).connect(method.getResult());
@ -87,11 +83,9 @@ public class ObjectNativeGenerator implements Generator, Injector, DependencyPlu
writer.append(".constructor)");
}
private void achieveGetClass(DependencyChecker checker, MethodDependency method) {
String classClass = "java.lang.Class";
MethodReference initMethod = new MethodReference(classClass, new MethodDescriptor("createNew",
ValueType.object(classClass)));
checker.addEntryPoint(initMethod);
private void achieveGetClass(DependencyAgent agent, MethodDependency method) {
MethodReference initMethod = new MethodReference(Class.class, "createNew", Class.class);
agent.linkMethod(initMethod, method.getStack()).use();
method.getResult().propagate("java.lang.Class");
}

View File

@ -16,7 +16,7 @@
package org.teavm.classlib.java.lang;
import java.io.IOException;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyAgent;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.javascript.ni.Injector;
@ -29,7 +29,7 @@ import org.teavm.model.MethodReference;
*/
public class StringNativeGenerator implements Injector, DependencyPlugin {
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "wrap":
method.getVariable(1).connect(method.getResult());

View File

@ -54,16 +54,16 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
}
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "doArrayCopy":
achieveArrayCopy(method);
break;
case "setOut":
achieveSetOut(checker, method);
achieveSetOut(agent, method);
break;
case "setErr":
achieveSetErr(checker, method);
achieveSetErr(agent, method);
break;
}
}
@ -97,13 +97,13 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
src.getArrayItem().connect(dest.getArrayItem());
}
private void achieveSetErr(DependencyChecker checker, MethodDependency method) {
FieldDependency fieldDep = checker.linkField(new FieldReference("java.lang.System", "err"), method.getStack());
private void achieveSetErr(DependencyAgent agent, MethodDependency method) {
FieldDependency fieldDep = agent.linkField(new FieldReference("java.lang.System", "err"), method.getStack());
method.getVariable(1).connect(fieldDep.getValue());
}
private void achieveSetOut(DependencyChecker checker, MethodDependency method) {
FieldDependency fieldDep = checker.linkField(new FieldReference("java.lang.System", "out"), method.getStack());
private void achieveSetOut(DependencyAgent agent, MethodDependency method) {
FieldDependency fieldDep = agent.linkField(new FieldReference("java.lang.System", "out"), method.getStack());
method.getVariable(1).connect(fieldDep.getValue());
}
}

View File

@ -17,10 +17,7 @@ package org.teavm.classlib.java.lang.reflect;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyConsumer;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.dependency.*;
import org.teavm.javascript.ni.Generator;
import org.teavm.javascript.ni.GeneratorContext;
import org.teavm.model.ClassReader;
@ -41,16 +38,16 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
ValueType.INTEGER, ValueType.LONG, ValueType.FLOAT, ValueType.DOUBLE, ValueType.BOOLEAN };
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "getLength":
achieveGetLength(checker, method);
achieveGetLength(agent, method);
break;
case "newInstanceImpl":
method.getResult().propagate("[java.lang.Object");
break;
case "getImpl":
achieveGet(checker, method);
achieveGet(agent, method);
break;
}
}
@ -81,13 +78,12 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
writer.append("return " + array + ".data.length;").softNewLine();
}
private void achieveGetLength(final DependencyChecker checker, final MethodDependency method) {
private void achieveGetLength(final DependencyAgent agent, final MethodDependency method) {
method.getVariable(1).addConsumer(new DependencyConsumer() {
@Override public void consume(String type) {
if (!type.startsWith("[")) {
MethodReference cons = new MethodReference("java.lang.IllegalArgumentException",
new MethodDescriptor("<init>", ValueType.VOID));
checker.addEntryPoint(cons);
MethodReference cons = new MethodReference(IllegalArgumentException.class, "<init>", void.class);
agent.linkMethod(cons, method.getStack()).use();
}
}
});
@ -129,7 +125,7 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
writer.outdent().append("}").softNewLine();
}
private void achieveGet(final DependencyChecker checker, final MethodDependency method) {
private void achieveGet(final DependencyAgent agent, final MethodDependency method) {
method.getVariable(1).getArrayItem().connect(method.getResult());
method.getVariable(1).addConsumer(new DependencyConsumer() {
@Override public void consume(String type) {
@ -140,7 +136,7 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
String wrapper = "java.lang." + primitiveWrappers[i];
MethodReference methodRef = new MethodReference(wrapper, "valueOf",
primitiveTypes[i], ValueType.object(wrapper));
checker.linkMethod(methodRef, method.getStack()).use();
agent.linkMethod(methodRef, method.getStack()).use();
method.getResult().propagate("java.lang." + primitiveWrappers[i]);
}
}

View File

@ -17,7 +17,7 @@ package org.teavm.classlib.java.util;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyAgent;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.javascript.ni.Generator;
@ -63,7 +63,7 @@ public class LocaleNativeGenerator implements Generator, DependencyPlugin {
}
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getMethod().getName()) {
case "getDefaultLocale":
case "getDisplayCountry":

View File

@ -17,7 +17,7 @@ package org.teavm.classlib.java.util;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyAgent;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.javascript.ni.Generator;
@ -34,10 +34,11 @@ public class TimerNativeGenerator implements Generator, DependencyPlugin {
"performOnce", ValueType.VOID);
@Override
public void methodAchieved(DependencyChecker checker, MethodDependency method) {
public void methodAchieved(DependencyAgent agent, MethodDependency method) {
switch (method.getReference().getName()) {
case "scheduleOnce": {
MethodDependency performMethod = checker.linkMethod(performOnceRef, method.getStack());
MethodDependency performMethod = agent.linkMethod(performOnceRef, method.getStack());
performMethod.use();
method.getVariable(1).connect(performMethod.getVariable(1));
break;
}

View File

@ -20,5 +20,5 @@ package org.teavm.dependency;
* @author Alexey Andreev
*/
public interface DependencyPlugin {
void methodAchieved(DependencyChecker checker, MethodDependency method);
void methodAchieved(DependencyAgent checker, MethodDependency method);
}

View File

@ -17,10 +17,7 @@ package org.teavm.jso;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyConsumer;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.dependency.*;
import org.teavm.javascript.ast.ConstantExpr;
import org.teavm.javascript.ast.Expr;
import org.teavm.javascript.ast.InvocationExpr;
@ -28,7 +25,10 @@ import org.teavm.javascript.ni.Generator;
import org.teavm.javascript.ni.GeneratorContext;
import org.teavm.javascript.ni.Injector;
import org.teavm.javascript.ni.InjectorContext;
import org.teavm.model.*;
import org.teavm.model.ClassReader;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference;
/**
*
@ -115,24 +115,24 @@ public class JSNativeGenerator implements Generator, Injector, DependencyPlugin
}
@Override
public void methodAchieved(final DependencyChecker checker, final MethodDependency method) {
public void methodAchieved(final DependencyAgent agent, final MethodDependency method) {
for (int i = 0; i < method.getReference().parameterCount(); ++i) {
method.getVariable(i).addConsumer(new DependencyConsumer() {
@Override public void consume(String type) {
achieveFunctorMethods(checker, type, method);
achieveFunctorMethods(agent, type, method);
}
});
}
}
private void achieveFunctorMethods(DependencyChecker checker, String type, MethodDependency caller) {
private void achieveFunctorMethods(DependencyAgent agent, String type, MethodDependency caller) {
if (caller.isMissing()) {
return;
}
ClassReader cls = checker.getClassSource().get(type);
ClassReader cls = agent.getClassSource().get(type);
if (cls != null) {
for (MethodReader method : cls.getMethods()) {
checker.linkMethod(method.getReference(), caller.getStack()).use();
agent.linkMethod(method.getReference(), caller.getStack()).use();
}
}
}