Change to the spec...missed a consistency property. Adding timing option.
[repair.git] / Repair / RepairCompiler / MCC / IR / RelationQuantifier.java
index 7281d2e4086ea7c6bc0a320874c48f4f0d61c897..48959afc7e426a9fee455214ce83c0cef10fdf27 100755 (executable)
@@ -13,6 +13,10 @@ public class RelationQuantifier extends Quantifier {
         relation = rd; 
     }
 
+    public RelationDescriptor getRelation() {
+       return relation;
+    }
+
     public void setTuple(VarDescriptor x, VarDescriptor y) {
         this.x = x;
         this.y = y;
@@ -29,11 +33,36 @@ public class RelationQuantifier extends Quantifier {
     }
 
     public void generate_open(CodeWriter writer) {
-        writer.outputline("for (SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator(); " + x.getSafeSymbol() + "_iterator->hasNext(); )");
+       writer.outputline("SimpleIterator "+x.getSafeSymbol()+"_iterator;");
+        writer.outputline("for ("+relation.getSafeSymbol() + "_hash->iterator("+x.getSafeSymbol()+"_iterator); " + x.getSafeSymbol() + "_iterator.hasNext(); )");
         writer.startblock();
-        writer.outputline(y.getType().getSafeSymbol() + " " + y.getSafeSymbol() + " = (" + y.getType().getSafeSymbol() + ") " + x.getSafeSymbol() + "_iterator->next();");        
+        writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator.next();");        
         // #ATTN#: key is called second because next() forwards ptr and key does not! 
-        writer.outputline(x.getType().getSafeSymbol() + " " + x.getSafeSymbol() + " = (" + x.getType().getSafeSymbol() + ") " + x.getSafeSymbol() + "_iterator->key();");
+        writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator.key();");
+    }
+
+    public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
+       VarDescriptor tmp=VarDescriptor.makeNew("flag");
+        writer.outputline("SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator();");
+       writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
+       writer.outputline("if ("+type+"=="+number+")");
+       writer.outputline(tmp.getSafeSymbol()+"=1;");
+       
+       writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&"+x.getSafeSymbol() + "_iterator->hasNext()))");
+        writer.startblock();
+        writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + ";");
+        writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + ";");
+       writer.outputline("if ("+type+"=="+number+")");
+       writer.startblock();
+       writer.outputline(tmp.getSafeSymbol()+"=0;");
+        writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + left + ";");
+        writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + right + ";");
+       writer.endblock();
+       writer.outputline("else");
+       writer.startblock();
+        writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->next();");        
+        writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->key();");
+       writer.endblock();
     }
 
     public int generate_worklistload(CodeWriter writer, int offset) {