Rename achieved -> reached. Fix - operator generation in minified mode

This commit is contained in:
Alexey Andreev 2015-10-21 12:08:30 +03:00
parent bb16e891b9
commit 2640234391
10 changed files with 18 additions and 23 deletions

View File

@ -52,7 +52,7 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
} }
@Override @Override
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
switch (method.getReference().getName()) { switch (method.getReference().getName()) {
case "doArrayCopy": case "doArrayCopy":
achieveArrayCopy(method); achieveArrayCopy(method);

View File

@ -39,7 +39,7 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
ValueType.INTEGER, ValueType.LONG, ValueType.FLOAT, ValueType.DOUBLE, ValueType.BOOLEAN }; ValueType.INTEGER, ValueType.LONG, ValueType.FLOAT, ValueType.DOUBLE, ValueType.BOOLEAN };
@Override @Override
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
switch (method.getReference().getName()) { switch (method.getReference().getName()) {
case "getLength": case "getLength":
achieveGetLength(agent, method); achieveGetLength(agent, method);

View File

@ -382,7 +382,7 @@ public class DependencyChecker implements DependencyInfo {
private void activateDependencyPlugin(MethodDependency methodDep, CallLocation location) { private void activateDependencyPlugin(MethodDependency methodDep, CallLocation location) {
attachDependencyPlugin(methodDep); attachDependencyPlugin(methodDep);
if (methodDep.dependencyPlugin != null) { if (methodDep.dependencyPlugin != null) {
methodDep.dependencyPlugin.methodAchieved(agent, methodDep, location); methodDep.dependencyPlugin.methodReached(agent, methodDep, location);
} }
} }

View File

@ -22,5 +22,5 @@ import org.teavm.model.CallLocation;
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public interface DependencyPlugin { public interface DependencyPlugin {
void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location); void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location);
} }

View File

@ -1525,10 +1525,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
case NEGATE: case NEGATE:
if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) {
writer.append('('); writer.append('(');
} else if (outerPrecedence.ordinal() >= Precedence.ADDITION.ordinal()) {
writer.append(' ');
} }
writer.append("-"); writer.append(" -");
precedence = Precedence.UNARY; precedence = Precedence.UNARY;
expr.getOperand().acceptVisitor(this); expr.getOperand().acceptVisitor(this);
if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) {
@ -1664,16 +1662,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
} }
String str = constantToString(expr.getValue()); String str = constantToString(expr.getValue());
if (str.startsWith("-")) { if (str.startsWith("-")) {
if (precedence.ordinal() >= Precedence.UNARY.ordinal()) { writer.append(' ');
writer.append('(');
} else {
writer.append(' ');
}
} }
writer.append(str); writer.append(str);
if (str.startsWith("-") && precedence.ordinal() >= Precedence.UNARY.ordinal()) {
writer.append(')');
}
if (expr.getLocation() != null) { if (expr.getLocation() != null) {
popLocation(); popLocation();
} }

View File

@ -717,13 +717,16 @@ public class AstWriter {
private void printUnary(UnaryExpression node, int precedence) throws IOException { private void printUnary(UnaryExpression node, int precedence) throws IOException {
int innerPrecedence = node.isPostfix() ? PRECEDENCE_POSTFIX : PRECEDENCE_PREFIX; int innerPrecedence = node.isPostfix() ? PRECEDENCE_POSTFIX : PRECEDENCE_PREFIX;
if (innerPrecedence > precedence) { if (innerPrecedence > precedence) {
writer.append('('); writer.append('(');
} }
if (!node.isPostfix()) { 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())) { if (requiresWhitespaces(node.getType())) {
writer.append(' '); writer.append(' ');
} }
@ -768,13 +771,14 @@ public class AstWriter {
} }
print(node.getLeft(), leftPrecedence); print(node.getLeft(), leftPrecedence);
String op = AstNode.operatorToString(node.getType());
boolean ws = requiresWhitespaces(node.getType()); boolean ws = requiresWhitespaces(node.getType());
if (ws) { if (ws || op.startsWith("-")) {
writer.append(' '); writer.append(' ');
} else { } else {
writer.ws(); writer.ws();
} }
writer.append(AstNode.operatorToString(node.getType())); writer.append(op);
if (ws) { if (ws) {
writer.append(' '); writer.append(' ');
} else { } else {

View File

@ -169,7 +169,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
} }
@Override @Override
public void methodAchieved(final DependencyAgent agent, final MethodDependency method, public void methodReached(final DependencyAgent agent, final MethodDependency method,
final CallLocation location) { final CallLocation location) {
switch (method.getReference().getName()) { switch (method.getReference().getName()) {
case "invoke": case "invoke":

View File

@ -98,7 +98,7 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin {
} }
@Override @Override
public void methodAchieved(DependencyAgent checker, MethodDependency method, CallLocation location) { public void methodReached(DependencyAgent checker, MethodDependency method, CallLocation location) {
MethodReference ref = method.getReference(); MethodReference ref = method.getReference();
MethodReference asyncRef = getAsyncReference(ref); MethodReference asyncRef = getAsyncReference(ref);
MethodDependency asyncMethod = checker.linkMethod(asyncRef, location); MethodDependency asyncMethod = checker.linkMethod(asyncRef, location);

View File

@ -41,7 +41,7 @@ import org.teavm.platform.PlatformRunnable;
*/ */
public class PlatformGenerator implements Generator, Injector, DependencyPlugin { public class PlatformGenerator implements Generator, Injector, DependencyPlugin {
@Override @Override
public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
switch (method.getReference().getName()) { switch (method.getReference().getName()) {
case "asJavaClass": case "asJavaClass":
method.getResult().propagate(agent.getType("java.lang.Class")); method.getResult().propagate(agent.getType("java.lang.Class"));

View File

@ -32,7 +32,7 @@ import org.teavm.platform.PlatformQueue;
*/ */
public class PlatformQueueGenerator implements Injector, DependencyPlugin { public class PlatformQueueGenerator implements Injector, DependencyPlugin {
@Override @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", MethodDependency addMethod = agent.linkMethod(new MethodReference(PlatformQueue.class, "wrap",
Object.class, PlatformObject.class), null); Object.class, PlatformObject.class), null);
addMethod.getVariable(1).connect(method.getResult()); addMethod.getVariable(1).connect(method.getResult());