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