# HG changeset patch # User Christian Humer # Date 1407766914 -7200 # Node ID e6d15134ca86a5dfab5957f5959e2d201d6fd3b4 # Parent ea9903f9684f24fb9cd2d5c58eb9a1630f8bf17e Truffle-DSL: fixed formatting problems. diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ReachabilityTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ReachabilityTest.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ReachabilityTest.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,353 +1,353 @@ -package com.oracle.truffle.api.dsl.test; - -import java.math.*; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.dsl.test.TypeSystemTest.*; - -public class ReachabilityTest { - - static class Reachability1 extends ValueNode { - @Specialization - int do2() { - return 2; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization - int do1() { - return 2; - } - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType1 extends ValueNode { - @Specialization - int do2(int a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(int).") - @Specialization - int do1(int a) { - return a; - } - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType2 extends ValueNode { - @Specialization - BExtendsAbstract do2(BExtendsAbstract a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(BExtendsAbstract).") - @Specialization - BExtendsAbstract do1(BExtendsAbstract a) { - return a; - } - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType3 extends ValueNode { - @Specialization - Abstract do2(Abstract a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(Abstract).") - @Specialization - BExtendsAbstract do1(BExtendsAbstract a) { - return a; - } - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType4 extends ValueNode { - - @Specialization - BExtendsAbstract do2(BExtendsAbstract a) { - return a; - } - - @Specialization - Abstract do1(Abstract a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType5 extends ValueNode { - - @Specialization - double do2(double a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(double).") - @Specialization - int do1(int a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType6 extends ValueNode { - - @Specialization - BigInteger do2(BigInteger a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(BigInteger).") - @Specialization - int do1(int a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType7 extends ValueNode { - - @Specialization - int do2(int a) { - return a; - } - - @Specialization - BigInteger do1(BigInteger a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType8 extends ValueNode { - - @Specialization - int do2(int a) { - return a; - } - - @Specialization - Object do1(Object a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class ReachabilityType9 extends ValueNode { - - @Specialization - Object do2(Object a) { - return a; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2(Object).") - @Specialization - int do1(int a) { - return a; - } - } - - static class ReachabilityGuard1 extends ValueNode { - - boolean foo() { - return false; - } - - @Specialization(guards = "foo") - int do2() { - return 1; - } - - @Specialization - int do1() { - return 2; - } - - } - - static class ReachabilityGuard2 extends ValueNode { - - boolean foo() { - return false; - } - - @Specialization - int do2() { - return 2; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(guards = "foo") - int do1() { - return 1; - } - - } - - static class ReachabilityGuard3 extends ValueNode { - - boolean foo() { - return false; - } - - @Specialization(guards = "foo") - int do2() { - return 1; - } - - @Specialization - int do1() { - return 2; - } - - } - - static class ReachabilityGuard4 extends ValueNode { - - boolean foo() { - return false; - } - - @Specialization(guards = "foo") - int do2() { - return 1; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(guards = "foo") - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1"}) - static class ReachabilityAssumption1 extends ValueNode { - - @Specialization(assumptions = "a1") - int do2() { - return 1; - } - - @Specialization - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1"}) - static class ReachabilityAssumption2 extends ValueNode { - - @Specialization(assumptions = "a1") - int do2() { - return 1; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(assumptions = "a1") - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1", "a2"}) - static class ReachabilityAssumption3 extends ValueNode { - - @Specialization(assumptions = {"a1", "a2"}) - int do2() { - return 1; - } - - @Specialization(assumptions = "a1") - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1", "a2"}) - static class ReachabilityAssumption4 extends ValueNode { - - @Specialization(assumptions = "a1") - int do2() { - return 1; - } - - @Specialization(assumptions = "a2") - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1", "a2"}) - static class ReachabilityAssumption5 extends ValueNode { - - @Specialization - int do2() { - return 1; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(assumptions = "a2") - int do1() { - return 2; - } - - } - - @NodeAssumptions({"a1", "a2"}) - static class ReachabilityAssumption6 extends ValueNode { - - @Specialization(assumptions = {"a1"}) - int do2() { - return 1; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(assumptions = {"a1", "a2"}) - int do1() { - return 2; - } - - } - - static class ReachabilityThrowable1 extends ValueNode { - - @Specialization(rewriteOn = RuntimeException.class) - int do2() throws RuntimeException { - return 1; - } - - @Specialization - int do1() { - return 2; - } - - } - - static class ReachabilityThrowable2 extends ValueNode { - - @Specialization - int do2() { - return 1; - } - - @ExpectError("Specialization is not reachable. It is shadowed by do2().") - @Specialization(rewriteOn = RuntimeException.class) - int do1() throws RuntimeException { - return 2; - } - - } - -} +package com.oracle.truffle.api.dsl.test; + +import java.math.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.*; + +public class ReachabilityTest { + + static class Reachability1 extends ValueNode { + @Specialization + int do2() { + return 2; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization + int do1() { + return 2; + } + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType1 extends ValueNode { + @Specialization + int do2(int a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(int).") + @Specialization + int do1(int a) { + return a; + } + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType2 extends ValueNode { + @Specialization + BExtendsAbstract do2(BExtendsAbstract a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(BExtendsAbstract).") + @Specialization + BExtendsAbstract do1(BExtendsAbstract a) { + return a; + } + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType3 extends ValueNode { + @Specialization + Abstract do2(Abstract a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(Abstract).") + @Specialization + BExtendsAbstract do1(BExtendsAbstract a) { + return a; + } + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType4 extends ValueNode { + + @Specialization + BExtendsAbstract do2(BExtendsAbstract a) { + return a; + } + + @Specialization + Abstract do1(Abstract a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType5 extends ValueNode { + + @Specialization + double do2(double a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(double).") + @Specialization + int do1(int a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType6 extends ValueNode { + + @Specialization + BigInteger do2(BigInteger a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(BigInteger).") + @Specialization + int do1(int a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType7 extends ValueNode { + + @Specialization + int do2(int a) { + return a; + } + + @Specialization + BigInteger do1(BigInteger a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType8 extends ValueNode { + + @Specialization + int do2(int a) { + return a; + } + + @Specialization + Object do1(Object a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class ReachabilityType9 extends ValueNode { + + @Specialization + Object do2(Object a) { + return a; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2(Object).") + @Specialization + int do1(int a) { + return a; + } + } + + static class ReachabilityGuard1 extends ValueNode { + + boolean foo() { + return false; + } + + @Specialization(guards = "foo") + int do2() { + return 1; + } + + @Specialization + int do1() { + return 2; + } + + } + + static class ReachabilityGuard2 extends ValueNode { + + boolean foo() { + return false; + } + + @Specialization + int do2() { + return 2; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(guards = "foo") + int do1() { + return 1; + } + + } + + static class ReachabilityGuard3 extends ValueNode { + + boolean foo() { + return false; + } + + @Specialization(guards = "foo") + int do2() { + return 1; + } + + @Specialization + int do1() { + return 2; + } + + } + + static class ReachabilityGuard4 extends ValueNode { + + boolean foo() { + return false; + } + + @Specialization(guards = "foo") + int do2() { + return 1; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(guards = "foo") + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1"}) + static class ReachabilityAssumption1 extends ValueNode { + + @Specialization(assumptions = "a1") + int do2() { + return 1; + } + + @Specialization + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1"}) + static class ReachabilityAssumption2 extends ValueNode { + + @Specialization(assumptions = "a1") + int do2() { + return 1; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(assumptions = "a1") + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1", "a2"}) + static class ReachabilityAssumption3 extends ValueNode { + + @Specialization(assumptions = {"a1", "a2"}) + int do2() { + return 1; + } + + @Specialization(assumptions = "a1") + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1", "a2"}) + static class ReachabilityAssumption4 extends ValueNode { + + @Specialization(assumptions = "a1") + int do2() { + return 1; + } + + @Specialization(assumptions = "a2") + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1", "a2"}) + static class ReachabilityAssumption5 extends ValueNode { + + @Specialization + int do2() { + return 1; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(assumptions = "a2") + int do1() { + return 2; + } + + } + + @NodeAssumptions({"a1", "a2"}) + static class ReachabilityAssumption6 extends ValueNode { + + @Specialization(assumptions = {"a1"}) + int do2() { + return 1; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(assumptions = {"a1", "a2"}) + int do1() { + return 2; + } + + } + + static class ReachabilityThrowable1 extends ValueNode { + + @Specialization(rewriteOn = RuntimeException.class) + int do2() throws RuntimeException { + return 1; + } + + @Specialization + int do1() { + return 2; + } + + } + + static class ReachabilityThrowable2 extends ValueNode { + + @Specialization + int do2() { + return 1; + } + + @ExpectError("Specialization is not reachable. It is shadowed by do2().") + @Specialization(rewriteOn = RuntimeException.class) + int do1() throws RuntimeException { + return 2; + } + + } + +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,350 +1,350 @@ -package com.oracle.truffle.api.dsl.test; - -import static com.oracle.truffle.api.dsl.test.TestHelper.*; - -import org.junit.*; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest0Factory; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest1Factory; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest2Factory; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest3Factory; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest4Factory; -import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest5Factory; -import com.oracle.truffle.api.dsl.test.TestHelper.ExecutionListener; -import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; -import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; - -public class SpecializationFallthroughTest { - - @Test - public void testFallthrough0() { - assertRuns(FallthroughTest0Factory.getInstance(), // - array(0, 0, 1, 2), // - array(0, 0, 1, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest0.fallthroughCount > 1) { - Assert.fail("The fallthrough case must never be triggered twice. Therfore count must be <= 1, but is not."); - } - } - }); - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest0 extends ValueNode { - - static int fallthroughCount = 0; - - public FallthroughTest0() { - fallthroughCount = 0; - } - - @Specialization(rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthroughCount++; - throw new ArithmeticException(); - } - return a; - } - - @Fallback - Object doFallback(Object a) { - return a; - } - } - - /* - * Tests that the fall through is never triggered twice for monomorphic cases. - */ - @Test - public void testFallthrough1() { - assertRuns(FallthroughTest1Factory.getInstance(), // - array(0, 0, 0, 1, 2), // - array(0, 0, 0, 1, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest1.fallthroughCount > 1) { - Assert.fail("The fallthrough case must never be triggered twice. Therfore count must be <= 1, but is not."); - } - } - }); - } - - /* TODO assert falltrough do1 before do2 */ - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest1 extends ValueNode { - - static int fallthroughCount; - - public FallthroughTest1() { - fallthroughCount = 0; - } - - @Specialization(rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthroughCount++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization - int do2(int a) { - return a; - } - - } - - /* - * Tests that the fall through is never triggered twice with two falltrhoughs in one operation. - */ - @Test - public void testFallthrough2() { - assertRuns(FallthroughTest2Factory.getInstance(), // - array(0, 0, 1, 1, 2, 2), // - array(0, 0, 1, 1, 2, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest2.fallthrough1 > 1) { - Assert.fail(); - } - if (FallthroughTest2.fallthrough2 > 1) { - Assert.fail(); - } - FallthroughTest2.fallthrough1 = 0; - FallthroughTest2.fallthrough2 = 0; - } - }); - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest2 extends ValueNode { - - static int fallthrough1; - static int fallthrough2; - - @Specialization(order = 1, rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthrough1++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization(order = 2, rewriteOn = ArithmeticException.class) - int do2(int a) throws ArithmeticException { - if (a == 1) { - fallthrough2++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization - int do3(int a) { - return a; - } - } - - /* - * Tests that the fall through is never triggered twice. In this case mixed fallthrough with - * normal specializations. - */ - @Test - public void testFallthrough3() { - assertRuns(FallthroughTest3Factory.getInstance(), // - array(0, 0, 1, 1, 2, 2), // - array(0, 0, 1, 1, 2, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest3.fallthrough1 > 1) { - Assert.fail(String.valueOf(FallthroughTest3.fallthrough1)); - } - FallthroughTest3.fallthrough1 = 0; - } - }); - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest3 extends ValueNode { - - static int fallthrough1; - - boolean guard0(int a) { - return a == 1; - } - - @Specialization(guards = "guard0") - int do2(int a) { - return a; - } - - @Specialization(rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthrough1++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization - int do3(int a) { - return a; - } - - } - - @Test - public void testFallthrough4() { - assertRuns(FallthroughTest4Factory.getInstance(), // - array(0, 0, 1, 1, 2, 2), // - array(0, 0, 1, 1, 2, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest4.fallthrough1 > 1) { - Assert.fail(String.valueOf(FallthroughTest4.fallthrough1)); - } - if (FallthroughTest4.fallthrough2 > 1) { - Assert.fail(String.valueOf(FallthroughTest4.fallthrough1)); - } - FallthroughTest4.fallthrough1 = 0; - FallthroughTest4.fallthrough2 = 0; - } - }); - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest4 extends ValueNode { - - static int fallthrough1; - static int fallthrough2; - - @Specialization(order = 1, rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthrough1++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization(order = 2, rewriteOn = ArithmeticException.class) - int do2(int a) throws ArithmeticException { - if (a == 1) { - fallthrough2++; - throw new ArithmeticException(); - } - return a; - } - - @Specialization - int do3(int a) { - return a; - } - - } - - @Test - public void testFallthrough5() { - assertRuns(FallthroughTest5Factory.getInstance(), // - array(0, 0, 1, 1, 2, 2), // - array(0, 0, 1, 1, 2, 2),// - new ExecutionListener() { - public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { - if (!last) { - return; - } - if (FallthroughTest5.fallthrough1 > 1) { - Assert.fail(String.valueOf(FallthroughTest5.fallthrough1)); - } - FallthroughTest5.fallthrough1 = 0; - } - }); - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest5 extends ValueNode { - - static int fallthrough1; - - @Specialization(guards = "isDo1", rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - if (a == 0) { - fallthrough1++; - throw new ArithmeticException(); - } - return a; - } - - protected static boolean isDo1(int a) { - return a == 0 || a == 1; - } - - @Specialization(guards = "isDo1") - int do2(int a) { - return a; - } - - @Specialization - int do3(int a) { - return a; - } - - } - - @NodeChildren({@NodeChild("a")}) - static class FallthroughTest6 extends ValueNode { - - static int fallthrough1; - static int fallthrough2; - static int fallthrough3; - static int fallthrough4; - - @Specialization(order = 1, rewriteOn = ArithmeticException.class) - int do4(int a) throws ArithmeticException { - return a; - } - - @Specialization(order = 2, rewriteOn = ArithmeticException.class) - int do2(int a) throws ArithmeticException { - return a; - } - - @Specialization(order = 3, rewriteOn = ArithmeticException.class) - int do3(int a) throws ArithmeticException { - return a; - } - - @Specialization(order = 4, rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - return a; - } - - @Specialization - double do5(double a) { - return a; - } - - } - -} +package com.oracle.truffle.api.dsl.test; + +import static com.oracle.truffle.api.dsl.test.TestHelper.*; + +import org.junit.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest0Factory; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest1Factory; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest2Factory; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest3Factory; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest4Factory; +import com.oracle.truffle.api.dsl.test.SpecializationFallthroughTestFactory.FallthroughTest5Factory; +import com.oracle.truffle.api.dsl.test.TestHelper.ExecutionListener; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; + +public class SpecializationFallthroughTest { + + @Test + public void testFallthrough0() { + assertRuns(FallthroughTest0Factory.getInstance(), // + array(0, 0, 1, 2), // + array(0, 0, 1, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest0.fallthroughCount > 1) { + Assert.fail("The fallthrough case must never be triggered twice. Therfore count must be <= 1, but is not."); + } + } + }); + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest0 extends ValueNode { + + static int fallthroughCount = 0; + + public FallthroughTest0() { + fallthroughCount = 0; + } + + @Specialization(rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthroughCount++; + throw new ArithmeticException(); + } + return a; + } + + @Fallback + Object doFallback(Object a) { + return a; + } + } + + /* + * Tests that the fall through is never triggered twice for monomorphic cases. + */ + @Test + public void testFallthrough1() { + assertRuns(FallthroughTest1Factory.getInstance(), // + array(0, 0, 0, 1, 2), // + array(0, 0, 0, 1, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest1.fallthroughCount > 1) { + Assert.fail("The fallthrough case must never be triggered twice. Therfore count must be <= 1, but is not."); + } + } + }); + } + + /* TODO assert falltrough do1 before do2 */ + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest1 extends ValueNode { + + static int fallthroughCount; + + public FallthroughTest1() { + fallthroughCount = 0; + } + + @Specialization(rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthroughCount++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization + int do2(int a) { + return a; + } + + } + + /* + * Tests that the fall through is never triggered twice with two falltrhoughs in one operation. + */ + @Test + public void testFallthrough2() { + assertRuns(FallthroughTest2Factory.getInstance(), // + array(0, 0, 1, 1, 2, 2), // + array(0, 0, 1, 1, 2, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest2.fallthrough1 > 1) { + Assert.fail(); + } + if (FallthroughTest2.fallthrough2 > 1) { + Assert.fail(); + } + FallthroughTest2.fallthrough1 = 0; + FallthroughTest2.fallthrough2 = 0; + } + }); + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest2 extends ValueNode { + + static int fallthrough1; + static int fallthrough2; + + @Specialization(order = 1, rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthrough1++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization(order = 2, rewriteOn = ArithmeticException.class) + int do2(int a) throws ArithmeticException { + if (a == 1) { + fallthrough2++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization + int do3(int a) { + return a; + } + } + + /* + * Tests that the fall through is never triggered twice. In this case mixed fallthrough with + * normal specializations. + */ + @Test + public void testFallthrough3() { + assertRuns(FallthroughTest3Factory.getInstance(), // + array(0, 0, 1, 1, 2, 2), // + array(0, 0, 1, 1, 2, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest3.fallthrough1 > 1) { + Assert.fail(String.valueOf(FallthroughTest3.fallthrough1)); + } + FallthroughTest3.fallthrough1 = 0; + } + }); + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest3 extends ValueNode { + + static int fallthrough1; + + boolean guard0(int a) { + return a == 1; + } + + @Specialization(guards = "guard0") + int do2(int a) { + return a; + } + + @Specialization(rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthrough1++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization + int do3(int a) { + return a; + } + + } + + @Test + public void testFallthrough4() { + assertRuns(FallthroughTest4Factory.getInstance(), // + array(0, 0, 1, 1, 2, 2), // + array(0, 0, 1, 1, 2, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest4.fallthrough1 > 1) { + Assert.fail(String.valueOf(FallthroughTest4.fallthrough1)); + } + if (FallthroughTest4.fallthrough2 > 1) { + Assert.fail(String.valueOf(FallthroughTest4.fallthrough1)); + } + FallthroughTest4.fallthrough1 = 0; + FallthroughTest4.fallthrough2 = 0; + } + }); + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest4 extends ValueNode { + + static int fallthrough1; + static int fallthrough2; + + @Specialization(order = 1, rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthrough1++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization(order = 2, rewriteOn = ArithmeticException.class) + int do2(int a) throws ArithmeticException { + if (a == 1) { + fallthrough2++; + throw new ArithmeticException(); + } + return a; + } + + @Specialization + int do3(int a) { + return a; + } + + } + + @Test + public void testFallthrough5() { + assertRuns(FallthroughTest5Factory.getInstance(), // + array(0, 0, 1, 1, 2, 2), // + array(0, 0, 1, 1, 2, 2),// + new ExecutionListener() { + public void afterExecution(TestRootNode node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { + if (!last) { + return; + } + if (FallthroughTest5.fallthrough1 > 1) { + Assert.fail(String.valueOf(FallthroughTest5.fallthrough1)); + } + FallthroughTest5.fallthrough1 = 0; + } + }); + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest5 extends ValueNode { + + static int fallthrough1; + + @Specialization(guards = "isDo1", rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + if (a == 0) { + fallthrough1++; + throw new ArithmeticException(); + } + return a; + } + + protected static boolean isDo1(int a) { + return a == 0 || a == 1; + } + + @Specialization(guards = "isDo1") + int do2(int a) { + return a; + } + + @Specialization + int do3(int a) { + return a; + } + + } + + @NodeChildren({@NodeChild("a")}) + static class FallthroughTest6 extends ValueNode { + + static int fallthrough1; + static int fallthrough2; + static int fallthrough3; + static int fallthrough4; + + @Specialization(order = 1, rewriteOn = ArithmeticException.class) + int do4(int a) throws ArithmeticException { + return a; + } + + @Specialization(order = 2, rewriteOn = ArithmeticException.class) + int do2(int a) throws ArithmeticException { + return a; + } + + @Specialization(order = 3, rewriteOn = ArithmeticException.class) + int do3(int a) throws ArithmeticException { + return a; + } + + @Specialization(order = 4, rewriteOn = ArithmeticException.class) + int do1(int a) throws ArithmeticException { + return a; + } + + @Specialization + double do5(double a) { + return a; + } + + } + +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/TypeCheck.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/TypeCheck.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/TypeCheck.java Mon Aug 11 16:21:54 2014 +0200 @@ -57,17 +57,17 @@ * * {@literal @}TypeSystem(types = {int.class, BigInteger.class, String.class}, nodeBaseClass = TypedNode.class) * public abstract class Types { - * + * * {@literal @}TypeCheck * public boolean isBigInteger(Object value) { * return value instanceof Integer || value instanceof BigInteger; * } - * + * * {@literal @}TypeCheck * public boolean isBigInteger(int value) { * return true; * } - * + * * } * * diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLMetadata.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLMetadata.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLMetadata.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,51 +1,51 @@ -package com.oracle.truffle.api.dsl.internal; - -/** - * This is NOT public API. Do not use directly. This code may change without notice. - */ -public final class DSLMetadata { - - public static final Class[] EMPTY_CLASS_ARRAY = new Class[]{}; - public static final DSLMetadata NONE = new DSLMetadata(null, EMPTY_CLASS_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_CLASS_ARRAY, 0, 0); - - private final Class specializationClass; - private final Class[] includes; - private final Class[] excludedBy; - private final Class[] specializedTypes; - - private final int costs; - private final int order; - - public DSLMetadata(Class specializationClass, Class[] includes, Class[] excludes, Class[] specializedTypes, int costs, int order) { - this.specializationClass = specializationClass; - this.includes = includes; - this.excludedBy = excludes; - this.specializedTypes = specializedTypes; - this.costs = costs; - this.order = order; - } - - public Class getSpecializationClass() { - return specializationClass; - } - - public Class[] getSpecializedTypes() { - return specializedTypes; - } - - Class[] getIncludes() { - return includes; - } - - Class[] getExcludedBy() { - return excludedBy; - } - - int getCosts() { - return costs; - } - - int getOrder() { - return order; - } -} +package com.oracle.truffle.api.dsl.internal; + +/** + * This is NOT public API. Do not use directly. This code may change without notice. + */ +public final class DSLMetadata { + + public static final Class[] EMPTY_CLASS_ARRAY = new Class[]{}; + public static final DSLMetadata NONE = new DSLMetadata(null, EMPTY_CLASS_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_CLASS_ARRAY, 0, 0); + + private final Class specializationClass; + private final Class[] includes; + private final Class[] excludedBy; + private final Class[] specializedTypes; + + private final int costs; + private final int order; + + public DSLMetadata(Class specializationClass, Class[] includes, Class[] excludes, Class[] specializedTypes, int costs, int order) { + this.specializationClass = specializationClass; + this.includes = includes; + this.excludedBy = excludes; + this.specializedTypes = specializedTypes; + this.costs = costs; + this.order = order; + } + + public Class getSpecializationClass() { + return specializationClass; + } + + public Class[] getSpecializedTypes() { + return specializedTypes; + } + + Class[] getIncludes() { + return includes; + } + + Class[] getExcludedBy() { + return excludedBy; + } + + int getCosts() { + return costs; + } + + int getOrder() { + return order; + } +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLNode.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLNode.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLNode.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,18 +1,18 @@ -package com.oracle.truffle.api.dsl.internal; - -import com.oracle.truffle.api.nodes.*; - -/** - * This is NOT public API. Do not use directly. This code may change without notice. - */ -public interface DSLNode { - - DSLMetadata getMetadata0(); - - void adoptChildren0(Node other, Node next); - - void updateTypes0(Class[] types); - - Node getNext0(); - -} +package com.oracle.truffle.api.dsl.internal; + +import com.oracle.truffle.api.nodes.*; + +/** + * This is NOT public API. Do not use directly. This code may change without notice. + */ +public interface DSLNode { + + DSLMetadata getMetadata0(); + + void adoptChildren0(Node other, Node next); + + void updateTypes0(Class[] types); + + Node getNext0(); + +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,176 +1,176 @@ -package com.oracle.truffle.api.dsl.internal; - -import java.util.*; - -import com.oracle.truffle.api.nodes.*; - -/** Contains utility classes shared across generated DSLNode implementations. */ -public class DSLShare { - - public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) { - assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded."; - Node cur = findRoot(currentNode); - while (cur != null) { - Class curClass = cur.getClass(); - if (curClass == otherMetadata.getSpecializationClass()) { - return true; - } else if (containsClass(otherMetadata.getExcludedBy(), cur)) { - return true; - } - cur = getNext(cur); - } - return false; - } - - private static boolean includes(Node oldNode, DSLNode newNode) { - return containsClass(newNode.getMetadata0().getIncludes(), oldNode); - } - - public static T rewrite(Node thisNode, T newNode, String message) { - assert newNode != null; - if (getNext(thisNode) != null || getPrevious(thisNode) != null) { - // already polymorphic -> append - return appendPolymorphic(findUninitialized(thisNode), newNode); - } else if (includes(thisNode, newNode)) { - // included -> remains monomorphic - newNode.adoptChildren0(thisNode, null); - return thisNode.replace(newNode, message); - } else { - // goto polymorphic - return null; - } - } - - @SuppressWarnings("unchecked") - public static T findRoot(T node) { - Node prev = node; - Node cur; - do { - cur = prev; - prev = getPrevious(cur); - } while (prev != null); - return (T) cur; - } - - private static Node findUninitialized(Node node) { - Node next = node; - Node cur; - do { - cur = next; - next = getNext(cur); - } while (next != null); - return cur; - } - - public static T rewriteUninitialized(Node uninitialized, T newNode) { - Node prev = getPrevious(uninitialized); - if (prev == null) { - newNode.adoptChildren0(uninitialized, null); - return uninitialized.replace(newNode, "Uninitialized monomorphic"); - } else { - return appendPolymorphic(uninitialized, newNode); - } - } - - public static T rewriteToPolymorphic(Node oldNode, DSLNode uninitialized, T polymorphic, DSLNode currentCopy, DSLNode newNode, String message) { - assert getNext(oldNode) == null; - assert getPrevious(oldNode) == null; - - polymorphic.adoptChildren0(oldNode, (Node) currentCopy); - - if (newNode == null) { - // fallback - currentCopy.adoptChildren0(null, (Node) uninitialized); - } else { - // new specialization - newNode.adoptChildren0(null, (Node) uninitialized); - currentCopy.adoptChildren0(null, (Node) newNode); - } - - oldNode.replace(polymorphic, message); - - assert polymorphic.getNext0() == currentCopy; - assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; - assert uninitialized.getNext0() == null; - return polymorphic; - } - - private static Class[] mergeTypes(DSLNode node, Class[] types) { - Class[] specializedTypes = node.getMetadata0().getSpecializedTypes(); - if (specializedTypes.length == 0) { - return null; - } else if (types == null) { - return Arrays.copyOf(specializedTypes, specializedTypes.length); - } else { - for (int i = 0; i < specializedTypes.length; i++) { - if (specializedTypes[i] != types[i]) { - types[i] = Object.class; - } - } - return types; - } - } - - private static T appendPolymorphic(Node uninitialized, T newNode) { - Class[] includes = newNode.getMetadata0().getIncludes(); - Node cur = getPrevious(uninitialized); - Node prev = uninitialized; - int depth = 0; - Class[] types = null; - while (cur != null) { - if (containsClass(includes, cur)) { - cur.replace(prev, "Included in other specialization"); - cur = prev; - } else { - depth++; - types = mergeTypes((DSLNode) cur, types); - } - prev = cur; - cur = getPrevious(cur); - } - assert prev.getCost() == NodeCost.POLYMORPHIC; - - if (depth == 0) { - newNode.adoptChildren0(prev, null); - return prev.replace(newNode, "Polymorphic to monomorphic."); - } else { - newNode.adoptChildren0(null, uninitialized); - ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); - return uninitialized.replace(newNode, "Appended polymorphic"); - } - } - - private static boolean containsClass(Class[] classList, Node node) { - Class nodeClass = node.getClass(); - for (Class toCheck : classList) { - if (nodeClass == toCheck) { - if (node.getCost() == NodeCost.UNINITIALIZED) { - /* - * In case a specialization is excluded by the fallback specialization the - * uninitialized class is used as exclusion class. Because the fallback field in - * the uninitialized specialization is not accessible we use the costs to check - * if the fallback was reached or not. In case the fallback was reached in the - * uninitialized version the cost is MONOMORPHIC, otherwise it is UNINITIALIZED. - */ - continue; - } - return true; - } - } - return false; - } - - private static Node getNext(Node node) { - return ((DSLNode) node).getNext0(); - } - - private static Node getPrevious(Node node) { - Node parent = node.getParent(); - if (parent instanceof DSLNode && getNext(parent) == node) { - return parent; - } else { - return null; - } - } - +package com.oracle.truffle.api.dsl.internal; + +import java.util.*; + +import com.oracle.truffle.api.nodes.*; + +/** Contains utility classes shared across generated DSLNode implementations. */ +public class DSLShare { + + public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) { + assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded."; + Node cur = findRoot(currentNode); + while (cur != null) { + Class curClass = cur.getClass(); + if (curClass == otherMetadata.getSpecializationClass()) { + return true; + } else if (containsClass(otherMetadata.getExcludedBy(), cur)) { + return true; + } + cur = getNext(cur); + } + return false; + } + + private static boolean includes(Node oldNode, DSLNode newNode) { + return containsClass(newNode.getMetadata0().getIncludes(), oldNode); + } + + public static T rewrite(Node thisNode, T newNode, String message) { + assert newNode != null; + if (getNext(thisNode) != null || getPrevious(thisNode) != null) { + // already polymorphic -> append + return appendPolymorphic(findUninitialized(thisNode), newNode); + } else if (includes(thisNode, newNode)) { + // included -> remains monomorphic + newNode.adoptChildren0(thisNode, null); + return thisNode.replace(newNode, message); + } else { + // goto polymorphic + return null; + } + } + + @SuppressWarnings("unchecked") + public static T findRoot(T node) { + Node prev = node; + Node cur; + do { + cur = prev; + prev = getPrevious(cur); + } while (prev != null); + return (T) cur; + } + + private static Node findUninitialized(Node node) { + Node next = node; + Node cur; + do { + cur = next; + next = getNext(cur); + } while (next != null); + return cur; + } + + public static T rewriteUninitialized(Node uninitialized, T newNode) { + Node prev = getPrevious(uninitialized); + if (prev == null) { + newNode.adoptChildren0(uninitialized, null); + return uninitialized.replace(newNode, "Uninitialized monomorphic"); + } else { + return appendPolymorphic(uninitialized, newNode); + } + } + + public static T rewriteToPolymorphic(Node oldNode, DSLNode uninitialized, T polymorphic, DSLNode currentCopy, DSLNode newNode, String message) { + assert getNext(oldNode) == null; + assert getPrevious(oldNode) == null; + + polymorphic.adoptChildren0(oldNode, (Node) currentCopy); + + if (newNode == null) { + // fallback + currentCopy.adoptChildren0(null, (Node) uninitialized); + } else { + // new specialization + newNode.adoptChildren0(null, (Node) uninitialized); + currentCopy.adoptChildren0(null, (Node) newNode); + } + + oldNode.replace(polymorphic, message); + + assert polymorphic.getNext0() == currentCopy; + assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; + assert uninitialized.getNext0() == null; + return polymorphic; + } + + private static Class[] mergeTypes(DSLNode node, Class[] types) { + Class[] specializedTypes = node.getMetadata0().getSpecializedTypes(); + if (specializedTypes.length == 0) { + return null; + } else if (types == null) { + return Arrays.copyOf(specializedTypes, specializedTypes.length); + } else { + for (int i = 0; i < specializedTypes.length; i++) { + if (specializedTypes[i] != types[i]) { + types[i] = Object.class; + } + } + return types; + } + } + + private static T appendPolymorphic(Node uninitialized, T newNode) { + Class[] includes = newNode.getMetadata0().getIncludes(); + Node cur = getPrevious(uninitialized); + Node prev = uninitialized; + int depth = 0; + Class[] types = null; + while (cur != null) { + if (containsClass(includes, cur)) { + cur.replace(prev, "Included in other specialization"); + cur = prev; + } else { + depth++; + types = mergeTypes((DSLNode) cur, types); + } + prev = cur; + cur = getPrevious(cur); + } + assert prev.getCost() == NodeCost.POLYMORPHIC; + + if (depth == 0) { + newNode.adoptChildren0(prev, null); + return prev.replace(newNode, "Polymorphic to monomorphic."); + } else { + newNode.adoptChildren0(null, uninitialized); + ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); + return uninitialized.replace(newNode, "Appended polymorphic"); + } + } + + private static boolean containsClass(Class[] classList, Node node) { + Class nodeClass = node.getClass(); + for (Class toCheck : classList) { + if (nodeClass == toCheck) { + if (node.getCost() == NodeCost.UNINITIALIZED) { + /* + * In case a specialization is excluded by the fallback specialization the + * uninitialized class is used as exclusion class. Because the fallback field in + * the uninitialized specialization is not accessible we use the costs to check + * if the fallback was reached or not. In case the fallback was reached in the + * uninitialized version the cost is MONOMORPHIC, otherwise it is UNINITIALIZED. + */ + continue; + } + return true; + } + } + return false; + } + + private static Node getNext(Node node) { + return ((DSLNode) node).getNext0(); + } + + private static Node getPrevious(Node node) { + Node parent = node.getParent(); + if (parent instanceof DSLNode && getNext(parent) == node) { + return parent; + } else { + return null; + } + } + } \ No newline at end of file diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/NodeFactoryBase.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/NodeFactoryBase.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/NodeFactoryBase.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,42 +1,42 @@ -package com.oracle.truffle.api.dsl.internal; - -import java.util.*; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.nodes.*; - -/** - * This is NOT public API. Do not use directly. This code may change without notice. - */ -public abstract class NodeFactoryBase implements NodeFactory { - - private final Class nodeClass; - private final Class[][] nodeSignatures; - private final Class[] executionSignatures; - - @SuppressWarnings("unchecked") - public NodeFactoryBase(Class nodeClass, Class[] executionSignatures, Class[][] nodeSignatures) { - this.nodeClass = nodeClass; - this.nodeSignatures = nodeSignatures; - this.executionSignatures = (Class[]) executionSignatures; - } - - public abstract T createNode(Object... arguments); - - public final Class getNodeClass() { - return nodeClass; - } - - public final List>> getNodeSignatures() { - List>> signatures = new ArrayList<>(); - for (int i = 0; i < nodeSignatures.length; i++) { - signatures.add(Arrays.asList(nodeSignatures[i])); - } - return signatures; - } - - public final List> getExecutionSignature() { - return Arrays.asList(executionSignatures); - } - -} +package com.oracle.truffle.api.dsl.internal; + +import java.util.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; + +/** + * This is NOT public API. Do not use directly. This code may change without notice. + */ +public abstract class NodeFactoryBase implements NodeFactory { + + private final Class nodeClass; + private final Class[][] nodeSignatures; + private final Class[] executionSignatures; + + @SuppressWarnings("unchecked") + public NodeFactoryBase(Class nodeClass, Class[] executionSignatures, Class[][] nodeSignatures) { + this.nodeClass = nodeClass; + this.nodeSignatures = nodeSignatures; + this.executionSignatures = (Class[]) executionSignatures; + } + + public abstract T createNode(Object... arguments); + + public final Class getNodeClass() { + return nodeClass; + } + + public final List>> getNodeSignatures() { + List>> signatures = new ArrayList<>(); + for (int i = 0; i < nodeSignatures.length; i++) { + signatures.add(Arrays.asList(nodeSignatures[i])); + } + return signatures; + } + + public final List> getExecutionSignature() { + return Arrays.asList(executionSignatures); + } + +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeCodeGenerator.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeCodeGenerator.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeCodeGenerator.java Mon Aug 11 16:21:54 2014 +0200 @@ -322,12 +322,12 @@ /** *
      * variant1 $condition != null
