@Override public Seq<Sort> params() { return Seq(); }
@Override public Seq<org.kframework.kore.Sort> params() { return Seq(); }
public org.kframework.definition.Module apply(Module mainModule, Set<Module> allKilModules, Map<String, org.kframework.definition.Module> koreModules) { return apply(mainModule, allKilModules, koreModules, Seq()); }
private static Set<Sentence> makeCasts(Sort outerSort, Sort innerSort, Sort castSort) { Set<Sentence> prods = new HashSet<>(); Att attrs1 = Att().add(Sort.class, castSort); prods.add(Production(KLabel("#SyntacticCast"), castSort, Seq(NonTerminal(castSort), Terminal("::" + castSort.toString())), attrs1)); prods.add(Production(KLabel("#SemanticCastTo" + castSort.toString()), castSort, Seq(NonTerminal(castSort), Terminal(":" + castSort.toString())), attrs1)); prods.add(Production(KLabel("#InnerCast"), outerSort, Seq(Terminal("{"), NonTerminal(castSort), Terminal("}"), Terminal("<:" + castSort.toString())), attrs1)); prods.add(Production(KLabel("#OuterCast"), castSort, Seq(Terminal("{"), NonTerminal(innerSort), Terminal("}"), Terminal(":>" + castSort.toString())), attrs1)); return prods; } }
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); }
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()); } }
public void applyUserList(Set<org.kframework.definition.Sentence> res, org.kframework.kore.Sort sort, Production p, UserList userList) { // Transform list declarations of the form Es ::= List{E, ","} into something representable in kore org.kframework.kore.Sort elementSort = userList.getSort(); org.kframework.attributes.Att attrs = convertAttributes(p).add(Att.userList(), userList.getListType()); String kilProductionId = "" + System.identityHashCode(p); Att attrsWithKilProductionId = attrs.add(PRODUCTION_ID, kilProductionId); org.kframework.definition.Production prod1, prod3; // Es ::= E "," Es prod1 = Production(KLabel(p.getKLabel(kore)), sort, Seq(NonTerminal(elementSort), Terminal(userList.getSeparator()), NonTerminal(sort)), attrsWithKilProductionId.add("right")); // Es ::= ".Es" prod3 = Production(KLabel(p.getTerminatorKLabel(kore)), sort, Seq(Terminal("." + sort.toString())), attrsWithKilProductionId.remove("format").remove("strict").add("klabel", p.getTerminatorKLabel(false))); res.add(prod1); res.add(prod3); }
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()); } }
Seq(Terminal("is" + sort.toString()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Attribute.FUNCTION_KEY).add(Attribute.PREDICATE_KEY, Sort.class, sort)); res.add(prod);
.map(p -> Production(Sorts.Cell(), Seq(NonTerminal(p.sort())))).collect(Collections.toSet());
public ProductionReference addBrackets(ProductionReference inner, TermCons outer, ProductionReference leftCapture, ProductionReference rightCapture) { if (requiresBracketWithSimpleAlgorithm(outer, leftCapture, rightCapture, inner)) { int position = getPosition(inner, outer); Sort outerSort = ((NonTerminal)outer.production().items().apply(position)).sort(); Sort innerSort = inner.production().sort(); for (Tuple2<Sort, scala.collection.immutable.List<Production>> sort : iterable(m.bracketProductionsFor())) { boolean isCorrectOuterSort = m.subsorts().lessThanEq(sort._1(), outerSort); if (isCorrectOuterSort) { for (Production p : mutable(sort._2())) { boolean isCorrectInnerSort = stream(p.items()) .filter(i -> i instanceof NonTerminal) .map(i -> (NonTerminal) i) .map(NonTerminal::sort) .filter(s -> m.subsorts().lessThanEq(innerSort, s)) .findAny().isPresent(); if (isCorrectInnerSort) { return TermCons.apply(ConsPStack.singleton(inner), p); } } } } return TermCons.apply(ConsPStack.singleton(inner), Production(Sorts.KBott(), Seq(NonTerminal(Sorts.K())))); } return inner; }
Seq<ProductionItem> pi = Seq(p.items().head(), optDots, body, optDots, p.items().last()); Production p1 = Production(p.klabel().get(), p.sort(), pi, p.att()); Production p2 = Production(Sorts.Cell(), Seq(NonTerminal(p.sort()))); return Stream.of(p1, p2); Production p1 = Production(Sorts.Cell(), Seq(NonTerminal(p.sort()))); return Stream.of(p, p1); if (!isParserSort(srt) && !mod.listSorts().contains(srt)) { prods3.add(Production(Sorts.K(), Seq(NonTerminal(srt)), Att())); prod1 = Production(ul.terminatorKLabel, Sort(ul.sort.name() + "#Terminator", ul.sort.params()), Seq(Terminal("")), newAtts.remove("format").add(Constants.ORIGINAL_PRD, Production.class, ul.pTerminator)); Seq(NonTerminal(ul.childSort), Terminal(ul.separator), NonTerminal(Sort("Ne#" + ul.sort.name(), ul.sort.params()))), newAtts.add(Constants.ORIGINAL_PRD, Production.class, ul.pList)); Seq(NonTerminal(ul.childSort), Terminal(""), NonTerminal(Sort(ul.sort.name() + "#Terminator", ul.sort.params()))), newAtts.add(Constants.ORIGINAL_PRD, Production.class, ul.pList)); prod4 = Production(ul.sort, Seq(NonTerminal(Sort("Ne#" + ul.sort.name(), ul.sort.params())))); prod5 = Production(ul.sort, Seq(NonTerminal(Sort(ul.sort.name() + "#Terminator", ul.sort.params())))); prod1 = Production(ul.sort, Seq(NonTerminal(ul.childSort))); res.add(prod1);
Rule initializerRule; if (hasConfigurationOrRegularVariable || isStream) { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel), Terminal("("), NonTerminal(Sorts.Map()), Terminal(")")), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel), INIT), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); } else { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel)), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel)), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); Sentence bagSubsort = Production(bagSort, Seq(NonTerminal(sort))); Sentence bagElement; if (type.equals("Map")) { bagElement = Production(KLabel(bagSort.name() + "Item"), bagSort, Seq( Terminal(bagSort.name() + "Item"), Terminal("("), Terminal(")")), Att().add(Attribute.HOOK_KEY, elementHook).add(Attribute.FUNCTION_KEY)); } else { bagElement = Production(KLabel(bagSort.name() + "Item"), bagSort, Seq( Terminal(bagSort.name() + "Item"), Terminal("("), Sentence bagUnit = Production(KLabel("." + bagSort.name()), bagSort, Seq(Terminal("." + bagSort.name())), Att().add(Attribute.HOOK_KEY, unitHook).add(Attribute.FUNCTION_KEY)); Sentence bag = Production(KLabel("_" + bagSort + "_"), bagSort, Seq(NonTerminal(bagSort), NonTerminal(bagSort)), bagAtt); sentences.add(sortDecl); Production cellUnit = Production(KLabel("." + sortName), sort, Seq(Terminal("." + sortName))); sentences.add(cellUnit);
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());
ModuleTransformer.fromSentenceTransformer(s -> s, "identity function -- no transformation"); ModuleTransformer preprocessKLabelPredicates = ModuleTransformer.fromSentenceTransformer(new PreprocessKLabelPredicates(def.executionModule())::convert, "preprocess klabel predicates"); Sentence thread = Production(KLabel("#Thread"), Sorts.KItem(), Seq( Terminal("#Thread"), Terminal("("), NonTerminal(Sorts.K()), Terminal(","), NonTerminal(Sorts.K()), Terminal(","), NonTerminal(Sorts.K()), Terminal(")"))); Sentence bottom = Production(KLabel("#Bottom"), Sorts.KItem(), Seq(Terminal("#Bottom"))); Sentence threadLocal = Production(KLabel("#ThreadLocal"), Sorts.KItem(), Seq(Terminal("#ThreadLocal"))); Function1<Module, Module> pipeline = preprocessKLabelPredicates .andThen(splitThreadCell)
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); }
@Test public void testSingleTop() { Production prod = Production(KLabel(".Opt"), Sort("OptCellContent"), Seq(Terminal(""))); Production prod2 = Production(KLabel("#SemanticCastToKItem"), Sort("KItem"), Seq(NonTerminal(Sort("KItem")))); K configuration = cell("threads", Collections.emptyMap(), cell("thread", Collections.singletonMap("multiplicity", "*"), Att productionAtts = initializerAtts.add("function").add("noThread"); Set<Sentence> reference = Set(Production(KLabel("<threads>"), Sort("ThreadsCell"), Seq(Terminal("<threads>"), NonTerminal(Sort("ThreadCellBag")), Terminal("</threads>")), Att().add("cell").add("cellName", "threads").add("topcell").add("format", "%1%i%n%2%d%n%3")), SyntaxSort(Sort("ThreadCellBag"), Att().add("hook", "BAG.Bag")), Production(KLabel("_ThreadCellBag_"), Sort("ThreadCellBag"), Seq(NonTerminal(Sort("ThreadCellBag")), NonTerminal(Sort("ThreadCellBag"))), Att().add("assoc","").add("comm","").add("unit",".ThreadCellBag") .add("element","ThreadCellBagItem").add("wrapElement","<thread>") .add("function").add("avoid").add("bag").add("cellCollection").add("hook","BAG.concat")), Production(KLabel(".ThreadCellBag"), Sort("ThreadCellBag"), Seq(Terminal(".ThreadCellBag")), Att().add("function").add("hook","BAG.unit")), Production(Sort("ThreadCellBag"), Seq(NonTerminal(Sort("ThreadCell")))), Production(KLabel("ThreadCellBagItem"), Sort("ThreadCellBag"), Seq(Terminal("ThreadCellBagItem"), Terminal("("), NonTerminal(Sort("ThreadCell")), Terminal(")")), Att().add("function").add("hook","BAG.element")), Production(KLabel("<thread>"), Sort("ThreadCell"), Seq(Terminal("<thread>"), NonTerminal(Sort("KCell")), NonTerminal(Sort("OptCell")), Terminal("</thread>")), Att().add("cell").add("cellName", "thread").add("multiplicity","*").add("format", "%1%i%n%2%n%3%d%n%4")), Production(KLabel("<k>"), Sort("KCell"), Seq(Terminal("<k>"), NonTerminal(Sort("K")), Terminal("</k>")),