Reduce amount of generated JSO aliases

This commit is contained in:
Alexey Andreev 2015-12-25 22:39:25 +03:00
parent 03538071c4
commit 33d61412fb
2 changed files with 18 additions and 4 deletions

View File

@ -20,6 +20,8 @@ import java.util.Map;
import org.teavm.codegen.SourceWriter;
import org.teavm.javascript.RenderingContext;
import org.teavm.jso.impl.JSDependencyListener.ExposedClass;
import org.teavm.model.ClassReader;
import org.teavm.model.ClassReaderSource;
import org.teavm.model.MethodDescriptor;
import org.teavm.vm.BuildTarget;
import org.teavm.vm.spi.RendererListener;
@ -32,6 +34,7 @@ class JSAliasRenderer implements RendererListener {
private static String variableChars = "abcdefghijklmnopqrstuvwxyz";
private JSDependencyListener dependencyListener;
private SourceWriter writer;
private ClassReaderSource classSource;
public JSAliasRenderer(JSDependencyListener dependencyListener) {
this.dependencyListener = dependencyListener;
@ -40,6 +43,7 @@ class JSAliasRenderer implements RendererListener {
@Override
public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException {
writer = context.getWriter();
classSource = context.getClassSource();
}
@Override
@ -52,11 +56,20 @@ class JSAliasRenderer implements RendererListener {
writer.append("var c;").softNewLine();
for (Map.Entry<String, ExposedClass> entry : dependencyListener.getExposedClasses().entrySet()) {
ExposedClass cls = entry.getValue();
if (cls.methods.isEmpty()) {
ClassReader classReader = classSource.get(entry.getKey());
if (classReader == null || cls.methods.isEmpty()) {
continue;
}
writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;").softNewLine();
boolean first = true;
for (Map.Entry<MethodDescriptor, String> aliasEntry : cls.methods.entrySet()) {
if (classReader.getMethod(aliasEntry.getKey()) == null) {
continue;
}
if (first) {
writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;")
.softNewLine();
first = false;
}
if (isKeyword(aliasEntry.getValue())) {
writer.append("c[\"").append(aliasEntry.getValue()).append("\"]");
} else {

View File

@ -101,7 +101,7 @@ class JSDependencyListener extends AbstractDependencyListener {
private ExposedClass createExposedClass(String name) {
ClassReader cls = classSource.get(name);
ExposedClass exposedCls = new ExposedClass();
if (cls == null) {
if (cls == null || cls.hasModifier(ElementModifier.INTERFACE)) {
return exposedCls;
}
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
@ -146,7 +146,8 @@ class JSDependencyListener extends AbstractDependencyListener {
if (addInterface(exposedCls, iface)) {
added = true;
for (MethodReader method : iface.getMethods()) {
if (method.hasModifier(ElementModifier.STATIC)) {
if (method.hasModifier(ElementModifier.STATIC)
|| (method.getProgram() != null && method.getProgram().basicBlockCount() > 0)) {
continue;
}
if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) {