IR: use IrFactory in psi2ir

This commit is contained in:
Alexander Udalov
2020-07-13 19:09:43 +02:00
parent 8c41ba8ee4
commit 305288aa82
7 changed files with 25 additions and 25 deletions
@@ -29,8 +29,6 @@ import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irTemporary
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
import org.jetbrains.kotlin.ir.expressions.*
@@ -392,7 +390,7 @@ private fun StatementGenerator.createFunctionForSuspendConversion(
val irAdapterFun = context.symbolTable.declareSimpleFunction(
adapterFunctionDescriptor
) { irAdapterSymbol ->
IrFunctionImpl(
context.irFactory.createFunction(
startOffset, endOffset,
IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION,
irAdapterSymbol,
@@ -418,7 +416,7 @@ private fun StatementGenerator.createFunctionForSuspendConversion(
adaptedParameterDescriptor,
irParameterType,
) { irValueParameterSymbol ->
IrValueParameterImpl(
context.irFactory.createValueParameter(
startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION,
irValueParameterSymbol,
Name.identifier("p$index"),
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.withScope
@@ -54,7 +52,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
is KtScript ->
ScriptGenerator(this).generateScriptDeclaration(ktDeclaration)
else ->
IrErrorDeclarationImpl(
context.irFactory.createErrorDeclaration(
ktDeclaration.startOffsetSkippingComments, ktDeclaration.endOffset,
getOrFail(BindingContext.DECLARATION_TO_DESCRIPTOR, ktDeclaration)
)
@@ -85,7 +83,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
private fun generateTypeAliasDeclaration(ktTypeAlias: KtTypeAlias): IrTypeAlias =
with(getOrFail(BindingContext.TYPE_ALIAS, ktTypeAlias)) {
context.symbolTable.declareTypeAlias(this) { symbol ->
IrTypeAliasImpl(
context.irFactory.createTypeAlias(
ktTypeAlias.startOffsetSkippingComments, ktTypeAlias.endOffset, symbol,
name, visibility, expandedType.toIrType(), isActual, IrDeclarationOrigin.DEFINED
)
@@ -183,4 +181,4 @@ abstract class DeclarationGeneratorExtension(val declarationGenerator: Declarati
}
fun Generator.createBodyGenerator(scopeOwnerSymbol: IrSymbol) =
BodyGenerator(scopeOwnerSymbol, context)
BodyGenerator(scopeOwnerSymbol, context)
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.builders.irBlockBody
import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irReturn
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptorImpl
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
@@ -133,7 +132,7 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
context.symbolTable.declareField(
startOffset, endOffset, origin, delegateDescriptor, type
) {
IrFieldImpl(
context.irFactory.createField(
startOffset, endOffset, origin, it, delegateDescriptor.name, type, delegateDescriptor.visibility,
!delegateDescriptor.isVar, false, delegateDescriptor.dispatchReceiverParameter == null
).apply {
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrExpression
@@ -253,7 +252,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
val origin = IrDeclarationOrigin.DEFINED
return context.symbolTable.declareConstructor(constructorDescriptor) {
with(constructorDescriptor) {
IrConstructorImpl(
context.irFactory.createConstructor(
startOffset, endOffset, origin, it, context.symbolTable.nameProvider.nameForDeclaration(this),
visibility, IrUninitializedType, isInline, isEffectivelyExternal(), isPrimary, isExpect
)
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.NotFoundClasses
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
@@ -32,6 +33,7 @@ class GeneratorContext(
val constantValueGenerator: ConstantValueGenerator,
override val irBuiltIns: IrBuiltIns
) : IrGeneratorContext {
val irFactory: IrFactory get() = symbolTable.irFactory
val callToSubstitutedDescriptorMap = mutableMapOf<IrDeclarationReference, CallableDescriptor>()
@@ -26,8 +26,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
import org.jetbrains.kotlin.ir.expressions.*
@@ -345,7 +343,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
return context.symbolTable.declareSimpleFunction(
adapterFunctionDescriptor
) { irAdapterSymbol ->
IrFunctionImpl(
context.irFactory.createFunction(
startOffset, endOffset,
IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE,
irAdapterSymbol,
@@ -400,7 +398,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
return context.symbolTable.declareValueParameter(
startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE, descriptor, type.toIrType()
) { irAdapterParameterSymbol ->
IrValueParameterImpl(
context.irFactory.createValueParameter(
startOffset, endOffset,
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE,
irAdapterParameterSymbol,
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.*
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
@@ -27,6 +26,7 @@ import org.jetbrains.kotlin.types.KotlinType
class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
private val typeTranslator = context.typeTranslator
private val symbolTable = context.symbolTable
private val irFactory = context.irFactory
// TODO: use this generator in psi2ir too
@@ -97,9 +97,11 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
return irClass
}
fun generateEnumEntry(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, symbol: IrEnumEntrySymbol): IrEnumEntry {
fun generateEnumEntry(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, symbol: IrEnumEntrySymbol
): IrEnumEntry {
// TODO: corresponging class?
val irEntry = IrEnumEntryImpl(startOffset, endOffset, origin, symbol, descriptor.name)
val irEntry = irFactory.createEnumEntry(startOffset, endOffset, origin, symbol, descriptor.name)
return irEntry
}
@@ -111,7 +113,9 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
descriptor: TypeAliasDescriptor,
symbol: IrTypeAliasSymbol
): IrTypeAlias = with(descriptor) {
IrTypeAliasImpl(startOffset, endOffset, symbol, name, visibility, expandedType.toIrType(), isActual, origin).also {
irFactory.createTypeAlias(
startOffset, endOffset, symbol, name, visibility, expandedType.toIrType(), isActual, origin
).also {
generateGlobalTypeParametersDeclarations(it, declaredTypeParameters)
}
}
@@ -156,7 +160,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
defaultArgumentFactory: IrFunction.(IrValueParameter) -> IrExpressionBody? = { null }
): IrConstructor {
val irConstructor = with(descriptor) {
IrConstructorImpl(
irFactory.createConstructor(
startOffset, endOffset, origin, symbol, name, visibility, IrUninitializedType, isInline,
isEffectivelyExternal(), isPrimary, isExpect
)
@@ -182,7 +186,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
defaultArgumentFactory: IrFunction.(IrValueParameter) -> IrExpressionBody? = { null }
): IrSimpleFunction {
val irFunction = with(descriptor) {
IrFunctionImpl(
irFactory.createFunction(
startOffset, endOffset, origin, symbol, name, visibility, modality, IrUninitializedType,
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect
)
@@ -199,8 +203,10 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
return irFunction
}
fun generateProperty(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor, symbol: IrPropertySymbol): IrProperty {
val irProperty = IrPropertyImpl(
fun generateProperty(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor, symbol: IrPropertySymbol
): IrProperty {
val irProperty = irFactory.createProperty(
startOffset, endOffset, origin, symbol,
name = descriptor.name,
visibility = descriptor.visibility,