5 public class ComparisonPredicate extends Predicate {
7 VarDescriptor quantifier;
8 RelationDescriptor relation;
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");
24 this.quantifier = quantifier;
25 this.relation = relation;
30 public Set getRequiredDescriptors() {
32 Set v = expr.getRequiredDescriptors();
37 public int[] getRepairs(boolean negated) {
38 return new int[] {AbstractRepair.MODIFYRELATION};
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
45 String rv = (VarDescriptor.makeNew("relval")).getSafeSymbol();
46 writer.outputline("int " + rv + " = " + relation.getSafeSymbol() + "_hash->get(" + quantifier.getSafeSymbol() + ");");
48 // #TBD# deal with maybe (catch exception?)
50 VarDescriptor ev = VarDescriptor.makeNew("exprval");
51 expr.generate(writer, ev);
53 writer.outputline("int " + vd.getSafeSymbol() + " = " + rv + opcode.toString() + ev.getSafeSymbol() + ";");