inline-c-0.9.1.0: Write Haskell source files including C code inline. No FFI required.
Safe HaskellNone
LanguageHaskell2010

Language.C.Types

Description

Views of C datatypes. While Language.C.Types.Parse defines datatypes for representing the concrete syntax tree of C types, this module provides friendlier views of C types, by turning them into a data type matching more closely how we read and think about types, both in Haskell and in C. To appreciate the difference, look at the difference between ParameterDeclaration and ParameterDeclaration.

As a bonus, routines are provided for describing types in natural language (English) -- see describeParameterDeclaration and describeType.

Synopsis

Types

data CIdentifier Source #

A type for C identifiers.

Instances

Instances details
Eq CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

(==) :: CIdentifier -> CIdentifier -> Bool

(/=) :: CIdentifier -> CIdentifier -> Bool

Ord CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Show CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

showsPrec :: Int -> CIdentifier -> ShowS

show :: CIdentifier -> String

showList :: [CIdentifier] -> ShowS

IsString CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

fromString :: String -> CIdentifier

Pretty CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Hashable CIdentifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

hashWithSalt :: Int -> CIdentifier -> Int Source #

hash :: CIdentifier -> Int Source #

cIdentifierFromString :: Bool -> String -> Either String CIdentifier Source #

data TypeQualifier Source #

Constructors

CONST 
RESTRICT 
VOLATILE 

Instances

Instances details
Eq TypeQualifier Source # 
Instance details

Defined in Language.C.Types.Parse

Show TypeQualifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

showsPrec :: Int -> TypeQualifier -> ShowS

show :: TypeQualifier -> String

showList :: [TypeQualifier] -> ShowS

Pretty TypeQualifier Source # 
Instance details

Defined in Language.C.Types.Parse

data FunctionSpecifier Source #

Constructors

INLINE 

Instances

Instances details
Eq FunctionSpecifier Source # 
Instance details

Defined in Language.C.Types.Parse

Show FunctionSpecifier Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

showsPrec :: Int -> FunctionSpecifier -> ShowS

show :: FunctionSpecifier -> String

showList :: [FunctionSpecifier] -> ShowS

Pretty FunctionSpecifier Source # 
Instance details

Defined in Language.C.Types.Parse

data ArrayType i Source #

Instances

Instances details
Functor ArrayType Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

fmap :: (a -> b) -> ArrayType a -> ArrayType b

(<$) :: a -> ArrayType b -> ArrayType a

Foldable ArrayType Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

fold :: Monoid m => ArrayType m -> m

foldMap :: Monoid m => (a -> m) -> ArrayType a -> m

foldMap' :: Monoid m => (a -> m) -> ArrayType a -> m

foldr :: (a -> b -> b) -> b -> ArrayType a -> b

foldr' :: (a -> b -> b) -> b -> ArrayType a -> b

foldl :: (b -> a -> b) -> b -> ArrayType a -> b

foldl' :: (b -> a -> b) -> b -> ArrayType a -> b

foldr1 :: (a -> a -> a) -> ArrayType a -> a

foldl1 :: (a -> a -> a) -> ArrayType a -> a

toList :: ArrayType a -> [a]

null :: ArrayType a -> Bool

length :: ArrayType a -> Int

elem :: Eq a => a -> ArrayType a -> Bool

maximum :: Ord a => ArrayType a -> a

minimum :: Ord a => ArrayType a -> a

sum :: Num a => ArrayType a -> a

product :: Num a => ArrayType a -> a

Traversable ArrayType Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

traverse :: Applicative f => (a -> f b) -> ArrayType a -> f (ArrayType b)

sequenceA :: Applicative f => ArrayType (f a) -> f (ArrayType a)

mapM :: Monad m => (a -> m b) -> ArrayType a -> m (ArrayType b)

sequence :: Monad m => ArrayType (m a) -> m (ArrayType a)

Eq i => Eq (ArrayType i) Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

(==) :: ArrayType i -> ArrayType i -> Bool

(/=) :: ArrayType i -> ArrayType i -> Bool

Show i => Show (ArrayType i) Source # 
Instance details

Defined in Language.C.Types.Parse

Methods

showsPrec :: Int -> ArrayType i -> ShowS

show :: ArrayType i -> String

showList :: [ArrayType i] -> ShowS

