Language.C.Syntax.Constants

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

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

Language.C.Syntax.Constants

Contents

- Utilities
- C char constants (and multi-character character constants)
- C integral constants
- C floating point constants
- C string literals
- Clang C version literals

Description

This module provides support for representing, checking and exporting c constants, i.e. integral, float, character and string constants.

Synopsis

- escapeChar :: Char -> String
- unescapeChar :: String -> (Char, String)
- unescapeString :: String -> String
- newtype Flags f = Flags Integer
- noFlags :: Flags f
- setFlag :: Enum f => f -> Flags f -> Flags f
- clearFlag :: Enum f => f -> Flags f -> Flags f
- testFlag :: Enum f => f -> Flags f -> Bool
- cChar :: Char -> CChar
- cChar_w :: Char -> CChar
- cChars :: String -> Bool -> CChar
- data CChar
  - = CChar !Char !Bool
  - | CChars [Char] !Bool
- getCChar :: CChar -> String
- getCCharAsInt :: CChar -> Integer
- isWideChar :: CChar -> Bool
- showCharConst :: Char -> ShowS
- data CIntFlag
  - = FlagUnsigned
  - | FlagLong
  - | FlagLongLong
  - | FlagImag
- data CIntRepr
  - = DecRepr
  - | HexRepr
  - | OctalRepr
- cInteger :: Integer -> CInteger
- data CInteger = CInteger !Integer !CIntRepr !(Flags CIntFlag)
- getCInteger :: CInteger -> Integer
- readCInteger :: CIntRepr -> String -> Either String CInteger
- cFloat :: Float -> CFloat
- data CFloat = CFloat !String
- readCFloat :: String -> CFloat
- cString :: String -> CString
- cString_w :: String -> CString
- data CString = CString String Bool
- getCString :: CString -> String
- showStringLit :: String -> ShowS
- concatCStrings :: [CString] -> CString
- data ClangCVersion = ClangCVersion !String
- readClangCVersion :: String -> ClangCVersion

# Utilities

escapeChar :: Char -> String #

unescapeChar :: String -> (Char, String) #

unescapeString :: String -> String #

newtype Flags f #

Constructors

Flags Integer |

Instances

Eq (Flags f) # |
Methods (==) :: Flags f -> Flags f -> Bool # (/=) :: Flags f -> Flags f -> Bool #
Data f => Data (Flags f) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Flags f -> c (Flags f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Flags f) # toConstr :: Flags f -> Constr # dataTypeOf :: Flags f -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Flags f)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Flags f)) # gmapT :: (forall b. Data b => b -> b) -> Flags f -> Flags f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Flags f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Flags f -> r # gmapQ :: (forall d. Data d => d -> u) -> Flags f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Flags f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Flags f -> m (Flags f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Flags f -> m (Flags f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Flags f -> m (Flags f) #
Ord (Flags f) # |
Methods compare :: Flags f -> Flags f -> Ordering # (<) :: Flags f -> Flags f -> Bool # (<=) :: Flags f -> Flags f -> Bool # (>) :: Flags f -> Flags f -> Bool # (>=) :: Flags f -> Flags f -> Bool # max :: Flags f -> Flags f -> Flags f # min :: Flags f -> Flags f -> Flags f #

noFlags :: Flags f #

setFlag :: Enum f => f -> Flags f -> Flags f #

clearFlag :: Enum f => f -> Flags f -> Flags f #

testFlag :: Enum f => f -> Flags f -> Bool #

# C char constants (and multi-character character constants)

cChar :: Char -> CChar #

construct a character constant from a haskell `Char` Use `cchar_w` if you want a wide character constant.

cChar_w :: Char -> CChar #

construct a wide chararacter constant

cChars :: String -> Bool -> CChar #

create a multi-character character constant

data CChar #

C char constants (abstract)

Constructors

CChar !Char !Bool |
CChars [Char] !Bool |

Instances

