X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fghci%2FDebugger.hs;h=cc0d5baa482086ff349233846601ae45853348a8;hp=36c784b2389d17b119ba7d0151d7a610ed9bb97a;hb=18f671cc4b459195c24f0ea3b16fc600d5e7a4bf;hpb=066f10289f9711a0f6d0669aea97e134f1be2826 diff --git a/compiler/ghci/Debugger.hs b/compiler/ghci/Debugger.hs index 36c784b..cc0d5ba 100644 --- a/compiler/ghci/Debugger.hs +++ b/compiler/ghci/Debugger.hs @@ -23,7 +23,7 @@ import Var hiding ( varName ) import VarSet import Name import UniqSupply -import TcType +import Type import GHC import InteractiveEval import Outputable @@ -138,10 +138,11 @@ bindSuspensions cms@(Session ref) t = do -- A custom Term printer to enable the use of Show instances showTerm :: Session -> Term -> IO SDoc -showTerm cms@(Session ref) = cPprTerm cPpr +showTerm cms@(Session ref) term = do + cPprExtended <- cPprTermExtended cms + cPprTerm (liftM2 (++) cPprShowable cPprExtended) term where - cPpr = \p-> cPprShowable : cPprTermBase p - cPprShowable prec ty _ val tt = + cPprShowable _y = [\prec ty _ val tt -> if not (all isFullyEvaluatedTerm tt) then return Nothing else do @@ -164,7 +165,7 @@ showTerm cms@(Session ref) = cPprTerm cPpr _ -> return Nothing `finally` do writeIORef ref hsc_env - GHC.setSessionDynFlags cms dflags + GHC.setSessionDynFlags cms dflags] needsParens ('"':_) = False -- some simple heuristics to see whether parens -- are redundant in an arbitrary Show output needsParens ('(':_) = False @@ -179,6 +180,27 @@ showTerm cms@(Session ref) = cPprTerm cPpr new_ic = ictxt { ic_tmp_ids = id : tmp_ids } return (hsc_env {hsc_IC = new_ic }, name) +{- | A custom Term printer to handle some types that + we may not want to show, such as Data.Typeable.TypeRep -} +cPprTermExtended :: Monad m => Session -> IO (CustomTermPrinter m) +cPprTermExtended session = liftM22 (++) (return cPprTermBase) extended + where + extended = do + [typerep_name] <- parseName session "Data.Typeable.TypeRep" + Just (ATyCon typerep) <- lookupName session typerep_name + + return (\_y -> + [ ifType (isTyCon typerep) (\_val _prec -> return (text "")) ]) + + ifType pred f prec ty _ val _tt + | pred ty = Just `liftM` f prec val + | otherwise = return Nothing + isTyCon a_tc ty = fromMaybe False $ do + (tc,_) <- splitTyConApp_maybe ty + return (a_tc == tc) + liftM22 f x y = do x' <- x; y' <- y + return$ do x'' <- x';y'' <- y';return (f x'' y'') + -- Create new uniques and give them sequentially numbered names newGrimName :: String -> IO Name newGrimName userName = do