1) Added useDescriptor method to Expr's.
[repair.git] / Repair / RepairCompiler / MCC / IR / RelationExpr.java
index fc2a4c7dabcc76494438fefd1e821e7c9b42b4bf..def95760ec410a02395af921ecd83525c7a797ed 100755 (executable)
@@ -8,22 +8,72 @@ public class RelationExpr extends Expr {
     RelationDescriptor relation;
     boolean inverse;
 
+    public Set getfunctions() {
+       HashSet functions=new HashSet();
+       Set exprfunctions=expr.getfunctions();
+       if (exprfunctions!=null)
+           functions.addAll(exprfunctions);
+       functions.add(new ConstraintDependence.Function(relation,expr.getSet(),inverse));
+       
+       return functions;
+    }
+
+    public SetDescriptor getSet() {
+       if (inverse)
+           return relation.domain;
+       else
+           return relation.range;
+    }
+
     public RelationExpr(Expr expr, RelationDescriptor relation, boolean inverse) {
         this.expr = expr;
         this.relation = relation;
         this.inverse = inverse;
     }
 
+    public Set freeVars() {
+       return expr.freeVars();
+    }
+
+    public String name() {
+       String name=expr.name()+".";
+       if (inverse)
+           name+="~";
+       name+=relation.toString();
+       return name;
+    }
+
     public Expr getExpr() {
         return expr;
     }
 
-    public boolean usesDescriptor(RelationDescriptor rd) {
+    public boolean equals(Map remap, Expr e) {
+       if (e==null||!(e instanceof RelationExpr))
+           return false;
+       RelationExpr re=(RelationExpr)e;
+       if (re.relation!=relation)
+           return false;
+       if (!expr.equals(remap,re.expr))
+           return false;
+       if (inverse!=re.inverse)
+           return false;
+       return true;
+    }
+
+    public boolean usesDescriptor(Descriptor rd) {
        if (rd==relation)
            return true;
        else
            return expr.usesDescriptor(rd);
     }
+
+    public Set useDescriptor(Descriptor rd) {
+       HashSet newset=new HashSet();
+       if (rd==relation)
+           newset.add(this);
+       newset.addAll(expr.useDescriptor(rd));
+       return newset;
+    }
     
     public RelationDescriptor getRelation() {
         return relation;