-- | Diagnostics describe parse errors
module LLVM.Diagnostic (
  DiagnosticKind(..),
  Diagnostic(..),
  diagnosticDisplay
 ) where

import LLVM.Prelude

-- | What kind of problem does a diagnostic describe?
data DiagnosticKind 
  = ErrorKind
  | WarningKind
  | NoteKind
  deriving (DiagnosticKind -> DiagnosticKind -> Bool
(DiagnosticKind -> DiagnosticKind -> Bool)
-> (DiagnosticKind -> DiagnosticKind -> Bool) -> Eq DiagnosticKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DiagnosticKind -> DiagnosticKind -> Bool
$c/= :: DiagnosticKind -> DiagnosticKind -> Bool
== :: DiagnosticKind -> DiagnosticKind -> Bool
$c== :: DiagnosticKind -> DiagnosticKind -> Bool
Eq, Eq DiagnosticKind
Eq DiagnosticKind =>
(DiagnosticKind -> DiagnosticKind -> Ordering)
-> (DiagnosticKind -> DiagnosticKind -> Bool)
-> (DiagnosticKind -> DiagnosticKind -> Bool)
-> (DiagnosticKind -> DiagnosticKind -> Bool)
-> (DiagnosticKind -> DiagnosticKind -> Bool)
-> (DiagnosticKind -> DiagnosticKind -> DiagnosticKind)
-> (DiagnosticKind -> DiagnosticKind -> DiagnosticKind)
-> Ord DiagnosticKind
DiagnosticKind -> DiagnosticKind -> Bool
DiagnosticKind -> DiagnosticKind -> Ordering
DiagnosticKind -> DiagnosticKind -> DiagnosticKind
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DiagnosticKind -> DiagnosticKind -> DiagnosticKind
$cmin :: DiagnosticKind -> DiagnosticKind -> DiagnosticKind
max :: DiagnosticKind -> DiagnosticKind -> DiagnosticKind
$cmax :: DiagnosticKind -> DiagnosticKind -> DiagnosticKind
>= :: DiagnosticKind -> DiagnosticKind -> Bool
$c>= :: DiagnosticKind -> DiagnosticKind -> Bool
> :: DiagnosticKind -> DiagnosticKind -> Bool
$c> :: DiagnosticKind -> DiagnosticKind -> Bool
<= :: DiagnosticKind -> DiagnosticKind -> Bool
$c<= :: DiagnosticKind -> DiagnosticKind -> Bool
< :: DiagnosticKind -> DiagnosticKind -> Bool
$c< :: DiagnosticKind -> DiagnosticKind -> Bool
compare :: DiagnosticKind -> DiagnosticKind -> Ordering
$ccompare :: DiagnosticKind -> DiagnosticKind -> Ordering
$cp1Ord :: Eq DiagnosticKind
Ord, ReadPrec [DiagnosticKind]
ReadPrec DiagnosticKind
Int -> ReadS DiagnosticKind
ReadS [DiagnosticKind]
(Int -> ReadS DiagnosticKind)
-> ReadS [DiagnosticKind]
-> ReadPrec DiagnosticKind
-> ReadPrec [DiagnosticKind]
-> Read DiagnosticKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DiagnosticKind]
$creadListPrec :: ReadPrec [DiagnosticKind]
readPrec :: ReadPrec DiagnosticKind
$creadPrec :: ReadPrec DiagnosticKind
readList :: ReadS [DiagnosticKind]
$creadList :: ReadS [DiagnosticKind]
readsPrec :: Int -> ReadS DiagnosticKind
$creadsPrec :: Int -> ReadS DiagnosticKind
Read, Int -> DiagnosticKind -> ShowS
[DiagnosticKind] -> ShowS
DiagnosticKind -> String
(Int -> DiagnosticKind -> ShowS)
-> (DiagnosticKind -> String)
-> ([DiagnosticKind] -> ShowS)
-> Show DiagnosticKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DiagnosticKind] -> ShowS
$cshowList :: [DiagnosticKind] -> ShowS
show :: DiagnosticKind -> String
$cshow :: DiagnosticKind -> String
showsPrec :: Int -> DiagnosticKind -> ShowS
$cshowsPrec :: Int -> DiagnosticKind -> ShowS
Show, Typeable, Typeable DiagnosticKind
DataType
Constr
Typeable DiagnosticKind =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DiagnosticKind -> c DiagnosticKind)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DiagnosticKind)
-> (DiagnosticKind -> Constr)
-> (DiagnosticKind -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DiagnosticKind))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DiagnosticKind))
-> ((forall b. Data b => b -> b)
    -> DiagnosticKind -> DiagnosticKind)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> DiagnosticKind -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DiagnosticKind -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> DiagnosticKind -> m DiagnosticKind)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DiagnosticKind -> m DiagnosticKind)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DiagnosticKind -> m DiagnosticKind)
