Added support to printout data structure update nodes (bindings/updates)
[repair.git] / Repair / RepairCompiler / MCC / IR / ConcreteInterferes.java
1 package MCC.IR;
2 import java.util.*;
3
4 class ConcreteInterferes {
5     static public boolean interferes(MultUpdateNode mun, Rule r, boolean satisfy) {
6         for(int i=0;i<mun.numUpdates();i++) {
7             UpdateNode un=mun.getUpdate(i);
8             for (int j=0;j<un.numUpdates();j++) {
9                 Updates update=un.getUpdate(j);
10                 
11                 DNFRule drule=r.getDNFGuardExpr();
12                 if (satisfy)
13                     drule=r.getDNFNegGuardExpr();
14
15                 if (!update.isAbstract()) {
16                     Descriptor updated_des=update.getDescriptor();
17                     assert updated_des!=null;
18                     if (r.getInclusion().usesDescriptor(updated_des))
19                         return true; /* Interferes with inclusion condition */
20                     
21                     for(int k=0;k<drule.size();k++) {
22                         RuleConjunction rconj=drule.get(k);
23                         for(int l=0;l<rconj.size();l++) {
24                             DNFExpr dexpr=rconj.get(l);
25                             /* See if update interferes w/ dexpr */
26                             if (interferes(un,update, r,dexpr))
27                                 return true;
28                         }
29                     }
30                 }
31             }
32         }
33         return false;
34     }
35
36     static private boolean interferes(UpdateNode un,Updates update, Rule r,DNFExpr dexpr) {
37         Descriptor descriptor=update.getDescriptor();
38         if (!dexpr.getExpr().usesDescriptor(descriptor))
39             return false;
40         /* We need to pair the variables */
41         if (update.isExpr()) {
42             Set vars=update.getRightExpr().freeVars();
43             Opcode op1=update.getOpcode();
44             Expr lexpr1=update.getLeftExpr();
45             Expr rexpr1=update.getRightExpr();
46             boolean good=true;
47             for(Iterator it=vars.iterator();it.hasNext();) {
48                 VarDescriptor vd=(VarDescriptor) it.next();
49                 if (un.getBinding(vd)!=null) {
50                     /* VarDescriptor isn't a global */
51                     if (update.getVar()!=vd) {
52                         good=false;
53                         break;
54                     }
55                 }
56             }
57             if (good&&(dexpr.getExpr() instanceof OpExpr)) {
58                 OpExpr expr=(OpExpr)dexpr.getExpr();
59                 Expr lexpr2=expr.getLeftExpr();
60                 Expr rexpr2=expr.getRightExpr();
61                 Opcode op2=expr.getOpcode();
62                 if (dexpr.getNegation()) {
63                     /* remove negation through opcode translation */
64                     if (op2==Opcode.GT)
65                         op2=Opcode.LE;
66                     else if (op2==Opcode.GE)
67                         op2=Opcode.LT;
68                     else if (op2==Opcode.EQ)
69                         op2=Opcode.NE;
70                     else if (op2==Opcode.NE)
71                         op2=Opcode.EQ;
72                     else if (op2==Opcode.LT)
73                         op2=Opcode.GE;
74                     else if (op2==Opcode.LE)
75                         op2=Opcode.GT;
76                 }
77                 good=true;
78                 vars=rexpr2.freeVars();
79                 VarDescriptor leftdescriptor=null;
80                 if (lexpr2 instanceof VarExpr)
81                     leftdescriptor=((VarExpr)lexpr2).getVar();
82                 else if (lexpr2 instanceof DotExpr) {
83                     Expr e=lexpr2;
84                     for(;e instanceof DotExpr;e=((DotExpr)e).getExpr()) ;
85                     leftdescriptor=((VarExpr)e).getVar();
86                 } else throw new Error("Bad Expr");
87                 
88                 for(Iterator it=vars.iterator();it.hasNext();) {
89                     VarDescriptor vd=(VarDescriptor) it.next();
90                     if (un.getBinding(vd)!=null) {
91                         /* VarDescriptor isn't a global */
92                         if (leftdescriptor!=vd) {
93                             good=false;
94                             break;
95                         }
96                     }
97                 }
98                 if (good) {
99                     HashMap remap=new HashMap();
100                     remap.put(update.getVar(),leftdescriptor);
101                     if ((op1==op2)&&
102                         lexpr1.equals(remap,lexpr2)&&
103                         rexpr1.equals(remap,rexpr2))
104                         return false;
105                 }
106             }
107         }
108         return true;
109     }
110 }