private Set<KApply> getOrContents(KApply k) { return KLabels.ML_OR.equals(k.klabel()) ? k.klist().items().stream().map(KApply.class::cast).collect(Collectors.toSet()) : Collections.singleton(k); }
public static boolean isOpenLeft(KApply cell) { return isOpen(cell.klist().items().get(0)); } public static boolean isOpenRight(KApply cell) {
public static boolean isOpenRight(KApply cell) { return isOpen(cell.klist().items().get(2)); }
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 void applyKLabel(KApply k) { sb.append("KApply ("); apply(k.klabel()); sb.append(", "); apply(k.klist().items(), true); sb.append(")"); }
private void convertLHS(StringBuilder sb, RuleType type, K left, VarInfo vars) { Visitor visitor = convert(sb, false, vars, false, false); if (type == RuleType.ANYWHERE || type == RuleType.FUNCTION) { KApply kapp = (KApply) ((KSequence) left).items().get(0); sb.append("("); visitor.applyTuple(kapp.klist().items()); sb.append(")"); } else { visitor.apply(left); } }
public scala.collection.Set<K> apply(KApply k) { if (k.klabel().name().equals("#RESTORE_CONFIGURATION")) return org.kframework.Collections.Set(k.klist().items().get(0)); else return super.apply(k); } }.apply(theNew).head();
@Override public K apply(KVariable k) { if (varToTypedVar.containsKey(k)) { return varToTypedVar.get(k); } return super.apply(k); } }.apply(term);
private static void flattenCells(List<K> children, K item) { if (item instanceof KApply && KLabels.CELLS.equals(((KApply) item).klabel())) { for (K deeper : ((KApply) item).klist().items()) { flattenCells(children, deeper); } } else { children.add(item); } } public static List<K> flattenCells(K cells) {
@Override public K apply(KApply k) { List<K> children = new ArrayList<>(); for (K child : k.klist().items()) { K res = apply(child); if (res instanceof KSequence) { children.add(res); } else { children.add(KSequence(res)); } } return KApply(k.klabel(), KList(children), k.att()); }
@Override public K apply(KApply k) { if (k.klabel() instanceof KVariable && predicates.containsKey(k.klabel())) { return KApply(apply(k.klabel()), k.klist().items().stream().map(this::apply).collect(org.kframework.Collections.toList()), k.att()); } return super.apply(k); }
private Context upContext(K contents) { KApply ruleContents = (KApply) contents; List<K> items = ruleContents.klist().items(); switch (ruleContents.klabel().name()) { case "#ruleNoConditions": return Context(items.get(0), BooleanUtils.TRUE, ruleContents.att()); case "#ruleRequires": return Context(items.get(0), items.get(1), ruleContents.att()); default: throw KEMException.criticalError("Illegal context with ensures clause detected.", contents); } }
@Override public K apply(KApply k) { k = (KApply) super.apply(k); return KApply(apply(k.klabel()), k.klist(), k.att()); }
@Override default org.kframework.kore.KList klist() { if (kLabel() instanceof KLabelInjection) { return ((KApply) ((KLabelInjection) kLabel()).term()).klist(); } else { return (KList) KCollection.upKind(kList(), Kind.KLIST); } } }
public static K flattenTerm(Module mod, KApply kapp) { List<K> items = new ArrayList<>(); Att att = mod.attributesFor().apply(KLabel(kapp.klabel().name())); if (att.contains("assoc") && att.contains("unit")) { items = Assoc.flatten(kapp.klabel(), kapp.klist().items(), KLabel(att.get("unit"))); } else { items = kapp.klist().items(); } return KApply(kapp.klabel(), KList(items), kapp.att()); }
/** * Takes a rule representing a predicate of one sort and promotes it to a rule representing a predicate for one of its supersorts */ private Rule promotePredicate(Rule r, Sort s) { K left = RewriteToTop.toLeft(r.body()); K right = RewriteToTop.toRight(r.body()); if (left instanceof KApply) { // the case where a rewrite applies unconditionally may be dependent on the klabel, so we hoist the rhs into the side condition return Rule(KRewrite(KApply(KLabel("is" + s.toString()), ((KApply) left).klist()), BooleanUtils.TRUE), BooleanUtils.and(r.requires(), right), r.ensures(), r.att()); } else { throw new IllegalArgumentException("not a predicate rule"); } } }
@Override public K apply(KApply k) { if (k.att().contains("dummy_cell")) { KLabel klabel = KLabel(k.klabel().name() + "-fragment"); return KApply(klabel, k.klist(), k.att()); } return super.apply(k); } }.apply(term);