model and checks
[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 void generate(CodeWriter writer, VarDescriptor vd) {
38         // get (first) value for quantifer.relation ... then do comparison with expr... 
39         // can this be maybe? i guess if quantifer.relation is empty
40
41         String rv = (VarDescriptor.makeNew("relval")).getSafeSymbol();
42         writer.outputline("int " + rv + " = " + relation.getSafeSymbol() + "_hash->get(" + quantifier.getSafeSymbol() + ");");
43
44         // #TBD# deal with maybe (catch exception?)
45
46         VarDescriptor ev = VarDescriptor.makeNew("exprval");
47         expr.generate(writer, ev);
48
49         writer.outputline("int " + vd.getSafeSymbol() + " = " + rv + opcode.toString() + ev.getSafeSymbol() + ";");       
50     }
51
52 }
53     
54
55
56
57
58
59