public Sort getCellSort(K k) { if (k instanceof KApply) { return labels.getCodomain(((KApply) k).klabel()); } else if (k instanceof KVariable) { return k.att().get(Sort.class); } else { throw new AssertionError("expected KApply or KVariable, found " + k.getClass().getSimpleName()); } }
private void filterRequired(Set<Sort> required, K item) { if (item instanceof KApply) { required.remove(labelInfo.getCodomain(((KApply) item).klabel())); } else if (item instanceof KVariable) { if (item.att().contains(Sort.class)) { Sort sort = item.att().get(Sort.class); if (cfg.cfg.isCell(sort)) { required.remove(sort); } else { required.clear(); } } else { required.clear(); } } } }
private KLabel computePolyKLabel(KApply k) { List<Set<Integer>> poly = polyKLabels.get(k.klabel().name()); List<Sort> params = new ArrayList<>(); for (Set<Integer> positions : poly) { int pos = positions.iterator().next(); Sort sort; if (pos == 0) { sort = k.att().get(Sort.class); } else { sort = k.items().get(pos-1).att().get(Sort.class); } params.add(sort); } return KLabel(k.klabel().name(), immutable(params)); }
@Override public void apply(KSequence k) { for (int i = 0; i < k.items().size(); i++) { K item = k.items().get(i); boolean isList = item.att().get(Sort.class).equals(Sorts.K()); if (i == k.items().size() - 1) { if (isList) { apply(item); } else { sb.append("kseq{}("); apply(item); sb.append(",dotk{}())"); } } else { if (item.att().get(Sort.class).equals(Sorts.K())) { sb.append("append{}("); } else { sb.append("kseq{}("); } apply(item); sb.append(","); } } if (k.items().size() == 0) { sb.append("dotk{}()"); } for (int i = 0; i < k.items().size() - 1; i++) { sb.append(")"); } }
K topOfKCell = seq.items().get(0); if (topOfKCell instanceof KVariable) { Optional<Sort> sortAtt = topOfKCell.att().getOptional(Sort.class); if (sortAtt.isPresent()) { Sort sort = sortAtt.get();
public Term convert(org.kframework.kore.K k) { if (k instanceof Term) return (Term) k; else if (k instanceof org.kframework.kore.KToken) return KToken(((org.kframework.kore.KToken) k).s(), ((org.kframework.kore.KToken) k).sort(), k.att()); else if (k instanceof org.kframework.kore.KApply) { return KApply1(((KApply) k).klabel(), ((KApply) k).klist(), k.att()); } else if (k instanceof org.kframework.kore.KSequence) return KSequence(((org.kframework.kore.KSequence) k).items(), k.att()); else if (k instanceof org.kframework.kore.KVariable) return KVariable(((org.kframework.kore.KVariable) k).name(), k.att()); else if (k instanceof org.kframework.kore.InjectedKLabel) return InjectedKLabel(((org.kframework.kore.InjectedKLabel) k).klabel(), k.att()); else if (k instanceof org.kframework.kore.KRewrite) { return KItem.of(KLabelConstant.of(KLabels.KREWRITE, definition), KList.concatenate(convert(((KRewrite) k).left()), convert(((KRewrite) k).right())), global); } else throw new AssertionError("BUM!"); }
private Set<Sort> sort(K k, Rule r) { if (k instanceof KVariable) { return Collections.singleton(k.att().get(Sort.class)); } else if (k instanceof KToken) { return Collections.singleton(((KToken)k).sort()); } else if (k instanceof KApply) { KApply kapp = (KApply)k; if (kapp.klabel() instanceof KVariable) { throw KEMException.compilerError("Cannot compute macros with klabel variables.", r); } Set<Production> prods = new HashSet<>(mutable(mod.productionsFor().apply(kapp.klabel()))); prods.removeIf(p -> p.arity() != kapp.items().size()); for (int i = 0; i < kapp.items().size(); i++) { final int idx = i; Set<Sort> sorts = sort(kapp.items().get(idx), r); prods.removeIf(p -> sorts.stream().noneMatch(s -> mod.subsorts().lessThanEq(s, p.nonterminal(idx).sort()))); } Set<Sort> candidates = prods.stream().map(Production::sort).collect(Collectors.toSet()); return candidates; } else { throw KEMException.compilerError("Cannot compute macros with sort check on terms that are not KApply, KToken, or KVariable.", r); } }
Sort sort = k.att().get(Sort.class); return Optional.of(cfg.getParent(sort)); } else {
Sort s = head.att().getOptional(Sort.class).orElse(Sort("")); if (mainModule.sortAttributesFor().contains(s)) { String hook = mainModule.sortAttributesFor().apply(s).<String>getOptional("hook").orElse("");
private boolean attEquals(K thisK, K thatK) { if (!filterAtt(thisK.att()).equals(filterAtt(thatK.att()))) { return false; } if ((thisK instanceof KToken && thatK instanceof KToken) || (thisK instanceof KVariable && thatK instanceof KVariable) || (thisK instanceof InjectedKLabel && thatK instanceof InjectedKLabel)) { return thisK.equals(thatK); } else if (thisK instanceof KApply && thatK instanceof KApply) { KApply thisKItem = (KApply) thisK; KApply thatKItem = (KApply) thatK; return thisKItem.klabel().equals(thatKItem.klabel()) && attEquals(thisKItem.klist().items(), thatKItem.klist().items()); } else if (thisK instanceof KSequence && thatK instanceof KSequence) { return attEquals(((KSequence) thisK).items(), ((KSequence) thatK).items()); } else if (thisK instanceof KRewrite && thatK instanceof KRewrite) { KRewrite thisKR = (KRewrite) thisK; KRewrite thatKR = (KRewrite) thatK; return attEquals(thisKR.left(), thatKR.left()) && attEquals(thisKR.right(), thatKR.right()); } else { return false; } }
return ((KToken) term).sort(); } else if (term instanceof KVariable) { return term.att().getOptional(Sort.class).orElse(Sorts.K()); } else if (term instanceof KSequence) { return Sorts.K();
private Sort sort(K k) { if (k instanceof KSequence) return Sorts.K(); if (k instanceof KAs) return sort(((KAs) k).pattern()); if (k instanceof InjectedKLabel) return Sorts.KItem(); if (k instanceof KToken) return ((KToken) k).sort(); if (k instanceof KApply) return k.att().get(Production.class).sort(); if (k instanceof KVariable) return Sorts.K(); throw KEMException.compilerError("Could not compute sort of term", k); }
if (item.items().size() == 1 && vars.vars.containsKey(item.items().get(0))) { Optional<Sort> varSort = item.items().get(0).att().getOptional(Sort.class); if (varSort.isPresent() && varSort.get().equals(s)) {
private K visitChildren(K term, Sort parentSort, Sort actualSort) { Att att = term.att().add(Sort.class, actualSort); if (term instanceof KApply) { KApply kapp = (KApply)term;