Initial support of unsigned literals translation in JS
This commit is contained in:
committed by
Ilya Gorbunov
parent
1792a77a47
commit
61efbea9a8
@@ -62,6 +62,7 @@ public final class Namer {
|
||||
public static final String LONG_FROM_NUMBER = "fromNumber";
|
||||
public static final String LONG_TO_NUMBER = "toNumber";
|
||||
public static final String LONG_FROM_INT = "fromInt";
|
||||
public static final String UINT_FROM_INT = "toUInt";
|
||||
public static final String LONG_ZERO = "ZERO";
|
||||
public static final String LONG_ONE = "ONE";
|
||||
public static final String LONG_NEG_ONE = "NEG_ONE";
|
||||
|
||||
@@ -47,9 +47,7 @@ import org.jetbrains.kotlin.js.translate.utils.mutator.AssignToExpressionMutator
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.*;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstDeserializer;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
@@ -150,6 +148,10 @@ public final class Translation {
|
||||
if (constant instanceof NullValue) {
|
||||
return new JsNullLiteral();
|
||||
}
|
||||
if (constant instanceof UnsignedValueConstant<?>) {
|
||||
return translateUnsignedConstant((UnsignedValueConstant<?>) constant);
|
||||
}
|
||||
|
||||
Object value = constant.getValue();
|
||||
if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
|
||||
return new JsIntLiteral(((Number) value).intValue());
|
||||
@@ -186,6 +188,23 @@ public final class Translation {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static JsExpression translateUnsignedConstant(@NotNull UnsignedValueConstant<?> unsignedConstant) {
|
||||
if (unsignedConstant instanceof UByteValue) {
|
||||
return null;
|
||||
}
|
||||
else if (unsignedConstant instanceof UShortValue) {
|
||||
return null;
|
||||
}
|
||||
else if (unsignedConstant instanceof UIntValue) {
|
||||
return JsAstUtils.intToUInt(((UIntValue) unsignedConstant).getValue());
|
||||
}
|
||||
else if (unsignedConstant instanceof ULongValue) {
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsNode doTranslateExpression(KtExpression expression, TranslationContext context) {
|
||||
try {
|
||||
|
||||
@@ -217,6 +217,11 @@ public final class JsAstUtils {
|
||||
return invokeMethod(expression, Namer.LONG_TO_NUMBER);
|
||||
}
|
||||
|
||||
public static JsExpression intToUInt(int value) {
|
||||
JsIntLiteral literal = new JsIntLiteral(value);
|
||||
return invokeMethod(Namer.kotlinObject(), Namer.UINT_FROM_INT, literal);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression compareForObject(@NotNull JsExpression left, @NotNull JsExpression right) {
|
||||
return invokeMethod(left, Namer.COMPARE_TO_METHOD_NAME, right);
|
||||
|
||||
Reference in New Issue
Block a user