public CloseCells(ConfigurationInfo cfg, SortInfo sortInfo, LabelInfo labelInfo) { this.cfg = new ConcretizationInfo(cfg, labelInfo); this.sortInfo = sortInfo; this.labelInfo = labelInfo; }
Optional<Integer> getLevel(KApply k) { int level = cfg.getLevel(k.klabel()); if (level >= 0) { return Optional.of(level); } else { return Optional.empty(); } }
private void addDefaultCells(K item, Map<Sort, K> splitLeft, Map<Sort, K> splitRight) { for (Sort s : Sets.difference(splitLeft.keySet(), splitRight.keySet())) { if (cfg.getMultiplicity(s) == Multiplicity.ONE) { throw KEMException.compilerError("Cannot rewrite a multiplicity=\"1\" cell to or from the cell unit.", item); } else { splitRight.put(s, cfg.cfg.getUnit(s)); } } }
if (!cfg.isCell(label)) { return cell; List<K> contents = IncompleteCellUtils.getChildren(cell); if (cfg.isParentCell(label)) { Set<Sort> requiredLeft = new HashSet<>(); Set<Sort> requiredRight; for (Sort child : cfg.getChildren(label)) { if (cfg.getMultiplicity(child) == ConfigurationInfo.Multiplicity.ONE) { requiredLeft.add(child); if (!cfg.cfg.isConstantInitializer(reqChild)) throw KEMException.compilerError("Cannot close cell on right hand side because the initializer for " + reqChild.toString() + " requires configuration variables."); newContents.add(cfg.getDefaultCell(reqChild)); Sort cellType = cfg.leafCellType(label); if (cellType.equals(Sorts.K())) {
K replacementTerm() { getSplit(var); KLabel fragmentLabel = cfg.getCellFragmentLabel(parentCell); if (fragmentLabel == null) { throw KEMException.compilerError("Unsupported cell fragment with types: " + remainingCells, var); } List<Sort> children = cfg.getChildren(parentCell); List<K> arguments = new ArrayList<>(children.size()); for (Sort child : children) { K arg = split.get(child); if (arg == null) { if (cfg.getMultiplicity(child) == Multiplicity.ONE) { arg = cfg.getCellAbsentTerm(child); } else { arg = cfg.cfg.getUnit(child); } } assert arg != null; arguments.add(arg); } return KApply(fragmentLabel, immutable(arguments)); }
KLabel cellLabel = cfg.cfg.getCellLabel(cellSort); List<Sort> subcellSorts = cfg.getChildren(cellLabel); KApply kapp = (KApply) item; if (cfg.cfg.isCellLabel(kapp.klabel())) { Sort sort = cfg.getCellSort(kapp.klabel()); if (!subcellSorts.contains(sort)) { throw new IllegalArgumentException("No such sub-cell " + sort + " in the cell " + cellLabel); klist.set(i, cellFragment.klist().items().get(i)); } else { if (cfg.getMultiplicity(subcellSorts.get(i)) == Multiplicity.ONE) { klist.set(i, cfg.getCellAbsentTerm(subcellSorts.get(i))); } else { // Multiplicity.OPTIONAL || Multiplicity.STAR klist.set(i, cfg.cfg.getUnit(subcellSorts.get(i)));
@Override public K apply(KApply k) { if (!cfg.isParentCell(k.klabel())) { if (isCellFragmentTest(k)) { return getSplit(k.klist().items().get(0)).entrySet().stream() List<Sort> order = cfg.getChildren(k.klabel()); ArrayList<K> ordered = new ArrayList<K>(Collections.nCopies(order.size(), null)); for (K item : k.klist().items()) { if (cfg.getMultiplicity(sort) == Multiplicity.ONE) { throw KEMException.compilerError("Missing cell of multiplicity=\"1\": " + sort, k); } else {
remainingCells = new LinkedHashSet<>(cfg.getChildren(cell)); if (item instanceof KApply) { KApply kApply = (KApply) item; Sort s = cfg.getCellSort(kApply.klabel()); if (s != null && cfg.getMultiplicity(s) != Multiplicity.STAR) { remainingCells.remove(s);
KApply app = (KApply) k; KLabel target = app.klabel(); if (cfg.isLeafCell(target)) { return k; int targetLevel = cfg.getLevel(target) + 1; TreeMap<Integer, Collection<K>> levelMap = new TreeMap<>(); Multimap<Integer, K> levels = Multimaps.newMultimap(levelMap, ArrayList::new); KLabel parent = e.getKey(); List<KApply> newCells = makeParents(parent, ellipses, e.getValue()); levels.putAll(cfg.getLevel(parent), newCells);
BiFunction<List<K>, Set<Sort>, Boolean> useCells = (cells, used) -> { for (K k : cells) { Sort sort = cfg.getCellSort(k); if (cfg.getMultiplicity(sort) != ConfigurationInfo.Multiplicity.STAR) { if (used.contains(sort)) { return false; Sort label = cfg.getCellSort(children.get(0)); if (cfg.getMultiplicity(label) == ConfigurationInfo.Multiplicity.STAR) { forcedSeparate = false; } else { for (K child : children) { Sort sort = cfg.getCellSort(child); if (!sort.equals(label)) { forcedSeparate = false; 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 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(l -> cfg.getMultiplicity(l) != ConfigurationInfo.Multiplicity.STAR) .collect(Collectors.toSet());
if(children.size() == 1 && children.get(0) == item) { final KLabel label = ((KApply) item).klabel(); Sort s = cfg.getCellSort(label); if (s == null) { s = cfg.getCellCollectionCell(label); if (s == null) { throw new IllegalArgumentException("Attempting to split non-cell term " + item);
public KLabel getParent(KLabel klabel) { return getParent(labels.getCodomain(klabel)); }
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 SortCells(ConfigurationInfo cfgInfo, LabelInfo labelInfo, Module module) { this.cfg = new ConcretizationInfo(cfgInfo, labelInfo); this.labelInfo = labelInfo; this.module = module; } public SortCells(ConfigurationInfo cfgInfo, LabelInfo labelInfo) {
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; }
public SortCells(ConfigurationInfo cfgInfo, LabelInfo labelInfo) { this.cfg = new ConcretizationInfo(cfgInfo, labelInfo); this.labelInfo = labelInfo; this.module = null; }
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; }
public AddParentCells(ConfigurationInfo configInfo, LabelInfo labelInfo) { cfg = new ConcretizationInfo(configInfo, labelInfo); }
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; } }