Generation of ++ and += fixed for platform types

This commit is contained in:
Andrey Breslav
2014-10-21 18:38:08 +04:00
parent d28c96837e
commit 7ed7f020d3
24 changed files with 354 additions and 18 deletions
@@ -3005,9 +3005,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
StackValue value = gen(lhs); // receiver
value.dupReceiver(v); // receiver receiver
value.put(lhsType, v); // receiver lhs
((IntrinsicMethod) callable).generate(this, v, typeMapper.mapType(descriptor), expression,
Type returnType = typeMapper.mapType(descriptor);
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
Collections.singletonList(expression.getRight()), StackValue.onStack(lhsType));
value.store(lhsType, v);
value.store(returnType, v);
return StackValue.none();
}
else {
@@ -3137,7 +3138,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
throw new UnsupportedOperationException("Don't know how to generate this postfix expression: " + originalOperationName + " " + op);
}
Type asmType = expressionType(expression);
Type asmResultType = expressionType(expression);
Type asmBaseType = expressionType(expression.getBaseExpression());
DeclarationDescriptor cls = op.getContainingDeclaration();
int increment;
@@ -3152,9 +3154,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
boolean isPrimitiveNumberClassDescriptor = isPrimitiveNumberClassDescriptor(cls);
if (isPrimitiveNumberClassDescriptor) {
if (isPrimitiveNumberClassDescriptor && AsmUtil.isPrimitive(asmBaseType)) {
JetExpression operand = expression.getBaseExpression();
if (operand instanceof JetReferenceExpression && asmType == Type.INT_TYPE) {
if (operand instanceof JetReferenceExpression && asmResultType == Type.INT_TYPE) {
int index = indexOfLocal((JetReferenceExpression) operand);
if (index >= 0) {
return StackValue.postIncrement(index, increment);
@@ -3171,8 +3173,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
pushReceiverAndValueViaDup(value, type); // receiver and new value
Type storeType;
if (isPrimitiveNumberClassDescriptor) {
genIncrement(asmType, increment, v);
if (isPrimitiveNumberClassDescriptor && AsmUtil.isPrimitive(asmBaseType)) {
genIncrement(asmResultType, increment, v);
storeType = type;
}
else {
@@ -3181,7 +3183,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
value.store(storeType, v);
return StackValue.onStack(asmType); // old value
return StackValue.onStack(asmResultType); // old value
}
private void pushReceiverAndValueViaDup(StackValue value, Type type) {
@@ -18,18 +18,21 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.genIncrement;
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
import static org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_TYPE;
public class Increment extends IntrinsicMethod {
private final int myDelta;
@@ -51,15 +54,15 @@ public class Increment extends IntrinsicMethod {
assert isPrimitive(returnType) : "Return type of Increment intrinsic should be of primitive type : " + returnType;
if (arguments.size() > 0) {
JetExpression operand = arguments.get(0);
while (operand instanceof JetParenthesizedExpression) {
operand = ((JetParenthesizedExpression) operand).getExpression();
}
JetExpression operand = JetPsiUtil.deparenthesize(arguments.get(0));
if (operand instanceof JetReferenceExpression && returnType == Type.INT_TYPE) {
int index = codegen.indexOfLocal((JetReferenceExpression) operand);
if (index >= 0) {
StackValue.preIncrement(index, myDelta).put(returnType, v);
return returnType;
JetType operandType = codegen.getBindingContext().get(EXPRESSION_TYPE, operand);
if (operandType != null && KotlinBuiltIns.getInstance().isPrimitiveType(operandType)) {
StackValue.preIncrement(index, myDelta).put(returnType, v);
return returnType;
}
}
}
StackValue value = codegen.genQualified(receiver, operand);