[klib] Return the block's return value in inFile methods
This commit is contained in:
committed by
Space Team
parent
da9f0e7af8
commit
c8f8316e9b
+1
-2
@@ -81,7 +81,6 @@ internal class Fir2IrFakeOverrideStrategy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun inFile(file: IrFile?, block: () -> Unit) {
|
override fun <R> inFile(file: IrFile?, block: () -> R): R =
|
||||||
publicIdSignatureComputer.inFile(file?.symbol, block)
|
publicIdSignatureComputer.inFile(file?.symbol, block)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ abstract class FakeOverrideBuilderStrategy(
|
|||||||
* Contract:
|
* Contract:
|
||||||
* * must call [block] exactly once.
|
* * must call [block] exactly once.
|
||||||
*/
|
*/
|
||||||
abstract fun inFile(file: IrFile?, block: () -> Unit)
|
abstract fun <R> inFile(file: IrFile?, block: () -> R): R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for creating a symbol for fake override function.
|
* Callback for creating a symbol for fake override function.
|
||||||
|
|||||||
@@ -1305,7 +1305,7 @@ private object BindToNewEmptySymbols : FakeOverrideBuilderStrategy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun inFile(file: IrFile?, block: () -> Unit) { block() }
|
override fun <R> inFile(file: IrFile?, block: () -> R): R = block()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrClass.addFakeOverrides(
|
fun IrClass.addFakeOverrides(
|
||||||
|
|||||||
+1
-2
@@ -87,9 +87,8 @@ private class IrLinkerFakeOverrideBuilderStrategy(
|
|||||||
unimplementedOverridesStrategy = unimplementedOverridesStrategy
|
unimplementedOverridesStrategy = unimplementedOverridesStrategy
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun inFile(file: IrFile?, block: () -> Unit) {
|
override fun <R> inFile(file: IrFile?, block: () -> R): R =
|
||||||
fakeOverrideDeclarationTable.inFile(file, block)
|
fakeOverrideDeclarationTable.inFile(file, block)
|
||||||
}
|
|
||||||
|
|
||||||
override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) {
|
override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||||
val (signature, symbol) = computeFunctionFakeOverrideSymbol(function, manglerCompatibleMode)
|
val (signature, symbol) = computeFunctionFakeOverrideSymbol(function, manglerCompatibleMode)
|
||||||
|
|||||||
+1
-3
@@ -46,10 +46,8 @@ open class DeclarationTable(globalTable: GlobalDeclarationTable) {
|
|||||||
// TODO: we need to disentangle signature construction with declaration tables.
|
// TODO: we need to disentangle signature construction with declaration tables.
|
||||||
open val signaturer: IdSignatureFactory = IdSignatureFactory(globalTable.publicIdSignatureComputer, this)
|
open val signaturer: IdSignatureFactory = IdSignatureFactory(globalTable.publicIdSignatureComputer, this)
|
||||||
|
|
||||||
fun inFile(file: IrFile?, block: () -> Unit) {
|
fun <R> inFile(file: IrFile?, block: () -> R): R =
|
||||||
signaturer.inFile(file?.symbol, block)
|
signaturer.inFile(file?.symbol, block)
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun IrDeclaration.isLocalDeclaration(compatibleMode: Boolean): Boolean {
|
private fun IrDeclaration.isLocalDeclaration(compatibleMode: Boolean): Boolean {
|
||||||
return !isExportedDeclaration(this, compatibleMode)
|
return !isExportedDeclaration(this, compatibleMode)
|
||||||
|
|||||||
+2
-12
@@ -1326,17 +1326,7 @@ open class IrFileSerializer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serializeIrFile(file: IrFile): SerializedIrFile {
|
fun serializeIrFile(file: IrFile): SerializedIrFile = declarationTable.inFile(file) {
|
||||||
var result: SerializedIrFile? = null
|
|
||||||
|
|
||||||
declarationTable.inFile(file) {
|
|
||||||
result = serializeIrFileImpl(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result!!
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun serializeIrFileImpl(file: IrFile): SerializedIrFile {
|
|
||||||
val topLevelDeclarations = mutableListOf<SerializedDeclaration>()
|
val topLevelDeclarations = mutableListOf<SerializedDeclaration>()
|
||||||
|
|
||||||
val proto = ProtoFile.newBuilder()
|
val proto = ProtoFile.newBuilder()
|
||||||
@@ -1379,7 +1369,7 @@ open class IrFileSerializer(
|
|||||||
|
|
||||||
fillPlatformExplicitlyExported(file, proto)
|
fillPlatformExplicitlyExported(file, proto)
|
||||||
|
|
||||||
return SerializedIrFile(
|
SerializedIrFile(
|
||||||
fileData = proto.build().toByteArray(),
|
fileData = proto.build().toByteArray(),
|
||||||
fqName = file.packageFqName.asString(),
|
fqName = file.packageFqName.asString(),
|
||||||
path = file.path,
|
path = file.path,
|
||||||
|
|||||||
+2
-4
@@ -36,7 +36,7 @@ interface IdSignatureComputer {
|
|||||||
* @param block A block within which signatures computed for private declarations will include [file]'s signature.
|
* @param block A block within which signatures computed for private declarations will include [file]'s signature.
|
||||||
* @see [IdSignature.FileSignature]
|
* @see [IdSignature.FileSignature]
|
||||||
*/
|
*/
|
||||||
fun inFile(file: IrFileSymbol?, block: () -> Unit)
|
fun <R> inFile(file: IrFileSymbol?, block: () -> R): R
|
||||||
}
|
}
|
||||||
|
|
||||||
class DescToIrIdSignatureComputer(private val delegate: IdSignatureDescriptor) : IdSignatureComputer {
|
class DescToIrIdSignatureComputer(private val delegate: IdSignatureDescriptor) : IdSignatureComputer {
|
||||||
@@ -49,7 +49,5 @@ class DescToIrIdSignatureComputer(private val delegate: IdSignatureDescriptor) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun inFile(file: IrFileSymbol?, block: () -> Unit) {
|
override fun <R> inFile(file: IrFileSymbol?, block: () -> R): R = block()
|
||||||
block()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -39,12 +39,13 @@ class PublicIdSignatureComputer(val mangler: KotlinMangler.IrMangler) : IdSignat
|
|||||||
|
|
||||||
private var currentFileSignatureX: IdSignature.FileSignature? = null
|
private var currentFileSignatureX: IdSignature.FileSignature? = null
|
||||||
|
|
||||||
override fun inFile(file: IrFileSymbol?, block: () -> Unit) {
|
override fun <R> inFile(file: IrFileSymbol?, block: () -> R): R {
|
||||||
currentFileSignatureX = file?.let { IdSignature.FileSignature(it) }
|
currentFileSignatureX = file?.let { IdSignature.FileSignature(it) }
|
||||||
|
try {
|
||||||
block()
|
return block()
|
||||||
|
} finally {
|
||||||
currentFileSignatureX = null
|
currentFileSignatureX = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrDeclaration.checkIfPlatformSpecificExport(): Boolean = mangler.run { isPlatformSpecificExport() }
|
private fun IrDeclaration.checkIfPlatformSpecificExport(): Boolean = mangler.run { isPlatformSpecificExport() }
|
||||||
@@ -211,9 +212,8 @@ class IdSignatureFactory(
|
|||||||
private var localIndex: Long = startIndex.toLong()
|
private var localIndex: Long = startIndex.toLong()
|
||||||
private var scopeIndex: Int = startIndex
|
private var scopeIndex: Int = startIndex
|
||||||
|
|
||||||
override fun inFile(file: IrFileSymbol?, block: () -> Unit) {
|
override fun <R> inFile(file: IrFileSymbol?, block: () -> R): R =
|
||||||
publicSignatureBuilder.inFile(file, block)
|
publicSignatureBuilder.inFile(file, block)
|
||||||
}
|
|
||||||
|
|
||||||
private fun composeContainerIdSignature(container: IrDeclarationParent, compatibleMode: Boolean): IdSignature =
|
private fun composeContainerIdSignature(container: IrDeclarationParent, compatibleMode: Boolean): IdSignature =
|
||||||
when (container) {
|
when (container) {
|
||||||
|
|||||||
Reference in New Issue
Block a user