# HG changeset patch # User Christian Humer # Date 1407767860 -7200 # Node ID f9fff060dc41d5f0669e979580394ffb9fb68fd6 # Parent e6d15134ca86a5dfab5957f5959e2d201d6fd3b4 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive. diff -r e6d15134ca86 -r f9fff060dc41 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/InsertBeforeTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/InsertBeforeTest.java Mon Aug 11 16:21:54 2014 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/InsertBeforeTest.java Mon Aug 11 16:37:40 2014 +0200 @@ -120,6 +120,34 @@ } @NodeChild("a") + static class InsertBefore1T6_1 extends InsertBefore1Base { + + boolean g0(int a) { + return a == 0; + } + + @Specialization(insertBefore = "f1", guards = "g0") + int f0(int a) { + return a; + } + + } + + @NodeChild("a") + static class InsertBefore1T6_2 extends InsertBefore1T6_1 { + + boolean g(int a) { + return a == 0; + } + + @Specialization(insertBefore = "f0", guards = "g") + int f(int a) { + return a; + } + + } + + @NodeChild("a") static class InsertBefore1Error1 extends InsertBefore1Base { @ExpectError("Specializations can only be inserted before specializations in superclasses.") diff -r e6d15134ca86 -r f9fff060dc41 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java Mon Aug 11 16:21:54 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java Mon Aug 11 16:37:40 2014 +0200 @@ -580,21 +580,14 @@ specialization.setInsertBefore(found); } - int endIndex = specializations.size() - 1; - for (int i = endIndex; i >= 0; i--) { + for (int i = 0; i < specializations.size(); i++) { SpecializationData specialization = specializations.get(i); - if (specialization.isGeneric() || specialization.isPolymorphic()) { - endIndex--; - continue; - } - SpecializationData insertBefore = specialization.getInsertBefore(); if (insertBefore != null) { int insertIndex = specializations.indexOf(insertBefore); if (insertIndex < i) { - List range = new ArrayList<>(specializations.subList(i, endIndex + 1)); - specializations.removeAll(range); - specializations.addAll(insertIndex, range); + specializations.remove(i); + specializations.add(insertIndex, specialization); } } }