import RdrHsSyn ( mkHsOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat )
import RdrName ( RdrName, mkUnqual )
import BasicTypes ( RecFlag(..), Fixity(..), FixityDirection(..)
- , maxPrecedence
+ , maxPrecedence, defaultFixity
, Boxity(..)
)
import FieldLabel ( fieldLabelName )
Name, NamedThing(..),
isDataSymOcc, isSymOcc
)
-import HscTypes ( GlobalSymbolTable, lookupFixityEnv )
import PrelInfo -- Lots of RdrNames
import SrcLoc ( generatedSrcLoc, SrcLoc )
import Util ( mapAccumL, zipEqual, zipWithEqual,
zipWith3Equal, nOfThem )
import Panic ( panic, assertPanic )
-import Maybes ( maybeToBool )
+import Maybes ( maybeToBool, orElse )
import Constants
import List ( partition, intersperse )
-import Outputable ( pprPanic, ppr )
+import Outputable ( pprPanic, ppr, pprTrace )
#if __GLASGOW_HASKELL__ >= 404
import GlaExts ( fromInt )
%************************************************************************
\begin{code}
-gen_Read_binds :: GlobalSymbolTable -> TyCon -> RdrNameMonoBinds
+gen_Read_binds :: (Name -> Maybe Fixity) -> TyCon -> RdrNameMonoBinds
-gen_Read_binds gst tycon
+gen_Read_binds get_fixity tycon
= reads_prec `AndMonoBinds` read_list
where
tycon_loc = getSrcLoc tycon
then d_Expr
else HsVar (last bs_needed)] Boxed
- [lp,rp] = getLRPrecs is_infix gst dc_nm
+ [lp,rp] = getLRPrecs is_infix get_fixity dc_nm
quals
| is_infix = let (h:t) = field_quals in (h:con_qual:t)
c.f. Figure 18 in Haskell 1.1 report.
-}
paren_prec_limit
- | not is_infix = fromInt maxPrecedence
- | otherwise = getFixity gst dc_nm
+ | not is_infix = defaultPrecedence
+ | otherwise = getPrecedence get_fixity dc_nm
read_paren_arg -- parens depend on precedence...
| nullary_con = false_Expr -- it's optional.
%************************************************************************
\begin{code}
-gen_Show_binds :: GlobalSymbolTable -> TyCon -> RdrNameMonoBinds
+gen_Show_binds :: (Name -> Maybe Fixity) -> TyCon -> RdrNameMonoBinds
-gen_Show_binds gst tycon
+gen_Show_binds get_fixity tycon
= shows_prec `AndMonoBinds` show_list
where
tycon_loc = getSrcLoc tycon
mk_showString_app str = HsApp (HsVar showString_RDR)
(HsLit (mkHsString str))
- prec_cons = getLRPrecs is_infix gst dc_nm
+ prec_cons = getLRPrecs is_infix get_fixity dc_nm
real_show_thingies
| is_infix =
c.f. Figure 16 and 17 in Haskell 1.1 report
-}
paren_prec_limit
- | not is_infix = fromInt maxPrecedence + 1
- | otherwise = getFixity gst dc_nm + 1
+ | not is_infix = defaultPrecedence + 1
+ | otherwise = getPrecedence get_fixity dc_nm + 1
\end{code}
\begin{code}
-getLRPrecs :: Bool -> GlobalSymbolTable -> Name -> [Integer]
-getLRPrecs is_infix gst nm = [lp, rp]
+getLRPrecs :: Bool -> (Name -> Maybe Fixity) -> Name -> [Integer]
+getLRPrecs is_infix get_fixity nm = [lp, rp]
where
{-
Figuring out the fixities of the arguments to a constructor,
cf. Figures 16-18 in Haskell 1.1 report.
-}
- (con_left_assoc, con_right_assoc) = isLRAssoc gst nm
- paren_con_prec = getFixity gst nm
- maxPrec = fromInt maxPrecedence
+ (con_left_assoc, con_right_assoc) = isLRAssoc get_fixity nm
+ paren_con_prec = getPrecedence get_fixity nm
lp
- | not is_infix = maxPrec + 1
+ | not is_infix = defaultPrecedence + 1
| con_left_assoc = paren_con_prec
| otherwise = paren_con_prec + 1
rp
- | not is_infix = maxPrec + 1
+ | not is_infix = defaultPrecedence + 1
| con_right_assoc = paren_con_prec
| otherwise = paren_con_prec + 1
-getFixity :: GlobalSymbolTable -> Name -> Integer
-getFixity gst nm
- = case lookupFixityEnv gst nm of
+defaultPrecedence :: Integer
+defaultPrecedence = fromInt maxPrecedence
+
+getPrecedence :: (Name -> Maybe Fixity) -> Name -> Integer
+getPrecedence get_fixity nm
+ = case get_fixity nm of
Just (Fixity x _) -> fromInt x
- other -> pprPanic "TcGenDeriv.getFixity" (ppr nm)
-
-isLRAssoc :: GlobalSymbolTable -> Name -> (Bool, Bool)
-isLRAssoc fixs_assoc nm =
- case lookupFixityEnv fixs_assoc nm of
- Just (Fixity _ InfixN) -> (False, False)
- Just (Fixity _ InfixR) -> (False, True)
- Just (Fixity _ InfixL) -> (True, False)
- other -> pprPanic "TcGenDeriv.isLRAssoc" (ppr nm)
+ other -> defaultPrecedence
+
+isLRAssoc :: (Name -> Maybe Fixity) -> Name -> (Bool, Bool)
+isLRAssoc get_fixity nm =
+ case get_fixity nm `orElse` defaultFixity of
+ Fixity _ InfixN -> (False, False)
+ Fixity _ InfixR -> (False, True)
+ Fixity _ InfixL -> (True, False)
isInfixOccName :: String -> Bool
isInfixOccName str =