Ejemplo n.º 1
0
  @Override
  public ASTNode visit(org.kframework.kil.KApp node, Void _void) {
    if (node.getLabel() instanceof org.kframework.kil.Token) {
      if (node.getLabel() instanceof BoolBuiltin) {
        return BoolToken.of(((BoolBuiltin) node.getLabel()).booleanValue());
      } else if (node.getLabel() instanceof IntBuiltin) {
        return IntToken.of(((IntBuiltin) node.getLabel()).bigIntegerValue());
      } else if (node.getLabel() instanceof StringBuiltin) {
        return StringToken.of(((StringBuiltin) node.getLabel()).stringValue());
      } else if (node.getLabel() instanceof FloatBuiltin) {
        return FloatToken.of(
            ((FloatBuiltin) node.getLabel()).bigFloatValue(),
            ((FloatBuiltin) node.getLabel()).exponent());
      } else if (node.getLabel() instanceof GenericToken) {
        return UninterpretedToken.of(
            Sort.of(((GenericToken) node.getLabel()).tokenSort()),
            ((GenericToken) node.getLabel()).value());
      } else {
        assert false : "unsupported Token " + node.getLabel();
      }
    }

    Term kLabel = (Term) this.visitNode(node.getLabel());
    Term kList = (Term) this.visitNode(node.getChild());
    if (kList instanceof Variable) {
      kList = kList.sort().equals(Sort.KLIST) ? kList : KList.singleton(kList);
    }
    return KItem.of(kLabel, kList, termContext, node.getSource(), node.getLocation());
  }
Ejemplo n.º 2
0
  @Override
  public ASTNode visit(org.kframework.kil.KList node, Void _void) {
    List<org.kframework.kil.Term> list = new ArrayList<>();
    KILtoBackendJavaKILTransformer.flattenKList(list, node.getContents());

    Variable variable = null;
    if (!list.isEmpty()
        && list.get(list.size() - 1) instanceof org.kframework.kil.Variable
        && list.get(list.size() - 1).getSort().equals(org.kframework.kil.Sort.KLIST)) {
      variable = (Variable) this.visitNode(list.remove(list.size() - 1));
    }

    KList.Builder builder = KList.builder();
    for (org.kframework.kil.Term term : list) {
      builder.concatenate((Term) this.visitNode(term));
    }
    if (variable != null) {
      builder.concatenate(variable);
    }

    return builder.build();
  }
Ejemplo n.º 3
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.º 4
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);
    }
  }