public Iterator<Element> iterator() { return new ArrayIterator<Element>(elements); }
protected Sequence(Element[] elements) {
this.elements = elements;
- this.firstp = new Position(0);
+ for(int i=0; i<elements.length; i++)
+ if (elements[i]==null)
+ throw new RuntimeException("cannot have nulls in a sequence: " + this);
+ this.firstp = new Position(0, null);
}
// DO NOT MESS WITH THE FOLLOWING LINE!!!
class Position implements IntegerMappable {
public int ord = -1;
- public int compareTo(Position p, Walk.Cache cache) {
- Position position = this;
- Position rposition = p;
- int ret = 0;
- if (Reduction.canKill(cache, position, rposition) &&
- Reduction.canKill(cache, rposition, position)) throw new Error();
- if (Reduction.canKill(cache, position, rposition)) ret = 1;
- else if (Reduction.canKill(cache, rposition, position)) ret = -1;
- if (Reduction.canNeed(cache, position, rposition)) ret = 1;
- else if (Reduction.canNeed(cache, rposition, position)) ret = -1;
- return ret;
- }
private Forest zero = null;
public Forest zero(Input.Region reg) {
if (zero != null) return zero;
- if (pos > 0) throw new Error();
+ if (pos > 0) throw new RuntimeException("Position.zero(): pos>0");
return zero = rewrite(reg);
}
-
final int pos;
private final Position next;
private final Position prev;
final Forest[] holder;
- private Position(int pos) {
+ private Position(int pos, Position prev) {
this.pos = pos;
- this.next = pos==elements.length ? null : new Position(pos+1);
+ this.next = pos==elements.length ? null : new Position(pos+1, this);
this.holder = new Forest[elements.length];
this.prev = prev;
}
if (holder[i]==null) holder[i] = elements[i].epsilonForm(loc);
if (holder[i]==null) throw new Error("bad " + i);
}
- Forest<T> ret = Sequence.this.postReduce(loc, holder, this);
- //for(int k=0; k<pos; k++) holder[k] = null; // to help GC
- return ret;
+ return Sequence.this.postReduce(loc, holder, this);
}
public String toString() {
Forest<T>[] args2 = new Forest[count];
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);
}
public StringBuffer toString(StringBuffer sb, boolean spacing) {