checkpoint
authoradam <adam@megacz.com>
Sat, 15 Jul 2006 05:42:15 +0000 (01:42 -0400)
committeradam <adam@megacz.com>
Sat, 15 Jul 2006 05:42:15 +0000 (01:42 -0400)
darcs-hash:20060715054215-5007d-ed3fe5a5c10e09772e1c29240f113fde77b99623.gz

src/edu/berkeley/sbp/Forest.java
src/edu/berkeley/sbp/Sequence.java
src/edu/berkeley/sbp/chr/CharParser.java
src/edu/berkeley/sbp/util/ArrayUtil.java [new file with mode: 0644]

index b00f069..baf1265 100644 (file)
@@ -77,12 +77,11 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
         public InnerAmbiguous(Forest<?> f) { this.f = f; }
     }
 
-    static        <T> Forest<T> singleton(Input.Region loc, Position p) {
-        return create(loc, null, new Forest[] { }, false, true, p); }
+    static        <T> Forest<T> singleton(Input.Region loc, Position p) { return create(loc, null, new Forest[] { }, false, p); }
     static        <T> Forest<T> singleton(Input.Region loc, Forest<T> body, Position p) { return body; }
-    static        <T> Forest<T> leaf(Input.Region loc, T tag, Position p) { return create(loc, tag, null, false, false, p); }
-    public static <T> Forest<T> create(Input.Region 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, Position p) { return create(loc, tag, null, false, p); }
+    public static <T> Forest<T> create(Input.Region loc, T tag, Forest<T>[] tokens, boolean unwrap, Position p) {
+        return new MyBody<T>(loc, tag, tokens, unwrap, p);
     }
     // Body //////////////////////////////////////////////////////////////////////////////
 
@@ -121,21 +120,19 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
             ivbc.invoke(this, b, c);
         }
 
-        private final Input.Region    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.Region loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton, Position reduction) {
+        private MyBody(Input.Region loc, T tag, Forest<T>[] 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<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) {
@@ -162,10 +159,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 +168,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) {
index 33a91bb..1b336ff 100644 (file)
@@ -215,13 +215,13 @@ public abstract class Sequence extends Element implements Iterable<Element> {
         Sequence _clone() { return new Unwrap(elements, drops); }
         public <T> Forest<T> postReduce(Input.Region loc, Forest<T>[] args, Position p) {
             for(int i=0; i<args.length; i++) if (args[i]==null) throw new Error();
-            if (drops==null) return Forest.create(loc, (T)tag, args, true, false, p);
+            if (drops==null) return Forest.create(loc, (T)tag, args, true, p);
             int count = 0;
             for(int i=0; i<drops.length; i++) if (!drops[i]) count++;
             Forest<T>[] args2 = new Forest[count];
             int j = 0;
             for(int i=0; i<args.length; i++) if (!drops[i]) args2[j++] = args[i];
-            return Forest.create(loc, (T)tag, args2, true, false, p);
+            return Forest.create(loc, (T)tag, args2, true, p);
         }
     }
 
@@ -258,7 +258,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
             int j = 0;
             for(int i=0; i<args.length; i++) if (!drops[i]) args2[j++] = args[i];
             //System.out.println("reduce \""+tag+"\"");
-            return Forest.create(loc, (T)tag, args2, false, false, p);
+            return Forest.create(loc, (T)tag, args2, false, p);
         }
         public StringBuffer toString(StringBuffer sb, boolean spacing) {
             int len = sb.length();
index 0a05011..bce5b60 100644 (file)
@@ -16,7 +16,7 @@ public class CharParser extends Parser<Character,String> {
     public CharParser(Union u) { super(u, new CharTopology()); }
 
     public Forest<String> shiftToken(Location oldloc, Character ct, Location newloc) {
-        return Forest.create(new Input.Region(oldloc, newloc), ct.toString(), null, false, false, null);
+        return Forest.create(new Input.Region(oldloc, newloc), ct.toString(), null, false, null);
     }
 
 }
diff --git a/src/edu/berkeley/sbp/util/ArrayUtil.java b/src/edu/berkeley/sbp/util/ArrayUtil.java
new file mode 100644 (file)
index 0000000..f4f7278
--- /dev/null
@@ -0,0 +1,14 @@
+package edu.berkeley.sbp.util;
+import java.lang.reflect.*;
+import java.util.*;
+
+public class ArrayUtil {
+
+  public static <T> T[] append(T[] arr, T t, Class<T> c) {
+      T[] ret = (T[])Array.newInstance(c, arr.length+1);
+      System.arraycopy(arr, 0, ret, 0, arr.length);
+      ret[ret.length-1] = t;
+      return ret;
+  }
+
+}