X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FGHC.hs;h=ce3fe7624539c82fc535f9cf169b3a90adb8d995;hb=63179a7b10069d8f69f5bceef27008c9c7fb0aa8;hp=2aa7b4769a21948f56177698fbd94db7012f8e55;hpb=f9fa73dd0f96280ddc73800ca8d247aa788561b5;p=ghc-hetmet.git diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs index 2aa7b47..ce3fe76 100644 --- a/compiler/main/GHC.hs +++ b/compiler/main/GHC.hs @@ -78,6 +78,9 @@ module GHC ( findGlobalAnns, mkPrintUnqualifiedForModule, + -- * Querying the environment + packageDbModules, + -- * Printing PrintUnqualified, alwaysQualify, @@ -283,6 +286,7 @@ import SysTools ( initSysTools, cleanTempFiles, cleanTempFilesExcept, import Annotations import Module import LazyUniqFM +import qualified UniqFM as UFM import UniqSet import Unique import FiniteMap @@ -2428,6 +2432,23 @@ getGRE = withSession $ \hsc_env-> return $ ic_rn_gbl_env (hsc_IC hsc_env) #endif -- ----------------------------------------------------------------------------- + +-- | Return all /external/ modules available in the package database. +-- Modules from the current session (i.e., from the 'HomePackageTable') are +-- not included. +packageDbModules :: GhcMonad m => + Bool -- ^ Only consider exposed packages. + -> m [Module] +packageDbModules only_exposed = do + dflags <- getSessionDynFlags + let pkgs = UFM.eltsUFM (pkgIdMap (pkgState dflags)) + return $ + [ mkModule pid modname | p <- pkgs + , not only_exposed || exposed p + , pid <- [mkPackageId (package p)] + , modname <- exposedModules p ] + +-- ----------------------------------------------------------------------------- -- Misc exported utils dataConType :: DataCon -> Type