blob: e918b02cc9e2ac0371d2923415102a7810b5f682 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
module Simple.SourcePlugin where
import Control.Monad.IO.Class
import Data.List (intercalate)
import Data.Maybe (isJust)
import GHC.Driver.Plugins
import GHC.Driver.Session
import GHC.Plugins
import GHC.Tc.Types
import Language.Haskell.Syntax.Extension
import GHC.Types.Avail
import GHC.Hs
import GHC.Hs.Expr
import GHC.Utils.Outputable
import GHC.Hs.ImpExp
import GHC.Hs.Decls
import GHC.Hs.Doc
import System.IO
plugin :: Plugin
plugin = defaultPlugin { parsedResultAction = parsedPlugin
, typeCheckResultAction = typecheckPlugin
, spliceRunAction = metaPlugin'
, interfaceLoadAction = interfaceLoadPlugin'
, renamedResultAction = renamedAction
}
parsedPlugin :: [CommandLineOption] -> ModSummary
-> ParsedResult -> Hsc ParsedResult
parsedPlugin opts _ parsed
= do liftIO $ putStrLn $ "parsePlugin(" ++ intercalate "," opts ++ ")"
-- TODO: Remove #20791
liftIO $ hFlush stdout
return parsed
renamedAction :: [CommandLineOption]
-> TcGblEnv -> HsGroup GhcRn
-> TcM (TcGblEnv, HsGroup GhcRn)
renamedAction _ env grp
= do liftIO $ putStrLn "typeCheckPlugin (rn)"
-- TODO: Remove #20791
liftIO $ hFlush stdout
return (env, grp)
typecheckPlugin :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
typecheckPlugin _ _ tc
= do liftIO $ putStrLn "typeCheckPlugin (tc)"
-- TODO: Remove #20791
liftIO $ hFlush stdout
return tc
metaPlugin' :: [CommandLineOption] -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
metaPlugin' _ meta
= do dflags <- getDynFlags
liftIO $ putStrLn $ "metaPlugin: " ++ (showSDoc dflags $ ppr meta)
-- TODO: Remove #20791
liftIO $ hFlush stdout
return meta
interfaceLoadPlugin' :: [CommandLineOption] -> ModIface -> IfM lcl ModIface
interfaceLoadPlugin' _ iface
= do dflags <- getDynFlags
liftIO $ putStrLn $ "interfacePlugin: "
++ (showSDoc dflags $ ppr $ mi_module iface)
-- TODO: Remove #20791
liftIO $ hFlush stdout
return iface
|