private Term getCanonicalKSeq(Term term) { return stream(Assoc.flatten(kSeqLabel, Seq(term), kDotLabel).reverse()) .map(Term.class::cast) .reduce((a, b) -> KItem.of(kSeqLabel, KList.concatenate(b, a), termContext.global())) .orElse(kDot); }
/** * 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(); }
@Override public K apply(KApply k) { if (k.klabel() instanceof KVariable) { return super.apply(k); } Att att = test.attributesFor().apply(KLabel(k.klabel().name())); if (att.contains("comm") && att.contains("assoc") && att.contains("unit")) { List<K> items = new ArrayList<>(Assoc.flatten(k.klabel(), k.klist().items(), KLabel(att.get("unit")))); List<Tuple2<String, K>> printed = new ArrayList<>(); for (K item : items) { String s = unparseInternal(test, apply(item), ColorSetting.OFF); printed.add(Tuple2.apply(s, item)); } printed.sort(Comparator.comparing(Tuple2::_1, new AlphanumComparator())); items = printed.stream().map(Tuple2::_2).map(this::apply).collect(Collectors.toList()); return items.stream().reduce((k1, k2) -> KApply(k.klabel(), k1, k2)).orElse(KApply(KLabel(att.get("unit")))); } return super.apply(k); } }.apply(input);
KLabel collectionLabel = collectionFor.get(((KApply)threadsCellSet).klabel()); KLabel unitLabel = KLabel(m.attributesFor().get(collectionLabel).get().get("unit")); List<K> threads = Assoc.flatten(collectionLabel, Collections.singletonList(threadsCellSet), unitLabel); K firstConcreteThread = null; List<K> otherThreadComponents = new ArrayList<>();
List<K> components = Assoc.flatten(collectionLabel, Collections.singletonList(left), m); if (att.contains(Attribute.COMMUTATIVE_KEY)) { if (att.contains(Attribute.IDEMPOTENT_KEY)) {
encodeStringToIdentifier(sb, collectionLabel); sb.append(", "); List<K> components = Assoc.flatten(collectionLabel, Collections.singletonList(new LiftToKSequence().lower(k)), mainModule); LiftToKSequence lift = new LiftToKSequence(); boolean frame = false;
if (kapp.klabel().equals(compiledDefinition.topCellInitializer)) { if (kapp.klist().size() == 1) { List<K> elements = Assoc.flatten(KLabel("_Map_"), kapp.klist().items(), KLabel(".Map")); for (K element : elements) { if (element instanceof KApply) {
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()); }
private Rule convert(Rule rule) { Map<KVariable, KApply> predicates = new HashMap<>(); K requires = rule.requires(); List<K> clauses = Assoc.flatten(KLabel("_andBool_"), Collections.singletonList(requires), BooleanUtils.TRUE); for (K clause : clauses) { if (clause instanceof KApply) {
List<K> components = Assoc.flatten(collectionLabel, Collections.singletonList(left), m); if (att.contains(Attribute.COMMUTATIVE_KEY)) { if (att.contains(Attribute.IDEMPOTENT_KEY)) {
KLabelConstant andLabel = KLabel("_andBool_"); List<Term> requiresAndLookups = stream(Assoc.flatten(andLabel, Seq(rule.requires()), null)) .map(this::convert) .collect(Collectors.toList()); List<Term> ensures = stream(Assoc.flatten(andLabel, Seq(rule.ensures()), null)) .map(this::convert) .collect(Collectors.toList());
return genInternal(generatedTop, ensures, cfgAtt, m, kore); List<K> cells = Assoc.flatten(kapp.klabel(), kapp.klist().items(), m); Set<Sentence> accumSentences = Set(); List<Sort> sorts = Lists.newArrayList();