Exemplo n.º 1
0
 /**
  * This function obtains from a predicate that is a conjunction of assignments the assignment
  * related to an identifier
  *
  * @param specID The identifier of a variable in the specification
  * @param pred A predicate
  * @return the equality
  */
 public static MemPred getRelatedEquality(Pred pred, String specID) {
   AbstractRepository<Pred> predRep = pred.accept(new AndPredClausesExtractor());
   AbstractIterator<Pred> predIt = predRep.createIterator();
   while (predIt.hasNext()) {
     Pred auxPred = predIt.next();
     if (auxPred instanceof MemPred) {
       MemPred memPred = ((MemPred) auxPred);
       if (memPred.getMixfix()) {
         String id = ((RefExpr) memPred.getLeftExpr()).getName().toString();
         if (id.equals(specID)) {
           return memPred;
         }
       } else return null;
     } else return null;
   }
   return null;
 }
 /* (non-Javadoc)
  * @see pea.util.z.TermToCDDVisitor#visitMemPred(net.sourceforge.czt.z.ast.MemPred)
  */
 @Override
 public CDD visitMemPred(MemPred pred) {
   if (pred.getRightExpr() instanceof RefExpr) {
     final RefExpr refExpr = (RefExpr) pred.getRightExpr();
     final ZName name = refExpr.getZName();
     // We replace expressions like a != b + c with NOT(a = b + c)
     if (name.getOperatorName().getWord().equals(Z_NEQ_OPERATOR)) {
       final ZName newRefName = factory.createZName(Z_EQUALS_OPERATOR, name.getStrokeList());
       final RefExpr newRefExpr =
           factory.createRefExpr(newRefName, refExpr.getZExprList(), refExpr.getMixfix());
       final Pred newMemPred =
           factory.createMemPred(pred.getLeftExpr(), newRefExpr, pred.getMixfix());
       return newMemPred.accept(this).negate();
     }
   }
   return visitTerm(pred);
 }