Convert ParameterInfo.java into Kotlin

This commit is contained in:
Mikhael Bogdanov
2019-04-02 13:05:07 +02:00
parent 53dd1dd76d
commit d8336bd0a1
8 changed files with 35 additions and 83 deletions
@@ -309,9 +309,9 @@ class AnonymousObjectTransformer(
} }
if (size != 0) { //skip this if (size != 0) { //skip this
descTypes.add(info.getType()) descTypes.add(info.type)
} }
size += info.getType().size size += info.type.size
} }
} }
@@ -345,7 +345,7 @@ class AnonymousObjectTransformer(
if (fake.functionalArgument is LambdaInfo) { if (fake.functionalArgument is LambdaInfo) {
//set remap value to skip this fake (captured with lambda already skipped) //set remap value to skip this fake (captured with lambda already skipped)
val composed = StackValue.field( val composed = StackValue.field(
fake.getType(), fake.type,
oldObjectType, oldObjectType,
fake.newFieldName, fake.newFieldName,
false, false,
@@ -63,7 +63,7 @@ public class CapturedParamInfo extends ParameterInfo {
@NotNull @NotNull
public CapturedParamInfo cloneWithNewDeclarationIndex(int newDeclarationIndex) { public CapturedParamInfo cloneWithNewDeclarationIndex(int newDeclarationIndex) {
CapturedParamInfo result = new CapturedParamInfo( CapturedParamInfo result = new CapturedParamInfo(
desc, newFieldName, isSkipped, getIndex(), getRemapValue(), skipInConstructor, newDeclarationIndex desc, newFieldName, isSkipped(), getIndex(), getRemapValue(), skipInConstructor, newDeclarationIndex
); );
result.setFunctionalArgument(getFunctionalArgument()); result.setFunctionalArgument(getFunctionalArgument());
result.setSynthetic(synthetic); result.setSynthetic(synthetic);
@@ -340,7 +340,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
if (capturedParamIndex >= 0) { if (capturedParamIndex >= 0) {
val capturedParamInfoInLambda = activeLambda!!.capturedVars[capturedParamIndex] val capturedParamInfoInLambda = activeLambda!!.capturedVars[capturedParamIndex]
info = invocationParamBuilder.addCapturedParam(capturedParamInfoInLambda, capturedParamInfoInLambda.fieldName, false) info = invocationParamBuilder.addCapturedParam(capturedParamInfoInLambda, capturedParamInfoInLambda.fieldName, false)
info.setRemapValue(remappedValue) info.remapValue = remappedValue
} else { } else {
info = invocationParamBuilder.addNextValueParameter(jvmType, false, remappedValue, parameterIndex) info = invocationParamBuilder.addNextValueParameter(jvmType, false, remappedValue, parameterIndex)
if (kind == ValueKind.NON_INLINEABLE_CALLED_IN_SUSPEND) { if (kind == ValueKind.NON_INLINEABLE_CALLED_IN_SUSPEND) {
@@ -363,7 +363,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
): Function0<Unit>? { ): Function0<Unit>? {
val index = IntArray(infos.size) { i -> val index = IntArray(infos.size) { i ->
if (!infos[i].isSkippedOrRemapped) { if (!infos[i].isSkippedOrRemapped) {
codegen.frameMap.enterTemp(infos[i].getType()) codegen.frameMap.enterTemp(infos[i].type)
} else -1 } else -1
} }
@@ -377,7 +377,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
local.store(StackValue.onStack(type), codegen.v) local.store(StackValue.onStack(type), codegen.v)
} }
if (info is CapturedParamInfo) { if (info is CapturedParamInfo) {
info.setRemapValue(local) info.remapValue = local
info.isSynthetic = true info.isSynthetic = true
} }
} }
@@ -35,11 +35,11 @@ class LocalVarRemapper(private val params: Parameters, private val additionalShi
val shift = params.getDeclarationSlot(info) val shift = params.getDeclarationSlot(info)
if (!info.isSkippedOrRemapped) { if (!info.isSkippedOrRemapped) {
remapValues[shift] = StackValue.local(realSize, AsmTypes.OBJECT_TYPE) remapValues[shift] = StackValue.local(realSize, AsmTypes.OBJECT_TYPE)
realSize += info.getType().size realSize += info.type.size
} else { } else {
remapValues[shift] = if (info.isRemapped) info.remapValue else null remapValues[shift] = if (info.isRemapped) info.remapValue else null
if (CapturedParamInfo.isSynthetic(info)) { if (CapturedParamInfo.isSynthetic(info)) {
realSize += info.getType().size realSize += info.type.size
} }
} }
} }
@@ -14,81 +14,33 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.codegen.inline; package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.annotations.Nullable; import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.kotlin.codegen.StackValue;
import org.jetbrains.org.objectweb.asm.Type;
public class ParameterInfo { open class ParameterInfo(
private final int index; val type: Type,
public final int declarationIndex; val isSkipped: Boolean, //for skipped parameter: e.g. inlined lambda
public final Type type; val index: Int,
//for skipped parameter: e.g. inlined lambda var remapValue: StackValue?, //in case when parameter could be extracted from outer context (e.g. from local var)
public final boolean isSkipped; val declarationIndex: Int = -1
) {
private boolean isCaptured; var isCaptured: Boolean = false
private FunctionalArgument functionalArgument; var functionalArgument: FunctionalArgument? = null
//in case when parameter could be extracted from outer context (e.g. from local var)
private StackValue remapValue;
public ParameterInfo(@NotNull Type type, boolean skipped, int index, int remapValue, int declarationIndex) { val isSkippedOrRemapped: Boolean
this(type, skipped, index, remapValue == -1 ? null : StackValue.local(remapValue, type), declarationIndex); get() = isSkipped || isRemapped
}
public ParameterInfo(@NotNull Type type, boolean skipped, int index, @Nullable StackValue remapValue, int declarationIndex) { val isRemapped: Boolean
this.type = type; get() = remapValue != null
this.isSkipped = skipped;
this.remapValue = remapValue;
this.index = index;
this.declarationIndex = declarationIndex;
}
public boolean isSkippedOrRemapped() { constructor(type: Type, skipped: Boolean, index: Int, remapValue: Int, declarationIndex: Int) : this(
return isSkipped || isRemapped(); type,
} skipped,
index,
public boolean isRemapped() { if (remapValue == -1) null else StackValue.local(remapValue, type),
return remapValue != null; declarationIndex
} )
@Nullable
public StackValue getRemapValue() {
return remapValue;
}
public int getIndex() {
return index;
}
@NotNull
public Type getType() {
return type;
}
@Nullable
public FunctionalArgument getFunctionalArgument() {
return functionalArgument;
}
@NotNull
public ParameterInfo setFunctionalArgument(@Nullable FunctionalArgument functionalArgument) {
this.functionalArgument = functionalArgument;
return this;
}
@NotNull
public ParameterInfo setRemapValue(@Nullable StackValue remapValue) {
this.remapValue = remapValue;
return this;
}
public boolean isCaptured() {
return isCaptured;
}
public void setCaptured(boolean isCaptured) {
this.isCaptured = isCaptured;
}
} }
@@ -70,5 +70,5 @@ class Parameters(val parameters: List<ParameterInfo>) : Iterable<ParameterInfo>
} }
val capturedTypes: List<Type> val capturedTypes: List<Type>
get() = captured.map(CapturedParamInfo::getType) get() = captured.map(CapturedParamInfo::type)
} }
@@ -69,7 +69,7 @@ class ParametersBuilder private constructor() {
private fun <T : ParameterInfo> addParameter(info: T): T { private fun <T : ParameterInfo> addParameter(info: T): T {
params.add(info) params.add(info)
nextParameterOffset += info.getType().size nextParameterOffset += info.type.size
if (info !is CapturedParamInfo) { if (info !is CapturedParamInfo) {
nextValueParameterIndex++ nextValueParameterIndex++
} }
@@ -78,7 +78,7 @@ class RegeneratedLambdaFieldRemapper(
if (field.isSkipped && field.functionalArgument is LambdaInfo) if (field.isSkipped && field.functionalArgument is LambdaInfo)
Type.getObjectType(parent!!.parent!!.newLambdaInternalName) Type.getObjectType(parent!!.parent!!.newLambdaInternalName)
else else
field.getType(), field.type,
Type.getObjectType(newLambdaInternalName), /*TODO owner type*/ Type.getObjectType(newLambdaInternalName), /*TODO owner type*/
field.newFieldName, false, field.newFieldName, false,
prefix ?: StackValue.LOCAL_0 prefix ?: StackValue.LOCAL_0