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 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
41 String rv = (VarDescriptor.makeNew("relval")).getSafeSymbol();
42 writer.outputline("int " + rv + " = " + relation.getSafeSymbol() + "_hash->get(" + quantifier.getSafeSymbol() + ");");
44 // #TBD# deal with maybe (catch exception?)
46 VarDescriptor ev = VarDescriptor.makeNew("exprval");
47 expr.generate(writer, ev);
49 writer.outputline("int " + vd.getSafeSymbol() + " = " + rv + opcode.toString() + ev.getSafeSymbol() + ";");