X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=1730f607eba82daeb513f88053b53d08137a33e2;hp=43ffb10fcfc4a0a1daaef9f0c59e92dc8559dfc1;hb=0ddfec9ac2783f59115205dc0f3806137265c59c;hpb=8a5250c184672495fae152e096b2e800749cd0db diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 43ffb10..1730f60 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -1,3 +1,5 @@ +// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp; import edu.berkeley.sbp.*; import edu.berkeley.sbp.Sequence.Position; @@ -21,7 +23,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { public void expand(HashSet> ht) { expand(ht, new HashSet>(), null); } static Forest create(Input.Region loc, NodeType head, Forest[] children, boolean lift) { - if (loc == null) throw new Error(); + if (loc == null) throw new RuntimeException("invoked Forest.create(null,,,,) -- this should never happen"); return new One(loc, head, children, lift); } @@ -55,6 +57,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { private One(Input.Region loc, NodeType head, Forest[] children, boolean lift) { this.location = loc; this.head = head; + if (head==null) throw new RuntimeException("invoked Forest.create(,null,,,) -- this should never happen"); this.children = children==null ? emptyForestArray : new Forest[children.length]; if (children != null) System.arraycopy(children, 0, this.children, 0, children.length); if (children != null) for(int i=0; i implements GraphViz.ToGraphViz { /** An "ambiguity node"; this is immutable once it has been "looked at" */ static class Many extends Forest { - HashSet parents = new HashSet(); private FastSet> hp = new FastSet>(); private boolean touched = false; @@ -156,6 +158,14 @@ public abstract class Forest implements GraphViz.ToGraphViz { void gather(HashSet> ht) { touched(); + + // FIXME: do something more sensible here + if (ht.contains(this)) { + System.err.println("WARNING: grammar produced a circular forest\n" + this); + //throw new Error("grammar produced a circular forest:\n" + this); + return; + } + ht.add(this); for(Forest f : hp) f.gather(ht); }