Minor. Reformat

This commit is contained in:
Mikhael Bogdanov
2018-04-17 13:00:11 +02:00
parent 579822c114
commit a8dacccdd3
3 changed files with 62 additions and 39 deletions
@@ -40,12 +40,13 @@ interface IrCallGenerator {
} }
fun genValueAndPut( fun genValueAndPut(
valueParameterDescriptor: ValueParameterDescriptor?, valueParameterDescriptor: ValueParameterDescriptor?,
argumentExpression: IrExpression, argumentExpression: IrExpression,
parameterType: Type, parameterType: Type,
parameterIndex: Int, parameterIndex: Int,
codegen: ExpressionCodegen, codegen: ExpressionCodegen,
blockInfo: BlockInfo) { blockInfo: BlockInfo
) {
codegen.gen(argumentExpression, parameterType, blockInfo) codegen.gen(argumentExpression, parameterType, blockInfo)
} }
@@ -53,7 +54,5 @@ interface IrCallGenerator {
value.put(parameterType, codegen.visitor) value.put(parameterType, codegen.visitor)
} }
object DefaultCallGenerator: IrCallGenerator { object DefaultCallGenerator : IrCallGenerator
}
} }
@@ -23,11 +23,11 @@ import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.Method import org.jetbrains.org.objectweb.asm.commons.Method
class IrInlineCodegen( class IrInlineCodegen(
codegen: ExpressionCodegen, codegen: ExpressionCodegen,
state: GenerationState, state: GenerationState,
function: FunctionDescriptor, function: FunctionDescriptor,
typeParameterMappings: TypeParameterMappings, typeParameterMappings: TypeParameterMappings,
sourceCompiler: SourceCompilerForInline sourceCompiler: SourceCompilerForInline
) : InlineCodegen<ExpressionCodegen>(codegen, state, function, typeParameterMappings, sourceCompiler), IrCallGenerator { ) : InlineCodegen<ExpressionCodegen>(codegen, state, function, typeParameterMappings, sourceCompiler), IrCallGenerator {
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) { override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
@@ -41,17 +41,30 @@ class IrInlineCodegen(
activeLambda = null activeLambda = null
} }
override fun genValueAndPut(valueParameterDescriptor: ValueParameterDescriptor?, argumentExpression: IrExpression, parameterType: Type, parameterIndex: Int, codegen: ExpressionCodegen, blockInfo: BlockInfo) { override fun genValueAndPut(
valueParameterDescriptor: ValueParameterDescriptor?,
argumentExpression: IrExpression,
parameterType: Type,
parameterIndex: Int,
codegen: ExpressionCodegen,
blockInfo: BlockInfo
) {
if (valueParameterDescriptor?.let { isInlineParameter(it) } == true && isInlineIrExpression(argumentExpression)) { if (valueParameterDescriptor?.let { isInlineParameter(it) } == true && isInlineIrExpression(argumentExpression)) {
val irReference: IrFunctionReference = (argumentExpression as IrBlock).statements.filterIsInstance<IrFunctionReference>().single() val irReference: IrFunctionReference =
(argumentExpression as IrBlock).statements.filterIsInstance<IrFunctionReference>().single()
rememberClosure(irReference, parameterType, valueParameterDescriptor!!) as IrExpressionLambda rememberClosure(irReference, parameterType, valueParameterDescriptor!!) as IrExpressionLambda
} } else {
else {
putValueOnStack(argumentExpression, parameterType, valueParameterDescriptor?.index ?: -1) putValueOnStack(argumentExpression, parameterType, valueParameterDescriptor?.index ?: -1)
} }
} }
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int, codegen: ExpressionCodegen) { override fun putValueIfNeeded(
parameterType: Type,
value: StackValue,
kind: ValueKind,
parameterIndex: Int,
codegen: ExpressionCodegen
) {
putArgumentOrCapturedToLocalVal(JvmKotlinType(value.type, value.kotlinType), value, -1, parameterIndex, ValueKind.CAPTURED) putArgumentOrCapturedToLocalVal(JvmKotlinType(value.type, value.kotlinType), value, -1, parameterIndex, ValueKind.CAPTURED)
} }
@@ -81,7 +94,7 @@ class IrInlineCodegen(
val expression = irReference.symbol.owner as IrFunction val expression = irReference.symbol.owner as IrFunction
return IrExpressionLambda( return IrExpressionLambda(
irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/ irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/
).also { lambda -> ).also { lambda ->
val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index) val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index)
closureInfo.lambda = lambda closureInfo.lambda = lambda
@@ -91,11 +104,11 @@ class IrInlineCodegen(
} }
class IrExpressionLambda( class IrExpressionLambda(
val reference: IrFunctionReference, val reference: IrFunctionReference,
val function: IrFunction, val function: IrFunction,
typeMapper: KotlinTypeMapper, typeMapper: KotlinTypeMapper,
isCrossInline: Boolean, isCrossInline: Boolean,
override val isBoundCallableReference: Boolean override val isBoundCallableReference: Boolean
) : ExpressionLambda(typeMapper, isCrossInline) { ) : ExpressionLambda(typeMapper, isCrossInline) {
override fun isMyLabel(name: String): Boolean { override fun isMyLabel(name: String): Boolean {
@@ -109,9 +122,9 @@ class IrExpressionLambda(
override val capturedVars: List<CapturedParamDesc> by lazy { override val capturedVars: List<CapturedParamDesc> by lazy {
arrayListOf<CapturedParamDesc>().apply { arrayListOf<CapturedParamDesc>().apply {
reference.getArguments().forEachIndexed { _, (_, ir) -> reference.getArguments().forEachIndexed { _, (_, ir) ->
val getValue = ir as? IrGetValue ?: error("Unrecognized expression: $ir") val getValue = ir as? IrGetValue ?: error("Unrecognized expression: $ir")
add(capturedParamDesc(getValue.descriptor.name.asString(), typeMapper.mapType(getValue.descriptor.type))) add(capturedParamDesc(getValue.descriptor.name.asString(), typeMapper.mapType(getValue.descriptor.type)))
} }
} }
} }
@@ -130,4 +143,4 @@ class IrExpressionLambda(
} }
fun isInlineIrExpression(argumentExpression: IrExpression) = fun isInlineIrExpression(argumentExpression: IrExpression) =
argumentExpression is IrBlock && argumentExpression.origin == IrStatementOrigin.LAMBDA argumentExpression is IrBlock && argumentExpression.origin == IrStatementOrigin.LAMBDA
@@ -37,10 +37,10 @@ import org.jetbrains.org.objectweb.asm.commons.Method
import org.jetbrains.org.objectweb.asm.tree.MethodNode import org.jetbrains.org.objectweb.asm.tree.MethodNode
class IrSourceCompilerForInline( class IrSourceCompilerForInline(
override val state: GenerationState, override val state: GenerationState,
override val callElement: IrMemberAccessExpression, override val callElement: IrMemberAccessExpression,
private val codegen: ExpressionCodegen private val codegen: ExpressionCodegen
): SourceCompilerForInline { ) : SourceCompilerForInline {
//TODO //TODO
@@ -81,7 +81,12 @@ class IrSourceCompilerForInline(
return SMAP(/*TODO*/listOf(FileMapping("TODO", "TODO").also { it.id = 1; it.addRangeMapping(RangeMapping(1, 1, 1)) })) return SMAP(/*TODO*/listOf(FileMapping("TODO", "TODO").also { it.id = 1; it.addRangeMapping(RangeMapping(1, 1, 1)) }))
} }
override fun doCreateMethodNodeFromSource(callableDescriptor: FunctionDescriptor, jvmSignature: JvmMethodSignature, callDefault: Boolean, asmMethod: Method): SMAPAndMethodNode { override fun doCreateMethodNodeFromSource(
callableDescriptor: FunctionDescriptor,
jvmSignature: JvmMethodSignature,
callDefault: Boolean,
asmMethod: Method
): SMAPAndMethodNode {
assert(callableDescriptor == callElement.descriptor.original) assert(callableDescriptor == callElement.descriptor.original)
val owner = (callElement as IrCall).symbol.owner as IrFunction val owner = (callElement as IrCall).symbol.owner as IrFunction
//ExpressionCodegen() //ExpressionCodegen()
@@ -89,10 +94,12 @@ class IrSourceCompilerForInline(
var maxCalcAdapter: MethodVisitor? = null var maxCalcAdapter: MethodVisitor? = null
val functionCodegen = object : FunctionCodegen(owner, codegen.classCodegen) { val functionCodegen = object : FunctionCodegen(owner, codegen.classCodegen) {
override fun createMethod(flags: Int, signature: JvmMethodGenericSignature): MethodVisitor { override fun createMethod(flags: Int, signature: JvmMethodGenericSignature): MethodVisitor {
node = MethodNode(API, node = MethodNode(
flags, API,
signature.asmMethod.name, signature.asmMethod.descriptor, flags,
signature.genericsSignature, null) signature.asmMethod.name, signature.asmMethod.descriptor,
signature.genericsSignature, null
)
maxCalcAdapter = wrapWithMaxLocalCalc(node!!) maxCalcAdapter = wrapWithMaxLocalCalc(node!!)
return maxCalcAdapter!! return maxCalcAdapter!!
} }
@@ -104,7 +111,11 @@ class IrSourceCompilerForInline(
return SMAPAndMethodNode(node!!, SMAP(/*TODO*/listOf(FileMapping.SKIP))) return SMAPAndMethodNode(node!!, SMAP(/*TODO*/listOf(FileMapping.SKIP)))
} }
override fun generateAndInsertFinallyBlocks(intoNode: MethodNode, insertPoints: List<MethodInliner.PointForExternalFinallyBlocks>, offsetForFinallyLocalVar: Int) { override fun generateAndInsertFinallyBlocks(
intoNode: MethodNode,
insertPoints: List<MethodInliner.PointForExternalFinallyBlocks>,
offsetForFinallyLocalVar: Int
) {
//TODO("not implemented") //TODO("not implemented")
} }