From 888710102ff25477a2916f6528bb31dddc049c0a Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 28 Jul 2016 11:23:41 +0300 Subject: [PATCH] Refactoring --- .../cache}/EmptyRegularMethodNodeCache.java | 8 +- .../InMemoryRegularMethodNodeCache.java | 8 +- .../cache}/MethodNodeCache.java | 8 +- .../decompilation}/AsyncCallsFinder.java | 4 +- .../DecompilationException.java | 8 +- .../decompilation}/Decompiler.java | 18 +-- .../decompilation}/StatementGenerator.java | 4 +- .../optimization}/AllBlocksCountVisitor.java | 4 +- .../optimization}/BlockCountVisitor.java | 4 +- .../optimization}/BreakEliminator.java | 8 +- .../BreakToContinueReplacer.java | 4 +- .../EscapingStatementFinder.java | 4 +- .../optimization}/ExprOptimizer.java | 4 +- .../optimization}/Optimizer.java | 4 +- .../optimization}/OptimizingVisitor.java | 7 +- .../optimization}/ReadWriteStatsBuilder.java | 4 +- .../RedundantLabelEliminator.java | 4 +- .../UnusedVariableEliminator.java | 4 +- .../cache/DiskRegularMethodNodeCache.java | 2 +- .../teavm/javascript/AsyncInvocationType.java | 4 - .../NullPointerExceptionTransformer.java | 4 - .../java/org/teavm/javascript/Precedence.java | 4 - .../javascript/ReferenceCountingVisitor.java | 144 ------------------ .../java/org/teavm/javascript/Renderer.java | 30 +++- .../teavm/javascript/RenderingContext.java | 4 - .../teavm/javascript/RenderingException.java | 4 - .../org/teavm/javascript/RuntimeSupport.java | 4 - .../org/teavm/javascript/TryCatchFinder.java | 4 - .../org/teavm/javascript/spi/InjectedBy.java | 4 - .../resources/org/teavm/javascript/runtime.js | 55 +++++++ 30 files changed, 124 insertions(+), 248 deletions(-) rename core/src/main/java/org/teavm/{javascript => ast/cache}/EmptyRegularMethodNodeCache.java (92%) rename core/src/main/java/org/teavm/{javascript => ast/cache}/InMemoryRegularMethodNodeCache.java (93%) rename core/src/main/java/org/teavm/{javascript => ast/cache}/MethodNodeCache.java (90%) rename core/src/main/java/org/teavm/{javascript => ast/decompilation}/AsyncCallsFinder.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/decompilation}/DecompilationException.java (91%) rename core/src/main/java/org/teavm/{javascript => ast/decompilation}/Decompiler.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/decompilation}/StatementGenerator.java (99%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/AllBlocksCountVisitor.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/BlockCountVisitor.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/BreakEliminator.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/BreakToContinueReplacer.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/EscapingStatementFinder.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/ExprOptimizer.java (97%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/Optimizer.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/OptimizingVisitor.java (99%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/ReadWriteStatsBuilder.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/RedundantLabelEliminator.java (98%) rename core/src/main/java/org/teavm/{javascript => ast/optimization}/UnusedVariableEliminator.java (99%) delete mode 100644 core/src/main/java/org/teavm/javascript/ReferenceCountingVisitor.java diff --git a/core/src/main/java/org/teavm/javascript/EmptyRegularMethodNodeCache.java b/core/src/main/java/org/teavm/ast/cache/EmptyRegularMethodNodeCache.java similarity index 92% rename from core/src/main/java/org/teavm/javascript/EmptyRegularMethodNodeCache.java rename to core/src/main/java/org/teavm/ast/cache/EmptyRegularMethodNodeCache.java index 31fd84396..4d8c077d0 100644 --- a/core/src/main/java/org/teavm/javascript/EmptyRegularMethodNodeCache.java +++ b/core/src/main/java/org/teavm/ast/cache/EmptyRegularMethodNodeCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.cache; import org.teavm.ast.AsyncMethodNode; import org.teavm.ast.RegularMethodNode; import org.teavm.model.MethodReference; -/** - * - * @author Alexey Andreev - */ public class EmptyRegularMethodNodeCache implements MethodNodeCache { @Override public RegularMethodNode get(MethodReference methodReference) { diff --git a/core/src/main/java/org/teavm/javascript/InMemoryRegularMethodNodeCache.java b/core/src/main/java/org/teavm/ast/cache/InMemoryRegularMethodNodeCache.java similarity index 93% rename from core/src/main/java/org/teavm/javascript/InMemoryRegularMethodNodeCache.java rename to core/src/main/java/org/teavm/ast/cache/InMemoryRegularMethodNodeCache.java index 83dc70976..ba8bd9321 100644 --- a/core/src/main/java/org/teavm/javascript/InMemoryRegularMethodNodeCache.java +++ b/core/src/main/java/org/teavm/ast/cache/InMemoryRegularMethodNodeCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.cache; import java.util.HashMap; import java.util.Map; @@ -21,10 +21,6 @@ import org.teavm.ast.AsyncMethodNode; import org.teavm.ast.RegularMethodNode; import org.teavm.model.MethodReference; -/** - * - * @author Alexey Andreev - */ public class InMemoryRegularMethodNodeCache implements MethodNodeCache { private Map cache = new HashMap<>(); private Map asyncCache = new HashMap<>(); diff --git a/core/src/main/java/org/teavm/javascript/MethodNodeCache.java b/core/src/main/java/org/teavm/ast/cache/MethodNodeCache.java similarity index 90% rename from core/src/main/java/org/teavm/javascript/MethodNodeCache.java rename to core/src/main/java/org/teavm/ast/cache/MethodNodeCache.java index 118140ca7..8f189c738 100644 --- a/core/src/main/java/org/teavm/javascript/MethodNodeCache.java +++ b/core/src/main/java/org/teavm/ast/cache/MethodNodeCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.cache; import org.teavm.ast.AsyncMethodNode; import org.teavm.ast.RegularMethodNode; import org.teavm.model.MethodReference; -/** - * - * @author Alexey Andreev - */ public interface MethodNodeCache { RegularMethodNode get(MethodReference methodReference); diff --git a/core/src/main/java/org/teavm/javascript/AsyncCallsFinder.java b/core/src/main/java/org/teavm/ast/decompilation/AsyncCallsFinder.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/AsyncCallsFinder.java rename to core/src/main/java/org/teavm/ast/decompilation/AsyncCallsFinder.java index c5755cdcd..7c6328a34 100644 --- a/core/src/main/java/org/teavm/javascript/AsyncCallsFinder.java +++ b/core/src/main/java/org/teavm/ast/decompilation/AsyncCallsFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.decompilation; import java.util.HashSet; import java.util.List; diff --git a/core/src/main/java/org/teavm/javascript/DecompilationException.java b/core/src/main/java/org/teavm/ast/decompilation/DecompilationException.java similarity index 91% rename from core/src/main/java/org/teavm/javascript/DecompilationException.java rename to core/src/main/java/org/teavm/ast/decompilation/DecompilationException.java index 8cd49ccf5..1eb5d1fa6 100644 --- a/core/src/main/java/org/teavm/javascript/DecompilationException.java +++ b/core/src/main/java/org/teavm/ast/decompilation/DecompilationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.decompilation; -/** - * - * @author Alexey Andreev - */ public class DecompilationException extends RuntimeException { private static final long serialVersionUID = -1400142974526572669L; diff --git a/core/src/main/java/org/teavm/javascript/Decompiler.java b/core/src/main/java/org/teavm/ast/decompilation/Decompiler.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/Decompiler.java rename to core/src/main/java/org/teavm/ast/decompilation/Decompiler.java index 2dcef0a85..fe65cbd55 100644 --- a/core/src/main/java/org/teavm/javascript/Decompiler.java +++ b/core/src/main/java/org/teavm/ast/decompilation/Decompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.decompilation; import java.util.ArrayDeque; import java.util.ArrayList; @@ -44,6 +44,8 @@ import org.teavm.ast.SequentialStatement; import org.teavm.ast.Statement; import org.teavm.ast.TryCatchStatement; import org.teavm.ast.WhileStatement; +import org.teavm.ast.cache.MethodNodeCache; +import org.teavm.ast.optimization.Optimizer; import org.teavm.cache.NoCache; import org.teavm.common.Graph; import org.teavm.common.GraphIndexer; @@ -70,10 +72,6 @@ import org.teavm.model.util.AsyncProgramSplitter; import org.teavm.model.util.ListingBuilder; import org.teavm.model.util.ProgramUtils; -/** - * - * @author Alexey Andreev - */ public class Decompiler { private ClassHolderSource classSource; private ClassLoader classLoader; @@ -88,7 +86,7 @@ public class Decompiler { private RangeTree.Node currentNode; private RangeTree.Node parentNode; private Map generators = new HashMap<>(); - private Set methodsToPass = new HashSet<>(); + private Set methodsToSkip = new HashSet<>(); private MethodNodeCache regularMethodCache; private Set asyncMethods; private Set splitMethods = new HashSet<>(); @@ -169,8 +167,8 @@ public class Decompiler { generators.put(method, generator); } - public void addMethodToPass(MethodReference method) { - methodsToPass.add(method); + public void addMethodToSkip(MethodReference method) { + methodsToSkip.add(method); } private void orderClasses(String className, Set visited, List order) { @@ -203,7 +201,7 @@ public class Decompiler { continue; } if (method.getAnnotations().get(InjectedBy.class.getName()) != null - || methodsToPass.contains(method.getReference())) { + || methodsToSkip.contains(method.getReference())) { continue; } MethodNode methodNode = decompile(method); diff --git a/core/src/main/java/org/teavm/javascript/StatementGenerator.java b/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java similarity index 99% rename from core/src/main/java/org/teavm/javascript/StatementGenerator.java rename to core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java index 53a573173..58bcbb8cb 100644 --- a/core/src/main/java/org/teavm/javascript/StatementGenerator.java +++ b/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.decompilation; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/main/java/org/teavm/javascript/AllBlocksCountVisitor.java b/core/src/main/java/org/teavm/ast/optimization/AllBlocksCountVisitor.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/AllBlocksCountVisitor.java rename to core/src/main/java/org/teavm/ast/optimization/AllBlocksCountVisitor.java index fb24c59f1..0167417c8 100644 --- a/core/src/main/java/org/teavm/javascript/AllBlocksCountVisitor.java +++ b/core/src/main/java/org/teavm/ast/optimization/AllBlocksCountVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.HashMap; import java.util.List; diff --git a/core/src/main/java/org/teavm/javascript/BlockCountVisitor.java b/core/src/main/java/org/teavm/ast/optimization/BlockCountVisitor.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/BlockCountVisitor.java rename to core/src/main/java/org/teavm/ast/optimization/BlockCountVisitor.java index 20647168e..cb37eab59 100644 --- a/core/src/main/java/org/teavm/javascript/BlockCountVisitor.java +++ b/core/src/main/java/org/teavm/ast/optimization/BlockCountVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.List; import org.teavm.ast.AssignmentStatement; diff --git a/core/src/main/java/org/teavm/javascript/BreakEliminator.java b/core/src/main/java/org/teavm/ast/optimization/BreakEliminator.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/BreakEliminator.java rename to core/src/main/java/org/teavm/ast/optimization/BreakEliminator.java index 60bc7a7ad..05d1eccb9 100644 --- a/core/src/main/java/org/teavm/javascript/BreakEliminator.java +++ b/core/src/main/java/org/teavm/ast/optimization/BreakEliminator.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.HashMap; import java.util.HashSet; @@ -40,10 +40,6 @@ import org.teavm.ast.ThrowStatement; import org.teavm.ast.TryCatchStatement; import org.teavm.ast.WhileStatement; -/** - * - * @author Alexey Andreev - */ class BreakEliminator implements StatementVisitor { private Map> blockSuccessors = new HashMap<>(); private Set outerStatements = new HashSet<>(); diff --git a/core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java b/core/src/main/java/org/teavm/ast/optimization/BreakToContinueReplacer.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java rename to core/src/main/java/org/teavm/ast/optimization/BreakToContinueReplacer.java index 869f89ae2..e2f14e9e5 100644 --- a/core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java +++ b/core/src/main/java/org/teavm/ast/optimization/BreakToContinueReplacer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.List; import org.teavm.ast.AssignmentStatement; diff --git a/core/src/main/java/org/teavm/javascript/EscapingStatementFinder.java b/core/src/main/java/org/teavm/ast/optimization/EscapingStatementFinder.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/EscapingStatementFinder.java rename to core/src/main/java/org/teavm/ast/optimization/EscapingStatementFinder.java index f894139a6..438a11493 100644 --- a/core/src/main/java/org/teavm/javascript/EscapingStatementFinder.java +++ b/core/src/main/java/org/teavm/ast/optimization/EscapingStatementFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.List; import org.teavm.ast.AssignmentStatement; diff --git a/core/src/main/java/org/teavm/javascript/ExprOptimizer.java b/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java similarity index 97% rename from core/src/main/java/org/teavm/javascript/ExprOptimizer.java rename to core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java index 8d6040d08..34b174210 100644 --- a/core/src/main/java/org/teavm/javascript/ExprOptimizer.java +++ b/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import org.teavm.ast.BinaryExpr; import org.teavm.ast.BinaryOperation; diff --git a/core/src/main/java/org/teavm/javascript/Optimizer.java b/core/src/main/java/org/teavm/ast/optimization/Optimizer.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/Optimizer.java rename to core/src/main/java/org/teavm/ast/optimization/Optimizer.java index a624c273b..b256c4892 100644 --- a/core/src/main/java/org/teavm/javascript/Optimizer.java +++ b/core/src/main/java/org/teavm/ast/optimization/Optimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.BitSet; import java.util.List; diff --git a/core/src/main/java/org/teavm/javascript/OptimizingVisitor.java b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java similarity index 99% rename from core/src/main/java/org/teavm/javascript/OptimizingVisitor.java rename to core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java index b1defad24..bbc7e43d5 100644 --- a/core/src/main/java/org/teavm/javascript/OptimizingVisitor.java +++ b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.ArrayList; import java.util.Arrays; @@ -58,6 +58,7 @@ import org.teavm.ast.UnaryOperation; import org.teavm.ast.UnwrapArrayExpr; import org.teavm.ast.VariableExpr; import org.teavm.ast.WhileStatement; +import org.teavm.javascript.ExpressionSideEffectDecomposer; class OptimizingVisitor implements StatementVisitor, ExprVisitor { private Expr resultExpr; @@ -116,7 +117,7 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor { case GREATER: case GREATER_OR_EQUALS: { BinaryExpr comparison = (BinaryExpr) p; - Expr result = BinaryExpr.binary(expr.getOperation(), expr.getType(), + Expr result = BinaryExpr.binary(expr.getOperation(), comparison.getType(), comparison.getFirstOperand(), comparison.getSecondOperand()); result.setLocation(comparison.getLocation()); if (invert) { diff --git a/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java b/core/src/main/java/org/teavm/ast/optimization/ReadWriteStatsBuilder.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java rename to core/src/main/java/org/teavm/ast/optimization/ReadWriteStatsBuilder.java index 7d4ab35af..7978a64b1 100644 --- a/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java +++ b/core/src/main/java/org/teavm/ast/optimization/ReadWriteStatsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.Arrays; import org.teavm.common.Graph; diff --git a/core/src/main/java/org/teavm/javascript/RedundantLabelEliminator.java b/core/src/main/java/org/teavm/ast/optimization/RedundantLabelEliminator.java similarity index 98% rename from core/src/main/java/org/teavm/javascript/RedundantLabelEliminator.java rename to core/src/main/java/org/teavm/ast/optimization/RedundantLabelEliminator.java index e516e6f8b..80d173d91 100644 --- a/core/src/main/java/org/teavm/javascript/RedundantLabelEliminator.java +++ b/core/src/main/java/org/teavm/ast/optimization/RedundantLabelEliminator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.HashSet; import java.util.List; diff --git a/core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java b/core/src/main/java/org/teavm/ast/optimization/UnusedVariableEliminator.java similarity index 99% rename from core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java rename to core/src/main/java/org/teavm/ast/optimization/UnusedVariableEliminator.java index dfec74b13..8a79d7481 100644 --- a/core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java +++ b/core/src/main/java/org/teavm/ast/optimization/UnusedVariableEliminator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Alexey Andreev. + * Copyright 2016 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.javascript; +package org.teavm.ast.optimization; import java.util.Arrays; import java.util.List; diff --git a/core/src/main/java/org/teavm/cache/DiskRegularMethodNodeCache.java b/core/src/main/java/org/teavm/cache/DiskRegularMethodNodeCache.java index f5c9b095c..4281eeadd 100644 --- a/core/src/main/java/org/teavm/cache/DiskRegularMethodNodeCache.java +++ b/core/src/main/java/org/teavm/cache/DiskRegularMethodNodeCache.java @@ -69,7 +69,7 @@ import org.teavm.ast.UnaryExpr; import org.teavm.ast.UnwrapArrayExpr; import org.teavm.ast.VariableExpr; import org.teavm.ast.WhileStatement; -import org.teavm.javascript.MethodNodeCache; +import org.teavm.ast.cache.MethodNodeCache; import org.teavm.model.MethodReference; import org.teavm.parsing.ClassDateProvider; diff --git a/core/src/main/java/org/teavm/javascript/AsyncInvocationType.java b/core/src/main/java/org/teavm/javascript/AsyncInvocationType.java index 8e2c55563..058d5804d 100644 --- a/core/src/main/java/org/teavm/javascript/AsyncInvocationType.java +++ b/core/src/main/java/org/teavm/javascript/AsyncInvocationType.java @@ -15,10 +15,6 @@ */ package org.teavm.javascript; -/** - * - * @author Alexey Andreev - */ public enum AsyncInvocationType { COMPLETE, ERROR diff --git a/core/src/main/java/org/teavm/javascript/NullPointerExceptionTransformer.java b/core/src/main/java/org/teavm/javascript/NullPointerExceptionTransformer.java index 0fb56a8c5..368bb2de0 100644 --- a/core/src/main/java/org/teavm/javascript/NullPointerExceptionTransformer.java +++ b/core/src/main/java/org/teavm/javascript/NullPointerExceptionTransformer.java @@ -21,10 +21,6 @@ import org.teavm.model.instructions.InvocationType; import org.teavm.model.instructions.InvokeInstruction; import org.teavm.model.instructions.NullCheckInstruction; -/** - * - * @author Alexey Andreev - */ public class NullPointerExceptionTransformer implements ClassHolderTransformer { @Override public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) { diff --git a/core/src/main/java/org/teavm/javascript/Precedence.java b/core/src/main/java/org/teavm/javascript/Precedence.java index 7cedc626f..91d942869 100644 --- a/core/src/main/java/org/teavm/javascript/Precedence.java +++ b/core/src/main/java/org/teavm/javascript/Precedence.java @@ -15,10 +15,6 @@ */ package org.teavm.javascript; -/** - * - * @author Alexey Andreev - */ public enum Precedence { COMMA, ASSIGNMENT, diff --git a/core/src/main/java/org/teavm/javascript/ReferenceCountingVisitor.java b/core/src/main/java/org/teavm/javascript/ReferenceCountingVisitor.java deleted file mode 100644 index 89be1604a..000000000 --- a/core/src/main/java/org/teavm/javascript/ReferenceCountingVisitor.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2012 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; - -import org.teavm.ast.AssignmentStatement; -import org.teavm.ast.BlockStatement; -import org.teavm.ast.BreakStatement; -import org.teavm.ast.ConditionalStatement; -import org.teavm.ast.ContinueStatement; -import org.teavm.ast.GotoPartStatement; -import org.teavm.ast.IdentifiedStatement; -import org.teavm.ast.InitClassStatement; -import org.teavm.ast.MonitorEnterStatement; -import org.teavm.ast.MonitorExitStatement; -import org.teavm.ast.ReturnStatement; -import org.teavm.ast.SequentialStatement; -import org.teavm.ast.Statement; -import org.teavm.ast.StatementVisitor; -import org.teavm.ast.SwitchClause; -import org.teavm.ast.SwitchStatement; -import org.teavm.ast.ThrowStatement; -import org.teavm.ast.TryCatchStatement; -import org.teavm.ast.WhileStatement; - -/** - * - * @author Alexey Andreev - */ -class ReferenceCountingVisitor implements StatementVisitor { - private IdentifiedStatement target; - public int count; - - public ReferenceCountingVisitor(IdentifiedStatement target) { - this.target = target; - } - - @Override - public void visit(AssignmentStatement statement) { - } - - @Override - public void visit(SequentialStatement statement) { - for (Statement part : statement.getSequence()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(ConditionalStatement statement) { - for (Statement part : statement.getConsequent()) { - part.acceptVisitor(this); - } - for (Statement part : statement.getAlternative()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(SwitchStatement statement) { - for (SwitchClause clause : statement.getClauses()) { - for (Statement part : clause.getBody()) { - part.acceptVisitor(this); - } - } - for (Statement part : statement.getDefaultClause()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(WhileStatement statement) { - for (Statement part : statement.getBody()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(BlockStatement statement) { - for (Statement part : statement.getBody()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(BreakStatement statement) { - if (statement.getTarget() == target) { - ++count; - } - } - - @Override - public void visit(ContinueStatement statement) { - if (statement.getTarget() == target) { - ++count; - } - } - - @Override - public void visit(ReturnStatement statement) { - } - - @Override - public void visit(ThrowStatement statement) { - } - - @Override - public void visit(InitClassStatement statement) { - } - - @Override - public void visit(TryCatchStatement statement) { - for (Statement part : statement.getProtectedBody()) { - part.acceptVisitor(this); - } - for (Statement part : statement.getHandler()) { - part.acceptVisitor(this); - } - } - - @Override - public void visit(GotoPartStatement statement) { - } - - @Override - public void visit(MonitorEnterStatement statement) { - } - - @Override - public void visit(MonitorExitStatement statement) { - } -} diff --git a/core/src/main/java/org/teavm/javascript/Renderer.java b/core/src/main/java/org/teavm/javascript/Renderer.java index 26914b2c8..36c140599 100644 --- a/core/src/main/java/org/teavm/javascript/Renderer.java +++ b/core/src/main/java/org/teavm/javascript/Renderer.java @@ -1477,6 +1477,24 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext case COMPARE: visitBinaryFunction(expr, "Long_compare"); break; + case EQUALS: + visitBinaryFunction(expr, "Long_eq"); + break; + case NOT_EQUALS: + visitBinaryFunction(expr, "Long_ne"); + break; + case LESS: + visitBinaryFunction(expr, "Long_lt"); + break; + case LESS_OR_EQUALS: + visitBinaryFunction(expr, "Long_le"); + break; + case GREATER: + visitBinaryFunction(expr, "Long_gt"); + break; + case GREATER_OR_EQUALS: + visitBinaryFunction(expr, "Long_ge"); + break; default: break; } @@ -1531,22 +1549,22 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext visitBinary(expr, "&&", false); break; case BITWISE_OR: - visitBinary(expr, "|", expr.getType() == OperationType.INT); + visitBinary(expr, "|", false); break; case BITWISE_AND: - visitBinary(expr, "&", expr.getType() == OperationType.INT); + visitBinary(expr, "&", false); break; case BITWISE_XOR: - visitBinary(expr, "^", expr.getType() == OperationType.INT); + visitBinary(expr, "^", false); break; case LEFT_SHIFT: - visitBinary(expr, "<<", expr.getType() == OperationType.INT); + visitBinary(expr, "<<", false); break; case RIGHT_SHIFT: - visitBinary(expr, ">>", expr.getType() == OperationType.INT); + visitBinary(expr, ">>", false); break; case UNSIGNED_RIGHT_SHIFT: - visitBinary(expr, ">>>", expr.getType() == OperationType.INT); + visitBinary(expr, ">>>", false); break; } } diff --git a/core/src/main/java/org/teavm/javascript/RenderingContext.java b/core/src/main/java/org/teavm/javascript/RenderingContext.java index 0adecee90..edf9181d0 100644 --- a/core/src/main/java/org/teavm/javascript/RenderingContext.java +++ b/core/src/main/java/org/teavm/javascript/RenderingContext.java @@ -21,10 +21,6 @@ import org.teavm.codegen.SourceWriter; import org.teavm.common.ServiceRepository; import org.teavm.model.ListableClassReaderSource; -/** - * - * @author Alexey Andreev - */ public interface RenderingContext extends ServiceRepository { NamingStrategy getNaming(); diff --git a/core/src/main/java/org/teavm/javascript/RenderingException.java b/core/src/main/java/org/teavm/javascript/RenderingException.java index c08473c46..a1fedf9d2 100644 --- a/core/src/main/java/org/teavm/javascript/RenderingException.java +++ b/core/src/main/java/org/teavm/javascript/RenderingException.java @@ -15,10 +15,6 @@ */ package org.teavm.javascript; -/** - * - * @author Alexey Andreev - */ public class RenderingException extends RuntimeException { private static final long serialVersionUID = 631804556597569547L; diff --git a/core/src/main/java/org/teavm/javascript/RuntimeSupport.java b/core/src/main/java/org/teavm/javascript/RuntimeSupport.java index f6106f294..ae9ba47db 100644 --- a/core/src/main/java/org/teavm/javascript/RuntimeSupport.java +++ b/core/src/main/java/org/teavm/javascript/RuntimeSupport.java @@ -15,10 +15,6 @@ */ package org.teavm.javascript; -/** - * - * @author Alexey Andreev - */ public final class RuntimeSupport { private RuntimeSupport() { } diff --git a/core/src/main/java/org/teavm/javascript/TryCatchFinder.java b/core/src/main/java/org/teavm/javascript/TryCatchFinder.java index 9b19cd443..8d567b824 100644 --- a/core/src/main/java/org/teavm/javascript/TryCatchFinder.java +++ b/core/src/main/java/org/teavm/javascript/TryCatchFinder.java @@ -35,10 +35,6 @@ import org.teavm.ast.ThrowStatement; import org.teavm.ast.TryCatchStatement; import org.teavm.ast.WhileStatement; -/** - * - * @author Alexey Andreev - */ class TryCatchFinder implements StatementVisitor { public boolean tryCatchFound; diff --git a/core/src/main/java/org/teavm/javascript/spi/InjectedBy.java b/core/src/main/java/org/teavm/javascript/spi/InjectedBy.java index 103bb6541..fc9508058 100644 --- a/core/src/main/java/org/teavm/javascript/spi/InjectedBy.java +++ b/core/src/main/java/org/teavm/javascript/spi/InjectedBy.java @@ -20,10 +20,6 @@ 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 InjectedBy { diff --git a/core/src/main/resources/org/teavm/javascript/runtime.js b/core/src/main/resources/org/teavm/javascript/runtime.js index ef9cb589e..499aedcd0 100644 --- a/core/src/main/resources/org/teavm/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/javascript/runtime.js @@ -632,6 +632,61 @@ function Long_toNumber(val) { } return 0x100000000 * hi + lo; } +function Long_eq(a, b) { + return a.hi === b.hi && a.lo === b.lo; +} +function Long_ne(a, b) { + return a.hi !== b.hi || a.lo !== b.lo; +} +function Long_gt(a, b) { + if (a.hi < b.hi) { + return false; + } + if (a.hi > b.hi) { + return true; + } + if ((a.lo >>> 1) > (b.lo >>> 1)) { + return true; + } + return (a.lo & 1) > (b.lo & 1); +} +function Long_ge(a, b) { + if (a.hi < b.hi) { + return false; + } + if (a.hi > b.hi) { + return true; + } + if ((a.lo >>> 1) >= (b.lo >>> 1)) { + return true; + } + return (a.lo & 1) >= (b.lo & 1); +} +function Long_lt(a, b) { + if (a.hi > b.hi) { + return false; + } + if (a.hi < b.hi) { + return true; + } + if ((a.lo >>> 1) < (b.lo >>> 1)) { + return true; + } + return (a.lo & 1) < (b.lo & 1); +} +function Long_le(a, b) { + if (a.hi > b.hi) { + return false; + } + if (a.hi < b.hi) { + return true; + } + if ((a.lo >>> 1) <= (b.lo >>> 1)) { + return true; + } + return (a.lo & 1) <= (b.lo & 1); +} + function Long_add(a, b) { if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) { return Long_fromNumber(a.lo + b.lo);