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.addDeclaration("struct SimpleIterator",x.getSafeSymbol()+"_iterator");
37 writer.outputline("for (SimpleHashiterator("+relation.getSafeSymbol()+"_hash, &"+x.getSafeSymbol()+"_iterator); hasNext(&"+x.getSafeSymbol()+"_iterator); )");
39 // #ATTN#: key is called first because next() forwards ptr and key does not!
40 writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());
41 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
43 writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());
44 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
48 public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
49 VarDescriptor tmp=VarDescriptor.makeNew("flag");
50 writer.addDeclaration("struct SimpleIterator", x.getSafeSymbol() + "_iterator");
51 writer.outputline("SimpleHashiterator("+relation.getSafeSymbol()+"_hash,& "+x.getSafeSymbol()+"_iterator);");
52 writer.addDeclaration("int",tmp.getSafeSymbol());
53 writer.outputline(tmp.getSafeSymbol()+"=0;");
54 writer.outputline("if ("+type+"=="+number+")");
55 writer.outputline(tmp.getSafeSymbol()+"=1;");
57 writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&& hasNext(&"+x.getSafeSymbol()+"_iterator)))");
59 writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());
60 writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());
61 writer.outputline("if ("+type+"=="+number+")");
63 writer.outputline(tmp.getSafeSymbol()+"=0;");
64 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + left + ";");
65 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + right + ";");
67 writer.outputline("else");
69 writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
70 writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
74 public int generate_worklistload(CodeWriter writer, int offset) {
75 String varx = x.getSafeSymbol();
76 String vary = y.getSafeSymbol();
77 writer.outputline("int " + varx + " = wi->word" + offset + "; /* r1*/");
78 writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; /*r2*/");
82 public int generate_workliststore(CodeWriter writer, int offset) {
83 String varx = x.getSafeSymbol();
84 String vary = y.getSafeSymbol();
85 writer.outputline("wi->word" + offset + " = " + varx + "; /* r1*/");
86 writer.outputline("wi->word" + (offset+1) + " = " + vary + "; /* r2*/");