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