private KLabel apply(KLabel klabel) { if (klabel.name().equals(builtinCellLabel)) { return userCellLabel; } else { return klabel; } } }.apply(rule.body());
/** * Converts a KRewrite to an rule-labeled ML OR ({@link RuleAutomatonDisjunction}) on the left and * a {@link InnerRHSRewrite} on the right. * * @param klabel is the KRewrite * @param klist contains the LHS and RHS * @return */ private Term convertKRewrite(KLabel klabel, org.kframework.kore.KList klist) { K kk = klist.items().get(1); if (!(kk instanceof KApply)) throw new AssertionError("k should be a KApply"); KApply k = (KApply) kk; Set<KApply> orContents = getOrContents(k); Term[] theRHSs = new Term[this.definition.reverseRuleTable.size()]; orContents.forEach(c -> { if (!KLabels.ML_AND.equals(c.klabel())) throw new AssertionError("c should be an KApply AND but is " + c.klabel().name()); K term = c.klist().items().get(0); Integer ruleIndex = getRuleIndex((KApply) c.klist().items().get(1)); theRHSs[ruleIndex] = convert(term); }); return KItem.of(convert1(klabel), org.kframework.backend.java.kil.KList.concatenate(convert(klist.items().get(0)), new InnerRHSRewrite(theRHSs)), global); }
private void convertParams(Option<KLabel> maybeKLabel, boolean hasR) { sb.append("{"); String conn = ""; if (hasR) { sb.append("R"); if (maybeKLabel.isDefined()) { conn = ", "; } } if (maybeKLabel.isDefined()) { for (Sort param : iterable(maybeKLabel.get().params())) { sb.append(conn); convert(param, true); conn = ", "; } } sb.append("}"); }
@Override public int hashCode() { return klabel.hashCode(); } }
private String wellformedAndGetSortNameOfCast(KList klist) { try { if (klist.size() == 3) { KApply k1 = (KApply) klist.items().get(0); KApply k3 = (KApply) klist.items().get(2); if (KLabels.NO_DOTS.equals(k1.klabel()) && k1.klist().size() == 0 && KLabels.DOTS.equals(k3.klabel()) && k3.klist().size() == 0) { KRewrite k2 = (KRewrite) klist.items().get(1); KApply k2l = (KApply) k2.left(); KApply k2r = (KApply) k2.right(); if (k2l.klabel().name().equals("ListItem") && k2l.klist().size() == 1 && k2r.klabel().name().equals(".List") && k2r.klist().size() == 0) { KApply k2li = (KApply) k2l.klist().items().get(0); if (k2li.klabel().name().startsWith("#SemanticCastTo") && k2li.klist().size() == 1 && k2li.klist().items().get(0) instanceof KVariable) { return ResolveSemanticCasts.getSortNameOfCast(k2li); // k2li.klabel().name().substring("#SemanticCastTo".length()); } } } } } catch (ClassCastException ignored) { } return ""; } }.apply(rule.body());
private void convert(Sort sort, Production prod) { convert(sort, prod.klabel().isDefined() && prod.klabel().get().params().contains(sort)); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + klabel.hashCode(); return result; }
private KLabel apply(KLabel klabel) { if (klabel.name().equals(builtinCellLabel)) { return userCellLabel; } else { return klabel; } } }.apply(unblockRule.body());
private boolean isBuiltinModuloConstructor(KLabel label) { return label.equals(KLabels.DotMap) || label.equals(KLabels.Map) || label.equals(KLabels.MapItem) || label.equals(KLabels.DotList) || label.equals(KLabels.List) || label.equals(KLabels.ListItem) || label.equals(KLabels.DotSet) || label.equals(KLabels.Set) || label.equals(KLabels.SetItem); }
.filter(t -> t instanceof KApply && ((KApply) t).klabel().name().contains(Strategy.strategyCellName())) .findFirst(); if ((topOfStrategyCell instanceof KApply) && KLabels.KSEQ.equals(((KApply) topOfStrategyCell).klabel())) { topOfStrategyCell = ((KApply) topOfStrategyCell).klist().items().get(0); ((KApply) topOfStrategyCell).klabel().name().equals(Att.stuck()); Term entireConf = constructor.KApply1(((KApply) subject.term()).klabel(), constructor.KList(((KApply) subject.term()).klist().stream().map(k -> k instanceof KApply && ((KApply) k).klabel().name().contains(Strategy.strategyCellName()) ? s : k).collect(Collectors.toList())), emptyAtt); return Optional.of(new ConstrainedTerm(entireConf, subject.termContext()));
private void convert(KLabel klabel, boolean var) { if (klabel.name().equals(KLabels.INJ)) { sb.append(klabel.name()); } else { sb.append("Lbl"); convert(klabel.name()); } sb.append("{"); String conn = ""; for (Sort param : iterable(klabel.params())) { sb.append(conn); convert(param, var); conn = ", "; } sb.append("}"); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; KApply kApply = (KApply) o; return klabel.equals(kApply.klabel); }
public static Sort getSortOfCast(TermCons tc) { switch (tc.production().klabel().get().name()) { case "#ruleNoConditions": case "#ruleRequires": case "#ruleEnsures": case "#ruleRequiresEnsures": { ProductionReference child = (ProductionReference) tc.get(0); if (child.production().klabel().isDefined() && child.production().klabel().get().equals(KLabels.KREWRITE)) { child = (ProductionReference)((TermCons)child).get(0); } return child.production().sort(); } case "#SyntacticCast": case "#OuterCast": return tc.production().sort(); case "#InnerCast": return ((NonTerminal)tc.production().items().apply(1)).sort(); default: if (tc.production().klabel().get().name().startsWith("#SemanticCastTo")) { return tc.production().sort(); } throw new AssertionError("Unexpected cast type"); } }
private void convert(KLabel klabel, Production prod) { if (klabel.name().equals(KLabels.INJ)) { sb.append(klabel.name()); } else { sb.append("Lbl"); convert(klabel.name()); } sb.append("{"); String conn = ""; for (Sort param : iterable(klabel.params())) { sb.append(conn); convert(param, prod); conn = ", "; } sb.append("}"); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InjectedKLabel that = (InjectedKLabel) o; return klabel.equals(that.klabel); }