diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/CharacterNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/CharacterNativeGenerator.java index 0a06f086c..6a4470e07 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/CharacterNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/CharacterNativeGenerator.java @@ -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": diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java index 88aa1666e..30b71de3b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java @@ -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(), "", + agent.linkMethod(new MethodReference(InstantiationException.class.getName(), "", ValueType.VOID), graph.getStack()).use(); break; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java index 20a5942c6..64c3c2d1a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java @@ -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"); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java index 34ccf207e..2dec76c28 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java @@ -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()); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java index 81b66a994..78c4de695 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java @@ -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()); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java index a3b9b6a12..0f65e69ed 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java @@ -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("", ValueType.VOID)); - checker.addEntryPoint(cons); + MethodReference cons = new MethodReference(IllegalArgumentException.class, "", 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]); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleNativeGenerator.java index 1a8fec60b..b81a1d1c1 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleNativeGenerator.java @@ -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": diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TimerNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TimerNativeGenerator.java index 387f44216..4d9177f5c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TimerNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TimerNativeGenerator.java @@ -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; } diff --git a/teavm-core/src/main/java/org/teavm/dependency/DependencyPlugin.java b/teavm-core/src/main/java/org/teavm/dependency/DependencyPlugin.java index a69fa55b2..29d650351 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyPlugin.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyPlugin.java @@ -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); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java index cb7e4b2a4..74157561c 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java @@ -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(); } } }