- public void queueReductions(Node n2) {
- if (!allqueued) { queueReductions(); return; }
- state.invokeReductions(token, this, this, n2);
+ public void performReductions(Node n2) {
+ if (!allqueued) performReductions();
+ else state.invokeReductions(token, this, this, n2);
+ }
+
+ public void performEmptyReductions() { state.invokeReductions(token, this, null, null); }
+ public final void invoke(Position r, Node n, Node n2) {
+ reductions++;
+ if (n==null || n2==null || r.pos==0) {
+ if (r.pos==0) {
+ if (n==null) n = this;
+ else return;
+ }
+ if (n==null) return;
+ Forest[] holder = new Forest[r.pos];
+ if (r.pos==0) n.finish(r, r.zero(), n.phase());
+ else n.reduce(r, r.pos-1, n.phase(), null);
+ } else {
+ if (r.pos<=0) throw new Error("called wrong form of reduce()");
+ int pos = r.pos-1;
+ n.reduce(r, pos, n.phase(), n2);
+ }
+ }
+
+ public void reduce(Position r, int pos, Phase target, Node only) {
+ Forest[] holder = r.holder;
+ Forest old = holder[pos];
+
+ for(Forest result : results())
+ for(Node child : ((Forest.Ref<?>)result).parents) {
+ if (only != null && child!=only) continue;
+ holder[pos] = result;
+ if (pos==0) child.finish(r, r.rewrite(phase().getLocation()), target);
+ else child.reduce(r, pos-1, target, null);
+ }
+
+ holder[pos] = old;