コード例 #1
0
 private static void flattenKList(
     List<org.kframework.kil.Term> flatList, List<org.kframework.kil.Term> nestedList) {
   for (org.kframework.kil.Term term : nestedList) {
     if (term instanceof org.kframework.kil.KList) {
       org.kframework.kil.KList kList = (org.kframework.kil.KList) term;
       KILtoBackendJavaKILTransformer.flattenKList(flatList, kList.getContents());
     } else {
       flatList.add(term);
     }
   }
 }
コード例 #2
0
 private static void flattenBag(
     List<org.kframework.kil.Term> flatBag, List<org.kframework.kil.Term> nestedBag) {
   for (org.kframework.kil.Term term : nestedBag) {
     if (term instanceof org.kframework.kil.Bag) {
       org.kframework.kil.Bag bag = (org.kframework.kil.Bag) term;
       KILtoBackendJavaKILTransformer.flattenBag(flatBag, bag.getContents());
     } else {
       flatBag.add(term);
     }
   }
 }
コード例 #3
0
ファイル: JavaSymbolicProver.java プロジェクト: sal000-000/k
  @Override
  public KRunProofResult<Set<org.kframework.kil.Term>> prove(Module module)
      throws KRunExecutionException {
    TermContext termContext = TermContext.of(globalContext);
    List<Rule> rules = new ArrayList<Rule>();
    for (org.kframework.kil.ModuleItem moduleItem : module.getItems()) {
      if (!(moduleItem instanceof org.kframework.kil.Rule)) {
        continue;
      }

      Rule rule = transformer.transformAndEval((org.kframework.kil.Rule) moduleItem);
      Rule freshRule = rule.getFreshRule(termContext);
      rules.add(freshRule);
    }

    CounterGetter counterGetter = new CounterGetter(context);
    counterGetter.visitNode(module);
    BigInteger counter = counterGetter.counter.add(BigInteger.ONE);

    SymbolicRewriter symbolicRewriter = executor.getSymbolicRewriter();
    List<ConstrainedTerm> proofResults = new ArrayList<>();
    for (org.kframework.kil.ModuleItem moduleItem : module.getItems()) {
      if (!(moduleItem instanceof org.kframework.kil.Rule)
          || moduleItem.containsAttribute(Attribute.TRUSTED_KEY)) {
        continue;
      }

      termContext.setCounter(counter);
      Rule rule = transformer.transformAndEval((org.kframework.kil.Rule) moduleItem);
      ConstrainedTerm initialTerm =
          new ConstrainedTerm(
              rule.leftHandSide(), ConjunctiveFormula.of(termContext).addAll(rule.requires()));
      ConstrainedTerm targetTerm =
          new ConstrainedTerm(
              rule.rightHandSide(), ConjunctiveFormula.of(termContext).addAll(rule.ensures()));
      proofResults.addAll(symbolicRewriter.proveRule(initialTerm, targetTerm, rules));
    }

    return new KRunProofResult<>(
        proofResults.isEmpty(), Collections.<org.kframework.kil.Term>emptySet());
  }
コード例 #4
0
  @Override
  public ASTNode transform(org.kframework.kil.KList node) throws TransformerException {
    List<org.kframework.kil.Term> list = new ArrayList<org.kframework.kil.Term>();
    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.KSorts.KLIST)) {
      variable = (Variable) list.remove(list.size() - 1).accept(this);
    }

    ImmutableList.Builder<Term> builder = new ImmutableList.Builder<Term>();
    for (org.kframework.kil.Term term : list) {
      builder.add((Term) term.accept(this));
    }

    return new KList(builder.build(), variable);
  }
コード例 #5
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();
  }
コード例 #6
0
  @Override
  public ASTNode transform(org.kframework.kil.Cell node) throws TransformerException {
    if (node.getContents() instanceof org.kframework.kil.Bag
        || node.getContents() instanceof org.kframework.kil.Cell) {
      List<org.kframework.kil.Term> contents;
      if (node.getContents() instanceof org.kframework.kil.Bag) {
        contents = new ArrayList<org.kframework.kil.Term>();
        KILtoBackendJavaKILTransformer.flattenBag(
            contents, ((org.kframework.kil.Bag) node.getContents()).getContents());
      } else {
        contents = Collections.singletonList(node.getContents());
      }

      Multimap<String, Cell> cells = HashMultimap.create();
      Variable variable = null;
      for (org.kframework.kil.Term term : contents) {
        if (term instanceof org.kframework.kil.Cell) {
          Cell cell = (Cell) term.accept(this);
          cells.put(cell.getLabel(), cell);
        } else if (variable == null
            && term instanceof org.kframework.kil.Variable
            && term.getSort().equals("Bag")) {
          variable = (Variable) term.accept(this);
        } else {
          throw new RuntimeException();
        }
      }

      // TODO(AndreiS): get the multiplicity
      boolean isStar = !cells.isEmpty() && cells.keySet().iterator().next().equals("thread");

      return new Cell<CellCollection>(node.getLabel(), new CellCollection(cells, variable, isStar));
    } else {
      Term content = (Term) node.getContents().accept(this);

      if (content instanceof KItem) {
        return new Cell<KItem>(node.getLabel(), (KItem) content);
      } else if (content instanceof Token) {
        return new Cell<Token>(node.getLabel(), (Token) content);
      } else if (content instanceof KSequence) {
        return new Cell<KSequence>(node.getLabel(), (KSequence) content);
      } else if (content instanceof KList) {
        return new Cell<KList>(node.getLabel(), (KList) content);
      } else if (content instanceof BuiltinList) {
        return new Cell<BuiltinList>(node.getLabel(), (BuiltinList) content);
        //            } else if (content instanceof ListUpdate) {
        //                return new Cell<ListUpdate>(node.getLabel(), (ListUpdate) content);
      } else if (content instanceof BuiltinSet) {
        return new Cell<BuiltinSet>(node.getLabel(), (BuiltinSet) content);
      } else if (content instanceof SetUpdate) {
        return new Cell<SetUpdate>(node.getLabel(), (SetUpdate) content);
      } else if (content instanceof BuiltinMap) {
        return new Cell<BuiltinMap>(node.getLabel(), (BuiltinMap) content);
      } else if (content instanceof MapUpdate) {
        return new Cell<MapUpdate>(node.getLabel(), (MapUpdate) content);
      } else if (content instanceof Variable) {
        return new Cell<Term>(node.getLabel(), content);
      } else {
        throw new RuntimeException();
      }
    }
  }