4
4
5
5
module Refact.Compat (
6
6
-- * ApiAnnotation / GHC.Parser.ApiAnnotation
7
+ #if MIN_VERSION_ghc(9,12,0)
8
+ #else
7
9
AnnKeywordId (.. ),
10
+ #endif
8
11
DeltaPos (.. ),
9
12
10
13
-- * BasicTypes / GHC.Types.Basic
@@ -93,6 +96,12 @@ module Refact.Compat (
93
96
setSrcSpanFile ,
94
97
srcSpanToAnnSpan ,
95
98
AnnSpan ,
99
+ commentSrcSpan ,
100
+ ann ,
101
+ transferEntryDP ,
102
+ transferEntryDP' ,
103
+ AnnConstraint ,
104
+ showAst ,
96
105
97
106
#if MIN_VERSION_ghc(9,4,0)
98
107
-- * GHC 9.4 stuff
@@ -101,7 +110,11 @@ module Refact.Compat (
101
110
) where
102
111
103
112
import Control.Monad.Trans.State.Strict (StateT )
113
+ #if MIN_VERSION_ghc(9,12,0)
114
+ import Data.Data (Data , Typeable )
115
+ #else
104
116
import Data.Data (Data )
117
+ #endif
105
118
import qualified GHC
106
119
import GHC.Data.Bag (unitBag , bagToList )
107
120
import GHC.Data.FastString (FastString , mkFastString )
@@ -115,7 +128,7 @@ import GHC.Driver.Errors.Types (ErrorMessages, ghcUnknownMessage, GhcMessage)
115
128
#endif
116
129
import GHC.Driver.Session hiding (initDynFlags )
117
130
#if MIN_VERSION_ghc(9,6,0)
118
- import GHC.Hs hiding (Pat , Stmt , parseModuleName )
131
+ import GHC.Hs hiding (Pat , Stmt , parseModuleName , ann )
119
132
#else
120
133
import GHC.Hs hiding (Pat , Stmt )
121
134
#endif
@@ -148,6 +161,18 @@ import GHC.Utils.Panic
148
161
import Language.Haskell.GHC.ExactPrint.Parsers (Parser )
149
162
import Language.Haskell.GHC.ExactPrint.Utils
150
163
import Refact.Types (Refactoring )
164
+ #if MIN_VERSION_ghc(9,12,0)
165
+ import qualified Language.Haskell.GHC.ExactPrint.Transform as Exact
166
+ #else
167
+ import Language.Haskell.GHC.ExactPrint (transferEntryDP , transferEntryDP' , showAst )
168
+ #endif
169
+
170
+
171
+ #if MIN_VERSION_ghc(9,12,0)
172
+ type AnnConstraint an = (NoAnn an , Semigroup an )
173
+ #else
174
+ type AnnConstraint an = (Monoid an )
175
+ #endif
151
176
152
177
type MonadFail' = MonadFail
153
178
@@ -171,7 +196,11 @@ ppp pst = concatMap unDecorated $ fmap (diagnosticMessage . errMsgDiagnostic) $
171
196
ppp pst = concatMap unDecorated (errMsgDiagnostic <$> bagToList pst)
172
197
#endif
173
198
199
+ #if MIN_VERSION_ghc(9,12,0)
200
+ type FunBind = HsMatchContext (LocatedN RdrName )
201
+ #else
174
202
type FunBind = HsMatchContext GhcPs
203
+ #endif
175
204
176
205
pattern RealSrcLoc' :: RealSrcLoc -> SrcLoc
177
206
pattern RealSrcLoc' r <- RealSrcLoc r _ where
@@ -266,3 +295,33 @@ type ReplaceWorker a mod =
266
295
Int ->
267
296
Refactoring SrcSpan ->
268
297
IO mod
298
+
299
+
300
+ commentSrcSpan :: GHC. LEpaComment -> SrcSpan
301
+ #if MIN_VERSION_ghc(9,12,0)
302
+ commentSrcSpan (GHC. L (GHC. EpaSpan l) _) = l
303
+ commentSrcSpan (GHC. L (GHC. EpaDelta l _ _) _) = l
304
+ #else
305
+ commentSrcSpan (GHC. L (GHC. Anchor l _) _) = GHC. RealSrcSpan l Strict. Nothing
306
+ #endif
307
+
308
+ #if MIN_VERSION_ghc(9,12,0)
309
+ transferEntryDP :: (Typeable t1 , Typeable t2 , Exact. HasTransform m )
310
+ => LocatedAn t1 a -> LocatedAn t2 b -> m (LocatedAn t2 b )
311
+ transferEntryDP a b = return $ Exact. transferEntryDP a b
312
+ #endif
313
+
314
+ #if MIN_VERSION_ghc(9,12,0)
315
+ transferEntryDP' :: (Exact. HasTransform m )
316
+ => LHsDecl GhcPs -> LHsDecl GhcPs -> m (LHsDecl GhcPs )
317
+ transferEntryDP' a b = return $ Exact. transferEntryDP' a b
318
+ #endif
319
+
320
+
321
+ #if MIN_VERSION_ghc(9,12,0)
322
+ ann :: EpAnn a -> a
323
+ ann ls = GHC. anns ls
324
+ #else
325
+ ann :: SrcSpanAnn' a -> a
326
+ ann = GHC. ann
327
+ #endif
0 commit comments