-> Data DiagnosticKind
DiagnosticKind -> DataType
DiagnosticKind -> Constr
(forall b. Data b => b -> b) -> DiagnosticKind -> DiagnosticKind
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DiagnosticKind -> c DiagnosticKind
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DiagnosticKind
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> DiagnosticKind -> u
forall u. (forall d. Data d => d -> u) -> DiagnosticKind -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DiagnosticKind
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DiagnosticKind -> c DiagnosticKind
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DiagnosticKind)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DiagnosticKind)
$cNoteKind :: Constr
$cWarningKind :: Constr
$cErrorKind :: Constr
$tDiagnosticKind :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
gmapMp :: (forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
gmapM :: (forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> DiagnosticKind -> m DiagnosticKind
gmapQi :: Int -> (forall d. Data d => d -> u) -> DiagnosticKind -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> DiagnosticKind -> u
gmapQ :: (forall d. Data d => d -> u) -> DiagnosticKind -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DiagnosticKind -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DiagnosticKind -> r
gmapT :: (forall b. Data b => b -> b) -> DiagnosticKind -> DiagnosticKind
$cgmapT :: (forall b. Data b => b -> b) -> DiagnosticKind -> DiagnosticKind
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DiagnosticKind)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DiagnosticKind)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c DiagnosticKind)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DiagnosticKind)
dataTypeOf :: DiagnosticKind -> DataType
$cdataTypeOf :: DiagnosticKind -> DataType
toConstr :: DiagnosticKind -> Constr
$ctoConstr :: DiagnosticKind -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DiagnosticKind
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DiagnosticKind
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DiagnosticKind -> c DiagnosticKind
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DiagnosticKind -> c DiagnosticKind
$cp1Data :: Typeable DiagnosticKind
Data, (forall x. DiagnosticKind -> Rep DiagnosticKind x)
-> (forall x. Rep DiagnosticKind x -> DiagnosticKind)
-> Generic DiagnosticKind
forall x. Rep DiagnosticKind x -> DiagnosticKind
forall x. DiagnosticKind -> Rep DiagnosticKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DiagnosticKind x -> DiagnosticKind
$cfrom :: forall x. DiagnosticKind -> Rep DiagnosticKind x
Generic)

