K concretize(K term) { if (term instanceof KApply) { KApply app = (KApply) term; KApply newTerm = KApply(app.klabel(), KList(app.klist().stream() .map(this::concretize).collect(Collectors.toList()))); if (cfg.isParentCell(newTerm.klabel())) { return concretizeCell(newTerm); } else { return newTerm; } } else if (term instanceof KRewrite) { KRewrite rew = (KRewrite) term; return KRewrite(concretize(rew.left()), concretize(rew.right())); } else if (term instanceof KSequence) { return KSequence(((KSequence) term).stream() .map(this::concretize).collect(Collectors.toList())); } else { return term; } }
|| IncompleteCellUtils.isOpenRight(app); for (K item : IncompleteCellUtils.getChildren(app)) { if (isCompletionItem(item)) { children.add(item); } else { Multimap<Integer, K> levels = Multimaps.newMultimap(levelMap, ArrayList::new); for (K child : children) { levels.put(getLevel(child).get(), child); for (Map.Entry<KLabel, List<K>> e : level.stream().collect(Collectors.groupingBy(t -> getParent(t).get())).entrySet()) { KLabel parent = e.getKey(); List<KApply> newCells = makeParents(parent, ellipses, e.getValue()); levels.putAll(cfg.getLevel(parent), newCells);
public ConcretizeCells(ConfigurationInfo configurationInfo, LabelInfo labelInfo, SortInfo sortInfo, Module module) { this.configurationInfo = configurationInfo; this.labelInfo = labelInfo; this.sortInfo = sortInfo; this.module = module; addRootCell = new AddTopCellToRules(configurationInfo, labelInfo); addParentCells = new AddParentCells(configurationInfo, labelInfo); closeCells = new CloseCells(configurationInfo, sortInfo, labelInfo); sortCells = new SortCells(configurationInfo, labelInfo, module); }
@Test public void testOneLeafCellNoCompletion() { K term = cell("<k>", intToToken(2)); K expected = cell("<k>", intToToken(2)); Assert.assertEquals(expected, pass.concretizeCell(term)); }
public Sentence concretize(Sentence m) { if (m instanceof Rule) { Rule r = (Rule) m; return new Rule(concretize(r.body()), r.requires(), r.ensures(), r.att()); } else if (m instanceof Context) { Context c = (Context) m; return new Context(concretize(c.body()), c.requires(), c.att()); } else { return m; } } }
@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))))); }
boolean isCompletionItem(K k) { return (k instanceof KApply || k instanceof KRewrite || k instanceof KVariable) && getLevel(k).isPresent(); }
if (!(streamSideCells(rew.left()).anyMatch(l -> cfg.getCellSort(l).equals(label)) || streamSideCells(rew.left()).anyMatch(l -> cfg.getCellSort(l).equals(label)))) { forcedSeparate = false; break; for (KRewrite rew1 : rewrites) { for (KRewrite rew2 : rewrites) { Set<Sort> left1NonRepeatable = streamSideCells(rew1.left()).map(cfg::getCellSort) .filter(l -> cfg.getMultiplicity(l) != ConfigurationInfo.Multiplicity.STAR) .collect(Collectors.toSet()); boolean lhsConflict = streamSideCells(rew2.left()).map(cfg::getCellSort) .filter(left1NonRepeatable::contains).count() >= 1; Set<Sort> right1NonRepeatable = streamSideCells(rew1.right()).map(cfg::getCellSort) .filter(l -> cfg.getMultiplicity(l) != ConfigurationInfo.Multiplicity.STAR) .collect(Collectors.toSet()); boolean rhsConflict = streamSideCells(rew2.right()).map(cfg::getCellSort) .filter(right1NonRepeatable::contains).count() >= 1; if (!(lhsConflict || rhsConflict)) {
return Optional.empty(); Optional<KLabel> parent = getParent(items.get(0)); for (K item : items) { if (!parent.equals(getParent(item))) { throw KEMException.criticalError("Can't mix items with different parent cells under a rewrite," + " found "+items.get(0)+" and "+item, k); return Optional.of(cfg.getParent(sort)); } else { Optional<KLabel> leftParent = getParent(((KRewrite) k).left()); Optional<KLabel> rightParent = getParent(((KRewrite) k).right()); if (!leftParent.isPresent()) { return rightParent;
@Test public void testTwoCellsNoCompletion() { K term = cell("<t>", cell("<k>", intToToken(2))); K expected = cell("<t>", cell("<k>", intToToken(2))); Assert.assertEquals(expected, pass.concretizeCell(term)); }
public Sentence concretize(Sentence s) { s = addRootCell.addImplicitCells(s); s = addParentCells.concretize(s); s = closeCells.close(s); s = sortCells.preprocess(s); s = sortCells.sortCells(s); s = sortCells.postprocess(s); return s; } }
Optional<Integer> getLevel(K k) { if (k instanceof KApply) { return getLevel((KApply) k); } else if (k instanceof KVariable) { if (k.att().contains(Sort.class)) { Optional<Integer> level = Optional.empty(); for (K item : cells) { Optional<Integer> level2 = getLevel(item); if (item instanceof KVariable && !level2.isPresent()) { continue;
@Test(expected = KEMException.class) public void testAmbiguityError() { K term = cell("<ts>", cell("<k>", intToToken(1)), cell("<k>", intToToken(2)), cell("<env>", intToToken(2))); pass.concretizeCell(term); }
@Test public void testNonCellItemRewrite() { K term = cell("<T>", KRewrite(KApply(KLabel("label")),cells(KApply(KLabel(".K")), cell("<k>",KVariable("X"))))); exception.expect(KEMException.class); exception.expectMessage("Can't mix items with different parent cells under a rewrite"); pass.concretize(term); }
@Test public void testTwoCellsCompletion() { K term = cell("<ts>", cell("<k>", intToToken(2))); K expected = cell("<ts>", cell("<t>", cell("<k>", intToToken(2)))); Assert.assertEquals(expected, pass.concretizeCell(term)); }
@Test public void testNonCellItem() { K term = cell("<T>", KApply(KLabel(".K")), cell("<k>",KVariable("X"))); K expected = cell("<T>",cells(KApply(KLabel(".K")), cell("<ts>", cell("<t>", cell("<k>", KVariable("X")))))); Assert.assertEquals(expected, pass.concretize(term)); }
@Test public void testMultiplicityShared() { K term = cell("<ts>", cell("<k>", intToToken(1)), cell("<env>", intToToken(2))); K expected = cell("<ts>", cell("<t>", cell("<k>", intToToken(1)), cell("<env>", intToToken(2)))); Assert.assertEquals(expected, pass.concretizeCell(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 testDotsTogether() { K term = cell("<ts>", true, false, cell("<k>", intToToken(0)), cell("<env>",intToToken(2))); K expected = cell("<ts>", true, true, cell("<t>", true, true, cell("<k>", intToToken(0)), cell("<env>",intToToken(2)))); Assert.assertEquals(expected, pass.concretizeCell(term)); }
@Test public void testNestedCompletion() { K term = cell("<T>", cell("<t>", cell("<msg>", intToToken(0)), cell("<msgId>", intToToken(1))), cell("<k>", intToToken(2)), cell("<env>", intToToken(3)), cell("<msgId>", intToToken(4)), cell("<msgId>", intToToken(5)), cell("<t>", cell("<k>", intToToken(6)))); K expected = cell("<T>",cell("<ts>", cell("<t>", cell("<msg>", intToToken(0)), cell("<msg>", cell("<msgId>", intToToken(1)))), cell("<t>", cell("<k>", intToToken(6))), cell("<t>", cell("<k>", intToToken(2)), cell("<env>", intToToken(3)), cell("<msg>", cell("<msgId>", intToToken(4))), cell("<msg>", cell("<msgId>", intToToken(5)))) )); Assert.assertEquals(expected, pass.concretize(term)); }