private KLabel getUniqueLambdaLabel(String nameHint1, String nameHint2) { if (klabels.isEmpty()) { klabels.addAll(mutable(module.definedKLabels())); } int counter = 0; KLabel freezer; do { freezer = KLabel("#lambda" + nameHint1 + "_" + nameHint2 + "_" + (counter++ == 0 ? "" : counter)); } while (klabels.contains(freezer)); klabels.add(freezer); return freezer; }
private KLabel getUniqueFreezerLabel(Module input, String nameHint) { if (klabels.isEmpty()) { klabels.addAll(mutable(input.definedKLabels())); } int counter = 0; KLabel freezer; do { freezer = KLabel("#freezer" + nameHint + "_" + (counter++ == 0 ? "" : counter)); } while (klabels.contains(freezer)); klabels.add(freezer); return freezer; }
private void addOpaqueKLabels(Set<KLabel> klabels) { if (options.klabels == null) return; File definitionFile = files.resolveWorkingDirectory(options.klabels).getAbsoluteFile(); List<File> lookupDirectories = kompileOptions.outerParsing.includes.stream().map(files::resolveWorkingDirectory).collect(Collectors.toList()); lookupDirectories.add(Kompile.BUILTIN_DIRECTORY); java.util.Set<Module> mods = new ParserUtils(files::resolveWorkingDirectory, kem, globalOptions).loadModules( new HashSet<>(), "require " + StringUtil.enquoteCString(definitionFile.getPath()), Source.apply(definitionFile.getAbsolutePath()), definitionFile.getParentFile(), lookupDirectories, new HashSet<>(), false); mods.stream().forEach(m -> klabels.addAll(mutable(m.definedKLabels()))); }
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); } }
private void apply(KLabel klabel, K k) { if (klabel instanceof KVariable) return; if (!m.definedKLabels().apply(klabel) && !isInternalKLabel(klabel.name(), m)) { errors.add(KEMException.compilerError("Found klabel " + klabel.name() + " not defined in any production.", k)); } } };
sb.append("\n"); Set<KLabel> klabels = mutable(mainModule.definedKLabels()); klabels.add(KLabel("#Bottom")); klabels.add(KLabel("littleEndianBytes"));
.collect(Collectors.toList()); sb.append("let rec get_next_op_from_exp(c: kitem) : (k -> k * (step_function)) = "); Set<KLabel> allStepFunctions = Sets.difference(mutable(mainModule.definedKLabels()), functions); Map<Optional<KLabel>, List<Rule>> groupedByStepFunction = sortedRules.stream().collect( Collectors.groupingBy(r -> getNextOperation(RewriteToTop.toLeft(r.body()), false)));
att = att.add("format", format.toString()); if(!m.definedKLabels().contains(KLabel(klabel)) && multiplicity != Multiplicity.OPTIONAL) { Production cellProduction = Production(KLabel(klabel), sort, immutable(items), att); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel)), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); if (!m.definedKLabels().contains(KLabel(initLabel))) { sentences.add(initializer); if (!m.definedKLabels().contains(KLabel("no"+childSort.toString()))) { sentences.add(Production(KLabel("no"+childSort.toString()), childOptSort, List(Terminal("no"+childSort.toString())), Att().add(Attribute.CELL_OPT_ABSENT_KEY,Sort.class,childSort))); if (!m.definedKLabels().contains(KLabel("<" + cellName + ">-fragment"))) { sentences.add(Production(KLabel("<" + cellName + ">-fragment"), fragmentSort, immutable(fragmentItems), Att().add(Attribute.CELL_FRAGMENT_KEY, Sort.class, Sort(sortName)))); sentences.add(cellUnit); if(!m.definedKLabels().contains(KLabel(klabel))) { Production cellProduction = Production(KLabel(klabel), sort, immutable(items), att.add(Attribute.UNIT_KEY, cellUnit.klabel().get().name())); sentences.add(cellProduction);
private static Set<Sentence> genProjection(Sort sort, Module m) { KLabel lbl = getProjectLbl(sort, m); KVariable var = KVariable("K", Att.empty().add(Sort.class, sort)); Rule r = Rule(KRewrite(KApply(lbl, var), var), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("projection")); if (m.definedKLabels().contains(lbl)) { return Set(r); } return Set(Production(lbl, sort, Seq(Terminal(lbl.name()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add("function").add("projection")), r); }
if (mainModule.definedKLabels().contains(stratCell)) { Rule makeStuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KSequence(), KApply(KLabel("#STUCK"))), true), BooleanUtils.TRUE, BooleanUtils.TRUE); Rule makeUnstuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KApply(KLabel("#STUCK")), KSequence()), true), BooleanUtils.TRUE, BooleanUtils.TRUE);
KApply freshCell = KApply(KLabel("#configCell"), counterCellLabel, KApply(KLabel("#cellPropertyListTerminator")), KToken("0", Sorts.Int()), counterCellLabel); if (m.equals(def.mainModule()) && kore) { if (!m.definedKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true);