import BasicTypes
import Type
import SrcLoc
+import PrelNames
import FastString
+import Outputable
#include "../HsVersions.h"
vdef :: { RdrNameCoreDecl }
: qname '::' ty '=' exp { CoreDecl $1 $3 $5 noSrcLoc }
+ -- NB: qname includes data constructors, because
+ -- we allow data-constructor wrappers at top level
vbind :: { (RdrName, RdrNameHsType) }
| con ';' cons1 { $1:$3 }
con :: { ConDecl RdrName }
- : q_d_name attbinds atys
+ : q_d_patt attbinds atys
{ ConDecl $1 $2 [] (PrefixCon (map unbangedType $3)) noSrcLoc}
atys :: { [ RdrNameHsType] }
aexp :: { UfExpr RdrName }
: qname { UfVar $1 }
- | q_d_name { UfVar $1 }
| lit { UfLit $1 }
| '(' exp ')' { $2 }
| alt ';' alts1 { $1:$3 }
alt :: { UfAlt RdrName }
- : q_d_name attbinds vbinds '->' exp
- { {- ToDo: sort out-} (UfDataAlt $1, (map hsTyVarName $2 ++ map fst $3), $5) }
+ : q_d_patt attbinds vbinds '->' exp
+ { (UfDataAlt $1, (map hsTyVarName $2 ++ map fst $3), $5) }
| lit '->' exp
{ (UfLitAlt $1, [], $3) }
| '%_' '->' exp
{ (UfDefault, [], $3) }
lit :: { Literal }
- : '(' INTEGER '::' aty ')' { MachInt $2 }
- | '(' RATIONAL '::' aty ')' { MachDouble $2 }
+ : '(' INTEGER '::' aty ')' { convIntLit $2 $4 }
+ | '(' RATIONAL '::' aty ')' { convRatLit $2 $4 }
| '(' CHAR '::' aty ')' { MachChar (fromEnum $2) }
| '(' STRING '::' aty ')' { MachStr (mkFastString $2) }
modid :: { ModuleName }
: CNAME { mkSysModuleNameFS (mkFastString $1) }
-qname :: { RdrName }
- : name { $1 }
- | mname '.' NAME
- { mkIfaceOrig varName (mkFastString $1,mkFastString $3) }
+qname :: { RdrName } -- Includes data constructors
+ : name { $1 }
+ | mname '.' NAME { mkIfaceOrig varName (mkFastString $1) (mkFastString $3) }
+ | q_d_occ { $1 }
+
-- Type constructor
q_tc_name :: { RdrName }
: mname '.' cname
- { mkIfaceOrig tcName (mkFastString $1,mkFastString $3) }
+ { mkIfaceOrig tcName (mkFastString $1) (mkFastString $3) }
+
+-- Data constructor in a pattern or data type declaration; use the dataName,
+-- because that's what we expect in Core case patterns
+q_d_patt :: { RdrName }
+ : mname '.' cname
+ { mkIfaceOrig dataName (mkFastString $1) (mkFastString $3) }
--- Data constructor
-q_d_name :: { RdrName }
+-- Data constructor occurrence in an expression;
+-- use the varName because that's the worker Id
+q_d_occ :: { RdrName }
: mname '.' cname
- { mkIfaceOrig dataName (mkFastString $1,mkFastString $3) }
+ { mkIfaceOrig varName (mkFastString $1) (mkFastString $3) }
{
convBind :: RdrNameCoreDecl -> (UfBinder RdrName, UfExpr RdrName)
convBind (CoreDecl n ty rhs _) = (UfValBinder n ty, rhs)
+convIntLit :: Integer -> RdrNameHsType -> Literal
+convIntLit i (HsTyVar n)
+ | n == intPrimRdrName = MachInt i
+ | n == wordPrimRdrName = MachWord i
+convIntLit i aty
+ = pprPanic "Unknown integer literal type" (ppr aty $$ ppr intPrimRdrName)
+
+convRatLit :: Rational -> RdrNameHsType -> Literal
+convRatLit r (HsTyVar n)
+ | n == floatPrimRdrName = MachFloat r
+ | n == doublePrimRdrName = MachDouble r
+convRatLit i aty
+ = pprPanic "Unknown rational literal type" (ppr aty $$ ppr intPrimRdrName)
+
+
+wordPrimRdrName, intPrimRdrName, floatPrimRdrName, doublePrimRdrName :: RdrName
+wordPrimRdrName = nameRdrName wordPrimTyConName
+intPrimRdrName = nameRdrName intPrimTyConName
+floatPrimRdrName = nameRdrName floatPrimTyConName
+doublePrimRdrName = nameRdrName doublePrimTyConName
+
happyError :: P a
happyError s l = failP (show l ++ ": Parse error\n") (take 100 s) l
}