5 public class RelationQuantifier extends Quantifier {
7 RelationDescriptor relation;
8 VarDescriptor x, y; // y = x.relation
10 public RelationQuantifier() {}
12 public void setRelation(RelationDescriptor rd) {
16 public RelationDescriptor getRelation() {
20 public void setTuple(VarDescriptor x, VarDescriptor y) {
25 public Set getRequiredDescriptors() {
26 HashSet v = new HashSet();
31 public String toString() {
32 return "relation quantifier <" + x.getSymbol() + "," + y.getSymbol() + "> in " + relation.getSymbol();
35 public void generate_open(CodeWriter writer) {
36 writer.outputline("for (SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator(); " + x.getSafeSymbol() + "_iterator->hasNext(); )");
38 writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->next();");
39 // #ATTN#: key is called second because next() forwards ptr and key does not!
40 writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->key();");
43 public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
44 VarDescriptor tmp=VarDescriptor.makeNew("flag");
45 writer.outputline("SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator();");
46 writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
47 writer.outputline("if ("+type+"=="+number+")");
48 writer.outputline(tmp.getSafeSymbol()+"=1;");
50 writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&"+x.getSafeSymbol() + "_iterator->hasNext()))");
52 writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + ";");
53 writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + ";");
54 writer.outputline("if ("+type+"=="+number+")");
56 writer.outputline(tmp.getSafeSymbol()+"=0;");
57 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + left + ";");
58 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + right + ";");
60 writer.outputline("else");
62 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->next();");
63 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->key();");
67 public int generate_worklistload(CodeWriter writer, int offset) {
68 String varx = x.getSafeSymbol();
69 String vary = y.getSafeSymbol();
70 writer.outputline("int " + varx + " = wi->word" + offset + "; // r1");
71 writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; //r2");
75 public int generate_workliststore(CodeWriter writer, int offset) {
76 String varx = x.getSafeSymbol();
77 String vary = y.getSafeSymbol();
78 writer.outputline("wi->word" + offset + " = " + varx + "; // r1");
79 writer.outputline("wi->word" + (offset+1) + " = " + vary + "; // r2");