private static KLabel getProjectLbl(Sort sort, Module m) { KLabel lbl; lbl = KLabel("project:" + sort.toString()); return lbl; }
protected void addLabel(Sort result, String label, boolean isAssoc, boolean isComm, boolean isFunction) { codomain.put(KLabel(label), result); AssocInfo info = new AssocInfo(isAssoc, isComm); if (assocInfo.containsKey(KLabel(label))) { assert assocInfo.get(KLabel(label)).equals(info); } else { assocInfo.put(KLabel(label), new AssocInfo(isAssoc, isComm)); } if (isFunction) { functionLabels.add(KLabel(label)); } }
private KLabel getUniqueLambdaLabel(String nameHint1, String nameHint2) { if (klabels.isEmpty()) { klabels.addAll(mutable(module.definedKLabels())); } int counter = 0; KLabel freezer; do { freezer = KLabel("#lambda" + nameHint1 + "_" + nameHint2 + "_" + (counter++ == 0 ? "" : counter)); } while (klabels.contains(freezer)); klabels.add(freezer); return freezer; }
private KLabel getUniqueFreezerLabel(Module input, String nameHint) { if (klabels.isEmpty()) { klabels.addAll(mutable(input.definedKLabels())); } int counter = 0; KLabel freezer; do { freezer = KLabel("#freezer" + nameHint + "_" + (counter++ == 0 ? "" : counter)); } while (klabels.contains(freezer)); klabels.add(freezer); return freezer; }
private Optional<KLabel> getAssocKLabelForUnit(KLabel klabel) { return definition.kLabelAttributes().entrySet().stream() .filter(e -> effectivelyAssocAttributes(e.getValue()) && e.getValue().get(Att.unit()).equals(klabel.name())) .map(e -> KORE.KLabel(e.getKey())) .findAny(); }
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 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); }
private boolean isCellFragmentTest(KApply app) { if (app.klist().size() != 1) return false; K argument = app.klist().items().get(0); if (!(argument instanceof KVariable)) return false; VarInfo info = variables.get((KVariable)argument); if (info == null) return false; KLabel expectedPredicate = KLabel("is"+cfg.getCellSort(info.parentCell).toString()+"Fragment"); return app.klabel().equals(expectedPredicate); }
public static K flattenTerm(Module mod, KApply kapp) { List<K> items = new ArrayList<>(); Att att = mod.attributesFor().apply(KLabel(kapp.klabel().name())); if (att.contains("assoc") && att.contains("unit")) { items = Assoc.flatten(kapp.klabel(), kapp.klist().items(), KLabel(att.get("unit"))); } else { items = kapp.klist().items(); } return KApply(kapp.klabel(), KList(items), kapp.att()); }
@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);
@Override public K apply(KApply k) { if (m.attributesFor().apply(k.klabel()).contains("thread")) { return KApply(k.klabel(), KApply(KLabel("#ThreadLocal"))); } return super.apply(k); } }.apply(body);
@Test public void testCloseList() { K term = KApply(KLabels.CELLS, cell("<list>", true, false, intToToken(1)), cell("<list>", false, true, intToToken(2)), cell("<list>", true, true, intToToken(3))); K expected = KApply(KLabels.CELLS, ccell("<list>", KApply(KLabel("_List_"), KVariable("DotVar0"), intToToken(1))), ccell("<list>", KApply(KLabel("_List_"), intToToken(2), KVariable("DotVar1"))), ccell("<list>", KApply(KLabel("_List_"), KVariable("DotVar2"), KApply(KLabel("_List_"), intToToken(3), KVariable("DotVar3"))))); Assert.assertEquals(expected, new CloseCells(cfgInfo, sortInfo, labelInfo).close(term)); }
@Test public void testDeep2() { Assert.assertEquals(Lists.newArrayList(cell("<ts>", cell("<t>", intToToken(1)), cell("<t>", intToToken(2)))), pass.makeParents(KLabel("<ts>"), false, Lists.newArrayList(cell("<t>", intToToken(1)), cell("<t>", intToToken(2))))); }
@Test public void testSimpleClosure() { K term = cell("<k>", false, true, KApply(KLabel("_+_"), KVariable("I"), KVariable("J"))); K expected = ccell("<k>", KSequence(KApply(KLabel("_+_"), KVariable("I"), KVariable("J")), KVariable("DotVar0"))); Assert.assertEquals(expected, new CloseCells(cfgInfo, sortInfo, labelInfo).close(term)); }
@Test public void testLeafContent() { K term = cell("<T>", cell("<k>", KSequence(KApply(KLabel("_+_"), KVariable("I"), KVariable("J")), KVariable("Rest")))); K expected = cell("<T>", cell("<ts>", cell("<t>", cell("<k>", KSequence(KApply(KLabel("_+_"), KVariable("I"), KVariable("J")), KVariable("Rest")))))); Assert.assertEquals(expected, pass.concretize(term)); }
@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()); }
@Test public void testCloseCellTerm() { K term = KRewrite(cells(), cells(cell("<thread>", true, false, cell("<k>", intToToken(1))), cell("<thread>", false, true, cell("<k>", intToToken(2))), cell("<thread>", true, true, cell("<env>", intToToken(2))))); K expected = KRewrite(cells(), cells(ccell("<thread>", ccell("<k>", intToToken(1)), ccell("<env>", KApply(KLabel(".Map")))), ccell("<thread>", ccell("<k>", intToToken(2)), ccell("<env>", KApply(KLabel(".Map")))), ccell("<thread>", ccell("<env>", intToToken(2)), ccell("<k>", stringToToken("defaultK"))))); Assert.assertEquals(expected, new CloseCells(cfgInfo, sortInfo, labelInfo).close(term)); }