mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Improves minification
This commit is contained in:
parent
029f655b55
commit
62df1018cc
|
@ -27,17 +27,17 @@ public class ClassNativeGenerator implements Generator {
|
||||||
|
|
||||||
private void generateIsInstance(GeneratorContext context, SourceWriter writer) {
|
private void generateIsInstance(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return $rt_isInstance(").append(context.getParameterName(1)).append(", ")
|
writer.append("return $rt_isInstance(").append(context.getParameterName(1)).append(", ")
|
||||||
.append(context.getParameterName(0)).append(".$data);").newLine();
|
.append(context.getParameterName(0)).append(".$data);").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateIsAssignableFrom(GeneratorContext context, SourceWriter writer) {
|
private void generateIsAssignableFrom(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return $rt_isAssignable(").append(context.getParameterName(1)).append(".$data, ")
|
writer.append("return $rt_isAssignable(").append(context.getParameterName(1)).append(".$data, ")
|
||||||
.append(context.getParameterName(0)).append(".$data;").newLine();
|
.append(context.getParameterName(0)).append(".$data;").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateGetComponentType(GeneratorContext context, SourceWriter writer) {
|
private void generateGetComponentType(GeneratorContext context, SourceWriter writer) {
|
||||||
String thisArg = context.getParameterName(0);
|
String thisArg = context.getParameterName(0);
|
||||||
writer.append("var item = " + thisArg + ".$data.$meta.item;").newLine();
|
writer.append("var item = " + thisArg + ".$data.$meta.item;").softNewLine();
|
||||||
writer.append("return item != null ? $rt_cls(item) : null;").newLine();
|
writer.append("return item != null ? $rt_cls(item) : null;").softNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,12 +52,12 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateInit(GeneratorContext context, SourceWriter writer) {
|
private void generateInit(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append(context.getParameterName(0)).append(".$id = $rt_nextId();").newLine();
|
writer.append(context.getParameterName(0)).append(".$id = $rt_nextId();").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateGetClass(GeneratorContext context, SourceWriter writer) {
|
private void generateGetClass(GeneratorContext context, SourceWriter writer) {
|
||||||
String thisArg = context.getParameterName(0);
|
String thisArg = context.getParameterName(0);
|
||||||
writer.append("return $rt_cls(").append(thisArg).append(".$class);").newLine();
|
writer.append("return $rt_cls(").append(thisArg).append(".$class);").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveGetClass(DependencyChecker checker) {
|
private void achieveGetClass(DependencyChecker checker) {
|
||||||
|
@ -68,16 +68,16 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateHashCode(GeneratorContext context, SourceWriter writer) {
|
private void generateHashCode(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return ").append(context.getParameterName(0)).append(".$id;").newLine();
|
writer.append("return ").append(context.getParameterName(0)).append(".$id;").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateClone(GeneratorContext context, SourceWriter writer) {
|
private void generateClone(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("var copy = new ").append(context.getParameterName(0)).append(".$class();").newLine();
|
writer.append("var copy = new ").append(context.getParameterName(0)).append(".$class();").softNewLine();
|
||||||
writer.append("for (var field in obj) {").newLine().indent();
|
writer.append("for (var field in obj) {").softNewLine().indent();
|
||||||
writer.append("if (!obj.hasOwnProperty(field)) {").newLine().indent();
|
writer.append("if (!obj.hasOwnProperty(field)) {").softNewLine().indent();
|
||||||
writer.append("continue;").newLine().outdent().append("}").newLine();
|
writer.append("continue;").softNewLine().outdent().append("}").softNewLine();
|
||||||
writer.append("copy[field] = obj[field];").newLine().outdent().append("}").newLine();
|
writer.append("copy[field] = obj[field];").softNewLine().outdent().append("}").softNewLine();
|
||||||
writer.append("return copy;").newLine();
|
writer.append("return copy;").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveClone(DependencyChecker checker, MethodReference method) {
|
private void achieveClone(DependencyChecker checker, MethodReference method) {
|
||||||
|
@ -86,7 +86,7 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return ").append(context.getParameterName(1)).append(";").newLine();
|
writer.append("return ").append(context.getParameterName(1)).append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveWrap(DependencyChecker checker, MethodReference method) {
|
private void achieveWrap(DependencyChecker checker, MethodReference method) {
|
||||||
|
|
|
@ -20,6 +20,6 @@ public class StringNativeGenerator implements Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return ").append(context.getParameterName(1)).newLine();
|
writer.append("return ").append(context.getParameterName(1)).softNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
|
||||||
String dest = context.getParameterName(3);
|
String dest = context.getParameterName(3);
|
||||||
String destPos = context.getParameterName(4);
|
String destPos = context.getParameterName(4);
|
||||||
String length = context.getParameterName(5);
|
String length = context.getParameterName(5);
|
||||||
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().newLine();
|
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().softNewLine();
|
||||||
writer.append(dest + ".data[" + srcPos + "++] = " + src + ".data[" + destPos + "++];").newLine();
|
writer.append(dest + ".data[" + srcPos + "++] = " + src + ".data[" + destPos + "++];").softNewLine();
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveArrayCopy(DependencyChecker checker, MethodReference method) {
|
private void achieveArrayCopy(DependencyChecker checker, MethodReference method) {
|
||||||
|
|
|
@ -35,12 +35,12 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
|
||||||
private void generateGetLength(GeneratorContext context, SourceWriter writer) {
|
private void generateGetLength(GeneratorContext context, SourceWriter writer) {
|
||||||
String array = context.getParameterName(1);
|
String array = context.getParameterName(1);
|
||||||
writer.append("if (" + array + " === null || " + array + " .$class.$meta.item === undefined) {")
|
writer.append("if (" + array + " === null || " + array + " .$class.$meta.item === undefined) {")
|
||||||
.newLine().indent();
|
.softNewLine().indent();
|
||||||
String clsName = "java.lang.IllegalArgumentException";
|
String clsName = "java.lang.IllegalArgumentException";
|
||||||
MethodReference cons = new MethodReference(clsName, new MethodDescriptor("<init>", ValueType.VOID));
|
MethodReference cons = new MethodReference(clsName, new MethodDescriptor("<init>", ValueType.VOID));
|
||||||
writer.append("$rt_throw(").appendClass(clsName).append(".").appendMethod(cons).append("());").newLine();
|
writer.append("$rt_throw(").appendClass(clsName).append(".").appendMethod(cons).append("());").softNewLine();
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
writer.append("return " + array + ".data.length;").newLine();
|
writer.append("return " + array + ".data.length;").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveGetLength(final DependencyChecker checker, MethodReference methodRef) {
|
private void achieveGetLength(final DependencyChecker checker, MethodReference methodRef) {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import org.teavm.model.MethodReference;
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class MinifyingAliasProvider implements AliasProvider {
|
public class MinifyingAliasProvider implements AliasProvider {
|
||||||
private String startLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
private static String startLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
private String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
private static String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
private int lastSuffix;
|
private int lastSuffix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,7 +28,7 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNewAlias() {
|
private String getNewAlias() {
|
||||||
int index = lastSuffix;
|
int index = lastSuffix++;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(startLetters.charAt(index % startLetters.length()));
|
sb.append(startLetters.charAt(index % startLetters.length()));
|
||||||
index /= startLetters.length();
|
index /= startLetters.length();
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
.append("=").ws().append(constantToString(value)).append(";").softNewLine();
|
.append("=").ws().append(constantToString(value)).append(";").softNewLine();
|
||||||
}
|
}
|
||||||
writer.append("this.$class").ws().append("=").ws().appendClass(cls.getName()).append(";").softNewLine();
|
writer.append("this.$class").ws().append("=").ws().appendClass(cls.getName()).append(";").softNewLine();
|
||||||
writer.outdent().append("}").softNewLine();
|
writer.outdent().append("}").newLine();
|
||||||
|
|
||||||
for (FieldNode field : cls.getFields()) {
|
for (FieldNode field : cls.getFields()) {
|
||||||
if (!field.getModifiers().contains(NodeModifier.STATIC)) {
|
if (!field.getModifiers().contains(NodeModifier.STATIC)) {
|
||||||
|
@ -243,25 +243,25 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
if (startParam == 0) {
|
if (startParam == 0) {
|
||||||
writer.append("prototype.");
|
writer.append("prototype.");
|
||||||
}
|
}
|
||||||
writer.appendMethod(ref).append(" = function(");
|
writer.appendMethod(ref).ws().append("=").ws().append("function(");
|
||||||
for (int i = 1; i <= ref.parameterCount(); ++i) {
|
for (int i = 1; i <= ref.parameterCount(); ++i) {
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
writer.append(", ");
|
writer.append(", ");
|
||||||
}
|
}
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
writer.append(") {").newLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
writer.append("return ").appendClass(ref.getClassName()).append('_').appendMethod(ref).append("(");
|
writer.append("return ").appendMethodBody(ref).append("(");
|
||||||
if (startParam == 0) {
|
if (startParam == 0) {
|
||||||
writer.append("this");
|
writer.append("this");
|
||||||
}
|
}
|
||||||
for (int i = 1; i <= ref.parameterCount(); ++i) {
|
for (int i = 1; i <= ref.parameterCount(); ++i) {
|
||||||
if (i > 1 || startParam == 0) {
|
if (i > 1 || startParam == 0) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
writer.append(");").newLine();
|
writer.append(");").softNewLine();
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").newLine();
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
throw new RenderingException("Error rendering method " + method.getReference() + ". " +
|
throw new RenderingException("Error rendering method " + method.getReference() + ". " +
|
||||||
|
@ -271,32 +271,32 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
public void renderStub(MethodNode method) {
|
public void renderStub(MethodNode method) {
|
||||||
MethodReference ref = method.getReference();
|
MethodReference ref = method.getReference();
|
||||||
writer.appendClass(ref.getClassName()).append('_').appendMethod(ref).append(" = function(");
|
writer.appendMethodBody(ref).ws().append("=").ws().append("function(");
|
||||||
int startParam = 0;
|
int startParam = 0;
|
||||||
if (method.getModifiers().contains(NodeModifier.STATIC)) {
|
if (method.getModifiers().contains(NodeModifier.STATIC)) {
|
||||||
startParam = 1;
|
startParam = 1;
|
||||||
}
|
}
|
||||||
for (int i = startParam; i <= ref.parameterCount(); ++i) {
|
for (int i = startParam; i <= ref.parameterCount(); ++i) {
|
||||||
if (i > startParam) {
|
if (i > startParam) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
String owner = ref.getClassName();
|
String owner = ref.getClassName();
|
||||||
writer.append(") { ").appendClass(owner).append(".clinit(); ").append("return ").appendClass(owner)
|
writer.append(")").ws().append("{").ws().appendClass(owner).append(".clinit();")
|
||||||
.append("_").appendMethod(ref).append("(");
|
.ws().append("return ").appendMethodBody(ref).append("(");
|
||||||
for (int i = startParam; i <= ref.parameterCount(); ++i) {
|
for (int i = startParam; i <= ref.parameterCount(); ++i) {
|
||||||
if (i > startParam) {
|
if (i > startParam) {
|
||||||
writer.append(", ");
|
writer.append(", ");
|
||||||
}
|
}
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
writer.append("); };").newLine();
|
writer.append(");").ws().append("};").newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderBody(MethodNode method) {
|
public void renderBody(MethodNode method) {
|
||||||
MethodReference ref = method.getReference();
|
MethodReference ref = method.getReference();
|
||||||
writer.appendClass(ref.getClassName()).append('_').appendMethod(ref).append(" = function(");
|
writer.appendMethodBody(ref).ws().append("=").ws().append("function(");
|
||||||
int startParam = 0;
|
int startParam = 0;
|
||||||
if (method.getModifiers().contains(NodeModifier.STATIC)) {
|
if (method.getModifiers().contains(NodeModifier.STATIC)) {
|
||||||
startParam = 1;
|
startParam = 1;
|
||||||
|
@ -307,7 +307,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
}
|
}
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
writer.append(") {").newLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
method.acceptVisitor(new MethodBodyRenderer());
|
method.acceptVisitor(new MethodBodyRenderer());
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").newLine();
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
first = false;
|
first = false;
|
||||||
writer.append(variableName(i));
|
writer.append(variableName(i));
|
||||||
}
|
}
|
||||||
writer.append(";").newLine();
|
writer.append(";").softNewLine();
|
||||||
}
|
}
|
||||||
method.getBody().acceptVisitor(Renderer.this);
|
method.getBody().acceptVisitor(Renderer.this);
|
||||||
}
|
}
|
||||||
|
@ -348,10 +348,10 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
public void visit(AssignmentStatement statement) {
|
public void visit(AssignmentStatement statement) {
|
||||||
if (statement.getLeftValue() != null) {
|
if (statement.getLeftValue() != null) {
|
||||||
statement.getLeftValue().acceptVisitor(this);
|
statement.getLeftValue().acceptVisitor(this);
|
||||||
writer.append(" = ");
|
writer.ws().append("=").ws();
|
||||||
}
|
}
|
||||||
statement.getRightValue().acceptVisitor(this);
|
statement.getRightValue().acceptVisitor(this);
|
||||||
writer.append(";").newLine();
|
writer.append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -363,15 +363,15 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ConditionalStatement statement) {
|
public void visit(ConditionalStatement statement) {
|
||||||
writer.append("if (");
|
writer.append("if").ws().append("(");
|
||||||
statement.getCondition().acceptVisitor(this);
|
statement.getCondition().acceptVisitor(this);
|
||||||
writer.append(") {").newLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
statement.getConsequent().acceptVisitor(this);
|
statement.getConsequent().acceptVisitor(this);
|
||||||
if (statement.getAlternative() != null) {
|
if (statement.getAlternative() != null) {
|
||||||
writer.outdent().append("} else {").indent().newLine();
|
writer.outdent().append("}").ws().append("else").ws().append("{").indent().softNewLine();
|
||||||
statement.getAlternative().acceptVisitor(this);
|
statement.getAlternative().acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -379,50 +379,50 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
if (statement.getId() != null) {
|
if (statement.getId() != null) {
|
||||||
writer.append(statement.getId()).append(": ");
|
writer.append(statement.getId()).append(": ");
|
||||||
}
|
}
|
||||||
writer.append("switch (");
|
writer.append("switch").ws().append("(");
|
||||||
statement.getValue().acceptVisitor(this);
|
statement.getValue().acceptVisitor(this);
|
||||||
writer.append(") {").newLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
for (SwitchClause clause : statement.getClauses()) {
|
for (SwitchClause clause : statement.getClauses()) {
|
||||||
for (int condition : clause.getConditions()) {
|
for (int condition : clause.getConditions()) {
|
||||||
writer.append("case ").append(condition).append(":").newLine();
|
writer.append("case ").append(condition).append(":").softNewLine();
|
||||||
}
|
}
|
||||||
writer.indent();
|
writer.indent();
|
||||||
clause.getStatement().acceptVisitor(this);
|
clause.getStatement().acceptVisitor(this);
|
||||||
writer.outdent();
|
writer.outdent();
|
||||||
}
|
}
|
||||||
if (statement.getDefaultClause() != null) {
|
if (statement.getDefaultClause() != null) {
|
||||||
writer.append("default:").newLine().indent();
|
writer.append("default:").softNewLine().indent();
|
||||||
statement.getDefaultClause().acceptVisitor(this);
|
statement.getDefaultClause().acceptVisitor(this);
|
||||||
writer.outdent();
|
writer.outdent();
|
||||||
}
|
}
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(WhileStatement statement) {
|
public void visit(WhileStatement statement) {
|
||||||
if (statement.getId() != null) {
|
if (statement.getId() != null) {
|
||||||
writer.append(statement.getId()).append(": ");
|
writer.append(statement.getId()).append(":").ws();
|
||||||
}
|
}
|
||||||
writer.append("while (");
|
writer.append("while").ws().append("(");
|
||||||
if (statement.getCondition() != null) {
|
if (statement.getCondition() != null) {
|
||||||
statement.getCondition().acceptVisitor(this);
|
statement.getCondition().acceptVisitor(this);
|
||||||
} else {
|
} else {
|
||||||
writer.append("true");
|
writer.append("true");
|
||||||
}
|
}
|
||||||
writer.append(") {").newLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
for (Statement part : statement.getBody()) {
|
for (Statement part : statement.getBody()) {
|
||||||
part.acceptVisitor(this);
|
part.acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BlockStatement statement) {
|
public void visit(BlockStatement statement) {
|
||||||
writer.append(statement.getId()).append(": {").newLine().indent();
|
writer.append(statement.getId()).append(":").ws().append("{").softNewLine().indent();
|
||||||
for (Statement part : statement.getBody()) {
|
for (Statement part : statement.getBody()) {
|
||||||
part.acceptVisitor(this);
|
part.acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.outdent().append("}").newLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -432,12 +432,12 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BreakStatement statement) {
|
public void visit(BreakStatement statement) {
|
||||||
writer.append("break ").append(statement.getTarget().getId()).append(";").newLine();
|
writer.append("break ").append(statement.getTarget().getId()).append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ContinueStatement statement) {
|
public void visit(ContinueStatement statement) {
|
||||||
writer.append("continue ").append(statement.getTarget().getId()).append(";").newLine();
|
writer.append("continue ").append(statement.getTarget().getId()).append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -447,14 +447,14 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
writer.append(' ');
|
writer.append(' ');
|
||||||
statement.getResult().acceptVisitor(this);
|
statement.getResult().acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.append(";").newLine();
|
writer.append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ThrowStatement statement) {
|
public void visit(ThrowStatement statement) {
|
||||||
writer.append("$rt_throw(");
|
writer.append("$rt_throw(");
|
||||||
statement.getException().acceptVisitor(this);
|
statement.getException().acceptVisitor(this);
|
||||||
writer.append(");").newLine();
|
writer.append(");").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -464,16 +464,16 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
if (statement.getAmount() == 1) {
|
if (statement.getAmount() == 1) {
|
||||||
writer.append("++");
|
writer.append("++");
|
||||||
} else {
|
} else {
|
||||||
writer.append(" += ").append(statement.getAmount());
|
writer.ws().append("+=").ws().append(statement.getAmount());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (statement.getAmount() == -1) {
|
if (statement.getAmount() == -1) {
|
||||||
writer.append("--");
|
writer.append("--");
|
||||||
} else {
|
} else {
|
||||||
writer.append(" -= ").append(statement.getAmount());
|
writer.ws().append("-=").ws().append(statement.getAmount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.append(";").newLine();
|
writer.append(";").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String variableName(int index) {
|
public String variableName(int index) {
|
||||||
|
@ -492,7 +492,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
private void visitBinary(BinaryExpr expr, String op) {
|
private void visitBinary(BinaryExpr expr, String op) {
|
||||||
writer.append('(');
|
writer.append('(');
|
||||||
expr.getFirstOperand().acceptVisitor(this);
|
expr.getFirstOperand().acceptVisitor(this);
|
||||||
writer.append(' ').append(op).append(' ');
|
writer.ws().append(op).ws();
|
||||||
expr.getSecondOperand().acceptVisitor(this);
|
expr.getSecondOperand().acceptVisitor(this);
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
}
|
}
|
||||||
|
@ -501,7 +501,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
writer.append(function);
|
writer.append(function);
|
||||||
writer.append('(');
|
writer.append('(');
|
||||||
expr.getFirstOperand().acceptVisitor(this);
|
expr.getFirstOperand().acceptVisitor(this);
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
expr.getSecondOperand().acceptVisitor(this);
|
expr.getSecondOperand().acceptVisitor(this);
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
}
|
}
|
||||||
|
@ -673,9 +673,9 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
public void visit(ConditionalExpr expr) {
|
public void visit(ConditionalExpr expr) {
|
||||||
writer.append('(');
|
writer.append('(');
|
||||||
expr.getCondition().acceptVisitor(this);
|
expr.getCondition().acceptVisitor(this);
|
||||||
writer.append(" ? ");
|
writer.ws().append("?").ws();
|
||||||
expr.getConsequent().acceptVisitor(this);
|
expr.getConsequent().acceptVisitor(this);
|
||||||
writer.append(" : ");
|
writer.ws().append(":").ws();
|
||||||
expr.getAlternative().acceptVisitor(this);
|
expr.getAlternative().acceptVisitor(this);
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
}
|
}
|
||||||
|
@ -819,22 +819,23 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
public void visit(InvocationExpr expr) {
|
public void visit(InvocationExpr expr) {
|
||||||
String className = naming.getNameFor(expr.getMethod().getClassName());
|
String className = naming.getNameFor(expr.getMethod().getClassName());
|
||||||
String name = naming.getNameFor(expr.getMethod());
|
String name = naming.getNameFor(expr.getMethod());
|
||||||
|
String fullName = naming.getFullNameFor(expr.getMethod());
|
||||||
switch (expr.getType()) {
|
switch (expr.getType()) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
writer.append(className).append("_").append(name).append("(");
|
writer.append(fullName).append("(");
|
||||||
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
expr.getArguments().get(i).acceptVisitor(this);
|
expr.getArguments().get(i).acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
break;
|
break;
|
||||||
case SPECIAL:
|
case SPECIAL:
|
||||||
writer.append(className).append("_").append(name).append("(");
|
writer.append(fullName).append("(");
|
||||||
expr.getArguments().get(0).acceptVisitor(this);
|
expr.getArguments().get(0).acceptVisitor(this);
|
||||||
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
expr.getArguments().get(i).acceptVisitor(this);
|
expr.getArguments().get(i).acceptVisitor(this);
|
||||||
}
|
}
|
||||||
writer.append(")");
|
writer.append(")");
|
||||||
|
@ -844,7 +845,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
writer.append(".").append(name).append("(");
|
writer.append(".").append(name).append("(");
|
||||||
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
expr.getArguments().get(i).acceptVisitor(this);
|
expr.getArguments().get(i).acceptVisitor(this);
|
||||||
}
|
}
|
||||||
|
@ -854,7 +855,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
writer.append(className).append(".").append(name).append("(");
|
writer.append(className).append(".").append(name).append("(");
|
||||||
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
expr.getArguments().get(i).acceptVisitor(this);
|
expr.getArguments().get(i).acceptVisitor(this);
|
||||||
}
|
}
|
||||||
|
@ -932,11 +933,12 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NewMultiArrayExpr expr) {
|
public void visit(NewMultiArrayExpr expr) {
|
||||||
writer.append("$rt_createMultiArray(").append(typeToClsString(naming, expr.getType())).append(", [");
|
writer.append("$rt_createMultiArray(").append(typeToClsString(naming, expr.getType())).append(",")
|
||||||
|
.ws().append("[");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Expr dimension : expr.getDimensions()) {
|
for (Expr dimension : expr.getDimensions()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
writer.append(", ");
|
writer.append(",").ws();
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
dimension.acceptVisitor(this);
|
dimension.acceptVisitor(this);
|
||||||
|
@ -958,7 +960,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
}
|
}
|
||||||
writer.append("$rt_isInstance(");
|
writer.append("$rt_isInstance(");
|
||||||
expr.getExpr().acceptVisitor(this);
|
expr.getExpr().acceptVisitor(this);
|
||||||
writer.append(", ").append(typeToClsString(naming, expr.getType())).append(")");
|
writer.append(",").ws().append(typeToClsString(naming, expr.getType())).append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user