|
|
@ -88,11 +88,12 @@ public class ComplexExpression extends Expression { |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i=0; i < subExpressions.length; i++) { |
|
|
|
return subExpressions[0].canCombine(e); |
|
|
|
int can = subExpressions[i].canCombine(e); |
|
|
|
// for (int i=0; i < subExpressions.length; i++) {
|
|
|
|
if (can != 0) |
|
|
|
// int can = subExpressions[i].canCombine(e);
|
|
|
|
return can; |
|
|
|
// if (can != 0)
|
|
|
|
} |
|
|
|
// return can;
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -120,7 +121,7 @@ public class ComplexExpression extends Expression { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
throw new AssertError("combine didn't succeed"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Operator getOperator() { |
|
|
|
public Operator getOperator() { |
|
|
@ -235,36 +236,32 @@ public class ComplexExpression extends Expression { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Expression emptyString = |
|
|
|
|
|
|
|
new EmptyStringOperator(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Expression simplifyStringBuffer() { |
|
|
|
public Expression simplifyStringBuffer() { |
|
|
|
gnu.bytecode.CpoolRef field; |
|
|
|
|
|
|
|
if (operator instanceof InvokeOperator |
|
|
|
if (operator instanceof InvokeOperator |
|
|
|
&& (((InvokeOperator)operator).getClassType() |
|
|
|
&& (((InvokeOperator)operator).getClassType() |
|
|
|
.equals(Type.tStringBuffer)) |
|
|
|
.equals(Type.tStringBuffer)) |
|
|
|
&& !((InvokeOperator)operator).isStatic() |
|
|
|
&& !((InvokeOperator)operator).isStatic() |
|
|
|
&& (((InvokeOperator)operator).getMethodName().equals("append")) |
|
|
|
&& (((InvokeOperator)operator).getMethodName().equals("append")) |
|
|
|
&& (((InvokeOperator)operator).getMethodType() |
|
|
|
&& (((InvokeOperator)operator).getMethodType() |
|
|
|
.getArgumentTypes().length == 1)) { |
|
|
|
.getParameterTypes().length == 1)) { |
|
|
|
|
|
|
|
|
|
|
|
Expression e = subExpressions[0].simplifyStringBuffer(); |
|
|
|
Expression e = subExpressions[0].simplifyStringBuffer(); |
|
|
|
if (e == null) |
|
|
|
if (e == null) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
if (e.getOperator() instanceof EmptyStringOperator && |
|
|
|
if (e == EMPTYSTRING |
|
|
|
subExpressions[1].getType().isOfType(Type.tString)) |
|
|
|
&& subExpressions[1].getType().isOfType(Type.tString)) |
|
|
|
return subExpressions[1]; |
|
|
|
return subExpressions[1]; |
|
|
|
|
|
|
|
|
|
|
|
return new ComplexExpression |
|
|
|
return new ComplexExpression |
|
|
|
(new StringAddOperator(), new Expression[] |
|
|
|
(new StringAddOperator(), new Expression[] |
|
|
|
{ e, subExpressions[1] }); |
|
|
|
{ e, subExpressions[1] }); |
|
|
|
} |
|
|
|
} |
|
|
|
if (operator instanceof ConstructorOperator && |
|
|
|
if (operator instanceof ConstructorOperator |
|
|
|
operator.getType().isOfType(Type.tStringBuffer)) { |
|
|
|
&& (((ConstructorOperator) operator).getClassType() |
|
|
|
if (subExpressions.length == 0) |
|
|
|
== Type.tStringBuffer)) { |
|
|
|
return emptyString; |
|
|
|
|
|
|
|
else if (subExpressions.length == 1 && |
|
|
|
if (subExpressions.length == 1 && |
|
|
|
subExpressions[0].getType().isOfType(Type.tString)) |
|
|
|
subExpressions[0].getType().isOfType(Type.tString)) |
|
|
|
return subExpressions[0]; |
|
|
|
return subExpressions[0]; |
|
|
|
} |
|
|
|
} |
|
|
@ -276,7 +273,7 @@ public class ComplexExpression extends Expression { |
|
|
|
InvokeOperator invoke = (InvokeOperator) operator; |
|
|
|
InvokeOperator invoke = (InvokeOperator) operator; |
|
|
|
if (invoke.getMethodName().equals("toString") |
|
|
|
if (invoke.getMethodName().equals("toString") |
|
|
|
&& !invoke.isStatic() |
|
|
|
&& !invoke.isStatic() |
|
|
|
&& (invoke.getClassType().equals(Type.tStringBuffer)) |
|
|
|
&& invoke.getClassType().equals(Type.tStringBuffer) |
|
|
|
&& subExpressions.length == 1) { |
|
|
|
&& subExpressions.length == 1) { |
|
|
|
Expression simple = subExpressions[0].simplifyStringBuffer(); |
|
|
|
Expression simple = subExpressions[0].simplifyStringBuffer(); |
|
|
|
if (simple != null) |
|
|
|
if (simple != null) |
|
|
@ -292,7 +289,7 @@ public class ComplexExpression extends Expression { |
|
|
|
|
|
|
|
|
|
|
|
return new ComplexExpression |
|
|
|
return new ComplexExpression |
|
|
|
(new StringAddOperator(), new Expression[] |
|
|
|
(new StringAddOperator(), new Expression[] |
|
|
|
{ emptyString, subExpressions[0] }); |
|
|
|
{ EMPTYSTRING, subExpressions[0] }); |
|
|
|
} |
|
|
|
} |
|
|
|
/* The pizza way (pizza is the compiler of kaffe) */ |
|
|
|
/* The pizza way (pizza is the compiler of kaffe) */ |
|
|
|
else if (invoke.getMethodName().equals("concat") |
|
|
|
else if (invoke.getMethodName().equals("concat") |
|
|
@ -304,7 +301,7 @@ public class ComplexExpression extends Expression { |
|
|
|
if (right instanceof ComplexExpression |
|
|
|
if (right instanceof ComplexExpression |
|
|
|
&& right.getOperator() instanceof StringAddOperator |
|
|
|
&& right.getOperator() instanceof StringAddOperator |
|
|
|
&& (((ComplexExpression) right).subExpressions[0] |
|
|
|
&& (((ComplexExpression) right).subExpressions[0] |
|
|
|
== emptyString)) |
|
|
|
== EMPTYSTRING)) |
|
|
|
right = ((ComplexExpression)right).subExpressions[1]; |
|
|
|
right = ((ComplexExpression)right).subExpressions[1]; |
|
|
|
|
|
|
|
|
|
|
|
return new ComplexExpression |
|
|
|
return new ComplexExpression |
|
|
|