Add (a) CoreM monad, (b) new Annotations feature
[ghc-hetmet.git] / compiler / typecheck / TcAnnotations.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The AQUA Project, Glasgow University, 1993-1998
4 %
5 \section[TcAnnotations]{Typechecking annotations}
6
7 \begin{code}
8 module TcAnnotations ( tcAnnotations ) where
9
10 import HsSyn
11 import Annotations
12 import Name
13 import TcRnMonad
14 import SrcLoc
15 import Outputable
16
17 #ifdef GHCI
18 import Module
19 import TcExpr
20 import {-# SOURCE #-} TcSplice ( runAnnotation )
21 import FastString
22 #endif
23
24 import Control.Monad
25 \end{code}
26
27 \begin{code}
28 tcAnnotations :: [LAnnDecl Name] -> TcM [Annotation]
29 tcAnnotations = mapM tcAnnotation
30
31 tcAnnotation :: LAnnDecl Name -> TcM Annotation
32 #ifndef GHCI
33 -- TODO: modify lexer so ANN pragmas are parsed as comments in a stage1 compiler, so developers don't see this error
34 tcAnnotation (L _ (HsAnnotation _ expr)) = pprPanic "Cant do annotations without GHCi" (ppr expr)
35 #else
36 tcAnnotation ann@(L loc (HsAnnotation provenance expr)) = do
37     -- Work out what the full target of this annotation was
38     mod <- getModule
39     let target = annProvenanceToTarget mod provenance
40     
41     -- Run that annotation and construct the full Annotation data structure
42     setSrcSpan loc $ addErrCtxt (annCtxt ann) $ addExprErrCtxt expr $ runAnnotation target expr
43
44 annProvenanceToTarget :: Module -> AnnProvenance Name -> AnnTarget Name
45 annProvenanceToTarget _   (ValueAnnProvenance name) = NamedTarget name
46 annProvenanceToTarget _   (TypeAnnProvenance name)  = NamedTarget name
47 annProvenanceToTarget mod ModuleAnnProvenance       = ModuleTarget mod
48
49 annCtxt :: OutputableBndr id => LAnnDecl id -> SDoc
50 annCtxt ann
51   = hang (ptext (sLit "In the annotation:")) 4 (ppr ann)
52 #endif
53 \end{code}