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
23 Fixity(..), FixityDirection(..),
24 defaultFixity, maxPrecedence, negateFixity, negatePrecedence,
28 RecFlag(..), isRec, isNonRec,
30 TopLevelFlag(..), isTopLevel, isNotTopLevel,
32 OccInfo(..), seqOccInfo, isFragileOccInfo,
33 InsideLam, insideLam, notInsideLam,
34 OneBranch, oneBranch, notOneBranch
38 #include "HsVersions.h"
43 %************************************************************************
45 \subsection[Unused]{Unused}
47 %************************************************************************
49 Used as a placeholder in types.
55 unused = error "Unused is used!"
59 %************************************************************************
61 \subsection[Arity]{Arity}
63 %************************************************************************
70 %************************************************************************
72 \subsection[Version]{Module and identifier version numbers}
74 %************************************************************************
81 %************************************************************************
83 \subsection[Fixity]{Fixity info}
85 %************************************************************************
88 data Fixity = Fixity Int FixityDirection
89 data FixityDirection = InfixL | InfixR | InfixN
92 instance Outputable Fixity where
93 ppr (Fixity prec dir) = hcat [ppr dir, space, int prec]
95 instance Outputable FixityDirection where
96 ppr InfixL = ptext SLIT("infixl")
97 ppr InfixR = ptext SLIT("infixr")
98 ppr InfixN = ptext SLIT("infix")
100 instance Eq Fixity where -- Used to determine if two fixities conflict
101 (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
103 maxPrecedence = (9::Int)
104 defaultFixity = Fixity maxPrecedence InfixL
106 negateFixity :: Fixity
107 negateFixity = Fixity negatePrecedence InfixL -- Precedence of unary negate is wired in as infixl 6!
109 negatePrecedence :: Int
114 %************************************************************************
116 \subsection[NewType/DataType]{NewType/DataType flag}
118 %************************************************************************
122 = NewType -- "newtype Blah ..."
123 | DataType -- "data Blah ..."
124 deriving( Eq ) -- Needed because Demand derives Eq
127 %************************************************************************
129 \subsection[Top-level/local]{Top-level/not-top level flag}
131 %************************************************************************
138 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
140 isNotTopLevel NotTopLevel = True
141 isNotTopLevel TopLevel = False
143 isTopLevel TopLevel = True
144 isTopLevel NotTopLevel = False
147 %************************************************************************
149 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
151 %************************************************************************
154 data RecFlag = Recursive
157 isRec :: RecFlag -> Bool
158 isRec Recursive = True
159 isRec NonRecursive = False
161 isNonRec :: RecFlag -> Bool
162 isNonRec Recursive = False
163 isNonRec NonRecursive = True
167 %************************************************************************
169 \subsection{Occurrence information}
171 %************************************************************************
173 This data type is used exclusively by the simplifier, but it appears in a
174 SubstResult, which is currently defined in VarEnv, which is pretty near
175 the base of the module hierarchy. So it seemed simpler to put the
176 defn of OccInfo here, safely at the bottom
182 | IAmDead -- Marks unused variables. Sometimes useful for
183 -- lambda and case-bound variables.
189 | IAmALoopBreaker -- Used by the occurrence analyser to mark loop-breakers
190 -- in a group of recursive definitions
192 seqOccInfo :: OccInfo -> ()
193 seqOccInfo (OneOcc in_lam once) = in_lam `seq` once `seq` ()
196 type InsideLam = Bool -- True <=> Occurs inside a non-linear lambda
197 -- Substituting a redex for this occurrence is
198 -- dangerous because it might duplicate work.
202 type OneBranch = Bool -- True <=> Occurs in only one case branch
203 -- so no code-duplication issue to worry about
207 isFragileOccInfo :: OccInfo -> Bool
208 isFragileOccInfo (OneOcc _ _) = True
209 isFragileOccInfo other = False
213 instance Outputable OccInfo where
214 -- only used for debugging; never parsed. KSW 1999-07
215 ppr NoOccInfo = empty
216 ppr IAmALoopBreaker = ptext SLIT("_Kx")
217 ppr IAmDead = ptext SLIT("_Kd")
218 ppr (OneOcc inside_lam one_branch) | inside_lam = ptext SLIT("_Kl")
219 | one_branch = ptext SLIT("_Ks")
220 | otherwise = ptext SLIT("_Ks*")
222 instance Show OccInfo where
223 showsPrec p occ = showsPrecSDoc p (ppr occ)