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(); }
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; }
String cellName = label.s(); Sort sort = Sort(getSortOfCell(cellName)); Option<Set<Production>> initializerProduction = m.productionsFor().get(KLabel(getInitLabel(sort))); if (initializerProduction.isDefined()) { Set<Production> realProds = stream(initializerProduction.get()).filter(p -> !p.att().contains("recordPrd", Production.class)).collect(Collections.toSet()); if (realProds.head().items().size() == 1) { return Tuple4.apply(Set(), Lists.newArrayList(sort), KApply(KLabel(getInitLabel(sort))), true); } else if (realProds.head().items().size() == 4) { return Tuple4.apply(Set(), Lists.newArrayList(sort), KApply(KLabel(getInitLabel(sort)), INIT), true);
String initLabel = getInitLabel(sort); Sentence initializer; Rule initializerRule;