Eq CChar # |
Methods (==) :: CChar -> CChar -> Bool # (/=) :: CChar -> CChar -> Bool #
Data CChar # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CChar -> c CChar # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CChar # toConstr :: CChar -> Constr # dataTypeOf :: CChar -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CChar) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CChar) # gmapT :: (forall b. Data b => b -> b) -> CChar -> CChar # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CChar -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CChar -> r # gmapQ :: (forall d. Data d => d -> u) -> CChar -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CChar -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CChar -> m CChar # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CChar -> m CChar # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CChar -> m CChar #
Ord CChar # |
Methods compare :: CChar -> CChar -> Ordering # (<) :: CChar -> CChar -> Bool # (<=) :: CChar -> CChar -> Bool # (>) :: CChar -> CChar -> Bool # (>=) :: CChar -> CChar -> Bool # max :: CChar -> CChar -> CChar # min :: CChar -> CChar -> CChar #
Show CChar # |
Methods showsPrec :: Int -> CChar -> ShowS # show :: CChar -> String # showList :: [CChar] -> ShowS #

getCChar :: CChar -> String #

get the haskell representation of a char constant

getCCharAsInt :: CChar -> Integer #

get integer value of a C char constant undefined result for multi-char char constants

isWideChar :: CChar -> Bool #

return `true` if the character constant is wide.

showCharConst :: Char -> ShowS #

`showCharConst c` prepends _a_ String representing the C char constant corresponding to `c`. If necessary uses octal or hexadecimal escape sequences.

# C integral constants

data CIntFlag #

datatype representing type flags for integers

Constructors

FlagUnsigned |
FlagLong |
FlagLongLong |
FlagImag |

Instances

Bounded CIntFlag # |
Methods minBound :: CIntFlag # maxBound :: CIntFlag #
Enum CIntFlag # |
Methods succ :: CIntFlag -> CIntFlag # pred :: CIntFlag -> CIntFlag # toEnum :: Int -> CIntFlag # fromEnum :: CIntFlag -> Int # enumFrom :: CIntFlag -> [CIntFlag] # enumFromThen :: CIntFlag -> CIntFlag -> [CIntFlag] # enumFromTo :: CIntFlag -> CIntFlag -> [CIntFlag] # enumFromThenTo :: CIntFlag -> CIntFlag -> CIntFlag -> [CIntFlag] #
Eq CIntFlag # |
Methods (==) :: CIntFlag -> CIntFlag -> Bool # (/=) :: CIntFlag -> CIntFlag -> Bool #
Data CIntFlag # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CIntFlag -> c CIntFlag # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CIntFlag # toConstr :: CIntFlag -> Constr # dataTypeOf :: CIntFlag -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CIntFlag) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CIntFlag) # gmapT :: (forall b. Data b => b -> b) -> CIntFlag -> CIntFlag # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CIntFlag -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CIntFlag -> r # gmapQ :: (forall d. Data d => d -> u) -> CIntFlag -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CIntFlag -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CIntFlag -> m CIntFlag # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CIntFlag -> m CIntFlag # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CIntFlag -> m CIntFlag #
Ord CIntFlag # |
Methods compare :: CIntFlag -> CIntFlag -> Ordering # (<) :: CIntFlag -> CIntFlag -> Bool # (<=) :: CIntFlag -> CIntFlag -> Bool # (>) :: CIntFlag -> CIntFlag -> Bool # (>=) :: CIntFlag -> CIntFlag -> Bool # max :: CIntFlag -> CIntFlag -> CIntFlag # min :: CIntFlag -> CIntFlag -> CIntFlag #
Show CIntFlag # |
Methods showsPrec :: Int -> CIntFlag -> ShowS # show :: CIntFlag -> String # showList :: [CIntFlag] -> ShowS #

data CIntRepr #

datatype for memorizing the representation of an integer

Constructors

DecRepr |
HexRepr |
OctalRepr |

Instances

