public KLabel getParent(Sort sort) { return cfg.getCellLabel(cfg.getParent(sort)); }
public K getCellAbsentTerm(Sort cellSort) { KLabel l = cfg.getCellAbsentLabel(cellSort); return l == null ? null : KApply(l); }
/** If {@code label} is a label making a cell collection, return the * Sort of the cells in that collection. */ public Sort getCellCollectionCell(KLabel label) { Option<Sort> result = cfg.getCellForConcat(label); if (result.isEmpty()) { result = cfg.getCellForUnit(label); } return result.isDefined() ? result.get() : null; } public KLabel getCellFragmentLabel(KLabel cellLabel) {
public boolean isCell(KLabel klabel) { Sort s = labels.getCodomain(klabel); return cfg.isCell(s) && cfg.getCellLabel(s).equals(klabel); } public boolean isLeafCell(KLabel klabel) {
protected K addRootCell(K term) { KLabel root = cfg.getCellLabel(cfg.getRootCell()); if (term instanceof KApply && ((KApply) term).klabel().equals(root)) { return term; } else if (term instanceof KRewrite) { KRewrite rew = (KRewrite) term; K left = addRootCell(rew.left()); if (left == rew.left()) { return KRewrite(rew.left(), rew.right()); } else { return IncompleteCellUtils.make(root, true, term, true); } } else { return IncompleteCellUtils.make(root, true, term, true); } }
KLabel cellLabel = cfg.cfg.getCellLabel(cellSort); if (item instanceof KApply) { KApply kapp = (KApply) item; if (cfg.cfg.isCellLabel(kapp.klabel())) { Sort sort = cfg.getCellSort(kapp.klabel()); if (!subcellSorts.contains(sort)) { if (cfg.cfg.isCell(sort)) { if (!subcellSorts.contains(sort)) { throw new IllegalArgumentException("No such sub-cell " + sort + " in the cell " + cellLabel); if (cfg.cfg.isCell(s)) { if (!subcellSorts.contains(s)) { throw new IllegalArgumentException("No such sub-cell " + s + " in the cell " + cellLabel); klist.set(i, cfg.getCellAbsentTerm(subcellSorts.get(i))); } else { // Multiplicity.OPTIONAL || Multiplicity.STAR klist.set(i, cfg.cfg.getUnit(subcellSorts.get(i)));
private K apply(K term) { if (labelInfo.isFunction(term)) return term; List<K> items = IncompleteCellUtils.flattenCells(term); if (items.size() != 1) { return term; } K item = items.get(0); if (isCell(item)) { return term; } else if (item instanceof KRewrite) { final KRewrite rew = (KRewrite) item; if (Stream.concat( IncompleteCellUtils.flattenCells(rew.left()).stream(), IncompleteCellUtils.flattenCells(rew.right()).stream()) .anyMatch(this::isCell)) { return term; } } KLabel computation = cfg.getCellLabel(cfg.getComputationCell()); return IncompleteCellUtils.make(computation, false, item, true); }
private K concatenateStarCells(Sort sort, List<K> children) { if (cfg.getMultiplicity(sort) != Multiplicity.STAR) { throw KEMException.compilerError("Attempting to concatenate cells not of multiplicity=\"*\" " + "into a cell collection.", children.iterator().next()); } if (children.size() == 0) { return cfg.cfg.getUnit(sort); } KLabel concat = cfg.cfg.getConcat(sort); int ix = children.size(); K result = children.get(--ix); while (ix > 0) { result = KApply(concat,children.get(--ix),result); } return result; }
@Override public K apply(KApply k0) { if (hasCells(k0)) { ArrayList<K> klist0 = new ArrayList<K>(Collections.nCopies(k0.klist().size(), null)); for (int idx = 0; idx < k0.klist().size(); idx++) { K item0 = k0.klist().items().get(idx); klist0.set(idx, item0); if (item0 instanceof KApply) { KApply k = (KApply) item0; if (k.klabel().name().equals("#cells")) { if (cellFragmentVarsCell.contains(k)) { Sort cellFragmentSort = nthArgSort(k0.klabel(), idx); if (cellFragmentSort == null) { throw new IllegalArgumentException("Not found " + idx + "th argument sort of " + k0.klabel()); } if (cellFragmentSort.name().endsWith("Fragment")) { Sort cellSort = Sort(cellFragmentSort.name().substring(0,cellFragmentSort.name().indexOf("Fragment"))); KLabel cellLabel = cfg.cfg.getCellLabel(cellSort); klist0.set(idx, KApply(cellLabel, KList(item0), Att().add("dummy_cell"))); } } } } } return KApply(k0.klabel(), KList(klist0), k0.att()); } return super.apply(k0); } @Override
public KLabel getCellFragmentLabel(KLabel cellLabel) { Sort s = labels.getCodomain(cellLabel); return cfg.getCellFragmentLabel(s); }
public List<Sort> getChildren(KLabel label) { return cfg.getChildren(labels.getCodomain(label)); }
private Sort getPredicateSort(Sort s) { if (cfg.getMultiplicity(s) == Multiplicity.STAR) { scala.collection.Set<Sort> sorts = cfg.cfg.getCellBagSortsOfCell(s); if (sorts.size() != 1) { throw KEMException.compilerError("Expected exactly one cell collection sort for the sort " + s + "; found " + sorts); } return stream(sorts).findFirst().get(); } return s; }
@Override public K apply(KApply k) { if (k.klabel().equals(configInfo.getCellLabel(configInfo.getRootCell()))) { if (isLHS() && isRHS()) { K lhs = RewriteToTop.toLeft(k);