-- | A 'Diagnostic' described a problem during parsing of LLVM IR
data Diagnostic = Diagnostic {
    Diagnostic -> Int
lineNumber :: Int,
    Diagnostic -> Int
columnNumber :: Int,
    Diagnostic -> DiagnosticKind
diagnosticKind :: DiagnosticKind,
    Diagnostic -> String
filename :: String,
    Diagnostic -> String
message :: String,
    Diagnostic -> String
lineContents :: String
  }
  deriving (Diagnostic -> Diagnostic -> Bool
(Diagnostic -> Diagnostic -> Bool)
-> (Diagnostic -> Diagnostic -> Bool) -> Eq Diagnostic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Diagnostic -> Diagnostic -> Bool
$c/= :: Diagnostic -> Diagnostic -> Bool
== :: Diagnostic -> Diagnostic -> Bool
$c== :: Diagnostic -> Diagnostic -> Bool
Eq, Eq Diagnostic
Eq Diagnostic =>
(Diagnostic -> Diagnostic -> Ordering)
-> (Diagnostic -> Diagnostic -> Bool)
-> (Diagnostic -> Diagnostic -> Bool)
-> (Diagnostic -> Diagnostic -> Bool)
-> (Diagnostic -> Diagnostic -> Bool)
-> (Diagnostic -> Diagnostic -> Diagnostic)
-> (Diagnostic -> Diagnostic -> Diagnostic)
-> Ord Diagnostic
Diagnostic -> Diagnostic -> Bool
Diagnostic -> Diagnostic -> Ordering
Diagnostic -> Diagnostic -> Diagnostic
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Diagnostic -> Diagnostic -> Diagnostic
$cmin :: Diagnostic -> Diagnostic -> Diagnostic
max :: Diagnostic -> Diagnostic -> Diagnostic
$cmax :: Diagnostic -> Diagnostic -> Diagnostic
>= :: Diagnostic -> Diagnostic -> Bool
$c>= :: Diagnostic -> Diagnostic -> Bool
> :: Diagnostic -> Diagnostic -> Bool
$c> :: Diagnostic -> Diagnostic -> Bool
<= :: Diagnostic -> Diagnostic -> Bool
$c<= :: Diagnostic -> Diagnostic -> Bool
< :: Diagnostic -> Diagnostic -> Bool
$c< :: Diagnostic -> Diagnostic -> Bool
compare :: Diagnostic -> Diagnostic -> Ordering
$ccompare :: Diagnostic -> Diagnostic -> Ordering
$cp1Ord :: Eq Diagnostic
Ord, ReadPrec [Diagnostic]
ReadPrec Diagnostic
Int -> ReadS Diagnostic
ReadS [Diagnostic]
(Int -> ReadS Diagnostic)
-> ReadS [Diagnostic]
-> ReadPrec Diagnostic
-> ReadPrec [Diagnostic]
-> Read Diagnostic
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Diagnostic]
$creadListPrec :: ReadPrec [Diagnostic]
readPrec :: ReadPrec Diagnostic
$creadPrec :: ReadPrec Diagnostic
readList :: ReadS [Diagnostic]
$creadList :: ReadS [Diagnostic]
readsPrec :: Int -> ReadS Diagnostic
$creadsPrec :: Int -> ReadS Diagnostic
Read, Int -> Diagnostic -> ShowS
[Diagnostic] -> ShowS
Diagnostic -> String
(Int -> Diagnostic -> ShowS)
-> (Diagnostic -> String)
-> ([Diagnostic] -> ShowS)
-> Show Diagnostic
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Diagnostic] -> ShowS
$cshowList :: [Diagnostic] -> ShowS
show :: Diagnostic -> String
$cshow :: Diagnostic -> String
showsPrec :: Int -> Diagnostic -> ShowS
$cshowsPrec :: Int -> Diagnostic -> ShowS
Show)

-- | Convert a 'Diagnostic' to a printable form.
diagnosticDisplay :: Diagnostic -> String
diagnosticDisplay :: Diagnostic -> String
diagnosticDisplay d :: Diagnostic
d = 
  (Diagnostic -> String
filename Diagnostic
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ ":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Diagnostic -> Int
lineNumber Diagnostic
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ ":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Diagnostic -> Int
columnNumber Diagnostic
d)
  String -> ShowS
forall a. [a] -> [a] -> [a]
++ ":\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++ DiagnosticKind -> String
forall a. Show a => a -> String
show (Diagnostic -> DiagnosticKind
diagnosticKind Diagnostic
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ ": " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Diagnostic -> String
message Diagnostic
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "\n"
  String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Diagnostic -> String
lineContents Diagnostic
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "\n"