worklist version
[repair.git] / Repair / RepairCompiler / MCC / IR / RelationQuantifier.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class RelationQuantifier extends Quantifier {
6
7     RelationDescriptor relation;
8     VarDescriptor x, y; // y = x.relation
9
10     public RelationQuantifier() {}
11
12     public void setRelation(RelationDescriptor rd) {
13         relation = rd; 
14     }
15
16     public void setTuple(VarDescriptor x, VarDescriptor y) {
17         this.x = x;
18         this.y = y;
19     }
20
21     public Set getRequiredDescriptors() {
22         HashSet v = new HashSet();
23         v.add(relation);
24         return v;
25     }
26
27     public String toString() {
28         return "relation quantifier <" + x.getSymbol() + "," + y.getSymbol() + "> in " + relation.getSymbol();
29     }
30
31     public void generate_open(CodeWriter writer) {
32         writer.outputline("for (SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator(); " + x.getSafeSymbol() + "_iterator->hasNext(); )");
33         writer.startblock();
34         writer.outputline(y.getType().getSafeSymbol() + " " + y.getSafeSymbol() + " = (" + y.getType().getSafeSymbol() + ") " + x.getSafeSymbol() + "_iterator->next();");        
35         // #ATTN#: key is called second because next() forwards ptr and key does not! 
36         writer.outputline(x.getType().getSafeSymbol() + " " + x.getSafeSymbol() + " = (" + x.getType().getSafeSymbol() + ") " + x.getSafeSymbol() + "_iterator->key();");
37     }
38
39     public int generate_worklistload(CodeWriter writer, int offset) {        
40         String varx = x.getSafeSymbol();
41         String vary = y.getSafeSymbol();
42         writer.outputline("int " + varx + " = wi->word" + offset + "; // r1"); 
43         writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; //r2"); 
44         return offset + 2;       
45     }
46
47     public int generate_workliststore(CodeWriter writer, int offset) {        
48         String varx = x.getSafeSymbol();
49         String vary = y.getSafeSymbol();
50         writer.outputline("wi->word" + offset + " = " + varx + "; // r1");
51         writer.outputline("wi->word" + (offset+1) + " = " + vary + "; // r2");
52         return offset + 2;       
53     }
54
55
56 }