- 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.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>(location, tag, trees));
- return;
- }
- for(Tree<T> tree : ht[i]) {
- if (unwrap && i==trees.length-1) {
- // I think this is wrong
- Tree[] trees2 = new Tree[trees.length - 1 + tree.numChildren()];
- 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>(location, tag, trees2));
- } else {
- trees[i] = tree;
- gather(tl, ht, target, trees, i+1);
- trees[i] = null;
- }
- }
- }
- public void expand(TaskList tl, HashSet<Tree<T>> ht) {
- HashSet<Tree<T>>[] children = new HashSet[tokens.length];
- tl.gather(this, children, ht);
- for(int i=0; i<children.length; i++) {
- children[i] = new HashSet<Tree<T>>();
- tl.expand(tokens[i], children[i]);
- }
- }