Capture original source for literals
[ghc.git] / testsuite / tests / ghc-api / annotations-literals / literals.hs
1 -- This program must be called with GHC's libdir as the single command line
2 -- argument.
3 module Main where
4
5 -- import Data.Generics
6 import Data.Data
7 import Data.List
8 import System.IO
9 import GHC
10 import DynFlags
11 import MonadUtils
12 import Outputable
13 import Bag (filterBag,isEmptyBag)
14 import System.Directory (removeFile)
15 import System.Environment( getArgs )
16 import qualified Data.Map as Map
17 import Data.Dynamic ( fromDynamic,Dynamic )
18
19 main::IO()
20 main = do
21 [libdir] <- getArgs
22 testOneFile libdir "LiteralsTest"
23
24 testOneFile libdir fileName = do
25 t <- runGhc (Just libdir) $ do
26 dflags <- getSessionDynFlags
27 setSessionDynFlags dflags
28 let mn =mkModuleName fileName
29 addTarget Target { targetId = TargetModule mn
30 , targetAllowObjCode = True
31 , targetContents = Nothing }
32 load LoadAllTargets
33 modSum <- getModSummary mn
34 toks <- getRichTokenStream (ms_mod modSum)
35 return toks
36
37 putStrLn (intercalate "\n" [showToks t])
38
39 showToks ts = intercalate ",\n\n"
40 $ map (\((L p t),s) ->
41 "(" ++ pp p ++ "," ++ show t ++ ",[" ++ s ++ "])") ts
42
43 pp a = showPpr unsafeGlobalDynFlags a