Migrate cvs diff from fptools-assoc branch
[ghc-hetmet.git] / compiler / parser / ParserCore.y
index 7b82eba..a6ee5dd 100644 (file)
@@ -7,9 +7,13 @@ import RdrHsSyn
 import HsSyn
 import RdrName
 import OccName
-import Kind( Kind(..) )
+import Type ( Kind,
+              liftedTypeKindTyCon, openTypeKindTyCon, unliftedTypeKindTyCon,
+              argTypeKindTyCon, ubxTupleKindTyCon, mkArrowKind, mkTyConApp
+            )
 import Name( nameOccName, nameModule )
 import Module
+import PackageConfig   ( mainPackageId )
 import ParserCoreUtils
 import LexCore
 import Literal
@@ -38,7 +42,7 @@ import Char
  '%in'         { TKin }
  '%case'       { TKcase }
  '%of'         { TKof }
- '%coerce'     { TKcoerce }
+ '%cast'       { TKcast }
  '%note'       { TKnote }
  '%external'   { TKexternal }
  '%_'          { TKwild }
@@ -72,7 +76,8 @@ module        :: { HsExtCore RdrName }
          : '%module' modid tdefs vdefgs { HsExtCore $2 $3 $4 }
 
 modid  :: { Module }
-       : CNAME                  { mkModuleFS (mkFastString $1) }
+        : CNAME                         { mkModule mainPackageId  -- ToDo: wrong
+                                       (mkModuleNameFS (mkFastString $1)) }
 
 -------------------------------------------------------------
 --     Type and newtype declarations are in HsSyn syntax
@@ -83,10 +88,18 @@ tdefs       :: { [TyClDecl RdrName] }
 
 tdef   :: { TyClDecl RdrName }
        : '%data' q_tc_name tv_bndrs '=' '{' cons '}'
-                { mkTyData DataType (noLoc [], noLoc (ifaceExtRdrName $2), map toHsTvBndr $3) Nothing $6 Nothing }
+                { mkTyData DataType ( noLoc []
+                                   , noLoc (ifaceExtRdrName $2)
+                                   , map toHsTvBndr $3
+                                   , Nothing
+                                   ) Nothing $6 Nothing }
        | '%newtype' q_tc_name tv_bndrs trep 
                { let tc_rdr = ifaceExtRdrName $2 in
-                  mkTyData NewType (noLoc [], noLoc tc_rdr, map toHsTvBndr $3) Nothing ($4 (rdrNameOcc tc_rdr)) Nothing }
+                  mkTyData NewType ( noLoc []
+                                  , noLoc tc_rdr
+                                  , map toHsTvBndr $3
+                                  , Nothing
+                                  ) Nothing ($4 (rdrNameOcc tc_rdr)) Nothing }
 
 -- For a newtype we have to invent a fake data constructor name
 -- It doesn't matter what it is, because it won't be used
@@ -105,7 +118,7 @@ con :: { LConDecl RdrName }
        : d_pat_occ attv_bndrs hs_atys 
                { noLoc $ ConDecl (noLoc (mkRdrUnqual $1)) Explicit $2 (noLoc []) (PrefixCon $3) ResTyH98}
         | d_pat_occ '::' ty
-                -- XXX - autrijus - $3 needs to be split into argument and return types!
+                -- XXX - audreyt - $3 needs to be split into argument and return types!
                 -- also not sure whether the [] below (quantified vars) appears.
                 -- also the "PrefixCon []" is wrong.
                 -- also we want to munge $3 somehow.
@@ -168,7 +181,7 @@ vdef        :: { (IfaceIdBndr, IfaceExpr) }
   -- same as the module being compiled, and Iface syntax only
   -- has OccNames in binding positions
 
-qd_occ :: { OccName }
+qd_occ :: { FastString }
         : var_occ { $1 }
         | d_occ   { $1 }
 
@@ -190,7 +203,7 @@ id_bndrs :: { [IfaceIdBndr] }
        | id_bndr id_bndrs      { $1:$2 }
 
 tv_bndr        :: { IfaceTvBndr }
-       :  tv_occ                    { ($1, LiftedTypeKind) }
+       :  tv_occ                    { ($1, ifaceLiftedTypeKind) }
        |  '(' tv_occ '::' akind ')' { ($2, $4) }
 
 tv_bndrs       :: { [IfaceTvBndr] }
@@ -198,21 +211,21 @@ tv_bndrs  :: { [IfaceTvBndr] }
        | tv_bndr tv_bndrs      { $1:$2 }
 
 akind  :: { IfaceKind }
-       : '*'              { LiftedTypeKind   } 
-       | '#'              { UnliftedTypeKind }
-       | '?'              { OpenTypeKind     }
+       : '*'              { ifaceLiftedTypeKind }      
+       | '#'              { ifaceUnliftedTypeKind }
+       | '?'              { ifaceOpenTypeKind }
         | '(' kind ')'    { $2 }
 
 kind   :: { IfaceKind }
        : akind            { $1 }
-       | akind '->' kind  { FunKind $1 $3 }
+       | akind '->' kind  { ifaceArrow $1 $3 }
 
 -----------------------------------------
 --             Expressions
 
 aexp    :: { IfaceExpr }
        : var_occ                { IfaceLcl $1 }
