// optimizing assignment like: i = i + 1 or i = 1 + i
if (assignment.expression.isCompactableOperation()) {
BinaryExpression operation = (BinaryExpression) assignment.expression;
int operator = (operation.bits & OperatorMASK) >> OperatorSHIFT;
SingleNameReference variableReference;
if ((operation.left instanceof SingleNameReference) && ((variableReference = (SingleNameReference) operation.left).binding == this.binding)) {
// i = i + value, then use the variable on the right hand side, since it has the correct implicit conversion
variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[WRITE], operation.right, operator, operation.implicitConversion, valueRequired);
if (valueRequired) {
codeStream.generateImplicitConversion(assignment.implicitConversion);
}
return;
}
if ((operation.right instanceof SingleNameReference)
&& ((operator == PLUS) || (operator == MULTIPLY)) // only commutative operations
&& ((variableReference = (SingleNameReference) operation.right).binding == this.binding)
&& (operation.left.constant != Constant.NotAConstant) // exclude non constant expressions, since could have side-effect
&& (((operation.left.implicitConversion & IMPLICIT_CONVERSION_MASK) >> 4) != T_JavaLangString) // exclude string concatenation which would occur backwards
&& (((operation.right.implicitConversion & IMPLICIT_CONVERSION_MASK) >> 4) != T_JavaLangString)) { // exclude string concatenation which would occur backwards
// i = value + i, then use the variable on the right hand side, since it has the correct implicit conversion
variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[WRITE], operation.left, operator, operation.implicitConversion, valueRequired);
if (valueRequired) {
codeStream.generateImplicitConversion(assignment.implicitConversion);
}
return;
}