ae6886e239d8844b73ab9d39651cb5b66577854f
[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.indent();
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 }