View Javadoc

1   // BooleanOperation.java, created Jun 29, 2004 1:52:09 PM 2004 by jwhaley
2   // Copyright (C) 2004 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package net.sf.bddbddb.ir.highlevel;
5   
6   import java.util.List;
7   import jwutil.collections.Pair;
8   import net.sf.bddbddb.Relation;
9   import net.sf.javabdd.BDDFactory.BDDOp;
10  
11  /***
12   * BooleanOperation
13   * 
14   * @author jwhaley
15   * @version $Id: BooleanOperation.java 328 2004-10-16 02:45:30Z joewhaley $
16   */
17  public abstract class BooleanOperation extends HighLevelOperation {
18      Relation r0, r1, r2;
19  
20      /***
21       * @param r0
22       * @param r1
23       * @param r2
24       */
25      public BooleanOperation(Relation r0, Relation r1, Relation r2) {
26          super();
27          this.r0 = r0;
28          this.r1 = r1;
29          this.r2 = r2;
30      }
31  
32      /***
33       * @return  the name of this operation
34       */
35      public abstract String getName();
36  
37      /*
38       * (non-Javadoc)
39       * 
40       * @see java.lang.Object#toString()
41       */
42      public String toString() {
43          return r0.toString() + " = " + getExpressionString();
44      }
45  
46      /*
47       * (non-Javadoc)
48       * 
49       * @see net.sf.bddbddb.ir.Operation#getExpressionString()
50       */
51      public String getExpressionString() {
52          return getName() + "(" + r1.toString() + "," + r2.toString() + ")";
53      }
54  
55      /*
56       * (non-Javadoc)
57       * 
58       * @see net.sf.bddbddb.ir.Operation#getDest()
59       */
60      public Relation getRelationDest() {
61          return r0;
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see net.sf.bddbddb.ir.Operation#getSrcs()
68       */
69      public List getSrcs() {
70          return new Pair(r1, r2);
71      }
72  
73      /***
74       * @return Returns the source relation.
75       */
76      public Relation getSrc1() {
77          return r1;
78      }
79  
80      /***
81       * @return Returns the source relation.
82       */
83      public Relation getSrc2() {
84          return r2;
85      }
86  
87      /***
88       * @return  the BDDOp for this operation
89       */
90      public abstract BDDOp getBDDOp();
91  
92      /*
93       * (non-Javadoc)
94       * 
95       * @see net.sf.bddbddb.ir.Operation#replaceSrc(net.sf.bddbddb.Relation,
96       *      net.sf.bddbddb.Relation)
97       */
98      public void replaceSrc(Relation r_old, Relation r_new) {
99          if (r1 == r_old) r1 = r_new;
100         if (r2 == r_old) r2 = r_new;
101     }
102 
103     /*
104      * (non-Javadoc)
105      * 
106      * @see net.sf.bddbddb.ir.Operation#setRelationDest(net.sf.bddbddb.Relation)
107      */
108     public void setRelationDest(Relation r0) {
109         this.r0 = r0;
110     }
111 }