2 import "StringBuilder" as StringBuilder
6 importJava "org.simantics.scl.compiler.errors.Failable" where
10 resultOfFailable :: Failable a -> Maybe a
13 importJava "org.simantics.scl.compiler.module.ImportDeclaration" where
14 data ImportDeclaration
17 moduleNameOfImportDeclaration :: ImportDeclaration -> String
19 localNameOfImportDeclaration :: ImportDeclaration -> Maybe String
20 @JavaName getSpecString
21 importSpecOfImportDeclaration :: ImportDeclaration -> String
24 importJava "org.simantics.scl.compiler.module.Module" where
26 @JavaName getDependencies
27 dependenciesOf :: Module -> [ImportDeclaration]
30 importJava "org.simantics.scl.compiler.elaboration.modules.SCLValue" where
33 nameOfValue :: Value -> Name
35 typeOfValue :: Value -> Type
38 importJava "org.simantics.scl.compiler.common.names.Name" where
41 nameOfName :: Name -> String
43 moduleOfName :: Name -> String
46 importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where
50 findModule :: ModuleRepository -> String -> <Proc> Failable Module
53 findValueRef :: ModuleRepository -> String -> <Proc> Value
56 findValue :: ModuleRepository -> String -> <Proc> a
58 @JavaName getSourceRepository
59 sourceRepositoryOf :: ModuleRepository -> ModuleSourceRepository
62 importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where
63 data ModuleSourceRepository
66 importJava "org.simantics.scl.compiler.module.repository.ModuleRepositories" where
67 allValues :: ModuleRepository -> <Proc> [Value]
68 allValuesMatching :: ModuleRepository -> String -> <Proc> [Value]
71 importJava "org.simantics.scl.compiler.source.repository.SourceRepositories" where
72 @JavaName getModuleNames
73 moduleNames :: ModuleSourceRepository -> <Proc> [String]
76 importJava "org.simantics.scl.osgi.SCLOsgi" where
77 @JavaName MODULE_REPOSITORY
78 ModuleRepository :: ModuleRepository
81 printTable :: [[String]] -> <Proc> ()
83 printTable rows = iter printRow rows
85 columnCount = maximum (map length rows)
86 columnWidth i = maximum (map ithColumnWidth rows)
88 ithColumnWidth cols | length cols <= i = 0
89 | otherwise = length (cols!i)
90 columnWidths = mapN columnWidth columnCount
91 printColumn i sb col = foldlN (\sb _ -> sb << " ") (sb << col) (columnWidths!i + 1 - length col)
92 printRow row = print $ StringBuilder.toString $ foldlI printColumn StringBuilder.new row
94 searchValue :: String -> <Proc> ()
95 searchValue pattern = printTable $ sort $ map tableRow $ allValuesMatching ModuleRepository pattern
98 moduleOfName $ nameOfValue value,
99 nameOfName $ nameOfValue value,
100 ":: " + (show $ removeForAll $ typeOfValue value)]
102 moduleDependencyGraph :: <Proc> [(String, [(String, Maybe String, String)])]
103 moduleDependencyGraph = mapMaybe
104 (\moduleName -> catch
105 (match resultOfFailable $ findModule ModuleRepository moduleName with
106 Just module -> Just (moduleName, findDependencies module)
109 $ \(_ :: Exception) -> Nothing
111 (moduleNames $ sourceRepositoryOf ModuleRepository)
113 mapImportDeclaration decl = (moduleNameOfImportDeclaration decl,
114 localNameOfImportDeclaration decl,
115 importSpecOfImportDeclaration decl)
116 findDependencies module = map mapImportDeclaration (dependenciesOf module)