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 | EnumType -- Enumeration; all constructors are nullary
125 deriving( Eq ) -- Needed because Demand derives Eq
128 %************************************************************************
130 \subsection[Top-level/local]{Top-level/not-top level flag}
132 %************************************************************************
139 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
141 isNotTopLevel NotTopLevel = True
142 isNotTopLevel TopLevel = False
144 isTopLevel TopLevel = True
145 isTopLevel NotTopLevel = False
148 %************************************************************************
150 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
152 %************************************************************************
155 data RecFlag = Recursive
158 isRec :: RecFlag -> Bool
159 isRec Recursive = True
160 isRec NonRecursive = False
162 isNonRec :: RecFlag -> Bool
163 isNonRec Recursive = False
164 isNonRec NonRecursive = True
168 %************************************************************************
170 \subsection{Occurrence information}
172 %************************************************************************
174 This data type is used exclusively by the simplifier, but it appears in a
175 SubstResult, which is currently defined in VarEnv, which is pretty near
176 the base of the module hierarchy. So it seemed simpler to put the
177 defn of OccInfo here, safely at the bottom
183 | IAmDead -- Marks unused variables. Sometimes useful for
184 -- lambda and case-bound variables.
190 | IAmALoopBreaker -- Used by the occurrence analyser to mark loop-breakers
191 -- in a group of recursive definitions
193 seqOccInfo :: OccInfo -> ()
194 seqOccInfo (OneOcc in_lam once) = in_lam `seq` once `seq` ()
197 type InsideLam = Bool -- True <=> Occurs inside a non-linear lambda
198 -- Substituting a redex for this occurrence is
199 -- dangerous because it might duplicate work.
203 type OneBranch = Bool -- True <=> Occurs in only one case branch
204 -- so no code-duplication issue to worry about
208 isFragileOccInfo :: OccInfo -> Bool
209 isFragileOccInfo (OneOcc _ _) = True
210 isFragileOccInfo other = False
214 instance Outputable OccInfo where
215 -- only used for debugging; never parsed. KSW 1999-07
216 ppr NoOccInfo = empty
217 ppr IAmALoopBreaker = ptext SLIT("_Kx")
218 ppr IAmDead = ptext SLIT("_Kd")
219 ppr (OneOcc inside_lam one_branch) | inside_lam = ptext SLIT("_Kl")
220 | one_branch = ptext SLIT("_Ks")
221 | otherwise = ptext SLIT("_Ks*")
223 instance Show OccInfo where
224 showsPrec p occ = showsPrecSDoc p (ppr occ)