[FIR2IR] Implement getIrConstructorSymbol like getIrFunctionSymbol
This commit is contained in:
+20
-12
@@ -497,7 +497,18 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCachedIrConstructor(constructor: FirConstructor): IrConstructor? = constructorCache[constructor]
|
fun getCachedIrConstructor(
|
||||||
|
constructor: FirConstructor,
|
||||||
|
signatureCalculator: (FirConstructor) -> IdSignature? = { null }
|
||||||
|
): IrConstructor? {
|
||||||
|
return constructorCache[constructor] ?: signatureCalculator(constructor)?.let { signature ->
|
||||||
|
symbolTable.referenceConstructorIfAny(signature)?.let { irConstructorSymbol ->
|
||||||
|
val irConstructor = irConstructorSymbol.owner
|
||||||
|
constructorCache[constructor] = irConstructor
|
||||||
|
irConstructor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
||||||
if (signature == null) {
|
if (signature == null) {
|
||||||
@@ -994,17 +1005,14 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
|
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
|
||||||
val firConstructor = firConstructorSymbol.fir
|
val firConstructor = firConstructorSymbol.fir
|
||||||
getCachedIrConstructor(firConstructor)?.let { return it.symbol }
|
val irParent by lazy { findIrParent(firConstructor) }
|
||||||
|
getCachedIrConstructor(firConstructor) {
|
||||||
|
irParent
|
||||||
|
signatureComposer.composeSignature(firConstructor)
|
||||||
|
}?.let { return it.symbol }
|
||||||
val signature = signatureComposer.composeSignature(firConstructor)
|
val signature = signatureComposer.composeSignature(firConstructor)
|
||||||
val irParent = findIrParent(firConstructor) as? IrClass
|
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||||
?: error("sadsad")
|
|
||||||
val parentOrigin = irParent.origin
|
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
symbolTable.referenceConstructorIfAny(signature)?.let { irConstructorSymbol ->
|
|
||||||
val irFunction = irConstructorSymbol.owner
|
|
||||||
constructorCache[firConstructor] = irFunction
|
|
||||||
return irConstructorSymbol
|
|
||||||
}
|
|
||||||
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||||
"Should not have reference to public API uncached constructor from source code"
|
"Should not have reference to public API uncached constructor from source code"
|
||||||
}
|
}
|
||||||
@@ -1014,7 +1022,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
Fir2IrLazyConstructor(
|
Fir2IrLazyConstructor(
|
||||||
components, startOffset, endOffset, parentOrigin, firConstructor, symbol
|
components, startOffset, endOffset, parentOrigin, firConstructor, symbol
|
||||||
).apply {
|
).apply {
|
||||||
parent = irParent
|
parent = irParent!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1023,7 +1031,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
(irConstructor as Fir2IrLazyConstructor).prepareTypeParameters()
|
(irConstructor as Fir2IrLazyConstructor).prepareTypeParameters()
|
||||||
return symbol
|
return symbol
|
||||||
}
|
}
|
||||||
val irDeclaration = createIrConstructor(firConstructor, irParent, origin = parentOrigin).apply {
|
val irDeclaration = createIrConstructor(firConstructor, irParent as IrClass, origin = parentOrigin).apply {
|
||||||
setAndModifyParent(irParent)
|
setAndModifyParent(irParent)
|
||||||
}
|
}
|
||||||
return irDeclaration.symbol
|
return irDeclaration.symbol
|
||||||
|
|||||||
Reference in New Issue
Block a user