+\subsection{Getting information about an identifer}
+%* *
+%************************************************************************
+
+\begin{code}
+#ifdef GHCI
+hscThing -- like hscStmt, but deals with a single identifier
+ :: DynFlags
+ -> HomeSymbolTable
+ -> HomeIfaceTable
+ -> PersistentCompilerState -- IN: persistent compiler state
+ -> InteractiveContext -- Context for compiling
+ -> String -- The identifier
+ -> IO ( PersistentCompilerState,
+ [TyThing] )
+
+hscThing dflags hst hit pcs0 ic str
+ = do maybe_rdr_name <- myParseIdentifier dflags str
+ case maybe_rdr_name of {
+ Nothing -> return (pcs0, []);
+ Just rdr_name -> do
+
+ -- if the identifier is a constructor (begins with an
+ -- upper-case letter), then we need to consider both
+ -- constructor and type class identifiers.
+ let rdr_names
+ | occNameSpace occ == dataName = [ rdr_name, tccls_name ]
+ | otherwise = [ rdr_name ]
+ where
+ occ = rdrNameOcc rdr_name
+ tccls_occ = setOccNameSpace occ tcClsName
+ tccls_name = setRdrNameOcc rdr_name tccls_occ
+
+ (pcs, unqual, maybe_rn_result) <-
+ renameRdrName dflags hit hst pcs0 ic rdr_names
+
+ case maybe_rn_result of {
+ Nothing -> return (pcs, []);
+ Just (names, decls) -> do {
+
+ maybe_pcs <- typecheckExtraDecls dflags pcs hst unqual
+ iNTERACTIVE decls;
+
+ case maybe_pcs of {
+ Nothing -> return (pcs, []);
+ Just pcs ->
+ let do_lookup n
+ | isLocalName n = lookupNameEnv (ic_type_env ic) n
+ | otherwise = lookupType hst (pcs_PTE pcs) n
+
+ maybe_ty_things = map do_lookup names
+ in
+ return (pcs, catMaybes maybe_ty_things) }
+ }}}
+
+myParseIdentifier dflags str
+ = do buf <- stringToStringBuffer str
+
+ let exts = ExtFlags {glasgowExtsEF = dopt Opt_GlasgowExts dflags,
+ parrEF = dopt Opt_PArr dflags}
+ loc = mkSrcLoc SLIT("<interactive>") 1
+
+ case parseIdentifier buf (mkPState loc exts) of
+
+ PFailed err -> do { hPutStrLn stderr (showSDoc err);
+ freeStringBuffer buf;
+ return Nothing }
+
+ POk _ rdr_name -> do { --should, but can't: freeStringBuffer buf;
+ return (Just rdr_name) }
+#endif
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Find all the things defined in a module}
+%* *
+%************************************************************************
+
+\begin{code}
+#ifdef GHCI
+hscModuleContents
+ :: DynFlags
+ -> HomeSymbolTable
+ -> HomeIfaceTable
+ -> PersistentCompilerState -- IN: persistent compiler state
+ -> Module -- module to inspect
+ -> Bool -- grab just the exports, or the whole toplev
+ -> IO (PersistentCompilerState, Maybe [TyThing])
+
+hscModuleContents dflags hst hit pcs0 mod exports_only = do {
+
+ -- slurp the interface if necessary
+ (pcs1, print_unqual, maybe_rn_stuff)
+ <- slurpIface dflags hit hst pcs0 mod;
+
+ case maybe_rn_stuff of {
+ Nothing -> return (pcs0, Nothing);
+ Just (names, rn_decls) -> do {
+
+ -- Typecheck the declarations
+ maybe_pcs <-
+ typecheckExtraDecls dflags pcs1 hst print_unqual iNTERACTIVE rn_decls;
+
+ case maybe_pcs of {
+ Nothing -> return (pcs1, Nothing);
+ Just pcs2 ->
+
+ let { all_names
+ | exports_only = names
+ | otherwise =
+ let { iface = fromJust (lookupModuleEnv hit mod);
+ env = fromJust (mi_globals iface);
+ range = rdrEnvElts env;
+ } in
+ -- grab all the things from the global env that are locally def'd
+ nub [ n | elts <- range, GRE n LocalDef _ <- elts ];
+
+ pte = pcs_PTE pcs2;
+
+ ty_things = map (fromJust . lookupType hst pte) all_names;
+
+ } in
+
+ return (pcs2, Just ty_things)
+ }}}}
+#endif
+\end{code}
+
+%************************************************************************
+%* *