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