9ea2e6fc3c69bea07884852fa12f2faa5dae00c3
[ghc-hetmet.git] / ghc / compiler / basicTypes / BasicTypes.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1997
3 %
4 \section[BasicTypes]{Miscellanous types}
5
6 This module defines a miscellaneously collection of very simple
7 types that
8
9 \begin{itemize}
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
13 \end{itemize}
14
15 \begin{code}
16 module BasicTypes(
17         Version, Arity, 
18         Unused, unused,
19         Module, moduleString, pprModule,
20         Fixity(..), FixityDirection(..),
21         NewOrData(..), IfaceFlavour(..), TopLevelFlag(..), RecFlag(..)
22    ) where
23
24 #include "HsVersions.h"
25
26 import Outputable
27 \end{code}
28
29 %************************************************************************
30 %*                                                                      *
31 \subsection[Unused]{Unused}
32 %*                                                                      *
33 %************************************************************************
34
35 Used as a placeholder in types.
36
37 \begin{code}
38 type Unused = Void
39
40 unused :: Unused
41 unused = error "Unused is used!"
42 \end{code}
43
44
45 %************************************************************************
46 %*                                                                      *
47 \subsection[Arity]{Arity}
48 %*                                                                      *
49 %************************************************************************
50
51 \begin{code}
52 type Arity = Int
53 \end{code}
54
55
56 %************************************************************************
57 %*                                                                      *
58 \subsection[Version]{Module and identifier version numbers}
59 %*                                                                      *
60 %************************************************************************
61
62 \begin{code}
63 type Version = Int
64 \end{code}
65
66
67 %************************************************************************
68 %*                                                                      *
69 \subsection[Module]{The name of a module}
70 %*                                                                      *
71 %************************************************************************
72
73 \begin{code}
74 type Module   = FAST_STRING
75
76 moduleString :: Module -> String
77 moduleString mod = _UNPK_ mod
78
79 pprModule :: Module -> SDoc
80 pprModule m = ptext m
81 \end{code}
82
83 %************************************************************************
84 %*                                                                      *
85 \subsection[IfaceFlavour]{IfaceFlavour}
86 %*                                                                      *
87 %************************************************************************
88
89 The IfaceFlavour type is used mainly in an imported Name's Provenance
90 to say whether the name comes from a regular .hi file, or whether it comes
91 from a hand-written .hi-boot file.  This is important, because it has to be 
92 propagated.  Suppose
93
94         C.hs imports B
95         B.hs imports A
96         A.hs imports C {-# SOURCE -#} ( f )
97
98 Then in A.hi we may mention C.f, in an inlining.  When compiling B we *must not* 
99 read C.f's details from C.hi, even if the latter happens to exist from an earlier
100 compilation run.  So we use the name "C!f" in A.hi, and when looking for an interface
101 file with details of C!f we look in C.hi-boot.  The "!" stuff is recorded in the
102 IfaceFlavour in the Name of C.f in A. 
103
104 Not particularly beautiful, but it works.
105
106 \begin{code}
107 data IfaceFlavour = HiFile              -- The interface was read from a standard interface file
108                   | HiBootFile          -- ... or from a handwritten "hi-boot" interface file
109
110 instance Text IfaceFlavour where        -- Just used in debug prints of lex tokens
111   showsPrec n HiFile     s = s
112   showsPrec n HiBootFile s = "!" ++ s
113 \end{code}
114
115
116 %************************************************************************
117 %*                                                                      *
118 \subsection[Fixity]{Fixity info}
119 %*                                                                      *
120 %************************************************************************
121
122 \begin{code}
123 data Fixity = Fixity Int FixityDirection
124 data FixityDirection = InfixL | InfixR | InfixN 
125                      deriving(Eq)
126
127 instance Outputable Fixity where
128     ppr (Fixity prec dir) = hcat [ppr dir, space, int prec]
129
130 instance Outputable FixityDirection where
131     ppr InfixL = ptext SLIT("infixl")
132     ppr InfixR = ptext SLIT("infixr")
133     ppr InfixN = ptext SLIT("infix")
134
135 instance Eq Fixity where                -- Used to determine if two fixities conflict
136   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
137 \end{code}
138
139
140 %************************************************************************
141 %*                                                                      *
142 \subsection[NewType/DataType]{NewType/DataType flag}
143 %*                                                                      *
144 %************************************************************************
145
146 \begin{code}
147 data NewOrData
148   = NewType     -- "newtype Blah ..."
149   | DataType    -- "data Blah ..."
150   deriving( Eq )        -- Needed because Demand derives Eq
151 \end{code}
152
153 The @RecFlag@ tells whether the thing is part of a recursive group or not.
154
155
156 %************************************************************************
157 %*                                                                      *
158 \subsection[Top-level/local]{Top-level/not-top level flag}
159 %*                                                                      *
160 %************************************************************************
161
162 \begin{code}
163 data TopLevelFlag
164   = TopLevel
165   | NotTopLevel
166 \end{code}
167
168
169 %************************************************************************
170 %*                                                                      *
171 \subsection[Top-level/local]{Top-level/not-top level flag}
172 %*                                                                      *
173 %************************************************************************
174
175 \begin{code} 
176 data RecFlag = Recursive 
177              | NonRecursive
178 \end{code}
179
180 %************************************************************************
181 %*                                                                      *
182 \subsection{Strictness indication}
183 %*                                                                      *
184 %************************************************************************
185
186 \begin{code}
187 data StrictnessMark = MarkedStrict
188                     | NotMarkedStrict
189 \end{code}