5 public class SizeofPredicate extends Predicate {
9 IntegerLiteralExpr cardinality;
11 public SizeofPredicate(SetExpr setexpr, Opcode opcode, IntegerLiteralExpr cardinality) {
12 if (setexpr == null || opcode == null || cardinality == null) {
13 throw new IllegalArgumentException();
14 } else if (opcode != Opcode.EQ &&
15 opcode != Opcode.GE &&
16 opcode != Opcode.LE) {
17 throw new IllegalArgumentException("invalid operator type");
20 this.setexpr = setexpr;
22 this.cardinality = cardinality;
25 public int[] getRepairs(boolean negated) {
26 if (setexpr instanceof ImageSetExpr) {
27 if (opcode==Opcode.EQ)
28 return new int[] {AbstractRepair.ADDTORELATION,
29 AbstractRepair.REMOVEFROMRELATION};
30 if (((opcode==Opcode.GE)&&!negated)||
31 ((opcode==Opcode.LE)&&negated))
32 return new int[]{AbstractRepair.ADDTORELATION};
34 return new int[]{AbstractRepair.REMOVEFROMRELATION};
36 if (opcode==Opcode.EQ)
37 return new int[] {AbstractRepair.ADDTOSET,
38 AbstractRepair.REMOVEFROMSET};
40 if (((opcode==Opcode.GE)&&!negated)||
41 ((opcode==Opcode.LE)&&negated))
42 return new int[] {AbstractRepair.ADDTOSET};
44 return new int[] {AbstractRepair.REMOVEFROMSET};
48 public Set getRequiredDescriptors() {
49 assert setexpr != null;
50 Set v = setexpr.getRequiredDescriptors();
51 // v.add(cardinality.getRequiredDescriptors()); // will be null
55 public void generate(CodeWriter writer, VarDescriptor dest) {
57 // #TBD#: generate the set which should generate a name (variable) which is the pointer
58 // to a hash table iterator that we can dereference get something blah blah blah
60 VarDescriptor size = VarDescriptor.makeNew("size");
61 setexpr.generate_size(writer, size);
63 writer.outputline("int " + dest.getSafeSymbol() + " = " + size.getSafeSymbol() + opcode.toString() + cardinality.getValue() + ";");