This checkin eliminates cases in which the repair algorithm generates unnecessary...
[repair.git] / Repair / RepairCompiler / MCC / IR / AbstractRepair.java
1 package MCC.IR;
2
3 class AbstractRepair {
4     public final static int ADDTOSET=1;
5     public final static int REMOVEFROMSET=2;
6     public final static int ADDTORELATION=3;
7     public final static int REMOVEFROMRELATION=4;
8     public final static int MODIFYRELATION=5;
9
10     DNFPredicate torepair;
11     int type;
12     Descriptor descriptor;
13     Sources sources;
14
15     public String type() {
16         switch(type) {
17         case ADDTOSET:
18             return "AddToSet";
19         case REMOVEFROMSET:
20             return "RemoveToSet";
21         case ADDTORELATION:
22             return "AddToRelation";
23         case REMOVEFROMRELATION:
24             return "RemoveFromRelation";
25         case MODIFYRELATION:
26             return "ModifyRelation";
27         default:
28             return "Unknown";
29         }
30     }
31     
32     public SetDescriptor getDomainSet() {
33         if (torepair==null)
34             return null;
35         Predicate predicate=torepair.getPredicate();
36         if (!(predicate.getDescriptor() instanceof RelationDescriptor))
37             return null;
38
39         /* Have relation descriptor now */
40         if (predicate instanceof InclusionPredicate) {
41             InclusionPredicate ip=(InclusionPredicate)predicate;
42             if (ip.inverted())
43                 return ip.expr.getSet();
44             else if (ip.setexpr instanceof ImageSetExpr) {
45                 ImageSetExpr ise=(ImageSetExpr)ip.setexpr;
46                 if (ise.isimageset)
47                     return ise.getImageSetExpr().getSet();
48                 else
49                     return ise.getVar().getSet();
50             }
51         } else if (predicate instanceof ExprPredicate) {
52             ExprPredicate ep=(ExprPredicate)predicate;
53
54             if (ep.inverted()&&ep.getType()==ExprPredicate.SIZE)
55                 return sources.relgetSourceSet((RelationDescriptor)predicate.getDescriptor(),true);
56             else if (ep.inverted()&&ep.getType()==ExprPredicate.COMPARISON)
57                 return ((OpExpr)ep.expr).right.getSet();
58             else if (!ep.inverted()) {
59                 switch(ep.getType()) {
60                 case ExprPredicate.SIZE: 
61                     {
62                         SizeofExpr soe=((SizeofExpr)((OpExpr)ep.expr).left);
63                         ImageSetExpr ise=(ImageSetExpr)soe.setexpr;
64                         if (ise.isimageset)
65                             return ise.getImageSetExpr().getSet();
66                         else
67                             return ise.getVar().getSet();
68                     }
69                 case ExprPredicate.COMPARISON:
70                     {
71                         RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
72                         return ep.expr.getSet();
73                     }
74                 default:
75                     throw new Error("");
76                 }
77             }
78         } else throw new Error("Unrecognized predicate");
79         return null;
80     }
81
82     public SetDescriptor getRangeSet() {
83         if (torepair==null)
84             return null;
85         Predicate predicate=torepair.getPredicate();
86         if (!(predicate.getDescriptor() instanceof RelationDescriptor))
87             return null;
88
89         /* Have relation descriptor now */
90         if (predicate instanceof InclusionPredicate) {
91             InclusionPredicate ip=(InclusionPredicate)predicate;
92             if (!ip.inverted())
93                 return ip.expr.getSet();
94             else if (ip.setexpr instanceof ImageSetExpr) {
95                 ImageSetExpr ise=(ImageSetExpr)ip.setexpr;
96                 if (ise.isimageset)
97                     return ise.getImageSetExpr().getSet();
98                 else
99                     return ise.getVar().getSet();
100             }
101         } else if (predicate instanceof ExprPredicate) {
102             ExprPredicate ep=(ExprPredicate)predicate;
103
104             if (!ep.inverted()&&ep.getType()==ExprPredicate.SIZE)
105                 return sources.relgetSourceSet((RelationDescriptor)predicate.getDescriptor(),false);
106             else if (!ep.inverted()&&ep.getType()==ExprPredicate.COMPARISON)
107                 return ((OpExpr)ep.expr).right.getSet();
108             else if (ep.inverted()) {
109                 switch(ep.getType()) {
110                 case ExprPredicate.SIZE: 
111                     {
112                         SizeofExpr soe=((SizeofExpr)((OpExpr)ep.expr).left);
113                         ImageSetExpr ise=(ImageSetExpr)soe.setexpr;
114                         if (ise.isimageset)
115                             return ise.getImageSetExpr().getSet();
116                         else
117                             return ise.getVar().getSet();
118                     }
119                 case ExprPredicate.COMPARISON:
120                     {
121                         RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
122                         return ep.expr.getSet();
123                     }
124                 default:
125                     throw new Error("");
126                 }
127             }
128         } else throw new Error("Unrecognized predicate");
129         return null;
130     }
131
132
133     
134
135     public int getType() {
136         return type;
137     }
138
139     public DNFPredicate getPredicate() {
140         return torepair;
141     }
142
143     public Descriptor getDescriptor() {
144         return descriptor;
145     }
146
147     public AbstractRepair(DNFPredicate dp,int typ, Descriptor d, Sources s) {
148         torepair=dp;
149         type=typ;
150         descriptor=d;
151         sources=s;
152     }
153 }