2 % (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
4 \section[BasicTypes]{Miscellanous types}
6 This module defines a miscellaneously collection of very simple
10 \item have no other obvious home
11 \item don't depend on any other complicated types
12 \item are used in more than one "part" of the compiler
17 Version, bumpVersion, initialVersion, bogusVersion,
23 Fixity(..), FixityDirection(..),
24 defaultFixity, maxPrecedence, negateFixity, negatePrecedence,
28 RecFlag(..), isRec, isNonRec,
30 TopLevelFlag(..), isTopLevel, isNotTopLevel,
32 Boxity(..), isBoxed, tupleParens,
34 OccInfo(..), seqOccInfo, isFragileOccInfo, isLoopBreaker,
36 InsideLam, insideLam, notInsideLam,
37 OneBranch, oneBranch, notOneBranch
41 #include "HsVersions.h"
46 %************************************************************************
48 \subsection[Unused]{Unused}
50 %************************************************************************
52 Used as a placeholder in types.
58 unused = error "Unused is used!"
62 %************************************************************************
64 \subsection[Arity]{Arity}
66 %************************************************************************
73 %************************************************************************
75 \subsection[Version]{Module and identifier version numbers}
77 %************************************************************************
82 bogusVersion :: Version -- Shouldn't look at these
83 bogusVersion = error "bogusVersion"
85 bumpVersion :: Version -> Version
88 initialVersion :: Version
93 %************************************************************************
95 \subsection[Fixity]{Fixity info}
97 %************************************************************************
100 data Fixity = Fixity Int FixityDirection
101 data FixityDirection = InfixL | InfixR | InfixN
104 instance Outputable Fixity where
105 ppr (Fixity prec dir) = hcat [ppr dir, space, int prec]
107 instance Outputable FixityDirection where
108 ppr InfixL = ptext SLIT("infixl")
109 ppr InfixR = ptext SLIT("infixr")
110 ppr InfixN = ptext SLIT("infix")
112 instance Eq Fixity where -- Used to determine if two fixities conflict
113 (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
115 maxPrecedence = (9::Int)
116 defaultFixity = Fixity maxPrecedence InfixL
118 negateFixity :: Fixity
119 negateFixity = Fixity negatePrecedence InfixL -- Precedence of unary negate is wired in as infixl 6!
121 negatePrecedence :: Int
126 %************************************************************************
128 \subsection[NewType/DataType]{NewType/DataType flag}
130 %************************************************************************
134 = NewType -- "newtype Blah ..."
135 | DataType -- "data Blah ..."
136 deriving( Eq ) -- Needed because Demand derives Eq
139 %************************************************************************
141 \subsection[Top-level/local]{Top-level/not-top level flag}
143 %************************************************************************
150 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
152 isNotTopLevel NotTopLevel = True
153 isNotTopLevel TopLevel = False
155 isTopLevel TopLevel = True
156 isTopLevel NotTopLevel = False
159 %************************************************************************
161 \subsection[Top-level/local]{Top-level/not-top level flag}
163 %************************************************************************
171 isBoxed :: Boxity -> Bool
173 isBoxed Unboxed = False
175 tupleParens :: Boxity -> SDoc -> SDoc
176 tupleParens Boxed p = parens p
177 tupleParens Unboxed p = ptext SLIT("(#") <+> p <+> ptext SLIT("#)")
181 %************************************************************************
183 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
185 %************************************************************************
188 data RecFlag = Recursive
191 isRec :: RecFlag -> Bool
192 isRec Recursive = True
193 isRec NonRecursive = False
195 isNonRec :: RecFlag -> Bool
196 isNonRec Recursive = False
197 isNonRec NonRecursive = True
201 %************************************************************************
203 \subsection{Occurrence information}
205 %************************************************************************
207 This data type is used exclusively by the simplifier, but it appears in a
208 SubstResult, which is currently defined in VarEnv, which is pretty near
209 the base of the module hierarchy. So it seemed simpler to put the
210 defn of OccInfo here, safely at the bottom
216 | IAmDead -- Marks unused variables. Sometimes useful for
217 -- lambda and case-bound variables.
223 | IAmALoopBreaker -- Used by the occurrence analyser to mark loop-breakers
224 -- in a group of recursive definitions
226 seqOccInfo :: OccInfo -> ()
227 seqOccInfo (OneOcc in_lam once) = in_lam `seq` once `seq` ()
230 type InsideLam = Bool -- True <=> Occurs inside a non-linear lambda
231 -- Substituting a redex for this occurrence is
232 -- dangerous because it might duplicate work.
236 type OneBranch = Bool -- True <=> Occurs in only one case branch
237 -- so no code-duplication issue to worry about
241 isLoopBreaker :: OccInfo -> Bool
242 isLoopBreaker IAmALoopBreaker = True
243 isLoopBreaker other = False
245 isFragileOccInfo :: OccInfo -> Bool
246 isFragileOccInfo (OneOcc _ _) = True
247 isFragileOccInfo other = False
251 instance Outputable OccInfo where
252 -- only used for debugging; never parsed. KSW 1999-07
253 ppr NoOccInfo = empty
254 ppr IAmALoopBreaker = ptext SLIT("_Kx")
255 ppr IAmDead = ptext SLIT("_Kd")
256 ppr (OneOcc inside_lam one_branch) | inside_lam = ptext SLIT("_Kl")
257 | one_branch = ptext SLIT("_Ks")
258 | otherwise = ptext SLIT("_Ks*")
260 instance Show OccInfo where
261 showsPrec p occ = showsPrecSDoc p (ppr occ)