public Module resolve(Module m) { module = m; funProds.clear(); funRules.clear(); Set<Sentence> newSentences = stream(m.localSentences()).map(this::resolve).collect(Collectors.toSet()); newSentences.addAll(funProds); newSentences.addAll(funRules); return Module(m.name(), m.imports(), immutable(newSentences), m.att()); } }
private static Module excludeModulesByTag(Set<String> excludedModuleTags, Module mod) { Set<Module> newImports = stream(mod.imports()).filter(_import -> excludedModuleTags.stream().noneMatch(tag -> _import.att().contains(tag))).collect(Collectors.toSet()); return Module(mod.name(), immutable(newImports), mod.localSentences(), mod.att()); }
public Module resolve(Module input) { Set<Sentence> rulesToAdd = stream(input.sentences()) .filter(s -> s instanceof Context) .map(s -> (Context) s) .flatMap(c -> this.resolve(c, input)).collect(Collectors.toCollection(HashSet::new)); if (!rulesToAdd.isEmpty()) { rulesToAdd.add(SyntaxSort(Sorts.K())); } return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) stream(input.localSentences()).filter(s -> !(s instanceof Context)).collect(Collections.toSet()).$bar(immutable(rulesToAdd)), input.att()); }
public Module resolve(Module input) { Set<Sentence> contextsToAdd = resolve(stream(input.localSentences()) .filter(s -> s instanceof Production) .map(s -> (Production) s) .filter(p -> p.att().contains("strict") || p.att().contains("seqstrict")).collect(Collectors.toSet())); return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) input.localSentences().$bar(immutable(contextsToAdd)), input.att()); } }
public static Module resolve(Module m) { Set<Sentence> newSentences = JavaConverters.asScalaSet(stream(m.localSentences()).map(s -> s instanceof Production ? resolve((Production) s) : s).collect(Collectors.toSet())); return Module(m.name(), m.imports(), newSentences, m.att()); }
public Module gen(Module mod) { this.mod = mod; predicateRules = stream(mod.rules()).filter(this::isPredicate).collect(Collectors.toSet()); return Module(mod.name(), mod.imports(), (Set<Sentence>) mod.localSentences().$bar(stream(mod.definedSorts()) .flatMap(this::gen).collect(Collections.toSet())), mod.att()); }
private void checkDefinition(Definition parsedDef) { CheckRHSVariables checkRHSVariables = new CheckRHSVariables(errors); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(checkRHSVariables::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckConfigurationCells(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckSortTopUniqueness(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckStreams(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckRewrite(errors, m)::check)); stream(parsedDef.modules()).forEach(new CheckImports(parsedDef.mainModule(), kem)::check); Set<String> moduleNames = new HashSet<>(); stream(parsedDef.modules()).forEach(m -> { if (moduleNames.contains(m.name())) { errors.add(KEMException.compilerError("Found multiple modules with name: " + m.name())); } moduleNames.add(m.name()); }); CheckKLabels checkKLabels = new CheckKLabels(errors); // only check imported modules because otherwise we might have false positives Consumer<Module> checkModuleKLabels = m -> stream(m.localSentences()).forEach(s -> checkKLabels.check(s, m)); stream(parsedDef.mainModule().importedModules()).forEach(checkModuleKLabels); checkModuleKLabels.accept(parsedDef.mainModule()); if (!errors.isEmpty()) { kem.addAllKException(errors.stream().map(e -> e.exception).collect(Collectors.toList())); throw KEMException.compilerError("Had " + errors.size() + " structural errors."); } }
private Module resolveNonConfigBubbles(Module module, Scanner scanner, RuleGrammarGenerator gen) { if (stream(module.localSentences()) .filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) if (stream(module.localSentences()).filter(s -> s instanceof Bubble).findAny().isPresent()) { parser.initialize(); final Scanner realScanner = needNewScanner ? parser.getScanner() : scanner; Set<Sentence> ruleSet = stream(module.localSentences()) .parallel() .filter(s -> s instanceof Bubble) .collect(Collections.toSet()); Set<Sentence> contextSet = stream(module.localSentences()) .parallel() .filter(s -> s instanceof Bubble) stream((Set<Sentence>) module.localSentences().$bar(ruleSet).$bar(contextSet)).filter(b -> !(b instanceof Bubble)).collect(Collections.toSet()), module.att());
private KList getContentsOfInitRule(Production streamProduction) { String streamName = streamProduction.att().get("stream"); // stdin, stdout String initLabel = GenerateSentencesFromConfigDecl.getInitLabel( Sort(GenerateSentencesFromConfigDecl.getSortOfCell(streamName))); // initStdinCell, initStdoutCell String cellLabel = "<" + streamName + ">"; // <stdin>, <stdout> java.util.List<Sentence> initRules = stream(getStreamModule(streamName).localSentences()) .filter(s -> isInitRule(initLabel, cellLabel, s)) .collect(Collectors.toList()); assert initRules.size() == 1; Sentence initRule = initRules.get(0); // rule initXCell(Init) => <x> ... </x> KRewrite body = (KRewrite) ((Rule) initRule).body(); KApply right = (KApply) body.right(); return right.klist(); }
java.util.List<Sentence> unblockRules = stream(getStreamModule(streamName).localSentences()) .filter(s -> s instanceof Rule && s.att().contains("unblock")) .collect(Collectors.toList());
return m; } else { java.util.Set<Sentence> sentences = mutable(m.localSentences()); if (!getStreamProductions(m.localSentences()).isEmpty()) { for (Production p : streamProductions) { sentences.addAll(getStreamModuleSentences(p));
return Module.apply(oldMod.name(), immutable(imports), oldMod.localSentences(), oldMod.att()); }, "apply program parsing modules").apply(mod);
public static Module subsortKItem(Module module) { java.util.Set<Sentence> prods = new HashSet<>(); for (Sort srt : iterable(module.definedSorts())) { if (!RuleGrammarGenerator.isParserSort(srt)) { // KItem ::= Sort Production prod = Production(Sorts.KItem(), Seq(NonTerminal(srt)), Att()); if (!module.sentences().contains(prod)) { prods.add(prod); } } } if (prods.isEmpty()) { return module; } else { return Module(module.name(), module.imports(), Stream.concat(stream(module.localSentences()), prods.stream()) .collect(org.kframework.Collections.toSet()), module.att()); } }
java.util.Set<Module> imports = mutable(mod.imports()); imports.add(defaultConfiguration); return Module(mod.name(), (Set<Module>) immutable(imports), mod.localSentences(), mod.att());
for (Sentence s : mutable(getStreamModule(streamName).localSentences())) { if (s instanceof Rule) { Rule rule = (Rule) s; for (Sentence s : mutable(getStreamSyntaxModule(streamName).localSentences())) { if (s instanceof Production) { Production production = (Production) s;
public Module apply(Module inputModule) { if (stream(inputModule.localSentences()) .filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) (Set<Sentence>) inputModule.localSentences().$bar(importedConfigurationSortsSubsortedToCell), inputModule.att()); Set<Sentence> configDeclProductions = stream(module.localSentences()) .parallel() .filter(s -> s instanceof Bubble) (Set<Sentence>) module.localSentences().$bar(configDeclSyntax), module.att()); } else { (Set<Sentence>) module.localSentences().$bar(configDeclRules), module.att());
public Module gen(Module mod) { Set<Sentence> res = new HashSet<>(); for (Sort sort : iterable(mod.definedSorts())) { Production prod = Production(KLabel("is" + sort.toString()), Sorts.Bool(), Seq(Terminal("is" + sort.toString()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Attribute.FUNCTION_KEY).add(Attribute.PREDICATE_KEY, Sort.class, sort)); if (!mod.productions().contains(prod)) res.add(prod); } if (!res.isEmpty()) { res.add(SyntaxSort(Sorts.K())); } return Module(mod.name(), mod.imports(), (scala.collection.Set<Sentence>) mod.localSentences().$bar(immutable(res)), mod.att()); } }
.andThen(splitThreadCell) .andThen(mod -> Module(mod.name(), mod.imports(), Stream.concat(stream(mod.localSentences()), Stream.<Sentence>of(thread, bottom, threadLocal)).collect(org.kframework.Collections.toSet()), mod.att())) .andThen(convertLookups)
public Module resolve(Module m) { this.m = m; Set<Sentence> sentences = map(this::resolve, m.localSentences()); KToken counterCellLabel = KToken("generatedCounter", Sort("#CellName")); KApply freshCell = KApply(KLabel("#configCell"), counterCellLabel, KApply(KLabel("#cellPropertyListTerminator")), KToken("0", Sorts.Int()), counterCellLabel); sentences = (Set<Sentence>) sentences.$bar(newSentences); if (sentences.equals(m.localSentences())) { return m;