public boolean collectionIsBag(KLabel collectionLabel) { return m.attributesFor().apply(collectionLabel).contains(Attribute.COMMUTATIVE_KEY) && !m.attributesFor().apply(collectionLabel).contains(Attribute.IDEMPOTENT_KEY) && m.attributesFor().apply(collectionLabel).contains(Att.bag()); }
public boolean collectionIsMap(KLabel collectionLabel) { return m.attributesFor().apply(collectionLabel).contains(Attribute.COMMUTATIVE_KEY) && !m.attributesFor().apply(collectionLabel).contains(Attribute.IDEMPOTENT_KEY) && !m.attributesFor().apply(collectionLabel).contains(Att.bag()); }
public boolean collectionIsMap(KLabel collectionLabel) { return m.attributesFor().apply(collectionLabel).contains(Attribute.COMMUTATIVE_KEY) && !m.attributesFor().apply(collectionLabel).contains(Attribute.IDEMPOTENT_KEY) && !m.attributesFor().apply(collectionLabel).contains(Att.bag()); }
public boolean collectionIsMap(KLabel collectionLabel) { return mod.attributesFor().apply(collectionLabel).contains(Attribute.COMMUTATIVE_KEY) && !mod.attributesFor().apply(collectionLabel).contains(Attribute.IDEMPOTENT_KEY) && !mod.attributesFor().apply(collectionLabel).contains(Att.bag()); }
public Definition invoke(Module module, KExceptionManager kem, GlobalContext global) { if (cache.containsKey(module)) { return cache.get(module); } Definition definition = new Definition(module, kem); global.setDefinition(definition); JavaConversions.setAsJavaSet(module.attributesFor().keySet()).stream() .map(l -> KLabelConstant.of(l, definition)) .forEach(definition::addKLabel); definition.addKoreRules(module, global); cache.put(module, definition); return definition; } }
@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);
private KLabel getWrapElement(KLabel collectionLabel) { return KLabel(m.attributesFor().apply(collectionLabel).get("wrapElement")); }
private KLabel getWrapElement(KLabel collectionLabel) { return KLabel(m.attributesFor().apply(collectionLabel).get("wrapElement")); }
@Override public Optional<KApply> apply(KApply k) { if (k.klabel() instanceof KVariable) { return super.apply(k); } if (m.attributesFor().apply(k.klabel()).contains("thread")) { return Optional.of(k); } return super.apply(k); }
JavaConversions.mapAsJavaMap(module.attributesFor()).entrySet().stream().forEach(e -> { attributesBuilder.put(e.getKey().name(), e.getValue()); });
@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);
private Optional<Sort> getPredicateSort(Rule r) { KLabel topKLabel; Optional<Sort> sort; if (r.body() instanceof KApply) { topKLabel = ((KApply) r.body()).klabel(); sort = mod.attributesFor().apply(topKLabel).getOptional(Attribute.PREDICATE_KEY, Sort.class); } else if (r.body() instanceof KRewrite) { KRewrite rw = (KRewrite) r.body(); if (rw.left() instanceof KApply) { topKLabel = ((KApply) rw.left()).klabel(); sort = mod.attributesFor().apply(topKLabel).getOptional(Attribute.PREDICATE_KEY, Sort.class); } else { sort = Optional.empty(); } } else sort = Optional.empty(); return sort; }
private boolean isUnit(K item, boolean klist, boolean rhs, VarInfo vars, boolean anywhereRule) { return isList(item, klist, rhs, vars, anywhereRule) && item instanceof KApply && !(((KApply)item).klabel() instanceof KVariable) && mainModule.attributesFor().apply(((KApply)item).klabel()).contains("returnsUnit"); }
if (threadsCellSet instanceof KApply) { 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;
@Override public K apply(KApply k) { for (KLabel collectionLabel : collectionFor.keySet()) { Optional<String> wrapElement = m.attributesFor().apply(collectionLabel).getOptional("wrapElement"); if (wrapElement.isPresent()) { KLabel wrappedLabel = KLabel(wrapElement.get()); KLabel elementLabel = KLabel(m.attributesFor().apply(collectionLabel).get("element")); if (k.klabel().equals(elementLabel)) { return k; } if (k.klabel().equals(wrappedLabel)) { if (collectionIsMap(collectionLabel)) { // Map return KApply(elementLabel, super.apply(k.klist().items().get(0)), super.apply(k)); } else { return KApply(elementLabel, super.apply(k)); } } } } return super.apply(k); } }.apply(term);
@Override public K apply(KApply k) { if (m.attributesFor().apply(k.klabel()).contains("thread")) { return KApply(k.klabel(), KApply(KLabel("#ThreadLocal"))); } return super.apply(k); } }.apply(body);
@Override public K apply(KApply k) { for (KLabel collectionLabel : collectionFor.keySet()) { Optional<String> wrapElement = m.attributesFor().apply(collectionLabel).getOptional("wrapElement"); if (wrapElement.isPresent()) { KLabel wrappedLabel = KLabel(wrapElement.get()); KLabel elementLabel = KLabel(m.attributesFor().apply(collectionLabel).get("element")); if (k.klabel().equals(elementLabel)) { return k; } if (k.klabel().equals(wrappedLabel)) { if (collectionIsMap(collectionLabel)) { // Map return KApply(elementLabel, super.apply(k.klist().items().get(0)), super.apply(k)); } else if (collectionIsBag(collectionLabel)) { // bags are handled differently in the java backend, so we don't want to infer here return super.apply(k); } else { return KApply(elementLabel, super.apply(k)); } } } } return super.apply(k); } }.apply(term);
if (inner.production().klabel().equals(outer.production().klabel()) && inner.production().klabel().isDefined() && m.attributesFor().apply(inner.production().klabel().get()).contains(Attribute.ASSOCIATIVE_KEY)) return false; if (inner instanceof Constant)
Att att = m.attributesFor().apply(collectionLabel);
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()); }