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(
valueParameterDescriptor: ValueParameterDescriptor?,
argumentExpression: IrExpression,
parameterType: Type,
parameterIndex: Int,
codegen: ExpressionCodegen,
blockInfo: BlockInfo) {
valueParameterDescriptor: ValueParameterDescriptor?,
argumentExpression: IrExpression,
parameterType: Type,
parameterIndex: Int,
codegen: ExpressionCodegen,
blockInfo: BlockInfo
) {
codegen.gen(argumentExpression, parameterType, blockInfo)
}
@@ -53,7 +54,5 @@ interface IrCallGenerator {
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
class IrInlineCodegen(
codegen: ExpressionCodegen,
state: GenerationState,
function: FunctionDescriptor,
typeParameterMappings: TypeParameterMappings,
sourceCompiler: SourceCompilerForInline
codegen: ExpressionCodegen,
state: GenerationState,
function: FunctionDescriptor,
typeParameterMappings: TypeParameterMappings,
sourceCompiler: SourceCompilerForInline
) : InlineCodegen<ExpressionCodegen>(codegen, state, function, typeParameterMappings, sourceCompiler), IrCallGenerator {
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
@@ -41,17 +41,30 @@ class IrInlineCodegen(
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)) {
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
}
else {
} else {
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)
}
@@ -81,7 +94,7 @@ class IrInlineCodegen(
val expression = irReference.symbol.owner as IrFunction
return IrExpressionLambda(
irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/
irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/
).also { lambda ->
val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index)
closureInfo.lambda = lambda
@@ -91,11 +104,11 @@ class IrInlineCodegen(
}
class IrExpressionLambda(
val reference: IrFunctionReference,
val function: IrFunction,
typeMapper: KotlinTypeMapper,
isCrossInline: Boolean,
override val isBoundCallableReference: Boolean
val reference: IrFunctionReference,
val function: IrFunction,
typeMapper: KotlinTypeMapper,
isCrossInline: Boolean,
override val isBoundCallableReference: Boolean
) : ExpressionLambda(typeMapper, isCrossInline) {
override fun isMyLabel(name: String): Boolean {
@@ -109,9 +122,9 @@ class IrExpressionLambda(
override val capturedVars: List<CapturedParamDesc> by lazy {
arrayListOf<CapturedParamDesc>().apply {
reference.getArguments().forEachIndexed { _, (_, ir) ->
val getValue = ir as? IrGetValue ?: error("Unrecognized expression: $ir")
add(capturedParamDesc(getValue.descriptor.name.asString(), typeMapper.mapType(getValue.descriptor.type)))
}
val getValue = ir as? IrGetValue ?: error("Unrecognized expression: $ir")
add(capturedParamDesc(getValue.descriptor.name.asString(), typeMapper.mapType(getValue.descriptor.type)))
}
}
}
@@ -130,4 +143,4 @@ class IrExpressionLambda(
}
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
class IrSourceCompilerForInline(
override val state: GenerationState,
override val callElement: IrMemberAccessExpression,
private val codegen: ExpressionCodegen
): SourceCompilerForInline {
override val state: GenerationState,
override val callElement: IrMemberAccessExpression,
private val codegen: ExpressionCodegen
) : SourceCompilerForInline {
//TODO
@@ -81,7 +81,12 @@ class IrSourceCompilerForInline(
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)
val owner = (callElement as IrCall).symbol.owner as IrFunction
//ExpressionCodegen()
@@ -89,10 +94,12 @@ class IrSourceCompilerForInline(
var maxCalcAdapter: MethodVisitor? = null
val functionCodegen = object : FunctionCodegen(owner, codegen.classCodegen) {
override fun createMethod(flags: Int, signature: JvmMethodGenericSignature): MethodVisitor {
node = MethodNode(API,
flags,
signature.asmMethod.name, signature.asmMethod.descriptor,
signature.genericsSignature, null)
node = MethodNode(
API,
flags,
signature.asmMethod.name, signature.asmMethod.descriptor,
signature.genericsSignature, null
)
maxCalcAdapter = wrapWithMaxLocalCalc(node!!)
return maxCalcAdapter!!
}
@@ -104,7 +111,11 @@ class IrSourceCompilerForInline(
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")
}