-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module HIndent.Ast.Declaration.Warning | ||
( WarningDeclaration | ||
, mkWarningDeclaration | ||
) where | ||
|
||
import qualified GHC.Types.SourceText as GHC | ||
import qualified GHC.Types.SrcLoc as GHC | ||
import HIndent.Ast.Declaration.Warning.Kind | ||
import HIndent.Ast.NodeComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Unit.Module.Warnings as GHC | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data WarningDeclaration = WarningDeclaration | ||
{ names :: [GHC.LIdP GHC.GhcPs] | ||
, kind :: Kind | ||
, reasons :: [GHC.Located GHC.StringLiteral] | ||
} | ||
|
||
instance CommentExtraction WarningDeclaration where | ||
nodeComments _ = NodeComments [] [] [] | ||
|
||
instance Pretty WarningDeclaration where | ||
pretty' WarningDeclaration {..} = do | ||
lined | ||
[ string "{-# " >> pretty kind | ||
, spaced [hCommaSep $ fmap pretty names, hCommaSep $ fmap pretty reasons] | ||
, string " #-}" | ||
] | ||
|
||
mkWarningDeclaration :: GHC.WarnDecl GHC.GhcPs -> WarningDeclaration | ||
#if MIN_VERSION_ghc_lib_parser(9, 8, 1) | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ rs)) = | ||
WarningDeclaration {kind = Deprecated, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ _ rs)) = | ||
WarningDeclaration {kind = Warning, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
#else | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ reasons)) = | ||
WarningDeclaration {kind = Deprecated, ..} | ||
Check failure on line 48 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (ubuntu-latest, 9.0.2)
Check failure on line 48 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (windows-latest, 9.0.2)
Check failure on line 48 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (macos-latest, 9.2.8)
Check failure on line 48 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (ubuntu-latest, 9.2.8)
|
||
mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ reasons)) = | ||
WarningDeclaration {kind = Warning, ..} | ||
Check failure on line 50 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (ubuntu-latest, 9.0.2)
Check failure on line 50 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (windows-latest, 9.0.2)
Check failure on line 50 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (macos-latest, 9.2.8)
Check failure on line 50 in src/HIndent/Ast/Declaration/Warning.hs GitHub Actions / CI (ubuntu-latest, 9.2.8)
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
module HIndent.Ast.Declaration.Warning.Collection | ||
( WarningCollection | ||
, mkWarningCollection | ||
) where | ||
|
||
import HIndent.Ast.Declaration.Warning | ||
import HIndent.Ast.NodeComments | ||
import HIndent.Ast.WithComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
newtype WarningCollection = | ||
WarningCollection [WithComments WarningDeclaration] | ||
|
||
instance CommentExtraction WarningCollection where | ||
nodeComments WarningCollection {} = NodeComments [] [] [] | ||
|
||
instance Pretty WarningCollection where | ||
pretty' (WarningCollection xs) = lined $ fmap pretty xs | ||
|
||
mkWarningCollection :: GHC.WarnDecls GHC.GhcPs -> WarningCollection | ||
#if MIN_VERSION_ghc_lib_parser(9, 6, 1) | ||
mkWarningCollection (GHC.Warnings _ xs) = | ||
WarningCollection $ fmap (fmap mkWarningDeclaration . fromGenLocated) xs | ||
#else | ||
mkWarningCollection (GHC.Warnings _ _ xs) = | ||
WarningCollection $ fmap (fmap mkWarningDeclaration . fromGenLocated) xs | ||
#endif |