@Override public void apply(KSequence k) { if (k.items().size() == 1 && inBooleanExp) { apply(k.items().get(0)); return; } if (vars.termCache.containsKey(k) && rhs) { sb.append(vars.termCache.get(k)); return; } sb.append("("); if (!rhs) { for (int i = 0; i < k.items().size() - 1; i++) { if (isList(k.items().get(i), false, false, vars, topAnywherePost)) { throw KEMException.criticalError("Cannot compile KSequence with K variable not at tail.", k.items().get(i)); } } } apply(k.items(), false); sb.append(")"); }
@Override public K apply(KSequence k) { ArrayList<K> newItems = new ArrayList<>(k.items()); boolean change = false; for (int i = 0; i < newItems.size(); ++i) { K in = newItems.get(i); K out = apply(newItems.get(i)); newItems.set(i, out); change = change || (in != out); } if (change) { return KSequence(newItems, k.att()); } else { return k; } }
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); } }
@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(")"); } }
@Override public K apply(KSequence k) { k = (KSequence) super.apply(k); return KSequence(k.items(), k.att()); }
if (kseq.items().size() != 1 || !(kseq.items().get(0) instanceof KApply)) { throw KEMException.compilerError("Unexpected form for klabel predicate rule, expected predicate(_) => false [owise] or predicate(#klabel(`klabel`)) => true.", r); KApply function = (KApply)kseq.items().get(0); if (function.items().size() != 1 || !(function.items().get(0) instanceof KSequence)) { throw KEMException.compilerError("Unexpected form for klabel predicate rule, expected predicate(_) => false [owise] or predicate(#klabel(`klabel`)) => true.", r); if (kseq.items().size() != 1 || !(kseq.items().get(0) instanceof InjectedKLabel)) { throw KEMException.compilerError("Unexpected form for klabel predicate rule, expected predicate(_) => false [owise] or predicate(#klabel(`klabel`)) => true.", r); InjectedKLabel injection = (InjectedKLabel) kseq.items().get(0); if (injection.klabel() instanceof KVariable) { throw KEMException.compilerError("Unexpected form for klabel predicate rule, expected predicate(_) => false [owise] or predicate(#klabel(`klabel`)) => true.", r);
@Override public void apply(KApply k) { if (k.klabel().name().equals("<k>")) { if (k.klist().items().size() == 1) { if (k.klist().items().get(0) instanceof KSequence) { KSequence seq = (KSequence) k.klist().items().get(0); if (seq.items().size() >= 1) { kCells.add(k); } } } } super.apply(k); } }.apply(body);
if (kCell.isPresent()) { KSequence seq = (KSequence) kCell.get().klist().items().get(0); K topOfKCell = seq.items().get(0); if (topOfKCell instanceof KVariable) { Optional<Sort> sortAtt = topOfKCell.att().getOptional(Sort.class);
@Override public void apply(KApply k) { if (k.klabel().name().equals("<k>")) { if (!hasProblem.booleanValue()) { hasProblem.setTrue(); if (k.klist().items().size() == 1) { if (k.klist().items().get(0) instanceof KSequence) { KSequence seq = (KSequence) k.klist().items().get(0); if (seq.items().size() >= 1) { K head = seq.items().get(0); while (head instanceof KAs) { head = ((KAs) head).pattern(); } if (head instanceof KApply) { KApply app = (KApply) head; if (!(app.klabel() instanceof KVariable)) { if (!rhs || (!functions.contains(app.klabel()) && !anywhereKLabels.contains(app.klabel()))) { nextOps.add(app.klabel()); hasProblem.setFalse(); } } } } } } } } super.apply(k); } }.apply(side);
if (left instanceof KSequence) { KSequence kseq = (KSequence) left; if (kseq.items().size() == 1 && kseq.items().get(0) instanceof KApply) { KApply kapp = (KApply) kseq.items().get(0); if (mainModule.attributesFor().apply(kapp.klabel()).contains(Attribute.FUNCTION_KEY)) { functionRules.put(kapp.klabel(), r);
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; } }
if (k.klist().items().size() == 1) { KSequence item = (KSequence) k.klist().items().get(0); 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)) { if (k.klist().items().get(0) instanceof KSequence) { KSequence item = (KSequence) k.klist().items().get(0); if (item.items().size() == 1) { apply(BooleanUtils.TRUE); return;
List<K> children = new ArrayList<>(); for (int i = 0; i < kseq.size(); i++) { K child = kseq.items().get(i); Sort childSort = sort(child, Sorts.KItem()); if (childSort.equals(Sorts.K())) {
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!"); }