Intrinsic default objects implementation
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicObjects;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind;
|
||||
@@ -33,7 +34,7 @@ public class FieldInfo {
|
||||
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
||||
}
|
||||
|
||||
if (kind == ClassKind.OBJECT) {
|
||||
if (kind == ClassKind.OBJECT || IntrinsicObjects.INSTANCE$.hasMappingToObject(classDescriptor)) {
|
||||
Type type = typeMapper.mapType(classDescriptor);
|
||||
return new FieldInfo(type, type, JvmAbi.INSTANCE_FIELD, true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.codegen.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.builtins.DefaultObjectMapping
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public object IntrinsicObjects : DefaultObjectMapping() {
|
||||
public fun mapType(classDescriptor: ClassDescriptor): FqName? {
|
||||
if (!hasMappingToObject(classDescriptor)) return null
|
||||
|
||||
val containingDeclaration = classDescriptor.getContainingDeclaration()
|
||||
val name = Name.identifier(containingDeclaration.getName().asString() + "DefaultObject")
|
||||
return FqName("kotlin.jvm.internal").child(name)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicObjects;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
||||
@@ -293,6 +294,18 @@ public class JetTypeMapper {
|
||||
return Type.getType("[" + boxType(mapType(memberType, kind)).getDescriptor());
|
||||
}
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
FqName defaultObjectMappedFqName = IntrinsicObjects.INSTANCE$.mapType((ClassDescriptor) descriptor);
|
||||
if (defaultObjectMappedFqName != null) {
|
||||
Type asmType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(defaultObjectMappedFqName);
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeAsmType(asmType);
|
||||
}
|
||||
|
||||
return asmType;
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
Type asmType = computeAsmType((ClassDescriptor) descriptor.getOriginal());
|
||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||
@@ -399,10 +412,10 @@ public class JetTypeMapper {
|
||||
else {
|
||||
Variance projectionKind = projectionsAllowed
|
||||
? getEffectiveVariance(
|
||||
parameter.getVariance(),
|
||||
argument.getProjectionKind(),
|
||||
howThisTypeIsUsed
|
||||
)
|
||||
parameter.getVariance(),
|
||||
argument.getProjectionKind(),
|
||||
howThisTypeIsUsed
|
||||
)
|
||||
: Variance.INVARIANT;
|
||||
signatureVisitor.writeTypeArgument(projectionKind);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user