X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FhsSyn%2FHsExpr.lhs;h=245631d789680d8cf873d97b567f66db29e32afe;hb=2fc5aa708982a414235d3aff68dea4329b546063;hp=bde737a25387a3deef726f30de0025a1a0f88918;hpb=b4556cace1b420341c3e3bc6c1d7a7f693c655e4;p=ghc-hetmet.git diff --git a/compiler/hsSyn/HsExpr.lhs b/compiler/hsSyn/HsExpr.lhs index bde737a..245631d 100644 --- a/compiler/hsSyn/HsExpr.lhs +++ b/compiler/hsSyn/HsExpr.lhs @@ -3,6 +3,7 @@ % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % \begin{code} +{-# LANGUAGE DeriveDataTypeable #-} -- | Abstract Haskell syntax for expressions. module HsExpr where @@ -24,6 +25,9 @@ import DataCon import SrcLoc import Outputable import FastString + +-- libraries: +import Data.Data hiding (Fixity) \end{code} @@ -44,7 +48,7 @@ type LHsExpr id = Located (HsExpr id) type PostTcExpr = HsExpr Id -- | We use a PostTcTable where there are a bunch of pieces of evidence, more -- than is convenient to keep individually. -type PostTcTable = [(Name, Id)] +type PostTcTable = [(Name, PostTcExpr)] noPostTcExpr :: PostTcExpr noPostTcExpr = HsLit (HsString (fsLit "noPostTcExpr")) @@ -58,7 +62,7 @@ noPostTcTable = [] -- -- E.g. @(>>=)@ is filled in before the renamer by the appropriate 'Name' for -- @(>>=)@, and then instantiated by the type checker with its type args --- tec +-- etc type SyntaxExpr id = HsExpr id @@ -275,6 +279,7 @@ data HsExpr id | HsWrap HsWrapper -- TRANSLATION (HsExpr id) + deriving (Data, Typeable) -- HsTupArg is used for tuple sections -- (,a,) is represented by ExplicitTuple [Mising ty1, Present a, Missing ty3] @@ -282,6 +287,7 @@ data HsExpr id data HsTupArg id = Present (LHsExpr id) -- The argument | Missing PostTcType -- The argument is missing, but this is its type + deriving (Data, Typeable) tupArgPresent :: HsTupArg id -> Bool tupArgPresent (Present {}) = True @@ -587,6 +593,7 @@ type HsCmd id = HsExpr id type LHsCmd id = LHsExpr id data HsArrAppType = HsHigherOrderApp | HsFirstOrderApp + deriving (Data, Typeable) \end{code} The legal constructors for commands are: @@ -640,6 +647,7 @@ data HsCmdTop id PostTcType -- return type of the command (SyntaxTable id) -- after type checking: -- names used in the command's desugaring + deriving (Data, Typeable) \end{code} %************************************************************************ @@ -681,6 +689,7 @@ data MatchGroup id PostTcType -- The type is the type of the entire group -- t1 -> ... -> tn -> tr -- where there are n patterns + deriving (Data, Typeable) type LMatch id = Located (Match id) @@ -690,6 +699,7 @@ data Match id (Maybe (LHsType id)) -- A type signature for the result of the match -- Nothing after typechecking (GRHSs id) + deriving (Data, Typeable) isEmptyMatchGroup :: MatchGroup id -> Bool isEmptyMatchGroup (MatchGroup ms _) = null ms @@ -712,13 +722,14 @@ data GRHSs id = GRHSs { grhssGRHSs :: [LGRHS id], -- ^ Guarded RHSs grhssLocalBinds :: (HsLocalBinds id) -- ^ The where clause - } + } deriving (Data, Typeable) type LGRHS id = Located (GRHS id) -- | Guarded Right Hand Side. data GRHS id = GRHS [LStmt id] -- Guards (LHsExpr id) -- Right hand side + deriving (Data, Typeable) \end{code} We know the list must have at least one @Match@ in it. @@ -884,9 +895,10 @@ data StmtLR idL idR -- the returned thing has to be *monomorphic*, -- so they may be type applications - , recS_dicts :: DictBinds idR -- Method bindings of Ids bound by the - -- RecStmt, and used afterwards + , recS_dicts :: TcEvBinds -- Method bindings of Ids bound by the + -- RecStmt, and used afterwards } + deriving (Data, Typeable) \end{code} Note [GroupStmt binder map] @@ -1047,14 +1059,23 @@ pprComp quals body -- Prints: body | qual1, ..., qualn data HsSplice id = HsSplice -- $z or $(f 4) id -- The id is just a unique name to (LHsExpr id) -- identify this splice point + deriving (Data, Typeable) instance OutputableBndr id => Outputable (HsSplice id) where ppr = pprSplice pprSplice :: OutputableBndr id => HsSplice id -> SDoc pprSplice (HsSplice n e) - = char '$' <> ifPprDebug (brackets (ppr n)) <> pprParendExpr e - + = char '$' <> ifPprDebug (brackets (ppr n)) <> eDoc + where + -- We use pprLExpr to match pprParendExpr: + -- Using pprLExpr makes sure that we go 'deeper' + -- I think that is usually (always?) right + pp_as_was = pprLExpr e + eDoc = case unLoc e of + HsPar _ -> pp_as_was + HsVar _ -> pp_as_was + _ -> parens pp_as_was data HsBracket id = ExpBr (LHsExpr id) -- [| expr |] | PatBr (LPat id) -- [p| pat |] @@ -1062,6 +1083,7 @@ data HsBracket id = ExpBr (LHsExpr id) -- [| expr |] | DecBrG (HsGroup id) -- [d| decls |]; result of renamer | TypBr (LHsType id) -- [t| type |] | VarBr id -- 'x, ''T + deriving (Data, Typeable) instance OutputableBndr id => Outputable (HsBracket id) where ppr = pprHsBracket @@ -1100,6 +1122,7 @@ data ArithSeqInfo id | FromThenTo (LHsExpr id) (LHsExpr id) (LHsExpr id) + deriving (Data, Typeable) \end{code} \begin{code} @@ -1124,8 +1147,8 @@ pp_dotdot = ptext (sLit " .. ") \begin{code} data HsMatchContext id -- Context of a Match = FunRhs id Bool -- Function binding for f; True <=> written infix - | CaseAlt -- Patterns and guards on a case alternative | LambdaExpr -- Patterns of a lambda + | CaseAlt -- Patterns and guards on a case alternative | ProcExpr -- Patterns of a proc | PatBindRhs -- Patterns in the *guards* of a pattern binding | RecUpd -- Record update [used only in DsExpr to @@ -1133,7 +1156,7 @@ data HsMatchContext id -- Context of a Match -- runtime error message to generate] | StmtCtxt (HsStmtContext id) -- Pattern of a do-stmt or list comprehension | ThPatQuote -- A Template Haskell pattern quotation [p| (a,b) |] - deriving () + deriving (Data, Typeable) data HsStmtContext id = ListComp @@ -1146,6 +1169,7 @@ data HsStmtContext id | PatGuard (HsMatchContext id) -- Pattern guard for specified thing | ParStmtCtxt (HsStmtContext id) -- A branch of a parallel stmt | TransformStmtCtxt (HsStmtContext id) -- A branch of a transform stmt + deriving (Data, Typeable) \end{code} \begin{code} @@ -1174,16 +1198,25 @@ matchSeparator ThPatQuote = panic "unused" \begin{code} pprMatchContext :: Outputable id => HsMatchContext id -> SDoc -pprMatchContext (FunRhs fun _) = ptext (sLit "the definition of") - <+> quotes (ppr fun) -pprMatchContext CaseAlt = ptext (sLit "a case alternative") -pprMatchContext RecUpd = ptext (sLit "a record-update construct") -pprMatchContext ThPatQuote = ptext (sLit "a Template Haskell pattern quotation") -pprMatchContext PatBindRhs = ptext (sLit "a pattern binding") -pprMatchContext LambdaExpr = ptext (sLit "a lambda abstraction") -pprMatchContext ProcExpr = ptext (sLit "an arrow abstraction") -pprMatchContext (StmtCtxt ctxt) = ptext (sLit "a pattern binding in") - $$ pprStmtContext ctxt +pprMatchContext ctxt + | want_an ctxt = ptext (sLit "an") <+> pprMatchContextNoun ctxt + | otherwise = ptext (sLit "a") <+> pprMatchContextNoun ctxt + where + want_an (FunRhs {}) = True -- Use "an" in front + want_an ProcExpr = True + want_an _ = False + +pprMatchContextNoun :: Outputable id => HsMatchContext id -> SDoc +pprMatchContextNoun (FunRhs fun _) = ptext (sLit "equation for") + <+> quotes (ppr fun) +pprMatchContextNoun CaseAlt = ptext (sLit "case alternative") +pprMatchContextNoun RecUpd = ptext (sLit "record-update construct") +pprMatchContextNoun ThPatQuote = ptext (sLit "Template Haskell pattern quotation") +pprMatchContextNoun PatBindRhs = ptext (sLit "pattern binding") +pprMatchContextNoun LambdaExpr = ptext (sLit "lambda abstraction") +pprMatchContextNoun ProcExpr = ptext (sLit "arrow abstraction") +pprMatchContextNoun (StmtCtxt ctxt) = ptext (sLit "pattern binding in") + $$ pprStmtContext ctxt pprStmtContext :: Outputable id => HsStmtContext id -> SDoc pprStmtContext (ParStmtCtxt c)