module Language.C.Inline.Error (
reportErrorAndFail,
tryWithPlaceholder,
prettyQC
) where
import Language.Haskell.TH as TH
import Language.Haskell.TH.Syntax as TH
import Language.C.Quote as QC
import Language.C.Quote.ObjC as QC
import Text.PrettyPrint.Mainland as QC
reportErrorAndFail :: QC.Extensions -> String -> Q a
reportErrorAndFail lang msg
= do
{ reportError' lang msg
; fail "Failure"
}
reportError' :: QC.Extensions -> String -> Q ()
reportError' lang msg
= do
{ loc <- location
; TH.reportError $ "Inline " ++ showLang lang ++ ": " ++ msg
}
where
showLang QC.Antiquotation = "C"
showLang QC.Gcc = "GCC C"
showLang QC.CUDA = "CUDA C"
showLang QC.OpenCL = "OpenCL"
showLang QC.ObjC = "Objective-C"
tryWithPlaceholder :: Q TH.Exp -> Q TH.Exp
tryWithPlaceholder = ([| error "language-c-quote: internal error: tryWithPlaceholder" |] `recover`)
prettyQC :: QC.Pretty a => a -> String
prettyQC = QC.pretty 80 . QC.ppr