-     * 
+     *
      * $type $name = defaultValue($type);
      * if ($condition) {
      *     $name = $value;
      * }
-     * 
+     *
      * variant2 $condition != null
      * $type $name = $value;
      * 
@@ -545,9 +545,6 @@ clazz.setSuperClass(nodeFactory); clazz.add(createNodeFactoryConstructor(node)); clazz.add(createCreateNodeMethod(node)); -// clazz.add(createGetNodeClassMethod(node)); -// clazz.add(createGetNodeSignaturesMethod()); -// clazz.add(createGetChildrenSignatureMethod(node)); clazz.add(createGetInstanceMethod(node, createVisibility)); clazz.add(createInstanceConstant(node, clazz.asType())); } diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedPackageElement.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedPackageElement.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedPackageElement.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,79 +1,79 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.dsl.processor.java.model; - -import javax.lang.model.element.*; -import javax.lang.model.type.*; - -public final class GeneratedPackageElement extends CodeElement implements PackageElement { - - private final Name qualifiedName; - private final Name simpleName; - - public GeneratedPackageElement(String qualifiedName) { - this.qualifiedName = CodeNames.of(qualifiedName); - int lastIndex = qualifiedName.lastIndexOf('.'); - if (lastIndex == -1) { - simpleName = CodeNames.of(""); - } else { - simpleName = CodeNames.of(qualifiedName.substring(lastIndex, qualifiedName.length())); - } - } - - public TypeMirror asType() { - throw new UnsupportedOperationException(); - } - - public ElementKind getKind() { - return ElementKind.PACKAGE; - } - - public R accept(ElementVisitor v, P p) { - return v.visitPackage(this, p); - } - - public Name getQualifiedName() { - return qualifiedName; - } - - public Name getSimpleName() { - return simpleName; - } - - public boolean isUnnamed() { - return simpleName.toString().equals(""); - } - - @Override - public int hashCode() { - return qualifiedName.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof PackageElement) { - return qualifiedName.equals(((PackageElement) obj).getQualifiedName()); - } - return super.equals(obj); - } +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.dsl.processor.java.model; + +import javax.lang.model.element.*; +import javax.lang.model.type.*; + +public final class GeneratedPackageElement extends CodeElement implements PackageElement { + + private final Name qualifiedName; + private final Name simpleName; + + public GeneratedPackageElement(String qualifiedName) { + this.qualifiedName = CodeNames.of(qualifiedName); + int lastIndex = qualifiedName.lastIndexOf('.'); + if (lastIndex == -1) { + simpleName = CodeNames.of(""); + } else { + simpleName = CodeNames.of(qualifiedName.substring(lastIndex, qualifiedName.length())); + } + } + + public TypeMirror asType() { + throw new UnsupportedOperationException(); + } + + public ElementKind getKind() { + return ElementKind.PACKAGE; + } + + public R accept(ElementVisitor v, P p) { + return v.visitPackage(this, p); + } + + public Name getQualifiedName() { + return qualifiedName; + } + + public Name getSimpleName() { + return simpleName; + } + + public boolean isUnnamed() { + return simpleName.toString().equals(""); + } + + @Override + public int hashCode() { + return qualifiedName.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof PackageElement) { + return qualifiedName.equals(((PackageElement) obj).getQualifiedName()); + } + return super.equals(obj); + } } \ No newline at end of file diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeElement.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeElement.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeElement.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.dsl.processor.java.model; - -import java.util.*; - -import javax.lang.model.element.*; - -public final class GeneratedTypeElement extends CodeTypeElement { - - public GeneratedTypeElement(Set modifiers, ElementKind kind, PackageElement packageElement, String simpleName) { - super(modifiers, kind, packageElement, simpleName); - setEnclosingElement(packageElement); - } - +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.dsl.processor.java.model; + +import java.util.*; + +import javax.lang.model.element.*; + +public final class GeneratedTypeElement extends CodeTypeElement { + + public GeneratedTypeElement(Set modifiers, ElementKind kind, PackageElement packageElement, String simpleName) { + super(modifiers, kind, packageElement, simpleName); + setEnclosingElement(packageElement); + } + } \ No newline at end of file diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeMirror.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeMirror.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/GeneratedTypeMirror.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.dsl.processor.java.model; - -import java.util.*; - -import javax.lang.model.element.*; - -import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror; - -public final class GeneratedTypeMirror extends DeclaredCodeTypeMirror { - - public GeneratedTypeMirror(String packageName, String name) { - super(new GeneratedTypeElement(Collections. emptySet(), ElementKind.CLASS, new GeneratedPackageElement(packageName), name)); - } - +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.dsl.processor.java.model; + +import java.util.*; + +import javax.lang.model.element.*; + +import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror; + +public final class GeneratedTypeMirror extends DeclaredCodeTypeMirror { + + public GeneratedTypeMirror(String packageName, String name) { + super(new GeneratedTypeElement(Collections. emptySet(), ElementKind.CLASS, new GeneratedPackageElement(packageName), name)); + } + } \ No newline at end of file diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java Mon Aug 11 16:21:54 2014 +0200 @@ -1,87 +1,87 @@ -package com.oracle.truffle.dsl.processor.model; - -import java.util.*; - -public final class GuardExpression { - - private GuardData resolvedGuard; - - private final String guardName; - private final boolean negated; - - public GuardExpression(String expression) { - if (expression.startsWith("!")) { - guardName = expression.substring(1, expression.length()); - negated = true; - } else { - guardName = expression; - negated = false; - } - } - - public boolean isResolved() { - return resolvedGuard != null; - } - - public String getGuardName() { - return guardName; - } - - public void setGuard(GuardData guard) { - this.resolvedGuard = guard; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof GuardExpression) { - GuardExpression other = (GuardExpression) obj; - if (isResolved() && other.isResolved()) { - return resolvedGuard.equals(other.resolvedGuard) && negated == other.negated; - } else { - return guardName.equals(other.guardName) && negated == other.negated; - } - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(guardName, negated, resolvedGuard); - } - - public final boolean implies(GuardExpression other) { - if (other == this) { - return true; - } - if (getGuardName().equals(other.getGuardName())) { - if (isNegated() == other.isNegated()) { - return true; - } - } - - if (isResolved() && other.isResolved()) { - for (GuardExpression implies : getResolvedGuard().getImpliesExpressions()) { - if (implies.getGuardName().equals(other.getGuardName())) { - if (implies.isNegated() == other.isNegated()) { - return true; - } - } - } - } - return false; - } - - @Override - public String toString() { - return (negated ? "!" : "") + guardName; - } - - public boolean isNegated() { - return negated; - } - - public GuardData getResolvedGuard() { - return resolvedGuard; - } - -} +package com.oracle.truffle.dsl.processor.model; + +import java.util.*; + +public final class GuardExpression { + + private GuardData resolvedGuard; + + private final String guardName; + private final boolean negated; + + public GuardExpression(String expression) { + if (expression.startsWith("!")) { + guardName = expression.substring(1, expression.length()); + negated = true; + } else { + guardName = expression; + negated = false; + } + } + + public boolean isResolved() { + return resolvedGuard != null; + } + + public String getGuardName() { + return guardName; + } + + public void setGuard(GuardData guard) { + this.resolvedGuard = guard; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof GuardExpression) { + GuardExpression other = (GuardExpression) obj; + if (isResolved() && other.isResolved()) { + return resolvedGuard.equals(other.resolvedGuard) && negated == other.negated; + } else { + return guardName.equals(other.guardName) && negated == other.negated; + } + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(guardName, negated, resolvedGuard); + } + + public final boolean implies(GuardExpression other) { + if (other == this) { + return true; + } + if (getGuardName().equals(other.getGuardName())) { + if (isNegated() == other.isNegated()) { + return true; + } + } + + if (isResolved() && other.isResolved()) { + for (GuardExpression implies : getResolvedGuard().getImpliesExpressions()) { + if (implies.getGuardName().equals(other.getGuardName())) { + if (implies.isNegated() == other.isNegated()) { + return true; + } + } + } + } + return false; + } + + @Override + public String toString() { + return (negated ? "!" : "") + guardName; + } + + public boolean isNegated() { + return negated; + } + + public GuardData getResolvedGuard() { + return resolvedGuard; + } + +} diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ImplicitCastData.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ImplicitCastData.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/ImplicitCastData.java Mon Aug 11 16:21:54 2014 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.truffle.dsl.processor.model; - public class ImplicitCastData extends TemplateMethod { private final TypeData sourceType; diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCastData.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCastData.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCastData.java Mon Aug 11 16:21:54 2014 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.truffle.dsl.processor.model; - public class TypeCastData extends TemplateMethod { private final TypeData targetType; diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCheckData.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCheckData.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeCheckData.java Mon Aug 11 16:21:54 2014 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.truffle.dsl.processor.model; - public class TypeCheckData extends TemplateMethod { private final TypeData checkedType; diff -r ea9903f9684f -r e6d15134ca86 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Mon Aug 11 15:57:47 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Mon Aug 11 16:21:54 2014 +0200 @@ -209,7 +209,8 @@ TypeData typeData = types.get(i); TypeMirror type = typeData.getBoxedType(); if (invalidTypes.containsKey(ElementUtils.getQualifiedName(type))) { - typeData.addError("Invalid type order. The type(s) %s are inherited from a earlier defined type %s.", invalidTypes.get(ElementUtils.getQualifiedName(type)), ElementUtils.getQualifiedName(type)); + typeData.addError("Invalid type order. The type(s) %s are inherited from a earlier defined type %s.", invalidTypes.get(ElementUtils.getQualifiedName(type)), + ElementUtils.getQualifiedName(type)); } List nextInvalidTypes = ElementUtils.getQualifiedSuperTypeNames(ElementUtils.fromTypeMirror(type)); nextInvalidTypes.add(getQualifiedName(type));