summaryrefslogtreecommitdiff
path: root/testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs
blob: ab3a1e26e3cb23e68c60d9b55975a2492c343973 (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
{-# OPTIONS_GHC -Wall #-}
module Hooks.Plugin (plugin) where

import BasicTypes
import GHC.Plugins
import GHC.Hs.Expr
import GHC.Hs.Extension
import GHC.Hs.Lit
import GHC.Driver.Hooks
import TcRnMonad

plugin :: Plugin
plugin = defaultPlugin { dynflagsPlugin = hooksP }

hooksP :: [CommandLineOption] -> DynFlags -> IO DynFlags
hooksP opts dflags = return $ dflags
  { hooks = (hooks dflags)
    { runMetaHook = Just (fakeRunMeta opts) }
  }

-- This meta hook doesn't actually care running code in splices,
-- it just replaces any expression splice with the "0"
-- integer literal, and errors out on all other types of
-- meta requests.
fakeRunMeta :: [CommandLineOption] -> MetaHook TcM
fakeRunMeta opts (MetaE r) _ = do
  liftIO . putStrLn $ "Options = " ++ show opts
  pure $ r zero

  where zero :: LHsExpr GhcPs
        zero = L noSrcSpan $ HsLit NoExtField $
          HsInt NoExtField (mkIntegralLit (0 :: Int))

fakeRunMeta _ _ _ = error "fakeRunMeta: unimplemented"