Bounded CIntRepr # |
Methods minBound :: CIntRepr # maxBound :: CIntRepr #
Enum CIntRepr # |
Methods succ :: CIntRepr -> CIntRepr # pred :: CIntRepr -> CIntRepr # toEnum :: Int -> CIntRepr # fromEnum :: CIntRepr -> Int # enumFrom :: CIntRepr -> [CIntRepr] # enumFromThen :: CIntRepr -> CIntRepr -> [CIntRepr] # enumFromTo :: CIntRepr -> CIntRepr -> [CIntRepr] # enumFromThenTo :: CIntRepr -> CIntRepr -> CIntRepr -> [CIntRepr] #
Eq CIntRepr # |
Methods (==) :: CIntRepr -> CIntRepr -> Bool # (/=) :: CIntRepr -> CIntRepr -> Bool #
Data CIntRepr # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CIntRepr -> c CIntRepr # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CIntRepr # toConstr :: CIntRepr -> Constr # dataTypeOf :: CIntRepr -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CIntRepr) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CIntRepr) # gmapT :: (forall b. Data b => b -> b) -> CIntRepr -> CIntRepr # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CIntRepr -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CIntRepr -> r # gmapQ :: (forall d. Data d => d -> u) -> CIntRepr -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CIntRepr -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CIntRepr -> m CIntRepr # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CIntRepr -> m CIntRepr # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CIntRepr -> m CIntRepr #
Ord CIntRepr # |
Methods compare :: CIntRepr -> CIntRepr -> Ordering # (<) :: CIntRepr -> CIntRepr -> Bool # (<=) :: CIntRepr -> CIntRepr -> Bool # (>) :: CIntRepr -> CIntRepr -> Bool # (>=) :: CIntRepr -> CIntRepr -> Bool # max :: CIntRepr -> CIntRepr -> CIntRepr # min :: CIntRepr -> CIntRepr -> CIntRepr #

cInteger :: Integer -> CInteger #

construct a integer constant (without type flags) from a haskell integer

data CInteger #

Constructors

CInteger !Integer !CIntRepr !(Flags CIntFlag) |

Instances

Eq CInteger # |
Methods (==) :: CInteger -> CInteger -> Bool # (/=) :: CInteger -> CInteger -> Bool #
Data CInteger # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CInteger -> c CInteger # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CInteger # toConstr :: CInteger -> Constr # dataTypeOf :: CInteger -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CInteger) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CInteger) # gmapT :: (forall b. Data b => b -> b) -> CInteger -> CInteger # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CInteger -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CInteger -> r # gmapQ :: (forall d. Data d => d -> u) -> CInteger -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CInteger -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CInteger -> m CInteger # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CInteger -> m CInteger # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CInteger -> m CInteger #
Ord CInteger # |
Methods compare :: CInteger -> CInteger -> Ordering # (<) :: CInteger -> CInteger -> Bool # (<=) :: CInteger -> CInteger -> Bool # (>) :: CInteger -> CInteger -> Bool # (>=) :: CInteger -> CInteger -> Bool # max :: CInteger -> CInteger -> CInteger # min :: CInteger -> CInteger -> CInteger #
Show CInteger # |
Methods showsPrec :: Int -> CInteger -> ShowS # show :: CInteger -> String # showList :: [CInteger] -> ShowS #

getCInteger :: CInteger -> Integer #

readCInteger :: CIntRepr -> String -> Either String CInteger #

# C floating point constants

cFloat :: Float -> CFloat #

data CFloat #

Floats (represented as strings)

Constructors

CFloat !String |

Instances

