Skip to content

Commit 98f3fb3

Browse files
author
Santiago Weight
committed
wip
1 parent d5534b3 commit 98f3fb3

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

tests/Test/Transform.hs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import Test.HUnit
3131
transformTestsTT :: LibDir -> Test
3232
transformTestsTT libdir = TestLabel "transformTestsTT" $ TestList
3333
[
34-
mkTestModChange libdir addLocaLDecl5 "AddLocalDecl5.hs"
34+
mkTestModChange libdir addLocaLDecl5 "AddLocalDecl5.hs",
35+
mkTestModChange libdir addLocaLDecl7 "AddLocalDecl7.hs",
36+
mkTestModChange libdir addLocaLDecl8 "AddLocalDecl8.hs"
3537
]
3638

3739
transformTests :: LibDir -> Test
@@ -294,6 +296,7 @@ transformHighLevelTests libdir =
294296
, mkTestModChange libdir addLocaLDecl5 "AddLocalDecl5.hs"
295297
, mkTestModChange libdir addLocaLDecl6 "AddLocalDecl6.hs"
296298
, mkTestModChange libdir addLocaLDecl7 "AddLocalDecl7.hs"
299+
, mkTestModChange libdir addLocaLDecl8 "AddLocalDecl8.hs"
297300

298301
, mkTestModChange libdir rmDecl1 "RmDecl1.hs"
299302
, mkTestModChange libdir rmDecl2 "RmDecl2.hs"
@@ -484,6 +487,27 @@ prependDecl ldecl = \case
484487
L (SrcSpanAnn EpAnnNotUsed _) _ -> error "Unexpected EpAnnNotUsed"
485488
ldecl' = setEntryDP ldecl (getAnchorOpDp ancOp)
486489

490+
addLocaLDecl8 :: Changer
491+
addLocaLDecl8 libdir top = do
492+
Right (L ld (ValD _ decl)) <- withDynFlags libdir (\df -> parseDecl df "decl" "nn = 2")
493+
let decl' = setEntryDP (L ld decl) (DifferentLine 1 5)
494+
doAddLocal = do
495+
let lp = makeDeltaAst top
496+
ds <- balanceCommentsList =<< hsDecls lp
497+
ds' <- flip mapM ds $ \d -> do
498+
(d',_) <- modifyValD (getLocA d) d $ \_m ds -> do
499+
pure (appendDecl ds (wrapDecl decl'), Nothing)
500+
pure d'
501+
replaceDecls lp ds'
502+
(lp',_,w) <- runTransformT doAddLocal
503+
debugM $ "addLocaLDecl7:" ++ intercalate "\n" w
504+
return lp'
505+
506+
appendDecl :: [LHsDecl GhcPs] -> LHsDecl GhcPs -> [LHsDecl GhcPs]
507+
appendDecl old newDecl = case old of
508+
[] -> [setEntryDP newDecl (DifferentLine 1 2)]
509+
old' -> old' <> [setEntryDP newDecl (DifferentLine 1 0)]
510+
487511
getAnchorDp :: Anchor -> DeltaPos
488512
getAnchorDp (Anchor _ (MovedAnchor dp)) = dp
489513
getAnchorDp (Anchor _ UnchangedAnchor) = error "Unexpected UnchangedAnchor"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module AddLocalDecl8 where
2+
3+
d1 = 1
4+
where -- c1
5+
w1 = 1
6+
7+
d2 = 1
8+
where w2 = 1
9+
10+
d3 = 1
11+
where
12+
13+
d4 = 1
14+
15+
d5 = 1
16+
where -- c5
17+
18+
d6 = 1 where
19+
20+
d7 = 1 where -- c7
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module AddLocalDecl8 where
2+
3+
d1 = 1
4+
where -- c1
5+
w1 = 1
6+
nn = 2
7+
8+
d2 = 1
9+
where w2 = 1
10+
nn = 2
11+
12+
d3 = 1
13+
where
14+
nn = 2
15+
16+
d4 = 1
17+
where
18+
nn = 2
19+
20+
d5 = 1
21+
where
22+
nn = 2 -- c5
23+
24+
d6 = 1 where
25+
nn = 2
26+
27+
d7 = 1 where
28+
nn = 2 -- c7

0 commit comments

Comments
 (0)