private K addFreshCell(K body) { if (freshVars.size() == 0) { return body; } KApply cellTerm = IncompleteCellUtils.make(KLabels.GENERATED_COUNTER_CELL, false, KRewrite(FRESH, KApply(KLabel("_+Int_"), FRESH, KToken(Integer.toString(freshVars.size()), Sorts.Int()))), false); return KApply(KLabels.CELLS, body, cellTerm); }
private K parseConfigVars(KRunOptions options, CompiledDefinition compiledDef) { HashMap<KToken, K> output = new HashMap<>(); for (Map.Entry<String, Pair<String, String>> entry : options.configurationCreation.configVars(compiledDef.getParsedDefinition().mainModule().name(), files).entrySet()) { String name = entry.getKey(); String value = entry.getValue().getLeft(); String parser = entry.getValue().getRight(); String configVarName = "$" + name; Sort sort = compiledDef.configurationVariableDefaultSorts.getOrDefault(configVarName, compiledDef.programStartSymbol); K configVar = externalParse(parser, value, sort, Source.apply("<command line: -c" + name + ">"), compiledDef); output.put(KToken(configVarName, Sorts.KConfigVar()), configVar); } if (compiledDef.kompiledDefinition.mainModule().definedSorts().contains(Sorts.String())) { if (options.io()) { output.put(KToken("$STDIN", Sorts.KConfigVar()), KToken("\"\"", Sorts.String())); output.put(KToken("$IO", Sorts.KConfigVar()), KToken("\"on\"", Sorts.String())); } else { String stdin = getStdinBuffer(tty.stdin); output.put(KToken("$STDIN", Sorts.KConfigVar()), KToken(StringUtil.enquoteKString(stdin), Sorts.String())); output.put(KToken("$IO", Sorts.KConfigVar()), KToken("\"off\"", Sorts.String())); } } if (options.global.debug) { // on the critical path, so don't perform this check because it's slow unless we're debugging. checkConfigVars(output.keySet(), compiledDef); } return plugConfigVars(compiledDef, output); }
private K addSideCondition(K requires) { Optional<KApply> sideCondition = freshVars.stream().map(k -> { Optional<Sort> s = k.att().getOptional(Sort.class); if (!s.isPresent()) { throw KEMException.compilerError("Fresh constant used without a declared sort.", k); } return KApply(KLabel("#match"), k, KApply(KLabel("#fresh"), KToken(StringUtil.enquoteKString(s.get().toString()), Sorts.String()))); }).reduce(BooleanUtils::and); if (!sideCondition.isPresent()) { return requires; } else if (requires.equals(BooleanUtils.TRUE) && sideCondition.isPresent()) { return sideCondition.get(); } else { // we order the lookup after the requires clause so that the fresh constant // matching side condition occurs last. This is necessary in order to // ensure that fresh constants in rule RHSs are consecutive return BooleanUtils.and(requires, sideCondition.get()); } }
stateLog.log(StateLog.LogEvent.Z3RESULT, KToken(result, Sorts.Z3Result())); if (!Z3_QUERY_RESULTS.contains(result)) { throw KEMException.criticalError("Z3 crashed on input query:\n" + query + "\nresult:\n" + result);
public synchronized boolean isUnsat(CharSequence query, int timeout, Z3Profiler timer) { stateLog.log(StateLog.LogEvent.Z3QUERY, KToken(SMT_PRELUDE + "\n" + query + "\n" + CHECK_SAT + "\n", Sorts.Z3Query())); if (options.z3JNI) { return checkQueryWithLibrary(query, timeout); } else { return checkQueryWithExternalProcess(query, timeout, timer); } }
public static K toKASTTerm(Module mod, KApply kapp) { String kastTerm = ToKast.apply(kapp); Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(kastTerm, finalSort); } }
@Override public K apply(KVariable k) { if (freshVars.contains(k)) { Optional<Sort> s = k.att().getOptional(Sort.class); if (!s.isPresent()) { throw KEMException.compilerError("Fresh constant used without a declared sort.", k); } Option<KLabel> lbl = m.freshFunctionFor().get(s.get()); if (!lbl.isDefined()) { throw KEMException.compilerError("No fresh generator defined for sort " + s, k); } return KApply(lbl.get(), KApply(KLabel("_+Int_"), FRESH, KToken(offsets.get(k).toString(), Sorts.Int()))); } return super.apply(k); } }.apply(term);
private static K omitTerm(Module mod, KApply kapp) { Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(kapp.klabel().name(), finalSort); }
private K tokenizeTerm(Module mod, KApply kapp) { Module unparsingModule = RuleGrammarGenerator.getCombinedGrammar(mod, false).getExtensionModule(); String tokenizedTerm = unparseTerm(kapp, unparsingModule, ColorSetting.OFF); Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(tokenizedTerm, finalSort); }
private KApply cell(String s, Map<String, String> att, K body) { K cellAtt = att.entrySet().stream() .map(e -> KApply(KLabel("#cellProperty"), KToken(e.getKey(), Sort("#CellName")), KToken(StringUtil.enquoteKString(e.getValue()), Sort("KString")))) .reduce(KApply(KLabel("#cellPropertyListTerminator")), (k1, k2) -> KApply(KLabel("#cellPropertyList"), k2, k1)); return KApply(KLabel("#configCell"), KToken(s, Sort("#CellName")), cellAtt, body, KToken(s, Sort("#CellName"))); } }
@Override public K apply(KApply k) { if (k.klabel().name().equals("#SemanticCastToString") && k.klist().size() == 1) { K i = k.klist().items().get(0); if (i instanceof KVariable) { KVariable x = (KVariable) i; switch (x.name()) { case "?Sort": return KToken("\"" + sort + "\"", Sorts.String()); case "?Delimiters": // TODO(Daejun): support `delimiter` attribute in stream cell return KToken("\" \\n\\t\\r\"", Sorts.String()); default: // fall through } } } k = (KApply) super.apply(k); return KApply(apply(k.klabel()), k.klist(), k.att()); }
@Override public K apply(KToken k) { return KToken(k.s(), Sort(k.sort().name(), k.sort().params()), k.att()); }
KToken(Integer.toString(elementsLeft.size()), Sorts.Int()), KToken(Integer.toString(elementsRight.size()), Sorts.Int())))); } else { KLabel unit = KLabel(m.attributesFor().apply(collectionLabel).get("unit")); KToken(Integer.toString(elementsLeft.size()), Sorts.Int()), KToken(Integer.toString(elementsRight.size()), Sorts.Int())))); state.add(KApply(KLabel("#match"), element, KApply(KLabel("List:get"), list, KToken(Integer.toString(i), Sorts.Int())))); state.add(KApply(KLabel("#match"), element, KApply(KLabel("List:get"), list, KToken(Integer.toString(i - elementsRight.size()), Sorts.Int()))));
if (frame != null) { state.add(KORE.KApply(KLabel("#match"), frame, KORE.KApply(KLabel("List:range"), list, KToken(Integer.toString(elementsLeft.size()), Sorts.Int()), KToken(Integer.toString(elementsRight.size()), Sorts.Int())))); } else { KLabel unit = KLabel(m.attributesFor().apply(collectionLabel).<String>get("unit")); KToken(Integer.toString(elementsLeft.size()), Sorts.Int()), KToken(Integer.toString(elementsRight.size()), Sorts.Int())))); KLabel("#match"), KORE.KApply(elementWrapper, elementsLeft.get(i)), KORE.KApply(KLabel("List:get"), list, KToken(Integer.toString(i), Sorts.Int())))); KLabel("#match"), KORE.KApply(elementWrapper, elementsRight.get(i)), KORE.KApply(KLabel("List:get"), list, KToken(Integer.toString(i - elementsRight.size()), Sorts.Int()))));
res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KApply(KLabel("#KToken"), KToken(s.toString(), Sorts.KString()), KVariable("_"))), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE));
public K gen(Rule r, K body) { if (!cover || !r.att().getOptional(Source.class).isPresent()) { return body; } K left = RewriteToTop.toLeft(body); K right = RewriteToTop.toRight(body); String file = r.att().get(Source.class).source(); if (file.startsWith(JarInfo.getKBase())) { return body; } int line = r.att().get(Location.class).startLine(); int col = r.att().get(Location.class).startColumn(); String loc = file + ":" + line + ":" + col; String id = r.att().get("UNIQUE_ID"); allRulesFile.print(id); allRulesFile.print(" "); allRulesFile.println(loc); if (r.att().contains("macro") || r.att().contains("alias")) { //handled by macro expander return body; } return KRewrite(left, KSequence(KApply(KLabel("#logToFile"), KToken(StringUtil.enquoteKString(files.resolveKompiled("coverage.txt").getAbsolutePath()), Sorts.String()), KToken(StringUtil.enquoteKString(id + '\n'), Sorts.String())), right)); }
return KVariable(((KVariable) term).name(), att); } else if (term instanceof KToken) { return KToken(((KToken) term).s(), ((KToken) term).sort(), att); } else if (term instanceof InjectedKLabel) { return InjectedKLabel(((InjectedKLabel) term).klabel(), att);
@Test public void test24() { String def = "" + "module TEST\n" + "syntax A\n" + "syntax A ::= f(A) [klabel(l)]\n" + "endmodule"; parseRule("l(_) => .K", def, 0, KApply(KLabel("#ruleNoConditions"),KApply(KLabel("#KRewrite"), KApply(KLabel("#KApply"), KToken("l",Sort("KLabel")), KToken("_",Sort("#KVariable"))), KApply(KLabel("#EmptyK")) ))); }
public Module resolve(Module m) { this.m = m; Set<Sentence> sentences = map(this::resolve, m.localSentences()); KToken counterCellLabel = KToken("generatedCounter", Sort("#CellName")); KApply freshCell = KApply(KLabel("#configCell"), counterCellLabel, KApply(KLabel("#cellPropertyListTerminator")), KToken("0", Sorts.Int()), counterCellLabel); if (m.equals(def.mainModule()) && kore) { if (!m.definedKLabels().contains(KLabels.GENERATED_TOP_CELL)) { KLabel topCellLabel = configInfo.getCellLabel(topCellSort); Production prod = m.productionsFor().apply(topCellLabel).head(); KToken cellName = KToken(prod.att().get("cellName"), Sort("#CellName")); KToken topCellToken = KToken(KLabels.GENERATED_TOP_CELL_NAME, Sort("#CellName")); K generatedTop = KApply(KLabel("#configCell"), topCellToken, KApply(KLabel("#cellPropertyListTerminator")), KApply(KLabels.CELLS, KApply(KLabel("#externalCell"), cellName), freshCell), topCellToken); Set<Sentence> newSentences = GenerateSentencesFromConfigDecl.gen(generatedTop, BooleanUtils.TRUE, Att.empty(), mod.getExtensionModule(), true);
sort = StringUtil.unquoteCString(token.image); jj_consume_token(RPAREN); {if (true) return KToken(value, Sort(sort));} break; case KVARIABLE: