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 AnnCoreCaseAlternatives(..), AnnCoreCaseDefault(..),
19 AnnCoreParCommunicate(..),
20 #endif {- Data Parallel Haskell -}
22 deAnnotate, -- we may eventually export some of the other deAnners
24 -- and to make the interface self-sufficient
25 BasicLit, Id, PrimOp, TyCon, TyVar, UniType, CostCentre
26 IF_ATTACK_PRAGMAS(COMMA cmpTyCon COMMA cmpTyVar)
27 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
30 import AbsPrel ( PrimOp(..), PrimKind
31 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
32 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
34 import AbsUniType ( Id, TyVar, TyCon, UniType
35 IF_ATTACK_PRAGMAS(COMMA cmpTyCon COMMA cmpTyVar)
36 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
38 import BasicLit ( BasicLit )
41 import CostCentre ( CostCentre )
42 #if USE_ATTACK_PRAGMAS
48 data AnnCoreBinding binder bindee annot
49 = AnnCoNonRec binder (AnnCoreExpr binder bindee annot)
50 | AnnCoRec [(binder, AnnCoreExpr binder bindee annot)]
54 type AnnCoreExpr binder bindee annot = (annot, AnnCoreExpr' binder bindee annot)
56 data AnnCoreExpr' binder bindee annot
60 | AnnCoCon Id [UniType] [CoreAtom bindee]
62 | AnnCoPrim PrimOp [UniType] [CoreAtom bindee]
65 (AnnCoreExpr binder bindee annot)
67 (AnnCoreExpr binder bindee annot)
69 | AnnCoApp (AnnCoreExpr binder bindee annot)
71 | AnnCoTyApp (AnnCoreExpr binder bindee annot)
74 | AnnCoCase (AnnCoreExpr binder bindee annot)
75 (AnnCoreCaseAlternatives binder bindee annot)
77 | AnnCoLet (AnnCoreBinding binder bindee annot)
78 (AnnCoreExpr binder bindee annot)
81 (AnnCoreExpr binder bindee annot)
83 | AnnCoZfExpr (AnnCoreExpr binder bindee annot)
84 (AnnCoreParQuals binder bindee annot)
86 | AnnCoParCon Id Int [UniType] [AnnCoreExpr binder bindee annot]
90 (AnnCoreExpr binder bindee annot)
91 (AnnCoreParCommunicate binder bindee annot)
94 (AnnCoreExpr binder bindee annot)
95 [AnnCoreExpr binder bindee annot]
96 #endif {- Data Parallel Haskell -}
101 data AnnCoreParQuals binder bindee annot
102 = AnnCoAndQuals (AnnCoreParQuals binder bindee annot)
103 (AnnCoreParQuals binder bindee annot)
104 | AnnCoParFilter (AnnCoreExpr binder bindee annot)
105 | AnnCoDrawnGen [binder]
107 (AnnCoreExpr binder bindee annot)
108 | AnnCoIndexGen [AnnCoreExpr binder bindee annot]
110 (AnnCoreExpr binder bindee annot)
111 #endif {- Data Parallel Haskell -}
115 data AnnCoreCaseAlternatives binder bindee annot
118 AnnCoreExpr binder bindee annot)]
119 (AnnCoreCaseDefault binder bindee annot)
120 | AnnCoPrimAlts [(BasicLit,
121 AnnCoreExpr binder bindee annot)]
122 (AnnCoreCaseDefault binder bindee annot)
124 | AnnCoParAlgAlts TyCon
128 AnnCoreExpr binder bindee annot)]
129 (AnnCoreCaseDefault binder bindee annot)
130 | AnnCoParPrimAlts TyCon
133 AnnCoreExpr binder bindee annot)]
134 (AnnCoreCaseDefault binder bindee annot)
135 #endif {- Data Parallel Haskell -}
137 data AnnCoreCaseDefault binder bindee annot
139 | AnnCoBindDefault binder
140 (AnnCoreExpr binder bindee annot)
145 data AnnCoreParCommunicate binder bindee annot
146 = AnnCoParSend [AnnCoreExpr binder bindee annot]
147 | AnnCoParFetch [AnnCoreExpr binder bindee annot]
150 #endif {- Data Parallel Haskell -}
154 deAnnotate :: AnnCoreExpr bndr bdee ann -> CoreExpr bndr bdee
156 deAnnotate (_, AnnCoVar v) = CoVar v
157 deAnnotate (_, AnnCoLit lit) = CoLit lit
158 deAnnotate (_, AnnCoCon con tys args) = CoCon con tys args
159 deAnnotate (_, AnnCoPrim op tys args) = CoPrim op tys args
160 deAnnotate (_, AnnCoLam binders body) = CoLam binders (deAnnotate body)
161 deAnnotate (_, AnnCoTyLam tyvar body) = CoTyLam tyvar (deAnnotate body)
162 deAnnotate (_, AnnCoApp fun arg) = CoApp (deAnnotate fun) arg
163 deAnnotate (_, AnnCoTyApp fun ty) = CoTyApp (deAnnotate fun) ty
164 deAnnotate (_, AnnCoSCC lbl body) = CoSCC lbl (deAnnotate body)
166 deAnnotate (_, AnnCoLet bind body)
167 = CoLet (deAnnBind bind) (deAnnotate body)
169 deAnnBind (AnnCoNonRec var rhs) = CoNonRec var (deAnnotate rhs)
170 deAnnBind (AnnCoRec pairs) = CoRec [(v,deAnnotate rhs) | (v,rhs) <- pairs]
172 deAnnotate (_, AnnCoCase scrut alts)
173 = CoCase (deAnnotate scrut) (deAnnAlts alts)
175 deAnnAlts (AnnCoAlgAlts alts deflt)
176 = CoAlgAlts [(con,args,deAnnotate rhs) | (con,args,rhs) <- alts]
179 deAnnAlts (AnnCoPrimAlts alts deflt)
180 = CoPrimAlts [(lit,deAnnotate rhs) | (lit,rhs) <- alts]
183 deAnnDeflt AnnCoNoDefault = CoNoDefault
184 deAnnDeflt (AnnCoBindDefault var rhs) = CoBindDefault var (deAnnotate rhs)