diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java b/classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java index 65bb9ba6e..5e633f728 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/SystemNativeGenerator.java @@ -52,7 +52,7 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin { } @Override - public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { switch (method.getReference().getName()) { case "doArrayCopy": achieveArrayCopy(method); diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java b/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java index 54b646443..c86a6d9e1 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java @@ -39,7 +39,7 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin { ValueType.INTEGER, ValueType.LONG, ValueType.FLOAT, ValueType.DOUBLE, ValueType.BOOLEAN }; @Override - public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { switch (method.getReference().getName()) { case "getLength": achieveGetLength(agent, method); diff --git a/core/src/main/java/org/teavm/dependency/DependencyChecker.java b/core/src/main/java/org/teavm/dependency/DependencyChecker.java index 7608ae471..12dba39d6 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -382,7 +382,7 @@ public class DependencyChecker implements DependencyInfo { private void activateDependencyPlugin(MethodDependency methodDep, CallLocation location) { attachDependencyPlugin(methodDep); if (methodDep.dependencyPlugin != null) { - methodDep.dependencyPlugin.methodAchieved(agent, methodDep, location); + methodDep.dependencyPlugin.methodReached(agent, methodDep, location); } } diff --git a/core/src/main/java/org/teavm/dependency/DependencyPlugin.java b/core/src/main/java/org/teavm/dependency/DependencyPlugin.java index 8061ceb58..e32d0d62a 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyPlugin.java +++ b/core/src/main/java/org/teavm/dependency/DependencyPlugin.java @@ -22,5 +22,5 @@ import org.teavm.model.CallLocation; * @author Alexey Andreev */ public interface DependencyPlugin { - void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location); + void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location); } diff --git a/core/src/main/java/org/teavm/javascript/Renderer.java b/core/src/main/java/org/teavm/javascript/Renderer.java index 5e9c69ea2..068486bf9 100644 --- a/core/src/main/java/org/teavm/javascript/Renderer.java +++ b/core/src/main/java/org/teavm/javascript/Renderer.java @@ -1525,10 +1525,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext case NEGATE: if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append('('); - } else if (outerPrecedence.ordinal() >= Precedence.ADDITION.ordinal()) { - writer.append(' '); } - writer.append("-"); + writer.append(" -"); precedence = Precedence.UNARY; expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { @@ -1664,16 +1662,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } String str = constantToString(expr.getValue()); if (str.startsWith("-")) { - if (precedence.ordinal() >= Precedence.UNARY.ordinal()) { - writer.append('('); - } else { - writer.append(' '); - } + writer.append(' '); } writer.append(str); - if (str.startsWith("-") && precedence.ordinal() >= Precedence.UNARY.ordinal()) { - writer.append(')'); - } if (expr.getLocation() != null) { popLocation(); } diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java b/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java index e2c1ab1ca..2da3c7b6c 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java @@ -717,13 +717,16 @@ public class AstWriter { private void printUnary(UnaryExpression node, int precedence) throws IOException { int innerPrecedence = node.isPostfix() ? PRECEDENCE_POSTFIX : PRECEDENCE_PREFIX; - if (innerPrecedence > precedence) { writer.append('('); } if (!node.isPostfix()) { - writer.append(AstNode.operatorToString(node.getType())); + String op = AstNode.operatorToString(node.getType()); + if (op.startsWith("-")) { + writer.append(' '); + } + writer.append(op); if (requiresWhitespaces(node.getType())) { writer.append(' '); } @@ -768,13 +771,14 @@ public class AstWriter { } print(node.getLeft(), leftPrecedence); + String op = AstNode.operatorToString(node.getType()); boolean ws = requiresWhitespaces(node.getType()); - if (ws) { + if (ws || op.startsWith("-")) { writer.append(' '); } else { writer.ws(); } - writer.append(AstNode.operatorToString(node.getType())); + writer.append(op); if (ws) { writer.append(' '); } else { diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java index e8151ae29..863131465 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java @@ -169,7 +169,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator } @Override - public void methodAchieved(final DependencyAgent agent, final MethodDependency method, + public void methodReached(final DependencyAgent agent, final MethodDependency method, final CallLocation location) { switch (method.getReference().getName()) { case "invoke": diff --git a/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java index 73768dfce..2c98c504d 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java @@ -98,7 +98,7 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { } @Override - public void methodAchieved(DependencyAgent checker, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent checker, MethodDependency method, CallLocation location) { MethodReference ref = method.getReference(); MethodReference asyncRef = getAsyncReference(ref); MethodDependency asyncMethod = checker.linkMethod(asyncRef, location); diff --git a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index f9bfd3cdf..966df1f92 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -41,7 +41,7 @@ import org.teavm.platform.PlatformRunnable; */ public class PlatformGenerator implements Generator, Injector, DependencyPlugin { @Override - public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { switch (method.getReference().getName()) { case "asJavaClass": method.getResult().propagate(agent.getType("java.lang.Class")); diff --git a/platform/src/main/java/org/teavm/platform/plugin/PlatformQueueGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/PlatformQueueGenerator.java index b0561f614..eacbee35c 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/PlatformQueueGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/PlatformQueueGenerator.java @@ -32,7 +32,7 @@ import org.teavm.platform.PlatformQueue; */ public class PlatformQueueGenerator implements Injector, DependencyPlugin { @Override - public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodDependency addMethod = agent.linkMethod(new MethodReference(PlatformQueue.class, "wrap", Object.class, PlatformObject.class), null); addMethod.getVariable(1).connect(method.getResult());