Refactor special descriptors.
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.backend.jvm.codegen
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSpecialDescriptor
|
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDescriptorWithExtraFlags
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
|
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
|
||||||
import org.jetbrains.kotlin.codegen.*
|
import org.jetbrains.kotlin.codegen.*
|
||||||
import org.jetbrains.kotlin.codegen.MemberCodegen.badDescriptor
|
import org.jetbrains.kotlin.codegen.MemberCodegen.badDescriptor
|
||||||
@@ -207,7 +207,7 @@ fun MemberDescriptor.calculateCommonFlags(): Int {
|
|||||||
|
|
||||||
flags = flags.or(calcModalityFlag())
|
flags = flags.or(calcModalityFlag())
|
||||||
|
|
||||||
if (this is JvmSpecialDescriptor) {
|
if (this is JvmDescriptorWithExtraFlags) {
|
||||||
flags = flags or extraFlags
|
flags = flags or extraFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.backend.jvm.descriptors
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
|
interface DefaultImplsClassDescriptor : ClassDescriptor {
|
||||||
|
val correspondingInterface: ClassDescriptor
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultImplsClassDescriptorImpl(
|
||||||
|
name: Name,
|
||||||
|
override val correspondingInterface: ClassDescriptor,
|
||||||
|
sourceElement: SourceElement
|
||||||
|
) : DefaultImplsClassDescriptor, KnownClassDescriptor(name, correspondingInterface, sourceElement, ClassKind.CLASS, Modality.FINAL, Visibilities.PUBLIC, Annotations.EMPTY) {
|
||||||
|
init {
|
||||||
|
initialize(emptyList(), listOf(correspondingInterface.module.builtIns.anyType))
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-3
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
interface JvmSpecialDescriptor {
|
interface JvmDescriptorWithExtraFlags {
|
||||||
val extraFlags: Int
|
val extraFlags: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,11 +39,17 @@ class JvmPropertyDescriptorImpl(
|
|||||||
source: SourceElement,
|
source: SourceElement,
|
||||||
isLateInit: Boolean,
|
isLateInit: Boolean,
|
||||||
isConst: Boolean
|
isConst: Boolean
|
||||||
) : JvmSpecialDescriptor, PropertyDescriptorImpl(
|
) : JvmDescriptorWithExtraFlags, PropertyDescriptorImpl(
|
||||||
containingDeclaration, original, annotations, modality, visibility, isVar,
|
containingDeclaration, original, annotations, modality, visibility, isVar,
|
||||||
name, kind, source, isLateInit, isConst
|
name, kind, source, isLateInit, isConst
|
||||||
) {
|
) {
|
||||||
override fun createSubstitutedCopy(newOwner: DeclarationDescriptor, newModality: Modality, newVisibility: Visibility, original: PropertyDescriptor?, kind: CallableMemberDescriptor.Kind): PropertyDescriptorImpl =
|
override fun createSubstitutedCopy(
|
||||||
|
newOwner: DeclarationDescriptor,
|
||||||
|
newModality: Modality,
|
||||||
|
newVisibility: Visibility,
|
||||||
|
original: PropertyDescriptor?,
|
||||||
|
kind: CallableMemberDescriptor.Kind
|
||||||
|
): PropertyDescriptorImpl =
|
||||||
JvmPropertyDescriptorImpl(
|
JvmPropertyDescriptorImpl(
|
||||||
newOwner, original, annotations, newModality, newVisibility, extraFlags, isVar, name, kind,
|
newOwner, original, annotations, newModality, newVisibility, extraFlags, isVar, name, kind,
|
||||||
SourceElement.NO_SOURCE, isLateInit, isConst
|
SourceElement.NO_SOURCE, isLateInit, isConst
|
||||||
-80
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 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.backend.jvm.lower
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|
||||||
import org.jetbrains.kotlin.types.*
|
|
||||||
|
|
||||||
interface DefaultImplsClassDescriptor : ClassDescriptor {
|
|
||||||
val correspondingInterface: ClassDescriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
class DefaultImplsClassDescriptorImpl(
|
|
||||||
private val nameImpl: Name,
|
|
||||||
override val correspondingInterface: ClassDescriptor,
|
|
||||||
private val sourceElement: SourceElement
|
|
||||||
) : DefaultImplsClassDescriptor {
|
|
||||||
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
|
|
||||||
override fun getConstructors(): Collection<ClassConstructorDescriptor> = emptyList()
|
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor = correspondingInterface
|
|
||||||
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> = emptyList()
|
|
||||||
override fun getKind(): ClassKind = ClassKind.CLASS
|
|
||||||
|
|
||||||
override fun getMemberScope(typeSubstitution: TypeSubstitution): MemberScope = error("File class has no member scope")
|
|
||||||
override fun getModality(): Modality = Modality.FINAL
|
|
||||||
override fun getOriginal(): ClassDescriptor = this
|
|
||||||
override fun getName(): Name = nameImpl
|
|
||||||
override fun getStaticScope(): MemberScope = error("File class has no static scope")
|
|
||||||
override fun getThisAsReceiverParameter(): ReceiverParameterDescriptor = error("File class has no instances")
|
|
||||||
override fun getUnsubstitutedInnerClassesScope(): MemberScope = error("File class has no inner classes scope")
|
|
||||||
override fun getUnsubstitutedMemberScope(): MemberScope = error("File class has no member scope")
|
|
||||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null
|
|
||||||
override fun getVisibility(): Visibility = Visibilities.PUBLIC
|
|
||||||
override fun isCompanionObject(): Boolean = false
|
|
||||||
override fun isData(): Boolean = false
|
|
||||||
override fun substitute(substitutor: TypeSubstitutor): ClassDescriptor = error("File class can't be substituted")
|
|
||||||
override fun getSource(): SourceElement = sourceElement
|
|
||||||
override fun isInner(): Boolean = false
|
|
||||||
|
|
||||||
override val annotations = Annotations.EMPTY
|
|
||||||
|
|
||||||
private val typeConstructor = ClassTypeConstructorImpl(this, annotations, true, emptyList(), listOf(builtIns.anyType))
|
|
||||||
private val defaultType = KotlinTypeFactory.simpleNotNullType(annotations, this, emptyList())
|
|
||||||
|
|
||||||
override fun getTypeConstructor(): TypeConstructor = typeConstructor
|
|
||||||
|
|
||||||
override fun getDefaultType(): SimpleType = defaultType
|
|
||||||
|
|
||||||
override fun getMemberScope(typeArguments: MutableList<out TypeProjection>): MemberScope =
|
|
||||||
MemberScope.Empty // TODO do we need a more useful MemberScope here?
|
|
||||||
|
|
||||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
|
||||||
return visitor.visitClassDescriptor(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>) {
|
|
||||||
visitor.visitClassDescriptor(this, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
|
||||||
"IrFileClassDescriptor($fqNameUnsafe)"
|
|
||||||
}
|
|
||||||
+2
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.backend.common.CodegenUtil
|
|||||||
import org.jetbrains.kotlin.backend.jvm.ClassLoweringPass
|
import org.jetbrains.kotlin.backend.jvm.ClassLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptorImpl
|
||||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||||
import org.jetbrains.kotlin.codegen.isDefinitelyNotDefaultImplsMethod
|
import org.jetbrains.kotlin.codegen.isDefinitelyNotDefaultImplsMethod
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
|||||||
+1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.backend.jvm.lower
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.ClassLoweringPass
|
import org.jetbrains.kotlin.backend.jvm.ClassLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptorImpl
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.InitializersLowering.Companion.clinitName
|
import org.jetbrains.kotlin.backend.jvm.lower.InitializersLowering.Companion.clinitName
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
|||||||
Reference in New Issue
Block a user