@Override public DefaultMutableTreeNode apply(KToken k) { return new DefaultMutableTreeNode("#token{"+k.s()+"}"); }
@Override public void apply(KToken k) { if (k.sort().equals(Sorts.KConfigVar())) { hasConfigVar = true; } }
private Integer getRuleIndex(KApply kk) { return definition.reverseRuleTable.get(Integer.valueOf(((KToken) kk.klist().items().get(0)).s())); }
@Override public void apply(KToken k) { sb.append("\\dv{"); convert(k.sort(), false); sb.append("}("); if (module.sortAttributesFor().get(k.sort()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("").equals("STRING.String")) { sb.append(k.s()); } else { sb.append(StringUtil.enquoteKString(k.s())); } sb.append(")"); }
private void checkConfigVars(Set<KToken> inputConfigVars, CompiledDefinition compiledDef) { Set<KToken> defConfigVars = mutable(new ConfigurationInfoFromModule(compiledDef.kompiledDefinition.mainModule()).configVars()); for (KToken defConfigVar : defConfigVars) { if (!inputConfigVars.contains(defConfigVar)) { throw KEMException.compilerError("Configuration variable missing: " + defConfigVar.s()); } } for (KToken inputConfigVar : inputConfigVars) { if (!defConfigVars.contains(inputConfigVar)) { if (!inputConfigVar.s().equals("$STDIN") && !inputConfigVar.s().equals("$IO")) { kem.registerCompilerWarning("User specified configuration variable " + inputConfigVar.s() + " which does not exist."); } } } }
private Set<Sort> sort(K k, Rule r) { if (k instanceof KVariable) { return Collections.singleton(k.att().get(Sort.class)); } else if (k instanceof KToken) { return Collections.singleton(((KToken)k).sort()); } else if (k instanceof KApply) { KApply kapp = (KApply)k; if (kapp.klabel() instanceof KVariable) { throw KEMException.compilerError("Cannot compute macros with klabel variables.", r); } Set<Production> prods = new HashSet<>(mutable(mod.productionsFor().apply(kapp.klabel()))); prods.removeIf(p -> p.arity() != kapp.items().size()); for (int i = 0; i < kapp.items().size(); i++) { final int idx = i; Set<Sort> sorts = sort(kapp.items().get(idx), r); prods.removeIf(p -> sorts.stream().noneMatch(s -> mod.subsorts().lessThanEq(s, p.nonterminal(idx).sort()))); } Set<Sort> candidates = prods.stream().map(Production::sort).collect(Collectors.toSet()); return candidates; } else { throw KEMException.compilerError("Cannot compute macros with sort check on terms that are not KApply, KToken, or KVariable.", r); } }
@Override public void apply(KToken k) { if (inBooleanExp && k.sort().equals(Sorts.Bool())) { sb.append(k.s()); return; } if (mainModule.sortAttributesFor().contains(k.sort())) { String hook = mainModule.sortAttributesFor().apply(k.sort()).<String>getOptional("hook").orElse(""); if (sortHooks.containsKey(hook)) { sb.append(sortHooks.get(hook).apply(k.s())); return; } } sb.append("KToken ("); apply(k.sort()); sb.append(", "); sb.append(enquoteString(k.s())); sb.append(")"); }
Sort sort = Outer.parseSort(((KToken) ((KSequence) k.klist().items().get(0)).items().get(0)).s()); apply(sort); sb.append(", ");
private Sort sort(K k) { if (k instanceof KSequence) return Sorts.K(); if (k instanceof KAs) return sort(((KAs) k).pattern()); if (k instanceof InjectedKLabel) return Sorts.KItem(); if (k instanceof KToken) return ((KToken) k).sort(); if (k instanceof KApply) return k.att().get(Production.class).sort(); if (k instanceof KVariable) return Sorts.K(); throw KEMException.compilerError("Could not compute sort of term", k); }
/** * Function to return the exit code specified by the user given a substitution * * @param kem ExcpetionManager object * @param res The substitution from the match of the user specified pattern on the Final Configuration. * @return An int representing the error code. */ public static int getExitCode(KExceptionManager kem, K res) { KApply app = (KApply) res; List<K> solution = Assoc.flatten(KLabels.ML_AND, app.klist().items(), KLabels.ML_TRUE); Set<Integer> vars = new HashSet<>(); for (K conjunct : solution) { if (conjunct instanceof KApply) { KApply kapp = (KApply)conjunct; if (kapp.klabel().equals(KLabel("_==K_"))) { if (kapp.items().get(0) instanceof KVariable && kapp.items().get(1) instanceof KToken) { KToken rhs = (KToken) kapp.items().get(1); if (Sorts.Int().equals(rhs.sort())) { vars.add(Integer.valueOf(rhs.s())); } } } } } if (vars.size() != 1) { kem.registerCriticalWarning("Found " + vars.size() + " integer variables in exit code pattern. Returning 111."); return 111; } return vars.iterator().next(); }
@Override public K apply(KToken k) { if (k.sort().equals(Sorts.KConfigVar())) { if (sort == null || sort.equals(Sorts.K())) { return KApply(KLabel("Map:lookup"), INIT, k); } else { h.sentences = (Set<Sentence>) h.sentences.$bar(genProjection(sort, m)); return KApply(getProjectLbl(sort, m), KApply(KLabel("Map:lookup"), INIT, k)); } } return k; } }.apply(leafContents), h.sentences);
private static Tuple2<String, String> getCellProperty(K k) { if (k instanceof KApply) { KApply kapp = (KApply) k; if (kapp.klabel().name().equals("#cellProperty")) { if (kapp.klist().size() == 2) { if (kapp.klist().items().get(0) instanceof KToken) { KToken keyToken = (KToken) kapp.klist().items().get(0); if (keyToken.sort().equals(Sort("#CellName"))) { String key = keyToken.s(); if (kapp.klist().items().get(0) instanceof KToken) { KToken valueToken = (KToken) kapp.klist().items().get(1); if (valueToken.sort().equals(Sorts.KString())) { String value = StringUtil.unquoteKString(valueToken.s()); return Tuple2.apply(key, value); } } } } } } } throw KEMException.compilerError("Malformed cell property", k); }
return lubSort(leftSort, rightSort, expectedSort, term); } else if (term instanceof KToken) { return ((KToken) term).sort(); } else if (term instanceof KVariable) { return term.att().getOptional(Sort.class).orElse(Sorts.K());
public Term convert(org.kframework.kore.K k) { if (k instanceof Term) return (Term) k; else if (k instanceof org.kframework.kore.KToken) return KToken(((org.kframework.kore.KToken) k).s(), ((org.kframework.kore.KToken) k).sort(), k.att()); else if (k instanceof org.kframework.kore.KApply) { return KApply1(((KApply) k).klabel(), ((KApply) k).klist(), k.att()); } else if (k instanceof org.kframework.kore.KSequence) return KSequence(((org.kframework.kore.KSequence) k).items(), k.att()); else if (k instanceof org.kframework.kore.KVariable) return KVariable(((org.kframework.kore.KVariable) k).name(), k.att()); else if (k instanceof org.kframework.kore.InjectedKLabel) return InjectedKLabel(((org.kframework.kore.InjectedKLabel) k).klabel(), k.att()); else if (k instanceof org.kframework.kore.KRewrite) { return KItem.of(KLabelConstant.of(KLabels.KREWRITE, definition), KList.concatenate(convert(((KRewrite) k).left()), convert(((KRewrite) k).right())), global); } else throw new AssertionError("BUM!"); }