-       | modid '.' qd_occ       { IfaceExt (ExtPkg $1 $3) }
+        | modid '.' qd_occ      { IfaceExt (ExtPkg $1 (mkVarOccFS $3)) }
        | lit           { IfaceLit $1 }
        | '(' exp ')'   { $2 }
 
@@ -228,11 +241,10 @@ exp       :: { IfaceExpr }
 -- gaw 2004
        | '%case' '(' ty ')' aexp '%of' id_bndr
          '{' alts1 '}'               { IfaceCase $5 (fst $7) $3 $9 }
-       | '%coerce' aty exp           { IfaceNote (IfaceCoerce $2) $3 }
+        | '%cast' exp aty { IfaceCast $2 $3 }
        | '%note' STRING exp       
            { case $2 of
               --"SCC"      -> IfaceNote (IfaceSCC "scc") $3
-              "InlineCall" -> IfaceNote IfaceInlineCall $3
               "InlineMe"   -> IfaceNote IfaceInlineMe $3
             }
         | '%external' STRING aty   { IfaceFCall (ForeignCall.CCall 
@@ -261,11 +273,11 @@ lit       :: { Literal }
        | '(' CHAR '::' aty ')'         { MachChar $2 }
        | '(' STRING '::' aty ')'       { MachStr (mkFastString $2) }
 
-tv_occ :: { OccName }
-       : NAME  { mkOccName tvName $1 }
+tv_occ :: { FastString }
+       : NAME  { mkFastString $1 }
 
-var_occ        :: { OccName }
-       : NAME  { mkVarOcc $1 }
+var_occ        :: { FastString }
+       : NAME  { mkFastString $1 }
 
 
 -- Type constructor
@@ -279,11 +291,13 @@ d_pat_occ :: { OccName }
 
 -- Data constructor occurrence in an expression;
 -- use the varName because that's the worker Id
-d_occ :: { OccName }
-       : CNAME { mkVarOcc $1 }
+d_occ :: { FastString }
+       : CNAME { mkFastString $1 }
 
 {
 
+ifaceKind kc = IfaceTyConApp kc []
+
 ifaceBndrName (IfaceIdBndr (n,_)) = n
 ifaceBndrName (IfaceTvBndr (n,_)) = n
 
@@ -315,14 +329,37 @@ eqTc (IfaceTc (ExtPkg mod occ)) tycon
 -- are very limited (see the productions for 'ty', so the translation
 -- isn't hard
 toHsType :: IfaceType -> LHsType RdrName
-toHsType (IfaceTyVar v)                         = noLoc $ HsTyVar (mkRdrUnqual v)
+toHsType (IfaceTyVar v)                         = noLoc $ HsTyVar (mkRdrUnqual (mkTyVarOcc v))
 toHsType (IfaceAppTy t1 t2)                     = noLoc $ HsAppTy (toHsType t1) (toHsType t2)
 toHsType (IfaceFunTy t1 t2)                     = noLoc $ HsFunTy (toHsType t1) (toHsType t2)
 toHsType (IfaceTyConApp (IfaceTc tc) ts) = foldl mkHsAppTy (noLoc $ HsTyVar (ifaceExtRdrName tc)) (map toHsType ts) 
 toHsType (IfaceForAllTy tv t)            = add_forall (toHsTvBndr tv) (toHsType t)
 
+-- We also need to convert IfaceKinds to Kinds (now that they are different).
+-- Only a limited form of kind will be encountered... hopefully
+toKind :: IfaceKind -> Kind
+toKind (IfaceFunTy ifK1 ifK2)  = mkArrowKind (toKind ifK1) (toKind ifK2)
+toKind (IfaceTyConApp ifKc []) = mkTyConApp (toKindTc ifKc) []
+toKind other                   = pprPanic "toKind" (ppr other)
+
+toKindTc :: IfaceTyCon -> TyCon
+toKindTc IfaceLiftedTypeKindTc   = liftedTypeKindTyCon
+toKindTc IfaceOpenTypeKindTc     = openTypeKindTyCon
+toKindTc IfaceUnliftedTypeKindTc = unliftedTypeKindTyCon
+toKindTc IfaceUbxTupleKindTc     = ubxTupleKindTyCon
+toKindTc IfaceArgTypeKindTc      = argTypeKindTyCon
+toKindTc other                   = pprPanic "toKindTc" (ppr other)
+
+ifaceTcType ifTc = IfaceTyConApp ifTc []
+
+ifaceLiftedTypeKind   = ifaceTcType IfaceLiftedTypeKindTc
+ifaceOpenTypeKind     = ifaceTcType IfaceOpenTypeKindTc
+ifaceUnliftedTypeKind = ifaceTcType IfaceUnliftedTypeKindTc
+
+ifaceArrow ifT1 ifT2 = IfaceFunTy ifT1 ifT2
+
 toHsTvBndr :: IfaceTvBndr -> LHsTyVarBndr RdrName
-toHsTvBndr (tv,k) = noLoc $ KindedTyVar (mkRdrUnqual tv) k
+toHsTvBndr (tv,k) = noLoc $ KindedTyVar (mkRdrUnqual (mkTyVarOcc tv)) (toKind k)
 
 ifaceExtRdrName :: IfaceExtName -> RdrName
 ifaceExtRdrName (ExtPkg mod occ) = mkOrig mod occ