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); }
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; } }
private Rule sortCells(Rule rule) { resetVars(); analyzeVars(rule.body()); analyzeVars(rule.requires()); analyzeVars(rule.ensures()); rule = Rule( processVars(rule.body()), processVars(rule.requires()), processVars(rule.ensures()), rule.att()); rule = Rule( resolveIncompleteCellFragment(rule.body()), resolveIncompleteCellFragment(rule.requires()), resolveIncompleteCellFragment(rule.ensures()), rule.att()); return rule; }
public synchronized K sortCells(K term) { resetVars(); analyzeVars(term); return processVars(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()); }
/** * Post-process terms after processVar */ public synchronized Sentence postprocess(Sentence s) { if (s instanceof Rule) { return postprocess((Rule) s); } else { return s; } }
/** * Pre-process terms before processVar */ public synchronized Sentence preprocess(Sentence s) { if (s instanceof Rule) { return preprocess((Rule) s); } else { return s; } }
Map<Sort, K> getSplit(KVariable var) { if(split != null) { return split; } if (remainingCells.size() == 0) { split = Collections.emptyMap(); } else if (remainingCells.size() == 1) { Sort s = Iterables.getOnlyElement(remainingCells); if (cfg.getMultiplicity(s) == Multiplicity.STAR) { split = ImmutableMap.of(s, KVariable( var.name(), var.att().add(Sort.class, getPredicateSort(s)))); } else { split = ImmutableMap.of(s, KVariable(var.name(), var.att().add(Sort.class, s).add("cellSort"))); } } else { split = new HashMap<>(); for (Sort cell : remainingCells) { split.put(cell, newDotVariable(var.att().add(Sort.class, cell).add("cellSort"))); } } return split; } }
@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()); }
private Context sortCells(Context context) { resetVars(); analyzeVars(context.body()); analyzeVars(context.requires()); return new Context( processVars(context.body()), processVars(context.requires()), context.att()); }
private Rule postprocess(Rule rule) { return Rule( postprocess(rule.body()), postprocess(rule.requires()), postprocess(rule.ensures()), rule.att()); }
private Rule preprocess(Rule rule) { return Rule( preprocess(rule.body()), preprocess(rule.requires()), preprocess(rule.ensures()), rule.att()); }
@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 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 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()); }
/** * 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 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()); }
@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 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()); }