5 public class InclusionPredicate extends Predicate {
10 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
11 TypeDescriptor t=expr.typecheck(sa);
12 TypeDescriptor ts=setexpr.typecheck(sa);
13 if (t instanceof StructureTypeDescriptor) {
14 while(((StructureTypeDescriptor)t).getSuperType()!=null)
15 t=((StructureTypeDescriptor)t).getSuperType();
17 if (ts instanceof StructureTypeDescriptor) {
18 while(((StructureTypeDescriptor)ts).getSuperType()!=null)
19 ts=((StructureTypeDescriptor)ts).getSuperType();
24 return ReservedTypeDescriptor.INT;
27 public boolean inverted() {
28 return setexpr.inverted();
31 public String name() {
32 return expr.name() + " in "+setexpr.name();
35 public InclusionPredicate(Expr expr, SetExpr setexpr) {
37 throw new NullPointerException();
40 if (setexpr == null) {
41 throw new NullPointerException();
45 this.setexpr = setexpr;
48 public Set getRequiredDescriptors() {
49 Set v = expr.getRequiredDescriptors();
50 v.addAll(setexpr.getRequiredDescriptors());
54 public void generate(CodeWriter writer, VarDescriptor dest) {
55 VarDescriptor var = VarDescriptor.makeNew("exprval");
56 expr.generate(writer, var);
57 setexpr.generate_inclusion(writer, dest, var);
60 public Set getInversedRelations() {
62 throw new IRException("unsupported");
64 //Set set = setexpr.getInversedRelations();
65 //set.addAll(expr.getInversedRelations());
69 public Descriptor getDescriptor() {
70 if (setexpr instanceof ImageSetExpr) {
71 return ((ImageSetExpr)setexpr).getRelation();
76 public int[] getRepairs(boolean negated, Termination t) {
77 if (setexpr instanceof ImageSetExpr) {
79 return new int[] {AbstractRepair.REMOVEFROMRELATION};
81 return new int[] {AbstractRepair.ADDTORELATION};
84 return new int[] {AbstractRepair.REMOVEFROMSET};
86 return new int[] {AbstractRepair.ADDTOSET};