Binding: all current tests are green.

This commit is contained in:
Dmitry Petrov
2017-04-12 14:13:13 +03:00
parent 00e4accb7b
commit d7a362b4f6
41 changed files with 553 additions and 126 deletions
@@ -187,7 +187,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass {
enumEntriesByField[fieldPropertyDescriptor] = enumEntry.descriptor
enumEntryFields.add(fieldPropertyDescriptor)
val enumEntryInitializer = enumEntry.initializerExpression
val enumEntryInitializer = enumEntry.initializerExpression!!
return IrFieldImpl(
enumEntry.startOffset, enumEntry.endOffset, JvmLoweredDeclarationOrigin.FIELD_FOR_ENUM_ENTRY,
fieldPropertyDescriptor,
@@ -139,7 +139,7 @@ class SyntheticAccessorLowering(val state: GenerationState) : FileLoweringPass,
UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR,
accessorDescriptor, body
)
val calleeDescriptor = accessor.calleeDescriptor
val calleeDescriptor = accessor.calleeDescriptor as FunctionDescriptor
val returnExpr = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, calleeDescriptor)
copyAllArgsToValueParams(returnExpr, accessorDescriptor)
body.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, accessor, returnExpr))
@@ -90,8 +90,10 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
) =
@Suppress("DEPRECATION")
if (descriptor is LocalVariableDescriptor && descriptor.isDelegated) {
val getter = context.symbolTable.referenceFunction(descriptor.getter!!)
IrCallImpl(startOffset, endOffset, descriptor.type, getter, typeArguments, origin ?: IrStatementOrigin.GET_LOCAL_PROPERTY)
val getterDescriptor = descriptor.getter!!
val getterSymbol = context.symbolTable.referenceFunction(getterDescriptor.original)
IrCallImpl(startOffset, endOffset, descriptor.type, getterSymbol, getterDescriptor,
typeArguments, origin ?: IrStatementOrigin.GET_LOCAL_PROPERTY)
}
else
IrGetValueImpl(startOffset, endOffset, context.symbolTable.referenceValue(descriptor), origin)
@@ -100,7 +102,7 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
call.callReceiver.call { dispatchReceiver, extensionReceiver ->
val descriptor = call.descriptor as? ClassConstructorDescriptor
?: throw AssertionError("Class constructor expected: ${call.descriptor}")
val constructorSymbol = context.symbolTable.referenceConstructor(descriptor)
val constructorSymbol = context.symbolTable.referenceConstructor(descriptor.original)
val irCall = IrDelegatingConstructorCallImpl(startOffset, endOffset, constructorSymbol, getTypeArguments(call.original))
irCall.dispatchReceiver = dispatchReceiver?.load()
irCall.extensionReceiver = extensionReceiver?.load()
@@ -158,20 +160,21 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
}
private fun generateFunctionCall(
descriptor: FunctionDescriptor,
functionDescriptor: FunctionDescriptor,
startOffset: Int,
endOffset: Int,
origin: IrStatementOrigin?,
call: CallBuilder
): IrExpression =
call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue ->
val returnType = descriptor.returnType!!
val functionSymbol = context.symbolTable.referenceFunction(descriptor)
val returnType = functionDescriptor.returnType!!
val functionSymbol = context.symbolTable.referenceFunction(functionDescriptor.original)
val superQualifierSymbol = call.superQualifier?.let { context.symbolTable.referenceClass(it) }
val irCall = IrCallImpl(
startOffset, endOffset,
returnType,
functionSymbol,
functionDescriptor,
getTypeArguments(call.original),
origin,
superQualifierSymbol
@@ -210,7 +210,7 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe
val endOffset = irDelegate.endOffset
val irBlockBody = IrBlockBodyImpl(startOffset, endOffset)
val returnType = overridden.returnType!!
val irCall = IrCallImpl(startOffset, endOffset, returnType, context.symbolTable.referenceFunction(overridden), null)
val irCall = IrCallImpl(startOffset, endOffset, returnType, context.symbolTable.referenceFunction(overridden.original), overridden, null)
irCall.dispatchReceiver =
IrGetFieldImpl(
startOffset, endOffset, irDelegate.symbol,
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
@@ -114,7 +115,12 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
IrDeclarationOrigin.FAKE_OVERRIDE,
false,
propertyDescriptor,
null,
if (propertyDescriptor.getter == null)
context.symbolTable.declareField(
ktElement.startOffsetOrUndefined, ktElement.endOffsetOrUndefined, IrDeclarationOrigin.FAKE_OVERRIDE,
propertyDescriptor
)
else null,
propertyDescriptor.getter?.let { generateFakeOverrideFunction(it, ktElement) },
propertyDescriptor.setter?.let { generateFakeOverrideFunction(it, ktElement) }
)
@@ -113,18 +113,18 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
kPropertyType: KotlinType,
ktDelegate: KtPropertyDelegate
): IrField {
val irActualDelegateInitializer = generateInitializerBodyForPropertyDelegate(
propertyDescriptor, kPropertyType, ktDelegate,
context.symbolTable.referenceField(propertyDescriptor)
)
val delegateType = irActualDelegateInitializer.expression.type
val delegateType = getDelegatedPropertyDelegateType(propertyDescriptor, ktDelegate)
val delegateDescriptor = createPropertyDelegateDescriptor(propertyDescriptor, delegateType, kPropertyType)
return context.symbolTable.declareField(
ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATE,
delegateDescriptor, irActualDelegateInitializer
)
delegateDescriptor
).also { irDelegate ->
irDelegate.initializer = generateInitializerBodyForPropertyDelegate(
propertyDescriptor, kPropertyType, ktDelegate,
irDelegate.symbol
)
}
}
private fun generateInitializerBodyForPropertyDelegate(
@@ -257,7 +257,7 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
kPropertyType: KotlinType,
scopeOwner: IrSymbol
): IrVariable {
val delegateType = getLocalDelegatedPropertyDelegateType(variableDescriptor, ktDelegate)
val delegateType = getDelegatedPropertyDelegateType(variableDescriptor, ktDelegate)
val delegateDescriptor = createLocalPropertyDelegatedDescriptor(variableDescriptor, delegateType, kPropertyType)
return context.symbolTable.declareVariable(
@@ -272,11 +272,11 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
}
}
private fun getLocalDelegatedPropertyDelegateType(
variableDescriptor: VariableDescriptorWithAccessors,
private fun getDelegatedPropertyDelegateType(
delegatedPropertyDescriptor: VariableDescriptorWithAccessors,
ktDelegate: KtPropertyDelegate
): KotlinType {
val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, variableDescriptor)
val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, delegatedPropertyDescriptor)
return if (provideDelegateResolvedCall != null)
provideDelegateResolvedCall.resultingDescriptor.returnType!!
else
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.psi2ir.generators
import com.sun.org.apache.xpath.internal.operations.Mod
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
@@ -114,11 +115,14 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
}
private fun generateDefaultAccessorBody(ktProperty: KtElement, accessor: PropertyAccessorDescriptor, irAccessor: IrSimpleFunction) =
when (accessor) {
is PropertyGetterDescriptor -> generateDefaultGetterBody(ktProperty, accessor, irAccessor)
is PropertySetterDescriptor -> generateDefaultSetterBody(ktProperty, accessor, irAccessor)
else -> throw AssertionError("Should be getter or setter: $accessor")
}
if (accessor.modality == Modality.ABSTRACT)
null
else
when (accessor) {
is PropertyGetterDescriptor -> generateDefaultGetterBody(ktProperty, accessor, irAccessor)
is PropertySetterDescriptor -> generateDefaultSetterBody(ktProperty, accessor, irAccessor)
else -> throw AssertionError("Should be getter or setter: $accessor")
}
private fun generateDefaultGetterBody(ktProperty: KtElement, getter: PropertyGetterDescriptor, irAccessor: IrSimpleFunction): IrBlockBody {
val property = getter.correspondingProperty
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
@@ -49,7 +49,9 @@ class LocalClassGenerator(statementGenerator: StatementGenerator): StatementGene
IrCallImpl(
ktObjectLiteral.startOffset, ktObjectLiteral.endOffset, objectLiteralType,
context.symbolTable.referenceConstructor(objectConstructor),
null, IrStatementOrigin.OBJECT_LITERAL
objectConstructor,
null,
IrStatementOrigin.OBJECT_LITERAL
)
)
@@ -0,0 +1,202 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.descriptors.IrDeclarationStubBuilder
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.MemberScope
class ModuleDependenciesGenerator(override val context: GeneratorContext) : Generator {
private class DependenciesCollector {
private val modulesForDependencyDescriptors = LinkedHashSet<ModuleDescriptor>()
private val packageFragmentsForDependencyDescriptors = LinkedHashMap<ModuleDescriptor, MutableSet<PackageFragmentDescriptor>>()
private val topLevelDescriptors = LinkedHashMap<PackageFragmentDescriptor, MutableSet<DeclarationDescriptor>>()
val dependencyModules: Collection<ModuleDescriptor> get() = modulesForDependencyDescriptors
fun getPackageFragments(moduleDescriptor: ModuleDescriptor): Collection<PackageFragmentDescriptor> =
packageFragmentsForDependencyDescriptors[moduleDescriptor] ?: emptyList()
fun getTopLevelDescriptors(packageFragmentDescriptor: PackageFragmentDescriptor): Collection<DeclarationDescriptor> =
topLevelDescriptors[packageFragmentDescriptor] ?: emptyList()
fun collectTopLevelDescriptorsForUnboundSymbols(symbolTable: SymbolTable) {
assert(symbolTable.unboundTypeParameters.isEmpty()) { "Unbound type parameters: ${symbolTable.unboundTypeParameters}" }
assert(symbolTable.unboundValueParameters.isEmpty()) { "Unbound value parameters: ${symbolTable.unboundValueParameters}" }
assert(symbolTable.unboundVariables.isEmpty()) { "Unbound variables: ${symbolTable.unboundVariables}" }
symbolTable.unboundClasses.addTopLevelDeclarations()
symbolTable.unboundConstructors.addTopLevelDeclarations()
symbolTable.unboundEnumEntries.addTopLevelDeclarations()
symbolTable.unboundFields.addTopLevelDeclarations()
symbolTable.unboundSimpleFunctions.addTopLevelDeclarations()
}
private fun Collection<IrSymbol>.addTopLevelDeclarations() {
forEach { addTopLevelDeclaration(it) }
}
fun addTopLevelDeclaration(symbol: IrSymbol) {
val descriptor = symbol.descriptor
val topLevelDeclaration = getTopLevelDeclaration(descriptor)
addTopLevelDescriptor(topLevelDeclaration)
}
private fun getTopLevelDeclaration(descriptor: DeclarationDescriptor): DeclarationDescriptor {
val containingDeclaration = descriptor.containingDeclaration
return when (containingDeclaration) {
is PackageFragmentDescriptor -> descriptor
is ClassDescriptor -> getTopLevelDeclaration(containingDeclaration)
else -> throw AssertionError("Package or class expected: $containingDeclaration")
}
}
private fun addTopLevelDescriptor(descriptor: DeclarationDescriptor) {
val packageFragmentDescriptor = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java)!!
val moduleDescriptor = packageFragmentDescriptor.containingDeclaration
modulesForDependencyDescriptors.add(moduleDescriptor)
packageFragmentsForDependencyDescriptors.getOrPut(moduleDescriptor) { LinkedHashSet() }.add(packageFragmentDescriptor)
topLevelDescriptors.getOrPut(packageFragmentDescriptor) { LinkedHashSet() }.add(descriptor)
}
}
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) {
val collector = DependenciesCollector()
collector.collectTopLevelDescriptorsForUnboundSymbols(context.symbolTable)
collector.dependencyModules.mapTo(irModule.dependencyModules) { moduleDescriptor ->
generateModuleStub(collector, moduleDescriptor)
}
}
private fun generateModuleStub(collector: DependenciesCollector, moduleDescriptor: ModuleDescriptor): IrModuleFragmentImpl =
IrModuleFragmentImpl(moduleDescriptor, context.irBuiltIns).also { irDependencyModule ->
collector.getPackageFragments(moduleDescriptor).mapTo(irDependencyModule.externalPackageFragments) { packageFragmentDescriptor ->
generatePackageStub(packageFragmentDescriptor, collector.getTopLevelDescriptors(packageFragmentDescriptor))
}
}
private fun generatePackageStub(packageFragmentDescriptor: PackageFragmentDescriptor, topLevelDescriptors: Collection<DeclarationDescriptor>): IrExternalPackageFragment =
context.symbolTable.declareExternalPackageFragment(packageFragmentDescriptor).also { irExternalPackageFragment ->
topLevelDescriptors.mapTo(irExternalPackageFragment.declarations) {
generateStub(it)
}
}
private fun generateStub(descriptor: DeclarationDescriptor): IrDeclaration =
when (descriptor) {
is ClassDescriptor ->
if (DescriptorUtils.isEnumEntry(descriptor))
generateEnumEntryStub(descriptor)
else
generateClassStub(descriptor)
is ClassConstructorDescriptor ->
generateConstructorStub(descriptor)
is FunctionDescriptor ->
generateFunctionStub(descriptor)
is PropertyDescriptor ->
generatePropertyStub(descriptor)
else ->
throw AssertionError("Unexpected top-level descriptor: $descriptor")
}
private fun MemberScope.generateChildStubs(irParent: IrDeclarationContainer) {
getContributedDescriptors().generateChildStubs(irParent)
}
private fun Collection<DeclarationDescriptor>.generateChildStubs(irParent: IrDeclarationContainer) {
mapTo(irParent.declarations) { generateStub(it) }
}
private fun Collection<TypeParameterDescriptor>.generateTypeParameterStubs(irParent: IrTypeParametersContainer) {
mapTo(irParent.typeParameters) { generateTypeParameterStub(it) }
}
private fun Collection<ValueParameterDescriptor>.generateValueParametersStubs(irParent: IrFunction) {
mapTo(irParent.valueParameters) { generateValueParameterStub(it) }
}
private fun generateClassStub(classDescriptor: ClassDescriptor): IrClass =
context.symbolTable.declareClass(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
classDescriptor
).also { irClass ->
classDescriptor.declaredTypeParameters.generateTypeParameterStubs(irClass)
classDescriptor.constructors.generateChildStubs(irClass)
classDescriptor.defaultType.memberScope.generateChildStubs(irClass)
classDescriptor.staticScope.generateChildStubs(irClass)
}
private fun generateEnumEntryStub(enumEntryDescriptor: ClassDescriptor): IrEnumEntry =
context.symbolTable.declareEnumEntry(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
enumEntryDescriptor
)
private fun generateTypeParameterStub(typeParameterDescriptor: TypeParameterDescriptor): IrTypeParameter =
IrTypeParameterImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB, typeParameterDescriptor)
private fun generateValueParameterStub(valueParameterDescriptor: ValueParameterDescriptor): IrValueParameter =
IrValueParameterImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB, valueParameterDescriptor)
private fun generateConstructorStub(constructorDescriptor: ClassConstructorDescriptor): IrConstructor =
context.symbolTable.declareConstructor(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
constructorDescriptor
).also { irConstructor ->
constructorDescriptor.valueParameters.generateValueParametersStubs(irConstructor)
}
private fun generateFunctionStub(functionDescriptor: FunctionDescriptor): IrFunction =
context.symbolTable.declareSimpleFunction(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
functionDescriptor
).also { irFunction ->
functionDescriptor.typeParameters.generateTypeParameterStubs(irFunction)
functionDescriptor.valueParameters.generateValueParametersStubs(irFunction)
}
private fun generatePropertyStub(propertyDescriptor: PropertyDescriptor): IrProperty =
IrPropertyImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
propertyDescriptor
).also { irProperty ->
val getterDescriptor = propertyDescriptor.getter
if (getterDescriptor == null) {
irProperty.backingField =
context.symbolTable.declareField(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
propertyDescriptor
)
}
else {
irProperty.getter = generateFunctionStub(getterDescriptor)
}
irProperty.setter = propertyDescriptor.setter?.let { generateFunctionStub(it) }
}
}
@@ -25,10 +25,20 @@ import org.jetbrains.kotlin.resolve.BindingContext
class ModuleGenerator(override val context: GeneratorContext) : Generator {
fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment =
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns,
generateFiles(ktFiles))
generateModuleFragmentWithoutDependencies(ktFiles).also { irModule ->
generateUnboundSymbolsAsDependencies(irModule)
}
fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> {
fun generateModuleFragmentWithoutDependencies(ktFiles: Collection<KtFile>): IrModuleFragment =
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns).also { irModule ->
irModule.files.addAll(generateFiles(ktFiles))
}
private fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment) {
ModuleDependenciesGenerator(context).generateUnboundSymbolsAsDependencies(irModule)
}
private fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> {
val irDeclarationGenerator = DeclarationGenerator(context)
return ktFiles.map { ktFile ->
@@ -36,10 +46,6 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
}
}
fun generateSingleFileFragment(ktFile: KtFile) =
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns,
listOf(generateSingleFile(DeclarationGenerator(context), ktFile)))
private fun generateSingleFile(irDeclarationGenerator: DeclarationGenerator, ktFile: KtFile): IrFileImpl {
val irFile = createEmptyIrFile(ktFile)
@@ -54,7 +60,7 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
return irFile
}
fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
private fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
val fileEntry = context.sourceManager.getOrCreateFileEntry(ktFile)
val packageFragmentDescriptor = getOrFail(BindingContext.FILE_TO_PACKAGE_FRAGMENT, ktFile)
val irFile = IrFileImpl(fileEntry, packageFragmentDescriptor)
@@ -66,6 +66,7 @@ class SymbolTable {
val s = get(d)
if (s == null) {
val new = createSymbol().also { markAsUnbound(it) }
set(d, new)
return new
}
return s
@@ -173,6 +174,9 @@ class SymbolTable {
fun declareFile(fileEntry: SourceManager.FileEntry, packageFragmentDescriptor: PackageFragmentDescriptor): IrFile =
IrFileImpl(fileEntry, IrFileSymbolImpl(packageFragmentDescriptor))
fun declareExternalPackageFragment(packageFragmentDescriptor: PackageFragmentDescriptor): IrExternalPackageFragment =
IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragmentDescriptor))
fun declareAnonymousInitializer(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor): IrAnonymousInitializer =
IrAnonymousInitializerImpl(
startOffset, endOffset, origin,
@@ -186,7 +190,6 @@ class SymbolTable {
{ IrClassImpl(startOffset, endOffset, origin, it) }
)
fun referenceClass(descriptor: ClassDescriptor) =
classSymbolTable.referenced(descriptor) { IrClassSymbolImpl(descriptor) }
@@ -31,10 +31,10 @@ class DelegatedLocalPropertyLValue(
val origin: IrStatementOrigin? = null
) : LValue, AssignmentReceiver {
override fun load(): IrExpression =
IrCallImpl(startOffset, endOffset, type, getterSymbol!!, null, origin)
IrCallImpl(startOffset, endOffset, type, getterSymbol!!, getterSymbol.descriptor, null, origin)
override fun store(irExpression: IrExpression): IrExpression =
IrCallImpl(startOffset, endOffset, type, setterSymbol!!, null, origin).apply {
IrCallImpl(startOffset, endOffset, type, setterSymbol!!, setterSymbol.descriptor, null, origin).apply {
putValueArgument(0, irExpression)
}
@@ -138,7 +138,7 @@ fun IrBuilderWithScope.irGet(receiver: IrExpression, getterSymbol: IrFunctionSym
IrGetterCallImpl(startOffset, endOffset, getterSymbol, null, receiver, null, IrStatementOrigin.GET_PROPERTY)
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, type: KotlinType): IrCall =
IrCallImpl(startOffset, endOffset, type, callee, null)
IrCallImpl(startOffset, endOffset, type, callee, callee.descriptor, null)
fun IrBuilderWithScope.irCallOp(callee: IrFunctionSymbol, dispatchReceiver: IrExpression, argument: IrExpression): IrCall =
irCall(callee, callee.descriptor.returnType!!).apply {
@@ -31,6 +31,8 @@ interface IrDeclarationOrigin {
object NEW_INSTANCE_RECEIVER : IrDeclarationOriginImpl("NEW_INSTANCE_RECEIVER")
object PRIMARY_CONSTRUCTOR_PARAMETER : IrDeclarationOriginImpl("PRIMARY_CONSTRUCTOR_PARAMETER")
object IR_TEMPORARY_VARIABLE : IrDeclarationOriginImpl("IR_TEMPORARY_VARIABLE")
object IR_EXTERNAL_DECLARATION_STUB : IrDeclarationOriginImpl("IR_EXTERNAL_DECLARATION_STUB")
object IR_BUILTINS_STUB : IrDeclarationOriginImpl("IR_BUILTINS_STUB")
}
abstract class IrDeclarationOriginImpl(val name: String): IrDeclarationOrigin {
@@ -26,6 +26,6 @@ interface IrEnumEntry : IrSymbolDeclaration<IrEnumEntrySymbol> {
override val descriptor: ClassDescriptor
var correspondingClass: IrClass?
var initializerExpression: IrExpression
var initializerExpression: IrExpression?
}
@@ -25,7 +25,9 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
interface IrModuleFragment : IrElement {
val descriptor: ModuleDescriptor
val irBuiltins: IrBuiltIns
val files: List<IrFile>
val files: MutableList<IrFile>
val externalPackageFragments: MutableList<IrExternalPackageFragment>
val dependencyModules: MutableList<IrModuleFragment>
override val startOffset: Int get() = UNDEFINED_OFFSET
override val endOffset: Int get() = UNDEFINED_OFFSET
@@ -46,19 +46,19 @@ class IrEnumEntryImpl(
override val descriptor: ClassDescriptor get() = symbol.descriptor
override var correspondingClass: IrClass? = null
override lateinit var initializerExpression: IrExpression
override var initializerExpression: IrExpression? = null
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitEnumEntry(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
initializerExpression.accept(visitor, data)
initializerExpression?.accept(visitor, data)
correspondingClass?.accept(visitor, data)
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
initializerExpression = initializerExpression.transform(transformer, data)
initializerExpression = initializerExpression?.transform(transformer, data)
correspondingClass = correspondingClass?.transform(transformer, data) as? IrClass
}
}
@@ -17,30 +17,27 @@
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
import kotlin.collections.ArrayList
class IrModuleFragmentImpl(
override val descriptor: ModuleDescriptor,
override val irBuiltins: IrBuiltIns
) : IrModuleFragment {
constructor(descriptor: ModuleDescriptor, irBuiltins: IrBuiltIns, files: List<IrFile>) : this(descriptor, irBuiltins) {
this.addAll(files)
this.files.addAll(files)
}
override val files: MutableList<IrFile> = ArrayList()
fun addFile(file: IrFile) {
files.add(file)
}
override val externalPackageFragments: MutableList<IrExternalPackageFragment> = ArrayList()
fun addAll(newFiles: List<IrFile>) {
files.addAll(newFiles)
}
override val dependencyModules: MutableList<IrModuleFragment> = ArrayList()
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitModuleFragment(this, data)
@@ -30,6 +30,11 @@ class IrPropertyImpl(
override val isDelegated: Boolean,
override val descriptor: PropertyDescriptor
) : IrDeclarationBase(startOffset, endOffset, origin), IrProperty {
constructor(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
constructor(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, isDelegated: Boolean, descriptor: PropertyDescriptor,
backingField: IrField?
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
@@ -37,9 +38,7 @@ class IrBuiltIns(val builtIns: KotlinBuiltIns) {
private val packageFragment = IrBuiltinsPackageFragmentDescriptorImpl(builtIns.builtInsModule, KOTLIN_INTERNAL_IR_FQN)
val irBuiltInsExternalPackageFragment = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragment))
object IR_BUILTINS_STUB : IrDeclarationOriginImpl("IR_BUILTINS_STUB")
private val stubBuilder = IrDeclarationStubBuilder(IR_BUILTINS_STUB)
private val stubBuilder = IrDeclarationStubBuilder(IrDeclarationOrigin.IR_BUILTINS_STUB)
private fun defineOperator(name: String, returnType: KotlinType, valueParameterTypes: List<KotlinType>): IrSimpleFunction {
val operatorDescriptor = IrSimpleBuiltinOperatorDescriptorImpl(packageFragment, Name.identifier(name), returnType)
@@ -51,11 +51,7 @@ class IrDeclarationStubBuilder(val defaultOrigin: IrDeclarationOrigin) {
private fun <T : IrTypeParametersContainer>
T.buildTypeParameterStubs(typeParameterDescriptors: List<TypeParameterDescriptor>, origin: IrDeclarationOrigin): T =
apply {
typeParameterDescriptors.forEach { typeParameterDescriptor ->
typeParameters.add(
buildTypeParameterStub(IrTypeParameterSymbolImpl(typeParameterDescriptor), origin)
)
}
typeParameterDescriptors.mapTo(typeParameters) { buildTypeParameterStub(IrTypeParameterSymbolImpl(it), origin) }
}
private fun <T : IrFunction>
@@ -66,11 +62,7 @@ class IrDeclarationStubBuilder(val defaultOrigin: IrDeclarationOrigin) {
addIfNotNull(functionDescriptor.extensionReceiverParameter)
addAll(functionDescriptor.valueParameters)
}
valueParameterDescriptors.forEach { valueParameterDescriptor ->
valueParameters.add(
buildValueParameterStub(IrValueParameterSymbolImpl(valueParameterDescriptor), origin)
)
}
valueParameterDescriptors.mapTo(valueParameters) { buildValueParameterStub(IrValueParameterSymbolImpl(it), origin) }
}
private val DeclarationDescriptorWithSource.startOffset
@@ -32,6 +32,7 @@ class IrCallImpl(
endOffset: Int,
type: KotlinType,
override val symbol: IrFunctionSymbol,
override val descriptor: FunctionDescriptor,
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
override val origin: IrStatementOrigin? = null,
override val superQualifierSymbol: IrClassSymbol? = null
@@ -42,14 +43,15 @@ class IrCallImpl(
constructor(
startOffset: Int,
endOffset: Int,
calleeDescriptor: CallableMemberDescriptor,
calleeDescriptor: FunctionDescriptor,
typeArguments: Map<TypeParameterDescriptor, KotlinType>? = null,
origin: IrStatementOrigin? = null,
superQualifierDescriptor: ClassDescriptor? = null
) : this(
startOffset, endOffset,
calleeDescriptor.returnType!!,
createFunctionSymbol(calleeDescriptor),
createFunctionSymbol(calleeDescriptor.original),
calleeDescriptor,
typeArguments, origin,
createClassSymbolOrNull(superQualifierDescriptor)
)
@@ -57,12 +59,16 @@ class IrCallImpl(
constructor(
startOffset: Int, endOffset: Int,
symbol: IrFunctionSymbol,
descriptor: FunctionDescriptor,
typeArguments: Map<TypeParameterDescriptor, KotlinType>? = null,
origin: IrStatementOrigin? = null,
superQualifierSymbol: IrClassSymbol? = null
) : this(startOffset, endOffset, symbol.descriptor.returnType!!, symbol, typeArguments, origin, superQualifierSymbol)
) : this(startOffset, endOffset, symbol.descriptor.returnType!!, symbol, descriptor, typeArguments, origin, superQualifierSymbol)
constructor(startOffset: Int, endOffset: Int, symbol: IrFunctionSymbol) :
this(startOffset, endOffset, symbol, symbol.descriptor)
override val descriptor: FunctionDescriptor = symbol.descriptor
override val superQualifier: ClassDescriptor? = superQualifierSymbol?.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -32,7 +32,7 @@ abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolO
if (_owner == null)
_owner = owner
else
throw IllegalStateException("Symbol for $descriptor is already bound")
throw IllegalStateException("${javaClass.simpleName} for $descriptor is already bound")
}
override val isBound: Boolean
@@ -159,7 +159,7 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
symbolsRemapper.getDeclaredEnumEntry(declaration.symbol)
).apply {
correspondingClass = declaration.correspondingClass?.transform()
initializerExpression = declaration.initializerExpression.transform()
initializerExpression = declaration.initializerExpression?.transform()
}
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer): IrAnonymousInitializer =
@@ -317,6 +317,7 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
expression.startOffset, expression.endOffset,
expression.type,
symbolsRemapper.getReferencedFunction(expression.symbol),
expression.descriptor, // TODO substitute referenced descriptor
expression.getTypeArgumentsMap(),
mapStatementOrigin(expression.origin),
symbolsRemapper.getReferencedClassOrNull(expression.superQualifierSymbol)
@@ -54,6 +54,13 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
element.dumpLabeledSubTree(data)
}
override fun visitModuleFragment(declaration: IrModuleFragment, data: String) {
declaration.dumpLabeledElementWith(data) {
declaration.files.dumpElements()
declaration.externalPackageFragments.dumpElements()
}
}
override fun visitFile(declaration: IrFile, data: String) {
declaration.dumpLabeledElementWith(data) {
if (declaration.fileAnnotations.isNotEmpty()) {
@@ -117,7 +124,7 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
override fun visitEnumEntry(declaration: IrEnumEntry, data: String) {
declaration.dumpLabeledElementWith(data) {
declaration.initializerExpression.accept(this, "init")
declaration.initializerExpression?.accept(this, "init")
declaration.correspondingClass?.accept(this, "class")
}
}
+12
View File
@@ -0,0 +1,12 @@
abstract class AbstractClass {
abstract fun abstractFun()
abstract val abstractVal: Int
abstract var abstractVar: Int
}
interface Interface {
abstract fun abstractFun()
abstract val abstractVal: Int
abstract var abstractVar: Int
}
+36
View File
@@ -0,0 +1,36 @@
FILE /abstractMembers.kt
CLASS CLASS AbstractClass
$new: VALUE_PARAMETER <receiver: AbstractClass>
CONSTRUCTOR public constructor AbstractClass()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Any()'
INSTANCE_INITIALIZER_CALL classDescriptor='AbstractClass'
FUN public abstract fun abstractFun(): kotlin.Unit
$this: VALUE_PARAMETER <receiver: AbstractClass>
PROPERTY public abstract val abstractVal: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-abstractVal>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: AbstractClass>
PROPERTY public abstract var abstractVar: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-abstractVar>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: AbstractClass>
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <set-abstractVar>(<set-?>: kotlin.Int): kotlin.Unit
$this: VALUE_PARAMETER <receiver: AbstractClass>
VALUE_PARAMETER value-parameter <set-?>: kotlin.Int
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
CLASS INTERFACE Interface
FUN public abstract fun abstractFun(): kotlin.Unit
$this: VALUE_PARAMETER <receiver: Interface>
PROPERTY public abstract val abstractVal: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-abstractVal>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: Interface>
PROPERTY public abstract var abstractVar: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-abstractVar>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: Interface>
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <set-abstractVar>(<set-?>: kotlin.Int): kotlin.Unit
$this: VALUE_PARAMETER <receiver: Interface>
VALUE_PARAMETER value-parameter <set-?>: kotlin.Int
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
@@ -39,48 +39,24 @@ FILE /delegatedImplementation.kt
PROPERTY public abstract val x: kotlin.String
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-x>(): kotlin.String
$this: VALUE_PARAMETER <receiver: IOther>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-x>(): String'
GET_FIELD 'x: String' type=kotlin.String origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
PROPERTY public abstract var y: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-y>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: IOther>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-y>(): Int'
GET_FIELD 'y: Int' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <set-y>(<set-?>: kotlin.Int): kotlin.Unit
$this: VALUE_PARAMETER <receiver: IOther>
VALUE_PARAMETER value-parameter <set-?>: kotlin.Int
BLOCK_BODY
SET_FIELD 'y: Int' type=kotlin.Unit origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
value: GET_VAR 'value-parameter <set-?>: Int' type=kotlin.Int origin=null
PROPERTY public abstract val kotlin.Byte.z1: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun kotlin.Byte.<get-z1>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: IOther>
$receiver: VALUE_PARAMETER <receiver: z1: Int on Byte>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-z1>() on Byte: Int'
GET_FIELD 'z1: Int on Byte' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
PROPERTY public abstract var kotlin.Byte.z2: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun kotlin.Byte.<get-z2>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: IOther>
$receiver: VALUE_PARAMETER <receiver: z2: Int on Byte>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-z2>() on Byte: Int'
GET_FIELD 'z2: Int on Byte' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun kotlin.Byte.<set-z2>(<set-?>: kotlin.Int): kotlin.Unit
$this: VALUE_PARAMETER <receiver: IOther>
$receiver: VALUE_PARAMETER <receiver: z2: Int on Byte>
VALUE_PARAMETER value-parameter <set-?>: kotlin.Int
BLOCK_BODY
SET_FIELD 'z2: Int on Byte' type=kotlin.Unit origin=null
receiver: GET_VAR '<receiver: IOther>' type=IOther origin=null
value: GET_VAR 'value-parameter <set-?>: Int' type=kotlin.Int origin=null
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
@@ -10,10 +10,6 @@ FILE /fakeOverrides.kt
PROPERTY public abstract val bar: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-bar>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: IBar>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-bar>(): Int'
GET_FIELD 'bar: Int' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: IBar>' type=IBar origin=null
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
@@ -3,10 +3,6 @@ FILE /interfaceProperties.kt
PROPERTY public abstract val test1: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-test1>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: C>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-test1>(): Int'
GET_FIELD 'test1: Int' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: C>' type=C origin=null
PROPERTY public open val test2: kotlin.Int
FUN public open fun <get-test2>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: C>
@@ -16,17 +12,9 @@ FILE /interfaceProperties.kt
PROPERTY public abstract var test3: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-test3>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: C>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-test3>(): Int'
GET_FIELD 'test3: Int' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: C>' type=C origin=null
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <set-test3>(<set-?>: kotlin.Int): kotlin.Unit
$this: VALUE_PARAMETER <receiver: C>
VALUE_PARAMETER value-parameter <set-?>: kotlin.Int
BLOCK_BODY
SET_FIELD 'test3: Int' type=kotlin.Unit origin=null
receiver: GET_VAR '<receiver: C>' type=C origin=null
value: GET_VAR 'value-parameter <set-?>: Int' type=kotlin.Int origin=null
PROPERTY public open var test4: kotlin.Int
FUN public open fun <get-test4>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: C>
@@ -7,10 +7,6 @@ FILE /delegatedMembers.kt
PROPERTY public abstract val bar: kotlin.Int
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-bar>(): kotlin.Int
$this: VALUE_PARAMETER <receiver: IBase>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-bar>(): Int'
GET_FIELD 'bar: Int' type=kotlin.Int origin=null
receiver: GET_VAR '<receiver: IBase>' type=IBase<T> origin=null
FUN public abstract fun <X> qux(t: T, x: X): kotlin.Unit
TYPE_PARAMETER <X>
$this: VALUE_PARAMETER <receiver: IBase>
@@ -53,10 +53,6 @@ FILE /enumEntryAsReceiver.kt
PROPERTY public abstract val value: () -> kotlin.String
FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun <get-value>(): () -> kotlin.String
$this: VALUE_PARAMETER <receiver: X>
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-value>(): () -> String'
GET_FIELD 'value: () -> String' type=() -> kotlin.String origin=null
receiver: GET_VAR '<receiver: X>' type=X origin=null
FUN FAKE_OVERRIDE protected final override fun clone(): kotlin.Any
FUN FAKE_OVERRIDE protected/*protected and package*/ final override fun finalize(): kotlin.Unit
FUN FAKE_OVERRIDE public final override fun getDeclaringClass(): java.lang.Class<X!>!
@@ -24,6 +24,7 @@ FILE /Derived.kt
receiver: GET_VAR '<receiver: Derived>' type=Derived origin=null
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
PROPERTY FAKE_OVERRIDE public final override var value: kotlin.Int
FIELD FAKE_OVERRIDE public final override var value: kotlin.Int
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
+1
View File
@@ -90,6 +90,7 @@ FILE /kt16904.kt
receiver: GET_VAR '<receiver: Test2>' type=Test2 origin=null
value: CONST Int type=kotlin.Int value='42'
PROPERTY FAKE_OVERRIDE public final override var field: kotlin.Int
FIELD FAKE_OVERRIDE public final override var field: kotlin.Int
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
@@ -19,6 +19,7 @@ FILE /Derived.kt
value: TYPE_OP type=kotlin.String! origin=IMPLICIT_CAST typeOperand=kotlin.String!
GET_VAR 'value-parameter v: Any' type=kotlin.Any origin=null
PROPERTY FAKE_OVERRIDE public final override var value: kotlin.String!
FIELD FAKE_OVERRIDE public final override var value: kotlin.String!
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
+3
View File
@@ -0,0 +1,3 @@
// !DUMP_DEPENDENCIES
val test = 2 + 2
+11
View File
@@ -0,0 +1,11 @@
FILE /simple.kt
PROPERTY public val test: kotlin.Int = 4
FIELD PROPERTY_BACKING_FIELD public val test: kotlin.Int = 4
EXPRESSION_BODY
CALL 'plus(Int): Int' type=kotlin.Int origin=PLUS
$this: CONST Int type=kotlin.Int value='2'
other: CONST Int type=kotlin.Int value='2'
FUN DEFAULT_PROPERTY_ACCESSOR public fun <get-test>(): kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-test>(): Int'
GET_FIELD 'test: Int' type=kotlin.Int origin=null
@@ -0,0 +1,134 @@
MODULE_FRAGMENT <built-ins module>
EXTERNAL_PACKAGE_FRAGMENT kotlin
CLASS IR_EXTERNAL_DECLARATION_STUB CLASS Int
CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB private constructor Int()
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun and(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun compareTo(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun compareTo(other: kotlin.Double): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun compareTo(other: kotlin.Float): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun compareTo(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun compareTo(other: kotlin.Long): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun compareTo(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun dec(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun div(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun equals(other: kotlin.Any?): kotlin.Boolean
VALUE_PARAMETER value-parameter other: kotlin.Any?
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun hashCode(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun inc(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final fun inv(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun minus(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.Deprecated public final operator fun mod(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun or(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun plus(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun rangeTo(other: kotlin.Byte): kotlin.ranges.IntRange
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun rangeTo(other: kotlin.Int): kotlin.ranges.IntRange
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun rangeTo(other: kotlin.Long): kotlin.ranges.LongRange
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun rangeTo(other: kotlin.Short): kotlin.ranges.IntRange
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB @kotlin.SinceKotlin public final operator fun rem(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun shl(bitCount: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter bitCount: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun shr(bitCount: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter bitCount: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Byte): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Double): kotlin.Double
VALUE_PARAMETER value-parameter other: kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Float): kotlin.Float
VALUE_PARAMETER value-parameter other: kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Long): kotlin.Long
VALUE_PARAMETER value-parameter other: kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun times(other: kotlin.Short): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toByte(): kotlin.Byte
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toChar(): kotlin.Char
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toDouble(): kotlin.Double
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toFloat(): kotlin.Float
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toInt(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toLong(): kotlin.Long
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toShort(): kotlin.Short
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toString(): kotlin.String
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun unaryMinus(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final operator fun unaryPlus(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun ushr(bitCount: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter bitCount: kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public final infix fun xor(other: kotlin.Int): kotlin.Int
VALUE_PARAMETER value-parameter other: kotlin.Int
CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT companion object of Int
CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB private constructor Companion()
PROPERTY IR_EXTERNAL_DECLARATION_STUB public const final val MAX_VALUE: kotlin.Int = 2147483647
FUN IR_EXTERNAL_DECLARATION_STUB public final fun <get-MAX_VALUE>(): kotlin.Int
PROPERTY IR_EXTERNAL_DECLARATION_STUB public const final val MIN_VALUE: kotlin.Int = -2147483648
FUN IR_EXTERNAL_DECLARATION_STUB public final fun <get-MIN_VALUE>(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun equals(other: kotlin.Any?): kotlin.Boolean
VALUE_PARAMETER value-parameter other: kotlin.Any?
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun hashCode(): kotlin.Int
FUN IR_EXTERNAL_DECLARATION_STUB public open override fun toString(): kotlin.String
@@ -20,10 +20,7 @@ import com.intellij.openapi.util.text.StringUtil
import junit.framework.TestCase
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.deepCopy
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.util.dumpTreesFromLineNumber
@@ -38,9 +35,24 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
override fun doTest(wholeFile: File, testFiles: List<TestFile>) {
val dir = wholeFile.parentFile
val ignoreErrors = shouldIgnoreErrors(wholeFile)
for ((testFile, irFile) in generateIrFilesAsSingleModule(testFiles, ignoreErrors)) {
val irModule = generateIrModule(ignoreErrors)
val ktFiles = testFiles.filter { it.name.endsWith(".kt") }
for ((testFile, irFile) in ktFiles.zip(irModule.files)) {
doTestIrFileAgainstExpectations(dir, testFile, irFile)
}
if (shouldDumpDependencies(wholeFile)) {
doTestIrModuleDependencies(wholeFile, irModule)
}
}
private fun doTestIrModuleDependencies(wholeFile: File, irModule: IrModuleFragment) {
irModule.dependencyModules.forEach { irDependencyModule ->
val actual = irDependencyModule.dump()
val expectedFileName = wholeFile.absolutePath.replace(".kt", "__${irDependencyModule.descriptor.name.asString()}.txt")
KotlinTestUtils.assertEqualsToFile(File(expectedFileName), actual)
}
}
protected fun doTestIrFileAgainstExpectations(dir: File, testFile: TestFile, irFile: IrFile) {
@@ -166,6 +178,11 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
private val EXPECTED_OCCURRENCES_PATTERN = Regex("""^\s*//\s*(\d+)\s*(.*)$""")
private val IR_FILE_TXT_PATTERN = Regex("""// IR_FILE: (.*)$""")
private val DUMP_DEPENDENCIES_PATTERN = Regex("""// !DUMP_DEPENDENCIES""")
internal fun shouldDumpDependencies(wholeFile: File): Boolean =
DUMP_DEPENDENCIES_PATTERN.containsMatchIn(wholeFile.readText())
internal fun parseExpectations(dir: File, testFile: TestFile): Expectations {
val regexps = ArrayList<RegexpInText>()
val treeFiles = ArrayList<IrTreeFileLabel>()
@@ -40,6 +40,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Classes extends AbstractIrTextTestCase {
@TestMetadata("abstractMembers.kt")
public void testAbstractMembers() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/classes/abstractMembers.kt");
doTest(fileName);
}
public void testAllFilesPresentInClasses() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/classes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@@ -1010,4 +1016,19 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
doTest(fileName);
}
}
@TestMetadata("compiler/testData/ir/irText/stubs")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Stubs extends AbstractIrTextTestCase {
public void testAllFilesPresentInStubs() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/stubs"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/stubs/simple.kt");
doTest(fileName);
}
}
}