2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
4 \section[AnnCoreSyntax]{Annotated core syntax}
6 For when you want @CoreSyntax@ trees annotated at every node. Other
7 than that, just like @CoreSyntax@. (Important to be sure that it {\em
8 really is} just like @CoreSyntax@.)
11 #include "HsVersions.h"
14 AnnCoreBinding(..), AnnCoreExpr(..),
15 AnnCoreExpr'(..), -- v sad that this must be exported
16 AnnCoreCaseAlts(..), AnnCoreCaseDefault(..),
18 deAnnotate -- we may eventually export some of the other deAnners
20 -- and to make the interface self-sufficient
23 import PrelInfo ( PrimOp(..), PrimRep
24 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
25 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
27 import Literal ( Literal )
30 import CostCentre ( CostCentre )
31 #if USE_ATTACK_PRAGMAS
37 data AnnCoreBinding binder bindee annot
38 = AnnCoNonRec binder (AnnCoreExpr binder bindee annot)
39 | AnnCoRec [(binder, AnnCoreExpr binder bindee annot)]
43 type AnnCoreExpr binder bindee annot = (annot, AnnCoreExpr' binder bindee annot)
45 data AnnCoreExpr' binder bindee annot
49 | AnnCoCon Id [Type] [GenCoreAtom bindee]
51 | AnnCoPrim PrimOp [Type] [GenCoreAtom bindee]
54 (AnnCoreExpr binder bindee annot)
56 (AnnCoreExpr binder bindee annot)
58 | AnnCoApp (AnnCoreExpr binder bindee annot)
60 | AnnCoTyApp (AnnCoreExpr binder bindee annot)
63 | AnnCoCase (AnnCoreExpr binder bindee annot)
64 (AnnCoreCaseAlts binder bindee annot)
66 | AnnCoLet (AnnCoreBinding binder bindee annot)
67 (AnnCoreExpr binder bindee annot)
70 (AnnCoreExpr binder bindee annot)
74 data AnnCoreCaseAlts binder bindee annot
77 AnnCoreExpr binder bindee annot)]
78 (AnnCoreCaseDefault binder bindee annot)
79 | AnnCoPrimAlts [(Literal,
80 AnnCoreExpr binder bindee annot)]
81 (AnnCoreCaseDefault binder bindee annot)
83 data AnnCoreCaseDefault binder bindee annot
85 | AnnCoBindDefault binder
86 (AnnCoreExpr binder bindee annot)
90 deAnnotate :: AnnCoreExpr bndr bdee ann -> GenCoreExpr bndr bdee
92 deAnnotate (_, AnnCoVar v) = Var v
93 deAnnotate (_, AnnCoLit lit) = Lit lit
94 deAnnotate (_, AnnCoCon con tys args) = Con con tys args
95 deAnnotate (_, AnnCoPrim op tys args) = Prim op tys args
96 deAnnotate (_, AnnCoLam binder body) = Lam binder (deAnnotate body)
97 deAnnotate (_, AnnCoTyLam tyvar body) = CoTyLam tyvar (deAnnotate body)
98 deAnnotate (_, AnnCoApp fun arg) = App (deAnnotate fun) arg
99 deAnnotate (_, AnnCoTyApp fun ty) = CoTyApp (deAnnotate fun) ty
100 deAnnotate (_, AnnCoSCC lbl body) = SCC lbl (deAnnotate body)
102 deAnnotate (_, AnnCoLet bind body)
103 = Let (deAnnBind bind) (deAnnotate body)
105 deAnnBind (AnnCoNonRec var rhs) = NonRec var (deAnnotate rhs)
106 deAnnBind (AnnCoRec pairs) = Rec [(v,deAnnotate rhs) | (v,rhs) <- pairs]
108 deAnnotate (_, AnnCoCase scrut alts)
109 = Case (deAnnotate scrut) (deAnnAlts alts)
111 deAnnAlts (AnnCoAlgAlts alts deflt)
112 = AlgAlts [(con,args,deAnnotate rhs) | (con,args,rhs) <- alts]
115 deAnnAlts (AnnCoPrimAlts alts deflt)
116 = PrimAlts [(lit,deAnnotate rhs) | (lit,rhs) <- alts]
119 deAnnDeflt AnnCoNoDefault = NoDefault
120 deAnnDeflt (AnnCoBindDefault var rhs) = BindDefault var (deAnnotate rhs)