mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Reduce amount of generated JSO aliases
This commit is contained in:
parent
03538071c4
commit
33d61412fb
|
@ -20,6 +20,8 @@ import java.util.Map;
|
||||||
import org.teavm.codegen.SourceWriter;
|
import org.teavm.codegen.SourceWriter;
|
||||||
import org.teavm.javascript.RenderingContext;
|
import org.teavm.javascript.RenderingContext;
|
||||||
import org.teavm.jso.impl.JSDependencyListener.ExposedClass;
|
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.model.MethodDescriptor;
|
||||||
import org.teavm.vm.BuildTarget;
|
import org.teavm.vm.BuildTarget;
|
||||||
import org.teavm.vm.spi.RendererListener;
|
import org.teavm.vm.spi.RendererListener;
|
||||||
|
@ -32,6 +34,7 @@ class JSAliasRenderer implements RendererListener {
|
||||||
private static String variableChars = "abcdefghijklmnopqrstuvwxyz";
|
private static String variableChars = "abcdefghijklmnopqrstuvwxyz";
|
||||||
private JSDependencyListener dependencyListener;
|
private JSDependencyListener dependencyListener;
|
||||||
private SourceWriter writer;
|
private SourceWriter writer;
|
||||||
|
private ClassReaderSource classSource;
|
||||||
|
|
||||||
public JSAliasRenderer(JSDependencyListener dependencyListener) {
|
public JSAliasRenderer(JSDependencyListener dependencyListener) {
|
||||||
this.dependencyListener = dependencyListener;
|
this.dependencyListener = dependencyListener;
|
||||||
|
@ -40,6 +43,7 @@ class JSAliasRenderer implements RendererListener {
|
||||||
@Override
|
@Override
|
||||||
public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException {
|
public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException {
|
||||||
writer = context.getWriter();
|
writer = context.getWriter();
|
||||||
|
classSource = context.getClassSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,11 +56,20 @@ class JSAliasRenderer implements RendererListener {
|
||||||
writer.append("var c;").softNewLine();
|
writer.append("var c;").softNewLine();
|
||||||
for (Map.Entry<String, ExposedClass> entry : dependencyListener.getExposedClasses().entrySet()) {
|
for (Map.Entry<String, ExposedClass> entry : dependencyListener.getExposedClasses().entrySet()) {
|
||||||
ExposedClass cls = entry.getValue();
|
ExposedClass cls = entry.getValue();
|
||||||
if (cls.methods.isEmpty()) {
|
ClassReader classReader = classSource.get(entry.getKey());
|
||||||
|
if (classReader == null || cls.methods.isEmpty()) {
|
||||||
continue;
|
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()) {
|
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())) {
|
if (isKeyword(aliasEntry.getValue())) {
|
||||||
writer.append("c[\"").append(aliasEntry.getValue()).append("\"]");
|
writer.append("c[\"").append(aliasEntry.getValue()).append("\"]");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -101,7 +101,7 @@ class JSDependencyListener extends AbstractDependencyListener {
|
||||||
private ExposedClass createExposedClass(String name) {
|
private ExposedClass createExposedClass(String name) {
|
||||||
ClassReader cls = classSource.get(name);
|
ClassReader cls = classSource.get(name);
|
||||||
ExposedClass exposedCls = new ExposedClass();
|
ExposedClass exposedCls = new ExposedClass();
|
||||||
if (cls == null) {
|
if (cls == null || cls.hasModifier(ElementModifier.INTERFACE)) {
|
||||||
return exposedCls;
|
return exposedCls;
|
||||||
}
|
}
|
||||||
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
|
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
|
||||||
|
@ -146,7 +146,8 @@ class JSDependencyListener extends AbstractDependencyListener {
|
||||||
if (addInterface(exposedCls, iface)) {
|
if (addInterface(exposedCls, iface)) {
|
||||||
added = true;
|
added = true;
|
||||||
for (MethodReader method : iface.getMethods()) {
|
for (MethodReader method : iface.getMethods()) {
|
||||||
if (method.hasModifier(ElementModifier.STATIC)) {
|
if (method.hasModifier(ElementModifier.STATIC)
|
||||||
|
|| (method.getProgram() != null && method.getProgram().basicBlockCount() > 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) {
|
if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user