module Seminal.Enumerator.Modules(enumerateChangesInModule) where
import Seminal.Compiler.API
import Seminal.Change (Change(Change), ChangeType (Removal), (<&&>), node)
import Seminal.Enumerator.Declarations (enumerateChangesInDeclaration, enumerateChangesInTypeDeclaration)
import Data.List.HT (splitEverywhere)
import Data.Functor ((<&>))
import Seminal.Enumerator.Bindings (enumerateChangesInFuncBinding)
enumerateChangesInModule :: HsModule -> [Change HsModule]
enumerateChangesInModule :: HsModule -> [Change HsModule]
enumerateChangesInModule HsModule
hsmod = case HsModule
hsmod of
HsModule {} -> [LHsDecl GhcPs] -> [Change [LHsDecl GhcPs]]
enumerateChangesAtModuleRoot (HsModule -> [LHsDecl GhcPs]
hsmodDecls HsModule
hsmod)
[Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
-> ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> HsModule)
-> [Change HsModule]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
decls -> HsModule
hsmod { hsmodDecls :: [LHsDecl GhcPs]
hsmodDecls = [LHsDecl GhcPs]
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
decls })
enumerateChangesAtModuleRoot :: [LHsDecl GhcPs] -> [Change [LHsDecl GhcPs]]
enumerateChangesAtModuleRoot :: [LHsDecl GhcPs] -> [Change [LHsDecl GhcPs]]
enumerateChangesAtModuleRoot [LHsDecl GhcPs]
list = [[Change [LHsDecl GhcPs]]] -> [Change [LHsDecl GhcPs]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Change [LHsDecl GhcPs]]] -> [Change [LHsDecl GhcPs]])
-> [[Change [LHsDecl GhcPs]]] -> [Change [LHsDecl GhcPs]]
forall a b. (a -> b) -> a -> b
$ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [LHsDecl GhcPs]
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
list [([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])]
-> (([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]])
-> [[Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
h, L SrcSpanAnn' (EpAnn AnnListItem)
l HsDecl GhcPs
removed, [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
t) -> let
(SrcSpanAnn EpAnn AnnListItem
_ SrcSpan
removedLoc) = SrcSpanAnn' (EpAnn AnnListItem)
l
followups :: [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
followups = Enumerator (HsDecl GhcPs)
enumerateChangesInDeclaration HsDecl GhcPs
removed SrcSpan
removedLoc [Change (HsDecl GhcPs)]
-> (HsDecl GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\HsDecl GhcPs
r -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
h [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [SrcSpanAnn' (EpAnn AnnListItem)
-> HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
l HsDecl GhcPs
r] [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
t)
in case HsDecl GhcPs
removed of
(ValD XValD GhcPs
v HsBind GhcPs
body) -> case HsBind GhcPs
body of
(FunBind {}) -> Enumerator (HsBind GhcPs)
enumerateChangesInFuncBinding HsBind GhcPs
body SrcSpan
removedLoc
[Change (HsBind GhcPs)]
-> (HsBind GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> [Change
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcSpanAnn' (EpAnn AnnListItem)
-> HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
l (HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> (HsBind GhcPs -> HsDecl GhcPs)
-> HsBind GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XValD GhcPs -> HsBind GhcPs -> HsDecl GhcPs
forall p. XValD p -> HsBind p -> HsDecl p
ValD XValD GhcPs
v)
[Change
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
change -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
h [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
change] [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
t)
HsBind GhcPs
_ -> []
(TyClD XTyClD GhcPs
x TyClDecl GhcPs
typeDecl) -> Enumerator (TyClDecl GhcPs)
enumerateChangesInTypeDeclaration TyClDecl GhcPs
typeDecl SrcSpan
removedLoc
[Change (TyClDecl GhcPs)]
-> (TyClDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> [Change
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcSpanAnn' (EpAnn AnnListItem)
-> HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
l (HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> (TyClDecl GhcPs -> HsDecl GhcPs)
-> TyClDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XTyClD GhcPs -> TyClDecl GhcPs -> HsDecl GhcPs
forall p. XTyClD p -> TyClDecl p -> HsDecl p
TyClD XTyClD GhcPs
x)
[Change
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
change -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
h [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
change] [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
t)
HsDecl GhcPs
_ -> [ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
-> SrcSpan
-> [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
-> String
-> ChangeType
-> Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall n. Outputable n => n -> ChangeNode n
node [LHsDecl GhcPs]
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
list) [[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall n. Outputable n => n -> ChangeNode n
node ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> ChangeNode
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a b. (a -> b) -> a -> b
$ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
h [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
t] SrcSpan
removedLoc [Change
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]]
followups String
"The removed expression does not type-check." ChangeType
Removal]