import "String" import "StringBuilder" as StringBuilder import "IterN" @private importJava "org.simantics.scl.compiler.errors.Failable" where data Failable a @JavaName getResult resultOfFailable :: Failable a -> Maybe a @private importJava "org.simantics.scl.compiler.module.ImportDeclaration" where data ImportDeclaration @JavaName moduleName moduleNameOfImportDeclaration :: ImportDeclaration -> String @JavaName localName localNameOfImportDeclaration :: ImportDeclaration -> Maybe String @JavaName getSpecString importSpecOfImportDeclaration :: ImportDeclaration -> String @private importJava "org.simantics.scl.compiler.module.Module" where data Module @JavaName getDependencies dependenciesOf :: Module -> [ImportDeclaration] @private importJava "org.simantics.scl.compiler.elaboration.modules.SCLValue" where data Value @JavaName getName nameOfValue :: Value -> Name @JavaName getType typeOfValue :: Value -> Type @private importJava "org.simantics.scl.compiler.common.names.Name" where data Name @JavaName name nameOfName :: Name -> String @JavaName module moduleOfName :: Name -> String @private importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where data ModuleRepository @JavaName getModule findModule :: ModuleRepository -> String -> Failable Module @JavaName getValueRef findValueRef :: ModuleRepository -> String -> Value @JavaName getValue findValue :: ModuleRepository -> String -> a @JavaName getSourceRepository sourceRepositoryOf :: ModuleRepository -> ModuleSourceRepository @private importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where data ModuleSourceRepository @private importJava "org.simantics.scl.compiler.module.repository.ModuleRepositories" where allValues :: ModuleRepository -> [Value] allValuesMatching :: ModuleRepository -> String -> [Value] @private importJava "org.simantics.scl.compiler.source.repository.SourceRepositories" where @JavaName getModuleNames moduleNames :: ModuleSourceRepository -> [String] @private importJava "org.simantics.scl.osgi.SCLOsgi" where @JavaName MODULE_REPOSITORY ModuleRepository :: ModuleRepository @private printTable :: [[String]] -> () printTable [] = () printTable rows = iter printRow rows where columnCount = maximum (map length rows) columnWidth i = maximum (map ithColumnWidth rows) where ithColumnWidth cols | length cols <= i = 0 | otherwise = length (cols!i) columnWidths = mapN columnWidth columnCount printColumn i sb col = foldlN (\sb _ -> sb << " ") (sb << col) (columnWidths!i + 1 - length col) printRow row = print $ StringBuilder.toString $ foldlI printColumn StringBuilder.new row searchValue :: String -> () searchValue pattern = printTable $ sort $ map tableRow $ allValuesMatching ModuleRepository pattern where tableRow value = [ moduleOfName $ nameOfValue value, nameOfName $ nameOfValue value, ":: " + (show $ removeForAll $ typeOfValue value)] moduleDependencyGraph :: [(String, [(String, Maybe String, String)])] moduleDependencyGraph = mapMaybe (\moduleName -> catch (match resultOfFailable $ findModule ModuleRepository moduleName with Just module -> Just (moduleName, findDependencies module) Nothing -> Nothing ) $ \(_ :: Exception) -> Nothing ) (moduleNames $ sourceRepositoryOf ModuleRepository) where mapImportDeclaration decl = (moduleNameOfImportDeclaration decl, localNameOfImportDeclaration decl, importSpecOfImportDeclaration decl) findDependencies module = map mapImportDeclaration (dependenciesOf module)