diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2021-03-25 21:24:27 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-03-31 11:13:28 -0400 |
commit | 0fe5175ac537c0ce2afe969ec82a0d1c73a4ae38 (patch) | |
tree | da9e816a7d18be58e795b3c9dd07b87106ab82fc /compiler/GHC/Parser | |
parent | 2fcebb72d97edd1e630002bef89bc6982529e36f (diff) | |
download | haskell-0fe5175ac537c0ce2afe969ec82a0d1c73a4ae38.tar.gz |
EPA : Rename ApiAnn to EPAnn
Follow-up from !2418, see #19579
Updates haddock submodule
Diffstat (limited to 'compiler/GHC/Parser')
-rw-r--r-- | compiler/GHC/Parser/Annotation.hs | 252 | ||||
-rw-r--r-- | compiler/GHC/Parser/Lexer.x | 20 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 190 | ||||
-rw-r--r-- | compiler/GHC/Parser/Types.hs | 4 |
4 files changed, 233 insertions, 233 deletions
diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs index fe769a2783..6acb712833 100644 --- a/compiler/GHC/Parser/Annotation.hs +++ b/compiler/GHC/Parser/Annotation.hs @@ -4,27 +4,27 @@ {-# LANGUAGE FlexibleInstances #-} module GHC.Parser.Annotation ( - -- * Core API Annotation types + -- * Core Exact Print Annotation types AnnKeywordId(..), AnnotationComment(..), AnnotationCommentTok(..), IsUnicodeSyntax(..), unicodeAnn, HasE(..), - -- * In-tree Api Annotations + -- * In-tree Exact Print Annotations AddEpAnn(..), AnnAnchor(..), annAnchorRealSrcSpan, DeltaPos(..), - ApiAnn, ApiAnn'(..), Anchor(..), AnchorOperation(..), + EpAnn, EpAnn'(..), Anchor(..), AnchorOperation(..), spanAsAnchor, realSpanAsAnchor, noAnn, -- ** Comments in Annotations - ApiAnnComments(..), LAnnotationComment, com, noCom, + EpAnnComments(..), LAnnotationComment, com, noCom, getFollowingComments, setFollowingComments, setPriorComments, - ApiAnnCO, + EpAnnCO, -- ** Annotations in 'GenLocated' LocatedA, LocatedL, LocatedC, LocatedN, LocatedAn, LocatedP, @@ -37,7 +37,7 @@ module GHC.Parser.Annotation ( AnnPragma(..), AnnContext(..), NameAnn(..), NameAdornment(..), - NoApiAnns(..), + NoEpAnns(..), AnnSortKey(..), -- ** Trailing annotations in lists @@ -75,7 +75,7 @@ module GHC.Parser.Annotation ( -- ** Working with comments in annotations noComments, comment, addCommentsToSrcAnn, setCommentsSrcAnn, - addCommentsToApiAnn, setCommentsApiAnn, + addCommentsToEpAnn, setCommentsEpAnn, transferComments, placeholderRealSpan, @@ -153,9 +153,9 @@ PARSER EMISSION OF ANNOTATIONS The parser interacts with the lexer using the functions -> getCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments -> getPriorCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments -> getFinalCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments +> getCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments +> getPriorCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments +> getFinalCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments The 'getCommentsFor' function is the one used most often. It takes the AST element SrcSpan and removes and returns any comments in the @@ -343,7 +343,7 @@ instance Outputable AnnotationComment where -- | Certain tokens can have alternate representations when unicode syntax is -- enabled. This flag is attached to those tokens in the lexer so that the -- original source representation can be reproduced in the corresponding --- 'ApiAnnotation' +-- 'EpAnnotation' data IsUnicodeSyntax = UnicodeSyntax | NormalSyntax deriving (Eq, Ord, Data, Show) @@ -473,29 +473,29 @@ See Note [XRec and Anno in the AST] for details of how this is done. -- specialised to the specific set of locations of original API -- Annotation elements. So for 'HsLet' we have -- --- type instance XLet GhcPs = ApiAnn' AnnsLet +-- type instance XLet GhcPs = EpAnn' AnnsLet -- data AnnsLet -- = AnnsLet { -- alLet :: AnnAnchor, -- alIn :: AnnAnchor -- } deriving Data -- --- The spacing between the items under the scope of a given ApiAnn' is +-- The spacing between the items under the scope of a given EpAnn' is -- derived from the original 'Anchor'. But there is no requirement -- that the items included in the sub-element have a "matching" -- location in their relative anchors. This allows us to freely move -- elements around, and stitch together new AST fragments out of old -- ones, and have them still printed out in a reasonable way. -data ApiAnn' ann - = ApiAnn { entry :: Anchor +data EpAnn' ann + = EpAnn { entry :: Anchor -- ^ Base location for the start of the syntactic element -- holding the annotations. , anns :: ann -- ^ Annotations added by the Parser - , comments :: ApiAnnComments + , comments :: EpAnnComments -- ^ Comments enclosed in the SrcSpan of the element - -- this `ApiAnn'` is attached to + -- this `EpAnn'` is attached to } - | ApiAnnNotUsed -- ^ No Annotation for generated code, + | EpAnnNotUsed -- ^ No Annotation for generated code, -- e.g. from TH, deriving, etc. deriving (Data, Eq, Functor) @@ -536,7 +536,7 @@ realSpanAsAnchor s = Anchor s UnchangedAnchor -- comments into those occuring before the AST element and those -- following it. The 'AnnCommentsBalanced' constructor is used to do -- this. The GHC parser will only insert the 'AnnComments' form. -data ApiAnnComments = AnnComments +data EpAnnComments = AnnComments { priorComments :: ![LAnnotationComment] } | AnnCommentsBalanced { priorComments :: ![LAnnotationComment] @@ -545,19 +545,19 @@ data ApiAnnComments = AnnComments type LAnnotationComment = GenLocated Anchor AnnotationComment -noCom :: ApiAnnComments +noCom :: EpAnnComments noCom = AnnComments [] -com :: [LAnnotationComment] -> ApiAnnComments +com :: [LAnnotationComment] -> EpAnnComments com cs = AnnComments cs -- --------------------------------------------------------------------- --- | This type is the most direct mapping of the previous API --- Annotations model. It captures the containing `SrcSpan' in its --- `entry` `Anchor`, has a list of `AddEpAnn` as before, and keeps --- track of the comments associated with the anchor. -type ApiAnn = ApiAnn' [AddEpAnn] +-- | This type is the "vanilla" Exact Print Annotation. It captures +-- the containing `SrcSpan' in its `entry` `Anchor`, has a list of +-- `AddEpAnn`, and keeps track of the comments associated with the +-- anchor. +type EpAnn = EpAnn' [AddEpAnn] -- --------------------------------------------------------------------- -- Annotations attached to a 'SrcSpan'. @@ -570,8 +570,8 @@ data SrcSpanAnn' a = SrcSpanAnn { ann :: a, locA :: SrcSpan } deriving (Data, Eq) -- See Note [XRec and Anno in the AST] --- | We mostly use 'SrcSpanAnn\'' with an 'ApiAnn\'' -type SrcAnn ann = SrcSpanAnn' (ApiAnn' ann) +-- | We mostly use 'SrcSpanAnn\'' with an 'EpAnn\'' +type SrcAnn ann = SrcSpanAnn' (EpAnn' ann) -- AZ: is SrcAnn the right abbreviation here? Any better suggestions? -- AZ: should we rename LocatedA to LocatedL? The name comes from @@ -760,7 +760,7 @@ data NameAnn nann_trailing :: [TrailingAnn] } -- | Used when adding a 'TrailingAnn' to an existing 'LocatedN' - -- which has no Api Annotation (via the 'ApiAnnNotUsed' constructor. + -- which has no Api Annotation (via the 'EpAnnNotUsed' constructor. | NameAnnTrailing { nann_trailing :: [TrailingAnn] } @@ -805,10 +805,10 @@ data AnnSortKey -- | Helper function used in the parser to add a 'TrailingAnn' items -- to an existing annotation. -addTrailingAnnToL :: SrcSpan -> TrailingAnn -> ApiAnnComments - -> ApiAnn' AnnList -> ApiAnn' AnnList -addTrailingAnnToL s t cs ApiAnnNotUsed - = ApiAnn (spanAsAnchor s) (AnnList (Just $ spanAsAnchor s) Nothing Nothing [] [t]) cs +addTrailingAnnToL :: SrcSpan -> TrailingAnn -> EpAnnComments + -> EpAnn' AnnList -> EpAnn' AnnList +addTrailingAnnToL s t cs EpAnnNotUsed + = EpAnn (spanAsAnchor s) (AnnList (Just $ spanAsAnchor s) Nothing Nothing [] [t]) cs addTrailingAnnToL _ t cs n = n { anns = addTrailing (anns n) , comments = comments n <> cs } where @@ -816,10 +816,10 @@ addTrailingAnnToL _ t cs n = n { anns = addTrailing (anns n) -- | Helper function used in the parser to add a 'TrailingAnn' items -- to an existing annotation. -addTrailingAnnToA :: SrcSpan -> TrailingAnn -> ApiAnnComments - -> ApiAnn' AnnListItem -> ApiAnn' AnnListItem -addTrailingAnnToA s t cs ApiAnnNotUsed - = ApiAnn (spanAsAnchor s) (AnnListItem [t]) cs +addTrailingAnnToA :: SrcSpan -> TrailingAnn -> EpAnnComments + -> EpAnn' AnnListItem -> EpAnn' AnnListItem +addTrailingAnnToA s t cs EpAnnNotUsed + = EpAnn (spanAsAnchor s) (AnnListItem [t]) cs addTrailingAnnToA _ t cs n = n { anns = addTrailing (anns n) , comments = comments n <> cs } where @@ -827,9 +827,9 @@ addTrailingAnnToA _ t cs n = n { anns = addTrailing (anns n) -- | Helper function used in the parser to add a comma location to an -- existing annotation. -addTrailingCommaToN :: SrcSpan -> ApiAnn' NameAnn -> AnnAnchor -> ApiAnn' NameAnn -addTrailingCommaToN s ApiAnnNotUsed l - = ApiAnn (spanAsAnchor s) (NameAnnTrailing [AddCommaAnn l]) noCom +addTrailingCommaToN :: SrcSpan -> EpAnn' NameAnn -> AnnAnchor -> EpAnn' NameAnn +addTrailingCommaToN s EpAnnNotUsed l + = EpAnn (spanAsAnchor s) (NameAnnTrailing [AddCommaAnn l]) noCom addTrailingCommaToN _ n l = n { anns = addTrailing (anns n) l } where addTrailing :: NameAnn -> AnnAnchor -> NameAnn @@ -867,7 +867,7 @@ reLoc :: LocatedAn a e -> Located e reLoc (L (SrcSpanAnn _ l) a) = L l a reLocA :: Located e -> LocatedAn ann e -reLocA (L l a) = (L (SrcSpanAnn ApiAnnNotUsed l) a) +reLocA (L l a) = (L (SrcSpanAnn EpAnnNotUsed l) a) reLocL :: LocatedN e -> LocatedA e reLocL (L l a) = (L (na2la l) a) @@ -892,53 +892,53 @@ la2r l = realSrcSpan (locA l) extraToAnnList :: AnnList -> [AddEpAnn] -> AnnList extraToAnnList (AnnList a o c e t) as = AnnList a o c (e++as) t -reAnn :: [TrailingAnn] -> ApiAnnComments -> Located a -> LocatedA a -reAnn anns cs (L l a) = L (SrcSpanAnn (ApiAnn (spanAsAnchor l) (AnnListItem anns) cs) l) a +reAnn :: [TrailingAnn] -> EpAnnComments -> Located a -> LocatedA a +reAnn anns cs (L l a) = L (SrcSpanAnn (EpAnn (spanAsAnchor l) (AnnListItem anns) cs) l) a -reAnnC :: AnnContext -> ApiAnnComments -> Located a -> LocatedC a -reAnnC anns cs (L l a) = L (SrcSpanAnn (ApiAnn (spanAsAnchor l) anns cs) l) a +reAnnC :: AnnContext -> EpAnnComments -> Located a -> LocatedC a +reAnnC anns cs (L l a) = L (SrcSpanAnn (EpAnn (spanAsAnchor l) anns cs) l) a -reAnnL :: ann -> ApiAnnComments -> Located e -> GenLocated (SrcAnn ann) e -reAnnL anns cs (L l a) = L (SrcSpanAnn (ApiAnn (spanAsAnchor l) anns cs) l) a +reAnnL :: ann -> EpAnnComments -> Located e -> GenLocated (SrcAnn ann) e +reAnnL anns cs (L l a) = L (SrcSpanAnn (EpAnn (spanAsAnchor l) anns cs) l) a getLocAnn :: Located a -> SrcSpanAnnA -getLocAnn (L l _) = SrcSpanAnn ApiAnnNotUsed l +getLocAnn (L l _) = SrcSpanAnn EpAnnNotUsed l getLocA :: GenLocated (SrcSpanAnn' a) e -> SrcSpan getLocA (L (SrcSpanAnn _ l) _) = l noLocA :: a -> LocatedAn an a -noLocA = L (SrcSpanAnn ApiAnnNotUsed noSrcSpan) +noLocA = L (SrcSpanAnn EpAnnNotUsed noSrcSpan) noAnnSrcSpan :: SrcSpan -> SrcAnn ann -noAnnSrcSpan l = SrcSpanAnn ApiAnnNotUsed l +noAnnSrcSpan l = SrcSpanAnn EpAnnNotUsed l noSrcSpanA :: SrcAnn ann noSrcSpanA = noAnnSrcSpan noSrcSpan --- | Short form for 'ApiAnnNotUsed' -noAnn :: ApiAnn' a -noAnn = ApiAnnNotUsed +-- | Short form for 'EpAnnNotUsed' +noAnn :: EpAnn' a +noAnn = EpAnnNotUsed -addAnns :: ApiAnn -> [AddEpAnn] -> ApiAnnComments -> ApiAnn -addAnns (ApiAnn l as1 cs) as2 cs2 - = ApiAnn (widenAnchor l (as1 ++ as2)) (as1 ++ as2) (cs <> cs2) -addAnns ApiAnnNotUsed [] (AnnComments []) = ApiAnnNotUsed -addAnns ApiAnnNotUsed [] (AnnCommentsBalanced [] []) = ApiAnnNotUsed -addAnns ApiAnnNotUsed as cs = ApiAnn (Anchor placeholderRealSpan UnchangedAnchor) as cs +addAnns :: EpAnn -> [AddEpAnn] -> EpAnnComments -> EpAnn +addAnns (EpAnn l as1 cs) as2 cs2 + = EpAnn (widenAnchor l (as1 ++ as2)) (as1 ++ as2) (cs <> cs2) +addAnns EpAnnNotUsed [] (AnnComments []) = EpAnnNotUsed +addAnns EpAnnNotUsed [] (AnnCommentsBalanced [] []) = EpAnnNotUsed +addAnns EpAnnNotUsed as cs = EpAnn (Anchor placeholderRealSpan UnchangedAnchor) as cs -- AZ:TODO use widenSpan here too -addAnnsA :: SrcSpanAnnA -> [TrailingAnn] -> ApiAnnComments -> SrcSpanAnnA -addAnnsA (SrcSpanAnn (ApiAnn l as1 cs) loc) as2 cs2 - = SrcSpanAnn (ApiAnn l (AnnListItem (lann_trailing as1 ++ as2)) (cs <> cs2)) loc -addAnnsA (SrcSpanAnn ApiAnnNotUsed loc) [] (AnnComments []) - = SrcSpanAnn ApiAnnNotUsed loc -addAnnsA (SrcSpanAnn ApiAnnNotUsed loc) [] (AnnCommentsBalanced [] []) - = SrcSpanAnn ApiAnnNotUsed loc -addAnnsA (SrcSpanAnn ApiAnnNotUsed loc) as cs - = SrcSpanAnn (ApiAnn (spanAsAnchor loc) (AnnListItem as) cs) loc +addAnnsA :: SrcSpanAnnA -> [TrailingAnn] -> EpAnnComments -> SrcSpanAnnA +addAnnsA (SrcSpanAnn (EpAnn l as1 cs) loc) as2 cs2 + = SrcSpanAnn (EpAnn l (AnnListItem (lann_trailing as1 ++ as2)) (cs <> cs2)) loc +addAnnsA (SrcSpanAnn EpAnnNotUsed loc) [] (AnnComments []) + = SrcSpanAnn EpAnnNotUsed loc +addAnnsA (SrcSpanAnn EpAnnNotUsed loc) [] (AnnCommentsBalanced [] []) + = SrcSpanAnn EpAnnNotUsed loc +addAnnsA (SrcSpanAnn EpAnnNotUsed loc) as cs + = SrcSpanAnn (EpAnn (spanAsAnchor loc) (AnnListItem as) cs) loc -- | The annotations need to all come after the anchor. Make sure -- this is the case. @@ -967,24 +967,24 @@ widenAnchorR (Anchor s op) r = Anchor (combineRealSrcSpans s r) op widenLocatedAn :: SrcSpanAnn' an -> [AddEpAnn] -> SrcSpanAnn' an widenLocatedAn (SrcSpanAnn a l) as = SrcSpanAnn a (widenSpan l as) -apiAnnAnnsL :: ApiAnn' a -> [a] -apiAnnAnnsL ApiAnnNotUsed = [] -apiAnnAnnsL (ApiAnn _ anns _) = [anns] +apiAnnAnnsL :: EpAnn' a -> [a] +apiAnnAnnsL EpAnnNotUsed = [] +apiAnnAnnsL (EpAnn _ anns _) = [anns] -apiAnnAnns :: ApiAnn -> [AddEpAnn] -apiAnnAnns ApiAnnNotUsed = [] -apiAnnAnns (ApiAnn _ anns _) = anns +apiAnnAnns :: EpAnn -> [AddEpAnn] +apiAnnAnns EpAnnNotUsed = [] +apiAnnAnns (EpAnn _ anns _) = anns -annParen2AddEpAnn :: ApiAnn' AnnParen -> [AddEpAnn] -annParen2AddEpAnn ApiAnnNotUsed = [] -annParen2AddEpAnn (ApiAnn _ (AnnParen pt o c) _) +annParen2AddEpAnn :: EpAnn' AnnParen -> [AddEpAnn] +annParen2AddEpAnn EpAnnNotUsed = [] +annParen2AddEpAnn (EpAnn _ (AnnParen pt o c) _) = [AddEpAnn ai o, AddEpAnn ac c] where (ai,ac) = parenTypeKws pt -apiAnnComments :: ApiAnn' an -> ApiAnnComments -apiAnnComments ApiAnnNotUsed = AnnComments [] -apiAnnComments (ApiAnn _ _ cs) = cs +apiAnnComments :: EpAnn' an -> EpAnnComments +apiAnnComments EpAnnNotUsed = AnnComments [] +apiAnnComments (EpAnn _ _ cs) = cs -- --------------------------------------------------------------------- -- sortLocatedA :: [LocatedA a] -> [LocatedA a] @@ -1011,18 +1011,18 @@ addCLocAA :: GenLocated (SrcSpanAnn' a1) e1 -> GenLocated (SrcSpanAnn' a2) e2 -> addCLocAA a b c = L (noAnnSrcSpan $ combineSrcSpans (locA $ getLoc a) (locA $ getLoc b)) c -- --------------------------------------------------------------------- --- Utilities for manipulating ApiAnnComments +-- Utilities for manipulating EpAnnComments -- --------------------------------------------------------------------- -getFollowingComments :: ApiAnnComments -> [LAnnotationComment] +getFollowingComments :: EpAnnComments -> [LAnnotationComment] getFollowingComments (AnnComments _) = [] getFollowingComments (AnnCommentsBalanced _ cs) = cs -setFollowingComments :: ApiAnnComments -> [LAnnotationComment] -> ApiAnnComments +setFollowingComments :: EpAnnComments -> [LAnnotationComment] -> EpAnnComments setFollowingComments (AnnComments ls) cs = AnnCommentsBalanced ls cs setFollowingComments (AnnCommentsBalanced ls _) cs = AnnCommentsBalanced ls cs -setPriorComments :: ApiAnnComments -> [LAnnotationComment] -> ApiAnnComments +setPriorComments :: EpAnnComments -> [LAnnotationComment] -> EpAnnComments setPriorComments (AnnComments _) cs = AnnComments cs setPriorComments (AnnCommentsBalanced _ ts) cs = AnnCommentsBalanced cs ts @@ -1030,66 +1030,66 @@ setPriorComments (AnnCommentsBalanced _ ts) cs = AnnCommentsBalanced cs ts -- Comment-only annotations -- --------------------------------------------------------------------- --- TODO:AZ I think ApiAnnCO is not needed -type ApiAnnCO = ApiAnn' NoApiAnns -- ^ Api Annotations for comments only +-- TODO:AZ I think EpAnnCO is not needed +type EpAnnCO = EpAnn' NoEpAnns -- ^ Api Annotations for comments only -data NoApiAnns = NoApiAnns +data NoEpAnns = NoEpAnns deriving (Data,Eq,Ord) -noComments ::ApiAnnCO -noComments = ApiAnn (Anchor placeholderRealSpan UnchangedAnchor) NoApiAnns noCom +noComments ::EpAnnCO +noComments = EpAnn (Anchor placeholderRealSpan UnchangedAnchor) NoEpAnns noCom -- TODO:AZ get rid of this placeholderRealSpan :: RealSrcSpan placeholderRealSpan = realSrcLocSpan (mkRealSrcLoc (mkFastString "placeholder") (-1) (-1)) -comment :: RealSrcSpan -> ApiAnnComments -> ApiAnnCO -comment loc cs = ApiAnn (Anchor loc UnchangedAnchor) NoApiAnns cs +comment :: RealSrcSpan -> EpAnnComments -> EpAnnCO +comment loc cs = EpAnn (Anchor loc UnchangedAnchor) NoEpAnns cs -- --------------------------------------------------------------------- --- Utilities for managing comments in an `ApiAnn' a` structure. +-- Utilities for managing comments in an `EpAnn' a` structure. -- --------------------------------------------------------------------- -- | Add additional comments to a 'SrcAnn', used for manipulating the -- AST prior to exact printing the changed one. -addCommentsToSrcAnn :: (Monoid ann) => SrcAnn ann -> ApiAnnComments -> SrcAnn ann -addCommentsToSrcAnn (SrcSpanAnn ApiAnnNotUsed loc) cs - = SrcSpanAnn (ApiAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs) loc -addCommentsToSrcAnn (SrcSpanAnn (ApiAnn a an cs) loc) cs' - = SrcSpanAnn (ApiAnn a an (cs <> cs')) loc +addCommentsToSrcAnn :: (Monoid ann) => SrcAnn ann -> EpAnnComments -> SrcAnn ann +addCommentsToSrcAnn (SrcSpanAnn EpAnnNotUsed loc) cs + = SrcSpanAnn (EpAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs) loc +addCommentsToSrcAnn (SrcSpanAnn (EpAnn a an cs) loc) cs' + = SrcSpanAnn (EpAnn a an (cs <> cs')) loc -- | Replace any existing comments on a 'SrcAnn', used for manipulating the -- AST prior to exact printing the changed one. -setCommentsSrcAnn :: (Monoid ann) => SrcAnn ann -> ApiAnnComments -> SrcAnn ann -setCommentsSrcAnn (SrcSpanAnn ApiAnnNotUsed loc) cs - = SrcSpanAnn (ApiAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs) loc -setCommentsSrcAnn (SrcSpanAnn (ApiAnn a an _) loc) cs - = SrcSpanAnn (ApiAnn a an cs) loc +setCommentsSrcAnn :: (Monoid ann) => SrcAnn ann -> EpAnnComments -> SrcAnn ann +setCommentsSrcAnn (SrcSpanAnn EpAnnNotUsed loc) cs + = SrcSpanAnn (EpAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs) loc +setCommentsSrcAnn (SrcSpanAnn (EpAnn a an _) loc) cs + = SrcSpanAnn (EpAnn a an cs) loc -- | Add additional comments, used for manipulating the -- AST prior to exact printing the changed one. -addCommentsToApiAnn :: (Monoid a) - => SrcSpan -> ApiAnn' a -> ApiAnnComments -> ApiAnn' a -addCommentsToApiAnn loc ApiAnnNotUsed cs - = ApiAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs -addCommentsToApiAnn _ (ApiAnn a an ocs) ncs = ApiAnn a an (ocs <> ncs) +addCommentsToEpAnn :: (Monoid a) + => SrcSpan -> EpAnn' a -> EpAnnComments -> EpAnn' a +addCommentsToEpAnn loc EpAnnNotUsed cs + = EpAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs +addCommentsToEpAnn _ (EpAnn a an ocs) ncs = EpAnn a an (ocs <> ncs) -- | Replace any existing comments, used for manipulating the -- AST prior to exact printing the changed one. -setCommentsApiAnn :: (Monoid a) - => SrcSpan -> ApiAnn' a -> ApiAnnComments -> ApiAnn' a -setCommentsApiAnn loc ApiAnnNotUsed cs - = ApiAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs -setCommentsApiAnn _ (ApiAnn a an _) cs = ApiAnn a an cs +setCommentsEpAnn :: (Monoid a) + => SrcSpan -> EpAnn' a -> EpAnnComments -> EpAnn' a +setCommentsEpAnn loc EpAnnNotUsed cs + = EpAnn (Anchor (realSrcSpan loc) UnchangedAnchor) mempty cs +setCommentsEpAnn _ (EpAnn a an _) cs = EpAnn a an cs -- | Transfer comments from the annotations in one 'SrcAnn' to those -- in another. The originals are not changed. This is used when -- manipulating an AST prior to exact printing, transferComments :: (Monoid ann) => SrcAnn ann -> SrcAnn ann -> (SrcAnn ann, SrcAnn ann) -transferComments from@(SrcSpanAnn ApiAnnNotUsed _) to = (from, to) -transferComments (SrcSpanAnn (ApiAnn a an cs) l) to - = ((SrcSpanAnn (ApiAnn a an noCom) l), addCommentsToSrcAnn to cs) +transferComments from@(SrcSpanAnn EpAnnNotUsed _) to = (from, to) +transferComments (SrcSpanAnn (EpAnn a an cs) l) to + = ((SrcSpanAnn (EpAnn a an noCom) l), addCommentsToSrcAnn to cs) -- --------------------------------------------------------------------- -- Semigroup instances, to allow easy combination of annotaion elements @@ -1101,10 +1101,10 @@ instance (Semigroup an) => Semigroup (SrcSpanAnn' an) where -- annotations must follow it. So we combine them which yields the -- largest span -instance (Semigroup a) => Semigroup (ApiAnn' a) where - ApiAnnNotUsed <> x = x - x <> ApiAnnNotUsed = x - (ApiAnn l1 a1 b1) <> (ApiAnn l2 a2 b2) = ApiAnn (l1 <> l2) (a1 <> a2) (b1 <> b2) +instance (Semigroup a) => Semigroup (EpAnn' a) where + EpAnnNotUsed <> x = x + x <> EpAnnNotUsed = x + (EpAnn l1 a1 b1) <> (EpAnn l2 a2 b2) = EpAnn (l1 <> l2) (a1 <> a2) (b1 <> b2) -- The critical part about the anchor is its left edge, and all -- annotations must follow it. So we combine them which yields the -- largest span @@ -1115,15 +1115,15 @@ instance Ord Anchor where instance Semigroup Anchor where Anchor r1 o1 <> Anchor r2 _ = Anchor (combineRealSrcSpans r1 r2) o1 -instance Semigroup ApiAnnComments where +instance Semigroup EpAnnComments where AnnComments cs1 <> AnnComments cs2 = AnnComments (cs1 ++ cs2) AnnComments cs1 <> AnnCommentsBalanced cs2 as2 = AnnCommentsBalanced (cs1 ++ cs2) as2 AnnCommentsBalanced cs1 as1 <> AnnComments cs2 = AnnCommentsBalanced (cs1 ++ cs2) as1 AnnCommentsBalanced cs1 as1 <> AnnCommentsBalanced cs2 as2 = AnnCommentsBalanced (cs1 ++ cs2) (as1++as2) -instance (Monoid a) => Monoid (ApiAnn' a) where - mempty = ApiAnnNotUsed +instance (Monoid a) => Monoid (EpAnn' a) where + mempty = EpAnnNotUsed instance Semigroup AnnListItem where (AnnListItem l1) <> (AnnListItem l2) = AnnListItem (l1 <> l2) @@ -1159,9 +1159,9 @@ instance Semigroup AnnSortKey where instance Monoid AnnSortKey where mempty = NoAnnSortKey -instance (Outputable a) => Outputable (ApiAnn' a) where - ppr (ApiAnn l a c) = text "ApiAnn" <+> ppr l <+> ppr a <+> ppr c - ppr ApiAnnNotUsed = text "ApiAnnNotUsed" +instance (Outputable a) => Outputable (EpAnn' a) where + ppr (EpAnn l a c) = text "EpAnn" <+> ppr l <+> ppr a <+> ppr c + ppr EpAnnNotUsed = text "EpAnnNotUsed" instance Outputable Anchor where ppr (Anchor a o) = text "Anchor" <+> ppr a <+> ppr o @@ -1176,7 +1176,7 @@ instance Outputable DeltaPos where instance Outputable (GenLocated Anchor AnnotationComment) where ppr (L l c) = text "L" <+> ppr l <+> ppr c -instance Outputable ApiAnnComments where +instance Outputable EpAnnComments where ppr (AnnComments cs) = text "AnnComments" <+> ppr cs ppr (AnnCommentsBalanced cs ts) = text "AnnCommentsBalanced" <+> ppr cs <+> ppr ts diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x index 8eea1aea62..125e6aaaf6 100644 --- a/compiler/GHC/Parser/Lexer.x +++ b/compiler/GHC/Parser/Lexer.x @@ -65,7 +65,7 @@ module GHC.Parser.Lexer ( ExtBits(..), xtest, xunset, xset, lexTokenStream, - mkParensApiAnn, + mkParensEpAnn, getCommentsFor, getPriorCommentsFor, getFinalCommentsFor, getEofPos, commentToAnnotation, @@ -2892,13 +2892,13 @@ class Monad m => MonadP m where getBit :: ExtBits -> m Bool -- | Go through the @comment_q@ in @PState@ and remove all comments -- that belong within the given span - allocateCommentsP :: RealSrcSpan -> m ApiAnnComments + allocateCommentsP :: RealSrcSpan -> m EpAnnComments -- | Go through the @comment_q@ in @PState@ and remove all comments -- that come before or within the given span - allocatePriorCommentsP :: RealSrcSpan -> m ApiAnnComments + allocatePriorCommentsP :: RealSrcSpan -> m EpAnnComments -- | Go through the @comment_q@ in @PState@ and remove all comments -- that come after the given span - allocateFinalCommentsP :: RealSrcSpan -> m ApiAnnComments + allocateFinalCommentsP :: RealSrcSpan -> m EpAnnComments instance MonadP P where addError err @@ -2934,15 +2934,15 @@ instance MonadP P where comment_q = comment_q' } (AnnCommentsBalanced (fromMaybe [] header_comments') (reverse newAnns)) -getCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments +getCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments getCommentsFor (RealSrcSpan l _) = allocateCommentsP l getCommentsFor _ = return noCom -getPriorCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments +getPriorCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments getPriorCommentsFor (RealSrcSpan l _) = allocatePriorCommentsP l getPriorCommentsFor _ = return noCom -getFinalCommentsFor :: (MonadP m) => SrcSpan -> m ApiAnnComments +getFinalCommentsFor :: (MonadP m) => SrcSpan -> m EpAnnComments getFinalCommentsFor (RealSrcSpan l _) = allocateFinalCommentsP l getFinalCommentsFor _ = return noCom @@ -3437,9 +3437,9 @@ clean_pragma prag = canon_ws (map toLower (unprefix prag)) -- |Given a 'SrcSpan' that surrounds a 'HsPar' or 'HsParTy', generate -- 'AddEpAnn' values for the opening and closing bordering on the start -- and end of the span -mkParensApiAnn :: SrcSpan -> [AddEpAnn] -mkParensApiAnn (UnhelpfulSpan _) = [] -mkParensApiAnn (RealSrcSpan ss _) = [AddEpAnn AnnOpenP (AR lo),AddEpAnn AnnCloseP (AR lc)] +mkParensEpAnn :: SrcSpan -> [AddEpAnn] +mkParensEpAnn (UnhelpfulSpan _) = [] +mkParensEpAnn (RealSrcSpan ss _) = [AddEpAnn AnnOpenP (AR lo),AddEpAnn AnnCloseP (AR lc)] where f = srcSpanFile ss sl = srcSpanStartLine ss diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 56564ef908..d6248bd107 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -189,7 +189,7 @@ mkClassDecl loc' (L _ (mcxt, tycl_hdr)) fds where_cls layoutInfo annsIn ; (cls, tparams, fixity, ann) <- checkTyClHdr True tycl_hdr ; (tyvars,annst) <- checkTyVars (text "class") whereDots cls tparams ; cs <- getCommentsFor (locA loc) -- Get any remaining comments - ; let anns' = addAnns (ApiAnn (spanAsAnchor $ locA loc) annsIn noCom) (ann++annst) cs + ; let anns' = addAnns (EpAnn (spanAsAnchor $ locA loc) annsIn noCom) (ann++annst) cs ; return (L loc (ClassDecl { tcdCExt = (anns', NoAnnSortKey, layoutInfo) , tcdCtxt = mcxt , tcdLName = cls, tcdTyVars = tyvars @@ -215,7 +215,7 @@ mkTyData loc' new_or_data cType (L _ (mcxt, tycl_hdr)) ; (tc, tparams, fixity, ann) <- checkTyClHdr False tycl_hdr ; (tyvars, anns) <- checkTyVars (ppr new_or_data) equalsDots tc tparams ; cs <- getCommentsFor (locA loc) -- Get any remaining comments - ; let anns' = addAnns (ApiAnn (spanAsAnchor $ locA loc) annsIn noCom) (ann ++ anns) cs + ; let anns' = addAnns (EpAnn (spanAsAnchor $ locA loc) annsIn noCom) (ann ++ anns) cs ; defn <- mkDataDefn new_or_data cType mcxt ksig data_cons maybe_deriv anns' ; return (L loc (DataDecl { tcdDExt = anns', -- AZ: do we need these? tcdLName = tc, tcdTyVars = tyvars, @@ -228,7 +228,7 @@ mkDataDefn :: NewOrData -> Maybe (LHsKind GhcPs) -> [LConDecl GhcPs] -> HsDeriving GhcPs - -> ApiAnn + -> EpAnn -> P (HsDataDefn GhcPs) mkDataDefn new_or_data cType mcxt ksig data_cons maybe_deriv ann = do { checkDatatypeContext mcxt @@ -250,7 +250,7 @@ mkTySynonym loc lhs rhs annsIn ; cs1 <- getCommentsFor loc -- Add any API Annotations to the top SrcSpan [temp] ; (tyvars, anns) <- checkTyVars (text "type") equalsDots tc tparams ; cs2 <- getCommentsFor loc -- Add any API Annotations to the top SrcSpan [temp] - ; let anns' = addAnns (ApiAnn (spanAsAnchor loc) annsIn noCom) (ann ++ anns) (cs1 Semi.<> cs2) + ; let anns' = addAnns (EpAnn (spanAsAnchor loc) annsIn noCom) (ann ++ anns) (cs1 Semi.<> cs2) ; return (L (noAnnSrcSpan loc) (SynDecl { tcdSExt = anns' , tcdLName = tc, tcdTyVars = tyvars @@ -268,7 +268,7 @@ mkStandaloneKindSig loc lhs rhs anns = ; v <- check_singular_lhs (reverse vs) ; cs <- getCommentsFor loc ; return $ L (noAnnSrcSpan loc) - $ StandaloneKindSig (ApiAnn (spanAsAnchor loc) anns cs) v rhs } + $ StandaloneKindSig (EpAnn (spanAsAnchor loc) anns cs) v rhs } where check_lhs_name v@(unLoc->name) = if isUnqual name && isTcOcc (rdrNameOcc name) @@ -290,7 +290,7 @@ mkTyFamInstEqn loc bndrs lhs rhs anns = do { (tc, tparams, fixity, ann) <- checkTyClHdr False lhs ; cs <- getCommentsFor loc ; return (L (noAnnSrcSpan loc) $ FamEqn - { feqn_ext = ApiAnn (spanAsAnchor loc) (anns `mappend` ann) cs + { feqn_ext = EpAnn (spanAsAnchor loc) (anns `mappend` ann) cs , feqn_tycon = tc , feqn_bndrs = bndrs , feqn_pats = tparams @@ -312,7 +312,7 @@ mkDataFamInst loc new_or_data cType (mcxt, bndrs, tycl_hdr) = do { (tc, tparams, fixity, ann) <- checkTyClHdr False tycl_hdr ; -- AZ:TODO: deal with these comments ; cs <- getCommentsFor loc -- Add any API Annotations to the top SrcSpan [temp] - ; let anns' = addAnns (ApiAnn (spanAsAnchor loc) ann cs) anns noCom + ; let anns' = addAnns (EpAnn (spanAsAnchor loc) ann cs) anns noCom ; defn <- mkDataDefn new_or_data cType mcxt ksig data_cons maybe_deriv anns' ; return (L (noAnnSrcSpan loc) (DataFamInstD anns' (DataFamInstDecl (FamEqn { feqn_ext = noAnn -- AZ: get anns @@ -329,7 +329,7 @@ mkTyFamInst :: SrcSpan mkTyFamInst loc eqn anns = do cs <- getCommentsFor loc return (L (noAnnSrcSpan loc) (TyFamInstD noExtField - (TyFamInstDecl (ApiAnn (spanAsAnchor loc) anns cs) eqn))) + (TyFamInstDecl (EpAnn (spanAsAnchor loc) anns cs) eqn))) mkFamDecl :: SrcSpan -> FamilyInfo GhcPs @@ -344,7 +344,7 @@ mkFamDecl loc info topLevel lhs ksig injAnn annsIn ; cs1 <- getCommentsFor loc -- Add any API Annotations to the top SrcSpan [temp] ; (tyvars, anns) <- checkTyVars (ppr info) equals_or_where tc tparams ; cs2 <- getCommentsFor loc -- Add any API Annotations to the top SrcSpan [temp] - ; let anns' = addAnns (ApiAnn (spanAsAnchor loc) annsIn noCom) (ann++anns) (cs1 Semi.<> cs2) + ; let anns' = addAnns (EpAnn (spanAsAnchor loc) annsIn noCom) (ann++anns) (cs1 Semi.<> cs2) ; return (L (noAnnSrcSpan loc) (FamDecl noExtField (FamilyDecl { fdExt = anns' @@ -394,7 +394,7 @@ mkRoleAnnotDecl loc tycon roles anns = do { roles' <- mapM parse_role roles ; cs <- getCommentsFor loc ; return $ L (noAnnSrcSpan loc) - $ RoleAnnotDecl (ApiAnn (spanAsAnchor loc) anns cs) tycon roles' } + $ RoleAnnotDecl (EpAnn (spanAsAnchor loc) anns cs) tycon roles' } where role_data_type = dataTypeOf (undefined :: Role) all_roles = map fromConstr $ dataTypeConstrs role_data_type @@ -436,14 +436,14 @@ annBinds a (HsValBinds an bs) = (HsValBinds (add_where a an) bs) annBinds a (HsIPBinds an bs) = (HsIPBinds (add_where a an) bs) annBinds _ (EmptyLocalBinds x) = (EmptyLocalBinds x) -add_where :: AddEpAnn -> ApiAnn' AnnList -> ApiAnn' AnnList -add_where an@(AddEpAnn _ (AR rs)) (ApiAnn a (AnnList anc o c r t) cs) +add_where :: AddEpAnn -> EpAnn' AnnList -> EpAnn' AnnList +add_where an@(AddEpAnn _ (AR rs)) (EpAnn a (AnnList anc o c r t) cs) | valid_anchor (anchor a) - = ApiAnn (widenAnchor a [an]) (AnnList anc o c (an:r) t) cs + = EpAnn (widenAnchor a [an]) (AnnList anc o c (an:r) t) cs | otherwise - = ApiAnn (patch_anchor rs a) (AnnList (fmap (patch_anchor rs) anc) o c (an:r) t) cs -add_where an@(AddEpAnn _ (AR rs)) ApiAnnNotUsed - = ApiAnn (Anchor rs UnchangedAnchor) + = EpAnn (patch_anchor rs a) (AnnList (fmap (patch_anchor rs) anc) o c (an:r) t) cs +add_where an@(AddEpAnn _ (AR rs)) EpAnnNotUsed + = EpAnn (Anchor rs UnchangedAnchor) (AnnList (Just $ Anchor rs UnchangedAnchor) Nothing Nothing [an] []) noCom add_where (AddEpAnn _ (AD _)) _ = panic "add_where" -- AD should only be used for transformations @@ -679,7 +679,7 @@ recordPatSynErr :: SrcSpan -> LPat GhcPs -> P a recordPatSynErr loc pat = addFatalError $ PsError (PsErrRecordSyntaxInPatSynDecl pat) [] loc -mkConDeclH98 :: ApiAnn -> LocatedN RdrName -> Maybe [LHsTyVarBndr Specificity GhcPs] +mkConDeclH98 :: EpAnn -> LocatedN RdrName -> Maybe [LHsTyVarBndr Specificity GhcPs] -> Maybe (LHsContext GhcPs) -> HsConDeclH98Details GhcPs -> ConDecl GhcPs @@ -719,7 +719,7 @@ mkGadtDecl loc names ty annsIn = do in (PrefixConGADT arg_types, res_type, anns, cs) an = case outer_bndrs of - _ -> ApiAnn (spanAsAnchor loc) (annsIn ++ annsa) (cs Semi.<> csa) + _ -> EpAnn (spanAsAnchor loc) (annsIn ++ annsa) (cs Semi.<> csa) pure $ L l ConDeclGADT { con_g_ext = an @@ -836,16 +836,16 @@ checkTyVars pp_what equals_or_where tc tparms check (HsValArg ty) = chkParens [] noCom ty check (HsArgPar sp) = addFatalError $ PsError (PsErrMalformedDecl pp_what (unLoc tc)) [] sp -- Keep around an action for adjusting the annotations of extra parens - chkParens :: [AddEpAnn] -> ApiAnnComments -> LHsType GhcPs + chkParens :: [AddEpAnn] -> EpAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs, [AddEpAnn]) chkParens acc cs (L l (HsParTy an ty)) - = chkParens (mkParensApiAnn (locA l) ++ acc) (cs Semi.<> apiAnnComments an) ty + = chkParens (mkParensEpAnn (locA l) ++ acc) (cs Semi.<> apiAnnComments an) ty chkParens acc cs ty = do tv <- chk acc cs ty return (tv, reverse acc) -- Check that the name space is correct! - chk :: [AddEpAnn] -> ApiAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs) + chk :: [AddEpAnn] -> EpAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs) chk an cs (L l (HsKindSig annk (L annt (HsTyVar ann _ (L lv tv))) k)) | isRdrTyVar tv = return (L (widenLocatedAn (l Semi.<> annt) an) @@ -869,7 +869,7 @@ checkDatatypeContext (Just c) unless allowed $ addError $ PsError (PsErrIllegalDataTypeContext c) [] (getLocA c) type LRuleTyTmVar = Located RuleTyTmVar -data RuleTyTmVar = RuleTyTmVar ApiAnn (LocatedN RdrName) (Maybe (LHsType GhcPs)) +data RuleTyTmVar = RuleTyTmVar EpAnn (LocatedN RdrName) (Maybe (LHsType GhcPs)) -- ^ Essentially a wrapper for a @RuleBndr GhcPs@ -- turns RuleTyTmVars into RuleBnrs - this is straightforward @@ -944,7 +944,7 @@ checkTyClHdr is_cls ty | isRdrTc tc = return (ltc, acc, fix, ann) go _ (HsOpTy _ t1 ltc@(L _ tc) t2) acc ann _fix | isRdrTc tc = return (ltc, HsValArg t1:HsValArg t2:acc, Infix, ann) - go l (HsParTy _ ty) acc ann fix = goL ty acc (ann ++mkParensApiAnn l) fix + go l (HsParTy _ ty) acc ann fix = goL ty acc (ann ++mkParensEpAnn l) fix go _ (HsAppTy _ t1 t2) acc ann fix = goL t1 (HsValArg t2:acc) ann fix go _ (HsAppKindTy l ty ki) acc ann fix = goL ty (HsTypeArg l ki:acc) ann fix go l (HsTupleTy _ HsBoxedOrConstraintTuple ts) [] ann fix @@ -960,18 +960,18 @@ checkTyClHdr is_cls ty -- Combine the annotations from the HsParTy and HsStarTy into a -- new one for the LocatedN RdrName - newAnns :: SrcSpanAnnA -> ApiAnn' AnnParen -> SrcSpanAnnN - newAnns (SrcSpanAnn ApiAnnNotUsed l) (ApiAnn as (AnnParen _ o c) cs) = + newAnns :: SrcSpanAnnA -> EpAnn' AnnParen -> SrcSpanAnnN + newAnns (SrcSpanAnn EpAnnNotUsed l) (EpAnn as (AnnParen _ o c) cs) = let lr = combineRealSrcSpans (realSrcSpan l) (anchor as) -- lr = widenAnchorR as (realSrcSpan l) - an = (ApiAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (AR $ realSrcSpan l) c []) cs) + an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (AR $ realSrcSpan l) c []) cs) in SrcSpanAnn an (RealSrcSpan lr Nothing) - newAnns _ ApiAnnNotUsed = panic "missing AnnParen" - newAnns (SrcSpanAnn (ApiAnn ap (AnnListItem ta) csp) l) (ApiAnn as (AnnParen _ o c) cs) = + newAnns _ EpAnnNotUsed = panic "missing AnnParen" + newAnns (SrcSpanAnn (EpAnn ap (AnnListItem ta) csp) l) (EpAnn as (AnnParen _ o c) cs) = let lr = combineRealSrcSpans (anchor ap) (anchor as) - an = (ApiAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (AR $ realSrcSpan l) c ta) (csp Semi.<> cs)) + an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (AR $ realSrcSpan l) c ta) (csp Semi.<> cs)) in SrcSpanAnn an (RealSrcSpan lr Nothing) -- | Yield a parse error if we have a function applied directly to a do block @@ -1019,7 +1019,7 @@ checkContext :: LHsType GhcPs -> P (LHsContext GhcPs) checkContext orig_t@(L (SrcSpanAnn _ l) _orig_t) = check ([],[],noCom) orig_t where - check :: ([AnnAnchor],[AnnAnchor],ApiAnnComments) + check :: ([AnnAnchor],[AnnAnchor],EpAnnComments) -> LHsType GhcPs -> P (LHsContext GhcPs) check (oparens,cparens,cs) (L _l (HsTupleTy ann' HsBoxedOrConstraintTuple ts)) -- (Eq a, Ord b) shows up as a tuple type. Only boxed tuples can @@ -1027,22 +1027,22 @@ checkContext orig_t@(L (SrcSpanAnn _ l) _orig_t) = -- Ditto () = do let (op,cp,cs') = case ann' of - ApiAnnNotUsed -> ([],[],noCom) - ApiAnn _ (AnnParen _ o c) cs -> ([o],[c],cs) - return (L (SrcSpanAnn (ApiAnn (spanAsAnchor l) + EpAnnNotUsed -> ([],[],noCom) + EpAnn _ (AnnParen _ o c) cs -> ([o],[c],cs) + return (L (SrcSpanAnn (EpAnn (spanAsAnchor l) (AnnContext Nothing (op Semi.<> oparens) (cp Semi.<> cparens)) (cs Semi.<> cs')) l) ts) check (opi,cpi,csi) (L _lp1 (HsParTy ann' ty)) -- to be sure HsParTy doesn't get into the way = do let (op,cp,cs') = case ann' of - ApiAnnNotUsed -> ([],[],noCom) - ApiAnn _ (AnnParen _ open close ) cs -> ([open],[close],cs) + EpAnnNotUsed -> ([],[],noCom) + EpAnn _ (AnnParen _ open close ) cs -> ([open],[close],cs) check (op++opi,cp++cpi,cs' Semi.<> csi) ty -- No need for anns, returning original check (_opi,_cpi,_csi) _t = - return (L (SrcSpanAnn (ApiAnn (spanAsAnchor l) (AnnContext Nothing [] []) noCom) l) [orig_t]) + return (L (SrcSpanAnn (EpAnn (spanAsAnchor l) (AnnContext Nothing [] []) noCom) l) [orig_t]) checkImportDecl :: Maybe AnnAnchor -> Maybe AnnAnchor @@ -1148,7 +1148,7 @@ checkAPat loc e0 = do (L l p) <- checkLPat e let aa = [AddEpAnn ai o, AddEpAnn ac c] (ai,ac) = parenTypeKws pt - return (ParPat (ApiAnn (spanAsAnchor $ (widenSpan (locA l) aa)) an noCom) (L l p)) + return (ParPat (EpAnn (spanAsAnchor $ (widenSpan (locA l) aa)) an noCom) (L l p)) _ -> patFail (locA loc) (ppr e0) placeHolderPunRhs :: DisambECP b => PV (LocatedA b) @@ -1211,7 +1211,7 @@ checkFunBind strictness locF ann lhs_loc fun is_infix pats (L rhs_span grhss) let match_span = noAnnSrcSpan $ combineSrcSpans lhs_loc rhs_span cs <- getCommentsFor locF return (makeFunBind fun (L (noAnnSrcSpan $ locA match_span) - [L match_span (Match { m_ext = ApiAnn (spanAsAnchor locF) ann cs + [L match_span (Match { m_ext = EpAnn (spanAsAnchor locF) ann cs , m_ctxt = FunRhs { mc_fun = fun , mc_fixity = is_infix @@ -1240,10 +1240,10 @@ checkPatBind :: SrcSpan -> LPat GhcPs -> Located (GRHSs GhcPs (LHsExpr GhcPs)) -> P (HsBind GhcPs) -checkPatBind loc annsIn (L _ (BangPat (ApiAnn _ ans cs) (L _ (VarPat _ v)))) +checkPatBind loc annsIn (L _ (BangPat (EpAnn _ ans cs) (L _ (VarPat _ v)))) (L _match_span grhss) = return (makeFunBind v (L (noAnnSrcSpan loc) - [L (noAnnSrcSpan loc) (m (ApiAnn (spanAsAnchor loc) (ans++annsIn) cs) v)])) + [L (noAnnSrcSpan loc) (m (EpAnn (spanAsAnchor loc) (ans++annsIn) cs) v)])) where m a v = Match { m_ext = a , m_ctxt = FunRhs { mc_fun = v @@ -1254,7 +1254,7 @@ checkPatBind loc annsIn (L _ (BangPat (ApiAnn _ ans cs) (L _ (VarPat _ v)))) checkPatBind loc annsIn lhs (L _ grhss) = do cs <- getCommentsFor loc - return (PatBind (ApiAnn (spanAsAnchor loc) annsIn cs) lhs grhss ([],[])) + return (PatBind (EpAnn (spanAsAnchor loc) annsIn cs) lhs grhss ([],[])) checkValSigLhs :: LHsExpr GhcPs -> P (LocatedN RdrName) checkValSigLhs (L _ (HsVar _ lrdr@(L _ v))) @@ -1291,8 +1291,8 @@ isFunLhs e = go e [] [] | not (isRdrDataCon f) = return (Just (L loc f, Prefix, es, ann)) go (L _ (PatBuilderApp f e)) es ann = go f (e:es) ann go (L l (PatBuilderPar e _an)) es@(_:_) ann - = go e es (ann ++ mkParensApiAnn (locA l)) - go (L loc (PatBuilderOpApp l (L loc' op) r (ApiAnn loca anns cs))) es ann + = go e es (ann ++ mkParensEpAnn (locA l)) + go (L loc (PatBuilderOpApp l (L loc' op) r (EpAnn loca anns cs))) es ann | not (isRdrDataCon op) -- We have found the function! = return (Just (L loc' op, Infix, (l:r:es), (anns ++ ann))) | otherwise -- Infix data con; keep going @@ -1302,11 +1302,11 @@ isFunLhs e = go e [] [] -> return (Just (op', Infix, j : op_app : es', ann')) where op_app = L loc (PatBuilderOpApp k - (L loc' op) r (ApiAnn loca anns cs)) + (L loc' op) r (EpAnn loca anns cs)) _ -> return Nothing } go _ _ _ = return Nothing -mkBangTy :: ApiAnn -> SrcStrictness -> LHsType GhcPs -> HsType GhcPs +mkBangTy :: EpAnn -> SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy anns strictness = HsBangTy anns (HsSrcBang NoSourceText NoSrcUnpack strictness) @@ -1319,7 +1319,7 @@ addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do let l' = combineSrcSpans lprag (getLocA ty) cs <- getCommentsFor l' - let an = ApiAnn (spanAsAnchor l') anns cs + let an = EpAnn (spanAsAnchor l') anns cs t' = addUnpackedness an ty return (L (noAnnSrcSpan l') t') where @@ -1381,7 +1381,7 @@ type Fbind b = Either (LHsRecField GhcPs (LocatedA b)) (LHsRecProj GhcPs (Locate class DisambInfixOp b where mkHsVarOpPV :: LocatedN RdrName -> PV (LocatedN b) mkHsConOpPV :: LocatedN RdrName -> PV (LocatedN b) - mkHsInfixHolePV :: SrcSpan -> (ApiAnnComments -> ApiAnn' ApiAnnUnboundVar) -> PV (Located b) + mkHsInfixHolePV :: SrcSpan -> (EpAnnComments -> EpAnn' EpAnnUnboundVar) -> PV (Located b) instance DisambInfixOp (HsExpr GhcPs) where mkHsVarOpPV v = return $ L (getLoc v) (HsVar noExtField v) @@ -1418,7 +1418,7 @@ class (b ~ (Body b) GhcPs, AnnoBody b) => DisambECP b where -> LocatedA b -> Bool -> [AddEpAnn] -> PV (LHsRecProj GhcPs (LocatedA b)) -- | Disambiguate "\... -> ..." (lambda) mkHsLamPV - :: SrcSpan -> (ApiAnnComments -> MatchGroup GhcPs (LocatedA b)) -> PV (LocatedA b) + :: SrcSpan -> (EpAnnComments -> MatchGroup GhcPs (LocatedA b)) -> PV (LocatedA b) -- | Disambiguate "let ... in ..." mkHsLetPV :: SrcSpan -> HsLocalBinds GhcPs -> LocatedA b -> AnnsLet -> PV (LocatedA b) @@ -1433,7 +1433,7 @@ class (b ~ (Body b) GhcPs, AnnoBody b) => DisambECP b where -> PV (LocatedA b) -- | Disambiguate "case ... of ..." mkHsCasePV :: SrcSpan -> LHsExpr GhcPs -> (LocatedL [LMatch GhcPs (LocatedA b)]) - -> ApiAnnHsCase -> PV (LocatedA b) + -> EpAnnHsCase -> PV (LocatedA b) mkHsLamCasePV :: SrcSpan -> (LocatedL [LMatch GhcPs (LocatedA b)]) -> [AddEpAnn] -> PV (LocatedA b) @@ -1563,21 +1563,21 @@ instance DisambECP (HsCmd GhcPs) where return $ L (noAnnSrcSpan l) (HsCmdLam NoExtField (mg cs)) mkHsLetPV l bs e anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsCmdLet (ApiAnn (spanAsAnchor l) anns cs) bs e) + return $ L (noAnnSrcSpan l) (HsCmdLet (EpAnn (spanAsAnchor l) anns cs) bs e) type InfixOp (HsCmd GhcPs) = HsExpr GhcPs superInfixOp m = m mkHsOpAppPV l c1 op c2 = do let cmdArg c = L (getLocA c) $ HsCmdTop noExtField c cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) $ HsCmdArrForm (ApiAnn (spanAsAnchor l) (AnnList Nothing Nothing Nothing [] []) cs) (reLocL op) Infix Nothing [cmdArg c1, cmdArg c2] + return $ L (noAnnSrcSpan l) $ HsCmdArrForm (EpAnn (spanAsAnchor l) (AnnList Nothing Nothing Nothing [] []) cs) (reLocL op) Infix Nothing [cmdArg c1, cmdArg c2] mkHsCasePV l c (L lm m) anns = do cs <- getCommentsFor l let mg = mkMatchGroup FromSource (L lm m) - return $ L (noAnnSrcSpan l) (HsCmdCase (ApiAnn (spanAsAnchor l) anns cs) c mg) + return $ L (noAnnSrcSpan l) (HsCmdCase (EpAnn (spanAsAnchor l) anns cs) c mg) mkHsLamCasePV l (L lm m) anns = do cs <- getCommentsFor l let mg = mkMatchGroup FromSource (L lm m) - return $ L (noAnnSrcSpan l) (HsCmdLamCase (ApiAnn (spanAsAnchor l) anns cs) mg) + return $ L (noAnnSrcSpan l) (HsCmdLamCase (EpAnn (spanAsAnchor l) anns cs) mg) type FunArg (HsCmd GhcPs) = HsExpr GhcPs superFunArg m = m mkHsAppPV l c e = do @@ -1589,14 +1589,14 @@ instance DisambECP (HsCmd GhcPs) where mkHsIfPV l c semi1 a semi2 b anns = do checkDoAndIfThenElse PsErrSemiColonsInCondCmd c semi1 a semi2 b cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (mkHsCmdIf c a b (ApiAnn (spanAsAnchor l) anns cs)) + return $ L (noAnnSrcSpan l) (mkHsCmdIf c a b (EpAnn (spanAsAnchor l) anns cs)) mkHsDoPV l Nothing stmts anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsCmdDo (ApiAnn (spanAsAnchor l) anns cs) stmts) + return $ L (noAnnSrcSpan l) (HsCmdDo (EpAnn (spanAsAnchor l) anns cs) stmts) mkHsDoPV l (Just m) _ _ = addFatalError $ PsError (PsErrQualifiedDoInCmd m) [] l mkHsParPV l c ann = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsCmdPar (ApiAnn (spanAsAnchor l) ann cs) c) + return $ L (noAnnSrcSpan l) (HsCmdPar (EpAnn (spanAsAnchor l) ann cs) c) mkHsVarPV (L l v) = cmdFail (locA l) (ppr v) mkHsLitPV (L l a) = cmdFail l (ppr a) mkHsOverLitPV (L l a) = cmdFail l (ppr a) @@ -1637,26 +1637,26 @@ instance DisambECP (HsExpr GhcPs) where ecpFromExp' = return mkHsProjUpdatePV l fields arg isPun anns = do cs <- getCommentsFor l - return $ mkRdrProjUpdate (noAnnSrcSpan l) fields arg isPun (ApiAnn (spanAsAnchor l) anns cs) + return $ mkRdrProjUpdate (noAnnSrcSpan l) fields arg isPun (EpAnn (spanAsAnchor l) anns cs) mkHsLamPV l mg = do cs <- getCommentsFor l return $ L (noAnnSrcSpan l) (HsLam NoExtField (mg cs)) mkHsLetPV l bs c anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsLet (ApiAnn (spanAsAnchor l) anns cs) bs c) + return $ L (noAnnSrcSpan l) (HsLet (EpAnn (spanAsAnchor l) anns cs) bs c) type InfixOp (HsExpr GhcPs) = HsExpr GhcPs superInfixOp m = m mkHsOpAppPV l e1 op e2 = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) $ OpApp (ApiAnn (spanAsAnchor l) [] cs) e1 (reLocL op) e2 + return $ L (noAnnSrcSpan l) $ OpApp (EpAnn (spanAsAnchor l) [] cs) e1 (reLocL op) e2 mkHsCasePV l e (L lm m) anns = do cs <- getCommentsFor l let mg = mkMatchGroup FromSource (L lm m) - return $ L (noAnnSrcSpan l) (HsCase (ApiAnn (spanAsAnchor l) anns cs) e mg) + return $ L (noAnnSrcSpan l) (HsCase (EpAnn (spanAsAnchor l) anns cs) e mg) mkHsLamCasePV l (L lm m) anns = do cs <- getCommentsFor l let mg = mkMatchGroup FromSource (L lm m) - return $ L (noAnnSrcSpan l) (HsLamCase (ApiAnn (spanAsAnchor l) anns cs) mg) + return $ L (noAnnSrcSpan l) (HsLamCase (EpAnn (spanAsAnchor l) anns cs) mg) type FunArg (HsExpr GhcPs) = HsExpr GhcPs superFunArg m = m mkHsAppPV l e1 e2 = do @@ -1670,13 +1670,13 @@ instance DisambECP (HsExpr GhcPs) where mkHsIfPV l c semi1 a semi2 b anns = do checkDoAndIfThenElse PsErrSemiColonsInCondExpr c semi1 a semi2 b cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (mkHsIf c a b (ApiAnn (spanAsAnchor l) anns cs)) + return $ L (noAnnSrcSpan l) (mkHsIf c a b (EpAnn (spanAsAnchor l) anns cs)) mkHsDoPV l mod stmts anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsDo (ApiAnn (spanAsAnchor l) anns cs) (DoExpr mod) stmts) + return $ L (noAnnSrcSpan l) (HsDo (EpAnn (spanAsAnchor l) anns cs) (DoExpr mod) stmts) mkHsParPV l e ann = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsPar (ApiAnn (spanAsAnchor l) ann cs) e) + return $ L (noAnnSrcSpan l) (HsPar (EpAnn (spanAsAnchor l) ann cs) e) mkHsVarPV v@(L l _) = return $ L (na2la l) (HsVar noExtField v) mkHsLitPV (L l a) = do cs <- getCommentsFor l @@ -1687,20 +1687,20 @@ instance DisambECP (HsExpr GhcPs) where mkHsWildCardPV l = return $ L l (hsHoleExpr noAnn) mkHsTySigPV l a sig anns = do cs <- getCommentsFor (locA l) - return $ L l (ExprWithTySig (ApiAnn (spanAsAnchor $ locA l) anns cs) a (hsTypeToHsSigWcType sig)) + return $ L l (ExprWithTySig (EpAnn (spanAsAnchor $ locA l) anns cs) a (hsTypeToHsSigWcType sig)) mkHsExplicitListPV l xs anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (ExplicitList (ApiAnn (spanAsAnchor l) anns cs) xs) + return $ L (noAnnSrcSpan l) (ExplicitList (EpAnn (spanAsAnchor l) anns cs) xs) mkHsSplicePV sp@(L l _) = do cs <- getCommentsFor l - return $ mapLoc (HsSpliceE (ApiAnn (spanAsAnchor l) NoApiAnns cs)) sp + return $ mapLoc (HsSpliceE (EpAnn (spanAsAnchor l) NoEpAnns cs)) sp mkHsRecordPV opts l lrec a (fbinds, ddLoc) anns = do cs <- getCommentsFor l - r <- mkRecConstrOrUpdate opts a lrec (fbinds, ddLoc) (ApiAnn (spanAsAnchor l) anns cs) + r <- mkRecConstrOrUpdate opts a lrec (fbinds, ddLoc) (EpAnn (spanAsAnchor l) anns cs) checkRecordSyntax (L (noAnnSrcSpan l) r) mkHsNegAppPV l a anns = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (NegApp (ApiAnn (spanAsAnchor l) anns cs) a noSyntaxExpr) + return $ L (noAnnSrcSpan l) (NegApp (EpAnn (spanAsAnchor l) anns cs) a noSyntaxExpr) mkHsSectionR_PV l op e = do cs <- getCommentsFor l return $ L l (SectionR (comment (realSrcSpan l) cs) op e) @@ -1719,7 +1719,7 @@ instance DisambECP (HsExpr GhcPs) where rejectPragmaPV (L l (HsPragE _ prag _)) = addError $ PsError (PsErrUnallowedPragma prag) [] (locA l) rejectPragmaPV _ = return () -hsHoleExpr :: ApiAnn' ApiAnnUnboundVar -> HsExpr GhcPs +hsHoleExpr :: EpAnn' EpAnnUnboundVar -> HsExpr GhcPs hsHoleExpr anns = HsUnboundVar anns (mkVarOcc "_") type instance Anno (GRHS GhcPs (LocatedA (PatBuilder GhcPs))) = SrcSpan @@ -1738,7 +1738,7 @@ instance DisambECP (PatBuilder GhcPs) where superInfixOp m = m mkHsOpAppPV l p1 op p2 = do cs <- getCommentsFor l - let anns = ApiAnn (spanAsAnchor l) [] cs + let anns = EpAnn (spanAsAnchor l) [] cs return $ L (noAnnSrcSpan l) $ PatBuilderOpApp p1 op p2 anns mkHsCasePV l _ _ _ = addFatalError $ PsError PsErrCaseInPat [] l mkHsLamCasePV l _ _ = addFatalError $ PsError PsErrLambdaCaseInPat [] l @@ -1758,11 +1758,11 @@ instance DisambECP (PatBuilder GhcPs) where mkHsTySigPV l b sig anns = do p <- checkLPat b cs <- getCommentsFor (locA l) - return $ L l (PatBuilderPat (SigPat (ApiAnn (spanAsAnchor $ locA l) anns cs) p (mkHsPatSigType sig))) + return $ L l (PatBuilderPat (SigPat (EpAnn (spanAsAnchor $ locA l) anns cs) p (mkHsPatSigType sig))) mkHsExplicitListPV l xs anns = do ps <- traverse checkLPat xs cs <- getCommentsFor l - return (L (noAnnSrcSpan l) (PatBuilderPat (ListPat (ApiAnn (spanAsAnchor l) anns cs) ps))) + return (L (noAnnSrcSpan l) (PatBuilderPat (ListPat (EpAnn (spanAsAnchor l) anns cs) ps))) mkHsSplicePV (L l sp) = return $ L l (PatBuilderPat (SplicePat noExtField sp)) mkHsRecordPV _ l _ a (fbinds, ddLoc) anns = do let (fs, ps) = partitionEithers fbinds @@ -1770,32 +1770,32 @@ instance DisambECP (PatBuilder GhcPs) where then addFatalError $ PsError PsErrOverloadedRecordDotInvalid [] l else do cs <- getCommentsFor l - r <- mkPatRec a (mk_rec_fields fs ddLoc) (ApiAnn (spanAsAnchor l) anns cs) + r <- mkPatRec a (mk_rec_fields fs ddLoc) (EpAnn (spanAsAnchor l) anns cs) checkRecordSyntax (L (noAnnSrcSpan l) r) mkHsNegAppPV l (L lp p) anns = do lit <- case p of PatBuilderOverLit pos_lit -> return (L (locA lp) pos_lit) _ -> patFail l (text "-" <> ppr p) cs <- getCommentsFor l - let an = ApiAnn (spanAsAnchor l) anns cs + let an = EpAnn (spanAsAnchor l) anns cs return $ L (noAnnSrcSpan l) (PatBuilderPat (mkNPat lit (Just noSyntaxExpr) an)) mkHsSectionR_PV l op p = patFail l (pprInfixOcc (unLoc op) <> ppr p) mkHsViewPatPV l a b anns = do p <- checkLPat b cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (PatBuilderPat (ViewPat (ApiAnn (spanAsAnchor l) anns cs) a p)) + return $ L (noAnnSrcSpan l) (PatBuilderPat (ViewPat (EpAnn (spanAsAnchor l) anns cs) a p)) mkHsAsPatPV l v e a = do p <- checkLPat e cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (PatBuilderPat (AsPat (ApiAnn (spanAsAnchor l) a cs) v p)) + return $ L (noAnnSrcSpan l) (PatBuilderPat (AsPat (EpAnn (spanAsAnchor l) a cs) v p)) mkHsLazyPatPV l e a = do p <- checkLPat e cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (PatBuilderPat (LazyPat (ApiAnn (spanAsAnchor l) a cs) p)) + return $ L (noAnnSrcSpan l) (PatBuilderPat (LazyPat (EpAnn (spanAsAnchor l) a cs) p)) mkHsBangPatPV l e an = do p <- checkLPat e cs <- getCommentsFor l - let pb = BangPat (ApiAnn (spanAsAnchor l) an cs) p + let pb = BangPat (EpAnn (spanAsAnchor l) an cs) p hintBangPat l pb return $ L (noAnnSrcSpan l) (PatBuilderPat pb) mkSumOrTuplePV = mkSumOrTuplePat @@ -1811,7 +1811,7 @@ checkUnboxedStringLitPat (L loc lit) = mkPatRec :: LocatedA (PatBuilder GhcPs) -> HsRecFields GhcPs (LocatedA (PatBuilder GhcPs)) -> - ApiAnn -> + EpAnn -> PV (PatBuilder GhcPs) mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) anns | isRdrDataCon (unLoc c) @@ -2377,7 +2377,7 @@ mkRecConstrOrUpdate -> LHsExpr GhcPs -> SrcSpan -> ([Fbind (HsExpr GhcPs)], Maybe SrcSpan) - -> ApiAnn + -> EpAnn -> PV (HsExpr GhcPs) mkRecConstrOrUpdate _ (L _ (HsVar _ (L l c))) _lrec (fbinds,dd) anns | isRdrDataCon c @@ -2390,7 +2390,7 @@ mkRecConstrOrUpdate overloaded_update exp _ (fs,dd) anns | Just dd_loc <- dd = addFatalError $ PsError PsErrDotsInRecordUpdate [] dd_loc | otherwise = mkRdrRecordUpd overloaded_update exp fs anns -mkRdrRecordUpd :: Bool -> LHsExpr GhcPs -> [Fbind (HsExpr GhcPs)] -> ApiAnn -> PV (HsExpr GhcPs) +mkRdrRecordUpd :: Bool -> LHsExpr GhcPs -> [Fbind (HsExpr GhcPs)] -> EpAnn -> PV (HsExpr GhcPs) mkRdrRecordUpd overloaded_on exp@(L loc _) fbinds anns = do -- We do not need to know if OverloadedRecordDot is in effect. We do -- however need to know if OverloadedRecordUpdate (passed in @@ -2443,7 +2443,7 @@ mkRdrRecordUpd overloaded_on exp@(L loc _) fbinds anns = do punnedVar f = if not pun then arg else noLocA . HsVar noExtField . noLocA . mkRdrUnqual . mkVarOccFS $ f mkRdrRecordCon - :: LocatedN RdrName -> HsRecordBinds GhcPs -> ApiAnn -> HsExpr GhcPs + :: LocatedN RdrName -> HsRecordBinds GhcPs -> EpAnn -> HsExpr GhcPs mkRdrRecordCon con flds anns = RecordCon { rcon_ext = anns, rcon_con = con, rcon_flds = flds } @@ -2482,7 +2482,7 @@ mkInlinePragma src (inl, match_info) mb_act mkImport :: Located CCallConv -> Located Safety -> (Located StringLiteral, LocatedN RdrName, LHsSigType GhcPs) - -> P (ApiAnn -> HsDecl GhcPs) + -> P (EpAnn -> HsDecl GhcPs) mkImport cconv safety (L loc (StringLiteral esrc entity _), v, ty) = case unLoc cconv of CCallConv -> mkCImport @@ -2583,7 +2583,7 @@ parseCImport cconv safety nm str sourceText = -- mkExport :: Located CCallConv -> (Located StringLiteral, LocatedN RdrName, LHsSigType GhcPs) - -> P (ApiAnn -> HsDecl GhcPs) + -> P (EpAnn -> HsDecl GhcPs) mkExport (L lc cconv) (L le (StringLiteral esrc entity _), v, ty) = return $ \ann -> ForD noExtField $ ForeignExport { fd_e_ext = ann, fd_name = v, fd_sig_ty = ty @@ -2617,7 +2617,7 @@ data ImpExpQcSpec = ImpExpQcName (LocatedN RdrName) mkModuleImpExp :: [AddEpAnn] -> LocatedA ImpExpQcSpec -> ImpExpSubSpec -> P (IE GhcPs) mkModuleImpExp anns (L l specname) subs = do cs <- getCommentsFor (locA l) -- AZ: IEVar can discard comments - let ann = ApiAnn (spanAsAnchor $ locA l) anns cs + let ann = EpAnn (spanAsAnchor $ locA l) anns cs case subs of ImpExpAbs | isVarNameSpace (rdrNameSpace name) @@ -2883,9 +2883,9 @@ mkSumOrTupleExpr :: SrcSpanAnnA -> Boxity -> SumOrTuple (HsExpr GhcPs) -- Tuple mkSumOrTupleExpr l boxity (Tuple es) anns = do cs <- getCommentsFor (locA l) - return $ L l (ExplicitTuple (ApiAnn (spanAsAnchor $ locA l) anns cs) (map toTupArg es) boxity) + return $ L l (ExplicitTuple (EpAnn (spanAsAnchor $ locA l) anns cs) (map toTupArg es) boxity) where - toTupArg :: Either (ApiAnn' AnnAnchor) (LHsExpr GhcPs) -> HsTupArg GhcPs + toTupArg :: Either (EpAnn' AnnAnchor) (LHsExpr GhcPs) -> HsTupArg GhcPs toTupArg (Left ann) = missingTupArg ann toTupArg (Right a) = Present noAnn a @@ -2898,7 +2898,7 @@ mkSumOrTupleExpr l Unboxed (Sum alt arity e barsp barsa) anns = do AnnExplicitSum o barsp barsa c _ -> panic "mkSumOrTupleExpr" cs <- getCommentsFor (locA l) - return $ L l (ExplicitSum (ApiAnn (spanAsAnchor $ locA l) an cs) alt arity e) + return $ L l (ExplicitSum (EpAnn (spanAsAnchor $ locA l) an cs) alt arity e) mkSumOrTupleExpr l Boxed a@Sum{} _ = addFatalError $ PsError (PsErrUnsupportedBoxedSumExpr a) [] (locA l) @@ -2910,9 +2910,9 @@ mkSumOrTuplePat mkSumOrTuplePat l boxity (Tuple ps) anns = do ps' <- traverse toTupPat ps cs <- getCommentsFor (locA l) - return $ L l (PatBuilderPat (TuplePat (ApiAnn (spanAsAnchor $ locA l) anns cs) ps' boxity)) + return $ L l (PatBuilderPat (TuplePat (EpAnn (spanAsAnchor $ locA l) anns cs) ps' boxity)) where - toTupPat :: Either (ApiAnn' AnnAnchor) (LocatedA (PatBuilder GhcPs)) -> PV (LPat GhcPs) + toTupPat :: Either (EpAnn' AnnAnchor) (LocatedA (PatBuilder GhcPs)) -> PV (LPat GhcPs) -- Ignore the element location so that the error message refers to the -- entire tuple. See #19504 (and the discussion) for details. toTupPat p = case p of @@ -2923,7 +2923,7 @@ mkSumOrTuplePat l boxity (Tuple ps) anns = do mkSumOrTuplePat l Unboxed (Sum alt arity p barsb barsa) anns = do p' <- checkLPat p cs <- getCommentsFor (locA l) - let an = ApiAnn (spanAsAnchor $ locA l) (ApiAnnSumPat anns barsb barsa) cs + let an = EpAnn (spanAsAnchor $ locA l) (EpAnnSumPat anns barsb barsa) cs return $ L l (PatBuilderPat (SumPat an p' alt arity)) mkSumOrTuplePat l Boxed a@Sum{} _ = addFatalError $ PsError (PsErrUnsupportedBoxedSumPat a) [] (locA l) @@ -2950,7 +2950,7 @@ starSym False = "*" -- Bits and pieces for RecordDotSyntax. mkRdrGetField :: SrcSpanAnnA -> LHsExpr GhcPs -> Located (HsFieldLabel GhcPs) - -> ApiAnnCO -> LHsExpr GhcPs + -> EpAnnCO -> LHsExpr GhcPs mkRdrGetField loc arg field anns = L loc HsGetField { gf_ext = anns @@ -2958,7 +2958,7 @@ mkRdrGetField loc arg field anns = , gf_field = field } -mkRdrProjection :: [Located (HsFieldLabel GhcPs)] -> ApiAnn' AnnProjection -> HsExpr GhcPs +mkRdrProjection :: [Located (HsFieldLabel GhcPs)] -> EpAnn' AnnProjection -> HsExpr GhcPs mkRdrProjection [] _ = panic "mkRdrProjection: The impossible has happened!" mkRdrProjection flds anns = HsProjection { @@ -2967,7 +2967,7 @@ mkRdrProjection flds anns = } mkRdrProjUpdate :: SrcSpanAnnA -> Located [Located (HsFieldLabel GhcPs)] - -> LHsExpr GhcPs -> Bool -> ApiAnn + -> LHsExpr GhcPs -> Bool -> EpAnn -> LHsRecProj GhcPs (LHsExpr GhcPs) mkRdrProjUpdate _ (L _ []) _ _ _ = panic "mkRdrProjUpdate: The impossible has happened!" mkRdrProjUpdate loc (L l flds) arg isPun anns = diff --git a/compiler/GHC/Parser/Types.hs b/compiler/GHC/Parser/Types.hs index 843685ea36..5c3ff72597 100644 --- a/compiler/GHC/Parser/Types.hs +++ b/compiler/GHC/Parser/Types.hs @@ -28,7 +28,7 @@ import Language.Haskell.Syntax data SumOrTuple b = Sum ConTag Arity (LocatedA b) [AnnAnchor] [AnnAnchor] -- ^ Last two are the locations of the '|' before and after the payload - | Tuple [Either (ApiAnn' AnnAnchor) (LocatedA b)] + | Tuple [Either (EpAnn' AnnAnchor) (LocatedA b)] pprSumOrTuple :: Outputable b => Boxity -> SumOrTuple b -> SDoc pprSumOrTuple boxity = \case @@ -56,7 +56,7 @@ data PatBuilder p | PatBuilderApp (LocatedA (PatBuilder p)) (LocatedA (PatBuilder p)) | PatBuilderAppType (LocatedA (PatBuilder p)) SrcSpan (HsPatSigType GhcPs) | PatBuilderOpApp (LocatedA (PatBuilder p)) (LocatedN RdrName) - (LocatedA (PatBuilder p)) ApiAnn + (LocatedA (PatBuilder p)) EpAnn | PatBuilderVar (LocatedN RdrName) | PatBuilderOverLit (HsOverLit GhcPs) |