Modify Generators to allow multiple specs
[repair.git] / Repair / RepairCompiler / MCC / IR / TupleOfExpr.java
index a726e044ba44901e497300782d9f6b2235075928..9b56fabe42c55bc23885b6f0f48ca8d665bfbb00 100755 (executable)
@@ -8,16 +8,59 @@ public class TupleOfExpr extends Expr {
     Expr right = null;
     RelationDescriptor relation = null;
 
+    public Set freeVars() {
+       Set lset=left.freeVars();
+       Set rset=right.freeVars();
+       if (lset==null)
+           return rset;
+       if (rset!=null)
+           lset.addAll(rset);
+       return lset;
+    }
+
     public TupleOfExpr(Expr left, Expr right, RelationDescriptor relation) {
         if ((left == null) || (right == null) || (relation == null)) {
             throw new NullPointerException();
         }
-        
+
         this.left = left;
         this.right = right;
         this.relation = relation;
     }
 
+    public String name() {
+       return "<"+left.name()+","+right.name()+"> in "+relation.toString();
+    }
+
+    public boolean usesDescriptor(Descriptor d) {
+       if (d==relation)
+           return true;
+       else
+           return left.usesDescriptor(d)||right.usesDescriptor(d);
+    }
+
+    public Set useDescriptor(Descriptor d) {
+       HashSet newset=new HashSet();
+       if (d==relation)
+           newset.add(this);
+       newset.addAll(left.useDescriptor(d));
+       newset.addAll(right.useDescriptor(d));
+       return newset;
+    }
+
+    public boolean equals(Map remap, Expr e) {
+       if (e==null||!(e instanceof TupleOfExpr))
+           return false;
+       TupleOfExpr toe=(TupleOfExpr)e;
+       if (!left.equals(remap,toe.left))
+           return false;
+       if (!right.equals(remap,toe.right))
+           return false;
+       if (relation!=toe.relation)
+           return false;
+       return true;
+    }
+
     public Set getRequiredDescriptors() {
         Set v = left.getRequiredDescriptors();
         v.addAll(right.getRequiredDescriptors());
@@ -32,8 +75,10 @@ public class TupleOfExpr extends Expr {
         VarDescriptor rd = VarDescriptor.makeNew();
         right.generate(writer, rd);
 
-        writer.outputline("int " + dest.getSafeSymbol() + " = " + 
-                          relation.getSafeSymbol() + "_hash->contains(" + 
+        writer.addDeclaration("int", dest.getSafeSymbol());
+
+        writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
+                          +relation.getSafeSymbol() +"_hash, "+
                           ld.getSafeSymbol() + ", " +
                           rd.getSafeSymbol() + ");");
     }
@@ -49,7 +94,7 @@ public class TupleOfExpr extends Expr {
     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
         TypeDescriptor ld = left.typecheck(sa);
         TypeDescriptor rd = right.typecheck(sa);
-        
+
         if (ld == null || rd == null) {
             return null;
         }