checkpoint
[sbp.git] / src / edu / berkeley / sbp / Forest.java
index cadf343..e7c0be4 100644 (file)
@@ -77,12 +77,9 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
         public InnerAmbiguous(Forest<?> f) { this.f = f; }
     }
 
-    static        <T> Forest<T> singleton(Input.Location loc, Position p) {
-        return create(loc, null, new Forest[] { }, false, true, p); }
-    static        <T> Forest<T> singleton(Input.Location loc, Forest<T> body, Position p) { return body; }
-    static        <T> Forest<T> leaf(Input.Location loc, T tag, Position p) { return create(loc, tag, null, false, false, p); }
-    public static <T> Forest<T> create(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton, Position p) {
-        return new MyBody<T>(loc, tag, tokens, unwrap, singleton, p);
+    static        <T> Forest<T> leaf(Input.Region loc, T tag) { return create(loc, tag, null, false); }
+    public static <T> Forest<T> create(Input.Region loc, T tag, Forest<T>[] tokens, boolean unwrap) {
+        return new MyBody<T>(loc, tag, tokens, unwrap);
     }
     // Body //////////////////////////////////////////////////////////////////////////////
 
@@ -100,7 +97,7 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
             GraphViz.Node n = gv.createNode(this);
             n.label = headToString()==null?"":headToString();
             n.directed = true;
-            n.comment = reduction==null?null:reduction+"";
+            //n.comment = reduction==null?null:reduction+"";
             edges(n);
             return n;
         }
@@ -121,29 +118,25 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
             ivbc.invoke(this, b, c);
         }
 
-        private final Input.Location    location;
+        private final Input.Region      location;
         private final T                 tag;
         private final Forest<T>[]       tokens;
         private final boolean           unwrap;
-        private final boolean           singleton;
-        private final Sequence.Position reduction;
 
-        private MyBody(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton, Position reduction) {
+        private MyBody(Input.Region loc, T tag, Forest<T>[] tokens, boolean unwrap) {
             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<tokens.length; i++) if (tokens[i]==null) throw new Error(i+"");
             this.unwrap = unwrap;
-            this.singleton = singleton;
-            this.reduction = reduction;
         }
         public void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target) {
             gather(tl, ht, target, new Tree[ht.length], 0);
         }
         private void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target, Tree[] trees, int i) {
             if (i==ht.length) {
-                target.add(new Tree<T>(null, tag, trees));
+                target.add(new Tree<T>(location, tag, trees));
                 return;
             }
             for(Tree<T> tree : ht[i]) {
@@ -153,7 +146,7 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
                     System.arraycopy(trees, 0, trees2, 0, trees.length-1);
                     for(int j=0; j<tree.numChildren(); j++)
                         trees2[trees.length-1+j] = tree.child(j);
-                    target.add(new Tree<T>(null, tag, trees2));
+                    target.add(new Tree<T>(location, tag, trees2));
                 } else {
                     trees[i] = tree;
                     gather(tl, ht, target, trees, i+1);
@@ -162,10 +155,6 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
             }
         }
         public void expand(TaskList tl, HashSet<Tree<T>> ht) {
-            if (singleton) {
-                tokens[0].expand(tl, ht);
-                return;
-            }
             HashSet<Tree<T>>[] children = new HashSet[tokens.length];
             tl.gather(this, children, ht);
             for(int i=0; i<children.length; i++) {
@@ -175,10 +164,6 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
         }
 
         public void expand(final int i, final TreeBuilder<T> h) {
-            if (singleton) {
-                tokens[0].visit(h, null, i);
-                return;
-            }
             if (i==0) h.start(tag, location);
 
             if (i==tokens.length) {
@@ -190,9 +175,9 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
 
             } else {
                 tokens[i].visit(new TreeBuilder<T>(h.toss) {
-                    public void start(T head, Input.Location loc) { }
+                    public void start(T head, Input.Region loc) { }
                     public void addTree(Tree<T> 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<T>(loc, head, toks.toArray(tree_hint)));
                         expand(i+1, h);