diff options
Diffstat (limited to 'test/463-checker-boolean-simplifier/src/Main.java')
-rw-r--r-- | test/463-checker-boolean-simplifier/src/Main.java | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/test/463-checker-boolean-simplifier/src/Main.java b/test/463-checker-boolean-simplifier/src/Main.java index 9368488056..d1d02cdfee 100644 --- a/test/463-checker-boolean-simplifier/src/Main.java +++ b/test/463-checker-boolean-simplifier/src/Main.java @@ -32,14 +32,42 @@ public class Main { } } - // Invoke a method written in smali that implements the boolean ! operator. This method - // uses the if/else pattern generated by dx (while Jack generates a different pattern). - // Since this method is in a smali-generated class, we invoke it through reflection. - public static boolean SmaliBooleanNot(boolean x) throws Exception { - Class<?> c = Class.forName("BooleanNotSmali"); - java.lang.reflect.Method method = c.getMethod("BooleanNot", boolean.class); - Object retValue = method.invoke(null, new Object[] { Boolean.valueOf(x) }); - return ((Boolean) retValue).booleanValue(); + /* + * Elementary test negating a boolean. Verifies that blocks are merged and + * empty branches removed. + */ + + /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before) + /// CHECK-DAG: <<Param:z\d+>> ParameterValue + /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 + /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 + /// CHECK-DAG: If [<<Param>>] + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>] + /// CHECK-DAG: Return [<<Phi>>] + + /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before) + /// CHECK: Goto + /// CHECK: Goto + /// CHECK: Goto + /// CHECK-NOT: Goto + + /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) + /// CHECK-DAG: <<Param:z\d+>> ParameterValue + /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 + /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 + /// CHECK-DAG: <<NotParam:i\d+>> Select [<<Const1>>,<<Const0>>,<<Param>>] + /// CHECK-DAG: Return [<<NotParam>>] + + /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) + /// CHECK-NOT: If + /// CHECK-NOT: Phi + + /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) + /// CHECK: Goto + /// CHECK-NOT: Goto + + public static boolean BooleanNot(boolean x) { + return !x; } /* @@ -157,7 +185,11 @@ public class Main { /// CHECK-NOT: BooleanNot public static int NegatedCondition(boolean x) { - return (x != false) ? 42 : 43; + if (x != false) { + return 42; + } else { + return 43; + } } /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after) @@ -221,7 +253,13 @@ public class Main { /// CHECK-DAG: Return [<<Select123>>] public static int ThreeBlocks(boolean x, boolean y) { - return x ? 1 : (y ? 2 : 3); + if (x) { + return 1; + } else if (y) { + return 2; + } else { + return 3; + } } /// CHECK-START: int Main.MultiplePhis() select_generator (before) @@ -254,10 +292,8 @@ public class Main { while (y++ < 10) { if (y > 1) { x = 13; - continue; } else { x = 42; - continue; } } return x; @@ -330,8 +366,8 @@ public class Main { } public static void main(String[] args) throws Exception { - assertBoolEquals(false, SmaliBooleanNot(true)); - assertBoolEquals(true, SmaliBooleanNot(false)); + assertBoolEquals(false, BooleanNot(true)); + assertBoolEquals(true, BooleanNot(false)); assertBoolEquals(true, GreaterThan(10, 5)); assertBoolEquals(false, GreaterThan(10, 10)); assertBoolEquals(false, GreaterThan(5, 10)); |