public ConvertDataStructureToLookup(Module m, boolean matchOnConsList) { this.m = m; collectionFor = collectionFor(m); this.matchOnConsList = matchOnConsList; }
@Override public void apply(KApply k) { if (ConvertDataStructureToLookup.isLookupKLabel(k)) { h.i++; } super.apply(k); } }.apply(r.requires());
private Context convert(Context context) { reset(); gatherVars(context.body(), vars); gatherVars(context.requires(), vars); K body = transform(context.body()); return new Context( body, addSideCondition(context.requires()), context.att()); }
public void initialize(CompiledDefinition def) { Function1<Module, Module> generatePredicates = new GenerateSortPredicateRules(false)::gen; this.convertDataStructure = new ConvertDataStructureToLookup(def.executionModule(), true); ModuleTransformer convertLookups = ModuleTransformer.fromSentenceTransformer(convertDataStructure::convert, "convert data structures to lookups"); ModuleTransformer liftToKSequence = ModuleTransformer.fromSentenceTransformer(new LiftToKSequence()::lift, "lift K into KSequence"); .andThen(liftToKSequence); mainModule = pipeline.apply(def.executionModule()); collectionFor = ConvertDataStructureToLookup.collectionFor(mainModule); filteredMapConstructors = ConvertDataStructureToLookup.filteredMapConstructors(mainModule);
KVariable set = newDotVariable(); K accum = set; gatherVars(element, vars); if (vars.isEmpty()) { state.add(KApply(KLabel("Set:in"), element, accum));
public void initialize(DefinitionToOcaml serialized, CompiledDefinition def) { mainModule = serialized.mainModule; collectionFor = serialized.collectionFor; filteredMapConstructors = serialized.filteredMapConstructors; matchThreadSet = serialized.matchThreadSet; rewriteThreadSet = serialized.rewriteThreadSet; makeStuck = serialized.makeStuck; makeUnstuck = serialized.makeUnstuck; functions = serialized.functions; anywhereKLabels = serialized.anywhereKLabels; options = serialized.options; constants = serialized.constants; realStepFunctions = serialized.realStepFunctions; if (serialized.expandMacros == null) { serialized.expandMacros = new ExpandMacros(def.executionModule(), files, kompileOptions, false); } if (serialized.convertDataStructure == null) { serialized.convertDataStructure = new ConvertDataStructureToLookup(def.executionModule(), true); } expandMacros = serialized.expandMacros; convertDataStructure = serialized.convertDataStructure; threadCellExists = serialized.threadCellExists; if (serialized.exitCodePattern == null) { serialized.exitCodePattern = def.exitCodePattern; } exitCodePattern = serialized.exitCodePattern; sortHooks = userSortHooks; klabelsForEachPredicate = serialized.klabelsForEachPredicate; }
continue; gatherVars(k1.klist().items().get(1), rhsVars); for (KApply k2 : state) { Multiset<KVariable> lhsVars = HashMultiset.create(); continue; gatherVars(k2.klist().items().get(0), lhsVars); for (KVariable var : rhsVars) { if (lhsVars.contains(var)) {
list = newDotVariable();
/** * Adds lookups to the side condition in sorted order in which they must be performed. * Lookups are sorted based on dependencies between each other, * but non-lookup operations appear in no particular order with respect to the lookups. * @param requires Previous side condition, if any. * @return Side condition generated by this compiler pass + previous side condition. */ K addSideCondition(K requires) { Optional<KApply> sideCondition = getSortedLookups().reduce(BooleanUtils::and); if (!sideCondition.isPresent()) { return requires; } else if (requires.equals(BooleanUtils.TRUE) && sideCondition.isPresent()) { return sideCondition.get(); } else { // we order lookups before the requires clause so that the fresh constant // matching side condition remains last. This is necessary in order to // ensure that fresh constants in rule RHSs are consecutive return BooleanUtils.and(sideCondition.get(), requires); } }
public Sentence convert(Sentence s) { if (s.att().contains(Attribute.LEMMA_KEY) || s.att().contains(Attribute.SMT_LEMMA_KEY) || s.att().contains(Attribute.PATTERN_FOLDING_KEY)) { return s; } else if (s instanceof Rule) { return convert((Rule) s); } else if (s instanceof Context) { return convert((Context) s); } else { return s; } }
@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);
public Rule convert(Rule r) { Function1<Sentence, Sentence> convertLookups = new ConvertDataStructureToLookup(this.convertDataStructure)::convert; Function1<Sentence, Sentence> liftToKSequence = new LiftToKSequence()::lift; Function1<Sentence, Sentence> deconstructInts = new DeconstructIntegerAndFloatLiterals()::convert; Function1<Sentence, Sentence> expandMacros = this.expandMacros::expand; return (Rule) convertLookups .andThen(deconstructInts) .andThen(expandMacros) .andThen(liftToKSequence) .apply(r); }
gatherVars(RewriteToTop.toLeft(body), varConstraints); return new TransformK() { public K apply(KApply k) {
KVariable map = newDotVariable();
private Rule convert(Rule rule) { reset(); gatherVars(rule.body(), vars); gatherVars(rule.requires(), vars); gatherVars(rule.ensures(), vars); K body = transform(rule.body()); return Rule( body, addSideCondition(rule.requires()), rule.ensures(), rule.att()); }
public static boolean isLookupKLabel(KApply k) { return isLookupKLabel(k.klabel()); }
public AddSortInjections(Module mod) { this.mod = mod; this.collectionFor = ConvertDataStructureToLookup.collectionFor(mod); }
private void forEachKLabel(Consumer<Tuple2<KLabel, Long>> action) { for (KLabel label : iterable(mainModule.definedKLabels())) { if (ConvertDataStructureToLookup.isLookupKLabel(label) || label.name().equals("#KToken")) continue; stream(mainModule.productionsFor().apply(label)).map(p -> Tuple2.apply(p.klabel().get(), stream(p.items()).filter(pi -> pi instanceof NonTerminal).count())).distinct().forEach(action); } }
public SplitThreadsCell(Module m) { collectionFor = ConvertDataStructureToLookup.collectionFor(m); this.m = m; this.info = new LabelInfoFromModule(m); this.configInfo = new ConfigurationInfoFromModule(m); }
return; if (ConvertDataStructureToLookup.isLookupKLabel(k)) { apply(BooleanUtils.TRUE); } else if (k.klabel().name().equals("#KToken")) {