Commit d9ee9d9d authored by Simon Peyton Jones's avatar Simon Peyton Jones

Merge branch 'master' of http://darcs.haskell.org//ghc

Conflicts:
	compiler/main/HscStats.lhs
parents b857c8ad 4f6a56ea
Simon Marlow <marlowsd@gmail.com>, simonmar, simonmar@microsoft.com, simonm
Ross Paterson <ross@soi.city.ac.uk>, ross
Sven Panne <sven.panne@aedion.de>, panne
Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>, malcolm
Simon Peyton Jones <simonpj@microsoft.com>, simonpj
Don Stewart <dons@galois.com>, dons
Tim Harris <tharris@microsoft.com>, tharris
Lennart Augustsson <lennart@augustsson.net>, lennart.augustsson@credit-suisse.com
Duncan Coutts <duncan@haskell.org>, duncan.coutts@worc.ox.ac.uk, duncan@well-typed.com
Ben Lippmeier <benl@ouroborus.net>, benl@cse.unsw.edu.au, Ben.Lippmeier@anu.edu.au, Ben.Lippmeier.anu.edu.au
Manuel M T Chakravarty <chak@cse.unsw.edu.au>, chak
Jose Pedro Magalhaes <jpm@cs.uu.nl>, jpm@cs.uu.nl
Sigbjorn Finne <sof@galois.com>, sof
Wolfgang Thaller <wolfgang.thaller@gmx.net>, wolfgang
Julian Seward <jseward@acm.org>, sewardj
Ian Lynagh <igloo@earth.li>, igloo
Roman Leshchinskiy <rl@cse.unsw.edu.au>, rl@cse.unsw.edu.au
John Dias <dias@cs.tufts.edu>, dias@eecs.tufts.edu, dias@eecs.harvard.edu
Norman Ramsey <nr@eecs.harvard.edu>, nr@eecs.harvard.edu
Andy Gill <andygill@ku.edu>, andy
Will Partain <partain@dcs.gla.ac.uk>, partain
Don Syme <dsyme@microsoft.com>, dsyme
Pepe Iborra <mnislaih@gmail.com>, pepe
Neil Mitchell <ndmitchell@gmail.com>, Neil Mitchell
Gabriele Keller <keller@cse.unsw.edu.au>, keller
Daan Leijen <daan@microsoft.com>, daan
Audrey Tang <audreyt@audreyt.org>, audreyt@audreyt.org
Hans-Wolfgang Loidl <hwloidl@macs.hw.ac.uk>, hwloidl
Bernie Pope <bjpop@csse.unimelb.edu.au>, bjpop@csse.unimelb.edu.au
#Top-level dirs:
^alex/
^common-rts/
^CONTRIB/
^dll/
^greencard/
^green-card/
^haddock/
^haggis/
^happy/
^hdirect/
^hood/
^hslibs/
^hws/
^hx/
^literate/
^mhms/
^mkworld/
^nofib(/|$)
^lib/
^misc/
^mkworld/
^runtime/
^testsuite(/|$)
# bindists
^ghc-
^bin-manifest-
#Packages:
^libraries/Cabal(/|$)
^libraries/ALUT(/|$)
^libraries/GLUT(/|$)
^libraries/HGL(/|$)
^libraries/HUnit(/|$)
^libraries/HaXml(/|$)
^libraries/Japi(/|$)
^libraries/OpenAL(/|$)
^libraries/OpenGL(/|$)
^libraries/QuickCheck(/|$)
^libraries/Win32(/|$)
^libraries/X11(/|$)
^libraries/array(/|$)
^libraries/arrows(/|$)
^libraries/base(/|$)
^libraries/base3-compat(/|$)
^libraries/binary(/|$)
^libraries/bytestring(/|$)
^libraries/cgi(/|$)
^libraries/concurrent(/|$)
^libraries/containers(/|$)
^libraries/directory(/|$)
^libraries/editline(/|$)
^libraries/fgl(/|$)
^libraries/filepath(/|$)
^libraries/getopt(/|$)
^libraries/ghc-prim(/|$)
^libraries/haskell-src(/|$)
^libraries/haskell98(/|$)
^libraries/hpc(/|$)
^libraries/html(/|$)
^libraries/integer-.*(/|$)
^libraries/old-locale(/|$)
^libraries/old-time(/|$)
^libraries/monads(/|$)
^libraries/mtl(/|$)
^libraries/ndp(/|$)
^libraries/network(/|$)
^libraries/packedstring(/|$)
^libraries/parsec(/|$)
^libraries/parallel(/|$)
^libraries/pretty(/|$)
^libraries/process(/|$)
^libraries/random(/|$)
^libraries/readline(/|$)
^libraries/regex-base(/|$)
^libraries/regex-compat(/|$)
^libraries/regex-posix(/|$)
^libraries/st(/|$)
^libraries/stm(/|$)
^libraries/syb(/|$)
^libraries/template-haskell(/|$)
^libraries/time(/|$)
^libraries/timeout(/|$)
^libraries/unique(/|$)
^libraries/unix(/|$)
^libraries/xhtml(/|$)
^libraries/dph(/|$)
^libraries/utf8-string(/|$)
^libraries/terminfo(/|$)
^libraries/haskeline(/|$)
^libraries/extensible-exceptions(/|$)
# Other library bits that get generated:
^libraries/bootstrapping/
^libraries/stamp/
^libraries/ifBuildable(/|$)
^libraries/installPackage(/|$)
^libraries/index.html
^libraries/doc-index.*\.html
^libraries/haddock-util.js
^libraries/haddock.css
^libraries/haskell_icon.gif
^libraries/minus.gif
^libraries/plus.gif
^libraries/libraries.txt
# It's often useful to have somewhere in the build tree to install to
^inst(/|$)
# Boring file regexps:
\.hi$
\.hi-boot$
\.o-boot$
\.p_o$
\.t_o$
\.debug_o$
\.thr_o$
\.thr_p_o$
\.thr_debug_o$
\.o$
\.a$
\.o\.cmd$
# *.ko files aren't boring by default because they might
# be Korean translations rather than kernel modules.
# \.ko$
\.ko\.cmd$
\.mod\.c$
(^|/)\.tmp_versions($|/)
(^|/)CVS($|/)
(^|/)RCS($|/)
~$
#(^|/)\.[^/]
(^|/)_darcs($|/)
\.bak$
\.BAK$
\.orig$
(^|/)vssver\.scc$
\.swp$
(^|/)MT($|/)
(^|/)\{arch\}($|/)
(^|/).arch-ids($|/)
(^|/),
\.class$
\.prof$
(^|/)\.DS_Store$
(^|/)BitKeeper($|/)
(^|/)ChangeSet($|/)
(^|/)\.svn($|/)
(^|/)\.git($|/)
\.git-ignore$
\.py[co]$
\#
\.cvsignore$
(^|/)Thumbs\.db$
\.depend$
\.depend-.*$
^compiler/primop-
^compiler/cmm/CmmLex.hs$
^compiler/cmm/CmmParse.hs$
^compiler/ghci/LibFFI.hs$
^compiler/ghci/LibFFI_hsc.c$
^compiler/main/Config.hs$
^compiler/main/ParsePkgConf.hs$
^compiler/parser/Parser.y$
^compiler/parser/Parser.hs$
^compiler/parser/Lexer.hs$
^compiler/parser/ParserCore.hs$
^compiler/parser/HaddockLex.hs
^compiler/parser/HaddockParse.hs
^compiler/prelude/primops.txt$
^compiler/stage1($|/)
^compiler/stage2($|/)
^compiler/stage3($|/)
^compiler/utils/Fingerprint.hs$
^compiler/utils/Fingerprint_hsc.c$
^mk/build.mk$
^mk/validate.mk$
^mk/are-validating.mk$
^mk/config.h.in$
^mk/config.h$
^mk/config.mk$
^mk/stamp-h$
^stage3.package.conf$
^inplace-datadir(/|$)
(^|/)autom4te.cache($|/)
^rts/AutoApply.*cmm$
^rts/sm/Evac_thr.c$
^rts/sm/Scav_thr.c$
package.conf.inplace$
package.conf.installed$
(^|/)config.log$
(^|/)config.status$
(^|/)configure$
^ghc.spec$
^docs/users_guide/ug-book.xml$
^docs/man/flags.xml$
^docs/man/flags.xsl$
^docs/man/ghc.1$
^extra-gcc-opts$
# ignore scripts like push-monk
^push-
^pull-
# Common log file names; testlog is made by validate
^testlog
^log
^utils/[a-zA-Z0-9-]+/dist-install(/|$)
^utils/[a-zA-Z0-9-]+/dist-inplace(/|$)
^utils/[a-zA-Z0-9-]+/install-inplace(/|$)
^compiler/Makefile-stage[1-3](/|$)
^compiler/dist-stage[1-3](/|$)
^ghc/dist-stage[1-3](/|$)
^ghc/stage[1-3]-inplace(/|$)
^utils/ext-core/Driver$
^utils/ext-core/PrimEnv.hs$
^utils/genapply/genapply$
^utils/genprimopcode/Lexer.hs$
^utils/genprimopcode/Parser.hs$
^utils/genprimopcode/genprimopcode$
^utils/ghc-pkg/Version.hs$
^utils/ghc-pkg/ghc-pkg-inplace$
^utils/ghc-pkg/ghc-pkg-inplace.bin$
^utils/ghc-pkg/ghc-pkg-inplace.hs$
^utils/ghc-pkg/ghc-pkg.bin$
^utils/hasktags/hasktags$
^utils/hasktags/hasktags-inplace$
^utils/hp2ps/hp2ps$
^utils/hpc/HpcParser.hs$
^utils/hsc2hs(/|$)
^utils/haddock(/|$)
^utils/lndir/lndir$
^utils/mkdependC/mkdependC$
^utils/mkdirhier/mkdirhier$
^utils/prof/cgprof/cgprof$
^utils/prof/ghcprof-inplace$
^utils/pwd/pwd$
^utils/pwd/pwd-inplace$
^utils/runghc/runghc$
^utils/runghc/runghc-inplace$
^utils/runghc/runhaskell$
^utils/runstdtest/runstdtest$
^utils/unlit/unlit$
^driver/ghci/ghc-pkg-inplace$
^driver/ghci/ghci-inplace$
^driver/mangler/ghc-asm$
^driver/mangler/ghc-asm.prl$
^driver/package.conf$
^driver/package.conf.inplace.old$
^driver/split/ghc-split$
^driver/split/ghc-split.prl$
^driver/stamp-pkg-conf-rts$
^includes/DerivedConstants.h$
^includes/GHCConstants.h$
^includes/ghcautoconf.h$
^includes/ghcplatform.h$
^includes/mkDerivedConstantsHdr$
^includes/mkGHCConstants$
^libffi/build($|/)
^libffi/ffi.h$
^libffi/stamp.ffi.static$
......@@ -184,12 +184,11 @@ repTyClD (L loc (TyFamily { tcdFlavour = flavour,
= do { tc1 <- lookupLOcc tc -- See note [Binders and occurrences]
; dec <- addTyClTyVarBinds tvs $ \bndrs ->
do { flav <- repFamilyFlavour flavour
; bndrs1 <- coreList tyVarBndrTyConName bndrs
; case opt_kind of
Nothing -> repFamilyNoKind flav tc1 bndrs1
; case opt_kind of
Nothing -> repFamilyNoKind flav tc1 bndrs
Just (HsBSig ki _)
-> do { ki1 <- repKind ki
; repFamilyKind flav tc1 bndrs1 ki1 }
; repFamilyKind flav tc1 bndrs ki1 }
}
; return $ Just (loc, dec)
}
......@@ -293,19 +292,6 @@ repFamilyFlavour :: FamilyFlavour -> DsM (Core TH.FamFlavour)
repFamilyFlavour TypeFamily = rep2 typeFamName []
repFamilyFlavour DataFamily = rep2 dataFamName []
-- represent associated family declarations
--
repLAssocFamilys :: [LTyClDecl Name] -> DsM [Core TH.DecQ]
repLAssocFamilys = mapM repLAssocFamily
where
repLAssocFamily tydecl@(L _ (TyFamily {}))
= liftM (snd . fromJust) $ repTyFamily tydecl lookupTyVarBinds
repLAssocFamily tydecl
= failWithDs msg
where
msg = ptext (sLit "Illegal associated declaration in class:") <+>
ppr tydecl
-- Represent instance declarations
--
repInstD :: LInstDecl Name -> DsM (SrcSpan, Core TH.DecQ)
......@@ -342,7 +328,7 @@ repFamInstD (FamInstDecl { fid_tycon = tc_name, fid_pats = HsBSig tys tv_names,
= do { tc <- lookupLOcc tc_name -- See note [Binders and occurrences]
; let loc = getLoc tc_name
hs_tvs = [ L loc (UserTyVar n) | n <- tv_names] -- Yuk
; addTyVarBinds hs_tvs $ \ bndrs ->
; addTyClTyVarBinds hs_tvs $ \ bndrs ->
do { tys1 <- repLTys tys
; tys2 <- coreList typeQTyConName tys1
; repTyDefn tc bndrs (Just tys2) tv_names defn } }
......@@ -586,20 +572,13 @@ rep_InlinePrag (InlinePragma { inl_act = activation, inl_rule = match, inl_inlin
-- Types
-------------------------------------------------------
-- We process type variable bindings in two ways, either by generating fresh
-- names or looking up existing names. The difference is crucial for type
-- families, depending on whether they are associated or not.
--
type ProcessTyVarBinds a =
[LHsTyVarBndr Name] -- the binders to be added
-> (Core [TH.TyVarBndr] -> DsM (Core (TH.Q a))) -- action in the ext env
-> DsM (Core (TH.Q a))
addTyVarBinds :: [LHsTyVarBndr Name] -- the binders to be added
-> (Core [TH.TyVarBndr] -> DsM (Core (TH.Q a))) -- action in the ext env
-> DsM (Core (TH.Q a))
-- gensym a list of type variables and enter them into the meta environment;
-- the computations passed as the second argument is executed in that extended
-- meta environment and gets the *new* names on Core-level as an argument
--
addTyVarBinds :: ProcessTyVarBinds a
addTyVarBinds tvs m
= do { freshNames <- mkGenSyms (hsLTyVarNames tvs)
; term <- addBinds freshNames $
......@@ -610,7 +589,10 @@ addTyVarBinds tvs m
where
mk_tv_bndr (tv, (_,v)) = repTyVarBndrWithKind tv (coreVar v)
addTyClTyVarBinds :: ProcessTyVarBinds a
addTyClTyVarBinds :: [LHsTyVarBndr Name]
-> (Core [TH.TyVarBndr] -> DsM (Core (TH.Q a)))
-> DsM (Core (TH.Q a))
-- Used for data/newtype declarations, and family instances,
-- so that the nested type variables work right
-- instance C (T a) where
......@@ -624,12 +606,14 @@ addTyClTyVarBinds tvs m
-- This makes things work for family declarations
; term <- addBinds freshNames $
do { kindedBndrs <- mapM mk_tv_bndr tvs
; m kindedBndrs }
do { kbs1 <- mapM mk_tv_bndr tvs
; kbs2 <- coreList tyVarBndrTyConName kbs1
; m kbs2 }
; wrapGenSyms freshNames term }
where
mk_tv_bndr tv = do { v <- lookupOcc (hsLTyVarName tv); repTyVarBndrWithKind tv v }
mk_tv_bndr tv = do { v <- lookupOcc (hsLTyVarName tv)
; repTyVarBndrWithKind tv v }
-- Produce kinded binder constructors from the Haskell tyvar binders
--
......
......@@ -269,8 +269,9 @@ mkHsBSig :: a -> HsBndrSig a
mkHsBSig x = HsBSig x placeHolderBndrs
-------------
userHsTyVarBndrs :: [Located name] -> [Located (HsTyVarBndr name)]
userHsTyVarBndrs bndrs = [ L loc (UserTyVar v) | L loc v <- bndrs ]
userHsTyVarBndrs :: SrcSpan -> [Located name] -> [Located (HsTyVarBndr name)]
-- Caller sets location
userHsTyVarBndrs loc bndrs = [ L loc (UserTyVar v) | L _ v <- bndrs ]
\end{code}
......
%
% (c) The University of Glasgow 2006
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
\begin{code}
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details
-- |
-- Support for source code annotation feature of GHC. That is the ANN pragma.
--
-- (c) The University of Glasgow 2006
-- (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
--
module Annotations (
-- * Main Annotation data types
Annotation(..),
AnnTarget(..), CoreAnnTarget,
getAnnTargetName_maybe,
-- * AnnEnv for collecting and querying Annotations
AnnEnv,
mkAnnEnv, extendAnnEnvList, plusAnnEnv, emptyAnnEnv, findAnns,
deserializeAnns
) where
-- * Main Annotation data types
Annotation(..),
AnnTarget(..), CoreAnnTarget,
getAnnTargetName_maybe,
-- * AnnEnv for collecting and querying Annotations
AnnEnv,
mkAnnEnv, extendAnnEnvList, plusAnnEnv, emptyAnnEnv, findAnns,
deserializeAnns
) where
import Name
import Module ( Module )
import Name
import Outputable
import UniqFM
import Serialized
import UniqFM
import Unique
import Data.Typeable
import Data.Maybe
import Data.Typeable
import Data.Word ( Word8 )
......@@ -40,14 +33,14 @@ import Data.Word ( Word8 )
data Annotation = Annotation {
ann_target :: CoreAnnTarget, -- ^ The target of the annotation
ann_value :: Serialized -- ^ 'Serialized' version of the annotation that
-- allows recovery of its value or can
-- allows recovery of its value or can
-- be persisted to an interface file
}
-- | An annotation target
data AnnTarget name
= NamedTarget name -- ^ We are annotating something with a name:
-- a type or identifier
-- a type or identifier
| ModuleTarget Module -- ^ We are annotating a particular module
-- | The kind of annotation target found in the middle end of the compiler
......@@ -57,6 +50,7 @@ instance Functor AnnTarget where
fmap f (NamedTarget nm) = NamedTarget (f nm)
fmap _ (ModuleTarget mod) = ModuleTarget mod
-- | Get the 'name' of an annotation target if it exists.
getAnnTargetName_maybe :: AnnTarget name -> Maybe name
getAnnTargetName_maybe (NamedTarget nm) = Just nm
getAnnTargetName_maybe _ = Nothing
......@@ -74,20 +68,25 @@ instance Outputable Annotation where
ppr ann = ppr (ann_target ann)
-- | A collection of annotations
newtype AnnEnv = MkAnnEnv (UniqFM [Serialized])
-- Can't use a type synonym or we hit bug #2412 due to source import
newtype AnnEnv = MkAnnEnv (UniqFM [Serialized])
-- | An empty annotation environment.
emptyAnnEnv :: AnnEnv
emptyAnnEnv = MkAnnEnv emptyUFM
-- | Construct a new annotation environment that contains the list of
-- annotations provided.
mkAnnEnv :: [Annotation] -> AnnEnv
mkAnnEnv = extendAnnEnvList emptyAnnEnv
-- | Add the given annotation to the environment.
extendAnnEnvList :: AnnEnv -> [Annotation] -> AnnEnv
extendAnnEnvList (MkAnnEnv env) anns
= MkAnnEnv $ addListToUFM_C (++) env $
map (\ann -> (getUnique (ann_target ann), [ann_value ann])) anns
-- | Union two annotation environments.
plusAnnEnv :: AnnEnv -> AnnEnv -> AnnEnv
plusAnnEnv (MkAnnEnv env1) (MkAnnEnv env2) = MkAnnEnv $ plusUFM_C (++) env1 env2
......@@ -105,4 +104,4 @@ findAnns deserialize (MkAnnEnv ann_env)
deserializeAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> UniqFM [a]
deserializeAnns deserialize (MkAnnEnv ann_env)
= mapUFM (mapMaybe (fromSerialized deserialize)) ann_env
\end{code}
......@@ -252,6 +252,7 @@ data DynFlag
| Opt_DictsCheap
| Opt_EnableRewriteRules -- Apply rewrite rules during simplification
| Opt_Vectorise
| Opt_AvoidVect
| Opt_RegsGraph -- do graph coloring register allocation
| Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
| Opt_PedanticBottoms -- Be picky about how we treat bottom
......@@ -1865,10 +1866,11 @@ fFlags = [
( "run-cpsz", Opt_RunCPSZ, nop ),
( "new-codegen", Opt_TryNewCodeGen, nop ),
( "vectorise", Opt_Vectorise, nop ),
( "avoid-vect", Opt_AvoidVect, nop ),
( "regs-graph", Opt_RegsGraph, nop ),
( "regs-iterative", Opt_RegsIterative, nop ),
( "llvm-tbaa", Opt_LlvmTBAA, nop),
( "reg-liveness", Opt_RegLiveness, nop),
( "regs-liveness", Opt_RegLiveness, nop),
( "gen-manifest", Opt_GenManifest, nop ),
( "embed-manifest", Opt_EmbedManifest, nop ),
( "ext-core", Opt_EmitExternalCore, nop ),
......
This diff is collapsed.
-- |
-- Statistics for per-module compilations
--
-- (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
--
module HscStats ( ppSourceStats ) where
import Bag
import HsSyn
import Outputable
import RdrName
import SrcLoc
import Util
import Data.Char
-- | Source Statistics
ppSourceStats :: Bool -> Located (HsModule RdrName) -> SDoc
ppSourceStats short (L _ (HsModule _ exports imports ldecls _ _))
= (if short then hcat else vcat)
(map pp_val
[("ExportAll ", export_all), -- 1 if no export list
("ExportDecls ", export_ds),
("ExportModules ", export_ms),
("Imports ", imp_no),
(" ImpSafe ", imp_safe),
(" ImpQual ", imp_qual),
(" ImpAs ", imp_as),
(" ImpAll ", imp_all),
(" ImpPartial ", imp_partial),
(" ImpHiding ", imp_hiding),
("FixityDecls ", fixity_sigs),
("DefaultDecls ", default_ds),
("TypeDecls ", type_ds),
("DataDecls ", data_ds),
("NewTypeDecls ", newt_ds),
("TypeFamilyDecls ", type_fam_ds),
("DataConstrs ", data_constrs),
("DataDerivings ", data_derivs),
("ClassDecls ", class_ds),
("ClassMethods ", class_method_ds),
("DefaultMethods ", default_method_ds),
("InstDecls ", inst_ds),
("InstMethods ", inst_method_ds),
("InstType ", inst_type_ds),
("InstData ", inst_data_ds),
("TypeSigs ", bind_tys),
("GenericSigs ", generic_sigs),
("ValBinds ", val_bind_ds),
("FunBinds ", fn_bind_ds),
("InlineMeths ", method_inlines),
("InlineBinds ", bind_inlines),
("SpecialisedMeths ", method_specs),
("SpecialisedBinds ", bind_specs)
])
where
decls = map unLoc ldecls
pp_val (_, 0) = empty
pp_val (str, n)
| not short = hcat [text str, int n]
| otherwise = hcat [text (trim str), equals, int n, semi]
trim ls = takeWhile (not.isSpace) (dropWhile isSpace ls)
(fixity_sigs, bind_tys, bind_specs, bind_inlines, generic_sigs)
= count_sigs [d | SigD d <- decls]
-- NB: this omits fixity decls on local bindings and
-- in class decls. ToDo
tycl_decls = [d | TyClD d <- decls]
(class_ds, type_ds, data_ds, newt_ds, type_fam_ds) =
countTyClDecls tycl_decls
inst_decls = [d | InstD d <- decls]
inst_ds = length inst_decls
default_ds = count (\ x -> case x of { DefD{} -> True; _ -> False}) decls
val_decls = [d | ValD d <- decls]
real_exports = case exports of { Nothing -> []; Just es -> es }
n_exports = length real_exports
export_ms = count (\ e -> case unLoc e of { IEModuleContents{} -> True;_ -> False})
real_exports
export_ds = n_exports - export_ms
export_all = case exports of { Nothing -> 1; _ -> 0 }
(val_bind_ds, fn_bind_ds)
= foldr add2 (0,0) (map count_bind val_decls)
(imp_no, imp_safe, imp_qual, imp_as, imp_all, imp_partial, imp_hiding)
= foldr add7 (0,0,0,0,0,0,0) (map import_info imports)
(data_constrs, data_derivs)
= foldr add2 (0,0) (map data_info tycl_decls)
(class_method_ds, default_method_ds)
= foldr add2 (0,0) (map class_info tycl_decls)
(inst_method_ds, method_specs, method_inlines, inst_type_ds, inst_data_ds)
= foldr add5 (0,0,0,0,0) (map inst_info inst_decls)
count_bind (PatBind { pat_lhs = L _ (VarPat _) }) = (1,0)
count_bind (PatBind {}) = (0,1)
count_bind (FunBind {}) = (0,1)
count_bind b = pprPanic "count_bind: Unhandled binder" (ppr b)
count_sigs sigs = foldr add5 (0,0,0,0,0) (map sig_info sigs)
sig_info (FixSig _) = (1,0,0,0,0)
sig_info (TypeSig _ _) = (0,1,0,0,0)
sig_info (SpecSig _ _ _) = (0,0,1,0,0)
sig_info (InlineSig _ _) = (0,0,0,1,0)
sig_info (GenericSig _ _) = (0,0,0,0,1)
sig_info _ = (0,0,0,0,0)
import_info (L _ (ImportDecl { ideclSafe = safe, ideclQualified = qual
, ideclAs = as, ideclHiding = spec }))
= add7 (1, safe_info safe, qual_info qual, as_info as, 0,0,0) (spec_info spec)
safe_info = qual_info
qual_info False = 0
qual_info True = 1
as_info Nothing = 0
as_info (Just _) = 1
spec_info Nothing = (0,0,0,0,1,0,0)
spec_info (Just (False, _)) = (0,0,0,0,0,1,0)
spec_info (Just (True, _)) = (0,0,0,0,0,0,1)
data_info (TyData {tcdCons = cs, tcdDerivs = derivs})
= (length cs, case derivs of Nothing -> 0
Just ds -> length ds)
data_info _ = (0,0)
class_info decl@(ClassDecl {})
= case count_sigs (map unLoc (tcdSigs decl)) of
(_,classops,_,_,_) ->
(classops, addpr (foldr add2 (0,0) (map (count_bind.unLoc) (bagToList (tcdMeths decl)))))
class_info _ = (0,0)
inst_info (FamInstDecl d) = case countATDecl d of
(tyd, dtd) -> (0,0,0,tyd,dtd)
inst_info (ClsInstDecl _ inst_meths inst_sigs ats)
= case count_sigs (map unLoc inst_sigs) of
(_,_,ss,is,_) ->
case foldr add2 (0, 0) (map (countATDecl . unLoc) ats) of
(tyDecl, dtDecl) ->
(addpr (foldr add2 (0,0)
(map (count_bind.unLoc) (bagToList inst_meths))),
ss, is, tyDecl, dtDecl)
where
countATDecl (TyData {}) = (0, 1)
countATDecl (TySynonym {}) = (1, 0)
countATDecl d = pprPanic "countATDecl: Unhandled decl"
(ppr d)
addpr :: (Int,Int) -> Int
add2 :: (Int,Int) -> (Int,Int) -> (Int, Int)
add5 :: (Int,Int,Int,Int,Int) -> (Int,Int,Int,Int,Int) -> (Int, Int, Int, Int, Int)
add7 :: (Int,Int,Int,Int,Int,Int,Int) -> (Int,Int,Int,Int,Int,Int,Int) -> (Int, Int, Int, Int, Int, Int, Int)
addpr (x,y) = x+y
add2 (x1,x2) (y1,y2) = (x1+y1,x2+y2)
add5 (x1,x2,x3,x4,x5) (y1,y2,y3,y4,y5) = (x1+y1,x2+y2,x3+y3,x4+y4,x5+y5)
add7 (x1,x2,x3,x4,x5,x6,x7) (y1,y2,y3,y4,y5,y6,y7) = (x1+y1,x2+y2,x3+y3,x4+y4,x5+y5,x6+y6,x7+y7)
-- |
-- Package configuration information: essentially the interface to Cabal, with
-- some utilities
--
-- (c) The University of Glasgow, 2004
--
module PackageConfig (
-- $package_naming
-- | Package configuration information: essentially the interface to Cabal, with some utilities
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details
-- * PackageId
mkPackageId, packageConfigId,
module PackageConfig (
-- $package_naming
-- * PackageId
mkPackageId, packageConfigId,