Fir2Ir: put properties data from IrBuiltinsOverFir into symbol table
Properties themselves, accessors, backing fields.
This commit is contained in:
committed by
Alexander Udalov
parent
12b2828499
commit
571ba9298e
@@ -934,32 +934,41 @@ class IrBuiltInsOverFir(
|
||||
}
|
||||
|
||||
if (withGetter) {
|
||||
property.getter = irFactory.buildFun {
|
||||
this.name = Name.special("<get-$propertyName>")
|
||||
property.addGetter {
|
||||
this.returnType = returnType
|
||||
this.modality = modality
|
||||
this.isOperator = false
|
||||
}.also { getter ->
|
||||
getter.addDispatchReceiver { type = this@createProperty.defaultType }
|
||||
getter.parent = this
|
||||
getter.correspondingPropertySymbol = property.symbol
|
||||
getter.overriddenSymbols = property.overriddenSymbols.mapNotNull { it.owner.getter?.symbol }
|
||||
}
|
||||
}
|
||||
if (withField || fieldInit != null) {
|
||||
property.backingField = irFactory.buildField {
|
||||
this.name = property.name
|
||||
this.type = defaultType
|
||||
property.addBackingField {
|
||||
this.type = returnType
|
||||
this.isFinal = isConst
|
||||
}.also {
|
||||
if (fieldInit != null) {
|
||||
it.initializer = irFactory.createExpressionBody(0, 0) {
|
||||
expression = fieldInit
|
||||
}
|
||||
}
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
}
|
||||
}
|
||||
property.builder()
|
||||
components.symbolTable.declarePropertyWithSignature(
|
||||
irSignatureBuilder.computeSignature(property), property.symbol
|
||||
)
|
||||
property.getter?.let {
|
||||
components.symbolTable.declareSimpleFunctionWithSignature(
|
||||
irSignatureBuilder.computeSignature(it), it.symbol
|
||||
)
|
||||
}
|
||||
property.backingField?.let {
|
||||
components.symbolTable.declareFieldWithSignature(
|
||||
irSignatureBuilder.computeSignature(it), it.symbol
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -140,6 +140,18 @@ fun IrProperty.addDefaultGetter(parentClass: IrClass, builtIns: IrBuiltIns) {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun IrProperty.addBackingField(builder: IrFieldBuilder.() -> Unit = {}): IrField =
|
||||
IrFieldBuilder().run {
|
||||
name = this@addBackingField.name
|
||||
origin = IrDeclarationOrigin.PROPERTY_BACKING_FIELD
|
||||
builder()
|
||||
factory.buildField(this).also { field ->
|
||||
this@addBackingField.backingField = field
|
||||
field.correspondingPropertySymbol = this@addBackingField.symbol
|
||||
field.parent = this@addBackingField.parent
|
||||
}
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildFunction(builder: IrFunctionBuilder): IrSimpleFunction = with(builder) {
|
||||
createFunction(
|
||||
|
||||
@@ -683,6 +683,10 @@ open class SymbolTable(
|
||||
}
|
||||
}
|
||||
|
||||
fun declareFieldWithSignature(sig: IdSignature, symbol: IrFieldSymbol) {
|
||||
fieldSymbolTable.set(sig, symbol)
|
||||
}
|
||||
|
||||
override fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol =
|
||||
fieldSymbolTable.referenced(descriptor) { signature -> createFieldSymbol(descriptor, signature) }
|
||||
|
||||
@@ -760,6 +764,10 @@ open class SymbolTable(
|
||||
}
|
||||
}
|
||||
|
||||
fun declarePropertyWithSignature(sig: IdSignature, symbol: IrPropertySymbol) {
|
||||
propertySymbolTable.set(sig, symbol)
|
||||
}
|
||||
|
||||
override fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
|
||||
propertySymbolTable.referenced(descriptor) { signature -> createPropertySymbol(descriptor, signature) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user