| Safe Haskell | None |
|---|---|
| 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 :: 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, Hashable i)
- data CParserContext i
- cCParserContext :: 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_ :: 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
- 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
- describeType :: Pretty i => Type i -> Doc
Types
data CIdentifier #
A type for C identifiers.
Instances
| Eq CIdentifier # | |
Defined in Language.C.Types.Parse | |
| Ord CIdentifier # | |
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 # | |
| Show CIdentifier # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> CIdentifier -> ShowS # show :: CIdentifier -> String # showList :: [CIdentifier] -> ShowS # | |
| IsString CIdentifier # | |
Defined in Language.C.Types.Parse Methods fromString :: String -> CIdentifier # | |
| Pretty CIdentifier # | |
Defined in Language.C.Types.Parse | |
| Hashable CIdentifier # | |
Defined in Language.C.Types.Parse | |
unCIdentifier :: CIdentifier -> String #
data StorageClassSpecifier #
Instances
| Eq StorageClassSpecifier # | |
Defined in Language.C.Types.Parse Methods (==) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool # (/=) :: StorageClassSpecifier -> StorageClassSpecifier -> Bool # | |
| Show StorageClassSpecifier # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> StorageClassSpecifier -> ShowS # show :: StorageClassSpecifier -> String # showList :: [StorageClassSpecifier] -> ShowS # | |
| Pretty StorageClassSpecifier # | |
Defined in Language.C.Types.Parse | |
data TypeQualifier #
Instances
| Eq TypeQualifier # | |
Defined in Language.C.Types.Parse Methods (==) :: TypeQualifier -> TypeQualifier -> Bool # (/=) :: TypeQualifier -> TypeQualifier -> Bool # | |
| Show TypeQualifier # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> TypeQualifier -> ShowS # show :: TypeQualifier -> String # showList :: [TypeQualifier] -> ShowS # | |
| Pretty TypeQualifier # | |
Defined in Language.C.Types.Parse | |
data FunctionSpecifier #
Constructors
| INLINE |
Instances
| Eq FunctionSpecifier # | |
Defined in Language.C.Types.Parse Methods (==) :: FunctionSpecifier -> FunctionSpecifier -> Bool # (/=) :: FunctionSpecifier -> FunctionSpecifier -> Bool # | |
| Show FunctionSpecifier # | |
Defined in Language.C.Types.Parse Methods showsPrec :: Int -> FunctionSpecifier -> ShowS # show :: FunctionSpecifier -> String # showList :: [FunctionSpecifier] -> ShowS # | |
| Pretty FunctionSpecifier # | |
Defined in Language.C.Types.Parse | |
Constructors
| VariablySized | |
| Unsized | |
| SizedByInteger Integer | |
| SizedByIdentifier i |
Instances
| Functor ArrayType # | |
| Foldable ArrayType # | |
Defined in Language.C.Types.Parse Methods fold :: Monoid m => ArrayType m -> 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 # | |
Defined in Language.C.Types.Parse | |
| Eq i => Eq (ArrayType i) # | |
| Show i => Show (ArrayType i) # | |
| Pretty i => Pretty (ArrayType i) # | |
Defined in Language.C.Types.Parse | |
data Specifiers #
Constructors
| Specifiers | |
Instances
| Eq Specifiers # | |
Defined in Language.C.Types | |
| Show Specifiers # | |
Defined in Language.C.Types Methods showsPrec :: Int -> Specifiers -> ShowS # show :: Specifiers -> String # showList :: [Specifiers] -> ShowS # | |
| Semigroup Specifiers # | |
Defined in Language.C.Types Methods (<>) :: Specifiers -> Specifiers -> Specifiers # sconcat :: NonEmpty Specifiers -> Specifiers # stimes :: Integral b => b -> Specifiers -> Specifiers # | |
| Monoid Specifiers # | |
Defined in Language.C.Types Methods mempty :: Specifiers # mappend :: Specifiers -> Specifiers -> Specifiers # mconcat :: [Specifiers] -> Specifiers # | |
Constructors
| TypeSpecifier Specifiers TypeSpecifier | |
| Ptr [TypeQualifier] (Type i) | |
| Array (ArrayType i) (Type i) | |
| Proto (Type i) [ParameterDeclaration i] |
Instances
| Functor Type # | |
| Foldable Type # | |
Defined in Language.C.Types Methods fold :: Monoid m => Type m -> 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 # | |
| Eq i => Eq (Type i) # | |
| Show i => Show (Type i) # | |
| Pretty i => Pretty (Type i) # | |
Defined in Language.C.Types | |
data TypeSpecifier #
Constructors
| Void | |
| Char (Maybe Sign) | |
| Short Sign | |
| Int Sign | |
| Long Sign | |
| LLong Sign | |
| Float | |
| Double | |
| LDouble | |
| TypeName CIdentifier | |
| Struct CIdentifier | |
| Enum CIdentifier |
Instances
| Eq TypeSpecifier # | |
Defined in Language.C.Types Methods (==) :: TypeSpecifier -> TypeSpecifier -> Bool # (/=) :: TypeSpecifier -> TypeSpecifier -> Bool # | |
| Ord TypeSpecifier # | |
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 # | |
| Show TypeSpecifier # | |
Defined in Language.C.Types Methods showsPrec :: Int -> TypeSpecifier -> ShowS # show :: TypeSpecifier -> String # showList :: [TypeSpecifier] -> ShowS # | |
| Pretty TypeSpecifier # | |
Defined in Language.C.Types | |
data ParameterDeclaration i #
Constructors
| ParameterDeclaration | |
Fields | |
Instances
Parsing
type TypeNames = HashSet CIdentifier #
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, Hashable i) #
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 #
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
| :: 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) #
parseParameterList :: (CParser i m, Pretty i) => m [ParameterDeclaration i] #
parseIdentifier :: CParser i m => m i #
Convert to and from high-level views
data UntangleErr #
Constructors
| MultipleDataTypes [DeclarationSpecifier] | |
| NoDataTypes [DeclarationSpecifier] | |
| IllegalSpecifiers String [TypeSpecifier] |
Instances
| Eq UntangleErr # | |
Defined in Language.C.Types | |
| Show UntangleErr # | |
Defined in Language.C.Types Methods showsPrec :: Int -> UntangleErr -> ShowS # show :: UntangleErr -> String # showList :: [UntangleErr] -> ShowS # | |
| Pretty UntangleErr # | |
Defined in Language.C.Types | |
untangleParameterDeclaration :: ParameterDeclaration i -> Either UntangleErr (ParameterDeclaration i) #
tangleParameterDeclaration :: forall i. ParameterDeclaration i -> ParameterDeclaration i #
To english
describeParameterDeclaration :: Pretty i => ParameterDeclaration i -> Doc #
describeType :: Pretty i => Type i -> Doc #