checkpoint
authoradam <adam@megacz.com>
Fri, 21 Jul 2006 03:07:04 +0000 (23:07 -0400)
committeradam <adam@megacz.com>
Fri, 21 Jul 2006 03:07:04 +0000 (23:07 -0400)
darcs-hash:20060721030704-5007d-2b29da867a864163d503edee66e6dff6a9a9d862.gz

TODO
src/edu/berkeley/sbp/Tree.java
src/edu/berkeley/sbp/bind/BindingFunctor.java
src/edu/berkeley/sbp/meta/ArrayBuildingTreeFunctor.java
src/edu/berkeley/sbp/misc/RegressionTests.java
src/edu/berkeley/sbp/misc/TreeWalker.java
src/edu/berkeley/sbp/util/PrintableTree.java

diff --git a/TODO b/TODO
index cef631b..0c2d747 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,6 +2,8 @@ _____________________________________________________________________________
 Immediately
 
   - Sequence shouldn't be an Element
 Immediately
 
   - Sequence shouldn't be an Element
+  - Should Tree<T> really be type-parameterized?
+
   - More topology untangling
   - needs/hates/follow API ugliness
 
   - More topology untangling
   - needs/hates/follow API ugliness
 
index a6cbd3a..8368673 100644 (file)
@@ -9,8 +9,7 @@ import java.lang.reflect.*;
 /** <font color=blue>a tree (or node in a tree); see jargon.txt for details</font> */
 public class Tree<T>
     extends PrintableTree<Tree<T>>
 /** <font color=blue>a tree (or node in a tree); see jargon.txt for details</font> */
 public class Tree<T>
     extends PrintableTree<Tree<T>>
-    implements Iterable<Tree<T>>,
-               GraphViz.ToGraphViz {
+    implements Iterable<Tree<T>> {
 
     private final Input.Region location;
     private final T            head;
 
     private final Input.Region location;
     private final T            head;
@@ -23,9 +22,9 @@ public class Tree<T>
     private Tree<T> lifted() { return children[children.length-1]; }
 
     /** the number of children the tree has */
     private Tree<T> lifted() { return children[children.length-1]; }
 
     /** the number of children the tree has */
-    public int               numChildren() {
+    public int               size() {
         return lift
         return lift
-            ? (children.length-1)+lifted().numChildren()
+            ? (children.length-1)+lifted().size()
             : children.length;
     }
 
             : children.length;
     }
 
@@ -80,16 +79,4 @@ public class Tree<T>
     protected boolean ignoreSingleton() { return false; }
 
 
     protected boolean ignoreSingleton() { return false; }
 
 
-    // ToGraphViz /////////////////////////////////////////////////////////////////////////////
-
-    public GraphViz.Node toGraphViz(GraphViz gv) {
-        if (gv.hasNode(this)) return gv.createNode(this);
-        GraphViz.Node n = gv.createNode(this);
-        n.label = head()==null ? "" : head().toString();
-        for(Tree t : this) n.edge(t, null);
-        return n;
-    }
-    public boolean isTransparent() { return false; }
-    public boolean isHidden() { return false; }
-
 }
 }
