private Rule upRule(K contents) { KApply ruleContents = (KApply) contents; List<org.kframework.kore.K> items = ruleContents.klist().items(); switch (ruleContents.klabel().name()) { case "#ruleNoConditions": return Rule(items.get(0), BooleanUtils.TRUE, BooleanUtils.TRUE, ruleContents.att()); case "#ruleRequires": return Rule(items.get(0), items.get(1), BooleanUtils.TRUE, ruleContents.att()); case "#ruleEnsures": return Rule(items.get(0), BooleanUtils.TRUE, items.get(1), ruleContents.att()); case "#ruleRequiresEnsures": return Rule(items.get(0), items.get(1), items.get(2), ruleContents.att()); default: throw new AssertionError("Wrong KLabel for rule content"); } }
private Rule getExitCodeRule(Definition parsedDefinition) { Module mainMod = parsedDefinition.mainModule(); Set<Production> exitProds = stream(mainMod.productions()).filter(p -> p.att().contains("exit")).collect(Collectors.toSet()); if (exitProds.size() == 0) { return null; } else if (exitProds.size() > 1) { throw KEMException.compilerError("Found more than one or zero productions with 'exit' attribute. Exactly one production, a cell, must have this attribute, designating the exit code of krun. Found:\n" + exitProds); } Production exitProd = exitProds.iterator().next(); return Rule(IncompleteCellUtils.make(exitProd.klabel().get(), false, KApply(KLabel("#SemanticCastToInt"), KVariable("_")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); }
private Stream<? extends Sentence> genKore(Sort sort) { if (sort.equals(Sorts.K())) { return Stream.of(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); } else { List<Sentence> res = new ArrayList<>(); res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable(sort.name(), Att().add(Sort.class, sort))), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.FALSE), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("owise"))); return res.stream(); } }
private Rule funRule(KLabel fun, K k, Att att) { K resolved = transform(k); K withAnonVars = new ResolveAnonVar().resolveK(resolved); List<K> klist = new ArrayList<>(); klist.add(RewriteToTop.toLeft(withAnonVars)); klist.addAll(closure(k)); return Rule(KRewrite(KApply(fun, KList(klist)), RewriteToTop.toRight(withAnonVars)), BooleanUtils.TRUE, BooleanUtils.TRUE, att); }
private Rule lift(Rule rule) { return Rule( lift(rule.body()), lift(rule.requires()), lift(rule.ensures()), rule.att()); }
private Rule preprocess(Rule rule) { return Rule( preprocess(rule.body()), preprocess(rule.requires()), preprocess(rule.ensures()), rule.att()); }
/** * Takes a rule representing a predicate of one sort and promotes it to a rule representing a predicate for one of its supersorts */ private Rule promotePredicate(Rule r, Sort s) { K left = RewriteToTop.toLeft(r.body()); K right = RewriteToTop.toRight(r.body()); if (left instanceof KApply) { // the case where a rewrite applies unconditionally may be dependent on the klabel, so we hoist the rhs into the side condition return Rule(KRewrite(KApply(KLabel("is" + s.toString()), ((KApply) left).klist()), BooleanUtils.TRUE), BooleanUtils.and(r.requires(), right), r.ensures(), r.att()); } else { throw new IllegalArgumentException("not a predicate rule"); } } }
private Rule postprocess(Rule rule) { return Rule( postprocess(rule.body()), postprocess(rule.requires()), postprocess(rule.ensures()), rule.att()); }
private Rule expand(Rule rule) { return Rule(expand(rule.body()), expand(rule.requires()), expand(rule.ensures()), rule.att()); }
public Rule applyNormalization(Rule denormal, K... normals) { return Rule( applyNormalization(denormal.body(), normals), applyNormalization(denormal.requires(), normals), applyNormalization(denormal.ensures(), normals), denormal.att()); }
private Rule resolve(Rule rule) { return Rule( transformBody(rule.body(), rule.att()), transform(rule.requires(), rule.att()), rule.ensures(), rule.att()); }
public Rule normalize(Rule rule) { resetVars(rule.body(), rule.requires(), rule.ensures()); return Rule( transform(rule.body()), transform(rule.requires()), transform(rule.ensures()), rule.att()); }
private Rule sortCells(Rule rule) { resetVars(); analyzeVars(rule.body()); analyzeVars(rule.requires()); analyzeVars(rule.ensures()); rule = Rule( processVars(rule.body()), processVars(rule.requires()), processVars(rule.ensures()), rule.att()); rule = Rule( resolveIncompleteCellFragment(rule.body()), resolveIncompleteCellFragment(rule.requires()), resolveIncompleteCellFragment(rule.ensures()), rule.att()); return rule; }
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()); }
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()); }
private Rule resolveInitRule(Production streamProduction, Rule rule) { Sort streamSort = streamProduction.sort(); // InCell, OutCell String initLabel = GenerateSentencesFromConfigDecl.getInitLabel(streamSort); // initInCell, initOutCell KLabel cellLabel = streamProduction.klabel().get(); // <in>, <out> // rule initInCell(Init) => <in> ... </in> if (isInitRule(initLabel, cellLabel.name(), rule)) { KRewrite body = (KRewrite) rule.body(); KApply right = (KApply) body.right(); KList klist = getContentsOfInitRule(streamProduction); right = KApply(right.klabel(), klist, right.att()); body = KRewrite(body.left(), right, body.att()); return Rule(body, rule.requires(), rule.ensures(), rule.att()); } return rule; }
finishAnalysis(); if (kore) { Rule withFresh = Rule( addFreshCell(transform(rule.body())), transform(rule.requires()), List<K> rightItems = new ArrayList<>(right.items()); rightItems.set(1, newCells); return Rule( KRewrite(left, KApply(right.klabel(), immutable(rightItems))), withFresh.requires(), return Rule( rule.body(), addSideCondition(rule.requires()),
private Rule convert(Rule rule) { reset(); gatherVars(rule.body()); gatherVars(rule.requires()); gatherVars(rule.ensures()); K body = convert(rule.body()); K requires = convertLookups(rule.requires()); return Rule( body, addSideCondition(requires), rule.ensures(), rule.att()); }
return Constructors.Rule(markerAdder.apply(r.body()), markerAdder.apply(r.requires()), markerAdder.apply(r.ensures()), r.att()); } else { return s;
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); }