X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.osgi%2Fscl%2FReflection.scl;h=1e22b749cc095e5b46ff21a2d953a9a0832e9568;hb=3bcd1023180e2cdc55bc001d0f60075dd7184cfa;hp=f75f2925bce61263e2ff4c215a8800b301f549a3;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.osgi/scl/Reflection.scl b/bundles/org.simantics.scl.osgi/scl/Reflection.scl index f75f2925b..1e22b749c 100644 --- a/bundles/org.simantics.scl.osgi/scl/Reflection.scl +++ b/bundles/org.simantics.scl.osgi/scl/Reflection.scl @@ -1,116 +1,116 @@ -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) +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) \ No newline at end of file