From f1dba2b015c3da04fc2fab45604da2e6c9ae0a1d Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 16 Jul 2006 03:36:44 -0400 Subject: [PATCH 1/1] checkpoint darcs-hash:20060716073644-5007d-87e7c4c7a28a18ab4aec6eff9a1e9cfa96c39d1c.gz --- TODO | 1 + src/edu/berkeley/sbp/Forest.java | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index bed7ed8..f3b6476 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,7 @@ _____________________________________________________________________________ Immediately - do Forest/Tree still need a Region? + - the unwrap bit in Forest makes it really hard to expose an API for forests - evil problems with (x y? z /ws) - ParseFailed, GSS, Walk, Parser, Sequence, Forest diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 0fb10c6..1c8fbc5 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -12,7 +12,6 @@ import java.lang.reflect.*; */ public abstract class Forest implements GraphViz.ToGraphViz { - /** assume that this forest contains exactly one tree and return it; otherwise throw an exception */ public abstract Tree expand1() throws Ambiguous; @@ -24,7 +23,6 @@ public abstract class Forest implements GraphViz.ToGraphViz { return new One(loc, head, children, unwrap); } - // Package-Private ////////////////////////////////////////////////////////////////////////////// abstract void expand(HashSet> ht, HashSet> ignore, Tree bogus); @@ -37,7 +35,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { // One ////////////////////////////////////////////////////////////////////////////// /** A "single" forest with a head and child subforests */ - public static class One extends Forest { + private static class One extends Forest { private final Input.Region location; private final T head; @@ -61,11 +59,11 @@ public abstract class Forest implements GraphViz.ToGraphViz { return new Tree(location, head, ret, unwrap); } - public void gather(HashSet> hf) { + void gather(HashSet> hf) { hf.add(this); for(Forest f : children) f.gather(hf); } - public void expand(HashSet> ht, HashSet> ignore, Tree bogus) { + void expand(HashSet> ht, HashSet> ignore, Tree bogus) { if (ignore.contains(this)) { ht.add(bogus); return; } expand(0, new Tree[children.length], ht, ignore, bogus); } @@ -95,7 +93,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { edges(n); return n; } - boolean edges = false; + boolean edges = false; // FIXME ?? public void edges(GraphViz.Node n) { if (edges) return; edges = true; @@ -119,7 +117,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { // Many ////////////////////////////////////////////////////////////////////////////// /** An "ambiguity node"; this is immutable once it has been "looked at" */ - public static class Many extends Forest implements Iterable> { + static class Many extends Forest { HashSet parents = new HashSet(); private FastSet> hp = new FastSet>(); @@ -127,11 +125,6 @@ public abstract class Forest implements GraphViz.ToGraphViz { public Many() { } - public Iterator> iterator() { - touched(); - return (Iterator>)(Object)hp.iterator(); // FIXME: fastset's iterator is not safe! - } - public Tree expand1() throws Ambiguous { touched(); if (hp.size() > 1) { @@ -151,7 +144,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { return hp.iterator().next().expand1(); } - public void gather(HashSet> ht) { + void gather(HashSet> ht) { touched(); ht.add(this); for(Forest f : hp) f.gather(ht); @@ -160,12 +153,14 @@ public abstract class Forest implements GraphViz.ToGraphViz { private void touched() { if (touched) return; touched = true; + /* FastSet> f2 = new FastSet>(); for(Forest f : hp) if (f instanceof Forest.One) f2.add(f); else for(Forest ff : ((Forest.Many)f)) f2.add(ff); hp = f2; + */ } public boolean contains(Forest f) { touched(); @@ -183,7 +178,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { return true; } - public void expand(HashSet> ht, HashSet> ignore, Tree bogus) { + void expand(HashSet> ht, HashSet> ignore, Tree bogus) { touched(); if (ignore.contains(this)) { ht.add(bogus); return; } for (Forest f : hp) f.expand(ht, ignore, bogus); -- 1.7.10.4