{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeepSubsumption #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Ormolu.Diff.ParseResult
( ParseResultDiff (..),
diffParseResult,
)
where
import Data.ByteString (ByteString)
import Data.Foldable
import Data.Function
import Data.Generics
import GHC.Data.FastString (FastString)
import GHC.Hs
import GHC.Types.SourceText
import GHC.Types.SrcLoc
import Ormolu.Parser.CommentStream
import Ormolu.Parser.Result
import Ormolu.Utils
import Type.Reflection qualified as TR
data ParseResultDiff
=
Same
|
Different [RealSrcSpan]
deriving (Int -> ParseResultDiff -> ShowS
[ParseResultDiff] -> ShowS
ParseResultDiff -> String
(Int -> ParseResultDiff -> ShowS)
-> (ParseResultDiff -> String)
-> ([ParseResultDiff] -> ShowS)
-> Show ParseResultDiff
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseResultDiff -> ShowS
showsPrec :: Int -> ParseResultDiff -> ShowS
$cshow :: ParseResultDiff -> String
show :: ParseResultDiff -> String
$cshowList :: [ParseResultDiff] -> ShowS
showList :: [ParseResultDiff] -> ShowS
Show)
instance Semigroup ParseResultDiff where
ParseResultDiff
Same <> :: ParseResultDiff -> ParseResultDiff -> ParseResultDiff
<> ParseResultDiff
a = ParseResultDiff
a
ParseResultDiff
a <> ParseResultDiff
Same = ParseResultDiff
a
Different [RealSrcSpan]
xs <> Different [RealSrcSpan]
ys = [RealSrcSpan] -> ParseResultDiff
Different ([RealSrcSpan]
xs [RealSrcSpan] -> [RealSrcSpan] -> [RealSrcSpan]
forall a. [a] -> [a] -> [a]
++ [RealSrcSpan]
ys)
instance Monoid ParseResultDiff where
mempty :: ParseResultDiff
mempty = ParseResultDiff
Same
diffParseResult ::
ParseResult ->
ParseResult ->
ParseResultDiff
diffParseResult :: ParseResult -> ParseResult -> ParseResultDiff
diffParseResult
ParseResult
{ prCommentStream :: ParseResult -> CommentStream
prCommentStream = CommentStream
cstream0,
prParsedSource :: ParseResult -> HsModule GhcPs
prParsedSource = HsModule GhcPs
hs0
}
ParseResult
{ prCommentStream :: ParseResult -> CommentStream
prCommentStream = CommentStream
cstream1,
prParsedSource :: ParseResult -> HsModule GhcPs
prParsedSource = HsModule GhcPs
hs1
} =
CommentStream -> CommentStream -> ParseResultDiff
diffCommentStream CommentStream
cstream0 CommentStream
cstream1
ParseResultDiff -> ParseResultDiff -> ParseResultDiff
forall a. Semigroup a => a -> a -> a
<> HsModule GhcPs -> HsModule GhcPs -> ParseResultDiff
diffHsModule HsModule GhcPs
hs0 HsModule GhcPs
hs1
diffCommentStream :: CommentStream -> CommentStream -> ParseResultDiff
(CommentStream [LComment]
cs) (CommentStream [LComment]
cs')
| [LComment] -> [Text]
forall {l}. [GenLocated l Comment] -> [Text]
commentLines [LComment]
cs [Text] -> [Text] -> Bool
forall a. Eq a => a -> a -> Bool
== [LComment] -> [Text]
forall {l}. [GenLocated l Comment] -> [Text]
commentLines [LComment]
cs' = ParseResultDiff
Same
| Bool
otherwise = [RealSrcSpan] -> ParseResultDiff
Different []
where
commentLines :: [GenLocated l Comment] -> [Text]
commentLines = (GenLocated l Comment -> [Text])
-> [GenLocated l Comment] -> [Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (NonEmpty Text -> [Text])
-> (GenLocated l Comment -> NonEmpty Text)
-> GenLocated l Comment
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comment -> NonEmpty Text
unComment (Comment -> NonEmpty Text)
-> (GenLocated l Comment -> Comment)
-> GenLocated l Comment
-> NonEmpty Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated l Comment -> Comment
forall l e. GenLocated l e -> e
unLoc)
diffHsModule :: HsModule GhcPs -> HsModule GhcPs -> ParseResultDiff
diffHsModule :: HsModule GhcPs -> HsModule GhcPs -> ParseResultDiff
diffHsModule = HsModule GhcPs -> HsModule GhcPs -> ParseResultDiff
HsModule GhcPs -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery
where
genericQuery :: GenericQ (GenericQ ParseResultDiff)
genericQuery :: GenericQ (GenericQ ParseResultDiff)
genericQuery a
x a
y
| Just ByteString
x' <- a -> Maybe ByteString
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast a
x,
Just ByteString
y' <- a -> Maybe ByteString
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast a
y =
if ByteString
x' ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== (ByteString
y' :: ByteString)
then ParseResultDiff
Same
else [RealSrcSpan] -> ParseResultDiff
Different []
| Just SomeTypeRep
rep <- a -> Maybe SomeTypeRep
forall a. Typeable a => a -> Maybe SomeTypeRep
isEpTokenish a
x,
Just SomeTypeRep
rep' <- a -> Maybe SomeTypeRep
forall a. Typeable a => a -> Maybe SomeTypeRep
isEpTokenish a
y =
if SomeTypeRep
rep SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== SomeTypeRep
rep' then ParseResultDiff
Same else [RealSrcSpan] -> ParseResultDiff
Different []
| a -> SomeTypeRep
forall a. Typeable a => a -> SomeTypeRep
typeOf a
x SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== a -> SomeTypeRep
forall a. Typeable a => a -> SomeTypeRep
typeOf a
y,
a -> Constr
forall a. Data a => a -> Constr
toConstr a
x Constr -> Constr -> Bool
forall a. Eq a => a -> a -> Bool
== a -> Constr
forall a. Data a => a -> Constr
toConstr a
y =
[ParseResultDiff] -> ParseResultDiff
forall a. Monoid a => [a] -> a
mconcat ([ParseResultDiff] -> ParseResultDiff)
-> [ParseResultDiff] -> ParseResultDiff
forall a b. (a -> b) -> a -> b
$
GenericQ (GenericQ ParseResultDiff)
-> GenericQ (GenericQ [ParseResultDiff])
forall r. GenericQ (GenericQ r) -> GenericQ (GenericQ [r])
gzipWithQ
( a -> a -> ParseResultDiff
a -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery
(a -> a -> ParseResultDiff)
-> (SrcSpan -> a -> ParseResultDiff) -> a -> a -> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @SrcSpan
(a -> a -> ParseResultDiff)
-> (forall e. Data e => EpAnn e -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall d (t :: * -> *) q.
(Data d, Typeable t) =>
(d -> q) -> (forall e. Data e => t e -> q) -> d -> q
`ext1Q` EpAnn e -> a -> ParseResultDiff
forall e. Data e => EpAnn e -> a -> ParseResultDiff
forall a b. EpAnn a -> b -> ParseResultDiff
epAnnEq
(a -> a -> ParseResultDiff)
-> (SourceText -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @SourceText
(a -> a -> ParseResultDiff)
-> (EpAnnComments -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @EpAnnComments
(a -> a -> ParseResultDiff)
-> (EpaLocation -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @EpaLocation
(a -> a -> ParseResultDiff)
-> (EpLayout -> a -> ParseResultDiff) -> a -> a -> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @EpLayout
(a -> a -> ParseResultDiff)
-> (AnnSig -> a -> ParseResultDiff) -> a -> a -> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @AnnSig
(a -> a -> ParseResultDiff)
-> (HsRuleAnn -> a -> ParseResultDiff) -> a -> a -> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @HsRuleAnn
(a -> a -> ParseResultDiff)
-> (EpLinearArrow -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @EpLinearArrow
(a -> a -> ParseResultDiff)
-> (AnnSynDecl -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual @AnnSynDecl
(a -> a -> ParseResultDiff)
-> (FastString -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` (FastString -> FastString -> Bool)
-> FastString -> GenericQ ParseResultDiff
forall {t}.
Typeable t =>
(t -> t -> Bool) -> t -> GenericQ ParseResultDiff
considerEqualVia' (forall a. Eq a => a -> a -> Bool
(==) @FastString)
(a -> a -> ParseResultDiff)
-> (HsDocString -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` HsDocString -> a -> ParseResultDiff
HsDocString -> GenericQ ParseResultDiff
hsDocStringEq
(a -> a -> ParseResultDiff)
-> (ImportDeclQualifiedStyle -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` ImportDeclQualifiedStyle -> a -> ParseResultDiff
ImportDeclQualifiedStyle -> GenericQ ParseResultDiff
importDeclQualifiedStyleEq
(a -> a -> ParseResultDiff)
-> (TyClDecl GhcPs -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` TyClDecl GhcPs -> a -> ParseResultDiff
TyClDecl GhcPs -> GenericQ ParseResultDiff
classDeclCtxEq
(a -> a -> ParseResultDiff)
-> (DerivClauseTys GhcPs -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` DerivClauseTys GhcPs -> a -> ParseResultDiff
DerivClauseTys GhcPs -> GenericQ ParseResultDiff
derivedTyClsParensEq
(a -> a -> ParseResultDiff)
-> (forall d1 d2.
(Data d1, Data d2) =>
GenLocated d1 d2 -> a -> ParseResultDiff)
-> a
-> a
-> ParseResultDiff
forall d (t :: * -> * -> *) q.
(Data d, Typeable t) =>
(d -> q)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q) -> d -> q
`ext2Q` GenLocated d1 d2 -> a -> ParseResultDiff
GenLocated d1 d2 -> GenericQ ParseResultDiff
forall d1 d2.
(Data d1, Data d2) =>
GenLocated d1 d2 -> a -> ParseResultDiff
forall e0 e1.
(Data e0, Data e1) =>
GenLocated e0 e1 -> GenericQ ParseResultDiff
forLocated
)
a
x
a
y
| Bool
otherwise = [RealSrcSpan] -> ParseResultDiff
Different []
isEpTokenish :: (Typeable a) => a -> Maybe TR.SomeTypeRep
isEpTokenish :: forall a. Typeable a => a -> Maybe SomeTypeRep
isEpTokenish = (TypeRep a -> SomeTypeRep)
-> Maybe (TypeRep a) -> Maybe SomeTypeRep
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
TR.SomeTypeRep (Maybe (TypeRep a) -> Maybe SomeTypeRep)
-> (a -> Maybe (TypeRep a)) -> a -> Maybe SomeTypeRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep a -> Maybe (TypeRep a)
forall {k} (a :: k). TypeRep a -> Maybe (TypeRep a)
go (TypeRep a -> Maybe (TypeRep a))
-> (a -> TypeRep a) -> a -> Maybe (TypeRep a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> TypeRep a
forall a. Typeable a => a -> TypeRep a
TR.typeOf
where
go :: TR.TypeRep a -> Maybe (TR.TypeRep a)
go :: forall {k} (a :: k). TypeRep a -> Maybe (TypeRep a)
go TypeRep a
rep = case TypeRep a
rep of
TR.App TypeRep a
t TypeRep b
t'
| Just a :~~: []
HRefl <- TypeRep a -> TypeRep [] -> Maybe (a :~~: [])
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
TR.eqTypeRep TypeRep a
t (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: * -> *). Typeable a => TypeRep a
TR.typeRep @[]) ->
TypeRep a -> TypeRep b -> TypeRep a
forall k2 (t :: k2) k1 (a :: k1 -> k2) (b :: k1).
(t ~ a b) =>
TypeRep a -> TypeRep b -> TypeRep t
TR.App TypeRep a
t (TypeRep b -> TypeRep a) -> Maybe (TypeRep b) -> Maybe (TypeRep a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypeRep b -> Maybe (TypeRep b)
forall {k} (a :: k). TypeRep a -> Maybe (TypeRep a)
go TypeRep b
t'
TR.App (TR.App TypeRep a
t TypeRep b
_) TypeRep b
_ ->
TypeRep a
rep TypeRep a -> Maybe (a :~~: EpUniToken) -> Maybe (TypeRep a)
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TypeRep a -> TypeRep EpUniToken -> Maybe (a :~~: EpUniToken)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
TR.eqTypeRep TypeRep a
t (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Symbol -> Symbol -> *). Typeable a => TypeRep a
TR.typeRep @EpUniToken)
TR.App TypeRep a
t TypeRep b
_ ->
TypeRep a
rep TypeRep a -> Maybe (a :~~: EpToken) -> Maybe (TypeRep a)
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TypeRep a -> TypeRep EpToken -> Maybe (a :~~: EpToken)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
TR.eqTypeRep TypeRep a
t (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Symbol -> *). Typeable a => TypeRep a
TR.typeRep @EpToken)
TypeRep a
_ -> Maybe (TypeRep a)
forall a. Maybe a
Nothing
considerEqualVia ::
forall a.
(Typeable a) =>
(a -> a -> ParseResultDiff) ->
a ->
GenericQ ParseResultDiff
considerEqualVia :: forall a.
Typeable a =>
(a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff
considerEqualVia a -> a -> ParseResultDiff
f a
x (a -> Maybe a
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast -> Just a
x') = a -> a -> ParseResultDiff
f a
x a
x'
considerEqualVia a -> a -> ParseResultDiff
_ a
_ a
_ = [RealSrcSpan] -> ParseResultDiff
Different []
considerEqualVia' :: (t -> t -> Bool) -> t -> GenericQ ParseResultDiff
considerEqualVia' t -> t -> Bool
f =
(t -> t -> ParseResultDiff) -> t -> GenericQ ParseResultDiff
forall a.
Typeable a =>
(a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff
considerEqualVia ((t -> t -> ParseResultDiff) -> t -> GenericQ ParseResultDiff)
-> (t -> t -> ParseResultDiff) -> t -> GenericQ ParseResultDiff
forall a b. (a -> b) -> a -> b
$ \t
x t
x' -> if t -> t -> Bool
f t
x t
x' then ParseResultDiff
Same else [RealSrcSpan] -> ParseResultDiff
Different []
considerEqual :: forall a. (Typeable a) => a -> GenericQ ParseResultDiff
considerEqual :: forall a. Typeable a => a -> GenericQ ParseResultDiff
considerEqual = (a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff
forall a.
Typeable a =>
(a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff
considerEqualVia ((a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff)
-> (a -> a -> ParseResultDiff) -> a -> GenericQ ParseResultDiff
forall a b. (a -> b) -> a -> b
$ \a
_ a
_ -> ParseResultDiff
Same
epAnnEq :: EpAnn a -> b -> ParseResultDiff
epAnnEq :: forall a b. EpAnn a -> b -> ParseResultDiff
epAnnEq EpAnn a
_ b
_ = ParseResultDiff
Same
importDeclQualifiedStyleEq :: ImportDeclQualifiedStyle -> GenericQ ParseResultDiff
importDeclQualifiedStyleEq = (ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool)
-> ImportDeclQualifiedStyle -> GenericQ ParseResultDiff
forall {t}.
Typeable t =>
(t -> t -> Bool) -> t -> GenericQ ParseResultDiff
considerEqualVia' ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
f
where
f :: ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
f ImportDeclQualifiedStyle
QualifiedPre ImportDeclQualifiedStyle
QualifiedPost = Bool
True
f ImportDeclQualifiedStyle
QualifiedPost ImportDeclQualifiedStyle
QualifiedPre = Bool
True
f ImportDeclQualifiedStyle
x ImportDeclQualifiedStyle
x' = ImportDeclQualifiedStyle
x ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
forall a. Eq a => a -> a -> Bool
== ImportDeclQualifiedStyle
x'
hsDocStringEq :: HsDocString -> GenericQ ParseResultDiff
hsDocStringEq :: HsDocString -> GenericQ ParseResultDiff
hsDocStringEq = (HsDocString -> HsDocString -> Bool)
-> HsDocString -> GenericQ ParseResultDiff
forall {t}.
Typeable t =>
(t -> t -> Bool) -> t -> GenericQ ParseResultDiff
considerEqualVia' ([Text] -> [Text] -> Bool
forall a. Eq a => a -> a -> Bool
(==) ([Text] -> [Text] -> Bool)
-> (HsDocString -> [Text]) -> HsDocString -> HsDocString -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` HsDocString -> [Text]
splitDocString)
forLocated ::
(Data e0, Data e1) =>
GenLocated e0 e1 ->
GenericQ ParseResultDiff
forLocated :: forall e0 e1.
(Data e0, Data e1) =>
GenLocated e0 e1 -> GenericQ ParseResultDiff
forLocated x :: GenLocated e0 e1
x@(L e0
mspn e1
_) a
y =
(ParseResultDiff -> ParseResultDiff)
-> (SrcSpan -> ParseResultDiff -> ParseResultDiff)
-> Maybe SrcSpan
-> ParseResultDiff
-> ParseResultDiff
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ParseResultDiff -> ParseResultDiff
forall a. a -> a
id SrcSpan -> ParseResultDiff -> ParseResultDiff
appendSpan (e0 -> Maybe SrcSpan
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast (e0 -> Maybe SrcSpan)
-> (forall e. Data e => EpAnn e -> Maybe SrcSpan)
-> e0
-> Maybe SrcSpan
forall d (t :: * -> *) q.
(Data d, Typeable t) =>
(d -> q) -> (forall e. Data e => t e -> q) -> d -> q
`ext1Q` (SrcSpan -> Maybe SrcSpan
forall a. a -> Maybe a
Just (SrcSpan -> Maybe SrcSpan)
-> (EpAnn e -> SrcSpan) -> EpAnn e -> Maybe SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EpAnn e -> SrcSpan
forall ann. EpAnn ann -> SrcSpan
epAnnLoc) (e0 -> Maybe SrcSpan) -> e0 -> Maybe SrcSpan
forall a b. (a -> b) -> a -> b
$ e0
mspn) (GenLocated e0 e1 -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery GenLocated e0 e1
x a
y)
where
epAnnLoc :: EpAnn ann -> SrcSpan
epAnnLoc :: forall ann. EpAnn ann -> SrcSpan
epAnnLoc = EpAnn ann -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA
appendSpan :: SrcSpan -> ParseResultDiff -> ParseResultDiff
appendSpan :: SrcSpan -> ParseResultDiff -> ParseResultDiff
appendSpan SrcSpan
s' d :: ParseResultDiff
d@(Different [RealSrcSpan]
ss) =
case SrcSpan
s' of
RealSrcSpan RealSrcSpan
s Maybe BufSpan
_ ->
if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (RealSrcSpan -> Bool) -> [RealSrcSpan] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (RealSrcSpan -> RealSrcSpan -> Bool
`isRealSubspanOf` RealSrcSpan
s) [RealSrcSpan]
ss
then [RealSrcSpan] -> ParseResultDiff
Different (RealSrcSpan
s RealSrcSpan -> [RealSrcSpan] -> [RealSrcSpan]
forall a. a -> [a] -> [a]
: [RealSrcSpan]
ss)
else ParseResultDiff
d
UnhelpfulSpan UnhelpfulSpanReason
_ -> ParseResultDiff
d
appendSpan SrcSpan
_ ParseResultDiff
d = ParseResultDiff
d
classDeclCtxEq :: TyClDecl GhcPs -> GenericQ ParseResultDiff
classDeclCtxEq :: TyClDecl GhcPs -> GenericQ ParseResultDiff
classDeclCtxEq ClassDecl {tcdCtxt :: forall pass. TyClDecl pass -> Maybe (LHsContext pass)
tcdCtxt = Just (L SrcSpanAnnC
_ []), LHsBinds GhcPs
[LSig GhcPs]
[LDocDecl GhcPs]
[LFamilyDecl GhcPs]
[LHsFunDep GhcPs]
[LTyFamDefltDecl GhcPs]
LexicalFixity
XClassDecl GhcPs
LIdP GhcPs
LHsQTyVars GhcPs
tcdCExt :: XClassDecl GhcPs
tcdLName :: LIdP GhcPs
tcdTyVars :: LHsQTyVars GhcPs
tcdFixity :: LexicalFixity
tcdFDs :: [LHsFunDep GhcPs]
tcdSigs :: [LSig GhcPs]
tcdMeths :: LHsBinds GhcPs
tcdATs :: [LFamilyDecl GhcPs]
tcdATDefs :: [LTyFamDefltDecl GhcPs]
tcdDocs :: [LDocDecl GhcPs]
tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdCExt :: forall pass. TyClDecl pass -> XClassDecl pass
tcdDocs :: forall pass. TyClDecl pass -> [LDocDecl pass]
tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
..} a
tc' = TyClDecl GhcPs -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery ClassDecl {tcdCtxt :: Maybe (LHsContext GhcPs)
tcdCtxt = Maybe
(GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
Maybe (LHsContext GhcPs)
forall a. Maybe a
Nothing, LHsBinds GhcPs
[LSig GhcPs]
[LDocDecl GhcPs]
[LFamilyDecl GhcPs]
[LHsFunDep GhcPs]
[LTyFamDefltDecl GhcPs]
LexicalFixity
XClassDecl GhcPs
LIdP GhcPs
LHsQTyVars GhcPs
tcdCExt :: XClassDecl GhcPs
tcdLName :: LIdP GhcPs
tcdTyVars :: LHsQTyVars GhcPs
tcdFixity :: LexicalFixity
tcdFDs :: [LHsFunDep GhcPs]
tcdSigs :: [LSig GhcPs]
tcdMeths :: LHsBinds GhcPs
tcdATs :: [LFamilyDecl GhcPs]
tcdATDefs :: [LTyFamDefltDecl GhcPs]
tcdDocs :: [LDocDecl GhcPs]
tcdATDefs :: [LTyFamDefltDecl GhcPs]
tcdATs :: [LFamilyDecl GhcPs]
tcdCExt :: XClassDecl GhcPs
tcdDocs :: [LDocDecl GhcPs]
tcdFDs :: [LHsFunDep GhcPs]
tcdFixity :: LexicalFixity
tcdLName :: LIdP GhcPs
tcdMeths :: LHsBinds GhcPs
tcdSigs :: [LSig GhcPs]
tcdTyVars :: LHsQTyVars GhcPs
..} a
tc'
classDeclCtxEq TyClDecl GhcPs
tc a
tc' = TyClDecl GhcPs -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery TyClDecl GhcPs
tc a
tc'
derivedTyClsParensEq :: DerivClauseTys GhcPs -> GenericQ ParseResultDiff
derivedTyClsParensEq :: DerivClauseTys GhcPs -> GenericQ ParseResultDiff
derivedTyClsParensEq (DctSingle NoExtField
XDctSingle GhcPs
NoExtField LHsSigType GhcPs
sigTy) a
dct' = DerivClauseTys GhcPs -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery (XDctMulti GhcPs -> [LHsSigType GhcPs] -> DerivClauseTys GhcPs
forall pass.
XDctMulti pass -> [LHsSigType pass] -> DerivClauseTys pass
DctMulti NoExtField
XDctMulti GhcPs
NoExtField [LHsSigType GhcPs
sigTy]) a
dct'
derivedTyClsParensEq DerivClauseTys GhcPs
dct a
dct' = DerivClauseTys GhcPs -> GenericQ ParseResultDiff
GenericQ (GenericQ ParseResultDiff)
genericQuery DerivClauseTys GhcPs
dct a
dct'