/** which Phase this Node belongs to (node that Node is also a non-static inner class of Phase) */
public Phase phase() { return Phase.this; }
- //private Forest pending() { return !Phase.this.closed ? holder : holder.resolve(); }
- private HashMap<Node,Forest> resultMap = new HashMap<Node,Forest>();
+ //private HashMap<Node,Forest> resultMap = new HashMap<Node,Forest>();
+
+ private HashSet<Forest.Ref> resultMap = new HashSet<Forest.Ref>();
public void merge(Node parent, Forest result) {
- //holder.merge(result);
+ for(Forest.Ref f : results()) {
+ if (f.parents.contains(parent) && f.parents.size()==1) {
+ f.merge(result);
+ return;
+ }
+ }
+ Forest.Ref f = new Forest.Ref();
+ f.parents.add(parent);
+ f.merge(result);
+ resultMap.add(f);
+ set.add(parent, true);
+ /*
Forest.Ref f = (Forest.Ref)resultMap.get(parent);
if (f==null) { f = new Forest.Ref(); resultMap.put(parent, f); }
f.merge(result);
set.add(parent, true);
+ */
}
- //public Iterable<Node> childrenFor(Forest result) { return resultMap.getAll(result); }
- public Iterable<Forest> results() { return resultMap.values(); }
- private Forest pending(Node n) {
+ public Iterable<Forest.Ref> results() { return resultMap; }
+ //private Forest pending(Node n) {
//return !Phase.this.closed ? holder : holder.resolve();
/*
for(Forest f : resultMap)
return f;
return null;
*/
+ /*
return resultMap.get(n);
}
+ */
public FastSet<Node> parents() { return set; }
public void performReductions() {
if (n==null) return;
Forest[] holder = new Forest[r.pos];
if (r.pos==0) n.finish(r, r.zero(), n.phase(), holder);
- else n.reduce(r, r.pos-1, n.phase(), holder, null, n.pending(n));
+ else n.reduce(r, r.pos-1, n.phase(), holder, null, null);
} else {
Forest[] holder = new Forest[r.pos];
if (r.pos<=0) throw new Error("called wrong form of reduce()");
int pos = r.pos-1;
- n.reduce(r, pos, n.phase(), holder, n2, n.pending(n));
+ n.reduce(r, pos, n.phase(), holder, n2, null);
}
}
// since the same reduction can appear in more than one state.
if (only != null) {
- holder[pos] = pending(only);
- System.arraycopy(holder, 0, r.holder, 0, holder.length);
- for(int i=0; i<r.pos; i++) if (r.holder[i]==null) throw new Error("realbad");
- Forest rex = null;
- if (r.pos==1) rex = singularReductions.get(pending, r);
- if (rex==null) {
- rex = r.rewrite(phase().getLocation());
- if (r.pos==1) singularReductions.put(pending, r, rex);
- }
- only.finish(r, rex, target, holder);
+ for(Forest result : results())
+ for(Node child : ((Forest.Ref<?>)result).parents) {
+ if (child!=only) continue;
+ pending = holder[pos] = result;
+ System.arraycopy(holder, 0, r.holder, 0, holder.length);
+ for(int i=0; i<r.pos; i++) if (r.holder[i]==null) throw new Error("realbad");
+ Forest rex = null;
+ if (r.pos==1) rex = singularReductions.get(pending, r);
+ if (rex==null) {
+ rex = r.rewrite(phase().getLocation());
+ if (r.pos==1) singularReductions.put(pending, r, rex);
+ }
+ only.finish(r, rex, target, holder);
+ }
} else {
for(Forest result : results()) {
pending = holder[pos] = result;
rex = r.rewrite(phase().getLocation());
if (r.pos==1) singularReductions.put(pending, r, rex);
}
- for(Node child : parents()) {
- if (pending(child)==result)
- child.finish(r, rex, target, holder);
- }
+ for(Node child : ((Forest.Ref<?>)result).parents)
+ child.finish(r, rex, target, holder);
}
}
} else {
if (only != null) {
- holder[pos] = pending(only);
- only.reduce(r, pos-1, target, holder, null, only.pending(only));
+ for(Forest result : results())
+ for(Node child : ((Forest.Ref<?>)result).parents) {
+ if (child!=only) continue;
+ holder[pos] = result;
+ only.reduce(r, pos-1, target, holder, null, null);
+ }
} else {
- for(Node child : this.parents()) {
- holder[pos] = pending(child);
- child.reduce(r, pos-1, target, holder, null, child.pending(child));
- }
+ for(Forest result : results())
+ for(Node child : ((Forest.Ref<?>)result).parents) {
+ holder[pos] = result;
+ child.reduce(r, pos-1, target, holder, null, null);
+ }
}
}
holder[pos] = old;