DeclarationStubGenerator uses IrTypes

This commit is contained in:
Dmitry Petrov
2018-04-26 16:03:52 +03:00
parent 1353cf879c
commit 372f280578
10 changed files with 75 additions and 63 deletions
@@ -19,11 +19,12 @@ package org.jetbrains.kotlin.psi2ir
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.util.AnnotationGenerator
import org.jetbrains.kotlin.ir.util.patchDeclarationParents import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
import org.jetbrains.kotlin.psi2ir.generators.ModuleGenerator import org.jetbrains.kotlin.psi2ir.generators.ModuleGenerator
import org.jetbrains.kotlin.psi2ir.transformations.generateAnnotationsForDeclarations import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
@@ -63,4 +64,9 @@ class Psi2IrTranslator(val configuration: Psi2IrConfiguration = Psi2IrConfigurat
irElement.patchDeclarationParents() irElement.patchDeclarationParents()
} }
private fun generateAnnotationsForDeclarations(context: GeneratorContext, irElement: IrElement) {
val annotationGenerator = AnnotationGenerator(context.moduleDescriptor, context.symbolTable)
irElement.acceptVoid(annotationGenerator)
}
} }
@@ -22,13 +22,13 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.transformations.AnnotationGenerator import org.jetbrains.kotlin.ir.util.AnnotationGenerator
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile
class ModuleGenerator(override val context: GeneratorContext) : Generator { class ModuleGenerator(override val context: GeneratorContext) : Generator {
private val annotationGenerator = AnnotationGenerator(context) private val annotationGenerator = AnnotationGenerator(context.moduleDescriptor, context.symbolTable)
fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment = fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment =
generateModuleFragmentWithoutDependencies(ktFiles).also { irModule -> generateModuleFragmentWithoutDependencies(ktFiles).also { irModule ->
@@ -41,7 +41,9 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
} }
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) { fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) {
ExternalDependenciesGenerator(context.symbolTable, context.irBuiltIns).generateUnboundSymbolsAsDependencies(irModule) ExternalDependenciesGenerator(
irModule.descriptor, context.symbolTable, context.irBuiltIns
).generateUnboundSymbolsAsDependencies(irModule)
} }
private fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> { private fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> {
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset
@@ -42,7 +43,6 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import java.lang.AssertionError
class StatementGenerator( class StatementGenerator(
val bodyGenerator: BodyGenerator, val bodyGenerator: BodyGenerator,
@@ -206,7 +206,7 @@ class StatementGenerator(
) )
fun generateConstantExpression(expression: KtExpression, constant: CompileTimeConstant<*>): IrExpression = fun generateConstantExpression(expression: KtExpression, constant: CompileTimeConstant<*>): IrExpression =
ConstantValueGenerator(context).generateConstantValueAsExpression( ConstantValueGenerator(context.moduleDescriptor, context.symbolTable, null).generateConstantValueAsExpression(
expression.startOffset, expression.startOffset,
expression.endOffset, expression.endOffset,
constant.toConstantValue(getInferredTypeWithImplicitCastsOrFail(expression)) constant.toConstantValue(getInferredTypeWithImplicitCastsOrFail(expression))
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.util.ScopedTypeParametersResolver
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.psi2ir.containsNull import org.jetbrains.kotlin.psi2ir.containsNull
@@ -3,7 +3,7 @@
* that can be found in the license/LICENSE.txt file. * that can be found in the license/LICENSE.txt file.
*/ */
package org.jetbrains.kotlin.psi2ir.transformations package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -16,29 +16,20 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.psi2ir.generators.ConstantValueGenerator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.resolve.source.PsiSourceElement
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.addToStdlib.safeAs
fun generateAnnotationsForDeclarations(context: GeneratorContext, irElement: IrElement) {
val annotationGenerator = AnnotationGenerator(context.moduleDescriptor, context.symbolTable)
irElement.acceptVoid(annotationGenerator)
}
class AnnotationGenerator( class AnnotationGenerator(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
private val symbolTable: SymbolTable private val symbolTable: SymbolTable
) : IrElementVisitorVoid { ) : IrElementVisitorVoid {
constructor(context: GeneratorContext) : this(context.moduleDescriptor, context.symbolTable) private val typeTranslator = TypeTranslator(moduleDescriptor, symbolTable)
private val scopedTypeParameterResolver = ScopedTypeParametersResolver() private val scopedTypeParameterResolver = ScopedTypeParametersResolver()
private val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable, this, scopedTypeParameterResolver) private val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable, this, scopedTypeParameterResolver)
@@ -86,19 +77,24 @@ class AnnotationGenerator(
} }
} }
private fun KotlinType.toIrType() = typeTranslator.translateType(this)
fun generateAnnotationConstructorCall(annotationDescriptor: AnnotationDescriptor): IrCall { fun generateAnnotationConstructorCall(annotationDescriptor: AnnotationDescriptor): IrCall {
val annotationType = annotationDescriptor.type val annotationType = annotationDescriptor.type
val annotationClassDescriptor = annotationType.constructor.declarationDescriptor as? ClassDescriptor val annotationClassDescriptor = annotationType.constructor.declarationDescriptor as? ClassDescriptor
?: throw AssertionError("No declaration descriptor for annotation $annotationDescriptor") ?: throw AssertionError("No declaration descriptor for annotation $annotationDescriptor")
if (annotationClassDescriptor !is ClassDescriptor) {
throw AssertionError("Annotation type descriptor is not a class: $annotationClassDescriptor")
}
assert(DescriptorUtils.isAnnotationClass(annotationClassDescriptor)) { assert(DescriptorUtils.isAnnotationClass(annotationClassDescriptor)) {
"Annotation class expected: $annotationClassDescriptor" "Annotation class expected: $annotationClassDescriptor"
} }
val primaryConstructorDescriptor = val primaryConstructorDescriptor = annotationClassDescriptor.unsubstitutedPrimaryConstructor
annotationClassDescriptor.unsubstitutedPrimaryConstructor ?: annotationClassDescriptor.constructors.singleOrNull()
?: annotationClassDescriptor.constructors.singleOrNull() ?: throw AssertionError("No constructor for annotation class $annotationClassDescriptor")
?: throw AssertionError("No constructor for annotation class $annotationClassDescriptor")
val primaryConstructorSymbol = symbolTable.referenceConstructor(primaryConstructorDescriptor) val primaryConstructorSymbol = symbolTable.referenceConstructor(primaryConstructorDescriptor)
val psi = annotationDescriptor.source.safeAs<PsiSourceElement>()?.psi val psi = annotationDescriptor.source.safeAs<PsiSourceElement>()?.psi
@@ -106,7 +102,8 @@ class AnnotationGenerator(
val endOffset = psi?.startOffset ?: UNDEFINED_OFFSET val endOffset = psi?.startOffset ?: UNDEFINED_OFFSET
val irCall = IrCallImpl( val irCall = IrCallImpl(
startOffset, endOffset, annotationType, startOffset, endOffset,
annotationType.toIrType(),
primaryConstructorSymbol, primaryConstructorDescriptor, primaryConstructorSymbol, primaryConstructorDescriptor,
typeArgumentsCount = 0 typeArgumentsCount = 0
) )
@@ -3,7 +3,7 @@
* that can be found in the license/LICENSE.txt file. * that can be found in the license/LICENSE.txt file.
*/ */
package org.jetbrains.kotlin.psi2ir.generators package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -14,9 +14,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.psi2ir.transformations.AnnotationGenerator
import org.jetbrains.kotlin.psi2ir.transformations.ScopedTypeParametersResolver
import org.jetbrains.kotlin.resolve.constants.* import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.builtIns
@@ -29,10 +26,9 @@ class ConstantValueGenerator(
private val scopedTypeParameterResolver: ScopedTypeParametersResolver? private val scopedTypeParameterResolver: ScopedTypeParametersResolver?
) { ) {
constructor( private val typeTranslator = TypeTranslator(moduleDescriptor, symbolTable)
context: GeneratorContext,
annotationGenerator: AnnotationGenerator? = null private fun KotlinType.toIrType() = typeTranslator.translateType(this)
) : this(context.moduleDescriptor, context.symbolTable, annotationGenerator, null)
fun generateConstantValueAsExpression( fun generateConstantValueAsExpression(
startOffset: Int, startOffset: Int,
@@ -40,7 +36,8 @@ class ConstantValueGenerator(
constantValue: ConstantValue<*>, constantValue: ConstantValue<*>,
varargElementType: KotlinType? = null varargElementType: KotlinType? = null
): IrExpression { ): IrExpression {
val constantType = constantValue.getType(moduleDescriptor) val constantKtType = constantValue.getType(moduleDescriptor)
val constantType = constantKtType.toIrType()
return when (constantValue) { return when (constantValue) {
is StringValue -> IrConstImpl.string(startOffset, endOffset, constantType, constantValue.value) is StringValue -> IrConstImpl.string(startOffset, endOffset, constantType, constantValue.value)
@@ -59,11 +56,11 @@ class ConstantValueGenerator(
is UShortValue -> IrConstImpl.short(startOffset, endOffset, constantType, constantValue.value) is UShortValue -> IrConstImpl.short(startOffset, endOffset, constantType, constantValue.value)
is ArrayValue -> { is ArrayValue -> {
val arrayElementType = varargElementType ?: constantType.getArrayElementType() val arrayElementType = varargElementType ?: constantKtType.getArrayElementType()
IrVarargImpl( IrVarargImpl(
startOffset, endOffset, startOffset, endOffset,
constantType, constantType,
arrayElementType, arrayElementType.toIrType(),
constantValue.value.map { constantValue.value.map {
generateConstantValueAsExpression(startOffset, endOffset, it, null) generateConstantValueAsExpression(startOffset, endOffset, it, null)
} }
@@ -72,7 +69,7 @@ class ConstantValueGenerator(
is EnumValue -> { is EnumValue -> {
val enumEntryDescriptor = val enumEntryDescriptor =
constantType.memberScope.getContributedClassifier(constantValue.enumEntryName, NoLookupLocation.FROM_BACKEND) constantKtType.memberScope.getContributedClassifier(constantValue.enumEntryName, NoLookupLocation.FROM_BACKEND)
?: throw AssertionError("No such enum entry ${constantValue.enumEntryName} in $constantType") ?: throw AssertionError("No such enum entry ${constantValue.enumEntryName} in $constantType")
if (enumEntryDescriptor !is ClassDescriptor) { if (enumEntryDescriptor !is ClassDescriptor) {
throw AssertionError("Enum entry $enumEntryDescriptor should be a ClassDescriptor") throw AssertionError("Enum entry $enumEntryDescriptor should be a ClassDescriptor")
@@ -90,9 +87,9 @@ class ConstantValueGenerator(
} }
is KClassValue -> { is KClassValue -> {
val classifierType = constantValue.value val classifierKtType = constantValue.value
val classifierDescriptor = classifierType.constructor.declarationDescriptor val classifierDescriptor = classifierKtType.constructor.declarationDescriptor
?: throw AssertionError("Unexpected KClassValue: $classifierType") ?: throw AssertionError("Unexpected KClassValue: $classifierKtType")
val typeParameterSymbol = classifierDescriptor.safeAs<TypeParameterDescriptor>()?.let { val typeParameterSymbol = classifierDescriptor.safeAs<TypeParameterDescriptor>()?.let {
scopedTypeParameterResolver?.resolveScopedTypeParameter(it) scopedTypeParameterResolver?.resolveScopedTypeParameter(it)
@@ -100,9 +97,9 @@ class ConstantValueGenerator(
IrClassReferenceImpl( IrClassReferenceImpl(
startOffset, endOffset, startOffset, endOffset,
constantValue.getType(moduleDescriptor), constantValue.getType(moduleDescriptor).toIrType(),
typeParameterSymbol ?: symbolTable.referenceClassifier(classifierDescriptor), typeParameterSymbol ?: symbolTable.referenceClassifier(classifierDescriptor),
classifierType classifierKtType.toIrType()
) )
} }
@@ -29,12 +29,16 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class DeclarationStubGenerator( class DeclarationStubGenerator(
moduleDescriptor: ModuleDescriptor,
val symbolTable: SymbolTable, val symbolTable: SymbolTable,
val origin: IrDeclarationOrigin val origin: IrDeclarationOrigin
) { ) {
private val typeTranslator = TypeTranslator(moduleDescriptor, symbolTable)
fun generateEmptyModuleFragmentStub(descriptor: ModuleDescriptor, irBuiltIns: IrBuiltIns): IrModuleFragment = fun generateEmptyModuleFragmentStub(descriptor: ModuleDescriptor, irBuiltIns: IrBuiltIns): IrModuleFragment =
IrModuleFragmentImpl(descriptor, irBuiltIns) IrModuleFragmentImpl(descriptor, irBuiltIns)
@@ -59,7 +63,10 @@ class DeclarationStubGenerator(
} }
private fun generatePropertyStub(descriptor: PropertyDescriptor): IrProperty = private fun generatePropertyStub(descriptor: PropertyDescriptor): IrProperty =
IrPropertyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irProperty -> IrPropertyImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
descriptor, descriptor.type.toIrType()
).also { irProperty ->
val getterDescriptor = descriptor.getter val getterDescriptor = descriptor.getter
if (getterDescriptor == null) { if (getterDescriptor == null) {
irProperty.backingField = irProperty.backingField =
@@ -97,16 +104,24 @@ class DeclarationStubGenerator(
descriptor.valueParameters.mapTo(function.valueParameters) { generateValueParameterStub(it) } descriptor.valueParameters.mapTo(function.valueParameters) { generateValueParameterStub(it) }
} }
private fun KotlinType.toIrType() = typeTranslator.translateType(this)
private fun ReceiverParameterDescriptor.generateReceiverParameterStub(): IrValueParameter = private fun ReceiverParameterDescriptor.generateReceiverParameterStub(): IrValueParameter =
IrValueParameterImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, this) IrValueParameterImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, this,
type.toIrType(), null
)
private fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter = private fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter =
IrValueParameterImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irValueParameter -> IrValueParameterImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
descriptor, descriptor.type.toIrType(), descriptor.varargElementType?.toIrType()
).also { irValueParameter ->
if (descriptor.declaresDefaultValue()) { if (descriptor.declaresDefaultValue()) {
irValueParameter.defaultValue = irValueParameter.defaultValue =
IrExpressionBodyImpl( IrExpressionBodyImpl(
IrErrorExpressionImpl( IrErrorExpressionImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(),
"Stub expression for default value of ${descriptor.name}" "Stub expression for default value of ${descriptor.name}"
) )
) )
@@ -137,7 +152,10 @@ class DeclarationStubGenerator(
} }
private fun generateTypeParameterStub(descriptor: TypeParameterDescriptor): IrTypeParameter = private fun generateTypeParameterStub(descriptor: TypeParameterDescriptor): IrTypeParameter =
IrTypeParameterImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) IrTypeParameterImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
descriptor, descriptor.upperBounds.map { it.toIrType() }
)
private fun generateMemberStubs(memberScope: MemberScope, container: IrDeclarationContainer) { private fun generateMemberStubs(memberScope: MemberScope, container: IrDeclarationContainer) {
generateChildStubs(memberScope.getContributedDescriptors(), container) generateChildStubs(memberScope.getContributedDescriptors(), container)
@@ -24,9 +24,12 @@ import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
class ExternalDependenciesGenerator(val symbolTable: SymbolTable, val irBuiltIns: IrBuiltIns) { class ExternalDependenciesGenerator(
moduleDescriptor: ModuleDescriptor,
private val stubGenerator = DeclarationStubGenerator(symbolTable, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB) val symbolTable: SymbolTable,
val irBuiltIns: IrBuiltIns
) {
private val stubGenerator = DeclarationStubGenerator(moduleDescriptor,symbolTable, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB)
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) { fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) {
DependencyGenerationTask(irModule).run() DependencyGenerationTask(irModule).run()
@@ -3,7 +3,7 @@
* that can be found in the license/LICENSE.txt file. * that can be found in the license/LICENSE.txt file.
*/ */
package org.jetbrains.kotlin.psi2ir.transformations package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
@@ -3,29 +3,19 @@
* that can be found in the license/LICENSE.txt file. * that can be found in the license/LICENSE.txt file.
*/ */
package org.jetbrains.kotlin.psi2ir.types package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeProjection import org.jetbrains.kotlin.ir.types.IrTypeProjection
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
import org.jetbrains.kotlin.psi2ir.transformations.AnnotationGenerator
import org.jetbrains.kotlin.psi2ir.transformations.ScopedTypeParametersResolver
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
@@ -34,8 +24,6 @@ class TypeTranslator(
private val symbolTable: SymbolTable private val symbolTable: SymbolTable
) { ) {
constructor(context: GeneratorContext) : this(context.moduleDescriptor, context.symbolTable)
private val annotationGenerator = AnnotationGenerator(moduleDescriptor, symbolTable) private val annotationGenerator = AnnotationGenerator(moduleDescriptor, symbolTable)
private val typeParametersResolver = ScopedTypeParametersResolver() private val typeParametersResolver = ScopedTypeParametersResolver()