index 8a4d042..a7d1ecc 100644 (file)
@@ -29,7 +29,7 @@ public class BindingFunctor<T> implements TreeFunctor<T,Object>, ToJava {
         for(Tree tc : t) {
             if (tc.head() != null && tc.head() instanceof Functor)
                 ret.add(((TreeFunctor<Object,Object>)tc.head()).invoke(tc.children()));
         for(Tree tc : t) {
             if (tc.head() != null && tc.head() instanceof Functor)
                 ret.add(((TreeFunctor<Object,Object>)tc.head()).invoke(tc.children()));
-            else if (tc.numChildren() == 0)
+            else if (tc.size() == 0)
                 ret.add(tc.head());
             else {
                 System.err.println("FIXME: don't know what to do about " + tc);
                 ret.add(tc.head());
             else {
                 System.err.println("FIXME: don't know what to do about " + tc);
index f1477ed..4975d9c 100644 (file)
@@ -20,7 +20,7 @@ public class ArrayBuildingTreeFunctor<T> implements TreeFunctor<T,T[]>, ToJava {
         for(Tree tc : t) {
             if (tc.head() != null && tc.head() instanceof Functor)
                 ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
         for(Tree tc : t) {
             if (tc.head() != null && tc.head() instanceof Functor)
                 ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
-            else if (tc.numChildren() == 0)
+            else if (tc.size() == 0)
                 ret.add(tc.head());
             else {
                 System.err.println("FIXME: don't know what to do about " + tc);
                 ret.add(tc.head());
             else {
                 System.err.println("FIXME: don't know what to do about " + tc);
index d2443ad..bffc0da 100644 (file)
@@ -202,13 +202,13 @@ public class RegressionTests {
                 else if ("input".equals(tree.head())) return string(tree.children());
                 else if ("testcase".equals(tree.head())) {
                     String input = string(tree.child(0));
                 else if ("input".equals(tree.head())) return string(tree.children());
                 else if ("testcase".equals(tree.head())) {
                     String input = string(tree.child(0));
-                    String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
-                    Union grammar = Grammar.create(tree.child(tree.numChildren()-1), "s", new MetaGrammarBindings());
+                    String[] output = tree.size()>2 ? ((String[])walk(tree, 1)) : new String[0];
+                    Union grammar = Grammar.create(tree.child(tree.size()-1), "s", new MetaGrammarBindings());
                     TestCase tc = new TestCase(input, output, grammar, false, false);
                     return tc;
                 } else if ("ts".equals(tree.head())) return walk(tree, 0);
                 else if (tree.head() == null) {
                     TestCase tc = new TestCase(input, output, grammar, false, false);
                     return tc;
                 } else if ("ts".equals(tree.head())) return walk(tree, 0);
                 else if (tree.head() == null) {
-                    Object[] ret = new Object[tree.numChildren()];
+                    Object[] ret = new Object[tree.size()];
                     for(int i=0; i<ret.length; i++)
                         ret[i] = walk(tree.child(i));
                     return Reflection.lub(ret);
                     for(int i=0; i<ret.length; i++)
                         ret[i] = walk(tree.child(i));
                     return Reflection.lub(ret);
index f8a4496..b735673 100644 (file)
@@ -17,7 +17,7 @@ public abstract class TreeWalker<T> {
         for(Tree<T> child : tree.children()) walk(child);        
     }
     public Object walk(Tree<T> tree) {
         for(Tree<T> child : tree.children()) walk(child);        
     }
     public Object walk(Tree<T> tree) {
-        Object[] args = new Object[tree.numChildren()];
+        Object[] args = new Object[tree.size()];
         int i = 0;
         for(Tree<T> child : tree.children()) args[i++] = walk(child);
         args = Reflection.lub(args);
         int i = 0;
         for(Tree<T> child : tree.children()) args[i++] = walk(child);
         args = Reflection.lub(args);
index 8e12956..1b5ffc0 100644 (file)
@@ -5,8 +5,9 @@ import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 
 import java.util.*;
 import java.lang.reflect.*;
 
-public abstract class PrintableTree<T extends PrintableTree> implements Iterable<T>, ToJava /*, ToHTML*/ {
+public abstract class PrintableTree<T extends PrintableTree> implements Iterable<T>, ToJava /*, ToHTML*/, GraphViz.ToGraphViz {
 
 
+    protected abstract Object head();
     protected abstract String headToString();
     protected abstract String headToJava();    
     protected abstract String left();
     protected abstract String headToString();
     protected abstract String headToJava();    
     protected abstract String left();
@@ -82,4 +83,13 @@ public abstract class PrintableTree<T extends PrintableTree> implements Iterable
         sb.append("})");
     }
 
         sb.append("})");
     }
 
+    public GraphViz.Node toGraphViz(GraphViz gv) {
+        if (gv.hasNode(this)) return gv.createNode(this);
+        GraphViz.Node n = gv.createNode(this);
+        n.label = head()==null ? "" : head().toString();
+        for(T t : this) n.edge(t, null);
+        return n;
+    }
+    public boolean isTransparent() { return false; }
+    public boolean isHidden() { return false; }
 }
 }