1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE RankNTypes #-}
2
3
module Info
3
4
( getIdentifierInfo
@@ -12,6 +13,7 @@ import Data.Typeable (Typeable)
12
13
import MonadUtils (liftIO )
13
14
import qualified CoreUtils
14
15
import qualified Desugar
16
+ import qualified DynFlags
15
17
import qualified GHC
16
18
import qualified HscTypes
17
19
import qualified NameSet
@@ -24,7 +26,11 @@ import qualified TcRnTypes
24
26
getIdentifierInfo :: FilePath -> String -> GHC. Ghc (Either String String )
25
27
getIdentifierInfo file identifier =
26
28
withModSummary file $ \ m -> do
29
+ #if __GLASGOW_HASKELL__ >= 706
30
+ GHC. setContext [GHC. IIModule (GHC. moduleName (GHC. ms_mod m))]
31
+ #else
27
32
GHC. setContext [GHC. IIModule (GHC. ms_mod m)]
33
+ #endif
28
34
GHC. handleSourceError (return . Left . show ) $
29
35
liftM Right (infoThing identifier)
30
36
@@ -84,15 +90,26 @@ processTypeCheckedModule tcm (line, col) = do
84
90
bts <- mapM (getTypeLHsBind tcm) bs
85
91
ets <- mapM (getTypeLHsExpr tcm) es
86
92
pts <- mapM (getTypeLPat tcm) ps
87
- return $ map toTup $ sortBy cmp $ catMaybes $ concat [ets, bts, pts]
93
+ #if __GLASGOW_HASKELL__ >= 706
94
+ dflags <- DynFlags. getDynFlags
95
+ return $ map (toTup dflags) $
96
+ #else
97
+ return $ map toTup $
98
+ #endif
99
+ sortBy cmp $ catMaybes $ concat [ets, bts, pts]
88
100
where
89
101
cmp (a, _) (b, _)
90
102
| a `GHC.isSubspanOf` b = LT
91
103
| b `GHC.isSubspanOf` a = GT
92
104
| otherwise = EQ
93
105
106
+ #if __GLASGOW_HASKELL__ >= 706
107
+ toTup :: GHC. DynFlags -> (GHC. SrcSpan , GHC. Type ) -> ((Int , Int , Int , Int ), String )
108
+ toTup dflags (spn, typ) = (fourInts spn, pretty dflags typ)
109
+ #else
94
110
toTup :: (GHC. SrcSpan , GHC. Type ) -> ((Int , Int , Int , Int ), String )
95
111
toTup (spn, typ) = (fourInts spn, pretty typ)
112
+ #endif
96
113
97
114
fourInts :: GHC. SrcSpan -> (Int , Int , Int , Int )
98
115
fourInts = fromMaybe (0 , 0 , 0 , 0 ) . getSrcSpan
@@ -133,10 +150,20 @@ listifySpans tcs lc = listifyStaged TypeChecker p tcs
133
150
listifyStaged :: Typeable r => Stage -> (r -> Bool ) -> GenericQ [r ]
134
151
listifyStaged s p = everythingStaged s (++) [] ([] `mkQ` (\ x -> [x | p x]))
135
152
153
+ #if __GLASGOW_HASKELL__ >= 706
154
+ pretty :: GHC. DynFlags -> GHC. Type -> String
155
+ pretty dflags =
156
+ #else
136
157
pretty :: GHC. Type -> String
137
158
pretty =
159
+ #endif
138
160
Pretty. showDocWith Pretty. OneLineMode
139
- . Outputable. withPprStyleDoc (Outputable. mkUserStyle Outputable. neverQualify Outputable. AllTheWay )
161
+ #if __GLASGOW_HASKELL__ >= 706
162
+ . Outputable. withPprStyleDoc dflags
163
+ #else
164
+ . Outputable. withPprStyleDoc
165
+ #endif
166
+ (Outputable. mkUserStyle Outputable. neverQualify Outputable. AllTheWay )
140
167
. PprTyThing. pprTypeForUser False
141
168
142
169
------------------------------------------------------------------------------
@@ -170,7 +197,12 @@ infoThing str = do
170
197
mb_stuffs <- mapM GHC. getInfo names
171
198
let filtered = filterOutChildren (\ (t,_f,_i) -> t) (catMaybes mb_stuffs)
172
199
unqual <- GHC. getPrintUnqual
200
+ #if __GLASGOW_HASKELL__ >= 706
201
+ dflags <- DynFlags. getDynFlags
202
+ return $ Outputable. showSDocForUser dflags unqual $
203
+ #else
173
204
return $ Outputable. showSDocForUser unqual $
205
+ #endif
174
206
Outputable. vcat (intersperse (Outputable. text " " ) $ map (pprInfo False ) filtered)
175
207
176
208
-- Filter out names whose parent is also there Good
@@ -185,7 +217,11 @@ filterOutChildren get_thing xs
185
217
Just p -> GHC. getName p `NameSet.elemNameSet` all_names
186
218
Nothing -> False
187
219
220
+ #if __GLASGOW_HASKELL__ >= 706
221
+ pprInfo :: PprTyThing. PrintExplicitForalls -> (HscTypes. TyThing , GHC. Fixity , [GHC. ClsInst ]) -> Outputable. SDoc
222
+ #else
188
223
pprInfo :: PprTyThing. PrintExplicitForalls -> (HscTypes. TyThing , GHC. Fixity , [GHC. Instance ]) -> Outputable. SDoc
224
+ #endif
189
225
pprInfo pefas (thing, fixity, insts) =
190
226
PprTyThing. pprTyThingInContextLoc pefas thing
191
227
Outputable. $$ show_fixity fixity
0 commit comments