private static Module getModule(String defModule, Map<String, Module> modules, Definition oldDef) { if (modules.containsKey(defModule)) return modules.get(defModule); Option<Module> mod = oldDef.getModule(defModule); if (mod.isDefined()) { return mod.get(); } throw KEMException.criticalError("Module " + defModule + " does not exist."); }
private Module getStreamModule(String streamName) { // TODO(Daejun): fix hard-coded stream module naming convention String moduleName = streamName.toUpperCase() + "-STREAM"; Option<Module> module = definition.getModule(moduleName); if (module.isDefined()) { return module.get(); } else { throw KEMException.compilerError("no such module: " + moduleName); } }
private Module getStreamSyntaxModule(String streamName) { // TODO(Daejun): fix hard-coded stream module naming convention String moduleName = streamName.toUpperCase() + "-STREAM$SYNTAX"; Option<Module> module = definition.getModule(moduleName); if (module.isDefined()) { return module.get(); } else { throw KEMException.compilerError("no such module: " + moduleName); } }
/** * Creates the seed module that can be used to parse rules. * Imports module markers RULE-CELLS and K found in /include/kast.k. * @param mod The user defined module from which to start. * @return a new module which imports the original user module and a set of marker modules. */ public Module getRuleGrammar(Module mod) { // import RULE-CELLS in order to parse cells specific to rules Module newM = new Module( mod.name() + "-" + RULE_CELLS , Set(mod, baseK.getModule(K).get(), baseK.getModule(RULE_CELLS).get(), baseK.getModule(DEFAULT_LAYOUT).get()) , Set() , Att() ); return newM; }
/** * Creates the seed module that can be used to parse configurations. * Imports module markers CONFIG-CELLS and K found in /include/kast.k. * @param mod The user defined module from which to start. * @return a new module which imports the original user module and a set of marker modules. */ public Module getConfigGrammar(Module mod) { // import CONFIG-CELLS in order to parse cells specific to configurations Module newM = new Module( mod.name() + "-" + CONFIG_CELLS , Set(mod, baseK.getModule(K).get(), baseK.getModule(CONFIG_CELLS).get(), baseK.getModule(DEFAULT_LAYOUT).get()) , Set() , Att() ); return newM; }
public Definition parseDefinitionAndResolveBubbles(File definitionFile, String mainModuleName, String mainProgramsModule, java.util.Set<String> excludedModuleTags) { Definition parsedDefinition = parseDefinition(definitionFile, mainModuleName, mainProgramsModule); Stream<Module> modules = Stream.of(parsedDefinition.mainModule()); modules = Stream.concat(modules, stream(parsedDefinition.mainModule().importedModules())); Option<Module> syntaxModule = parsedDefinition.getModule(mainProgramsModule); if (syntaxModule.isDefined()) { modules = Stream.concat(modules, Stream.of(syntaxModule.get())); modules = Stream.concat(modules, stream(syntaxModule.get().importedModules())); } modules = Stream.concat(modules, Stream.of(parsedDefinition.getModule("K-REFLECTION").get())); modules = Stream.concat(modules, Stream.of(parsedDefinition.getModule("STDIN-STREAM").get())); modules = Stream.concat(modules, Stream.of(parsedDefinition.getModule("STDOUT-STREAM").get())); modules = Stream.concat(modules, stream(parsedDefinition.entryModules()).filter(m -> !stream(m.sentences()).anyMatch(s -> s instanceof Bubble))); Definition trimmed = Definition(parsedDefinition.mainModule(), modules.collect(Collections.toSet()), parsedDefinition.att()); trimmed = Kompile.excludeModulesByTag(excludedModuleTags).apply(trimmed); Definition afterResolvingConfigBubbles = resolveConfigBubbles(trimmed, parsedDefinition.getModule("DEFAULT-CONFIGURATION").get()); RuleGrammarGenerator gen = new RuleGrammarGenerator(afterResolvingConfigBubbles); Definition afterResolvingAllOtherBubbles = resolveNonConfigBubbles(afterResolvingConfigBubbles, gen); saveCachesAndReportParsingErrors(); return afterResolvingAllOtherBubbles; }
public static Definition addSemanticsModule(Definition d) { java.util.Set<Module> allModules = mutable(d.modules()); Module languageParsingModule = Constructors.Module("LANGUAGE-PARSING", Set(d.mainModule(), d.getModule(d.att().get(Att.syntaxModule())).get(), d.getModule("K-TERM").get(), d.getModule(RuleGrammarGenerator.ID_PROGRAM_PARSING).get()), Set(), Att()); allModules.add(languageParsingModule); return Constructors.Definition(d.mainModule(), immutable(allModules), d.att()); }
Set<Module> imports = stream(oldMod.imports()).map(_import -> { if (_import.name().equals(ID)) { return baseK.getModule(ID_PROGRAM_PARSING).get(); } else if (_import.name().equals(ID_SYNTAX)) { return baseK.getModule(ID_PROGRAM_PARSING_SYNTAX).get(); } else { return _import; modules.add(baseK.getModule(PROGRAM_LISTS).get()); modules.add(baseK.getModule(DEFAULT_LAYOUT).get());
/** * @return the module used for generating the program (i.e. ground) parser for the module named moduleName * It automatically generates this module unless the user has already defined a module postfixed with * {@link RuleGrammarGenerator#POSTFIX}. In latter case, it uses the user-defined module. */ public Option<Module> programParsingModuleFor(String moduleName, KExceptionManager kem) { RuleGrammarGenerator gen = new RuleGrammarGenerator(parsedDefinition); Option<Module> userProgramParsingModule = parsedDefinition.getModule(moduleName + RuleGrammarGenerator.POSTFIX); if (userProgramParsingModule.isDefined()) { kem.registerInternalHiddenWarning("Module " + userProgramParsingModule.get().name() + " is user-defined."); return userProgramParsingModule; } else { Option<Module> moduleOption = parsedDefinition.getModule(moduleName); Option<Module> programParsingModuleOption = moduleOption.isDefined() ? Option.apply(gen.getProgramsGrammar(moduleOption.get())) : Option.empty(); if (programParsingModuleOption.isDefined()) { kem.registerInternalHiddenWarning("Module " + programParsingModuleOption.get().name() + " has been automatically generated."); } return programParsingModuleOption; } }
public int run(KProveOptions options, CompiledDefinition compiledDefinition, Backend backend, Function<Module, Rewriter> rewriterGenerator) { Tuple2<Definition, Module> compiled = getProofDefinition(options.specFile(files), options.defModule, options.specModule, compiledDefinition, backend, files, kem, sw); Rewriter rewriter = rewriterGenerator.apply(compiled._1().mainModule()); Module specModule = compiled._2(); K results = rewriter.prove(specModule); int exit; if (results instanceof KApply) { KApply kapp = (KApply) results; exit = kapp.klabel().name().equals("#True") ? 0 : 1; } else { exit = 1; } kprint.prettyPrint(compiled._1(), compiled._1().getModule("LANGUAGE-PARSING").get(), s -> kprint.outputFile(s), results); return exit; }
public CompiledDefinition(KompileOptions kompileOptions, Definition parsedDefinition, Definition kompiledDefinition, FileUtil files, KExceptionManager kem, KLabel topCellInitializer) { this.kompileOptions = kompileOptions; this.parsedDefinition = parsedDefinition; this.kompiledDefinition = kompiledDefinition; initializeConfigurationVariableDefaultSorts(); this.programStartSymbol = configurationVariableDefaultSorts.getOrDefault("$PGM", Sorts.K()); this.topCellInitializer = topCellInitializer; this.languageParsingModule = kompiledDefinition.getModule("LANGUAGE-PARSING").get(); Rule exitCodeRule; if (kompileOptions.isKore()) { exitCodeRule = null; } else { exitCodeRule = getExitCodeRule(parsedDefinition); } if (exitCodeRule == null) { this.exitCodePattern = null; } else { this.exitCodePattern = new Kompile(kompileOptions, files, kem).compileRule(kompiledDefinition, exitCodeRule); } }
if (options.module == null) { mod = def.programParsingModuleFor(def.mainSyntaxModuleName(), kem).get(); compiledMod = def.kompiledDefinition.getModule(def.mainSyntaxModuleName()).get(); } else { Option<org.kframework.definition.Module> mod2 = def.programParsingModuleFor(options.module, kem); compiledMod = def.kompiledDefinition.getModule(options.module).get();
if (def.getModule("MAP$SYNTAX").isDefined()) { mapModule = def.getModule("MAP$SYNTAX").get(); } else { throw KEMException.compilerError("Module Map must be visible at the configuration declaration, in module " + module.name()); } else { Module mapModule; if (def.getModule("MAP").isDefined()) { mapModule = def.getModule("MAP").get(); } else { throw KEMException.compilerError("Module Map must be visible at the configuration declaration, in module " + module.name());
/** * Takes a definition in e-kore textual format and a main module name, and returns the KORE * representation of that module. Current implementation uses JavaCC and goes through KIL. * * @param definitionText textual representation of the modules. * @param mainModule main module name. * @return KORE representation of the main module. */ public static Module parseMainModuleOuterSyntax(String definitionText, Source source, String mainModule) { Definition def = new Definition(); def.setItems(Outer.parse(source, definitionText, null)); def.setMainModule(mainModule); def.setMainSyntaxModule(mainModule); Context context = new Context(); new CollectProductionsVisitor(false, context).visit(def); KILtoKORE kilToKore = new KILtoKORE(context); return kilToKore.apply(def).getModule(mainModule).get(); }
return m; return new GenerateSortPredicateSyntax().gen(Module(m.name(), kore ? m.imports() : add(def.getModule("K-REFLECTION").get(), m.imports()), sentences, m.att()));
cell("opt", Collections.singletonMap("multiplicity", "?"), KApply(KLabel(".Opt"), KList(), Att.empty().add(Production.class, prod)))))); Module m1 = Module("CONFIG", Set(def.getModule("KSEQ").get()), Set(prod), Att()); RuleGrammarGenerator parserGen = new RuleGrammarGenerator(def); Module m = RuleGrammarGenerator.getCombinedGrammar(parserGen.getConfigGrammar(m1), true).getExtensionModule();