UnwrapLeft, error reporting improvements
[sbp.git] / src / edu / berkeley / sbp / Tree.java
index bc450fb..1f55a90 100644 (file)
@@ -41,9 +41,19 @@ public class Tree<NodeType>
     // FIXME: fairly inefficient because we keep copying arrays
     /** package-private constructor, allows setting the "lift" bit */
     Tree(Input.Region loc, NodeType head, Tree<NodeType>[] children, boolean lift) {
+        this(loc, head, children, lift, false);
+    }
+    Tree(Input.Region loc, NodeType head, Tree<NodeType>[] children, boolean lift, boolean liftLeft) {
         this.location = loc;
         this.ihead = head;
-        if (lift && children != null && children.length > 0) {
+        // FIXME: lift+liftLeft togheter
+        if (liftLeft && children != null && children.length > 0) {
+            Tree<NodeType> last = children[0];
+            this.children = new Tree[(children.length-1)+last.children.length];
+            System.arraycopy(children, 1, this.children, last.children.length, children.length-1);
+            if (last.children.length > 0)
+                System.arraycopy(last.children, 0, this.children, 0, last.children.length);
+        } else if (lift && children != null && children.length > 0) {
             Tree<NodeType> last = children[children.length-1];
             this.children = new Tree[(children.length-1)+last.children.length];
             System.arraycopy(children, 0, this.children, 0, children.length-1);