Refactoring: Rename isUnsigned -> isUnsignedNumberLiteral

This commit is contained in:
Mikhail Zarechenskiy
2018-06-04 00:16:42 +03:00
parent cc19e4cd73
commit 57ffbd5941
3 changed files with 16 additions and 15 deletions
@@ -395,7 +395,7 @@ private class ConstantExpressionEvaluatorVisitor(
CompileTimeConstant.Parameters(
canBeUsedInAnnotation = true,
isPure = !typedConstant,
isUnsigned = isUnsigned,
isUnsignedNumberLiteral = isUnsigned,
usesVariableAsConstant = false,
usesNonConstValAsConstant = false
)
@@ -442,7 +442,7 @@ private class ConstantExpressionEvaluatorVisitor(
expectedType,
CompileTimeConstant.Parameters(
isPure = false,
isUnsigned = false,
isUnsignedNumberLiteral = false,
canBeUsedInAnnotation = canBeUsedInAnnotation,
usesVariableAsConstant = usesVariableAsConstant,
usesNonConstValAsConstant = usesNonConstantVariableAsConstant
@@ -505,7 +505,7 @@ private class ConstantExpressionEvaluatorVisitor(
CompileTimeConstant.Parameters(
canBeUsedInAnnotation = true,
isPure = false,
isUnsigned = false,
isUnsignedNumberLiteral = false,
usesVariableAsConstant = leftConstant.usesVariableAsConstant || rightConstant.usesVariableAsConstant,
usesNonConstValAsConstant = leftConstant.usesNonConstValAsConstant || rightConstant.usesNonConstValAsConstant
)
@@ -707,7 +707,7 @@ private class ConstantExpressionEvaluatorVisitor(
CompileTimeConstant.Parameters(
canBeUsedInAnnotation = isPropertyCompileTimeConstant(callableDescriptor),
isPure = false,
isUnsigned = false,
isUnsignedNumberLiteral = false,
usesVariableAsConstant = true,
usesNonConstValAsConstant = !callableDescriptor.isConst
)
@@ -911,7 +911,7 @@ private class ConstantExpressionEvaluatorVisitor(
expectedType: KotlinType?,
parameters: CompileTimeConstant.Parameters
): CompileTimeConstant<*>? {
return if (parameters.isPure || parameters.isUnsigned) {
return if (parameters.isPure || parameters.isUnsignedNumberLiteral) {
return createCompileTimeConstant(value, parameters, expectedType ?: TypeUtils.NO_EXPECTED_TYPE)
} else {
ConstantValueFactory.createConstantValue(value)?.wrap(parameters)
@@ -937,12 +937,12 @@ private class ConstantExpressionEvaluatorVisitor(
if (TypeUtils.noExpectedType(expectedType) || expectedType.isError) {
return createIntegerValueTypeConstant(value, constantExpressionEvaluator.module, parameters)
}
val integerValue = ConstantValueFactory.createIntegerConstantValue(value, expectedType, parameters.isUnsigned)
val integerValue = ConstantValueFactory.createIntegerConstantValue(value, expectedType, parameters.isUnsignedNumberLiteral)
if (integerValue != null) {
return integerValue.wrap(parameters)
}
return if (parameters.isUnsigned) {
return if (parameters.isUnsignedNumberLiteral) {
when (value) {
value.toInt().fromUIntToLong() -> UIntValue(value.toInt())
else -> ULongValue(value)
@@ -40,14 +40,15 @@ interface CompileTimeConstant<out T> {
val isPure: Boolean get() = parameters.isPure
val isUnsigned: Boolean get() = parameters.isUnsigned
val isUnsignedNumberLiteral: Boolean get() = parameters.isUnsignedNumberLiteral
class Parameters(
val canBeUsedInAnnotation: Boolean,
val isPure: Boolean,
val isUnsigned: Boolean,
val usesVariableAsConstant: Boolean,
val usesNonConstValAsConstant: Boolean
val canBeUsedInAnnotation: Boolean,
val isPure: Boolean,
// `isUnsignedNumberLiteral` means that this constant represents simple number literal with `u` suffix (123u, 0xFEu)
val isUnsignedNumberLiteral: Boolean,
val usesVariableAsConstant: Boolean,
val usesNonConstValAsConstant: Boolean
)
override fun equals(other: Any?): Boolean
@@ -88,7 +89,7 @@ fun createIntegerValueTypeConstant(
module: ModuleDescriptor,
parameters: CompileTimeConstant.Parameters
): CompileTimeConstant<*> {
return if (parameters.isUnsigned && !hasUnsignedTypesInModuleDependencies(module)) {
return if (parameters.isUnsignedNumberLiteral && !hasUnsignedTypesInModuleDependencies(module)) {
UnsignedErrorValueTypeConstant(value, parameters)
} else {
IntegerValueTypeConstant(value, module, parameters)
@@ -38,7 +38,7 @@ class IntegerValueTypeConstructor(
// order of types matters
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
// for expected type 'Any' result type 'Int' should be returned
val isUnsigned = parameters.isUnsigned
val isUnsigned = parameters.isUnsignedNumberLiteral
if (isUnsigned) {
assert(hasUnsignedTypesInModuleDependencies(module)) {