Support or, and, xor and etc in ConstantExpressionEvaluator

This commit is contained in:
Natalia Ukhorskaya
2013-11-08 13:19:01 +04:00
parent 41387c3544
commit f8f55799b9
4 changed files with 51 additions and 0 deletions
@@ -61,6 +61,11 @@ private val binaryOperations = hashMapOf<BinaryOperation<*, *>, (Any?, Any?) ->
bOp(STRING, FLOAT, "plus", { a, b -> a + b }),
bOp(STRING, CHAR, "plus", { a, b -> a + b }),
// Boolean
bOp(BOOLEAN, BOOLEAN, "and", { a, b -> a and b }),
bOp(BOOLEAN, BOOLEAN, "or", { a, b -> a or b }),
bOp(BOOLEAN, BOOLEAN, "xor", { a, b -> a xor b }),
// Byte
bOp(BYTE, DOUBLE, "plus", { a, b -> a + b }),
bOp(BYTE, FLOAT, "plus", { a, b -> a + b }),
@@ -171,6 +176,12 @@ private val binaryOperations = hashMapOf<BinaryOperation<*, *>, (Any?, Any?) ->
bOp(INT, SHORT, "mod", { a, b -> a % b }),
bOp(INT, BYTE, "mod", { a, b -> a % b }),
bOp(INT, CHAR, "mod", { a, b -> a % b }),
bOp(INT, INT, "shl", { a, b -> a shl b }),
bOp(INT, INT, "shr", { a, b -> a shr b }),
bOp(INT, INT, "ushr",{ a, b -> a ushr b }),
bOp(INT, INT, "and", { a, b -> a and b }),
bOp(INT, INT, "or", { a, b -> a or b }),
bOp(INT, INT, "xor", { a, b -> a xor b }),
// Long
bOp(LONG, DOUBLE, "plus", { a, b -> a + b }),
@@ -208,6 +219,12 @@ private val binaryOperations = hashMapOf<BinaryOperation<*, *>, (Any?, Any?) ->
bOp(LONG, SHORT, "mod", { a, b -> a % b }),
bOp(LONG, BYTE, "mod", { a, b -> a % b }),
bOp(LONG, CHAR, "mod", { a, b -> a % b }),
bOp(LONG, INT, "shl", { a, b -> a shl b }),
bOp(LONG, INT, "shr", { a, b -> a shr b }),
bOp(LONG, INT, "ushr",{ a, b -> a ushr b }),
bOp(LONG, LONG, "and", { a, b -> a and b }),
bOp(LONG, LONG, "or", { a, b -> a or b }),
bOp(LONG, LONG, "xor", { a, b -> a xor b }),
// Double
bOp(DOUBLE, DOUBLE, "plus", { a, b -> a + b }),
@@ -0,0 +1,11 @@
package test
annotation class Ann(
val b1: Boolean,
val b2: Boolean,
val b3: Boolean
)
Ann(true and false, false or true, true xor false) class MyClass
// EXPECTED: Ann[b1 = false: jet.Boolean, b2 = true: jet.Boolean, b3 = true: jet.Boolean]
@@ -0,0 +1,13 @@
package test
annotation class Ann(p1: Int,
p2: Short,
p3: Byte,
p4: Int,
p5: Int,
p6: Int
)
Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass
// EXPECTED: Ann[p1 = 1.toInt(): jet.Int, p2 = 1.toShort(): jet.Short, p3 = 0.toByte(): jet.Byte, p4 = 2.toInt(): jet.Int, p5 = 0.toInt(): jet.Int, p6 = 0.toInt(): jet.Int]
@@ -78,6 +78,11 @@ public class AnnotationParameterTestGenerated extends AbstractAnnotationParamete
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/resolveAnnotations/parameters/expressions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("boolean.kt")
public void testBoolean() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/boolean.kt");
}
@TestMetadata("char.kt")
public void testChar() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/char.kt");
@@ -128,6 +133,11 @@ public class AnnotationParameterTestGenerated extends AbstractAnnotationParamete
doTest("compiler/testData/resolveAnnotations/parameters/expressions/infixCallBinary.kt");
}
@TestMetadata("intrincics.kt")
public void testIntrincics() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/intrincics.kt");
}
@TestMetadata("long.kt")
public void testLong() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/long.kt");