Language.C.Data.Error

language-c-0.5.0: Analysis and generation of C code

Copyright | (c) 2008 Benedikt Huber, Manuel M. T. Chakravarty
License | BSD-style
Maintainer | benedikt.huber@gmail.com
Stability | experimental
Portability | ghc
Safe Haskell | None
Language | Haskell98

Language.C.Data.Error

Contents

- Severity Level
- Error class
- Error `supertype`
- Infos attached to errors
- Default error types
- Raising internal errors

Description

Base type for errors occurring in parsing, analysing and pretty-printing. With ideas from Simon Marlow's "An extensible dynamically-typed hierarchy of execeptions [2006]"

Synopsis

- data ErrorLevel
  - = LevelWarn
  - | LevelError
  - | LevelFatal
- isHardError :: Error ex => ex -> Bool
- class (Typeable e, Show e) => Error e where
- errorPos :: Error e => e -> Position
- errorLevel :: Error e => e -> ErrorLevel
- errorMsgs :: Error e => e -> [String]
- data CError = Error err => CError err
- data ErrorInfo = ErrorInfo ErrorLevel Position [String]
- showError :: Error e => String -> e -> String
- showErrorInfo :: String -> ErrorInfo -> String
- mkErrorInfo :: ErrorLevel -> String -> NodeInfo -> ErrorInfo
- data UnsupportedFeature
- unsupportedFeature :: Pos a => String -> a -> UnsupportedFeature
- unsupportedFeature_ :: String -> UnsupportedFeature
- data UserError
- userErr :: String -> UserError
- internalErr :: String -> a

# Severity Level

data ErrorLevel #

Error levels (severity)

Constructors

LevelWarn |
LevelError |
LevelFatal |

Instances

Eq ErrorLevel # |
Methods (==) :: ErrorLevel -> ErrorLevel -> Bool # (/=) :: ErrorLevel -> ErrorLevel -> Bool #
Ord ErrorLevel # |
Methods compare :: ErrorLevel -> ErrorLevel -> Ordering # (<) :: ErrorLevel -> ErrorLevel -> Bool # (<=) :: ErrorLevel -> ErrorLevel -> Bool # (>) :: ErrorLevel -> ErrorLevel -> Bool # (>=) :: ErrorLevel -> ErrorLevel -> Bool # max :: ErrorLevel -> ErrorLevel -> ErrorLevel # min :: ErrorLevel -> ErrorLevel -> ErrorLevel #
Show ErrorLevel # |
Methods showsPrec :: Int -> ErrorLevel -> ShowS # show :: ErrorLevel -> String # showList :: [ErrorLevel] -> ShowS #

isHardError :: Error ex => ex -> Bool #

return `True` when the given error makes it impossible to continue analysis or compilation.

# Error class

class (Typeable e, Show e) => Error e where #

errors in Language.C are instance of `Error`

Minimal complete definition

errorInfo

Methods

errorInfo :: e -> ErrorInfo #

obtain source location etc. of an error

toError :: e -> CError #

wrap error in `CError`

fromError :: CError -> Maybe e #

try to cast a generic `CError` to the specific error type

changeErrorLevel :: e -> ErrorLevel -> e #

modify the error level

Instances

