Ejemplo n.º 1
0
 @Override
 public void visit(Rule rule) {
   rule.leftHandSide().accept(this);
   rule.rightHandSide().accept(this);
   rule.lookups().accept(this);
   for (Term term : rule.requires()) {
     term.accept(this);
   }
   for (Term term : rule.ensures()) {
     term.accept(this);
   }
   for (Variable variable : rule.freshVariables()) {
     variable.accept(this);
   }
 }
Ejemplo n.º 2
0
 @Override
 public void visit(SetUpdate setUpdate) {
   setUpdate.base().accept(this);
   for (Term key : setUpdate.removeSet()) {
     key.accept(this);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void visit(KCollectionFragment kCollectionFragment) {
   for (Term term : kCollectionFragment) {
     term.accept(this);
   }
   visit((Collection) kCollectionFragment);
 }
Ejemplo n.º 4
0
 @Override
 public void visit(BuiltinSet builtinSet) {
   for (Term term : builtinSet.elements()) {
     term.accept(this);
   }
   //        for (BuiltinSet.Operation operation : builtinSet.operations()) {
   //            operation.element().accept(this);
   //        }
   visit((Collection) builtinSet);
 }
Ejemplo n.º 5
0
 @Override
 public void visit(BuiltinSet node) {
   if (node.isGround() && node.isNormal()) {
     rhsSchedule.add(RHSInstruction.PUSH(node));
   } else {
     int sizeBase = 0;
     for (Term base : node.baseTerms()) {
       base.accept(this);
       sizeBase++;
     }
     int sizeElem = 0;
     for (Term elem : node.elements()) {
       elem.accept(this);
       sizeElem++;
     }
     rhsSchedule.add(
         RHSInstruction.CONSTRUCT(
             new Constructor(ConstructorType.BUILTIN_SET, sizeElem, sizeBase)));
   }
 }
Ejemplo n.º 6
0
 @Override
 public void visit(MapUpdate mapUpdate) {
   mapUpdate.map().accept(this);
   for (Term key : mapUpdate.removeSet()) {
     key.accept(this);
   }
   for (java.util.Map.Entry<Term, Term> entry : mapUpdate.updateMap().entrySet()) {
     entry.getKey().accept(this);
     entry.getValue().accept(this);
   }
 }
Ejemplo n.º 7
0
 @Override
 public void visit(KList node) {
   if (node.isGround() && node.isNormal()) {
     rhsSchedule.add(RHSInstruction.PUSH(node));
   } else {
     int size = 0;
     if (node.hasFrame()) {
       node.frame().accept(this);
       size++;
     }
     for (int i = node.concreteSize() - 1; i >= 0; i--) {
       Term k = node.get(i);
       k.accept(this);
       size++;
     }
     rhsSchedule.add(RHSInstruction.CONSTRUCT(new Constructor(ConstructorType.KLIST, size)));
   }
 }
Ejemplo n.º 8
0
 @Override
 public void visit(BuiltinMap node) {
   if (node.isGround() && node.isNormal()) {
     rhsSchedule.add(RHSInstruction.PUSH(node));
   } else {
     int sizeBase = 0;
     for (Term base : node.baseTerms()) {
       base.accept(this);
       sizeBase++;
     }
     int sizeElem = 0;
     for (Map.Entry<Term, Term> entry : node.getEntries().entrySet()) {
       entry.getValue().accept(this);
       entry.getKey().accept(this);
       sizeElem++;
     }
     rhsSchedule.add(
         RHSInstruction.CONSTRUCT(
             new Constructor(ConstructorType.BUILTIN_MAP, sizeElem, sizeBase)));
   }
 }
Ejemplo n.º 9
0
 public static Term expand(
     Term term, SymbolicConstraint constraint, boolean narrow, TermContext context) {
   return (Term) term.accept(new PatternExpander(constraint, narrow, context));
 }
Ejemplo n.º 10
0
 @Override
 public void visit(BuiltinList node) {
   if (node.hasFrame()) node.frame().accept(this);
   for (Term t : node.elementsLeft()) t.accept(this);
   for (Term t : node.elementsRight()) t.accept(this);
 }
Ejemplo n.º 11
0
  @Override
  public ASTNode transform(KItem kItem) {
    if (!(kItem.kLabel() instanceof KLabelConstant)) {
      throw new UnsupportedOperationException();
    }
    KLabelConstant kLabel = (KLabelConstant) kItem.kLabel();

    if (!(kItem.kList() instanceof KList)) {
      throw new UnsupportedOperationException();
    }
    KList kList = (KList) kItem.kList();

    if (kList.hasFrame()) {
      throw new UnsupportedOperationException();
    }

    String label = kLabel.smtlib();
    if (label == null) {
      throw new UnsupportedOperationException("missing SMTLib translation for " + kLabel);
    }

    if (label.startsWith("(")) {
      // smtlib expression instead of operator
      String expression = label;
      for (int i = 0; i < kList.getContents().size(); i++) {
        expression =
            expression.replaceAll(
                "\\#" + (i + 1) + "(?![0-9])",
                ((SMTLibTerm) kList.get(i).accept(this)).expression());
      }
      return new SMTLibTerm(expression);
    }

    List<Term> arguments;
    switch (label) {
      case "exists":
        Variable variable = (Variable) kList.get(0);
        label = "exists ((" + variable.name() + " " + variable.sort() + ")) ";
        arguments = ImmutableList.of(kList.get(1));
        break;
      case "extract":
        int beginIndex = ((IntToken) kList.get(1)).intValue();
        int endIndex = ((IntToken) kList.get(2)).intValue() - 1;
        label = "(_ extract " + endIndex + " " + beginIndex + ")";
        arguments = ImmutableList.of(kList.get(0));
        break;
      default:
        arguments = kList.getContents();
    }

    if (!arguments.isEmpty()) {
      StringBuilder sb = new StringBuilder();
      sb.append("(");
      sb.append(label);
      for (Term argument : arguments) {
        sb.append(" ");
        sb.append(((SMTLibTerm) argument.accept(this)).expression());
      }
      sb.append(")");
      return new SMTLibTerm(sb.toString());
    } else {
      return new SMTLibTerm(label);
    }
  }