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 Production funProd(KLabel fun, K k) { List<ProductionItem> pis = new ArrayList<>(); K left = RewriteToTop.toLeft(k); K right = RewriteToTop.toRight(k); pis.add(Terminal(fun.name())); pis.add(Terminal("(")); pis.add(NonTerminal(sort(left))); for (KVariable var : closure(k)) { pis.add(Terminal(",")); pis.add(NonTerminal(var.att().getOptional(Sort.class).orElse(Sorts.K()))); } pis.add(Terminal(")")); return Production(fun, sort(right), immutable(pis), Att().add("function")); }
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()); } }
freezerLabel = getUniqueFreezerLabel(input, ""); items.add(Terminal(freezerLabel.name())); items.add(Terminal("(")); for (int i = 0; i < vars.size(); i++) { items.add(NonTerminal(Sorts.K())); items.add(Terminal(",")); items.add(Terminal(")")); Production freezer = Production(freezerLabel, Sorts.KItem(), immutable(items), Att()); K frozen = KApply(freezerLabel, vars.values().stream().collect(Collections.toList()));
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); }
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); }
items.add(Terminal(((Terminal) it).getTerminal())); } else { throw new AssertionError("Unhandled case");
Terminal("<" + cellName + ">")), childSorts.stream() .map(Constructors::NonTerminal)), Stream.of(Terminal("</" + cellName + ">"))) .collect(Collectors.toList()); 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")); fragmentItems.add(Terminal("<"+cellName+">-fragment")); for (Sort childSort : childSorts) { if (!childSort.name().endsWith("Cell")) { sentences.add(Production(KLabel("no"+childSort.toString()), childOptSort, List(Terminal("no"+childSort.toString())), Att().add(Attribute.CELL_OPT_ABSENT_KEY,Sort.class,childSort))); fragmentItems.add(Terminal("</"+cellName+">-fragment")); if (!m.definedKLabels().contains(KLabel("<" + cellName + ">-fragment"))) { sentences.add(Production(KLabel("<" + cellName + ">-fragment"), fragmentSort, immutable(fragmentItems), if (type.equals("Map")) { bagElement = Production(KLabel(bagSort.name() + "Item"), bagSort, Seq( Terminal(bagSort.name() + "Item"), Terminal("("), NonTerminal(childSorts.get(0)), Terminal(","),
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(","), 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)
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));
@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(), 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")), .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>")), Att().add("cell").add("cellName", "k").add("maincell").add("format", "%1%i%n%2%d%n%3")), Production(KLabel("<opt>"), Sort("OptCell"), Seq(Terminal("<opt>"), NonTerminal(Sort("OptCellContent")), Terminal("</opt>")), Att().add("cell").add("cellName", "opt").add("multiplicity","?").add("unit",".OptCell").add("format", "%1%i%n%2%d%n%3")),