| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data CIdentifier
- unCIdentifier :: CIdentifier -> String
- cIdentifierFromString :: Bool -> String -> Either String CIdentifier
- data StorageClassSpecifier
- data TypeQualifier
- data FunctionSpecifier = INLINE
- data ArrayType i
- data Specifiers = Specifiers {}
- data Type i
- = TypeSpecifier Specifiers TypeSpecifier
- | Ptr [TypeQualifier] (Type i)
- | Array (ArrayType i) (Type i)
- | Proto (Type i) [ParameterDeclaration i]
- data TypeSpecifier
- data Sign
- data ParameterDeclaration i = ParameterDeclaration {}
- type TypeNames = HashSet CIdentifier
- 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)
- data CParserContext i
- cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier
- runCParser :: Stream s Identity Char => CParserContext i -> String -> s -> ReaderT (CParserContext i) (Parsec s ()) a -> Either ParseError a
- quickCParser :: CParserContext i -> String -> ReaderT (CParserContext i) (Parsec String ()) a -> a
- quickCParser_ :: Bool -> String -> ReaderT (CParserContext CIdentifier) (Parsec String ()) a -> a
- parseParameterDeclaration :: (CParser i m, Pretty i) => m (ParameterDeclaration i)
- parseParameterList :: (CParser i m, Pretty i) => m [ParameterDeclaration i]
- parseIdentifier :: CParser i m => m i
- parseEnableCpp :: CParser i m => m Bool
- parseType :: (CParser i m, Pretty i) => m (Type i)
- data UntangleErr
- untangleParameterDeclaration :: ParameterDeclaration i -> Either UntangleErr (ParameterDeclaration i)
- tangleParameterDeclaration :: forall i. ParameterDeclaration i -> ParameterDeclaration i
- describeParameterDeclaration :: Pretty i => ParameterDeclaration i -> Doc ann
- describeType :: Pretty i => Type i -> Doc ann
Types
data CIdentifier Source #
A type for C identifiers.
Instances
| IsString CIdentifier Source # | |
Defined in Language.C.Types.Parse Methods fromString :: String -> CIdentifier # | |
| Show CIdentifier Source # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> CIdentifier -> ShowS # show :: CIdentifier -> String # showList :: [CIdentifier] -> ShowS # | |
| Eq CIdentifier Source # | |
Defined in Language.C.Types.Parse | |
| Ord CIdentifier Source # | |
Defined in Language.C.Types.Parse Methods compare :: CIdentifier -> CIdentifier -> Ordering # (<) :: CIdentifier -> CIdentifier -> Bool # (<=) :: CIdentifier -> CIdentifier -> Bool # (>) :: CIdentifier -> CIdentifier -> Bool # (>=) :: CIdentifier -> CIdentifier -> Bool # max :: CIdentifier -> CIdentifier -> CIdentifier # min :: CIdentifier -> CIdentifier -> CIdentifier # | |
| Hashable CIdentifier Source # | |
Defined in Language.C.Types.Parse | |
| Pretty CIdentifier Source # | |
Defined in Language.C.Types.Parse | |
unCIdentifier :: CIdentifier -> String Source #
cIdentifierFromString :: Bool -> String -> Either String CIdentifier Source #
data StorageClassSpecifier Source #
Instances
| Show StorageClassSpecifier Source # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> StorageClassSpecifier -> ShowS # show :: StorageClassSpecifier -> String # showList :: [StorageClassSpecifier] -> ShowS # | |
| Eq StorageClassSpecifier Source # | |
Defined in Language.C.Types.Parse Methods (==) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool # (/=) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool # | |
| Pretty StorageClassSpecifier Source # | |
Defined in Language.C.Types.Parse Methods pretty :: StorageClassSpecifier -> Doc ann # prettyList :: [StorageClassSpecifier] -> Doc ann # | |
data TypeQualifier Source #
Instances
| Show TypeQualifier Source # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> TypeQualifier -> ShowS # show :: TypeQualifier -> String # showList :: [TypeQualifier] -> ShowS # | |
| Eq TypeQualifier Source # | |
Defined in Language.C.Types.Parse Methods (==) :: TypeQualifier -> TypeQualifier -> Bool # (/=) :: TypeQualifier -> TypeQualifier -> Bool # | |
| Pretty TypeQualifier Source # | |
Defined in Language.C.Types.Parse | |
data FunctionSpecifier Source #
Constructors
| INLINE |
Instances
| Show FunctionSpecifier Source # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> FunctionSpecifier -> ShowS # show :: FunctionSpecifier -> String # showList :: [FunctionSpecifier] -> ShowS # | |
| Eq FunctionSpecifier Source # | |
Defined in Language.C.Types.Parse Methods (==) :: FunctionSpecifier -> FunctionSpecifier -> Bool # (/=) :: FunctionSpecifier -> FunctionSpecifier -> Bool # | |
| Pretty FunctionSpecifier Source # | |
Defined in Language.C.Types.Parse | |
Constructors
| VariablySized | |
| Unsized | |
| SizedByInteger Integer | |
| SizedByIdentifier i |
Instances
| Foldable ArrayType Source # | |
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] # length :: ArrayType a -> Int # elem :: Eq a => a -> ArrayType a -> Bool # maximum :: Ord a => ArrayType a -> a # minimum :: Ord a => ArrayType a -> a # | |
| Traversable ArrayType Source # | |
Defined in Language.C.Types.Parse | |
| Functor ArrayType Source # | |
| Show i => Show (ArrayType i) Source # | |
| Eq i => Eq (ArrayType i) Source # | |
| Pretty i => Pretty (ArrayType i) Source # | |
Defined in Language.C.Types.Parse | |
data Specifiers Source #
Constructors
| Specifiers | |
Instances
| Monoid Specifiers Source # | |
Defined in Language.C.Types Methods mempty :: Specifiers # mappend :: Specifiers -> Specifiers -> Specifiers # mconcat :: [Specifiers] -> Specifiers # | |
| Semigroup Specifiers Source # | |
Defined in Language.C.Types Methods (<>) :: Specifiers -> Specifiers -> Specifiers # sconcat :: NonEmpty Specifiers -> Specifiers # stimes :: Integral b => b -> Specifiers -> Specifiers # | |
| Show Specifiers Source # | |
Defined in Language.C.Types Methods showsPrec :: Int -> Specifiers -> ShowS # show :: Specifiers -> String # showList :: [Specifiers] -> ShowS # | |
| Eq Specifiers Source # | |
Defined in Language.C.Types | |
Constructors
| TypeSpecifier Specifiers TypeSpecifier | |
| Ptr [TypeQualifier] (Type i) | |
| Array (ArrayType i) (Type i) | |
| Proto (Type i) [ParameterDeclaration i] |
Instances
| Foldable Type Source # | |
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 # elem :: Eq a => a -> Type a -> Bool # maximum :: Ord a => Type a -> a # | |
| Traversable Type Source # | |
| Functor Type Source # | |
| Show i => Show (Type i) Source # | |
| Eq i => Eq (Type i) Source # | |
| Pretty i => Pretty (Type i) Source # | |
Defined in Language.C.Types | |
data TypeSpecifier Source #
Constructors
Instances
| Show TypeSpecifier Source # | |
Defined in Language.C.Types Methods showsPrec :: Int -> TypeSpecifier -> ShowS # show :: TypeSpecifier -> String # showList :: [TypeSpecifier] -> ShowS # | |
| Eq TypeSpecifier Source # | |
Defined in Language.C.Types Methods (==) :: TypeSpecifier -> TypeSpecifier -> Bool # (/=) :: TypeSpecifier -> TypeSpecifier -> Bool # | |
| Ord TypeSpecifier Source # | |
Defined in Language.C.Types Methods compare :: TypeSpecifier -> TypeSpecifier -> Ordering # (<) :: TypeSpecifier -> TypeSpecifier -> Bool # (<=) :: TypeSpecifier -> TypeSpecifier -> Bool # (>) :: TypeSpecifier -> TypeSpecifier -> Bool # (>=) :: TypeSpecifier -> TypeSpecifier -> Bool # max :: TypeSpecifier -> TypeSpecifier -> TypeSpecifier # min :: TypeSpecifier -> TypeSpecifier -> TypeSpecifier # | |
| Pretty TypeSpecifier Source # | |
Defined in Language.C.Types | |
data ParameterDeclaration i Source #
Constructors
| ParameterDeclaration | |
Fields | |
Instances
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.
data CParserContext i Source #
cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier 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 |
| -> Either ParseError a |
Runs a using CParserparsec.
Arguments
| :: CParserContext i | |
| -> String | String to parse. |
| -> ReaderT (CParserContext i) (Parsec String ()) a | Parser. Anything with type |
| -> a |
Useful for quick testing. Uses "quickCParser" as source name, and throws
an error if parsing fails.
Arguments
| :: Bool | |
| -> String | String to parse. |
| -> ReaderT (CParserContext CIdentifier) (Parsec String ()) a | Parser. Anything with type |
| -> a |
Like quickCParser, but uses as
cCParserContext (const False)CParserContext.
parseParameterDeclaration :: (CParser i m, Pretty i) => m (ParameterDeclaration i) Source #
parseParameterList :: (CParser i m, Pretty i) => m [ParameterDeclaration i] Source #
parseIdentifier :: CParser i m => m i Source #
parseEnableCpp :: CParser i m => m Bool Source #
Convert to and from high-level views
data UntangleErr Source #
Constructors
| MultipleDataTypes [DeclarationSpecifier] | |
| NoDataTypes [DeclarationSpecifier] | |
| IllegalSpecifiers String [TypeSpecifier] |
Instances
| Show UntangleErr Source # | |
Defined in Language.C.Types Methods showsPrec :: Int -> UntangleErr -> ShowS # show :: UntangleErr -> String # showList :: [UntangleErr] -> ShowS # | |
| Eq UntangleErr Source # | |
Defined in Language.C.Types | |
| Pretty UntangleErr Source # | |
Defined in Language.C.Types | |
untangleParameterDeclaration :: ParameterDeclaration i -> Either UntangleErr (ParameterDeclaration i) Source #
tangleParameterDeclaration :: forall i. ParameterDeclaration i -> ParameterDeclaration i Source #
To english
describeParameterDeclaration :: Pretty i => ParameterDeclaration i -> Doc ann Source #