*/
public abstract class Forest<T> implements GraphViz.ToGraphViz {
-
/** assume that this forest contains exactly one tree and return it; otherwise throw an exception */
public abstract Tree<T> expand1() throws Ambiguous;
return new One<T>(loc, head, children, unwrap);
}
-
// Package-Private //////////////////////////////////////////////////////////////////////////////
abstract void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus);
// One //////////////////////////////////////////////////////////////////////////////
/** A "single" forest with a head and child subforests */
- public static class One<T> extends Forest<T> {
+ private static class One<T> extends Forest<T> {
private final Input.Region location;
private final T head;
return new Tree<T>(location, head, ret, unwrap);
}
- public void gather(HashSet<Forest<T>> hf) {
+ void gather(HashSet<Forest<T>> hf) {
hf.add(this);
for(Forest<T> f : children) f.gather(hf);
}
- public void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+ void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
if (ignore.contains(this)) { ht.add(bogus); return; }
expand(0, new Tree[children.length], ht, ignore, bogus);
}
edges(n);
return n;
}
- boolean edges = false;
+ boolean edges = false; // FIXME ??
public void edges(GraphViz.Node n) {
if (edges) return;
edges = true;
// Many //////////////////////////////////////////////////////////////////////////////
/** An "ambiguity node"; this is immutable once it has been "looked at" */
- public static class Many<T> extends Forest<T> implements Iterable<One<T>> {
+ static class Many<T> extends Forest<T> {
HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
public Many() { }
- public Iterator<One<T>> iterator() {
- touched();
- return (Iterator<One<T>>)(Object)hp.iterator(); // FIXME: fastset's iterator is not safe!
- }
-
public Tree<T> expand1() throws Ambiguous {
touched();
if (hp.size() > 1) {
return hp.iterator().next().expand1();
}
- public void gather(HashSet<Forest<T>> ht) {
+ void gather(HashSet<Forest<T>> ht) {
touched();
ht.add(this);
for(Forest<T> f : hp) f.gather(ht);
private void touched() {
if (touched) return;
touched = true;
+ /*
FastSet<Forest<T>> f2 = new FastSet<Forest<T>>();
for(Forest f : hp)
if (f instanceof Forest.One) f2.add(f);
else for(Forest ff : ((Forest.Many<T>)f))
f2.add(ff);
hp = f2;
+ */
}
public boolean contains(Forest f) {
touched();
return true;
}
- public void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+ void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
touched();
if (ignore.contains(this)) { ht.add(bogus); return; }
for (Forest<T> f : hp) f.expand(ht, ignore, bogus);