Add KotlinType to methods coerceTo & coerceFrom

This commit is contained in:
Mikhail Zarechenskiy
2018-02-05 04:13:43 +03:00
parent 1ac4e9755a
commit b0ee61620c
6 changed files with 42 additions and 53 deletions
@@ -74,7 +74,7 @@ abstract class SafeCallFusedWithPrimitiveEqualityBase(
v.iconst(0)
v.mark(endLabel)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
}
@@ -31,7 +31,7 @@ open class BranchedValue(
v.visitLabel(branchJumpLabel)
v.iconst(0)
v.visitLabel(endLabel)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
open fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) {
@@ -67,7 +67,7 @@ open class BranchedValue(
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
v.iconst(1)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
}
@@ -89,7 +89,7 @@ open class BranchedValue(
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
v.iconst(0)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
}
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen;
@@ -728,7 +717,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
markLineNumberForElement(element.getPsiOrParent(), codegen.v);
generateMethodCallTo(original, accessor, codegen.v).coerceTo(signature.getReturnType(), codegen.v);
generateMethodCallTo(original, accessor, codegen.v).coerceTo(signature.getReturnType(), null, codegen.v);
codegen.v.areturn(signature.getReturnType());
}
@@ -363,11 +363,11 @@ public abstract class StackValue {
v.invokevirtual(methodOwner.getInternalName(), type.getClassName() + "Value", "()" + type.getDescriptor(), false);
}
protected void coerceTo(@NotNull Type toType, @NotNull InstructionAdapter v) {
protected void coerceTo(@NotNull Type toType, @Nullable KotlinType toKotlinType, @NotNull InstructionAdapter v) {
coerce(this.type, toType, v);
}
protected void coerceFrom(@NotNull Type topOfStackType, @NotNull InstructionAdapter v) {
protected void coerceFrom(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerce(topOfStackType, this.type, v);
}
@@ -665,7 +665,7 @@ public abstract class StackValue {
@Override
public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
@@ -700,13 +700,13 @@ public abstract class StackValue {
if (isLateinit) {
StackValue.genNonNullAssertForLateinit(v, name.asString());
}
coerceTo(type, v);
coerceTo(type, kotlinType, v);
// TODO unbox
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, v);
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, topOfStackKotlinType, v);
v.store(index, this.type);
if (isLateinit) {
PseudoInsnsKt.storeNotNull(v);
@@ -790,7 +790,7 @@ public abstract class StackValue {
@Override
public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
@Override
@@ -811,7 +811,7 @@ public abstract class StackValue {
throw new UnsupportedOperationException("don't know how to move type " + type + " to top of stack");
}
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
else if (depth == 2) {
int size = this.type.getSize();
@@ -827,7 +827,7 @@ public abstract class StackValue {
throw new UnsupportedOperationException("don't know how to move type " + type + " to top of stack");
}
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
else {
throw new UnsupportedOperationException("unsupported move-to-top depth " + depth);
@@ -867,7 +867,7 @@ public abstract class StackValue {
}
if (value != null || AsmUtil.isPrimitive(type)) {
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
}
@@ -881,8 +881,8 @@ public abstract class StackValue {
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, v);
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, topOfStackKotlinType, v);
v.astore(this.type);
}
@@ -896,7 +896,7 @@ public abstract class StackValue {
@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v
) {
v.aload(this.type); // assumes array and index are on the stack
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
@@ -1086,7 +1086,7 @@ public abstract class StackValue {
}
CallGenerator callGenerator = getCallGenerator();
callGenerator.genCall(getter, resolvedGetCall, genDefaultMaskIfPresent(callGenerator), codegen);
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
private boolean genDefaultMaskIfPresent(CallGenerator callGenerator) {
@@ -1202,12 +1202,12 @@ public abstract class StackValue {
@Override
public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
v.visitFieldInsn(isStaticPut ? GETSTATIC : GETFIELD, owner.getInternalName(), name, this.type.getDescriptor());
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, v);
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, topOfStackKotlinType, v);
v.visitFieldInsn(isStaticStore ? PUTSTATIC : PUTFIELD, owner.getInternalName(), name, this.type.getDescriptor());
}
@@ -1256,7 +1256,7 @@ public abstract class StackValue {
if (!skipLateinitAssertion) {
genNotNullAssertionForLateInitIfNeeded(v);
}
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
else {
PropertyGetterDescriptor getterDescriptor = descriptor.getGetter();
@@ -1348,9 +1348,9 @@ public abstract class StackValue {
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
if (setter == null) {
coerceFrom(topOfStackType, v);
coerceFrom(topOfStackType, topOfStackKotlinType, v);
assert fieldName != null : "Property should have either a setter or a field name: " + descriptor;
assert backingFieldOwner != null : "Property should have either a setter or a backingFieldOwner: " + descriptor;
v.visitFieldInsn(isStaticStore ? PUTSTATIC : PUTFIELD, backingFieldOwner.getInternalName(), fieldName, this.type.getDescriptor());
@@ -1447,13 +1447,13 @@ public abstract class StackValue {
if (isLateinit) {
StackValue.genNonNullAssertForLateinit(v, name.asString());
}
coerceFrom(refType, v);
coerceTo(type, v);
coerceFrom(refType, null, v);
coerceTo(type, kotlinType, v);
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, v);
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, topOfStackKotlinType, v);
Type refType = refType(this.type);
Type sharedType = sharedTypeForType(this.type);
v.visitFieldInsn(PUTFIELD, sharedType.getInternalName(), "element", refType.getDescriptor());
@@ -1511,13 +1511,13 @@ public abstract class StackValue {
if (isLateinit) {
StackValue.genNonNullAssertForLateinit(v, variableName.asString());
}
coerceFrom(refType, v);
coerceTo(type, v);
coerceFrom(refType, null, v);
coerceTo(type, kotlinType, v);
}
@Override
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, v);
public void storeSelector(@NotNull Type topOfStackType, @Nullable KotlinType topOfStackKotlinType, @NotNull InstructionAdapter v) {
coerceFrom(topOfStackType, topOfStackKotlinType, v);
v.visitFieldInsn(PUTFIELD, sharedTypeForType(type).getInternalName(), "element", refType(type).getDescriptor());
}
@@ -1566,7 +1566,7 @@ public abstract class StackValue {
public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
if (!type.equals(Type.VOID_TYPE)) {
v.load(index, Type.INT_TYPE);
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
v.iinc(index, increment);
}
@@ -1587,7 +1587,7 @@ public abstract class StackValue {
v.iinc(index, increment);
if (!type.equals(Type.VOID_TYPE)) {
v.load(index, Type.INT_TYPE);
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
}
@@ -1617,7 +1617,7 @@ public abstract class StackValue {
value.store(codegen.invokeFunction(resolvedCall, StackValue.onStack(this.type)), v, true);
value.put(this.type, this.kotlinType, v, true);
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
@@ -1859,7 +1859,7 @@ public abstract class StackValue {
v.dup();
v.ifnull(ifNull);
}
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
}
@@ -1884,7 +1884,7 @@ public abstract class StackValue {
}
v.mark(end);
coerceTo(type, v);
coerceTo(type, kotlinType, v);
}
@Override
@@ -64,7 +64,7 @@ open class OperationStackValue(resultType: Type, val lambda: (v: InstructionAdap
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
lambda(v)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
}
@@ -32,7 +32,7 @@ class CallBasedInExpressionGenerator(
object : BranchedValue(argument, null, argument.type, Opcodes.IFEQ) {
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
invokeFunction(v)
coerceTo(type, v)
coerceTo(type, kotlinType, v)
}
override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) {