From 63179a7b10069d8f69f5bceef27008c9c7fb0aa8 Mon Sep 17 00:00:00 2001 From: Thomas Schilling Date: Mon, 10 Nov 2008 14:35:10 +0000 Subject: [PATCH] Add 'packageDbModules' function to GHC API. This function returns a list of all modules available through the package DB. MERGE TO 6.10 --- compiler/main/GHC.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- 1.7.10.4