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("SimpleIterator "+x.getSafeSymbol()+"_iterator;");
37 writer.outputline("for ("+relation.getSafeSymbol() + "_hash->iterator("+x.getSafeSymbol()+"_iterator); " + x.getSafeSymbol() + "_iterator.hasNext(); )");
39 writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator.next();");
40 // #ATTN#: key is called second because next() forwards ptr and key does not!
41 writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator.key();");
44 public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
45 VarDescriptor tmp=VarDescriptor.makeNew("flag");
46 writer.outputline("SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator();");
47 writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
48 writer.outputline("if ("+type+"=="+number+")");
49 writer.outputline(tmp.getSafeSymbol()+"=1;");
51 writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&"+x.getSafeSymbol() + "_iterator->hasNext()))");
53 writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + ";");
54 writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + ";");
55 writer.outputline("if ("+type+"=="+number+")");
57 writer.outputline(tmp.getSafeSymbol()+"=0;");
58 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + left + ";");
59 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + right + ";");
61 writer.outputline("else");
63 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->next();");
64 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->key();");
68 public int generate_worklistload(CodeWriter writer, int offset) {
69 String varx = x.getSafeSymbol();
70 String vary = y.getSafeSymbol();
71 writer.outputline("int " + varx + " = wi->word" + offset + "; // r1");
72 writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; //r2");
76 public int generate_workliststore(CodeWriter writer, int offset) {
77 String varx = x.getSafeSymbol();
78 String vary = y.getSafeSymbol();
79 writer.outputline("wi->word" + offset + " = " + varx + "; // r1");
80 writer.outputline("wi->word" + (offset+1) + " = " + vary + "; // r2");