Pretty i => Pretty (ArrayType i) Source # 
Instance details

Defined in Language.C.Types.Parse

data Specifiers Source #

Instances

Instances details
Eq Specifiers Source # 
Instance details

Defined in Language.C.Types

Methods

(==) :: Specifiers -> Specifiers -> Bool

(/=) :: Specifiers -> Specifiers -> Bool

Show Specifiers Source # 
Instance details

Defined in Language.C.Types

Methods

showsPrec :: Int -> Specifiers -> ShowS

show :: Specifiers -> String

showList :: [Specifiers] -> ShowS

Semigroup Specifiers Source # 
Instance details

Defined in Language.C.Types

Methods

(<>) :: Specifiers -> Specifiers -> Specifiers #

sconcat :: NonEmpty Specifiers -> Specifiers

stimes :: Integral b => b -> Specifiers -> Specifiers

Monoid Specifiers Source # 
Instance details

Defined in Language.C.Types

data Type i Source #

Instances

Instances details
Functor Type Source # 
Instance details

Defined in Language.C.Types

Methods

fmap :: (a -> b) -> Type a -> Type b

(<$) :: a -> Type b -> Type a

Foldable Type Source # 
Instance details

Defined in Language.C.Types

Methods

fold :: Monoid m => Type m -> m

foldMap :: Monoid m => (a -> m) -> Type a -> m

foldMap' :: Monoid m => (a -> m) -> Type a -> m

foldr :: (a -> b -> b) -> b -> Type a -> b

foldr' :: (a -> b -> b) -> b -> Type a -> b

foldl :: (b -> a -> b) -> b -> Type a -> b

foldl' :: (b -> a -> b) -> b -> Type a -> b

foldr1 :: (a -> a -> a) -> Type a -> a

foldl1 :: (a -> a -> a) -> Type a -> a

toList :: Type a -> [a]

null :: Type a -> Bool

length :: Type a -> Int

elem :: Eq a => a -> Type a -> Bool

maximum :: Ord a => Type a -> a

minimum :: Ord a => Type a -> a

sum :: Num a => Type a -> a

product :: Num a => Type a -> a

Traversable Type Source # 
Instance details

Defined in Language.C.Types

Methods

traverse :: Applicative f => (a -> f b) -> Type a -> f (Type b)

sequenceA :: Applicative f => Type (f a) -> f (Type a)

mapM :: Monad m => (a -> m b) -> Type a -> m (Type b)

sequence :: Monad m => Type (m a) -> m (Type a)

Eq i => Eq (Type i) Source # 
Instance details

Defined in Language.C.Types

Methods

(==) :: Type i -> Type i -> Bool

(/=) :: Type i -> Type i -> Bool

Show i => Show (Type i) Source # 
Instance details

Defined in Language.C.Types

Methods

showsPrec :: Int -> Type i -> ShowS

show :: Type i -> String

showList :: [Type i] -> ShowS

Pretty i => Pretty (Type i) Source # 
Instance details

Defined in Language.C.Types

Methods

pretty :: Type i -> Doc Source #

prettyList :: [Type i] -> Doc Source #

data Sign Source #

Constructors

Signed 
Unsigned 

Instances

Instances details
Eq Sign Source # 
Instance details

Defined in Language.C.Types

Methods

(==) :: Sign -> Sign -> Bool

(/=) :: Sign -> Sign -> Bool

Ord Sign Source # 
Instance details

Defined in Language.C.Types

Methods

compare :: Sign -> Sign -> Ordering

(<) :: Sign -> Sign -> Bool

(<=) :: Sign -> Sign -> Bool

(>) :: Sign -> Sign -> Bool

(>=) :: Sign -> Sign -> Bool

max :: Sign -> Sign -> Sign

min :: Sign -> Sign -> Sign

Show Sign Source # 
Instance details

Defined in Language.C.Types

Methods

showsPrec :: Int -> Sign -> ShowS

show :: Sign -> String

showList :: [Sign] -> ShowS

data ParameterDeclaration i Source #

Instances

Instances details
Functor ParameterDeclaration Source # 
Instance details

Defined in Language.C.Types

Foldable ParameterDeclaration Source # 
Instance details

Defined in Language.C.Types

Methods

fold :: Monoid m => ParameterDeclaration m -> m

