[project @ 1997-07-05 03:02:04 by sof]
[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 #include "HsVersions.h"
17
18 module BasicTypes(
19         SYN_IE(Version), SYN_IE(Arity),
20         SYN_IE(Module), moduleString, pprModule,
21         Fixity(..), FixityDirection(..),
22         NewOrData(..), IfaceFlavour(..)
23    ) where
24
25 IMP_Ubiq()
26
27 import Pretty
28 import Outputable
29
30 \end{code}
31
32 %************************************************************************
33 %*                                                                      *
34 \subsection[Arity]{Arity}
35 %*                                                                      *
36 %************************************************************************
37
38 \begin{code}
39 type Arity = Int
40 \end{code}
41
42
43 %************************************************************************
44 %*                                                                      *
45 \subsection[Version]{Module and identifier version numbers}
46 %*                                                                      *
47 %************************************************************************
48
49 \begin{code}
50 type Version = Int
51 \end{code}
52
53
54 %************************************************************************
55 %*                                                                      *
56 \subsection[Module]{The name of a module}
57 %*                                                                      *
58 %************************************************************************
59
60 \begin{code}
61 type Module   = FAST_STRING
62
63 moduleString :: Module -> String
64 moduleString mod = _UNPK_ mod
65
66 pprModule :: PprStyle -> Module -> Doc
67 pprModule sty m = ptext m
68 \end{code}
69
70 %************************************************************************
71 %*                                                                      *
72 \subsection[IfaceFlavour]{IfaceFlavour}
73 %*                                                                      *
74 %************************************************************************
75
76 The IfaceFlavour type is used mainly in an imported Name's Provenance
77 to say whether the name comes from a regular .hi file, or whether it comes
78 from a hand-written .hi-boot file.  This is important, because it has to be 
79 propagated.  Suppose
80
81         C.hs imports B
82         B.hs imports A
83         A.hs imports C {-# SOURCE -#} ( f )
84
85 Then in A.hi we may mention C.f, in an inlining.  When compiling B we *must not* 
86 read C.f's details from C.hi, even if the latter happens to exist from an earlier
87 compilation run.  So we use the name "C!f" in A.hi, and when looking for an interface
88 file with details of C!f we look in C.hi-boot.  The "!" stuff is recorded in the
89 IfaceFlavour in the Name of C.f in A. 
90
91 Not particularly beautiful, but it works.
92
93 \begin{code}
94 data IfaceFlavour = HiFile              -- The interface was read from a standard interface file
95                   | HiBootFile          -- ... or from a handwritten "hi-boot" interface file
96
97 instance Text IfaceFlavour where        -- Just used in debug prints of lex tokens
98   showsPrec n HiFile     s = s
99   showsPrec n HiBootFile s = "!" ++ s
100 \end{code}
101
102
103 %************************************************************************
104 %*                                                                      *
105 \subsection[Fixity]{Fixity info}
106 %*                                                                      *
107 %************************************************************************
108
109 \begin{code}
110 data Fixity = Fixity Int FixityDirection
111 data FixityDirection = InfixL | InfixR | InfixN 
112                      deriving(Eq)
113
114 instance Outputable Fixity where
115     ppr sty (Fixity prec dir) = hcat [ppr sty dir, space, int prec]
116
117 instance Outputable FixityDirection where
118     ppr sty InfixL = ptext SLIT("infixl")
119     ppr sty InfixR = ptext SLIT("infixr")
120     ppr sty InfixN = ptext SLIT("infix")
121
122 instance Eq Fixity where                -- Used to determine if two fixities conflict
123   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
124 \end{code}
125
126
127 %************************************************************************
128 %*                                                                      *
129 \subsection[NewType/DataType]{NewType/DataType flag}
130 %*                                                                      *
131 %************************************************************************
132
133 \begin{code}
134 data NewOrData
135   = NewType         -- "newtype Blah ..."
136   | DataType        -- "data Blah ..."
137   deriving( Eq )
138 \end{code}