summaryrefslogtreecommitdiff
path: root/compiler/Language/Haskell/Syntax
diff options
context:
space:
mode:
authorromes <rodrigo.m.mesquita@gmail.com>2022-05-17 16:06:52 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-07-03 14:11:31 -0400
commitf9f8099598fd169fa2f17305fc660e5c473f8836 (patch)
tree5acdb9a38b78dc17ffa0abb63d87555e214d98af /compiler/Language/Haskell/Syntax
parent3a8970ac0c69335a1d229f9c9a71e6e333e99bfb (diff)
downloadhaskell-f9f8099598fd169fa2f17305fc660e5c473f8836.tar.gz
TTG: Move ImpExp client-independent bits to L.H.S.ImpExp
Move the GHC-independent definitions from GHC.Hs.ImpExp to Language.Haskell.Syntax.ImpExp with the required TTG extension fields such as to keep the AST independent from GHC. This is progress towards having the haskell-syntax package, as described in #21592 Bumps haddock submodule
Diffstat (limited to 'compiler/Language/Haskell/Syntax')
-rw-r--r--compiler/Language/Haskell/Syntax/Decls.hs2
-rw-r--r--compiler/Language/Haskell/Syntax/Extension.hs10
-rw-r--r--compiler/Language/Haskell/Syntax/ImpExp.hs177
-rw-r--r--compiler/Language/Haskell/Syntax/ImpExp.hs-boot22
4 files changed, 209 insertions, 2 deletions
diff --git a/compiler/Language/Haskell/Syntax/Decls.hs b/compiler/Language/Haskell/Syntax/Decls.hs
index 303105e3d4..da5265a144 100644
--- a/compiler/Language/Haskell/Syntax/Decls.hs
+++ b/compiler/Language/Haskell/Syntax/Decls.hs
@@ -100,7 +100,7 @@ import {-# SOURCE #-} Language.Haskell.Syntax.Expr
import Language.Haskell.Syntax.Binds
import Language.Haskell.Syntax.Type
-import GHC.Hs.Doc
+import GHC.Hs.Doc -- ROMES:TODO Discuss in #21592 whether this is parsed AST or base AST
import GHC.Core.TyCon
import GHC.Types.Basic
import GHC.Types.ForeignCall
diff --git a/compiler/Language/Haskell/Syntax/Extension.hs b/compiler/Language/Haskell/Syntax/Extension.hs
index f63ca09b30..6312681f52 100644
--- a/compiler/Language/Haskell/Syntax/Extension.hs
+++ b/compiler/Language/Haskell/Syntax/Extension.hs
@@ -399,7 +399,7 @@ type family XXInjectivityAnn x
-- =====================================================================
-- Type families for the HsModule extension points
-type family XModule x
+type family XCModule x
type family XXModule x
-- =====================================================================
@@ -686,6 +686,7 @@ type family XXFieldOcc x
-- ImportDecl type families
type family XCImportDecl x
type family XXImportDecl x
+type family ImportDeclPkgQual x -- stores the package qualifier in an import statement
-- -------------------------------------
-- IE type families
@@ -700,6 +701,13 @@ type family XIEDocNamed x
type family XXIE x
-- -------------------------------------
+-- IEWrappedName type families
+type family XIEName p
+type family XIEPattern p
+type family XIEType p
+type family XXIEWrappedName p
+
+
-- =====================================================================
-- Misc
diff --git a/compiler/Language/Haskell/Syntax/ImpExp.hs b/compiler/Language/Haskell/Syntax/ImpExp.hs
new file mode 100644
index 0000000000..7e529701c4
--- /dev/null
+++ b/compiler/Language/Haskell/Syntax/ImpExp.hs
@@ -0,0 +1,177 @@
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+module Language.Haskell.Syntax.ImpExp where
+
+import Language.Haskell.Syntax.Extension
+
+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 GHC.Data.FastString
+
+{-
+************************************************************************
+* *
+Import and export declaration lists
+* *
+************************************************************************
+
+One per import declaration in a module.
+-}
+
+-- | A ModuleName is essentially a simple string, e.g. @Data.List@.
+newtype ModuleName = ModuleName FastString deriving Show
+
+-- | 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
diff --git a/compiler/Language/Haskell/Syntax/ImpExp.hs-boot b/compiler/Language/Haskell/Syntax/ImpExp.hs-boot
new file mode 100644
index 0000000000..9cc78600b8
--- /dev/null
+++ b/compiler/Language/Haskell/Syntax/ImpExp.hs-boot
@@ -0,0 +1,22 @@
+module Language.Haskell.Syntax.ImpExp where
+
+import GHC.Data.FastString
+
+import Data.Eq
+import Data.Ord
+import Text.Show
+import Data.Data
+
+-- This boot file should be short lived: As soon as the dependency on
+-- `GHC.Hs.Doc` is gone we'll no longer have cycles and can get rid this file.
+
+data IsBootInterface = NotBoot | IsBoot
+
+instance Eq IsBootInterface
+instance Ord IsBootInterface
+instance Show IsBootInterface
+instance Data IsBootInterface
+
+newtype ModuleName = ModuleName FastString
+
+instance Show ModuleName