refactoring Browse.

This commit is contained in:
Kazu Yamamoto 2013-03-01 02:24:14 +09:00
parent 8fe6c99131
commit 9796d639ab

View File

@ -38,30 +38,28 @@ browse opt mdlName = withGHC $ do
where
lookupModuleInfo = findModule (mkModuleName mdlName) Nothing >>= getModuleInfo
processExports :: ModuleInfo -> [String]
processExports = map getOccString . modInfoExports
processExports :: ModuleInfo -> [String]
processExports = map getOccString . modInfoExports
processModule :: ModuleInfo -> Ghc [String]
processModule minfo = do
processModule :: ModuleInfo -> Ghc [String]
processModule minfo = do
dynFlags <- getDynFlags
let processName :: Name -> Ghc String
processName nm = do
mapM (processName dynFlags) names
where
names = modInfoExports minfo
processName :: DynFlags -> Name -> Ghc String
processName dynFlags nm = do
tyInfo <- modInfoLookupName minfo nm
-- If nothing found, load dependent module and lookup global
tyResult <- maybe inOtherModule (return . Just) tyInfo
return $ fromMaybe name (tyResult >>= showThing dynFlags)
where
inOtherModule :: Ghc (Maybe TyThing)
inOtherModule = do
tyResult <- maybe (inOtherModule nm) (return . Just) tyInfo
return $ fromMaybe (getOccString nm) (tyResult >>= showThing dynFlags)
inOtherModule :: Name -> Ghc (Maybe TyThing)
inOtherModule nm = do
_ <- getModuleInfo (nameModule nm) -- FIXME
lookupGlobalName nm
name = getOccString nm
mapM processName exports
where
exports = modInfoExports minfo
showThing :: DynFlags -> TyThing -> Maybe String
showThing dflags t = case t of
showThing :: DynFlags -> TyThing -> Maybe String
showThing dflags t = case t of
AnId i -> Just $ getOccString i ++ " :: " ++ showOutputable dflags (removeForAlls $ varType i)
ATyCon typ -> do
tyType' <- tyType typ
@ -78,8 +76,8 @@ browse opt mdlName = withGHC $ do
| isSynTyCon typ = Just "type"
| otherwise = Nothing
removeForAlls :: Type -> Type
removeForAlls ty = case splitFunTy_maybe ty' of
removeForAlls :: Type -> Type
removeForAlls ty = case splitFunTy_maybe ty' of
Nothing -> ty'
Just (pre, ftype) -> if isPredTy pre then mkFunTy pre (dropForAlls ftype) else ty'
where