Hack away BackendUtils

mxxun/ghc-9.2
mrkun 2022-01-30 15:25:55 +03:00
parent 9ee501753e
commit e46e459e87
1 changed files with 82 additions and 82 deletions

View File

@ -17,7 +17,7 @@ import Language.Haskell.Brittany.Internal.Prelude
import Language.Haskell.Brittany.Internal.PreludeUtils import Language.Haskell.Brittany.Internal.PreludeUtils
import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.Utils import Language.Haskell.Brittany.Internal.Utils
import Language.Haskell.GHC.ExactPrint.Types (AnnKey, Annotation) -- import Language.Haskell.GHC.ExactPrint.Types (AnnKey, Annotation)
import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint
@ -338,23 +338,23 @@ layoutAddSepSpace = do
-- TODO: when refactoring is complete, the other version of this method -- TODO: when refactoring is complete, the other version of this method
-- can probably be removed. -- can probably be removed.
moveToExactAnn -- moveToExactAnn
:: ( MonadMultiWriter Text.Builder.Builder m -- :: ( MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m -- , MonadMultiState LayoutState m
, MonadMultiReader (Map AnnKey Annotation) m -- -- , MonadMultiReader (Map AnnKey Annotation) m
) -- )
=> AnnKey -- => AnnKey
-> m () -- -> m ()
moveToExactAnn annKey = do -- moveToExactAnn annKey = do
traceLocal ("moveToExactAnn", annKey) -- traceLocal ("moveToExactAnn", annKey)
anns <- mAsk -- anns <- mAsk
case Map.lookup annKey anns of -- case Map.lookup annKey anns of
Nothing -> return () -- Nothing -> return ()
Just ann -> do -- Just ann -> do
-- curY <- mGet <&> _lstate_curY -- -- curY <- mGet <&> _lstate_curY
let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann -- let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann
-- mModify $ \state -> state { _lstate_addNewline = Just x } -- -- mModify $ \state -> state { _lstate_addNewline = Just x }
moveToY y -- moveToY y
moveToY :: MonadMultiState LayoutState m => Int -> m () moveToY :: MonadMultiState LayoutState m => Int -> m ()
moveToY y = mModify $ \state -> moveToY y = mModify $ \state ->
@ -379,77 +379,77 @@ moveToY y = mModify $ \state ->
-- then x-1 -- then x-1
-- else x -- else x
ppmMoveToExactLoc -- ppmMoveToExactLoc
:: MonadMultiWriter Text.Builder.Builder m => ExactPrint.DeltaPos -> m () -- :: MonadMultiWriter Text.Builder.Builder m => ExactPrint.DeltaPos -> m ()
ppmMoveToExactLoc (ExactPrint.DP (x, y)) = do -- ppmMoveToExactLoc (ExactPrint.DP (x, y)) = do
replicateM_ x $ mTell $ Text.Builder.fromString "\n" -- replicateM_ x $ mTell $ Text.Builder.fromString "\n"
replicateM_ y $ mTell $ Text.Builder.fromString " " -- replicateM_ y $ mTell $ Text.Builder.fromString " "
-- TODO: update and use, or clean up. Currently dead code. -- TODO: update and use, or clean up. Currently dead code.
layoutWritePriorComments -- layoutWritePriorComments
:: ( Data.Data.Data ast -- :: ( Data.Data.Data ast
, MonadMultiWriter Text.Builder.Builder m -- , MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m -- , MonadMultiState LayoutState m
) -- )
=> Located ast -- => Located ast
-> m () -- -> m ()
layoutWritePriorComments ast = do -- layoutWritePriorComments ast = do
mAnn <- do -- mAnn <- do
state <- mGet -- state <- mGet
let key = ExactPrint.mkAnnKey ast -- let key = ExactPrint.mkAnnKey ast
let anns = _lstate_comments state -- let anns = _lstate_comments state
let mAnn = ExactPrint.annPriorComments <$> Map.lookup key anns -- let mAnn = ExactPrint.annPriorComments <$> Map.lookup key anns
mSet $ state -- mSet $ state
{ _lstate_comments = Map.adjust -- { _lstate_comments = Map.adjust
(\ann -> ann { ExactPrint.annPriorComments = [] }) -- (\ann -> ann { ExactPrint.annPriorComments = [] })
key -- key
anns -- anns
} -- }
return mAnn -- return mAnn
case mAnn of -- case mAnn of
Nothing -> return () -- Nothing -> return ()
Just priors -> do -- Just priors -> do
unless (null priors) $ layoutSetCommentCol -- unless (null priors) $ layoutSetCommentCol
priors `forM_` \(ExactPrint.Comment comment _ _, ExactPrint.DP (x, y)) -> -- priors `forM_` \(ExactPrint.Comment comment _ _, ExactPrint.DP (x, y)) ->
do -- do
replicateM_ x layoutWriteNewline -- replicateM_ x layoutWriteNewline
layoutWriteAppendSpaces y -- layoutWriteAppendSpaces y
layoutWriteAppendMultiline $ Text.lines $ Text.pack comment -- layoutWriteAppendMultiline $ Text.lines $ Text.pack comment
-- TODO: update and use, or clean up. Currently dead code. -- TODO: update and use, or clean up. Currently dead code.
-- this currently only extracs from the `annsDP` field of Annotations. -- this currently only extracs from the `annsDP` field of Annotations.
-- per documentation, this seems sufficient, as the -- per documentation, this seems sufficient, as the
-- "..`annFollowingComments` are only added by AST transformations ..". -- "..`annFollowingComments` are only added by AST transformations ..".
layoutWritePostComments -- layoutWritePostComments
:: ( Data.Data.Data ast -- :: ( Data.Data.Data ast
, MonadMultiWriter Text.Builder.Builder m -- , MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m -- , MonadMultiState LayoutState m
) -- )
=> Located ast -- => Located ast
-> m () -- -> m ()
layoutWritePostComments ast = do -- layoutWritePostComments ast = do
mAnn <- do -- mAnn <- do
state <- mGet -- state <- mGet
let key = ExactPrint.mkAnnKey ast -- let key = ExactPrint.mkAnnKey ast
let anns = _lstate_comments state -- let anns = _lstate_comments state
let mAnn = ExactPrint.annFollowingComments <$> Map.lookup key anns -- let mAnn = ExactPrint.annFollowingComments <$> Map.lookup key anns
mSet $ state -- mSet $ state
{ _lstate_comments = Map.adjust -- { _lstate_comments = Map.adjust
(\ann -> ann { ExactPrint.annFollowingComments = [] }) -- (\ann -> ann { ExactPrint.annFollowingComments = [] })
key -- key
anns -- anns
} -- }
return mAnn -- return mAnn
case mAnn of -- case mAnn of
Nothing -> return () -- Nothing -> return ()
Just posts -> do -- Just posts -> do
unless (null posts) $ layoutSetCommentCol -- unless (null posts) $ layoutSetCommentCol
posts `forM_` \(ExactPrint.Comment comment _ _, ExactPrint.DP (x, y)) -> -- posts `forM_` \(ExactPrint.Comment comment _ _, ExactPrint.DP (x, y)) ->
do -- do
replicateM_ x layoutWriteNewline -- replicateM_ x layoutWriteNewline
layoutWriteAppend $ Text.pack $ replicate y ' ' -- layoutWriteAppend $ Text.pack $ replicate y ' '
mModify $ \s -> s { _lstate_addSepSpace = Nothing } -- mModify $ \s -> s { _lstate_addSepSpace = Nothing }
layoutWriteAppendMultiline $ Text.lines $ Text.pack $ comment -- layoutWriteAppendMultiline $ Text.lines $ Text.pack $ comment
layoutIndentRestorePostComment layoutIndentRestorePostComment
:: (MonadMultiState LayoutState m, MonadMultiWriter Text.Builder.Builder m) :: (MonadMultiState LayoutState m, MonadMultiWriter Text.Builder.Builder m)