Error UserError # |
Methods errorInfo :: UserError -> ErrorInfo # toError :: UserError -> CError # fromError :: CError -> Maybe UserError # changeErrorLevel :: UserError -> ErrorLevel -> UserError #
Error UnsupportedFeature # |
Methods errorInfo :: UnsupportedFeature -> ErrorInfo # toError :: UnsupportedFeature -> CError # fromError :: CError -> Maybe UnsupportedFeature # changeErrorLevel :: UnsupportedFeature -> ErrorLevel -> UnsupportedFeature #
Error CError # |
Methods errorInfo :: CError -> ErrorInfo # toError :: CError -> CError # fromError :: CError -> Maybe CError # changeErrorLevel :: CError -> ErrorLevel -> CError #
Error ErrorInfo # |
Methods errorInfo :: ErrorInfo -> ErrorInfo # toError :: ErrorInfo -> CError # fromError :: CError -> Maybe ErrorInfo # changeErrorLevel :: ErrorInfo -> ErrorLevel -> ErrorInfo #
Error TypeMismatch # |
Methods errorInfo :: TypeMismatch -> ErrorInfo # toError :: TypeMismatch -> CError # fromError :: CError -> Maybe TypeMismatch # changeErrorLevel :: TypeMismatch -> ErrorLevel -> TypeMismatch #
Error RedefError # |
Methods errorInfo :: RedefError -> ErrorInfo # toError :: RedefError -> CError # fromError :: CError -> Maybe RedefError # changeErrorLevel :: RedefError -> ErrorLevel -> RedefError #
Error BadSpecifierError # |
Methods errorInfo :: BadSpecifierError -> ErrorInfo # toError :: BadSpecifierError -> CError # fromError :: CError -> Maybe BadSpecifierError # changeErrorLevel :: BadSpecifierError -> ErrorLevel -> BadSpecifierError #
Error InvalidASTError # |
Methods errorInfo :: InvalidASTError -> ErrorInfo # toError :: InvalidASTError -> CError # fromError :: CError -> Maybe InvalidASTError # changeErrorLevel :: InvalidASTError -> ErrorLevel -> InvalidASTError #

errorPos :: Error e => e -> Position #

position of an `Error`

errorLevel :: Error e => e -> ErrorLevel #

severity level of an `Error`

errorMsgs :: Error e => e -> [String] #

message lines of an `Error`

# Error `supertype`

data CError #

`supertype` of all errors

Constructors

Error err => CError err |

Instances

Show CError # |
Methods showsPrec :: Int -> CError -> ShowS # show :: CError -> String # showList :: [CError] -> ShowS #
Error CError # |
Methods errorInfo :: CError -> ErrorInfo # toError :: CError -> CError # fromError :: CError -> Maybe CError # changeErrorLevel :: CError -> ErrorLevel -> CError #

# Infos attached to errors

data ErrorInfo #

information attached to every error in Language.C

Constructors

ErrorInfo ErrorLevel Position [String] |

Instances

Show ErrorInfo # |
Methods showsPrec :: Int -> ErrorInfo -> ShowS # show :: ErrorInfo -> String # showList :: [ErrorInfo] -> ShowS #
Error ErrorInfo # |
Methods errorInfo :: ErrorInfo -> ErrorInfo # toError :: ErrorInfo -> CError # fromError :: CError -> Maybe ErrorInfo # changeErrorLevel :: ErrorInfo -> ErrorLevel -> ErrorInfo #

showError :: Error e => String -> e -> String #

showErrorInfo :: String -> ErrorInfo -> String #

converts an error into a string using a fixed format

- either the lines of the long error message or the short message has to be non-empty
- the format is

       <fname>:<row>: (column <col>) [<err lvl>]
         >>> <line_1>
         <line_2>
           ...
         <line_n>

mkErrorInfo :: ErrorLevel -> String -> NodeInfo -> ErrorInfo #

# Default error types

data UnsupportedFeature #

error raised if a operation requires an unsupported or not yet implemented feature.

Instances

Show UnsupportedFeature # |
Methods showsPrec :: Int -> UnsupportedFeature -> ShowS # show :: UnsupportedFeature -> String # showList :: [UnsupportedFeature] -> ShowS #
Error UnsupportedFeature # |
Methods errorInfo :: UnsupportedFeature -> ErrorInfo # toError :: UnsupportedFeature -> CError # fromError :: CError -> Maybe UnsupportedFeature # changeErrorLevel :: UnsupportedFeature -> ErrorLevel -> UnsupportedFeature #

unsupportedFeature :: Pos a => String -> a -> UnsupportedFeature #

unsupportedFeature_ :: String -> UnsupportedFeature #

data UserError #

unspecified error raised by the user (in case the user does not want to define her own error types).

Instances

Show UserError # |
Methods showsPrec :: Int -> UserError -> ShowS # show :: UserError -> String # showList :: [UserError] -> ShowS #
Error UserError # |
Methods errorInfo :: UserError -> ErrorInfo # toError :: UserError -> CError # fromError :: CError -> Maybe UserError # changeErrorLevel :: UserError -> ErrorLevel -> UserError #

userErr :: String -> UserError #

# Raising internal errors

internalErr :: String -> a #

raise a fatal internal error; message may have multiple lines