Load unsigned constants from class file with the use of expected type
This commit is contained in:
+5
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
@@ -48,6 +49,8 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
|
||||
protected abstract fun loadConstant(desc: String, initializer: Any): C?
|
||||
|
||||
protected abstract fun transformToUnsignedConstant(constant: C): C?
|
||||
|
||||
protected abstract fun loadAnnotation(
|
||||
annotationClassId: ClassId,
|
||||
source: SourceElement,
|
||||
@@ -202,7 +205,8 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
val specialCase = getSpecialCaseContainerClass(container, property = true, field = true, isConst = Flags.IS_CONST.get(proto.flags))
|
||||
val kotlinClass = findClassWithAnnotationsAndInitializers(container, specialCase) ?: return null
|
||||
|
||||
return storage(kotlinClass).propertyConstants[signature]
|
||||
val constant = storage(kotlinClass).propertyConstants[signature] ?: return null
|
||||
return if (UnsignedTypes.isUnsignedType(expectedType)) transformToUnsignedConstant(constant) else constant
|
||||
}
|
||||
|
||||
private fun findClassWithAnnotationsAndInitializers(
|
||||
|
||||
+10
@@ -64,6 +64,16 @@ class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
return ConstantValueFactory.createConstantValue(normalizedValue)
|
||||
}
|
||||
|
||||
override fun transformToUnsignedConstant(constant: ConstantValue<*>): ConstantValue<*>? {
|
||||
return when (constant) {
|
||||
is ByteValue -> UByteValue(constant.value)
|
||||
is ShortValue -> UShortValue(constant.value)
|
||||
is IntValue -> UIntValue(constant.value)
|
||||
is LongValue -> ULongValue(constant.value)
|
||||
else -> constant
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadPropertyAnnotations(
|
||||
propertyAnnotations: List<AnnotationDescriptor>,
|
||||
fieldAnnotations: List<AnnotationDescriptor>,
|
||||
|
||||
Reference in New Issue
Block a user