diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 2cc793326..4cd7f3f43 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -131,7 +131,7 @@ public class ATNConfigSet implements Set { // a previous (s,i,pi,_), merge with it and save result boolean rootIsWildcard = !fullCtx; PredictionContext merged = - PredictionContext.merge(existing.context, config.context, rootIsWildcard); + PredictionContext.merge(existing.context, config.context, contextCache, rootIsWildcard); // no need to check for existing.context, config.context in cache // since only way to create new graphs is "call rule" and here. We // cache at both places. diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ArrayPredictionContext.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ArrayPredictionContext.java index 3b3affcd8..adedf8602 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ArrayPredictionContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ArrayPredictionContext.java @@ -1,5 +1,7 @@ package org.antlr.v4.runtime.atn; +import org.antlr.v4.runtime.misc.NotNull; + import java.util.Arrays; import java.util.Iterator; @@ -123,13 +125,17 @@ public class ArrayPredictionContext extends PredictionContext { * elements from this context and merge into new context. */ @Override - public PredictionContext popAll(int invokingState, boolean fullCtx) { + public PredictionContext popAll(int invokingState, + @NotNull PredictionContextCache contextCache, + boolean fullCtx) + { int index = Arrays.binarySearch(this.invokingStates, invokingState); if ( index < 0 ) { return this; } - PredictionContext newCtx = this.parents[index].popAll(invokingState, fullCtx); + PredictionContext newCtx = + this.parents[index].popAll(invokingState, contextCache, fullCtx); for (int i = 0; i < this.invokingStates.length; i++) { if (i == index) continue; PredictionContext next; @@ -141,7 +147,7 @@ public class ArrayPredictionContext extends PredictionContext { this.invokingStates[i]); } boolean rootIsWildcard = fullCtx; - newCtx = merge(newCtx, next, rootIsWildcard); + newCtx = merge(newCtx, next, contextCache, rootIsWildcard); } return newCtx; diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 8a1d97154..00fbf55e0 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -241,7 +241,7 @@ import java.util.Set; */ public class ParserATNSimulator extends ATNSimulator { public static boolean debug = false; - public static boolean debug_list_atn_decisions = true; + public static boolean debug_list_atn_decisions = false; public static boolean dfa_debug = false; public static boolean retry_debug = false; @@ -378,6 +378,7 @@ public class ParserATNSimulator extends ATNSimulator { if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s); boolean loopsSimulateTailRecursion = true; boolean fullCtx = false; + contextCache = new PredictionContextCache("predict ctx cache built in execDFA"); ATNConfigSet s0_closure = computeStartState(dfa.atnStartState, outerContext, greedy, loopsSimulateTailRecursion, @@ -388,6 +389,7 @@ public class ParserATNSimulator extends ATNSimulator { outerContext, decState.getNumberOfTransitions(), greedy); + contextCache = null; return fullCtxSet.uniqueAlt; } if ( s.isAcceptState ) { @@ -419,7 +421,9 @@ public class ParserATNSimulator extends ATNSimulator { " at DFA state "+s.stateNumber); } + contextCache = new PredictionContextCache("predict ctx cache built in execDFA"); alt = execATN(dfa, s, input, startIndex, outerContext); + contextCache = null; // this adds edge even if next state is accept for // same alt; e.g., s0-A->:s1=>2-B->:s2=>2 // TODO: This next stuff kills edge, but extra states remain. :( @@ -942,7 +946,7 @@ public class ParserATNSimulator extends ATNSimulator { boolean collectPredicates, boolean greedy, boolean loopsSimulateTailRecursion) { -// System.out.println(PredictionContext.toDotString(config.context)); +// System.out.println(PredictionContext.toDOTString(config.context)); final int initialDepth = 0; closureCheckingStopStateAndLoopRecursion(config, configs, closureBusy, collectPredicates, greedy, @@ -1017,7 +1021,9 @@ public class ParserATNSimulator extends ATNSimulator { if ( debug ) System.out.print("Loop end; pop, stack=" + config.context); LoopEndState end = (LoopEndState)config.state; // pop all the way back until we don't see the loopback state anymore - config.context = config.context.popAll(end.loopBackStateNumber, configs.fullCtx); + config.context = config.context.popAll(end.loopBackStateNumber, + contextCache, + configs.fullCtx); if ( debug ) System.out.println(" becomes "+config.context); } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java index ff8e6efc6..7100361f0 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java @@ -7,13 +7,16 @@ import org.antlr.v4.runtime.misc.Nullable; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -public abstract class PredictionContext implements Iterable { +public abstract class PredictionContext implements Iterable, + Comparable // to sort node lists by id +{ /** Represents $ in local ctx prediction, which means wildcard. *+x = *. */ public static final EmptyPredictionContext EMPTY = new EmptyPredictionContext(); @@ -68,7 +71,14 @@ public abstract class PredictionContext implements Iterable M @@ -252,7 +276,8 @@ public abstract class PredictionContext implements Iterable a'[x,y] - PredictionContext mergedParent = merge(a_parent, b_parent, rootIsWildcard); + PredictionContext mergedParent = + merge(a_parent, b_parent, contextCache, rootIsWildcard); mergedParents[k] = mergedParent; mergedInvokingStates[k] = payload; } @@ -298,16 +323,19 @@ public abstract class PredictionContext implements Iterable nodes = getAllContextNodes(context); + Collections.sort(nodes); for (PredictionContext current : nodes) { if ( current instanceof SingletonPredictionContext ) { @@ -476,7 +505,7 @@ public abstract class PredictionContext implements Iterable getAllContextNodes(PredictionContext context) { List nodes = new ArrayList(); Map visited = - new IdentityHashMap(); + new IdentityHashMap(); getAllContextNodes_(context, nodes, visited); return nodes; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java index af166c51b..0b12e9888 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java @@ -24,7 +24,7 @@ public class PredictionContextCache { if ( ctx==PredictionContext.EMPTY ) return PredictionContext.EMPTY; PredictionContext existing = cache.get(ctx); if ( existing!=null ) { - System.out.println(name+" reuses "+existing); +// System.out.println(name+" reuses "+existing); return existing; } cache.put(ctx, ctx); diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/SingletonPredictionContext.java b/runtime/Java/src/org/antlr/v4/runtime/atn/SingletonPredictionContext.java index 293ac3840..a55c629fc 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/SingletonPredictionContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/SingletonPredictionContext.java @@ -1,5 +1,7 @@ package org.antlr.v4.runtime.atn; +import org.antlr.v4.runtime.misc.NotNull; + import java.util.Iterator; public class SingletonPredictionContext extends PredictionContext { @@ -49,9 +51,12 @@ public class SingletonPredictionContext extends PredictionContext { } @Override - public PredictionContext popAll(int invokingState, boolean fullCtx) { + public PredictionContext popAll(int invokingState, + @NotNull PredictionContextCache contextCache, + boolean fullCtx) + { if ( invokingState == this.invokingState ) { - return parent.popAll(invokingState, fullCtx); + return parent.popAll(invokingState, contextCache, fullCtx); } return this; } diff --git a/tool/playground/Bar.java b/tool/playground/Bar.java new file mode 100644 index 000000000..a9d19585d --- /dev/null +++ b/tool/playground/Bar.java @@ -0,0 +1,11 @@ +class Bar { + private int bitsOrSingle(int bits, int ch) { + boolean d = + !(3==4 && + (ch == 0xff || ch == 0xb5 || +// ch == 0x53 || ch == 0x73 || +// ch == 0x4b || ch == 0x6b || + ch == 0xc5 || ch == 0xe5)); + return 9; + } +} diff --git a/tool/test/org/antlr/v4/test/TestGraphNodes.java b/tool/test/org/antlr/v4/test/TestGraphNodes.java index 0015b95f3..a6c2c3bfc 100644 --- a/tool/test/org/antlr/v4/test/TestGraphNodes.java +++ b/tool/test/org/antlr/v4/test/TestGraphNodes.java @@ -3,13 +3,17 @@ package org.antlr.v4.test; import junit.framework.TestCase; import org.antlr.v4.runtime.atn.ArrayPredictionContext; import org.antlr.v4.runtime.atn.PredictionContext; +import org.antlr.v4.runtime.atn.PredictionContextCache; import org.antlr.v4.runtime.atn.SingletonPredictionContext; import org.junit.Test; public class TestGraphNodes extends TestCase { + PredictionContextCache contextCache; + @Override protected void setUp() throws Exception { PredictionContext.globalNodeCount = 1; + contextCache = new PredictionContextCache("testing"); } public boolean rootIsWildcard() { return true; } @@ -18,188 +22,190 @@ public class TestGraphNodes extends TestCase { @Test public void test_$_$() { PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, PredictionContext.EMPTY, + contextCache, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + " s0 [label=\"$\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_$_$_fullctx() { PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, PredictionContext.EMPTY, + contextCache, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + " s0 [label=\"$\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_x_$() { - PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + " s0 [label=\"$\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_x_$_fullctx() { - PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s2 [shape=box, label=\"[$, 9]\"];\n" + " s0 [label=\"$\"];\n" + + " s2 [shape=box, label=\"[$, 9]\"];\n" + " s2->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_$_x() { - PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + " s0 [label=\"$\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_$_x_fullctx() { - PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s2 [shape=box, label=\"[$, 9]\"];\n" + " s0 [label=\"$\"];\n" + + " s2 [shape=box, label=\"[$, 9]\"];\n" + " s2->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a_a() { - PredictionContext r = PredictionContext.merge(a(), a(), rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a(), a(), contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s1 [label=\"1\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"1\"];\n" + " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a$_ax() { PredictionContext a1 = a(); PredictionContext x = x(); PredictionContext a2 = createSingleton(x, 1); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s1 [label=\"1\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"1\"];\n" + " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a$_ax_fullctx() { PredictionContext a1 = a(); PredictionContext x = x(); PredictionContext a2 = createSingleton(x, 1); - PredictionContext r = PredictionContext.merge(a1, a2, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s5 [label=\"1\"];\n" + - " s4 [shape=box, label=\"[$, 9]\"];\n" + " s0 [label=\"$\"];\n" + - " s5->s4;\n" + + " s4 [shape=box, label=\"[$, 9]\"];\n" + + " s5 [label=\"1\"];\n" + " s4->s0 [label=\"parent[1]\"];\n" + + " s5->s4;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax$_a$() { PredictionContext x = x(); PredictionContext a1 = createSingleton(x, 1); PredictionContext a2 = a(); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [label=\"1\"];\n" + " s0 [label=\"$\"];\n" + + " s3 [label=\"1\"];\n" + " s3->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax$_a$_fullctx() { PredictionContext x = x(); PredictionContext a1 = createSingleton(x, 1); PredictionContext a2 = a(); - PredictionContext r = PredictionContext.merge(a1, a2, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s5 [label=\"1\"];\n" + - " s4 [shape=box, label=\"[$, 9]\"];\n" + " s0 [label=\"$\"];\n" + - " s5->s4;\n" + + " s4 [shape=box, label=\"[$, 9]\"];\n" + + " s5 [label=\"1\"];\n" + " s4->s0 [label=\"parent[1]\"];\n" + + " s5->s4;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a_b() { - PredictionContext r = PredictionContext.merge(a(), b(), rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a(), b(), contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [shape=box, label=\"[1, 2]\"];\n" + " s0 [label=\"$\"];\n" + + " s3 [shape=box, label=\"[1, 2]\"];\n" + " s3->s0 [label=\"parent[0]\"];\n" + " s3->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax_ax_same() { PredictionContext x = x(); PredictionContext a1 = createSingleton(x, 1); PredictionContext a2 = createSingleton(x, 1); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s2 [label=\"1\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s2->s1;\n" + + " s1 [label=\"9\"];\n" + + " s2 [label=\"1\"];\n" + " s1->s0;\n" + + " s2->s1;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax_ax() { @@ -207,18 +213,18 @@ public class TestGraphNodes extends TestCase { PredictionContext x2 = x(); PredictionContext a1 = createSingleton(x1, 1); PredictionContext a2 = createSingleton(x2, 1); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [label=\"1\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s3->s1;\n" + + " s1 [label=\"9\"];\n" + + " s3 [label=\"1\"];\n" + " s1->s0;\n" + + " s3->s1;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_abx_abx() { @@ -228,20 +234,20 @@ public class TestGraphNodes extends TestCase { PredictionContext b2 = createSingleton(x2, 2); PredictionContext a1 = createSingleton(b1, 1); PredictionContext a2 = createSingleton(b2, 1); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s5 [label=\"1\"];\n" + - " s3 [label=\"2\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s5->s3;\n" + - " s3->s1;\n" + + " s1 [label=\"9\"];\n" + + " s3 [label=\"2\"];\n" + + " s5 [label=\"1\"];\n" + " s1->s0;\n" + + " s3->s1;\n" + + " s5->s3;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_abx_acx() { @@ -251,40 +257,40 @@ public class TestGraphNodes extends TestCase { PredictionContext c = createSingleton(x2, 3); PredictionContext a1 = createSingleton(b, 1); PredictionContext a2 = createSingleton(c, 1); - PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a1, a2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s8 [label=\"1\"];\n" + - " s7 [shape=box, label=\"[2, 3]\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s8->s7;\n" + + " s1 [label=\"9\"];\n" + + " s7 [shape=box, label=\"[2, 3]\"];\n" + + " s8 [label=\"1\"];\n" + + " s1->s0;\n" + " s7->s1 [label=\"parent[0]\"];\n" + " s7->s1 [label=\"parent[1]\"];\n" + - " s1->s0;\n" + + " s8->s7;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax_bx_same() { PredictionContext x = x(); PredictionContext a = createSingleton(x, 1); PredictionContext b = createSingleton(x, 2); - PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s4 [shape=box, label=\"[1, 2]\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"9\"];\n" + + " s4 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + " s4->s1 [label=\"parent[0]\"];\n" + " s4->s1 [label=\"parent[1]\"];\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax_bx() { @@ -292,75 +298,75 @@ public class TestGraphNodes extends TestCase { PredictionContext x2 = x(); PredictionContext a = createSingleton(x1, 1); PredictionContext b = createSingleton(x2, 2); - PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s5 [shape=box, label=\"[1, 2]\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"9\"];\n" + + " s5 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + " s5->s1 [label=\"parent[0]\"];\n" + " s5->s1 [label=\"parent[1]\"];\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_ax_by() { PredictionContext a = createSingleton(x(), 1); PredictionContext b = createSingleton(y(), 2); - PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s5 [shape=box, label=\"[1, 2]\"];\n" + - " s3 [label=\"10\"];\n" + " s0 [label=\"$\"];\n" + " s1 [label=\"9\"];\n" + + " s3 [label=\"10\"];\n" + + " s5 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + + " s3->s0;\n" + " s5->s1 [label=\"parent[0]\"];\n" + " s5->s3 [label=\"parent[1]\"];\n" + - " s3->s0;\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a$_bx() { PredictionContext x2 = x(); PredictionContext a = a(); PredictionContext b = createSingleton(x2, 2); - PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s4 [shape=box, label=\"[1, 2]\"];\n" + " s0 [label=\"$\"];\n" + + " s4 [shape=box, label=\"[1, 2]\"];\n" + " s4->s0 [label=\"parent[0]\"];\n" + " s4->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_a$_bx_fullctx() { PredictionContext x2 = x(); PredictionContext a = a(); PredictionContext b = createSingleton(x2, 2); - PredictionContext r = PredictionContext.merge(a, b, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s4 [shape=box, label=\"[1, 2]\"];\n" + - " s1 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"9\"];\n" + + " s4 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + " s4->s0 [label=\"parent[0]\"];\n" + " s4->s1 [label=\"parent[1]\"];\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_aex_bfx() { @@ -370,25 +376,25 @@ public class TestGraphNodes extends TestCase { PredictionContext f = createSingleton(x2, 6); PredictionContext a = createSingleton(e, 1); PredictionContext b = createSingleton(f, 2); - PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(a, b, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s7 [shape=box, label=\"[1, 2]\"];\n" + - " s4 [label=\"6\"];\n" + - " s2 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s3 [label=\"5\"];\n" + " s1 [label=\"9\"];\n" + - " s7->s3 [label=\"parent[0]\"];\n" + - " s7->s4 [label=\"parent[1]\"];\n" + - " s4->s2;\n" + + " s2 [label=\"9\"];\n" + + " s3 [label=\"5\"];\n" + + " s4 [label=\"6\"];\n" + + " s7 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + " s2->s0;\n" + " s3->s1;\n" + - " s1->s0;\n" + + " s4->s2;\n" + + " s7->s3 [label=\"parent[0]\"];\n" + + " s7->s4 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } // Array merges @@ -396,14 +402,14 @@ public class TestGraphNodes extends TestCase { @Test public void test_A$_A$_fullctx() { ArrayPredictionContext A1 = array(PredictionContext.EMPTY); ArrayPredictionContext A2 = array(PredictionContext.EMPTY); - PredictionContext r = PredictionContext.merge(A1, A2, fullCtx()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, fullCtx()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + " s1 [shape=box, label=\"[-2]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aab_Ac() { // a,b + c @@ -412,18 +418,18 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext c = c(); ArrayPredictionContext A1 = array(a, b); ArrayPredictionContext A2 = array(c); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s0 [label=\"$\"];\n" + + " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s6->s0 [label=\"parent[0]\"];\n" + " s6->s0 [label=\"parent[1]\"];\n" + " s6->s0 [label=\"parent[2]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aa_Aa() { @@ -431,16 +437,16 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext a2 = a(); ArrayPredictionContext A1 = array(a1); ArrayPredictionContext A2 = array(a2); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [shape=box, label=\"[1]\"];\n" + " s0 [label=\"$\"];\n" + + " s3 [shape=box, label=\"[1]\"];\n" + " s3->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aa_Abc() { // a + b,c @@ -449,18 +455,18 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext c = c(); ArrayPredictionContext A1 = array(a); ArrayPredictionContext A2 = array(b, c); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s0 [label=\"$\"];\n" + + " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s6->s0 [label=\"parent[0]\"];\n" + " s6->s0 [label=\"parent[1]\"];\n" + " s6->s0 [label=\"parent[2]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aac_Ab() { // a,c + b @@ -469,50 +475,50 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext c = c(); ArrayPredictionContext A1 = array(a, c); ArrayPredictionContext A2 = array(b); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s0 [label=\"$\"];\n" + + " s6 [shape=box, label=\"[1, 2, 3]\"];\n" + " s6->s0 [label=\"parent[0]\"];\n" + " s6->s0 [label=\"parent[1]\"];\n" + " s6->s0 [label=\"parent[2]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aab_Aa() { // a,b + a ArrayPredictionContext A1 = array(a(), b()); ArrayPredictionContext A2 = array(a()); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [shape=box, label=\"[1, 2]\"];\n" + " s0 [label=\"$\"];\n" + + " s3 [shape=box, label=\"[1, 2]\"];\n" + " s3->s0 [label=\"parent[0]\"];\n" + " s3->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aab_Ab() { // a,b + b ArrayPredictionContext A1 = array(a(), b()); ArrayPredictionContext A2 = array(b()); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s3 [shape=box, label=\"[1, 2]\"];\n" + " s0 [label=\"$\"];\n" + + " s3 [shape=box, label=\"[1, 2]\"];\n" + " s3->s0 [label=\"parent[0]\"];\n" + " s3->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aax_Aby() { // ax + by but in arrays @@ -520,21 +526,21 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext b = createSingleton(y(), 2); ArrayPredictionContext A1 = array(a); ArrayPredictionContext A2 = array(b); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s7 [shape=box, label=\"[1, 2]\"];\n" + - " s3 [label=\"10\"];\n" + " s0 [label=\"$\"];\n" + " s1 [label=\"9\"];\n" + + " s3 [label=\"10\"];\n" + + " s7 [shape=box, label=\"[1, 2]\"];\n" + + " s1->s0;\n" + + " s3->s0;\n" + " s7->s1 [label=\"parent[0]\"];\n" + " s7->s3 [label=\"parent[1]\"];\n" + - " s3->s0;\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aax_Aay() { // ax + ay -> merged singleton a, array parent @@ -542,19 +548,19 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext a2 = createSingleton(y(), 1); ArrayPredictionContext A1 = array(a1); ArrayPredictionContext A2 = array(a2); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s8 [label=\"1\"];\n" + - " s7 [shape=box, label=\"[9, 10]\"];\n" + " s0 [label=\"$\"];\n" + - " s8->s7;\n" + + " s7 [shape=box, label=\"[9, 10]\"];\n" + + " s8 [label=\"1\"];\n" + " s7->s0 [label=\"parent[0]\"];\n" + " s7->s0 [label=\"parent[1]\"];\n" + + " s8->s7;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaxc_Aayd() { // ax,c + ay,d -> merged a, array parent @@ -562,21 +568,21 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext a2 = createSingleton(y(), 1); ArrayPredictionContext A1 = array(a1, c()); ArrayPredictionContext A2 = array(a2, d()); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s10 [shape=box, label=\"[1, 3, 4]\"];\n" + " s0 [label=\"$\"];\n" + " s9 [shape=box, label=\"[9, 10]\"];\n" + + " s10 [shape=box, label=\"[1, 3, 4]\"];\n" + + " s9->s0 [label=\"parent[0]\"];\n" + + " s9->s0 [label=\"parent[1]\"];\n" + " s10->s9 [label=\"parent[0]\"];\n" + " s10->s0 [label=\"parent[1]\"];\n" + " s10->s0 [label=\"parent[2]\"];\n" + - " s9->s0 [label=\"parent[0]\"];\n" + - " s9->s0 [label=\"parent[1]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaubv_Acwdx() { // au,bv + cw,dx -> [a,b,c,d]->[u,v,w,x] @@ -586,27 +592,27 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext d = createSingleton(x(), 4); ArrayPredictionContext A1 = array(a, b); ArrayPredictionContext A2 = array(c, d); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s11 [shape=box, label=\"[1, 2, 3, 4]\"];\n" + - " s7 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s5 [label=\"8\"];\n" + - " s3 [label=\"7\"];\n" + " s1 [label=\"6\"];\n" + + " s3 [label=\"7\"];\n" + + " s5 [label=\"8\"];\n" + + " s7 [label=\"9\"];\n" + + " s11 [shape=box, label=\"[1, 2, 3, 4]\"];\n" + + " s1->s0;\n" + + " s3->s0;\n" + + " s5->s0;\n" + + " s7->s0;\n" + " s11->s1 [label=\"parent[0]\"];\n" + " s11->s3 [label=\"parent[1]\"];\n" + " s11->s5 [label=\"parent[2]\"];\n" + " s11->s7 [label=\"parent[3]\"];\n" + - " s7->s0;\n" + - " s5->s0;\n" + - " s3->s0;\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaubv_Abvdx() { // au,bv + bv,dx -> [a,b,d]->[u,v,x] @@ -616,24 +622,24 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext d = createSingleton(x(), 4); ArrayPredictionContext A1 = array(a, b1); ArrayPredictionContext A2 = array(b2, d); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s11 [shape=box, label=\"[1, 2, 4]\"];\n" + - " s7 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s3 [label=\"7\"];\n" + " s1 [label=\"6\"];\n" + + " s3 [label=\"7\"];\n" + + " s7 [label=\"9\"];\n" + + " s11 [shape=box, label=\"[1, 2, 4]\"];\n" + + " s1->s0;\n" + + " s3->s0;\n" + + " s7->s0;\n" + " s11->s1 [label=\"parent[0]\"];\n" + " s11->s3 [label=\"parent[1]\"];\n" + " s11->s7 [label=\"parent[2]\"];\n" + - " s7->s0;\n" + - " s3->s0;\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaubv_Abwdx() { // au,bv + bw,dx -> [a,b,d]->[u,[v,w],x] @@ -643,25 +649,25 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext d = createSingleton(x(), 4); ArrayPredictionContext A1 = array(a, b1); ArrayPredictionContext A2 = array(b2, d); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s12 [shape=box, label=\"[1, 2, 4]\"];\n" + - " s7 [label=\"9\"];\n" + " s0 [label=\"$\"];\n" + - " s11 [shape=box, label=\"[7, 8]\"];\n" + " s1 [label=\"6\"];\n" + - " s12->s1 [label=\"parent[0]\"];\n" + - " s12->s11 [label=\"parent[1]\"];\n" + - " s12->s7 [label=\"parent[2]\"];\n" + + " s7 [label=\"9\"];\n" + + " s11 [shape=box, label=\"[7, 8]\"];\n" + + " s12 [shape=box, label=\"[1, 2, 4]\"];\n" + + " s1->s0;\n" + " s7->s0;\n" + " s11->s0 [label=\"parent[0]\"];\n" + " s11->s0 [label=\"parent[1]\"];\n" + - " s1->s0;\n" + + " s12->s1 [label=\"parent[0]\"];\n" + + " s12->s11 [label=\"parent[1]\"];\n" + + " s12->s7 [label=\"parent[2]\"];\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaubv_Abvdu() { // au,bv + bv,du -> [a,b,d]->[u,v,u]; u,v shared @@ -671,22 +677,22 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext d = createSingleton(u(), 4); ArrayPredictionContext A1 = array(a, b1); ArrayPredictionContext A2 = array(b2, d); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s11 [shape=box, label=\"[1, 2, 4]\"];\n" + - " s3 [label=\"7\"];\n" + " s0 [label=\"$\"];\n" + " s1 [label=\"6\"];\n" + + " s3 [label=\"7\"];\n" + + " s11 [shape=box, label=\"[1, 2, 4]\"];\n" + + " s1->s0;\n" + + " s3->s0;\n" + " s11->s1 [label=\"parent[0]\"];\n" + " s11->s3 [label=\"parent[1]\"];\n" + " s11->s1 [label=\"parent[2]\"];\n" + - " s3->s0;\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); } @Test public void test_Aaubu_Acudu() { // au,bu + cu,du -> [a,b,c,d]->[u,u,u,u] @@ -696,21 +702,21 @@ public class TestGraphNodes extends TestCase { SingletonPredictionContext d = createSingleton(u(), 4); ArrayPredictionContext A1 = array(a, b); ArrayPredictionContext A2 = array(c, d); - PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard()); - System.out.println(PredictionContext.toDotString(r)); + PredictionContext r = PredictionContext.merge(A1, A2, contextCache, rootIsWildcard()); + System.out.println(PredictionContext.toDOTString(r)); String expecting = "digraph G {\n" + "rankdir=LR;\n" + - " s11 [shape=box, label=\"[1, 2, 3, 4]\"];\n" + - " s1 [label=\"6\"];\n" + " s0 [label=\"$\"];\n" + + " s1 [label=\"6\"];\n" + + " s11 [shape=box, label=\"[1, 2, 3, 4]\"];\n" + + " s1->s0;\n" + " s11->s1 [label=\"parent[0]\"];\n" + " s11->s1 [label=\"parent[1]\"];\n" + " s11->s1 [label=\"parent[2]\"];\n" + " s11->s1 [label=\"parent[3]\"];\n" + - " s1->s0;\n" + "}\n"; - assertEquals(expecting, PredictionContext.toDotString(r)); + assertEquals(expecting, PredictionContext.toDOTString(r)); }