1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.Sequence.Pos;
5 import edu.berkeley.sbp.Sequence.Pos;
7 final class Reduction implements Comparable<Reduction> {
10 private GSS.Phase phase;
11 private Forest forest;
14 public Reduction(Node pred, Pos reduction, Forest forest, GSS.Phase target) {
15 this.reduction = reduction;
19 target.addReduction(this);
22 public int compareTo(Reduction r) {
23 if (pred.phase()!=null || r.pred.phase()!=null) {
24 if (pred.phase()==null) return 1;
25 if (r.pred.phase()==null) return -1;
26 if (pred.phase().pos < r.pred.phase().pos) return 1;
27 if (pred.phase().pos > r.pred.phase().pos) return -1;
30 int master = Parser.mastercache.comparePositions(reduction(), r.reduction());
31 if (master != 0 && master != signum(reduction.ord() - r.reduction.ord()))
32 throw new Error("master="+master+" and a="+reduction.ord()+" and b="+r.reduction.ord()+"\n"+reduction+"\n"+r.reduction);
34 return reduction.compareTo(r.reduction);
37 private int signum(int x) {
43 public void perform() {
44 if (reduction==null) return;
45 phase.newNodeFromReduction(forest, reduction, pred);
47 public GSS.Phase predPhase() { return pred.phase(); }
48 public Pos reduction() { return reduction; }
49 public GSS.Phase targetPhase() { return phase; }
50 public String toString() { return (pred.phase()==null ? 0 : pred.phase().pos) + ":"+reduction; }