5 public final static int ADDTOSET=1;
6 public final static int REMOVEFROMSET=2;
7 public final static int ADDTORELATION=3;
8 public final static int REMOVEFROMRELATION=4;
9 public final static int MODIFYRELATION=5;
11 DNFPredicate torepair;
13 Descriptor descriptor;
16 public String type() {
23 return "AddToRelation";
24 case REMOVEFROMRELATION:
25 return "RemoveFromRelation";
27 return "ModifyRelation";
33 public boolean isNewObject(boolean isdomain) {
34 if (getType()==ADDTOSET) {
35 return sources.allocSource((SetDescriptor)descriptor);
36 } else if (getType()==ADDTORELATION) {
37 RelationDescriptor rd=(RelationDescriptor)descriptor;
38 return sources.relallocSource(rd,isdomain);
39 } else throw new Error(type());
42 public SetDescriptor getDomainSet() {
45 Predicate predicate=torepair.getPredicate();
46 if (!(predicate.getDescriptor() instanceof RelationDescriptor))
49 /* Have relation descriptor now */
50 if (predicate instanceof InclusionPredicate) {
51 InclusionPredicate ip=(InclusionPredicate)predicate;
53 return ip.expr.getSet();
54 else if (ip.setexpr instanceof ImageSetExpr) {
55 ImageSetExpr ise=(ImageSetExpr)ip.setexpr;
57 return ise.getImageSetExpr().getSet();
59 return ise.getVar().getSet();
61 } else if (predicate instanceof ExprPredicate) {
62 ExprPredicate ep=(ExprPredicate)predicate;
64 if (ep.inverted()&&ep.getType()==ExprPredicate.SIZE)
65 return sources.relgetSourceSet((RelationDescriptor)predicate.getDescriptor(),true);
66 else if (ep.inverted()&&ep.getType()==ExprPredicate.COMPARISON)
67 return ((OpExpr)ep.expr).right.getSet();
68 else if (!ep.inverted()) {
69 switch(ep.getType()) {
70 case ExprPredicate.SIZE:
72 SizeofExpr soe=((SizeofExpr)((OpExpr)ep.expr).left);
73 ImageSetExpr ise=(ImageSetExpr)soe.setexpr;
75 return ise.getImageSetExpr().getSet();
77 return ise.getVar().getSet();
79 case ExprPredicate.COMPARISON:
81 RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
82 return re.expr.getSet();
88 } else throw new Error("Unrecognized predicate");
92 public SetDescriptor getRangeSet() {
95 Predicate predicate=torepair.getPredicate();
96 if (!(predicate.getDescriptor() instanceof RelationDescriptor))
99 /* Have relation descriptor now */
100 if (predicate instanceof InclusionPredicate) {
101 InclusionPredicate ip=(InclusionPredicate)predicate;
103 return ip.expr.getSet();
104 else if (ip.setexpr instanceof ImageSetExpr) {
105 ImageSetExpr ise=(ImageSetExpr)ip.setexpr;
107 return ise.getImageSetExpr().getSet();
109 return ise.getVar().getSet();
111 } else if (predicate instanceof ExprPredicate) {
112 ExprPredicate ep=(ExprPredicate)predicate;
114 if (!ep.inverted()&&ep.getType()==ExprPredicate.SIZE)
115 return sources.relgetSourceSet((RelationDescriptor)predicate.getDescriptor(),false);
116 else if (!ep.inverted()&&ep.getType()==ExprPredicate.COMPARISON)
117 return ((OpExpr)ep.expr).right.getSet();
118 else if (ep.inverted()) {
119 switch(ep.getType()) {
120 case ExprPredicate.SIZE:
122 SizeofExpr soe=((SizeofExpr)((OpExpr)ep.expr).left);
123 ImageSetExpr ise=(ImageSetExpr)soe.setexpr;
125 return ise.getImageSetExpr().getSet();
127 return ise.getVar().getSet();
129 case ExprPredicate.COMPARISON:
131 RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
132 return re.expr.getSet();
138 } else throw new Error("Unrecognized predicate");
142 public int getType() {
146 public DNFPredicate getPredicate() {
150 public Descriptor getDescriptor() {
155 /** This method tells whether the repair needs to remove objects *
156 * from the relation, or whether the model definition rules make
157 * the remove unnecessary.*/
159 public boolean needsRemoves(State state) {
160 assert type==MODIFYRELATION;
161 SetDescriptor sd=getPredicate().getPredicate().inverted()?getRangeSet():getDomainSet();
162 return !ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), true);
165 /** This method tells whether the repair needs to force the
166 * relation to be function-like. */
168 public boolean mayNeedFunctionEnforcement(State state) {
169 assert type==MODIFYRELATION;
170 SetDescriptor sd=getPredicate().getPredicate().inverted()?getRangeSet():getDomainSet();
171 if (ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), false))
173 if (ConstraintDependence.constraintsensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(),false))
178 public AbstractRepair(DNFPredicate dp,int typ, Descriptor d, Sources s) {