Ejemplo n.º 1
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.º 2
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);
    }
  }