2 % (c) The University of Glasgow 2006
3 % (c) The AQUA Project, Glasgow University, 1993-1998
5 \section[TcAnnotations]{Typechecking annotations}
8 module TcAnnotations ( tcAnnotations ) where
20 import {-# SOURCE #-} TcSplice ( runAnnotation )
26 tcAnnotations :: [LAnnDecl Name] -> TcM [Annotation]
27 tcAnnotations = mapM tcAnnotation
29 tcAnnotation :: LAnnDecl Name -> TcM Annotation
31 -- TODO: modify lexer so ANN pragmas are parsed as comments in a stage1 compiler, so developers don't see this error
32 tcAnnotation (L _ (HsAnnotation _ expr)) = pprPanic "Cant do annotations without GHCi" (ppr expr)
34 tcAnnotation ann@(L loc (HsAnnotation provenance expr)) = do
35 -- Work out what the full target of this annotation was
37 let target = annProvenanceToTarget mod provenance
39 -- Run that annotation and construct the full Annotation data structure
40 setSrcSpan loc $ addErrCtxt (annCtxt ann) $ addExprErrCtxt expr $ runAnnotation target expr
42 annProvenanceToTarget :: Module -> AnnProvenance Name -> AnnTarget Name
43 annProvenanceToTarget _ (ValueAnnProvenance name) = NamedTarget name
44 annProvenanceToTarget _ (TypeAnnProvenance name) = NamedTarget name
45 annProvenanceToTarget mod ModuleAnnProvenance = ModuleTarget mod
47 annCtxt :: OutputableBndr id => LAnnDecl id -> SDoc
49 = hang (ptext (sLit "In the annotation:")) 2 (ppr ann)