*** empty log message ***
[repair.git] / Repair / RepairCompiler / MCC / IR / ComparisonPredicate.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class ComparisonPredicate extends Predicate {
6
7     VarDescriptor quantifier;
8     RelationDescriptor relation;
9     Opcode opcode;
10     Expr expr;
11
12     public ComparisonPredicate(VarDescriptor quantifier, RelationDescriptor relation, Opcode opcode, Expr expr) {
13         if (quantifier == null || relation == null || opcode == null || expr == null) {
14             throw new IllegalArgumentException();
15         } else if (opcode != Opcode.EQ &&
16                    opcode != Opcode.NE &&
17                    opcode != Opcode.GT &&
18                    opcode != Opcode.GE &&
19                    opcode != Opcode.LT &&
20                    opcode != Opcode.LE) {
21             throw new IllegalArgumentException("invalid operator type");
22         }
23        
24         this.quantifier = quantifier;
25         this.relation = relation;
26         this.opcode = opcode;
27         this.expr = expr;
28     }
29
30     public Set getRequiredDescriptors() {
31         assert expr != null;
32         Set v = expr.getRequiredDescriptors();
33         v.add(relation);
34         return v;
35     }
36
37     public int[] getRepairs(boolean negated) {
38         return new int[] {AbstractRepair.MODIFYRELATION};
39     }
40
41     public void generate(CodeWriter writer, VarDescriptor vd) {
42         // get (first) value for quantifer.relation ... then do comparison with expr... 
43         // can this be maybe? i guess if quantifer.relation is empty
44
45         String rv = (VarDescriptor.makeNew("relval")).getSafeSymbol();
46         writer.outputline("int " + rv + " = " + relation.getSafeSymbol() + "_hash->get(" + quantifier.getSafeSymbol() + ");");
47
48         // #TBD# deal with maybe (catch exception?)
49
50         VarDescriptor ev = VarDescriptor.makeNew("exprval");
51         expr.generate(writer, ev);
52
53         writer.outputline("int " + vd.getSafeSymbol() + " = " + rv + opcode.toString() + ev.getSafeSymbol() + ";");       
54     }
55
56 }
57     
58
59
60
61
62
63