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 void visit(KItem node) {
   if (node.isGround() && node.isNormal()) {
     rhsSchedule.add(RHSInstruction.PUSH(node));
   } else {
     node.kList().accept(this);
     node.kLabel().accept(this);
     rhsSchedule.add(
         RHSInstruction.CONSTRUCT(
             new Constructor(ConstructorType.KITEM, node.getSource(), node.getLocation())));
     rhsSchedule.add(RHSInstruction.EVAL);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void visit(KItem kItem) {
   kItem.kLabel().accept(this);
   kItem.kList().accept(this);
   visit((Term) kItem);
 }
Ejemplo n.º 4
0
 public ASTNode transform(KItem kItem) {
   return kItem.expandPattern(constraint, narrow, context);
 }
Ejemplo n.º 5
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);
    }
  }