foldMap :: Monoid m => (a -> m) -> ParameterDeclaration a -> m

foldMap' :: Monoid m => (a -> m) -> ParameterDeclaration a -> m

foldr :: (a -> b -> b) -> b -> ParameterDeclaration a -> b

foldr' :: (a -> b -> b) -> b -> ParameterDeclaration a -> b

foldl :: (b -> a -> b) -> b -> ParameterDeclaration a -> b

foldl' :: (b -> a -> b) -> b -> ParameterDeclaration a -> b

foldr1 :: (a -> a -> a) -> ParameterDeclaration a -> a

foldl1 :: (a -> a -> a) -> ParameterDeclaration a -> a

toList :: ParameterDeclaration a -> [a]

null :: ParameterDeclaration a -> Bool

length :: ParameterDeclaration a -> Int

elem :: Eq a => a -> ParameterDeclaration a -> Bool

maximum :: Ord a => ParameterDeclaration a -> a

minimum :: Ord a => ParameterDeclaration a -> a

sum :: Num a => ParameterDeclaration a -> a

product :: Num a => ParameterDeclaration a -> a

Traversable ParameterDeclaration Source # 
Instance details

Defined in Language.C.Types

Methods

traverse :: Applicative f => (a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b)

sequenceA :: Applicative f => ParameterDeclaration (f a) -> f (ParameterDeclaration a)

mapM :: Monad m => (a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b)

sequence :: Monad m => ParameterDeclaration (m a) -> m (ParameterDeclaration a)

Eq i => Eq (ParameterDeclaration i) Source # 
Instance details

Defined in Language.C.Types

Show i => Show (ParameterDeclaration i) Source # 
Instance details

Defined in Language.C.Types

Methods

showsPrec :: Int -> ParameterDeclaration i -> ShowS

show :: ParameterDeclaration i -> String

showList :: [ParameterDeclaration i] -> ShowS

Pretty i => Pretty (ParameterDeclaration i) Source # 
Instance details

Defined in Language.C.Types

Parsing

type TypeNames = HashSet CIdentifier Source #

A collection of named types (typedefs)

type CParser i m = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader (CParserContext i) m, MonadFail m, Hashable i) Source #

All the parsing is done using the type classes provided by the parsers package. You can use the parsing routines with any of the parsers that implement the classes, such as parsec or trifecta.

We parametrize the parsing by the type of the variable identifiers, i. We do so because we use this parser to implement anti-quoters referring to Haskell variables, and thus we need to parse Haskell identifiers in certain positions.

runCParser Source #

Arguments

:: Stream s Identity Char 
=> CParserContext i 
-> String

Source name.

-> s

String to parse.

-> ReaderT (CParserContext i) (Parsec s ()) a

Parser. Anything with type forall m. CParser i m => m a is a valid argument.

-> Either ParseError a 

Runs a CParser using parsec.

quickCParser Source #

Arguments

:: CParserContext i 
-> String

String to parse.

-> ReaderT (CParserContext i) (Parsec String ()) a

Parser. Anything with type forall m. CParser i m => m a is a valid argument.

-> a 

Useful for quick testing. Uses "quickCParser" as source name, and throws an error if parsing fails.

quickCParser_ Source #

Arguments

:: Bool 
-> String

String to parse.

-> ReaderT (CParserContext CIdentifier) (Parsec String ()) a

Parser. Anything with type forall m. CParser i m => m a is a valid argument.

-> a 

Like quickCParser, but uses cCParserContext (const False) as CParserContext.

parseEnableCpp :: CParser i m => m Bool Source #

parseType :: (CParser i m, Pretty i) => m (Type i) Source #

Convert to and from high-level views

data UntangleErr Source #

Instances

Instances details
Eq UntangleErr Source # 
Instance details

Defined in Language.C.Types

Methods

(==) :: UntangleErr -> UntangleErr -> Bool

(/=) :: UntangleErr -> UntangleErr -> Bool

Show UntangleErr Source # 
Instance details

Defined in Language.C.Types

Methods

showsPrec :: Int -> UntangleErr -> ShowS

show :: UntangleErr -> String

showList :: [UntangleErr] -> ShowS

Pretty UntangleErr Source # 
Instance details

Defined in Language.C.Types

To english