K arg, body; if (lbl.name().equals("#fun2")) { body = k.items().get(0); arg = k.items().get(1); } else { body = KRewrite(k.items().get(0), k.items().get(1)); arg = k.items().get(2); } else if (arg instanceof KApply && ((KApply) arg).klabel().name().startsWith("#SemanticCastTo") && ((KApply) arg).items().get(0) instanceof KVariable) { nameHint1 = ((KVariable) ((KApply) arg).items().get(0)).name();
@Override public void apply(KApply k) { String hook = module.attributesFor().get(k.klabel()).getOrElse(() -> Att.empty()).getOptional("hook").orElse(""); if (hook.equals("SET.element") || hook.equals("LIST.element") || hook.equals("LIST.concat") || hook.equals("MAP.concat") || hook.equals("SET.concat")) { return; } if (hook.equals("MAP.element")) { apply(k.items().get(1)); return; } super.apply(k); } }.apply(term);
h.inRewrite = false; h.hasRewrite = false; apply(k.items().get(0)); if (!h.hasRewrite) { errors.add(KEMException.compilerError("#fun expressions must have at least one rewrite.", k)); apply(k.items().get(1)); } else { boolean wasInRewrite = h.inRewrite; h.inRewrite = true; h.hasRewrite = true; apply(k.items().get(0)); apply(k.items().get(1)); apply(k.items().get(2));
/** * 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 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); } }
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(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(")"); }
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);
K threadsCellSet = threadsCell.items().get(0); if (threadsCellSet instanceof KApply) { KLabel collectionLabel = collectionFor.get(((KApply)threadsCellSet).klabel()); return Tuple3.apply(kapp.items().get(0), kapp, otherThreadComponents.stream().reduce((k1, k2) -> KApply(collectionLabel, k1, k2)).orElse(KApply(unitLabel)));
@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); } }
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 ++) {
if (r.att().contains(Attribute.ANYWHERE_KEY)) { if (kapp.klabel().name().equals(KLabels.INJ)) { K k = kapp.items().get(0); if (k instanceof KApply) { anywhereKLabels.add(((KApply)k).klabel());
Set<Sort> children = new HashSet<>(); for (int position : otherPositions) { children.add(sort(kapp.items().get(position-1), expectedSort));
if (kapp.klabel().equals(KLabels.INIT_GENERATED_TOP_CELL)) { KApply right = (KApply)RewriteToTop.toRight(withFresh.body()); KApply cells = (KApply)right.items().get(1); List<K> items = new ArrayList<>(cells.items()); items.add(KApply(KLabels.INIT_GENERATED_COUNTER_CELL)); KApply newCells = KApply(cells.klabel(), immutable(items)); List<K> rightItems = new ArrayList<>(right.items()); rightItems.set(1, newCells); return Rule(