From a4d948f26b480defa3777a466a0ca456b0b011e8 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 13 Feb 2015 22:30:41 +0400 Subject: [PATCH] Fix bugs --- .../org/teavm/classlib/impl/JCLPlugin.java | 1 - .../classlib/impl/ObjectEnrichRenderer.java | 53 ----------- .../src/main/java/org/teavm/cache/AstIO.java | 6 +- .../java/org/teavm/javascript/Decompiler.java | 4 - .../java/org/teavm/javascript/Renderer.java | 88 +------------------ .../org/teavm/javascript/ast/MethodNode.java | 9 -- .../javascript/spi/PreserveOriginalName.java | 30 ------- .../src/main/java/org/teavm/vm/TeaVM.java | 4 +- .../resources/org/teavm/javascript/runtime.js | 12 +-- .../platform/plugin/EnumTransformer.java | 39 -------- .../teavm/platform/plugin/PlatformPlugin.java | 1 - 11 files changed, 9 insertions(+), 238 deletions(-) delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/impl/ObjectEnrichRenderer.java delete mode 100644 teavm-core/src/main/java/org/teavm/javascript/spi/PreserveOriginalName.java delete mode 100644 teavm-platform/src/main/java/org/teavm/platform/plugin/EnumTransformer.java diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java index 895bf3d49..8c51cc719 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java @@ -29,7 +29,6 @@ import org.teavm.vm.spi.TeaVMPlugin; public class JCLPlugin implements TeaVMPlugin { @Override public void install(TeaVMHost host) { - host.add(new ObjectEnrichRenderer()); ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader()); host.add(serviceLoaderSupp); MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices", diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/ObjectEnrichRenderer.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/ObjectEnrichRenderer.java deleted file mode 100644 index 35495b3b5..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/ObjectEnrichRenderer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.classlib.impl; - -import java.io.IOException; -import org.teavm.javascript.RenderingContext; -import org.teavm.model.ClassReader; -import org.teavm.model.MethodDescriptor; -import org.teavm.model.MethodReader; -import org.teavm.vm.BuildTarget; -import org.teavm.vm.spi.RendererListener; - -/** - * - * @author Alexey Andreev - */ -public class ObjectEnrichRenderer implements RendererListener { - private RenderingContext context; - - @Override - public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException { - this.context = context; - } - - @Override - public void complete() throws IOException { - ClassReader cls = context.getClassSource().get("java.lang.Object"); - MethodReader toString = cls.getMethod(new MethodDescriptor("toString", String.class)); - if (toString != null) { - String clsName = context.getNaming().getNameFor(cls.getName()); - String toStringName = context.getNaming().getNameFor(toString.getReference()); - context.getWriter().append(clsName).append(".prototype.toString").ws().append('=').ws() - .append("function()").ws().append('{').indent().softNewLine(); - context.getWriter().append("return this.").append(toStringName).ws().append('?').ws() - .append("$rt_ustr(this.").append(toStringName).append("())").ws().append(':') - .append("Object.prototype.toString.call(this);").softNewLine(); - context.getWriter().outdent().append("}").newLine(); - } - } -} diff --git a/teavm-core/src/main/java/org/teavm/cache/AstIO.java b/teavm-core/src/main/java/org/teavm/cache/AstIO.java index 6edeb906b..d9bac61e0 100644 --- a/teavm-core/src/main/java/org/teavm/cache/AstIO.java +++ b/teavm-core/src/main/java/org/teavm/cache/AstIO.java @@ -59,7 +59,6 @@ public class AstIO { } } } - output.writeBoolean(method.isOriginalNamePreserved()); try { method.getBody().acceptVisitor(new NodeWriter(output)); } catch (IOExceptionWrapper e) { @@ -83,7 +82,6 @@ public class AstIO { } node.getParameterDebugNames().add(debugNames); } - node.setOriginalNamePreserved(input.readBoolean()); node.setBody(readStatement(input)); return node; } @@ -511,12 +509,12 @@ public class AstIO { @Override public void visit(MonitorEnterStatement statement) { - + } @Override public void visit(MonitorExitStatement statement) { - + } } diff --git a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java index e74a06ea6..ff34cdb26 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java @@ -21,7 +21,6 @@ import org.teavm.javascript.ast.*; import org.teavm.javascript.spi.GeneratedBy; import org.teavm.javascript.spi.Generator; import org.teavm.javascript.spi.InjectedBy; -import org.teavm.javascript.spi.PreserveOriginalName; import org.teavm.model.*; import org.teavm.model.util.AsyncProgramSplitter; import org.teavm.model.util.ProgramUtils; @@ -146,9 +145,6 @@ public class Decompiler { } MethodNode methodNode = decompile(method); clsNode.getMethods().add(methodNode); - if (method.getAnnotations().get(PreserveOriginalName.class.getName()) != null) { - methodNode.setOriginalNamePreserved(true); - } } clsNode.getInterfaces().addAll(cls.getInterfaces()); clsNode.getModifiers().addAll(mapModifiers(cls.getModifiers())); diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index c0674b09f..ab173325e 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -278,7 +278,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext renderMethodBodies(cls); } renderClassMetadata(classes); - renderMethodStubs(classes); } private void renderDeclaration(ClassNode cls) throws RenderingException { @@ -364,8 +363,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } else { virtualMethods.add(method); } - } else if (method.isOriginalNamePreserved()) { - renderStaticDeclaration(method); } } } @@ -381,56 +378,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext debugEmitter.emitClass(null); } - private void renderMethodStubs(List classes) { - try { - boolean first = true; - writer.append("$rt_methodStubs(["); - for (int i = 0; i < classes.size(); ++i) { - ClassNode cls = classes.get(i); - MethodHolder clinit = classSource.get(cls.getName()).getMethod( - new MethodDescriptor("", ValueType.VOID)); - if (clinit == null) { - continue; - } - List stubNames = new ArrayList<>(); - for (MethodNode method : cls.getMethods()) { - if (method.getModifiers().contains(NodeModifier.STATIC) || - method.getReference().getName().equals("")) { - stubNames.add(naming.getFullNameFor(method.getReference())); - } - } - if (stubNames.isEmpty()) { - continue; - } - if (!first) { - writer.append(',').softNewLine(); - } - first = false; - writer.appendClass(cls.getName()).append("_$clinit").append(",").ws(); - if (stubNames.size() == 1) { - writer.append("'").append(stubNames.get(0)).append("'"); - } else { - writer.append('['); - for (int j = 0; j < stubNames.size(); ++j) { - if (j > 0) { - writer.append(",").ws(); - } - writer.append("'").append(stubNames.get(j)).append("'"); - } - writer.append(']'); - } - } - writer.append("]);").newLine(); - } catch (NamingException e) { - throw new RenderingException("Error rendering method stubs. See a cause for details", e); - } catch (IOException e) { - throw new RenderingException("IO error occured", e); - } - } - private void renderClassMetadata(List classes) { try { - writer.append("$rt_declClasses(["); + writer.append("$rt_metadata(["); boolean first = true; for (ClassNode cls : classes) { if (!first) { @@ -538,7 +488,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } writer.append(variableName(i)); } - writer.append(")").ws().append("{").newLine().indent(); + writer.append(")").ws().append("{").softNewLine().indent(); writer.append("var result").ws().append("=").ws().append("new ").appendClass( ref.getClassName()).append("();").softNewLine(); writer.append(naming.getFullNameFor(ref)).append("(result"); @@ -563,12 +513,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } first = false; String methodName = method.isAsync() ? naming.getNameForAsync(ref) : naming.getNameFor(ref); - if (method.isOriginalNamePreserved()) { - writer.append("[\"").append(methodName).append("\",").ws().append("\"").append(ref.getName()) - .append("\"]"); - } else { - writer.append("\"").append(methodName).append("\""); - } + writer.append("\"").append(methodName).append("\""); writer.append(",").ws().append("function("); List args = new ArrayList<>(); for (int i = 1; i <= ref.parameterCount(); ++i) { @@ -604,33 +549,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append("]"); } - private void renderStaticDeclaration(MethodNode method) throws NamingException, IOException { - MethodReference ref = method.getReference(); - debugEmitter.emitMethod(ref.getDescriptor()); - if (ref.getDescriptor().getName().equals("")) { - renderInitializer(method); - } - writer.appendClass(ref.getClassName()).append(".").appendMethod(ref).ws().append("=").ws().append("function("); - for (int i = 0; i < ref.parameterCount(); ++i) { - if (i > 0) { - writer.append(", "); - } - writer.append(variableName(i + 1)); - } - writer.append(")").ws().append("{").softNewLine().indent(); - writer.append("return ").appendMethodBody(ref).append("("); - for (int i = 0; i < ref.parameterCount(); ++i) { - writer.append(",").ws().append(variableName(i + 1)); - } - writer.append(");").softNewLine(); - writer.outdent().append("}").newLine(); - if (method.isOriginalNamePreserved()) { - writer.appendClass(ref.getClassName()).append(".").append(ref.getName()).ws().append("=") - .ws().appendClass(ref.getClassName()).append(".").appendMethod(ref).append(';').newLine(); - } - debugEmitter.emitMethod(null); - } - public void renderBody(MethodNode method, boolean inner) throws IOException { MethodReference ref = method.getReference(); debugEmitter.emitMethod(ref.getDescriptor()); diff --git a/teavm-core/src/main/java/org/teavm/javascript/ast/MethodNode.java b/teavm-core/src/main/java/org/teavm/javascript/ast/MethodNode.java index 952a1d154..53bb6356f 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ast/MethodNode.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ast/MethodNode.java @@ -26,7 +26,6 @@ import org.teavm.model.MethodReference; public abstract class MethodNode { private MethodReference reference; private Set modifiers = EnumSet.noneOf(NodeModifier.class); - private boolean originalNamePreserved; public MethodNode(MethodReference reference) { this.reference = reference; @@ -41,14 +40,6 @@ public abstract class MethodNode { return modifiers; } - public boolean isOriginalNamePreserved() { - return originalNamePreserved; - } - - public void setOriginalNamePreserved(boolean originalNamePreserved) { - this.originalNamePreserved = originalNamePreserved; - } - public abstract void acceptVisitor(MethodNodeVisitor visitor); public abstract boolean isAsync(); diff --git a/teavm-core/src/main/java/org/teavm/javascript/spi/PreserveOriginalName.java b/teavm-core/src/main/java/org/teavm/javascript/spi/PreserveOriginalName.java deleted file mode 100644 index 272affd09..000000000 --- a/teavm-core/src/main/java/org/teavm/javascript/spi/PreserveOriginalName.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.javascript.spi; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * @author Alexey Andreev - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface PreserveOriginalName { -} diff --git a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java index 9f442f5d9..fde6d1549 100644 --- a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java +++ b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java @@ -466,11 +466,11 @@ public class TeaVM implements TeaVMHost, ServiceRepository { if (wrapAsync) { sourceWriter.append(")"); } - sourceWriter.append(";").softNewLine(); + sourceWriter.append(";").newLine(); } for (Map.Entry entry : exportedClasses.entrySet()) { sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws() - .appendClass(entry.getValue()).append(";").softNewLine(); + .appendClass(entry.getValue()).append(";").newLine(); } for (RendererListener listener : rendererListeners) { listener.complete(); diff --git a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js index 48b4806aa..53cf7a43a 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -217,14 +217,6 @@ function $rt_voidcls() { } return $rt_voidclsCache; } -function $rt_clinit(cls) { - if (cls.$clinit) { - var f = cls.$clinit; - delete cls.$clinit; - f(); - } - return cls; -} function $rt_init(cls, constructor, args) { var obj = new cls(); cls.prototype[constructor].apply(obj, args); @@ -409,7 +401,7 @@ function $rt_metadata(data) { return function() { var clinit = cls.$clinit; cls.$clinit = function() {}; - cls.$clinit(); + clinit(); return window[name].apply(window, arguments); } })(cls, names[j]); @@ -417,7 +409,7 @@ function $rt_metadata(data) { var virtualMethods = data[i + 7]; for (var j = 0; j < virtualMethods.length; j += 2) { - name = virtualMethods[j + 0]; + var name = virtualMethods[j + 0]; var func = virtualMethods[j + 1]; if (typeof name === 'string') { name = [name]; diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumTransformer.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumTransformer.java deleted file mode 100644 index 4be7e36a0..000000000 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/EnumTransformer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.platform.plugin; - -import org.teavm.diagnostics.Diagnostics; -import org.teavm.javascript.spi.PreserveOriginalName; -import org.teavm.model.*; - -/** - * - * @author Alexey Andreev - */ -public class EnumTransformer implements ClassHolderTransformer { - @Override - public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) { - if (cls.getParent() != null && !cls.getParent().equals("java.lang.Enum")) { - return; - } - MethodHolder method = cls.getMethod(new MethodDescriptor("values", - ValueType.arrayOf(ValueType.object(cls.getName())))); - if (method == null) { - return; - } - method.getAnnotations().add(new AnnotationHolder(PreserveOriginalName.class.getName())); - } -} diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java index 710e0c718..17a53af71 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java @@ -33,6 +33,5 @@ public class PlatformPlugin implements TeaVMPlugin { host.add(new NewInstanceDependencySupport()); host.add(new ClassLookupDependencySupport()); host.add(new EnumDependencySupport()); - host.add(new EnumTransformer()); } }