Icyrockton
01/19/2024, 9:24 AMIrAnonymousInitializer
to IrClass
, why do we need to call ReferenceSymbolTable.withReferenceScope
?
Can we ignore this step, or what does it do?Icyrockton
01/19/2024, 9:24 AM// IrBuilderWithPluginContext.kt
// from kotlinx-serialization.backend
fun IrClass.addAnonymousInit(body: IrBlockBodyBuilder.() -> Unit) {
val anonymousInit = this.run {
val symbol = IrAnonymousInitializerSymbolImpl(symbol)
this.factory.createAnonymousInitializer(startOffset, endOffset, SERIALIZATION_PLUGIN_ORIGIN, symbol).also {
it.parent = this
declarations.add(it)
}
}
anonymousInit.buildWithScope { initIrBody ->
initIrBody.body =
DeclarationIrBuilder(
compilerContext,
initIrBody.symbol,
initIrBody.startOffset,
initIrBody.endOffset
).irBlockBody(body = body)
}
}
fun <T : IrDeclaration> T.buildWithScope(builder: (T) -> Unit): T =
also { irDeclaration ->
compilerContext.symbolTable.withReferenceScope(irDeclaration) {
builder(irDeclaration)
}
}