diff options
Diffstat (limited to 'testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs')
-rw-r--r-- | testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs b/testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs new file mode 100644 index 0000000000..04e066c22f --- /dev/null +++ b/testsuite/tests/plugins/hooks-plugin/Hooks/Plugin.hs @@ -0,0 +1,34 @@ +{-# OPTIONS_GHC -Wall #-} +module Hooks.Plugin (plugin) where + +import BasicTypes +import GhcPlugins +import GHC.Hs.Expr +import GHC.Hs.Extension +import GHC.Hs.Lit +import 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" |