[IR] Reorder parameters in IrFactory#createField
This is to prepare for IrFactory auto-generation (KT-59308).
This commit is contained in:
committed by
Space Team
parent
90f6c53bf8
commit
0b7db067e6
@@ -149,15 +149,16 @@ class Fir2IrClassifierStorage(
|
||||
val contextReceiverFields = mutableListOf<IrField>()
|
||||
for ((index, contextReceiver) in klass.contextReceivers.withIndex()) {
|
||||
val irField = components.irFactory.createField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.FIELD_FOR_CLASS_CONTEXT_RECEIVER,
|
||||
IrFieldSymbolImpl(),
|
||||
Name.identifier("contextReceiverField$index"),
|
||||
contextReceiver.typeRef.toIrType(),
|
||||
DescriptorVisibilities.PRIVATE,
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.FIELD_FOR_CLASS_CONTEXT_RECEIVER,
|
||||
name = Name.identifier("contextReceiverField$index"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = contextReceiver.typeRef.toIrType(),
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
isStatic = false
|
||||
)
|
||||
irField.parent = this@createContextReceiverFields
|
||||
contextReceiverFields.add(irField)
|
||||
|
||||
+27
-12
@@ -798,11 +798,16 @@ class Fir2IrDeclarationStorage(
|
||||
val inferredType = type ?: firInitializerExpression!!.typeRef.toIrType()
|
||||
return declareIrField { symbol ->
|
||||
irFactory.createField(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
name, inferredType,
|
||||
visibility, isFinal = isFinal,
|
||||
isExternal = property.isExternal,
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = name,
|
||||
visibility = visibility,
|
||||
symbol = symbol,
|
||||
type = inferredType,
|
||||
isFinal = isFinal,
|
||||
isStatic = property.isStatic || !(parent is IrClass || parent is IrScript),
|
||||
isExternal = property.isExternal,
|
||||
).also {
|
||||
it.correspondingPropertySymbol = this@createBackingField.symbol
|
||||
}.apply {
|
||||
@@ -1122,20 +1127,30 @@ class Fir2IrDeclarationStorage(
|
||||
signature, symbolFactory = { IrFieldPublicSymbolImpl(signature) }
|
||||
) { symbol ->
|
||||
irFactory.createField(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = symbol,
|
||||
type = type,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isExternal = false,
|
||||
isStatic = field.isStatic
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
)
|
||||
}
|
||||
} else {
|
||||
irFactory.createField(
|
||||
startOffset, endOffset, origin, IrFieldSymbolImpl(),
|
||||
field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = type,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isExternal = false,
|
||||
isStatic = field.isStatic
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
)
|
||||
}.apply {
|
||||
val staticFakeOverrideKey = getFieldStaticFakeOverrideKey(field, containingClassLookupTag)
|
||||
|
||||
+10
-8
@@ -856,14 +856,16 @@ class LocalDeclarationsLowering(
|
||||
else
|
||||
DECLARATION_ORIGIN_FIELD_FOR_CAPTURED_VALUE
|
||||
context.irFactory.createField(
|
||||
classDeclaration.startOffset,
|
||||
classDeclaration.endOffset,
|
||||
origin,
|
||||
symbol,
|
||||
suggestNameForCapturedValue(capturedValue, generatedNames),
|
||||
capturedValue.type,
|
||||
visibilityPolicy.forCapturedField(capturedValue.symbol),
|
||||
isFinal = true, isExternal = false, isStatic = false,
|
||||
startOffset = classDeclaration.startOffset,
|
||||
endOffset = classDeclaration.endOffset,
|
||||
origin = origin,
|
||||
name = suggestNameForCapturedValue(capturedValue, generatedNames),
|
||||
visibility = visibilityPolicy.forCapturedField(capturedValue.symbol),
|
||||
symbol = symbol,
|
||||
type = capturedValue.type,
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
).also {
|
||||
it.parent = classDeclaration
|
||||
}
|
||||
|
||||
+20
-7
@@ -173,9 +173,16 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext, val inner
|
||||
|
||||
val earlierScriptField = irScript.earlierScriptsParameter?.let { earlierScriptsParameter ->
|
||||
irScriptClass.factory.createField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.SCRIPT_EARLIER_SCRIPTS,
|
||||
IrFieldSymbolImpl(), Name.identifier("\$\$earlierScripts"), earlierScriptsParameter.type,
|
||||
DescriptorVisibilities.PRIVATE, isFinal = true, isExternal = false, isStatic = false
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.SCRIPT_EARLIER_SCRIPTS,
|
||||
name = Name.identifier("\$\$earlierScripts"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = earlierScriptsParameter.type,
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
)
|
||||
}?.also {
|
||||
it.parent = irScriptClass
|
||||
@@ -185,10 +192,16 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext, val inner
|
||||
val implicitReceiversFieldsWithParameters = arrayListOf<Pair<IrField, IrValueParameter>>().apply {
|
||||
irScript.implicitReceiversParameters.forEach { param ->
|
||||
val field = irScriptClass.factory.createField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.SCRIPT_IMPLICIT_RECEIVER,
|
||||
IrFieldSymbolImpl(), Name.identifier("\$\$implicitReceiver_${param.type.classFqName?.shortName()?.asString()!!}"),
|
||||
typeRemapper.remapType(param.type),
|
||||
DescriptorVisibilities.PRIVATE, isFinal = true, isExternal = false, isStatic = false
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.SCRIPT_IMPLICIT_RECEIVER,
|
||||
name = Name.identifier("\$\$implicitReceiver_${param.type.classFqName?.shortName()?.asString()!!}"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = typeRemapper.remapType(param.type),
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false
|
||||
)
|
||||
field.parent = irScriptClass
|
||||
irScriptClass.declarations.add(field)
|
||||
|
||||
+8
-7
@@ -101,15 +101,16 @@ internal class WasmPropertyReferenceLowering(val context: WasmBackendContext) :
|
||||
|
||||
val kPropertiesField =
|
||||
context.irFactory.createField(
|
||||
SYNTHETIC_OFFSET, SYNTHETIC_OFFSET,
|
||||
DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION,
|
||||
IrFieldSymbolImpl(),
|
||||
Name.identifier("\$KPROPERTIES"),
|
||||
kPropertiesFieldType,
|
||||
DescriptorVisibilities.PRIVATE,
|
||||
startOffset = SYNTHETIC_OFFSET,
|
||||
endOffset = SYNTHETIC_OFFSET,
|
||||
origin = DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION,
|
||||
name = Name.identifier("\$KPROPERTIES"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = kPropertiesFieldType,
|
||||
isFinal = true,
|
||||
isExternal = false,
|
||||
isStatic = true,
|
||||
isExternal = false,
|
||||
).apply {
|
||||
parent = irFile
|
||||
}
|
||||
|
||||
+8
-8
@@ -172,16 +172,16 @@ class WasmSharedVariablesManager(val context: JsCommonBackendContext, val builtI
|
||||
val symbol = IrFieldSymbolImpl()
|
||||
val fieldName = Name.identifier("v")
|
||||
return context.irFactory.createField(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.FIELD_FOR_OUTER_THIS,
|
||||
symbol,
|
||||
fieldName,
|
||||
builtIns.anyNType,
|
||||
DescriptorVisibilities.PUBLIC,
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.FIELD_FOR_OUTER_THIS,
|
||||
name = fieldName,
|
||||
visibility = DescriptorVisibilities.PUBLIC,
|
||||
symbol = symbol,
|
||||
type = builtIns.anyNType,
|
||||
isFinal = false,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
).also {
|
||||
it.parent = closureBoxClassDeclaration
|
||||
closureBoxClassDeclaration.declarations += it
|
||||
|
||||
@@ -451,15 +451,16 @@ internal class ClassGenerator(
|
||||
private fun generateFieldsForContextReceivers(irClass: IrClass, classDescriptor: ClassDescriptor) {
|
||||
for ((fieldIndex, receiverDescriptor) in classDescriptor.contextReceivers.withIndex()) {
|
||||
val irField = context.irFactory.createField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.FIELD_FOR_CLASS_CONTEXT_RECEIVER,
|
||||
IrFieldSymbolImpl(),
|
||||
Name.identifier("contextReceiverField$fieldIndex"),
|
||||
receiverDescriptor.type.toIrType(),
|
||||
DescriptorVisibilities.PRIVATE,
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.FIELD_FOR_CLASS_CONTEXT_RECEIVER,
|
||||
name = Name.identifier("contextReceiverField$fieldIndex"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = receiverDescriptor.type.toIrType(),
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
isStatic = false
|
||||
)
|
||||
context.additionalDescriptorStorage.put(receiverDescriptor.value, irField)
|
||||
irClass.addMember(irField)
|
||||
|
||||
+10
-2
@@ -143,8 +143,16 @@ internal class DelegatedPropertyGenerator(
|
||||
startOffset, endOffset, origin, delegateDescriptor, type
|
||||
) {
|
||||
context.irFactory.createField(
|
||||
startOffset, endOffset, origin, it, delegateDescriptor.name, type, delegateDescriptor.visibility,
|
||||
!delegateDescriptor.isVar, false, delegateDescriptor.dispatchReceiverParameter == null
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = delegateDescriptor.name,
|
||||
visibility = delegateDescriptor.visibility,
|
||||
symbol = it,
|
||||
type = type,
|
||||
isFinal = !delegateDescriptor.isVar,
|
||||
isStatic = delegateDescriptor.dispatchReceiverParameter == null,
|
||||
isExternal = false
|
||||
).apply {
|
||||
metadata = DescriptorMetadataSource.Property(propertyDescriptor)
|
||||
}
|
||||
|
||||
+10
-3
@@ -43,9 +43,16 @@ inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) =
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildField(builder: IrFieldBuilder): IrField = with(builder) {
|
||||
createField(
|
||||
startOffset, endOffset, origin,
|
||||
IrFieldSymbolImpl(),
|
||||
name, type, visibility, isFinal, isExternal, isStatic,
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = name,
|
||||
visibility = visibility,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = type,
|
||||
isFinal = isFinal,
|
||||
isStatic = isStatic,
|
||||
isExternal = isExternal,
|
||||
).also {
|
||||
it.metadata = metadata
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ interface IrFactory {
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrFieldSymbol,
|
||||
name: Name,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility,
|
||||
symbol: IrFieldSymbol,
|
||||
type: IrType,
|
||||
isFinal: Boolean,
|
||||
isExternal: Boolean,
|
||||
isStatic: Boolean,
|
||||
isExternal: Boolean,
|
||||
): IrField
|
||||
|
||||
fun createFunction(
|
||||
|
||||
@@ -97,13 +97,13 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrFieldSymbol,
|
||||
name: Name,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility,
|
||||
symbol: IrFieldSymbol,
|
||||
type: IrType,
|
||||
isFinal: Boolean,
|
||||
isExternal: Boolean,
|
||||
isStatic: Boolean,
|
||||
isExternal: Boolean,
|
||||
): IrField =
|
||||
IrFieldImpl(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic, factory = this)
|
||||
|
||||
|
||||
+7
-7
@@ -138,25 +138,25 @@ class IrFactoryImplForJsIC(override val stageController: StageController) : Abst
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrFieldSymbol,
|
||||
name: Name,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility,
|
||||
symbol: IrFieldSymbol,
|
||||
type: IrType,
|
||||
isFinal: Boolean,
|
||||
isExternal: Boolean,
|
||||
isStatic: Boolean
|
||||
isStatic: Boolean,
|
||||
isExternal: Boolean
|
||||
): IrField {
|
||||
return super.createField(
|
||||
startOffset,
|
||||
endOffset,
|
||||
origin,
|
||||
symbol,
|
||||
name,
|
||||
type,
|
||||
visibility,
|
||||
symbol,
|
||||
type,
|
||||
isFinal,
|
||||
isExternal,
|
||||
isStatic,
|
||||
isExternal,
|
||||
).register()
|
||||
}
|
||||
|
||||
|
||||
@@ -81,17 +81,17 @@ class LazyIrFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrFieldSymbol,
|
||||
name: Name,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility,
|
||||
symbol: IrFieldSymbol,
|
||||
type: IrType,
|
||||
isFinal: Boolean,
|
||||
isExternal: Boolean,
|
||||
isStatic: Boolean
|
||||
isStatic: Boolean,
|
||||
isExternal: Boolean
|
||||
): IrField = if (symbol.isBound)
|
||||
symbol.owner
|
||||
else
|
||||
delegate.createField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic)
|
||||
delegate.createField(startOffset, endOffset, origin, name, visibility, symbol, type, isFinal, isStatic, isExternal)
|
||||
|
||||
override fun createFunction(
|
||||
startOffset: Int,
|
||||
|
||||
@@ -264,15 +264,16 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
|
||||
override fun visitField(declaration: IrField): IrField =
|
||||
declaration.factory.createField(
|
||||
declaration.startOffset, declaration.endOffset,
|
||||
mapDeclarationOrigin(declaration.origin),
|
||||
symbolRemapper.getDeclaredField(declaration.symbol),
|
||||
symbolRenamer.getFieldName(declaration.symbol),
|
||||
declaration.type.remapType(),
|
||||
declaration.visibility,
|
||||
startOffset = declaration.startOffset,
|
||||
endOffset = declaration.endOffset,
|
||||
origin = mapDeclarationOrigin(declaration.origin),
|
||||
name = symbolRenamer.getFieldName(declaration.symbol),
|
||||
visibility = declaration.visibility,
|
||||
symbol = symbolRemapper.getDeclaredField(declaration.symbol),
|
||||
type = declaration.type.remapType(),
|
||||
isFinal = declaration.isFinal,
|
||||
isExternal = declaration.isExternal,
|
||||
isStatic = declaration.isStatic,
|
||||
isExternal = declaration.isExternal,
|
||||
).apply {
|
||||
transformAnnotations(declaration)
|
||||
initializer = declaration.initializer?.transform()
|
||||
|
||||
@@ -715,9 +715,16 @@ open class SymbolTable(
|
||||
visibility: DescriptorVisibility? = null,
|
||||
fieldFactory: (IrFieldSymbol) -> IrField = {
|
||||
irFactory.createField(
|
||||
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type,
|
||||
visibility ?: it.descriptor.visibility, !it.descriptor.isVar, it.descriptor.isEffectivelyExternal(),
|
||||
it.descriptor.dispatchReceiverParameter == null
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = nameProvider.nameForDeclaration(descriptor),
|
||||
visibility = visibility ?: it.descriptor.visibility,
|
||||
symbol = it,
|
||||
type = type,
|
||||
isFinal = !it.descriptor.isVar,
|
||||
isStatic = it.descriptor.dispatchReceiverParameter == null,
|
||||
isExternal = it.descriptor.isEffectivelyExternal(),
|
||||
).apply {
|
||||
metadata = DescriptorMetadataSource.Property(it.descriptor)
|
||||
}
|
||||
|
||||
+10
-8
@@ -690,14 +690,16 @@ class IrDeclarationDeserializer(
|
||||
|
||||
val field = symbolTable.declareField(uniqId, { symbol.checkSymbolType(FIELD_SYMBOL) }) {
|
||||
irFactory.createField(
|
||||
startOffset, endOffset, origin,
|
||||
it,
|
||||
deserializeName(nameType.nameIndex),
|
||||
type,
|
||||
flags.visibility,
|
||||
flags.isFinal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isStatic,
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = deserializeName(nameType.nameIndex),
|
||||
visibility = flags.visibility,
|
||||
symbol = it,
|
||||
type = type,
|
||||
isFinal = flags.isFinal,
|
||||
isStatic = flags.isStatic,
|
||||
isExternal = flags.isExternal || isEffectivelyExternal,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -167,16 +167,16 @@ internal class CStructVarClassGenerator(
|
||||
}
|
||||
|
||||
val cleanerField = irFactory.createField(
|
||||
SYNTHETIC_OFFSET,
|
||||
SYNTHETIC_OFFSET,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
IrFieldSymbolImpl(),
|
||||
Name.identifier("cleaner"),
|
||||
symbols.createCleaner.owner.returnType,
|
||||
DescriptorVisibilities.PRIVATE,
|
||||
startOffset = SYNTHETIC_OFFSET,
|
||||
endOffset = SYNTHETIC_OFFSET,
|
||||
origin = IrDeclarationOrigin.DEFINED,
|
||||
name = Name.identifier("cleaner"),
|
||||
visibility = DescriptorVisibilities.PRIVATE,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = symbols.createCleaner.owner.returnType,
|
||||
isFinal = true,
|
||||
isStatic = false,
|
||||
isExternal = false,
|
||||
isStatic = false
|
||||
).also { field ->
|
||||
field.parent = irClass
|
||||
field.initializer = irBuilder(irBuiltIns, field.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).run {
|
||||
|
||||
+10
-3
@@ -136,9 +136,16 @@ fun AndroidIrBuilder.getParcelableCreator(irClass: IrClass): IrExpression {
|
||||
// field access.
|
||||
val creatorType = androidSymbols.androidOsParcelableCreator.typeWith(irClass.symbol.starProjectedType)
|
||||
val creatorField = irClass.factory.createField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
|
||||
IrFieldSymbolImpl(), CREATOR_NAME, creatorType, DescriptorVisibilities.PUBLIC,
|
||||
isFinal = true, isExternal = false, isStatic = true,
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
|
||||
name = CREATOR_NAME,
|
||||
visibility = DescriptorVisibilities.PUBLIC,
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = creatorType,
|
||||
isFinal = true,
|
||||
isStatic = true,
|
||||
isExternal = false,
|
||||
).also { it.parent = irClass }
|
||||
|
||||
return irGetField(null, creatorField)
|
||||
|
||||
Reference in New Issue
Block a user