continue;
for(Iterator fit=functions.iterator();fit.hasNext();) {
Function f=(Function)fit.next();
- if (rulesensurefunction(f))
+ if (rulesensurefunction(state,f,false))
continue; //no constraint needed to ensure
Set s=providesfunction(f);
}
}
- private boolean rulesensurefunction(Function f) {
+ /** This method determines whether the model definition rules
+ * ensure that the relation and evaluation domain descriped by f
+ * is either a function (if isPartial=false) or a partial function
+ * (if isPartial=true). */
+
+ static private boolean rulesensurefunction(State state,Function f, boolean isPartial) {
boolean foundrule=false;
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
SetDescriptor sd=e.getSet();
if (sd==null)
return false;
- if (!(sd.isSubset(f.getSet())||f.getSet().isSubset(sd)))
+ if (state.setanalysis.noIntersection(f.getSet(),sd))
continue; /* This rule doesn't effect the function */
if (foundrule) /* two different rules are a problem */
return false;
return false;
if (!sq.getSet().isSubset(f.getSet()))
return false;
- if (!((r.getGuardExpr() instanceof BooleanLiteralExpr)&&
- ((BooleanLiteralExpr)r.getGuardExpr()).getValue()==true))
+ if (!(((r.getGuardExpr() instanceof BooleanLiteralExpr)&&
+ ((BooleanLiteralExpr)r.getGuardExpr()).getValue()==true))||isPartial)
return false;
Expr e2=f.isInverse()?ri.getLeftExpr():ri.getRightExpr();
if (e2.isSafe())
return set;
}
+
+ /** This method determines whether the model definition rules
+ * ensure that the relation r (or inverse relation if inverse is
+ * true) evaluated on the domain sd is either a function (if
+ * isPartial=false) or a partial function (if isPartial=true). */
+
+ static public boolean rulesensurefunction(State state,RelationDescriptor r, SetDescriptor sd,boolean inverse, boolean isPartial) {
+ return rulesensurefunction(state, new Function(r,sd,inverse,null),isPartial);
+ }
+
public static class Function {
private RelationDescriptor rd;
private SetDescriptor sd;
SetAnalysis setanalysis;
public ImplicitSchema(State state) {
this.state=state;
- this.setanalysis=new SetAnalysis(state);
+ this.setanalysis=state.setanalysis;
}
public void update() {
if (supersets!=null)
for(Iterator superit=supersets.iterator();superit.hasNext();) {
SetDescriptor sd1=(SetDescriptor)superit.next();
+ Expr e=((SetInclusion)r.inclusion).getExpr();
+ while(e instanceof CastExpr) {
+ e=((CastExpr)e).getExpr();
+ }
+ if (e instanceof VarExpr) {
+ VarDescriptor vde=((VarExpr)e).getVar();
+ boolean ok=false;
+ for (int j=0;j<r.numQuantifiers();j++) {
+ Quantifier tmp=r.getQuantifier(j);
+ if (tmp instanceof SetQuantifier&&
+ ((SetQuantifier)tmp).getVar()==vde)
+ ok=true; /* Need to make sure we don't have a relation quantifier. */
+ }
+
+ SetDescriptor currentset=e.getSet();
+ if (ok&¤tset!=null&¤tset.isSubset(sd1))
+ continue; /* This rule doesn't add item to
+ this set, as item is already
+ in this set. */
+ }
+
Rule nr=new Rule();
nr.setGuardExpr(r.getGuardExpr());
nr.quantifiers=r.quantifiers;