1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Language.Haskell.Syntax.ImpExp where
import Language.Haskell.Syntax.Extension
import Language.Haskell.Syntax.Module.Name
import Data.Eq (Eq)
import Data.Ord (Ord)
import Text.Show (Show)
import Data.Data (Data)
import Data.Bool (Bool)
import Data.Maybe (Maybe)
import Data.String (String)
import Data.Int (Int)
import GHC.Hs.Doc -- ROMES:TODO Discuss in #21592 whether this is parsed AST or base AST
{-
************************************************************************
* *
Import and export declaration lists
* *
************************************************************************
One per import declaration in a module.
-}
-- | Located Import Declaration
type LImportDecl pass = XRec pass (ImportDecl pass)
-- ^ When in a list this may have
--
-- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnSemi'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
-- | If/how an import is 'qualified'.
data ImportDeclQualifiedStyle
= QualifiedPre -- ^ 'qualified' appears in prepositive position.
| QualifiedPost -- ^ 'qualified' appears in postpositive position.
| NotQualified -- ^ Not qualified.
deriving Data
-- | Indicates whether a module name is referring to a boot interface (hs-boot
-- file) or regular module (hs file). We need to treat boot modules specially
-- when building compilation graphs, since they break cycles. Regular source
-- files and signature files are treated equivalently.
data IsBootInterface = NotBoot | IsBoot
deriving (Eq, Ord, Show, Data)
-- | Import Declaration
--
-- A single Haskell @import@ declaration.
data ImportDecl pass
= ImportDecl {
ideclExt :: XCImportDecl pass,
ideclName :: XRec pass ModuleName, -- ^ Module name.
ideclPkgQual :: ImportDeclPkgQual pass, -- ^ Package qualifier.
ideclSource :: IsBootInterface, -- ^ IsBoot <=> {-\# SOURCE \#-} import
ideclSafe :: Bool, -- ^ True => safe import
ideclQualified :: ImportDeclQualifiedStyle, -- ^ If/how the import is qualified.
ideclAs :: Maybe (XRec pass ModuleName), -- ^ as Module
ideclImportList :: Maybe (ImportListInterpretation, XRec pass [LIE pass])
-- ^ Explicit import list (EverythingBut => hiding, names)
}
| XImportDecl !(XXImportDecl pass)
-- ^
-- 'GHC.Parser.Annotation.AnnKeywordId's
--
-- - 'GHC.Parser.Annotation.AnnImport'
--
-- - 'GHC.Parser.Annotation.AnnOpen', 'GHC.Parser.Annotation.AnnClose' for ideclSource
--
-- - 'GHC.Parser.Annotation.AnnSafe','GHC.Parser.Annotation.AnnQualified',
-- 'GHC.Parser.Annotation.AnnPackageName','GHC.Parser.Annotation.AnnAs',
-- 'GHC.Parser.Annotation.AnnVal'
--
-- - 'GHC.Parser.Annotation.AnnHiding','GHC.Parser.Annotation.AnnOpen',
-- 'GHC.Parser.Annotation.AnnClose' attached
-- to location in ideclImportList
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
-- | Whether the import list is exactly what to import, or whether `hiding` was
-- used, and therefore everything but what was listed should be imported
data ImportListInterpretation = Exactly | EverythingBut
deriving (Eq, Data)
-- | Located Import or Export
type LIE pass = XRec pass (IE pass)
-- ^ When in a list this may have
--
-- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnComma'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
-- | Imported or exported entity.
data IE pass
= IEVar (XIEVar pass) (LIEWrappedName pass)
-- ^ Imported or Exported Variable
| IEThingAbs (XIEThingAbs pass) (LIEWrappedName pass)
-- ^ Imported or exported Thing with Absent list
--
-- The thing is a Class/Type (can't tell)
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnPattern',
-- 'GHC.Parser.Annotation.AnnType','GHC.Parser.Annotation.AnnVal'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
-- See Note [Located RdrNames] in GHC.Hs.Expr
| IEThingAll (XIEThingAll pass) (LIEWrappedName pass)
-- ^ Imported or exported Thing with All imported or exported
--
-- The thing is a Class/Type and the All refers to methods/constructors
--
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnOpen',
-- 'GHC.Parser.Annotation.AnnDotdot','GHC.Parser.Annotation.AnnClose',
-- 'GHC.Parser.Annotation.AnnType'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
-- See Note [Located RdrNames] in GHC.Hs.Expr
| IEThingWith (XIEThingWith pass)
(LIEWrappedName pass)
IEWildcard
[LIEWrappedName pass]
-- ^ Imported or exported Thing With given imported or exported
--
-- The thing is a Class/Type and the imported or exported things are
-- methods/constructors and record fields; see Note [IEThingWith]
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnOpen',
-- 'GHC.Parser.Annotation.AnnClose',
-- 'GHC.Parser.Annotation.AnnComma',
-- 'GHC.Parser.Annotation.AnnType'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
| IEModuleContents (XIEModuleContents pass) (XRec pass ModuleName)
-- ^ Imported or exported module contents
--
-- (Export Only)
--
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnModule'
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
| IEGroup (XIEGroup pass) Int (LHsDoc pass) -- ^ Doc section heading
| IEDoc (XIEDoc pass) (LHsDoc pass) -- ^ Some documentation
| IEDocNamed (XIEDocNamed pass) String -- ^ Reference to named doc
| XIE !(XXIE pass)
-- | Wildcard in an import or export sublist, like the @..@ in
-- @import Mod ( T(Mk1, Mk2, ..) )@.
data IEWildcard
= NoIEWildcard -- ^ no wildcard in this list
| IEWildcard Int -- ^ wildcard after the given \# of items in this list
-- The @Int@ is in the range [0..n], where n is the length
-- of the list.
deriving (Eq, Data)
-- | A name in an import or export specification which may have
-- adornments. Used primarily for accurate pretty printing of
-- ParsedSource, and API Annotation placement. The
-- 'GHC.Parser.Annotation' is the location of the adornment in
-- the original source.
data IEWrappedName p
= IEName (XIEName p) (LIdP p) -- ^ no extra
| IEPattern (XIEPattern p) (LIdP p) -- ^ pattern X
| IEType (XIEType p) (LIdP p) -- ^ type (:+:)
| XIEWrappedName !(XXIEWrappedName p)
-- | Located name with possible adornment
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnType',
-- 'GHC.Parser.Annotation.AnnPattern'
type LIEWrappedName p = XRec p (IEWrappedName p)
-- For details on above see Note [exact print annotations] in GHC.Parser.Annotation
|