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 testUselessVariable() { K term = cell("<t>", cell("<env>"), cell("<k>"), cell("<opt>"), KVariable("X")); K expected = cell("<t>", cell("<k>"), cell("<env>"), 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 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 testMultipleSplit() { K term = KRewrite(cell("<t>", KVariable("X")), KVariable("Y")); K expected = KRewrite(cell("<t>", KVariable("_0"), KVariable("_1"), KVariable("_2")), KVariable("Y")); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testRemoveOptCell() { K term = cell("<t>", KVariable("X"), KRewrite(cell("<opt>"), cells())); K expected = cell("<t>", KVariable("_0"), KVariable("_1"), KRewrite(cell("<opt>"), KApply(KLabel(".OptCell")))); 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 testAddStarCell() { K term = cell("<top>", KRewrite(cells(), cell("<t>", KVariable("X")))); K expected = cell("<top>", KRewrite(KApply(KLabel(".ThreadCellBag")), 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()); }
/** * Ensure that a variable does not become a cell fragment if it is annotated * with a single-cell sort. */ @Test public void testSortedVar() { KVariable Y = KVariable("Y", Att().add(Sort.class, Sort("OptCell"))); K term = KRewrite(cell("<t>", cell("<env>"), KVariable("X"), Y), Y); K expected = KRewrite(cell("<t>", KVariable("X"), cell("<env>"), Y), Y); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testSimpleSplitting() { KVariable Y = KVariable("Y", Att().add(Sort.class, Sort("OptCell"))); K term = KRewrite(cell("<t>", cell("<env>"), KVariable("X"), Y), KVariable("X")); K expected = KRewrite(cell("<t>", KVariable("X"), cell("<env>"), Y), cell("<t>-fragment", KVariable("X"), app("noEnvCell"), app(".OptCell"))); 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 testFragmentBag() { K term = cell("<top>", KVariable("F"),cell("<t>", KRewrite(KVariable("Rest"),KSequence(KVariable("F"),KVariable("Rest"))))); K expected = cell("<top>", app("_ThreadCellBag_", KVariable("_0"), cell("<t>", KRewrite(KVariable("Rest"), KSequence(app("<top>-fragment",KVariable("_0"),KVariable("_1")),KVariable("Rest"))))), KVariable("_1")); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(bagCfgInfo, bagLabelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
/** * Test that splitting works properly if an item under a parent cell is * already a collection of multiplicity * cells joined by the proper label. */ @Test public void testMultipleCells() { KVariable T1 = KVariable("T1",Att().add(Sort.class,Sort("ThreadCell"))); KVariable T2 = KVariable("T2",Att().add(Sort.class,Sort("ThreadCell"))); K term = cell("<top>", KVariable("F"), cell("<t>", KVariable("T")), app("_ThreadCellBag_",T1,T2)); K expected = cell("<top>", app("_ThreadCellBag_", app("_ThreadCellBag_", KVariable("_0"), cell("<t>", KVariable("T"))), app("_ThreadCellBag_", T1, T2)), KVariable("_1")); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(bagCfgInfo, bagLabelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testFragment3() { K term = cell("<top>",cell("<t>",cell("<opt>",KVariable("O")),KVariable("F")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(KVariable("F"), KVariable("Rest")))), KVariable("F2"))); K expected = cell("<top>",app("_ThreadCellBag_", cell("<t>", KVariable("_0"), KVariable("_1"), cell("<opt>", KVariable("O"))), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(cell("<t>-fragment", KVariable("_0"), KVariable("_1"), app(".OptCell")), KVariable("Rest")))), KVariable("_2"), KVariable("_3")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); } @Test
@Test public void testFragment1() { K term = cell("<top>",cell("<t>",KVariable("F")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(KVariable("F"), KVariable("Rest")))), KVariable("F2"))); K expected = cell("<top>",app("_ThreadCellBag_", cell("<t>", KVariable("_0"), KVariable("_1"), KVariable("_2")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(cell("<t>-fragment", KVariable("_0"), KVariable("_1"), KVariable("_2")), KVariable("Rest")))), KVariable("_3"), KVariable("_4")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); } @Test
/** Ensure that the splitting in {@linkplain #testPredicateExpansion()} does not happen * in a term which applies the sort predicate for a <em>different</em> cell fragment sort * to a cell fragment variable. */ @Test public void testUnrelatedPredicate() { Rule term = new Rule(KRewrite(cell("<t>", cell("<env>"), KVariable("X"), KVariable("Y", Att().add(Sort.class, Sort("OptCell")))), KVariable("X")) , app("isTopCellFragment",KVariable("X")) , BooleanUtils.TRUE , Att()); K replacement = app("<t>-fragment", KVariable("X"), app("noEnvCell"), app(".OptCell")); K expectedBody = KRewrite(cell("<t>", KVariable("X"), cell("<env>"), KVariable("Y", Att().add(Sort.class, Sort("OptCell")))), replacement); Rule expected = new Rule(expectedBody , app("isTopCellFragment", replacement) , BooleanUtils.TRUE, Att()); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testFragment4() { K term = cell("<top>",cell("<t>",cell("<env>",KVariable("E")),KVariable("F")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(KVariable("F"), KVariable("Rest")))), KVariable("F2"))); K expected = cell("<top>",app("_ThreadCellBag_", cell("<t>", KVariable("_0"), cell("<env>", KVariable("E")), KVariable("_1")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(cell("<t>-fragment", KVariable("_0"), app("noEnvCell"), KVariable("_1")), KVariable("Rest")))), KVariable("_2"), KVariable("_3")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testFragment2() { K term = cell("<top>",cell("<t>",cell("<k>",KVariable("K")),KVariable("F")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(KVariable("F"), KVariable("Rest")))), KVariable("F2"))); K expected = cell("<top>",app("_ThreadCellBag_", cell("<t>", cell("<k>", KVariable("K")), KVariable("_0"), KVariable("_1")), cell("<t>", cell("<k>", KRewrite(KSequence(KVariable("Rest")), KSequence(cell("<t>-fragment", app("noKCell"), KVariable("_0"), KVariable("_1")), KVariable("Rest")))), KVariable("_2"), KVariable("_3")))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); } @Test
/** When a cell fragment variable occurs as an argument to the appropriate cell fragment sort predict, we * specialize the expansion by splitting it into a conjunction of individual sort predicate tests on * the variables the cell fragment variable splits into, rather than just using the generic replacement term. * This is a very special case of statically simplifying predicate applications. */ @Test public void testPredicateExpansion() { Rule term = new Rule(KRewrite(cell("<t>", cell("<env>"), KVariable("X"), KVariable("Y", Att().add(Sort.class, Sort("OptCell")))), KVariable("X")) , app("isThreadCellFragment",KVariable("X")) , BooleanUtils.TRUE , Att()); K expectedBody = KRewrite(cell("<t>", KVariable("X"), cell("<env>"), KVariable("Y", Att().add(Sort.class, Sort("OptCell")))), cell("<t>-fragment", KVariable("X"), app("noEnvCell"), app(".OptCell"))); Rule expected = new Rule(expectedBody , BooleanUtils.and(BooleanUtils.TRUE, app("isKCell", KVariable("X"))) , BooleanUtils.TRUE, Att()); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(cfgInfo, labelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }
@Test public void testFragmentRewrite() { K term = cell("<top>", cell("<t>",KRewrite(app("restore",KVariable("Ctx")), KVariable("Result"))), KRewrite(cells(KVariable("_1"), cell("<t>",KVariable("Result"))), KVariable("Ctx"))); K expected = cell("<top>", app("_ThreadCellBag_", cell("<t>",KRewrite( app("restore",app("<top>-fragment",KVariable("_0"),KVariable("_2"))), KVariable("Result"))), KRewrite(app("_ThreadCellBag_",KVariable("_3"), cell("<t>",KVariable("Result"))), KVariable("_0"))), KRewrite(KVariable("_4"),KVariable("_2"))); KExceptionManager kem = new KExceptionManager(new GlobalOptions()); Assert.assertEquals(expected, new SortCells(bagCfgInfo, bagLabelInfo).sortCells(term)); Assert.assertEquals(0, kem.getExceptions().size()); }