85fc870604b699b865bbd3f2ece13e350a0b3603
[ghc.git] / testsuite / tests / plugins / simple-plugin / Simple / SourcePlugin.hs
1 module Simple.SourcePlugin where
2
3 import Control.Monad.IO.Class
4 import Data.List (intercalate)
5 import Data.Maybe (isJust)
6 import Plugins
7 import HscTypes
8 import TcRnTypes
9 import HsExtension
10 import Avail
11 import HsExpr
12 import Outputable
13 import HsImpExp
14 import HsDecls
15 import HsDoc
16
17 plugin :: Plugin
18 plugin = defaultPlugin { parsedResultAction = parsedPlugin
19 , typeCheckResultAction = typecheckPlugin
20 , spliceRunAction = metaPlugin'
21 , interfaceLoadAction = interfaceLoadPlugin'
22 , renamedResultAction = Just renamedAction
23 }
24
25 parsedPlugin :: [CommandLineOption] -> ModSummary -> HsParsedModule
26 -> Hsc HsParsedModule
27 parsedPlugin opts _ pm
28 = do liftIO $ putStrLn $ "parsePlugin(" ++ intercalate "," opts ++ ")"
29 return pm
30
31 renamedAction :: [CommandLineOption] -> ModSummary
32 -> ( HsGroup GhcRn, [LImportDecl GhcRn]
33 , Maybe [(LIE GhcRn, Avails)], Maybe LHsDocString )
34 -> TcM ()
35 renamedAction _ _ ( gr, _, _, _ )
36 = liftIO $ putStrLn "typeCheckPlugin (rn)"
37
38 typecheckPlugin :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
39 typecheckPlugin _ _ tc
40 = do liftIO $ putStrLn "typeCheckPlugin (tc)"
41 return tc
42
43 metaPlugin' :: [CommandLineOption] -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
44 metaPlugin' _ meta
45 = do liftIO $ putStrLn $ "metaPlugin: " ++ (showSDocUnsafe $ ppr meta)
46 return meta
47
48 interfaceLoadPlugin' :: [CommandLineOption] -> ModIface -> IfM lcl ModIface
49 interfaceLoadPlugin' _ iface
50 = do liftIO $ putStrLn $ "interfacePlugin: "
51 ++ (showSDocUnsafe $ ppr $ mi_module iface)
52 return iface