@Override public DefaultMutableTreeNode apply(KApply k) { boolean childrenAllSmall = true; DefaultMutableTreeNode node = new DefaultMutableTreeNode(k.klabel().name()); for (K child : k.asIterable()) { DefaultMutableTreeNode c = apply(child); if (childrenAllSmall) { childrenAllSmall = c.isLeaf(); } node.add(c); } if (childrenAllSmall) { String text = ToKast.apply(k); if (text.length() < 80) { return new DefaultMutableTreeNode(text); } } return node; }
@Override public void apply(KApply k) { if (impureFunctions.contains(k.klabel().name())) { throw KEMException.internalError("Cannot yet translate impure function to kore: " + k.klabel().name(), k); } KLabel label = k.klabel(); if (polyKLabels.containsKey(k.klabel().name())) { label = computePolyKLabel(k); } convert(label, false); sb.append("("); String conn = ""; for (K item : k.items()) { sb.append(conn); apply(item); conn = ","; } sb.append(")"); }
@Override public void apply(KApply k) { if (k.klabel().name().startsWith("#SemanticCastTo")) { Sort savedContext = context; context = k.att().get(Production.class).sort(); apply(k.items().get(0)); context = savedContext; return; } if (k.klabel() instanceof KVariable) { apply((KVariable) k.klabel()); } super.apply(k); } }
/** * Function to return the exit code specified by the user given a substitution * * @param kem ExcpetionManager object * @param res The substitution from the match of the user specified pattern on the Final Configuration. * @return An int representing the error code. */ public static int getExitCode(KExceptionManager kem, K res) { KApply app = (KApply) res; List<K> solution = Assoc.flatten(KLabels.ML_AND, app.klist().items(), KLabels.ML_TRUE); Set<Integer> vars = new HashSet<>(); for (K conjunct : solution) { if (conjunct instanceof KApply) { KApply kapp = (KApply)conjunct; if (kapp.klabel().equals(KLabel("_==K_"))) { if (kapp.items().get(0) instanceof KVariable && kapp.items().get(1) instanceof KToken) { KToken rhs = (KToken) kapp.items().get(1); if (Sorts.Int().equals(rhs.sort())) { vars.add(Integer.valueOf(rhs.s())); } } } } } if (vars.size() != 1) { kem.registerCriticalWarning("Found " + vars.size() + " integer variables in exit code pattern. Returning 111."); return 111; } return vars.iterator().next(); }
private Integer getRuleIndex(KApply kk) { return definition.reverseRuleTable.get(Integer.valueOf(((KToken) kk.klist().items().get(0)).s())); }
KApply app = (KApply) k; for (K item : app.asIterable()) { traverse(item); writeString(app.klabel().name()); data.writeBoolean(app.klabel() instanceof KVariable); data.writeInt(app.size());
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); kseq = (KSequence) function.items().get(0); 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);
private boolean isList(K item, boolean klist, boolean rhs, VarInfo vars, boolean anywhereRule) { return !klist && ((item instanceof KVariable && getSortOfVar((KVariable)item, vars).equals("K")) || item instanceof KSequence || (item instanceof KAs && isList(((KAs) item).alias(), klist, rhs, vars, anywhereRule)) || (item instanceof KApply && (functions.contains(((KApply) item).klabel()) || (((anywhereKLabels.contains(((KApply) item).klabel()) && !anywhereRule) || ((KApply) item).klabel() instanceof KVariable) && rhs)))) && !(!rhs && item instanceof KApply && collectionFor.containsKey(((KApply) item).klabel())); }
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)); }
public static boolean isOpenLeft(KApply cell) { return isOpen(cell.klist().items().get(0)); } public static boolean isOpenRight(KApply cell) {
private Rule resolveInitRule(Production streamProduction, Rule rule) { Sort streamSort = streamProduction.sort(); // InCell, OutCell String initLabel = GenerateSentencesFromConfigDecl.getInitLabel(streamSort); // initInCell, initOutCell KLabel cellLabel = streamProduction.klabel().get(); // <in>, <out> // rule initInCell(Init) => <in> ... </in> if (isInitRule(initLabel, cellLabel.name(), rule)) { KRewrite body = (KRewrite) rule.body(); KApply right = (KApply) body.right(); KList klist = getContentsOfInitRule(streamProduction); right = KApply(right.klabel(), klist, right.att()); body = KRewrite(body.left(), right, body.att()); return Rule(body, rule.requires(), rule.ensures(), rule.att()); } return rule; }
productionLabel = production.klabel().get(); if (isFunction(prod) || rule.att().contains(Attribute.ANYWHERE_KEY)) { leftChildren = ((KApply) left).items(); equation = true; } else if ((rule.att().contains("heat") || rule.att().contains("cool")) && heatCoolEq) { List<K> notMatchingChildren = ((KApply) notMatchingLeft).items(); assert notMatchingChildren.size() == leftChildren.size() : "assuming function with fixed arity"; for (int childIdx = 0; childIdx < leftChildren.size(); childIdx ++) {