private static K makeBody(List<K> children) { if (children.size() == 1) { return children.get(0); } else { return KApply(KLabels.CELLS, KList(children)); } }
private K addFreshCell(K body) { if (freshVars.size() == 0) { return body; } KApply cellTerm = IncompleteCellUtils.make(KLabels.GENERATED_COUNTER_CELL, false, KRewrite(FRESH, KApply(KLabel("_+Int_"), FRESH, KToken(Integer.toString(freshVars.size()), Sorts.Int()))), false); return KApply(KLabels.CELLS, body, cellTerm); }
private K kApplyConversion(K k) { if (k instanceof KItem) { KItem kItem = (KItem) k; return KORE.KApply(kItem.klabel(), kItem.klist()); } return k; }
@Test public void testConcreteTop() { parseTerm(".As", "As", NIL); parseTerm("a,a", "As", KApply(CONS, A, KApply(CONS, A, NIL))); parseTerm("a,.As", "As", KApply(CONS, A, NIL)); parseTerm("a,b", "As", KApply(CONS, A, KApply(CONS, B, NIL))); parseTerm("b,.Bs", "As", KApply(CONS, B, NIL)); parseTerm("b,b", "As", KApply(CONS, B, KApply(CONS, B, NIL))); }
private Rule getExitCodeRule(Definition parsedDefinition) { Module mainMod = parsedDefinition.mainModule(); Set<Production> exitProds = stream(mainMod.productions()).filter(p -> p.att().contains("exit")).collect(Collectors.toSet()); if (exitProds.size() == 0) { return null; } else if (exitProds.size() > 1) { throw KEMException.compilerError("Found more than one or zero productions with 'exit' attribute. Exactly one production, a cell, must have this attribute, designating the exit code of krun. Found:\n" + exitProds); } Production exitProd = exitProds.iterator().next(); return Rule(IncompleteCellUtils.make(exitProd.klabel().get(), false, KApply(KLabel("#SemanticCastToInt"), KVariable("_")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); }
@Override public K apply(KApply k) { if (k.klabel() instanceof KVariable && predicates.containsKey(k.klabel())) { return KApply(apply(k.klabel()), k.klist().items().stream().map(this::apply).collect(org.kframework.Collections.toList()), k.att()); } return super.apply(k); }
private Rule funRule(KLabel fun, K k, Att att) { K resolved = transform(k); K withAnonVars = new ResolveAnonVar().resolveK(resolved); List<K> klist = new ArrayList<>(); klist.add(RewriteToTop.toLeft(withAnonVars)); klist.addAll(closure(k)); return Rule(KRewrite(KApply(fun, KList(klist)), RewriteToTop.toRight(withAnonVars)), BooleanUtils.TRUE, BooleanUtils.TRUE, att); }
@Override public K apply(KApply k) { k = (KApply) super.apply(k); return KApply(apply(k.klabel()), k.klist(), k.att()); }
@Ignore("The API of AddEmptyLists needs to change for this to be possible") @Test public void testItem() { parseTerm("a", "As", KApply(CONS, A, NIL)); }
@Override public K apply(KApply k) { if (k.att().contains("dummy_cell")) { KLabel klabel = KLabel(k.klabel().name() + "-fragment"); return KApply(klabel, k.klist(), k.att()); } return super.apply(k); } }.apply(term);
private static Set<Sentence> genProjection(Sort sort, Module m) { KLabel lbl = getProjectLbl(sort, m); KVariable var = KVariable("K", Att.empty().add(Sort.class, sort)); Rule r = Rule(KRewrite(KApply(lbl, var), var), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("projection")); if (m.definedKLabels().contains(lbl)) { return Set(r); } return Set(Production(lbl, sort, Seq(Terminal(lbl.name()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add("function").add("projection")), r); }
@Test public void testConcatStarCellEmptyl() { K term = cell("<top>", KRewrite(KVariable("Y"), cells())); K expected = cell("<top>", KRewrite(KVariable("Y"), KApply(KLabel(".ThreadCellBag")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testAddOptCell() { K term = cell("<t>", KVariable("X"), KRewrite(cells(), cell("<opt>"))); K expected = cell("<t>", KVariable("_0"), KVariable("_1"), KRewrite(KApply(KLabel(".OptCell")), cell("<opt>"))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testRemoveStarCell() { K term = cell("<top>", KRewrite(cell("<t>", KVariable("X")), cells())); K expected = cell("<top>", KRewrite(cell("<t>", KVariable("_0"), KVariable("_1"), KVariable("_2")), KApply(KLabel(".ThreadCellBag")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testConcatStarCell() { K term = cell("<top>", KRewrite(KVariable("Y"), cells(KVariable("Y"), cell("<t>", KVariable("X"))))); K expected = cell("<top>", KRewrite(KVariable("Y"), KApply(KLabel("_ThreadCellBag_"), KVariable("Y"), cell("<t>", KVariable("_0"), KVariable("_1"), KVariable("_2"))))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }