private void checkDefinition(Definition parsedDef) { CheckRHSVariables checkRHSVariables = new CheckRHSVariables(errors); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(checkRHSVariables::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckConfigurationCells(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckSortTopUniqueness(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckStreams(errors, m)::check)); stream(parsedDef.modules()).forEach(m -> stream(m.localSentences()).forEach(new CheckRewrite(errors, m)::check)); stream(parsedDef.modules()).forEach(new CheckImports(parsedDef.mainModule(), kem)::check); Set<String> moduleNames = new HashSet<>(); stream(parsedDef.modules()).forEach(m -> { if (moduleNames.contains(m.name())) { errors.add(KEMException.compilerError("Found multiple modules with name: " + m.name())); } moduleNames.add(m.name()); }); CheckKLabels checkKLabels = new CheckKLabels(errors); // only check imported modules because otherwise we might have false positives Consumer<Module> checkModuleKLabels = m -> stream(m.localSentences()).forEach(s -> checkKLabels.check(s, m)); stream(parsedDef.mainModule().importedModules()).forEach(checkModuleKLabels); checkModuleKLabels.accept(parsedDef.mainModule()); if (!errors.isEmpty()) { kem.addAllKException(errors.stream().map(e -> e.exception).collect(Collectors.toList())); throw KEMException.compilerError("Had " + errors.size() + " structural errors."); } }
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()); }
public java.util.Set<Module> parseModules(CompiledDefinition definition, String mainModule, File definitionFile) { Definition def = parser.loadDefinition( mainModule, mutable(definition.getParsedDefinition().modules()), "require " + StringUtil.enquoteCString(definitionFile.getPath()), Source.apply(definitionFile.getAbsolutePath()),