X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=baf1265aafc33ead357e476c80c620d1c76fc8e7;hb=aaa5d101e054dc548e7ef7831b1fcb7913a4d4d4;hp=cadf343e309761b7d56182b6ffbc0a22df8a03ac;hpb=a7ba8d8a5f0cb7fbb5bf67f1a95f1cad5226c507;p=sbp.git diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index cadf343..baf1265 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -77,12 +77,11 @@ public abstract class Forest /*extends PrintableTree>*/ public InnerAmbiguous(Forest f) { this.f = f; } } - static Forest singleton(Input.Location loc, Position p) { - return create(loc, null, new Forest[] { }, false, true, p); } - static Forest singleton(Input.Location loc, Forest body, Position p) { return body; } - static Forest leaf(Input.Location loc, T tag, Position p) { return create(loc, tag, null, false, false, p); } - public static Forest create(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position p) { - return new MyBody(loc, tag, tokens, unwrap, singleton, p); + static Forest singleton(Input.Region loc, Position p) { return create(loc, null, new Forest[] { }, false, p); } + static Forest singleton(Input.Region loc, Forest body, Position p) { return body; } + static Forest leaf(Input.Region loc, T tag, Position p) { return create(loc, tag, null, false, p); } + public static Forest create(Input.Region loc, T tag, Forest[] tokens, boolean unwrap, Position p) { + return new MyBody(loc, tag, tokens, unwrap, p); } // Body ////////////////////////////////////////////////////////////////////////////// @@ -121,21 +120,19 @@ public abstract class Forest /*extends PrintableTree>*/ ivbc.invoke(this, b, c); } - private final Input.Location location; + private final Input.Region location; private final T tag; private final Forest[] tokens; private final boolean unwrap; - private final boolean singleton; private final Sequence.Position reduction; - private MyBody(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position reduction) { + private MyBody(Input.Region loc, T tag, Forest[] tokens, boolean unwrap, Position reduction) { this.location = loc; this.tag = tag; this.tokens = tokens==null ? emptyForestArray : new Forest[tokens.length]; if (tokens != null) System.arraycopy(tokens, 0, this.tokens, 0, tokens.length); if (tokens != null) for(int i=0; i>[] ht, HashSet> target) { @@ -143,7 +140,7 @@ public abstract class Forest /*extends PrintableTree>*/ } private void gather(TaskList tl, HashSet>[] ht, HashSet> target, Tree[] trees, int i) { if (i==ht.length) { - target.add(new Tree(null, tag, trees)); + target.add(new Tree(location, tag, trees)); return; } for(Tree tree : ht[i]) { @@ -153,7 +150,7 @@ public abstract class Forest /*extends PrintableTree>*/ System.arraycopy(trees, 0, trees2, 0, trees.length-1); for(int j=0; j(null, tag, trees2)); + target.add(new Tree(location, tag, trees2)); } else { trees[i] = tree; gather(tl, ht, target, trees, i+1); @@ -162,10 +159,6 @@ public abstract class Forest /*extends PrintableTree>*/ } } public void expand(TaskList tl, HashSet> ht) { - if (singleton) { - tokens[0].expand(tl, ht); - return; - } HashSet>[] children = new HashSet[tokens.length]; tl.gather(this, children, ht); for(int i=0; i /*extends PrintableTree>*/ } public void expand(final int i, final TreeBuilder h) { - if (singleton) { - tokens[0].visit(h, null, i); - return; - } if (i==0) h.start(tag, location); if (i==tokens.length) { @@ -190,9 +179,9 @@ public abstract class Forest /*extends PrintableTree>*/ } else { tokens[i].visit(new TreeBuilder(h.toss) { - public void start(T head, Input.Location loc) { } + public void start(T head, Input.Region loc) { } public void addTree(Tree t) { toks.add(t); } - public void finish(T head, Input.Location loc) { + public void finish(T head, Input.Region loc) { int old = h.toks.size(); h.addTree(new Tree(loc, head, toks.toArray(tree_hint))); expand(i+1, h);