Move range utils into common compiler part
This commit is contained in:
committed by
teamcity
parent
100d7123c2
commit
4363667bc1
@@ -138,13 +138,6 @@ public class DescriptorAsmUtil {
|
|||||||
return boxedPrimitiveType != null ? boxedPrimitiveType : type;
|
return boxedPrimitiveType != null ? boxedPrimitiveType : type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPrimitiveNumberClassDescriptor(DeclarationDescriptor descriptor) {
|
|
||||||
if (!(descriptor instanceof ClassDescriptor)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return isPrimitiveClass((ClassDescriptor) descriptor) && !isBoolean((ClassDescriptor) descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAbstractMethod(FunctionDescriptor functionDescriptor, OwnerKind kind, JvmDefaultMode jvmDefaultMode) {
|
public static boolean isAbstractMethod(FunctionDescriptor functionDescriptor, OwnerKind kind, JvmDefaultMode jvmDefaultMode) {
|
||||||
return (functionDescriptor.getModality() == Modality.ABSTRACT ||
|
return (functionDescriptor.getModality() == Modality.ABSTRACT ||
|
||||||
(isJvmInterface(functionDescriptor.getContainingDeclaration()) && !JvmAnnotationUtilKt
|
(isJvmInterface(functionDescriptor.getContainingDeclaration()) && !JvmAnnotationUtilKt
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ import static org.jetbrains.kotlin.resolve.BindingContextUtils.getDelegationCons
|
|||||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isBoxedLocalCapturedInClosure;
|
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isBoxedLocalCapturedInClosure;
|
||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||||
|
import static org.jetbrains.kotlin.types.RangeUtilKt.isPrimitiveNumberClassDescriptor;
|
||||||
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression;
|
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression;
|
||||||
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral;
|
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral;
|
||||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.codegen.AsmUtil
|
|||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.OptimizationBasicInterpreter
|
import org.jetbrains.kotlin.codegen.optimization.common.OptimizationBasicInterpreter
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue
|
import org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue
|
||||||
import org.jetbrains.kotlin.codegen.range.*
|
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||||
import org.jetbrains.kotlin.codegen.topLevelClassInternalName
|
import org.jetbrains.kotlin.codegen.topLevelClassInternalName
|
||||||
@@ -36,6 +35,7 @@ import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
|||||||
import org.jetbrains.org.objectweb.asm.tree.InsnList
|
import org.jetbrains.org.objectweb.asm.tree.InsnList
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
||||||
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
open class BoxingInterpreter(
|
open class BoxingInterpreter(
|
||||||
private val insnList: InsnList,
|
private val insnList: InsnList,
|
||||||
|
|||||||
+1
-1
@@ -18,9 +18,9 @@ package org.jetbrains.kotlin.codegen.optimization.boxing
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue
|
import org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue
|
||||||
import org.jetbrains.kotlin.codegen.range.*
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||||
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
class ProgressionIteratorBasicValue
|
class ProgressionIteratorBasicValue
|
||||||
private constructor(
|
private constructor(
|
||||||
|
|||||||
+1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.kotlin.types.isClosedRangeContains
|
||||||
|
|
||||||
class ComparableRangeLiteralRangeValue(
|
class ComparableRangeLiteralRangeValue(
|
||||||
codegen: ExpressionCodegen,
|
codegen: ExpressionCodegen,
|
||||||
|
|||||||
+1
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.constants.*
|
import org.jetbrains.kotlin.resolve.constants.*
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
abstract class PrimitiveNumberRangeIntrinsicRangeValue(
|
abstract class PrimitiveNumberRangeIntrinsicRangeValue(
|
||||||
rangeCall: ResolvedCall<out CallableDescriptor>
|
rangeCall: ResolvedCall<out CallableDescriptor>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
|||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.getRangeOrProgressionElementType
|
||||||
|
|
||||||
class PrimitiveRangeRangeValue(private val rangeExpression: KtExpression) : ReversableRangeValue {
|
class PrimitiveRangeRangeValue(private val rangeExpression: KtExpression) : ReversableRangeValue {
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
import org.jetbrains.kotlin.types.*
|
||||||
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
|
|
||||||
fun ExpressionCodegen.createRangeValueForExpression(rangeExpression: KtExpression): RangeValue {
|
fun ExpressionCodegen.createRangeValueForExpression(rangeExpression: KtExpression): RangeValue {
|
||||||
// NB when you implement a new intrinsic RangeValue,
|
// NB when you implement a new intrinsic RangeValue,
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.codegen.range.comparison
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.range.getRangeOrProgressionElementType
|
import org.jetbrains.kotlin.types.getRangeOrProgressionElementType
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
|||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.codegen.range.comparison.SignedIntegerComparisonGenerator
|
import org.jetbrains.kotlin.codegen.range.comparison.SignedIntegerComparisonGenerator
|
||||||
import org.jetbrains.kotlin.codegen.range.comparison.getComparisonGeneratorForKotlinType
|
import org.jetbrains.kotlin.codegen.range.comparison.getComparisonGeneratorForKotlinType
|
||||||
import org.jetbrains.kotlin.codegen.range.getRangeOrProgressionElementType
|
import org.jetbrains.kotlin.types.getRangeOrProgressionElementType
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.codegen.range.forLoop
|
|||||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.codegen.filterOutDescriptorsWithSpecialNames
|
import org.jetbrains.kotlin.codegen.filterOutDescriptorsWithSpecialNames
|
||||||
import org.jetbrains.kotlin.codegen.range.getElementType
|
import org.jetbrains.kotlin.types.getElementType
|
||||||
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
|
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
|||||||
+33
-12
@@ -1,14 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.range
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil.isPrimitiveNumberClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -19,7 +18,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
|
|
||||||
fun isPrimitiveRange(rangeType: KotlinType) =
|
fun isPrimitiveRange(rangeType: KotlinType) =
|
||||||
isClassTypeWithFqn(rangeType, PRIMITIVE_RANGE_FQNS)
|
isClassTypeWithFqn(rangeType, PRIMITIVE_RANGE_FQNS)
|
||||||
@@ -43,14 +41,14 @@ private val KotlinType.classFqnString: String?
|
|||||||
private fun isClassTypeWithFqn(kotlinType: KotlinType, fqns: Set<String>): Boolean =
|
private fun isClassTypeWithFqn(kotlinType: KotlinType, fqns: Set<String>): Boolean =
|
||||||
kotlinType.classFqnString in fqns
|
kotlinType.classFqnString in fqns
|
||||||
|
|
||||||
internal const val CHAR_RANGE_FQN = "kotlin.ranges.CharRange"
|
const val CHAR_RANGE_FQN = "kotlin.ranges.CharRange"
|
||||||
internal const val INT_RANGE_FQN = "kotlin.ranges.IntRange"
|
const val INT_RANGE_FQN = "kotlin.ranges.IntRange"
|
||||||
internal const val LONG_RANGE_FQN = "kotlin.ranges.LongRange"
|
const val LONG_RANGE_FQN = "kotlin.ranges.LongRange"
|
||||||
private val PRIMITIVE_RANGE_FQNS = setOf(CHAR_RANGE_FQN, INT_RANGE_FQN, LONG_RANGE_FQN)
|
private val PRIMITIVE_RANGE_FQNS = setOf(CHAR_RANGE_FQN, INT_RANGE_FQN, LONG_RANGE_FQN)
|
||||||
|
|
||||||
internal const val CHAR_PROGRESSION_FQN = "kotlin.ranges.CharProgression"
|
const val CHAR_PROGRESSION_FQN = "kotlin.ranges.CharProgression"
|
||||||
internal const val INT_PROGRESSION_FQN = "kotlin.ranges.IntProgression"
|
const val INT_PROGRESSION_FQN = "kotlin.ranges.IntProgression"
|
||||||
internal const val LONG_PROGRESSION_FQN = "kotlin.ranges.LongProgression"
|
const val LONG_PROGRESSION_FQN = "kotlin.ranges.LongProgression"
|
||||||
private val PRIMITIVE_PROGRESSION_FQNS = setOf(CHAR_PROGRESSION_FQN, INT_PROGRESSION_FQN, LONG_PROGRESSION_FQN)
|
private val PRIMITIVE_PROGRESSION_FQNS = setOf(CHAR_PROGRESSION_FQN, INT_PROGRESSION_FQN, LONG_PROGRESSION_FQN)
|
||||||
|
|
||||||
private const val CLOSED_FLOAT_RANGE_FQN = "kotlin.ranges.ClosedFloatRange"
|
private const val CLOSED_FLOAT_RANGE_FQN = "kotlin.ranges.ClosedFloatRange"
|
||||||
@@ -67,11 +65,25 @@ internal const val UINT_PROGRESSION_FQN = "kotlin.ranges.UIntProgression"
|
|||||||
internal const val ULONG_PROGRESSION_FQN = "kotlin.ranges.ULongProgression"
|
internal const val ULONG_PROGRESSION_FQN = "kotlin.ranges.ULongProgression"
|
||||||
private val UNSIGNED_PROGRESSION_FQNS = setOf(UINT_PROGRESSION_FQN, ULONG_PROGRESSION_FQN)
|
private val UNSIGNED_PROGRESSION_FQNS = setOf(UINT_PROGRESSION_FQN, ULONG_PROGRESSION_FQN)
|
||||||
|
|
||||||
fun getRangeOrProgressionElementType(rangeType: KotlinType): KotlinType? {
|
private val ALL_PROGRESSION_AND_RANGES = listOf(
|
||||||
|
CHAR_RANGE_FQN, CHAR_PROGRESSION_FQN,
|
||||||
|
INT_RANGE_FQN, INT_PROGRESSION_FQN,
|
||||||
|
LONG_RANGE_FQN, LONG_PROGRESSION_FQN,
|
||||||
|
CLOSED_FLOAT_RANGE_FQN, CLOSED_DOUBLE_RANGE_FQN,
|
||||||
|
CLOSED_RANGE_FQN, CLOSED_FLOATING_POINT_RANGE_FQN,
|
||||||
|
COMPARABLE_RANGE_FQN,
|
||||||
|
UINT_RANGE_FQN, UINT_PROGRESSION_FQN,
|
||||||
|
ULONG_RANGE_FQN, ULONG_PROGRESSION_FQN
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getRangeOrProgressionElementType(rangeType: KotlinType, progressionsAndRanges: List<String> = ALL_PROGRESSION_AND_RANGES): KotlinType? {
|
||||||
val rangeClassDescriptor = rangeType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
val rangeClassDescriptor = rangeType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||||
val builtIns = rangeClassDescriptor.builtIns
|
val builtIns = rangeClassDescriptor.builtIns
|
||||||
|
val fqName = rangeClassDescriptor.fqNameSafe.asString()
|
||||||
|
|
||||||
return when (rangeClassDescriptor.fqNameSafe.asString()) {
|
if (fqName !in progressionsAndRanges) return null
|
||||||
|
|
||||||
|
return when (fqName) {
|
||||||
CHAR_RANGE_FQN, CHAR_PROGRESSION_FQN -> builtIns.charType
|
CHAR_RANGE_FQN, CHAR_PROGRESSION_FQN -> builtIns.charType
|
||||||
INT_RANGE_FQN, INT_PROGRESSION_FQN -> builtIns.intType
|
INT_RANGE_FQN, INT_PROGRESSION_FQN -> builtIns.intType
|
||||||
LONG_RANGE_FQN, LONG_PROGRESSION_FQN -> builtIns.longType
|
LONG_RANGE_FQN, LONG_PROGRESSION_FQN -> builtIns.longType
|
||||||
@@ -267,3 +279,12 @@ fun isCharSequenceIterator(descriptor: CallableDescriptor) =
|
|||||||
it.constructor.declarationDescriptor?.isTopLevelInPackage("CharSequence", "kotlin")
|
it.constructor.declarationDescriptor?.isTopLevelInPackage("CharSequence", "kotlin")
|
||||||
?: false
|
?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun isPrimitiveNumberClassDescriptor(descriptor: DeclarationDescriptor?): Boolean {
|
||||||
|
return if (descriptor !is ClassDescriptor) {
|
||||||
|
false
|
||||||
|
} else KotlinBuiltIns.isPrimitiveClass((descriptor as ClassDescriptor?)!!) && !KotlinBuiltIns.isBoolean(
|
||||||
|
(descriptor as ClassDescriptor?)!!
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user