Comment out / Explain TODO on unused code

pull/325/head
Lennart Spitzner 2020-04-05 15:32:05 +02:00 committed by Joe Hermaszewski
parent 614bf3424d
commit 5a65ed2356
1 changed files with 49 additions and 48 deletions

View File

@ -3,7 +3,6 @@
module Language.Haskell.Brittany.Internal.ExactPrintUtils module Language.Haskell.Brittany.Internal.ExactPrintUtils
( parseModule ( parseModule
, parseModuleFromString , parseModuleFromString
, commentAnnFixTransform
, commentAnnFixTransformGlob , commentAnnFixTransformGlob
, extractToplevelAnns , extractToplevelAnns
, foldedAnnKeys , foldedAnnKeys
@ -189,54 +188,56 @@ commentAnnFixTransformGlob ast = do
ExactPrint.modifyAnnsT $ \anns -> Map.insert annKey1 ann1' anns ExactPrint.modifyAnnsT $ \anns -> Map.insert annKey1 ann1' anns
-- TODO: this is unused by now, but it contains one detail that
-- commentAnnFixTransformGlob does not include: Moving of comments for
-- "RecordUpd"s.
-- commentAnnFixTransform :: GHC.ParsedSource -> ExactPrint.Transform ()
-- commentAnnFixTransform modul = SYB.everything (>>) genF modul
-- where
-- genF :: Data.Data.Data a => a -> ExactPrint.Transform ()
-- genF = (\_ -> return ()) `SYB.extQ` exprF
-- exprF :: Located (HsExpr GhcPs) -> ExactPrint.Transform ()
-- exprF lexpr@(L _ expr) = case expr of
-- #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
-- RecordCon _ _ (HsRecFields fs@(_:_) Nothing) ->
-- #else
-- RecordCon _ _ _ (HsRecFields fs@(_:_) Nothing) ->
-- #endif
-- moveTrailingComments lexpr (List.last fs)
-- #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
-- RecordUpd _ _e fs@(_:_) ->
-- #else
-- RecordUpd _e fs@(_:_) _cons _ _ _ ->
-- #endif
-- moveTrailingComments lexpr (List.last fs)
-- _ -> return ()
commentAnnFixTransform :: GHC.ParsedSource -> ExactPrint.Transform () -- moveTrailingComments :: (Data.Data.Data a,Data.Data.Data b)
commentAnnFixTransform modul = SYB.everything (>>) genF modul -- => GHC.Located a -> GHC.Located b -> ExactPrint.Transform ()
where -- moveTrailingComments astFrom astTo = do
genF :: Data.Data.Data a => a -> ExactPrint.Transform () -- let
genF = (\_ -> return ()) `SYB.extQ` exprF -- k1 = ExactPrint.mkAnnKey astFrom
exprF :: Located (HsExpr GhcPs) -> ExactPrint.Transform () -- k2 = ExactPrint.mkAnnKey astTo
exprF lexpr@(L _ expr) = case expr of -- moveComments ans = ans'
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ -- where
RecordCon _ _ (HsRecFields fs@(_:_) Nothing) -> -- an1 = Data.Maybe.fromJust $ Map.lookup k1 ans
#else -- an2 = Data.Maybe.fromJust $ Map.lookup k2 ans
RecordCon _ _ _ (HsRecFields fs@(_:_) Nothing) -> -- cs1f = ExactPrint.annFollowingComments an1
#endif -- cs2f = ExactPrint.annFollowingComments an2
moveTrailingComments lexpr (List.last fs) -- (comments, nonComments) = flip breakEither (ExactPrint.annsDP an1)
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ -- $ \case
RecordUpd _ _e fs@(_:_) -> -- (ExactPrint.AnnComment com, dp) -> Left (com, dp)
#else -- x -> Right x
RecordUpd _e fs@(_:_) _cons _ _ _ -> -- an1' = an1
#endif -- { ExactPrint.annsDP = nonComments
moveTrailingComments lexpr (List.last fs) -- , ExactPrint.annFollowingComments = []
_ -> return () -- }
-- an2' = an2
moveTrailingComments :: (Data.Data.Data a,Data.Data.Data b) -- { ExactPrint.annFollowingComments = cs1f ++ cs2f ++ comments
=> GHC.Located a -> GHC.Located b -> ExactPrint.Transform () -- }
moveTrailingComments astFrom astTo = do -- ans' = Map.insert k1 an1' $ Map.insert k2 an2' ans
let --
k1 = ExactPrint.mkAnnKey astFrom -- ExactPrint.modifyAnnsT moveComments
k2 = ExactPrint.mkAnnKey astTo
moveComments ans = ans'
where
an1 = Data.Maybe.fromJust $ Map.lookup k1 ans
an2 = Data.Maybe.fromJust $ Map.lookup k2 ans
cs1f = ExactPrint.annFollowingComments an1
cs2f = ExactPrint.annFollowingComments an2
(comments, nonComments) = flip breakEither (ExactPrint.annsDP an1)
$ \case
(ExactPrint.AnnComment com, dp) -> Left (com, dp)
x -> Right x
an1' = an1
{ ExactPrint.annsDP = nonComments
, ExactPrint.annFollowingComments = []
}
an2' = an2
{ ExactPrint.annFollowingComments = cs1f ++ cs2f ++ comments
}
ans' = Map.insert k1 an1' $ Map.insert k2 an2' ans
ExactPrint.modifyAnnsT moveComments
-- | split a set of annotations in a module into a map from top-level module -- | split a set of annotations in a module into a map from top-level module
-- elements to the relevant annotations. Avoids quadratic behaviour a trivial -- elements to the relevant annotations. Avoids quadratic behaviour a trivial