Eq CFloat # |
Methods (==) :: CFloat -> CFloat -> Bool # (/=) :: CFloat -> CFloat -> Bool #
Data CFloat # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CFloat -> c CFloat # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CFloat # toConstr :: CFloat -> Constr # dataTypeOf :: CFloat -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CFloat) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CFloat) # gmapT :: (forall b. Data b => b -> b) -> CFloat -> CFloat # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CFloat -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CFloat -> r # gmapQ :: (forall d. Data d => d -> u) -> CFloat -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CFloat -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CFloat -> m CFloat # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CFloat -> m CFloat # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CFloat -> m CFloat #
Ord CFloat # |
Methods compare :: CFloat -> CFloat -> Ordering # (<) :: CFloat -> CFloat -> Bool # (<=) :: CFloat -> CFloat -> Bool # (>) :: CFloat -> CFloat -> Bool # (>=) :: CFloat -> CFloat -> Bool # max :: CFloat -> CFloat -> CFloat # min :: CFloat -> CFloat -> CFloat #
Show CFloat # |
Methods showsPrec :: Int -> CFloat -> ShowS # show :: CFloat -> String # showList :: [CFloat] -> ShowS #

readCFloat :: String -> CFloat #

# C string literals

cString :: String -> CString #

cString_w :: String -> CString #

data CString #

C String literals

Constructors

CString String Bool |

Instances

Eq CString # |
Methods (==) :: CString -> CString -> Bool # (/=) :: CString -> CString -> Bool #
Data CString # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CString -> c CString # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CString # toConstr :: CString -> Constr # dataTypeOf :: CString -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CString) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CString) # gmapT :: (forall b. Data b => b -> b) -> CString -> CString # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CString -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CString -> r # gmapQ :: (forall d. Data d => d -> u) -> CString -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CString -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CString -> m CString # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CString -> m CString # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CString -> m CString #
Ord CString # |
Methods compare :: CString -> CString -> Ordering # (<) :: CString -> CString -> Bool # (<=) :: CString -> CString -> Bool # (>) :: CString -> CString -> Bool # (>=) :: CString -> CString -> Bool # max :: CString -> CString -> CString # min :: CString -> CString -> CString #
Show CString # |
Methods showsPrec :: Int -> CString -> ShowS # show :: CString -> String # showList :: [CString] -> ShowS #

getCString :: CString -> String #

showStringLit :: String -> ShowS #

`showStringLiteral s` prepends a String representing the C string literal corresponding to `s`. If necessary it uses octal or hexadecimal escape sequences.

concatCStrings :: [CString] -> CString #

concatenate a list of C string literals

# Clang C version literals

data ClangCVersion #

Clang dotted version literal https://clang.llvm.org/docs/AttributeReference.html#availability

Constructors

ClangCVersion !String |

Instances

Eq ClangCVersion # |
Methods (==) :: ClangCVersion -> ClangCVersion -> Bool # (/=) :: ClangCVersion -> ClangCVersion -> Bool #
Data ClangCVersion # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ClangCVersion -> c ClangCVersion # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ClangCVersion # toConstr :: ClangCVersion -> Constr # dataTypeOf :: ClangCVersion -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c ClangCVersion) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ClangCVersion) # gmapT :: (forall b. Data b => b -> b) -> ClangCVersion -> ClangCVersion # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ClangCVersion -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ClangCVersion -> r # gmapQ :: (forall d. Data d => d -> u) -> ClangCVersion -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ClangCVersion -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ClangCVersion -> m ClangCVersion # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ClangCVersion -> m ClangCVersion # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ClangCVersion -> m ClangCVersion #
Ord ClangCVersion # |
Methods compare :: ClangCVersion -> ClangCVersion -> Ordering # (<) :: ClangCVersion -> ClangCVersion -> Bool # (<=) :: ClangCVersion -> ClangCVersion -> Bool # (>) :: ClangCVersion -> ClangCVersion -> Bool # (>=) :: ClangCVersion -> ClangCVersion -> Bool # max :: ClangCVersion -> ClangCVersion -> ClangCVersion # min :: ClangCVersion -> ClangCVersion -> ClangCVersion #
Show ClangCVersion # |
Methods showsPrec :: Int -> ClangCVersion -> ShowS # show :: ClangCVersion -> String # showList :: [ClangCVersion] -> ShowS #

readClangCVersion :: String -> ClangCVersion #