{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | A parser for C99 declarations. Currently, the parser has the following limitations:
--
-- * Array sizes can only be @*@, @n@ (where n is a positive integer), @x@
-- (where @x@ is a C identifier). In C99 they can be arbitrary expressions. See
-- the @'ArrayType'@ data type.
--
-- * @_Bool@, @_Complex@, and @_Imaginary@ are not present.
--
-- * Untyped parameter lists (pre-K&R C) are not allowed.
--
-- The parser is incremental and generic (see 'CParser').  'PP.Pretty'
-- and 'QC.Arbitrary' instances are provided for all the data types.
--
-- The entry point if you want to parse C declarations is
-- @'parameter_declaration'@.

module Language.C.Types.Parse
  ( -- * Parser configuration
    TypeNames
  , CParserContext(..)
    -- ** Default configuration
  , CIdentifier
  , unCIdentifier
  , cIdentifierFromString
  , cCParserContext

    -- * Parser type
  , CParser
  , runCParser
  , quickCParser
  , quickCParser_

    -- * Types and parsing
  -- , identifier
  , identifier_no_lex
  , DeclarationSpecifier(..)
  , declaration_specifiers
  , StorageClassSpecifier(..)
  , storage_class_specifier
  , TypeSpecifier(..)
  , type_specifier
  , TypeQualifier(..)
  , type_qualifier
  , FunctionSpecifier(..)
  , function_specifier
  , Declarator(..)
  , declarator
  , DirectDeclarator(..)
  , direct_declarator
  , ArrayOrProto(..)
  , array_or_proto
  , ArrayType(..)
  , array_type
  , Pointer(..)
  , pointer
  , ParameterDeclaration(..)
  , DeclaratorOrAbstractDeclarator(..)
  , parameter_declaration
  , parameter_list
  , AbstractDeclarator(..)
  , abstract_declarator
  , DirectAbstractDeclarator(..)
  , direct_abstract_declarator

    -- * YACC grammar
    -- $yacc

    -- * Testing utilities
  , cIdentStart
  , cIdentLetter
  , cReservedWords
  , isTypeName
  ) where

import           Control.Applicative
import           Control.Monad (msum, void, MonadPlus, unless, when)
import           Control.Monad.Reader (MonadReader, runReaderT, ReaderT, asks, ask)
import           Data.List (intersperse)
import           Data.Functor.Identity (Identity)
import qualified Data.HashSet as HashSet
import           Data.Hashable (Hashable)
import           Data.Monoid ((<>))
import           Data.String (IsString(..))
import           Data.Typeable (Typeable)
import qualified Text.Parsec as Parsec
import           Text.Parser.Char
import           Text.Parser.Combinators
import           Text.Parser.LookAhead
import           Text.Parser.Token
import qualified Text.Parser.Token.Highlight as Highlight
import           Text.PrettyPrint.ANSI.Leijen (Pretty(..), (<+>), Doc, hsep)
import qualified Text.PrettyPrint.ANSI.Leijen as PP

#if __GLASGOW_HASKELL__ < 710
import           Data.Foldable (Foldable)
import           Data.Traversable (Traversable)
#endif

------------------------------------------------------------------------
-- Config

-- | A collection of named types (typedefs)
type TypeNames = HashSet.HashSet CIdentifier

data CParserContext i = CParserContext
  { CParserContext i -> String
cpcIdentName :: String
  , CParserContext i -> TypeNames
cpcTypeNames :: TypeNames
    -- ^ Function used to determine whether an identifier is a type name.
  , CParserContext i -> forall (m :: * -> *). CParser i m => m i
cpcParseIdent :: forall m. CParser i m => m i
    -- ^ Parses an identifier, *without consuming whitespace afterwards*.
  , CParserContext i -> i -> String
cpcIdentToString :: i -> String
  , CParserContext i -> Bool
cpcEnableCpp :: Bool
  }

-- | A type for C identifiers.
newtype CIdentifier = CIdentifier {CIdentifier -> String
unCIdentifier :: String}
  deriving (Typeable, CIdentifier -> CIdentifier -> Bool
(CIdentifier -> CIdentifier -> Bool)
-> (CIdentifier -> CIdentifier -> Bool) -> Eq CIdentifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CIdentifier -> CIdentifier -> Bool
$c/= :: CIdentifier -> CIdentifier -> Bool
== :: CIdentifier -> CIdentifier -> Bool
$c== :: CIdentifier -> CIdentifier -> Bool
Eq, Eq CIdentifier
Eq CIdentifier
-> (CIdentifier -> CIdentifier -> Ordering)
-> (CIdentifier -> CIdentifier -> Bool)
-> (CIdentifier -> CIdentifier -> Bool)
-> (CIdentifier -> CIdentifier -> Bool)
-> (CIdentifier -> CIdentifier -> Bool)
-> (CIdentifier -> CIdentifier -> CIdentifier)
-> (CIdentifier -> CIdentifier -> CIdentifier)
-> Ord CIdentifier
CIdentifier -> CIdentifier -> Bool
CIdentifier -> CIdentifier -> Ordering
CIdentifier -> CIdentifier -> CIdentifier
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CIdentifier -> CIdentifier -> CIdentifier
$cmin :: CIdentifier -> CIdentifier -> CIdentifier
max :: CIdentifier -> CIdentifier -> CIdentifier
$cmax :: CIdentifier -> CIdentifier -> CIdentifier
>= :: CIdentifier -> CIdentifier -> Bool
$c>= :: CIdentifier -> CIdentifier -> Bool
> :: CIdentifier -> CIdentifier -> Bool
$c> :: CIdentifier -> CIdentifier -> Bool
<= :: CIdentifier -> CIdentifier -> Bool
$c<= :: CIdentifier -> CIdentifier -> Bool
< :: CIdentifier -> CIdentifier -> Bool
$c< :: CIdentifier -> CIdentifier -> Bool
compare :: CIdentifier -> CIdentifier -> Ordering
$ccompare :: CIdentifier -> CIdentifier -> Ordering
$cp1Ord :: Eq CIdentifier
Ord, Int -> CIdentifier -> ShowS
[CIdentifier] -> ShowS
CIdentifier -> String
(Int -> CIdentifier -> ShowS)
-> (CIdentifier -> String)
-> ([CIdentifier] -> ShowS)
-> Show CIdentifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CIdentifier] -> ShowS
$cshowList :: [CIdentifier] -> ShowS
show :: CIdentifier -> String
$cshow :: CIdentifier -> String
showsPrec :: Int -> CIdentifier -> ShowS
$cshowsPrec :: Int -> CIdentifier -> ShowS
Show, Int -> CIdentifier -> Int
CIdentifier -> Int
(Int -> CIdentifier -> Int)
-> (CIdentifier -> Int) -> Hashable CIdentifier
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: CIdentifier -> Int
$chash :: CIdentifier -> Int
hashWithSalt :: Int -> CIdentifier -> Int
$chashWithSalt :: Int -> CIdentifier -> Int
Hashable)

cIdentifierFromString :: Bool -> String -> Either String CIdentifier
cIdentifierFromString :: Bool -> String -> Either String CIdentifier
cIdentifierFromString Bool
useCpp String
s =
  -- Note: it's important not to use 'cidentifier_raw' here, otherwise
  -- we go in a loop:
  --
  -- @
  -- cIdentifierFromString => fromString => cIdentifierFromString => ...
  -- @
  case Parsec String () String
-> String -> String -> Either ParseError String
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
Parsec.parse (Bool
-> IdentifierStyle (ParsecT String () Identity)
-> Parsec String () String
forall (m :: * -> *) s.
(TokenParsing m, Monad m, IsString s) =>
Bool -> IdentifierStyle m -> m s
identNoLex Bool
useCpp IdentifierStyle (ParsecT String () Identity)
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle Parsec String () String
-> ParsecT String () Identity () -> Parsec String () String
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String () Identity ()
forall (m :: * -> *). Parsing m => m ()
eof) String
"cIdentifierFromString" String
s of
    Left ParseError
err -> String -> Either String CIdentifier
forall a b. a -> Either a b
Left (String -> Either String CIdentifier)
-> String -> Either String CIdentifier
forall a b. (a -> b) -> a -> b
$ ParseError -> String
forall a. Show a => a -> String
show ParseError
err
    Right String
x -> CIdentifier -> Either String CIdentifier
forall a b. b -> Either a b
Right (CIdentifier -> Either String CIdentifier)
-> CIdentifier -> Either String CIdentifier
forall a b. (a -> b) -> a -> b
$ String -> CIdentifier
CIdentifier String
x

instance IsString CIdentifier where
  fromString :: String -> CIdentifier
fromString String
s =
    case Bool -> String -> Either String CIdentifier
cIdentifierFromString Bool
True String
s of
      Left String
err -> String -> CIdentifier
forall a. HasCallStack => String -> a
error (String -> CIdentifier) -> String -> CIdentifier
forall a b. (a -> b) -> a -> b
$ String
"CIdentifier fromString: invalid string " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
err
      Right CIdentifier
x -> CIdentifier
x

cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier
cCParserContext :: Bool -> TypeNames -> CParserContext CIdentifier
cCParserContext Bool
useCpp TypeNames
typeNames = CParserContext :: forall i.
String
-> TypeNames
-> (forall (m :: * -> *). CParser i m => m i)
-> (i -> String)
-> Bool
-> CParserContext i
CParserContext
  { cpcTypeNames :: TypeNames
cpcTypeNames = TypeNames
typeNames
  , cpcParseIdent :: forall (m :: * -> *). CParser CIdentifier m => m CIdentifier
cpcParseIdent = forall i (m :: * -> *). CParser i m => m CIdentifier
forall (m :: * -> *). CParser CIdentifier m => m CIdentifier
cidentifier_no_lex
  , cpcIdentToString :: CIdentifier -> String
cpcIdentToString = CIdentifier -> String
unCIdentifier
  , cpcIdentName :: String
cpcIdentName = String
"C identifier"
  , cpcEnableCpp :: Bool
cpcEnableCpp = Bool
useCpp
  }

------------------------------------------------------------------------
-- Parser

-- | 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.
type CParser i m =
  ( Monad m
  , Functor m
  , Applicative m
  , MonadPlus m
  , Parsing m
  , CharParsing m
  , TokenParsing m
  , LookAheadParsing m
  , MonadReader (CParserContext i) m
#if (MIN_VERSION_base(4,13,0))
  , MonadFail m
#endif
  , Hashable i
  )

-- | Runs a @'CParser'@ using @parsec@.
runCParser
  :: Parsec.Stream s Identity Char
  => CParserContext i
  -> String
  -- ^ Source name.
  -> s
  -- ^ String to parse.
  -> (ReaderT (CParserContext i) (Parsec.Parsec s ()) a)
  -- ^ Parser.  Anything with type @forall m. CParser i m => m a@ is a
  -- valid argument.
  -> Either Parsec.ParseError a
runCParser :: CParserContext i
-> String
-> s
-> ReaderT (CParserContext i) (Parsec s ()) a
-> Either ParseError a
runCParser CParserContext i
typeNames String
fn s
s ReaderT (CParserContext i) (Parsec s ()) a
p = Parsec s () a -> String -> s -> Either ParseError a
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
Parsec.parse (ReaderT (CParserContext i) (Parsec s ()) a
-> CParserContext i -> Parsec s () a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT (CParserContext i) (Parsec s ()) a
p CParserContext i
typeNames) String
fn s
s

-- | Useful for quick testing.  Uses @\"quickCParser\"@ as source name, and throws
-- an 'error' if parsing fails.
quickCParser
  :: CParserContext i
  -> String
  -- ^ String to parse.
  -> (ReaderT (CParserContext i) (Parsec.Parsec String ()) a)
  -- ^ Parser.  Anything with type @forall m. CParser i m => m a@ is a
  -- valid argument.
  -> a
quickCParser :: CParserContext i
-> String
-> ReaderT (CParserContext i) (ParsecT String () Identity) a
-> a
quickCParser CParserContext i
typeNames String
s ReaderT (CParserContext i) (ParsecT String () Identity) a
p = case CParserContext i
-> String
-> String
-> ReaderT (CParserContext i) (ParsecT String () Identity) a
-> Either ParseError a
forall s i a.
Stream s Identity Char =>
CParserContext i
-> String
-> s
-> ReaderT (CParserContext i) (Parsec s ()) a
-> Either ParseError a
runCParser CParserContext i
typeNames String
"quickCParser" String
s ReaderT (CParserContext i) (ParsecT String () Identity) a
p of
  Left ParseError
err -> String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"quickCParser: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ParseError -> String
forall a. Show a => a -> String
show ParseError
err
  Right a
x -> a
x

-- | Like 'quickCParser', but uses @'cCParserContext' ('const' 'False')@ as
-- 'CParserContext'.
quickCParser_
  :: Bool
  -> String
  -- ^ String to parse.
  -> (ReaderT (CParserContext CIdentifier) (Parsec.Parsec String ()) a)
  -- ^ Parser.  Anything with type @forall m. CParser i m => m a@ is a
  -- valid argument.
  -> a
quickCParser_ :: Bool
-> String
-> ReaderT
     (CParserContext CIdentifier) (ParsecT String () Identity) a
-> a
quickCParser_ Bool
useCpp = CParserContext CIdentifier
-> String
-> ReaderT
     (CParserContext CIdentifier) (ParsecT String () Identity) a
-> a
forall i a.
CParserContext i
-> String
-> ReaderT (CParserContext i) (ParsecT String () Identity) a
-> a
quickCParser (Bool -> TypeNames -> CParserContext CIdentifier
cCParserContext Bool
useCpp TypeNames
forall a. HashSet a
HashSet.empty)

cReservedWords :: HashSet.HashSet String
cReservedWords :: HashSet String
cReservedWords = [String] -> HashSet String
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList
  [ String
"auto", String
"else", String
"long", String
"switch"
  , String
"break", String
"enum", String
"register", String
"typedef"
  , String
"case", String
"extern", String
"return", String
"union"
  , String
"char", String
"float", String
"short", String
"unsigned"
  , String
"const", String
"for", String
"signed", String
"void"
  , String
"continue", String
"goto", String
"sizeof", String
"volatile"
  , String
"default", String
"if", String
"static", String
"while"
  , String
"do", String
"int", String
"struct", String
"double"
  ]

cIdentStart :: [Char]
cIdentStart :: String
cIdentStart = [Char
'a'..Char
'z'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
'A'..Char
'Z'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
'_']

cIdentLetter :: [Char]
cIdentLetter :: String
cIdentLetter = [Char
'a'..Char
'z'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
'A'..Char
'Z'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
'_'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
'0'..Char
'9']

cIdentStyle :: (TokenParsing m, Monad m) => IdentifierStyle m
cIdentStyle :: IdentifierStyle m
cIdentStyle = IdentifierStyle :: forall (m :: * -> *).
String
-> m Char
-> m Char
-> HashSet String
-> Highlight
-> Highlight
-> IdentifierStyle m
IdentifierStyle
  { _styleName :: String
_styleName = String
"C identifier"
  , _styleStart :: m Char
_styleStart = String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
cIdentStart
  , _styleLetter :: m Char
_styleLetter = String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf String
cIdentLetter
  , _styleReserved :: HashSet String
_styleReserved = HashSet String
cReservedWords
  , _styleHighlight :: Highlight
_styleHighlight = Highlight
Highlight.Identifier
  , _styleReservedHighlight :: Highlight
_styleReservedHighlight = Highlight
Highlight.ReservedIdentifier
  }

data DeclarationSpecifier
  = StorageClassSpecifier StorageClassSpecifier
  | TypeSpecifier TypeSpecifier
  | TypeQualifier TypeQualifier
  | FunctionSpecifier FunctionSpecifier
  deriving (Typeable, DeclarationSpecifier -> DeclarationSpecifier -> Bool
(DeclarationSpecifier -> DeclarationSpecifier -> Bool)
-> (DeclarationSpecifier -> DeclarationSpecifier -> Bool)
-> Eq DeclarationSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeclarationSpecifier -> DeclarationSpecifier -> Bool
$c/= :: DeclarationSpecifier -> DeclarationSpecifier -> Bool
== :: DeclarationSpecifier -> DeclarationSpecifier -> Bool
$c== :: DeclarationSpecifier -> DeclarationSpecifier -> Bool
Eq, Int -> DeclarationSpecifier -> ShowS
[DeclarationSpecifier] -> ShowS
DeclarationSpecifier -> String
(Int -> DeclarationSpecifier -> ShowS)
-> (DeclarationSpecifier -> String)
-> ([DeclarationSpecifier] -> ShowS)
-> Show DeclarationSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeclarationSpecifier] -> ShowS
$cshowList :: [DeclarationSpecifier] -> ShowS
show :: DeclarationSpecifier -> String
$cshow :: DeclarationSpecifier -> String
showsPrec :: Int -> DeclarationSpecifier -> ShowS
$cshowsPrec :: Int -> DeclarationSpecifier -> ShowS
Show)

declaration_specifiers :: CParser i m => m [DeclarationSpecifier]
declaration_specifiers :: m [DeclarationSpecifier]
declaration_specifiers = m DeclarationSpecifier -> m [DeclarationSpecifier]
forall i (m :: * -> *) a. CParser i m => m a -> m [a]
many1 (m DeclarationSpecifier -> m [DeclarationSpecifier])
-> m DeclarationSpecifier -> m [DeclarationSpecifier]
forall a b. (a -> b) -> a -> b
$ [m DeclarationSpecifier] -> m DeclarationSpecifier
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ StorageClassSpecifier -> DeclarationSpecifier
StorageClassSpecifier (StorageClassSpecifier -> DeclarationSpecifier)
-> m StorageClassSpecifier -> m DeclarationSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m StorageClassSpecifier
forall i (m :: * -> *). CParser i m => m StorageClassSpecifier
storage_class_specifier
  , TypeSpecifier -> DeclarationSpecifier
TypeSpecifier (TypeSpecifier -> DeclarationSpecifier)
-> m TypeSpecifier -> m DeclarationSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TypeSpecifier
forall i (m :: * -> *). CParser i m => m TypeSpecifier
type_specifier
  , TypeQualifier -> DeclarationSpecifier
TypeQualifier (TypeQualifier -> DeclarationSpecifier)
-> m TypeQualifier -> m DeclarationSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TypeQualifier
forall i (m :: * -> *). CParser i m => m TypeQualifier
type_qualifier
  , FunctionSpecifier -> DeclarationSpecifier
FunctionSpecifier (FunctionSpecifier -> DeclarationSpecifier)
-> m FunctionSpecifier -> m DeclarationSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m FunctionSpecifier
forall i (m :: * -> *). CParser i m => m FunctionSpecifier
function_specifier
  ]

data StorageClassSpecifier
  = TYPEDEF
  | EXTERN
  | STATIC
  | AUTO
  | REGISTER
  deriving (Typeable, StorageClassSpecifier -> StorageClassSpecifier -> Bool
(StorageClassSpecifier -> StorageClassSpecifier -> Bool)
-> (StorageClassSpecifier -> StorageClassSpecifier -> Bool)
-> Eq StorageClassSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StorageClassSpecifier -> StorageClassSpecifier -> Bool
$c/= :: StorageClassSpecifier -> StorageClassSpecifier -> Bool
== :: StorageClassSpecifier -> StorageClassSpecifier -> Bool
$c== :: StorageClassSpecifier -> StorageClassSpecifier -> Bool
Eq, Int -> StorageClassSpecifier -> ShowS
[StorageClassSpecifier] -> ShowS
StorageClassSpecifier -> String
(Int -> StorageClassSpecifier -> ShowS)
-> (StorageClassSpecifier -> String)
-> ([StorageClassSpecifier] -> ShowS)
-> Show StorageClassSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StorageClassSpecifier] -> ShowS
$cshowList :: [StorageClassSpecifier] -> ShowS
show :: StorageClassSpecifier -> String
$cshow :: StorageClassSpecifier -> String
showsPrec :: Int -> StorageClassSpecifier -> ShowS
$cshowsPrec :: Int -> StorageClassSpecifier -> ShowS
Show)

storage_class_specifier :: CParser i m => m StorageClassSpecifier
storage_class_specifier :: m StorageClassSpecifier
storage_class_specifier = [m StorageClassSpecifier] -> m StorageClassSpecifier
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ StorageClassSpecifier
TYPEDEF StorageClassSpecifier -> m () -> m StorageClassSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"typedef"
  , StorageClassSpecifier
EXTERN StorageClassSpecifier -> m () -> m StorageClassSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"extern"
  , StorageClassSpecifier
STATIC StorageClassSpecifier -> m () -> m StorageClassSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"static"
  , StorageClassSpecifier
AUTO StorageClassSpecifier -> m () -> m StorageClassSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"auto"
  , StorageClassSpecifier
REGISTER StorageClassSpecifier -> m () -> m StorageClassSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"register"
  ]

data TypeSpecifier
  = VOID
  | BOOL
  | CHAR
  | SHORT
  | INT
  | LONG
  | FLOAT
  | DOUBLE
  | SIGNED
  | UNSIGNED
  | Struct CIdentifier
  | Enum CIdentifier
  | TypeName CIdentifier
  | Template CIdentifier [TypeSpecifier]
  | TemplateConst String
  | TemplatePointer TypeSpecifier
  deriving (Typeable, TypeSpecifier -> TypeSpecifier -> Bool
(TypeSpecifier -> TypeSpecifier -> Bool)
-> (TypeSpecifier -> TypeSpecifier -> Bool) -> Eq TypeSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypeSpecifier -> TypeSpecifier -> Bool
$c/= :: TypeSpecifier -> TypeSpecifier -> Bool
== :: TypeSpecifier -> TypeSpecifier -> Bool
$c== :: TypeSpecifier -> TypeSpecifier -> Bool
Eq, Int -> TypeSpecifier -> ShowS
[TypeSpecifier] -> ShowS
TypeSpecifier -> String
(Int -> TypeSpecifier -> ShowS)
-> (TypeSpecifier -> String)
-> ([TypeSpecifier] -> ShowS)
-> Show TypeSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeSpecifier] -> ShowS
$cshowList :: [TypeSpecifier] -> ShowS
show :: TypeSpecifier -> String
$cshow :: TypeSpecifier -> String
showsPrec :: Int -> TypeSpecifier -> ShowS
$cshowsPrec :: Int -> TypeSpecifier -> ShowS
Show)

type_specifier :: CParser i m => m TypeSpecifier
type_specifier :: m TypeSpecifier
type_specifier = [m TypeSpecifier] -> m TypeSpecifier
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ TypeSpecifier
VOID TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"void"
  , TypeSpecifier
BOOL TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"bool"
  , TypeSpecifier
CHAR TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"char"
  , TypeSpecifier
SHORT TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"short"
  , TypeSpecifier
INT TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"int"
  , TypeSpecifier
LONG TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"long"
  , TypeSpecifier
FLOAT TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"float"
  , TypeSpecifier
DOUBLE TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"double"
  , TypeSpecifier
SIGNED TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"signed"
  , TypeSpecifier
UNSIGNED TypeSpecifier -> m () -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"unsigned"
  , CIdentifier -> TypeSpecifier
Struct (CIdentifier -> TypeSpecifier) -> m CIdentifier -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"struct" m () -> m CIdentifier -> m CIdentifier
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m CIdentifier
forall i (m :: * -> *). CParser i m => m CIdentifier
cidentifier)
  , CIdentifier -> TypeSpecifier
Enum (CIdentifier -> TypeSpecifier) -> m CIdentifier -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"enum" m () -> m CIdentifier -> m CIdentifier
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m CIdentifier
forall i (m :: * -> *). CParser i m => m CIdentifier
cidentifier)
  , m TypeSpecifier
forall i (m :: * -> *). CParser i m => m TypeSpecifier
template_parser
  , CIdentifier -> TypeSpecifier
TypeName (CIdentifier -> TypeSpecifier) -> m CIdentifier -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m CIdentifier
forall i (m :: * -> *). CParser i m => m CIdentifier
type_name
  ]

identifier :: CParser i m => m i
identifier :: m i
identifier = m i -> m i
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token m i
forall i (m :: * -> *). CParser i m => m i
identifier_no_lex

isTypeName :: Bool -> TypeNames -> String -> Bool
isTypeName :: Bool -> TypeNames -> String -> Bool
isTypeName Bool
useCpp TypeNames
typeNames String
id_ =
  case Bool -> String -> Either String CIdentifier
cIdentifierFromString Bool
useCpp String
id_ of
    -- If it's not a valid C identifier, then it's definitely not a C type name.
    Left String
_err -> Bool
False
    Right CIdentifier
s -> CIdentifier -> TypeNames -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member CIdentifier
s TypeNames
typeNames

identifier_no_lex :: CParser i m => m i
identifier_no_lex :: m i
identifier_no_lex = m i -> m i
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m i -> m i) -> m i -> m i
forall a b. (a -> b) -> a -> b
$ do
  CParserContext i
ctx <- m (CParserContext i)
forall r (m :: * -> *). MonadReader r m => m r
ask
  i
id_ <- CParserContext i -> forall (m :: * -> *). CParser i m => m i
forall i.
CParserContext i -> forall (m :: * -> *). CParser i m => m i
cpcParseIdent CParserContext i
ctx m i -> String -> m i
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> CParserContext i -> String
forall i. CParserContext i -> String
cpcIdentName CParserContext i
ctx
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> TypeNames -> String -> Bool
isTypeName (CParserContext i -> Bool
forall i. CParserContext i -> Bool
cpcEnableCpp CParserContext i
ctx) (CParserContext i -> TypeNames
forall i. CParserContext i -> TypeNames
cpcTypeNames CParserContext i
ctx) (CParserContext i -> i -> String
forall i. CParserContext i -> i -> String
cpcIdentToString CParserContext i
ctx i
id_)) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
    String -> m ()
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"type name " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CParserContext i -> i -> String
forall i. CParserContext i -> i -> String
cpcIdentToString CParserContext i
ctx i
id_
  i -> m i
forall (m :: * -> *) a. Monad m => a -> m a
return i
id_

-- | Same as 'cidentifier_no_lex', but does not check that the
-- identifier is not a type name.
cidentifier_raw :: (TokenParsing m, Monad m) => Bool -> m CIdentifier
cidentifier_raw :: Bool -> m CIdentifier
cidentifier_raw Bool
useCpp = Bool -> IdentifierStyle m -> m CIdentifier
forall (m :: * -> *) s.
(TokenParsing m, Monad m, IsString s) =>
Bool -> IdentifierStyle m -> m s
identNoLex Bool
useCpp IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle

-- | This parser parses a 'CIdentifier' and nothing else -- it does not consume
-- trailing spaces and the like.
cidentifier_no_lex :: CParser i m => m CIdentifier
cidentifier_no_lex :: m CIdentifier
cidentifier_no_lex = m CIdentifier -> m CIdentifier
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m CIdentifier -> m CIdentifier) -> m CIdentifier -> m CIdentifier
forall a b. (a -> b) -> a -> b
$ do
  CParserContext i
ctx <- m (CParserContext i)
forall r (m :: * -> *). MonadReader r m => m r
ask
  CIdentifier
s <- Bool -> m CIdentifier
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
Bool -> m CIdentifier
cidentifier_raw (CParserContext i -> Bool
forall i. CParserContext i -> Bool
cpcEnableCpp CParserContext i
ctx)
  TypeNames
typeNames <- (CParserContext i -> TypeNames) -> m TypeNames
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks CParserContext i -> TypeNames
forall i. CParserContext i -> TypeNames
cpcTypeNames
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CIdentifier -> TypeNames -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member CIdentifier
s TypeNames
typeNames) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
    String -> m ()
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"type name " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CIdentifier -> String
unCIdentifier CIdentifier
s
  CIdentifier -> m CIdentifier
forall (m :: * -> *) a. Monad m => a -> m a
return CIdentifier
s

cidentifier :: CParser i m => m CIdentifier
cidentifier :: m CIdentifier
cidentifier = m CIdentifier -> m CIdentifier
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token m CIdentifier
forall i (m :: * -> *). CParser i m => m CIdentifier
cidentifier_no_lex

type_name :: CParser i m => m CIdentifier
type_name :: m CIdentifier
type_name = m CIdentifier -> m CIdentifier
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m CIdentifier -> m CIdentifier) -> m CIdentifier -> m CIdentifier
forall a b. (a -> b) -> a -> b
$ do
  CParserContext i
ctx <- m (CParserContext i)
forall r (m :: * -> *). MonadReader r m => m r
ask
  CIdentifier
s <- Bool -> IdentifierStyle m -> m CIdentifier
forall (m :: * -> *) s.
(TokenParsing m, Monad m, IsString s) =>
Bool -> IdentifierStyle m -> m s
ident' (CParserContext i -> Bool
forall i. CParserContext i -> Bool
cpcEnableCpp CParserContext i
ctx) IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle m CIdentifier -> String -> m CIdentifier
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"type name"
  TypeNames
typeNames <- (CParserContext i -> TypeNames) -> m TypeNames
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks CParserContext i -> TypeNames
forall i. CParserContext i -> TypeNames
cpcTypeNames
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (CIdentifier -> TypeNames -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member CIdentifier
s TypeNames
typeNames) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
    String -> m ()
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"identifier  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CIdentifier -> String
unCIdentifier CIdentifier
s
  CIdentifier -> m CIdentifier
forall (m :: * -> *) a. Monad m => a -> m a
return CIdentifier
s

templateParser :: (Monad m, CharParsing m, CParser i m) => IdentifierStyle m -> m TypeSpecifier
templateParser :: IdentifierStyle m -> m TypeSpecifier
templateParser IdentifierStyle m
s = m TypeSpecifier
parse'
  where
    parse' :: m TypeSpecifier
parse' = do
      String
id' <- m String
cidentParserWithNamespace
      String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
"<"
      [TypeSpecifier]
args <- m [TypeSpecifier]
templateArgParser
      String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
">"
      TypeSpecifier -> m TypeSpecifier
forall (m :: * -> *) a. Monad m => a -> m a
return (TypeSpecifier -> m TypeSpecifier)
-> TypeSpecifier -> m TypeSpecifier
forall a b. (a -> b) -> a -> b
$ CIdentifier -> [TypeSpecifier] -> TypeSpecifier
Template (String -> CIdentifier
CIdentifier String
id') [TypeSpecifier]
args
    cidentParser :: m String
cidentParser = ((:) (Char -> ShowS) -> m Char -> m ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
s m ShowS -> m String -> m String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Char -> m String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) m String -> String -> m String
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s)
    cidentParserWithNamespace :: m String
cidentParserWithNamespace =
      m String -> m String
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> m [String] -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [m String] -> m [String]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [m String
cidentParser, (String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
"::"), m String
cidentParserWithNamespace]) m String -> m String -> m String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      m String
cidentParser
    templateArgType :: m TypeSpecifier
templateArgType = m TypeSpecifier -> m TypeSpecifier
forall (m :: * -> *) a. Parsing m => m a -> m a
try ((TypeSpecifier -> TypeSpecifier
TemplatePointer (TypeSpecifier -> TypeSpecifier)
-> m TypeSpecifier -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (m TypeSpecifier
forall i (m :: * -> *). CParser i m => m TypeSpecifier
type_specifier)) m TypeSpecifier -> m String -> m TypeSpecifier
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
"*")) m TypeSpecifier -> m TypeSpecifier -> m TypeSpecifier
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m TypeSpecifier -> m TypeSpecifier
forall (m :: * -> *) a. Parsing m => m a -> m a
try m TypeSpecifier
forall i (m :: * -> *). CParser i m => m TypeSpecifier
type_specifier m TypeSpecifier -> m TypeSpecifier -> m TypeSpecifier
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (String -> TypeSpecifier
TemplateConst (String -> TypeSpecifier) -> m String -> m TypeSpecifier
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (m Char -> m String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (m Char -> m String) -> m Char -> m String
forall a b. (a -> b) -> a -> b
$ String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
oneOf [Char
'0'..Char
'9']))
    templateArgParser' :: m [TypeSpecifier]
templateArgParser' = do
      TypeSpecifier
t <- m TypeSpecifier
templateArgType
      String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
","
      [TypeSpecifier]
tt <- m [TypeSpecifier]
templateArgParser
      [TypeSpecifier] -> m [TypeSpecifier]
forall (m :: * -> *) a. Monad m => a -> m a
return ([TypeSpecifier] -> m [TypeSpecifier])
-> [TypeSpecifier] -> m [TypeSpecifier]
forall a b. (a -> b) -> a -> b
$ TypeSpecifier
tTypeSpecifier -> [TypeSpecifier] -> [TypeSpecifier]
forall a. a -> [a] -> [a]
:[TypeSpecifier]
tt
    templateArgParser :: m [TypeSpecifier]
templateArgParser =
      m [TypeSpecifier] -> m [TypeSpecifier]
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m [TypeSpecifier]
templateArgParser') m [TypeSpecifier] -> m [TypeSpecifier] -> m [TypeSpecifier]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((:) (TypeSpecifier -> [TypeSpecifier] -> [TypeSpecifier])
-> m TypeSpecifier -> m ([TypeSpecifier] -> [TypeSpecifier])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TypeSpecifier
templateArgType m ([TypeSpecifier] -> [TypeSpecifier])
-> m [TypeSpecifier] -> m [TypeSpecifier]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [TypeSpecifier] -> m [TypeSpecifier]
forall (m :: * -> *) a. Monad m => a -> m a
return [])

template_parser :: CParser i m => m TypeSpecifier
template_parser :: m TypeSpecifier
template_parser = m TypeSpecifier -> m TypeSpecifier
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m TypeSpecifier -> m TypeSpecifier)
-> m TypeSpecifier -> m TypeSpecifier
forall a b. (a -> b) -> a -> b
$ IdentifierStyle m -> m TypeSpecifier
forall (m :: * -> *) i.
(Monad m, CharParsing m, CParser i m) =>
IdentifierStyle m -> m TypeSpecifier
templateParser IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle m TypeSpecifier -> String -> m TypeSpecifier
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"template name"

data TypeQualifier
  = CONST
  | RESTRICT
  | VOLATILE
  deriving (Typeable, TypeQualifier -> TypeQualifier -> Bool
(TypeQualifier -> TypeQualifier -> Bool)
-> (TypeQualifier -> TypeQualifier -> Bool) -> Eq TypeQualifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypeQualifier -> TypeQualifier -> Bool
$c/= :: TypeQualifier -> TypeQualifier -> Bool
== :: TypeQualifier -> TypeQualifier -> Bool
$c== :: TypeQualifier -> TypeQualifier -> Bool
Eq, Int -> TypeQualifier -> ShowS
[TypeQualifier] -> ShowS
TypeQualifier -> String
(Int -> TypeQualifier -> ShowS)
-> (TypeQualifier -> String)
-> ([TypeQualifier] -> ShowS)
-> Show TypeQualifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeQualifier] -> ShowS
$cshowList :: [TypeQualifier] -> ShowS
show :: TypeQualifier -> String
$cshow :: TypeQualifier -> String
showsPrec :: Int -> TypeQualifier -> ShowS
$cshowsPrec :: Int -> TypeQualifier -> ShowS
Show)

type_qualifier :: CParser i m => m TypeQualifier
type_qualifier :: m TypeQualifier
type_qualifier = [m TypeQualifier] -> m TypeQualifier
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ TypeQualifier
CONST TypeQualifier -> m () -> m TypeQualifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"const"
  , TypeQualifier
RESTRICT TypeQualifier -> m () -> m TypeQualifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"restrict"
  , TypeQualifier
VOLATILE TypeQualifier -> m () -> m TypeQualifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"volatile"
  ]

data FunctionSpecifier
  = INLINE
  deriving (Typeable, FunctionSpecifier -> FunctionSpecifier -> Bool
(FunctionSpecifier -> FunctionSpecifier -> Bool)
-> (FunctionSpecifier -> FunctionSpecifier -> Bool)
-> Eq FunctionSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionSpecifier -> FunctionSpecifier -> Bool
$c/= :: FunctionSpecifier -> FunctionSpecifier -> Bool
== :: FunctionSpecifier -> FunctionSpecifier -> Bool
$c== :: FunctionSpecifier -> FunctionSpecifier -> Bool
Eq, Int -> FunctionSpecifier -> ShowS
[FunctionSpecifier] -> ShowS
FunctionSpecifier -> String
(Int -> FunctionSpecifier -> ShowS)
-> (FunctionSpecifier -> String)
-> ([FunctionSpecifier] -> ShowS)
-> Show FunctionSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionSpecifier] -> ShowS
$cshowList :: [FunctionSpecifier] -> ShowS
show :: FunctionSpecifier -> String
$cshow :: FunctionSpecifier -> String
showsPrec :: Int -> FunctionSpecifier -> ShowS
$cshowsPrec :: Int -> FunctionSpecifier -> ShowS
Show)

function_specifier :: CParser i m => m FunctionSpecifier
function_specifier :: m FunctionSpecifier
function_specifier = [m FunctionSpecifier] -> m FunctionSpecifier
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ FunctionSpecifier
INLINE FunctionSpecifier -> m () -> m FunctionSpecifier
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
reserve IdentifierStyle m
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m
cIdentStyle String
"inline"
  ]

data Declarator i = Declarator
  { Declarator i -> [Pointer]
declaratorPointers :: [Pointer]
  , Declarator i -> DirectDeclarator i
declaratorDirect :: (DirectDeclarator i)
  } deriving (Typeable, Declarator i -> Declarator i -> Bool
(Declarator i -> Declarator i -> Bool)
-> (Declarator i -> Declarator i -> Bool) -> Eq (Declarator i)
forall i. Eq i => Declarator i -> Declarator i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Declarator i -> Declarator i -> Bool
$c/= :: forall i. Eq i => Declarator i -> Declarator i -> Bool
== :: Declarator i -> Declarator i -> Bool
$c== :: forall i. Eq i => Declarator i -> Declarator i -> Bool
Eq, Int -> Declarator i -> ShowS
[Declarator i] -> ShowS
Declarator i -> String
(Int -> Declarator i -> ShowS)
-> (Declarator i -> String)
-> ([Declarator i] -> ShowS)
-> Show (Declarator i)
forall i. Show i => Int -> Declarator i -> ShowS
forall i. Show i => [Declarator i] -> ShowS
forall i. Show i => Declarator i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Declarator i] -> ShowS
$cshowList :: forall i. Show i => [Declarator i] -> ShowS
show :: Declarator i -> String
$cshow :: forall i. Show i => Declarator i -> String
showsPrec :: Int -> Declarator i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> Declarator i -> ShowS
Show, a -> Declarator b -> Declarator a
(a -> b) -> Declarator a -> Declarator b
(forall a b. (a -> b) -> Declarator a -> Declarator b)
-> (forall a b. a -> Declarator b -> Declarator a)
-> Functor Declarator
forall a b. a -> Declarator b -> Declarator a
forall a b. (a -> b) -> Declarator a -> Declarator b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Declarator b -> Declarator a
$c<$ :: forall a b. a -> Declarator b -> Declarator a
fmap :: (a -> b) -> Declarator a -> Declarator b
$cfmap :: forall a b. (a -> b) -> Declarator a -> Declarator b
Functor, Declarator a -> Bool
(a -> m) -> Declarator a -> m
(a -> b -> b) -> b -> Declarator a -> b
(forall m. Monoid m => Declarator m -> m)
-> (forall m a. Monoid m => (a -> m) -> Declarator a -> m)
-> (forall m a. Monoid m => (a -> m) -> Declarator a -> m)
-> (forall a b. (a -> b -> b) -> b -> Declarator a -> b)
-> (forall a b. (a -> b -> b) -> b -> Declarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> Declarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> Declarator a -> b)
-> (forall a. (a -> a -> a) -> Declarator a -> a)
-> (forall a. (a -> a -> a) -> Declarator a -> a)
-> (forall a. Declarator a -> [a])
-> (forall a. Declarator a -> Bool)
-> (forall a. Declarator a -> Int)
-> (forall a. Eq a => a -> Declarator a -> Bool)
-> (forall a. Ord a => Declarator a -> a)
-> (forall a. Ord a => Declarator a -> a)
-> (forall a. Num a => Declarator a -> a)
-> (forall a. Num a => Declarator a -> a)
-> Foldable Declarator
forall a. Eq a => a -> Declarator a -> Bool
forall a. Num a => Declarator a -> a
forall a. Ord a => Declarator a -> a
forall m. Monoid m => Declarator m -> m
forall a. Declarator a -> Bool
forall a. Declarator a -> Int
forall a. Declarator a -> [a]
forall a. (a -> a -> a) -> Declarator a -> a
forall m a. Monoid m => (a -> m) -> Declarator a -> m
forall b a. (b -> a -> b) -> b -> Declarator a -> b
forall a b. (a -> b -> b) -> b -> Declarator a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Declarator a -> a
$cproduct :: forall a. Num a => Declarator a -> a
sum :: Declarator a -> a
$csum :: forall a. Num a => Declarator a -> a
minimum :: Declarator a -> a
$cminimum :: forall a. Ord a => Declarator a -> a
maximum :: Declarator a -> a
$cmaximum :: forall a. Ord a => Declarator a -> a
elem :: a -> Declarator a -> Bool
$celem :: forall a. Eq a => a -> Declarator a -> Bool
length :: Declarator a -> Int
$clength :: forall a. Declarator a -> Int
null :: Declarator a -> Bool
$cnull :: forall a. Declarator a -> Bool
toList :: Declarator a -> [a]
$ctoList :: forall a. Declarator a -> [a]
foldl1 :: (a -> a -> a) -> Declarator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Declarator a -> a
foldr1 :: (a -> a -> a) -> Declarator a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Declarator a -> a
foldl' :: (b -> a -> b) -> b -> Declarator a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Declarator a -> b
foldl :: (b -> a -> b) -> b -> Declarator a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Declarator a -> b
foldr' :: (a -> b -> b) -> b -> Declarator a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Declarator a -> b
foldr :: (a -> b -> b) -> b -> Declarator a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Declarator a -> b
foldMap' :: (a -> m) -> Declarator a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Declarator a -> m
foldMap :: (a -> m) -> Declarator a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Declarator a -> m
fold :: Declarator m -> m
$cfold :: forall m. Monoid m => Declarator m -> m
Foldable, Functor Declarator
Foldable Declarator
Functor Declarator
-> Foldable Declarator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Declarator a -> f (Declarator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Declarator (f a) -> f (Declarator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Declarator a -> m (Declarator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Declarator (m a) -> m (Declarator a))
-> Traversable Declarator
(a -> f b) -> Declarator a -> f (Declarator b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Declarator (m a) -> m (Declarator a)
forall (f :: * -> *) a.
Applicative f =>
Declarator (f a) -> f (Declarator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Declarator a -> m (Declarator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Declarator a -> f (Declarator b)
sequence :: Declarator (m a) -> m (Declarator a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
Declarator (m a) -> m (Declarator a)
mapM :: (a -> m b) -> Declarator a -> m (Declarator b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Declarator a -> m (Declarator b)
sequenceA :: Declarator (f a) -> f (Declarator a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Declarator (f a) -> f (Declarator a)
traverse :: (a -> f b) -> Declarator a -> f (Declarator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Declarator a -> f (Declarator b)
$cp2Traversable :: Foldable Declarator
$cp1Traversable :: Functor Declarator
Traversable)

declarator :: CParser i m => m (Declarator i)
declarator :: m (Declarator i)
declarator = ([Pointer] -> DirectDeclarator i -> Declarator i
forall i. [Pointer] -> DirectDeclarator i -> Declarator i
Declarator ([Pointer] -> DirectDeclarator i -> Declarator i)
-> m [Pointer] -> m (DirectDeclarator i -> Declarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Pointer -> m [Pointer]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m Pointer
forall i (m :: * -> *). CParser i m => m Pointer
pointer m (DirectDeclarator i -> Declarator i)
-> m (DirectDeclarator i) -> m (Declarator i)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (DirectDeclarator i)
forall i (m :: * -> *). CParser i m => m (DirectDeclarator i)
direct_declarator) m (Declarator i) -> String -> m (Declarator i)
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"declarator"

data DirectDeclarator i
  = DeclaratorRoot i
  | ArrayOrProto (DirectDeclarator i) (ArrayOrProto i)
  | DeclaratorParens (Declarator i)
  deriving (Typeable, DirectDeclarator i -> DirectDeclarator i -> Bool
(DirectDeclarator i -> DirectDeclarator i -> Bool)
-> (DirectDeclarator i -> DirectDeclarator i -> Bool)
-> Eq (DirectDeclarator i)
forall i. Eq i => DirectDeclarator i -> DirectDeclarator i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DirectDeclarator i -> DirectDeclarator i -> Bool
$c/= :: forall i. Eq i => DirectDeclarator i -> DirectDeclarator i -> Bool
== :: DirectDeclarator i -> DirectDeclarator i -> Bool
$c== :: forall i. Eq i => DirectDeclarator i -> DirectDeclarator i -> Bool
Eq, Int -> DirectDeclarator i -> ShowS
[DirectDeclarator i] -> ShowS
DirectDeclarator i -> String
(Int -> DirectDeclarator i -> ShowS)
-> (DirectDeclarator i -> String)
-> ([DirectDeclarator i] -> ShowS)
-> Show (DirectDeclarator i)
forall i. Show i => Int -> DirectDeclarator i -> ShowS
forall i. Show i => [DirectDeclarator i] -> ShowS
forall i. Show i => DirectDeclarator i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DirectDeclarator i] -> ShowS
$cshowList :: forall i. Show i => [DirectDeclarator i] -> ShowS
show :: DirectDeclarator i -> String
$cshow :: forall i. Show i => DirectDeclarator i -> String
showsPrec :: Int -> DirectDeclarator i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> DirectDeclarator i -> ShowS
Show, a -> DirectDeclarator b -> DirectDeclarator a
(a -> b) -> DirectDeclarator a -> DirectDeclarator b
(forall a b. (a -> b) -> DirectDeclarator a -> DirectDeclarator b)
-> (forall a b. a -> DirectDeclarator b -> DirectDeclarator a)
-> Functor DirectDeclarator
forall a b. a -> DirectDeclarator b -> DirectDeclarator a
forall a b. (a -> b) -> DirectDeclarator a -> DirectDeclarator b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> DirectDeclarator b -> DirectDeclarator a
$c<$ :: forall a b. a -> DirectDeclarator b -> DirectDeclarator a
fmap :: (a -> b) -> DirectDeclarator a -> DirectDeclarator b
$cfmap :: forall a b. (a -> b) -> DirectDeclarator a -> DirectDeclarator b
Functor, DirectDeclarator a -> Bool
(a -> m) -> DirectDeclarator a -> m
(a -> b -> b) -> b -> DirectDeclarator a -> b
(forall m. Monoid m => DirectDeclarator m -> m)
-> (forall m a. Monoid m => (a -> m) -> DirectDeclarator a -> m)
-> (forall m a. Monoid m => (a -> m) -> DirectDeclarator a -> m)
-> (forall a b. (a -> b -> b) -> b -> DirectDeclarator a -> b)
-> (forall a b. (a -> b -> b) -> b -> DirectDeclarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> DirectDeclarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> DirectDeclarator a -> b)
-> (forall a. (a -> a -> a) -> DirectDeclarator a -> a)
-> (forall a. (a -> a -> a) -> DirectDeclarator a -> a)
-> (forall a. DirectDeclarator a -> [a])
-> (forall a. DirectDeclarator a -> Bool)
-> (forall a. DirectDeclarator a -> Int)
-> (forall a. Eq a => a -> DirectDeclarator a -> Bool)
-> (forall a. Ord a => DirectDeclarator a -> a)
-> (forall a. Ord a => DirectDeclarator a -> a)
-> (forall a. Num a => DirectDeclarator a -> a)
-> (forall a. Num a => DirectDeclarator a -> a)
-> Foldable DirectDeclarator
forall a. Eq a => a -> DirectDeclarator a -> Bool
forall a. Num a => DirectDeclarator a -> a
forall a. Ord a => DirectDeclarator a -> a
forall m. Monoid m => DirectDeclarator m -> m
forall a. DirectDeclarator a -> Bool
forall a. DirectDeclarator a -> Int
forall a. DirectDeclarator a -> [a]
forall a. (a -> a -> a) -> DirectDeclarator a -> a
forall m a. Monoid m => (a -> m) -> DirectDeclarator a -> m
forall b a. (b -> a -> b) -> b -> DirectDeclarator a -> b
forall a b. (a -> b -> b) -> b -> DirectDeclarator a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: DirectDeclarator a -> a
$cproduct :: forall a. Num a => DirectDeclarator a -> a
sum :: DirectDeclarator a -> a
$csum :: forall a. Num a => DirectDeclarator a -> a
minimum :: DirectDeclarator a -> a
$cminimum :: forall a. Ord a => DirectDeclarator a -> a
maximum :: DirectDeclarator a -> a
$cmaximum :: forall a. Ord a => DirectDeclarator a -> a
elem :: a -> DirectDeclarator a -> Bool
$celem :: forall a. Eq a => a -> DirectDeclarator a -> Bool
length :: DirectDeclarator a -> Int
$clength :: forall a. DirectDeclarator a -> Int
null :: DirectDeclarator a -> Bool
$cnull :: forall a. DirectDeclarator a -> Bool
toList :: DirectDeclarator a -> [a]
$ctoList :: forall a. DirectDeclarator a -> [a]
foldl1 :: (a -> a -> a) -> DirectDeclarator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> DirectDeclarator a -> a
foldr1 :: (a -> a -> a) -> DirectDeclarator a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> DirectDeclarator a -> a
foldl' :: (b -> a -> b) -> b -> DirectDeclarator a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> DirectDeclarator a -> b
foldl :: (b -> a -> b) -> b -> DirectDeclarator a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> DirectDeclarator a -> b
foldr' :: (a -> b -> b) -> b -> DirectDeclarator a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> DirectDeclarator a -> b
foldr :: (a -> b -> b) -> b -> DirectDeclarator a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> DirectDeclarator a -> b
foldMap' :: (a -> m) -> DirectDeclarator a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> DirectDeclarator a -> m
foldMap :: (a -> m) -> DirectDeclarator a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> DirectDeclarator a -> m
fold :: DirectDeclarator m -> m
$cfold :: forall m. Monoid m => DirectDeclarator m -> m
Foldable, Functor DirectDeclarator
Foldable DirectDeclarator
Functor DirectDeclarator
-> Foldable DirectDeclarator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    DirectDeclarator (f a) -> f (DirectDeclarator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> DirectDeclarator a -> m (DirectDeclarator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    DirectDeclarator (m a) -> m (DirectDeclarator a))
-> Traversable DirectDeclarator
(a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
DirectDeclarator (m a) -> m (DirectDeclarator a)
forall (f :: * -> *) a.
Applicative f =>
DirectDeclarator (f a) -> f (DirectDeclarator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> DirectDeclarator a -> m (DirectDeclarator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b)
sequence :: DirectDeclarator (m a) -> m (DirectDeclarator a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
DirectDeclarator (m a) -> m (DirectDeclarator a)
mapM :: (a -> m b) -> DirectDeclarator a -> m (DirectDeclarator b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> DirectDeclarator a -> m (DirectDeclarator b)
sequenceA :: DirectDeclarator (f a) -> f (DirectDeclarator a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
DirectDeclarator (f a) -> f (DirectDeclarator a)
traverse :: (a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> DirectDeclarator a -> f (DirectDeclarator b)
$cp2Traversable :: Foldable DirectDeclarator
$cp1Traversable :: Functor DirectDeclarator
Traversable)

data ArrayOrProto i
  = Array (ArrayType i)
  | Proto [ParameterDeclaration i] -- We don't include old prototypes.
  deriving (ArrayOrProto i -> ArrayOrProto i -> Bool
(ArrayOrProto i -> ArrayOrProto i -> Bool)
-> (ArrayOrProto i -> ArrayOrProto i -> Bool)
-> Eq (ArrayOrProto i)
forall i. Eq i => ArrayOrProto i -> ArrayOrProto i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArrayOrProto i -> ArrayOrProto i -> Bool
$c/= :: forall i. Eq i => ArrayOrProto i -> ArrayOrProto i -> Bool
== :: ArrayOrProto i -> ArrayOrProto i -> Bool
$c== :: forall i. Eq i => ArrayOrProto i -> ArrayOrProto i -> Bool
Eq, Int -> ArrayOrProto i -> ShowS
[ArrayOrProto i] -> ShowS
ArrayOrProto i -> String
(Int -> ArrayOrProto i -> ShowS)
-> (ArrayOrProto i -> String)
-> ([ArrayOrProto i] -> ShowS)
-> Show (ArrayOrProto i)
forall i. Show i => Int -> ArrayOrProto i -> ShowS
forall i. Show i => [ArrayOrProto i] -> ShowS
forall i. Show i => ArrayOrProto i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArrayOrProto i] -> ShowS
$cshowList :: forall i. Show i => [ArrayOrProto i] -> ShowS
show :: ArrayOrProto i -> String
$cshow :: forall i. Show i => ArrayOrProto i -> String
showsPrec :: Int -> ArrayOrProto i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> ArrayOrProto i -> ShowS
Show, Typeable, a -> ArrayOrProto b -> ArrayOrProto a
(a -> b) -> ArrayOrProto a -> ArrayOrProto b
(forall a b. (a -> b) -> ArrayOrProto a -> ArrayOrProto b)
-> (forall a b. a -> ArrayOrProto b -> ArrayOrProto a)
-> Functor ArrayOrProto
forall a b. a -> ArrayOrProto b -> ArrayOrProto a
forall a b. (a -> b) -> ArrayOrProto a -> ArrayOrProto b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ArrayOrProto b -> ArrayOrProto a
$c<$ :: forall a b. a -> ArrayOrProto b -> ArrayOrProto a
fmap :: (a -> b) -> ArrayOrProto a -> ArrayOrProto b
$cfmap :: forall a b. (a -> b) -> ArrayOrProto a -> ArrayOrProto b
Functor, ArrayOrProto a -> Bool
(a -> m) -> ArrayOrProto a -> m
(a -> b -> b) -> b -> ArrayOrProto a -> b
(forall m. Monoid m => ArrayOrProto m -> m)
-> (forall m a. Monoid m => (a -> m) -> ArrayOrProto a -> m)
-> (forall m a. Monoid m => (a -> m) -> ArrayOrProto a -> m)
-> (forall a b. (a -> b -> b) -> b -> ArrayOrProto a -> b)
-> (forall a b. (a -> b -> b) -> b -> ArrayOrProto a -> b)
-> (forall b a. (b -> a -> b) -> b -> ArrayOrProto a -> b)
-> (forall b a. (b -> a -> b) -> b -> ArrayOrProto a -> b)
-> (forall a. (a -> a -> a) -> ArrayOrProto a -> a)
-> (forall a. (a -> a -> a) -> ArrayOrProto a -> a)
-> (forall a. ArrayOrProto a -> [a])
-> (forall a. ArrayOrProto a -> Bool)
-> (forall a. ArrayOrProto a -> Int)
-> (forall a. Eq a => a -> ArrayOrProto a -> Bool)
-> (forall a. Ord a => ArrayOrProto a -> a)
-> (forall a. Ord a => ArrayOrProto a -> a)
-> (forall a. Num a => ArrayOrProto a -> a)
-> (forall a. Num a => ArrayOrProto a -> a)
-> Foldable ArrayOrProto
forall a. Eq a => a -> ArrayOrProto a -> Bool
forall a. Num a => ArrayOrProto a -> a
forall a. Ord a => ArrayOrProto a -> a
forall m. Monoid m => ArrayOrProto m -> m
forall a. ArrayOrProto a -> Bool
forall a. ArrayOrProto a -> Int
forall a. ArrayOrProto a -> [a]
forall a. (a -> a -> a) -> ArrayOrProto a -> a
forall m a. Monoid m => (a -> m) -> ArrayOrProto a -> m
forall b a. (b -> a -> b) -> b -> ArrayOrProto a -> b
forall a b. (a -> b -> b) -> b -> ArrayOrProto a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: ArrayOrProto a -> a
$cproduct :: forall a. Num a => ArrayOrProto a -> a
sum :: ArrayOrProto a -> a
$csum :: forall a. Num a => ArrayOrProto a -> a
minimum :: ArrayOrProto a -> a
$cminimum :: forall a. Ord a => ArrayOrProto a -> a
maximum :: ArrayOrProto a -> a
$cmaximum :: forall a. Ord a => ArrayOrProto a -> a
elem :: a -> ArrayOrProto a -> Bool
$celem :: forall a. Eq a => a -> ArrayOrProto a -> Bool
length :: ArrayOrProto a -> Int
$clength :: forall a. ArrayOrProto a -> Int
null :: ArrayOrProto a -> Bool
$cnull :: forall a. ArrayOrProto a -> Bool
toList :: ArrayOrProto a -> [a]
$ctoList :: forall a. ArrayOrProto a -> [a]
foldl1 :: (a -> a -> a) -> ArrayOrProto a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ArrayOrProto a -> a
foldr1 :: (a -> a -> a) -> ArrayOrProto a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ArrayOrProto a -> a
foldl' :: (b -> a -> b) -> b -> ArrayOrProto a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ArrayOrProto a -> b
foldl :: (b -> a -> b) -> b -> ArrayOrProto a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ArrayOrProto a -> b
foldr' :: (a -> b -> b) -> b -> ArrayOrProto a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ArrayOrProto a -> b
foldr :: (a -> b -> b) -> b -> ArrayOrProto a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ArrayOrProto a -> b
foldMap' :: (a -> m) -> ArrayOrProto a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ArrayOrProto a -> m
foldMap :: (a -> m) -> ArrayOrProto a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ArrayOrProto a -> m
fold :: ArrayOrProto m -> m
$cfold :: forall m. Monoid m => ArrayOrProto m -> m
Foldable, Functor ArrayOrProto
Foldable ArrayOrProto
Functor ArrayOrProto
-> Foldable ArrayOrProto
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ArrayOrProto (f a) -> f (ArrayOrProto a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ArrayOrProto a -> m (ArrayOrProto b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ArrayOrProto (m a) -> m (ArrayOrProto a))
-> Traversable ArrayOrProto
(a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
ArrayOrProto (m a) -> m (ArrayOrProto a)
forall (f :: * -> *) a.
Applicative f =>
ArrayOrProto (f a) -> f (ArrayOrProto a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ArrayOrProto a -> m (ArrayOrProto b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b)
sequence :: ArrayOrProto (m a) -> m (ArrayOrProto a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
ArrayOrProto (m a) -> m (ArrayOrProto a)
mapM :: (a -> m b) -> ArrayOrProto a -> m (ArrayOrProto b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ArrayOrProto a -> m (ArrayOrProto b)
sequenceA :: ArrayOrProto (f a) -> f (ArrayOrProto a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ArrayOrProto (f a) -> f (ArrayOrProto a)
traverse :: (a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ArrayOrProto a -> f (ArrayOrProto b)
$cp2Traversable :: Foldable ArrayOrProto
$cp1Traversable :: Functor ArrayOrProto
Traversable)

array_or_proto :: CParser i m => m (ArrayOrProto i)
array_or_proto :: m (ArrayOrProto i)
array_or_proto = [m (ArrayOrProto i)] -> m (ArrayOrProto i)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ ArrayType i -> ArrayOrProto i
forall i. ArrayType i -> ArrayOrProto i
Array (ArrayType i -> ArrayOrProto i)
-> m (ArrayType i) -> m (ArrayOrProto i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (ArrayType i) -> m (ArrayType i)
forall (m :: * -> *) a. TokenParsing m => m a -> m a
brackets m (ArrayType i)
forall i (m :: * -> *). CParser i m => m (ArrayType i)
array_type
  , [ParameterDeclaration i] -> ArrayOrProto i
forall i. [ParameterDeclaration i] -> ArrayOrProto i
Proto ([ParameterDeclaration i] -> ArrayOrProto i)
-> m [ParameterDeclaration i] -> m (ArrayOrProto i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [ParameterDeclaration i] -> m [ParameterDeclaration i]
forall (m :: * -> *) a. TokenParsing m => m a -> m a
parens m [ParameterDeclaration i]
forall i (m :: * -> *). CParser i m => m [ParameterDeclaration i]
parameter_list
  ]

-- TODO handle more stuff in array brackets
data ArrayType i
  = VariablySized
  | Unsized
  | SizedByInteger Integer
  | SizedByIdentifier i
  deriving (Typeable, ArrayType i -> ArrayType i -> Bool
(ArrayType i -> ArrayType i -> Bool)
-> (ArrayType i -> ArrayType i -> Bool) -> Eq (ArrayType i)
forall i. Eq i => ArrayType i -> ArrayType i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArrayType i -> ArrayType i -> Bool
$c/= :: forall i. Eq i => ArrayType i -> ArrayType i -> Bool
== :: ArrayType i -> ArrayType i -> Bool
$c== :: forall i. Eq i => ArrayType i -> ArrayType i -> Bool
Eq, Int -> ArrayType i -> ShowS
[ArrayType i] -> ShowS
ArrayType i -> String
(Int -> ArrayType i -> ShowS)
-> (ArrayType i -> String)
-> ([ArrayType i] -> ShowS)
-> Show (ArrayType i)
forall i. Show i => Int -> ArrayType i -> ShowS
forall i. Show i => [ArrayType i] -> ShowS
forall i. Show i => ArrayType i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArrayType i] -> ShowS
$cshowList :: forall i. Show i => [ArrayType i] -> ShowS
show :: ArrayType i -> String
$cshow :: forall i. Show i => ArrayType i -> String
showsPrec :: Int -> ArrayType i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> ArrayType i -> ShowS
Show, a -> ArrayType b -> ArrayType a
(a -> b) -> ArrayType a -> ArrayType b
(forall a b. (a -> b) -> ArrayType a -> ArrayType b)
-> (forall a b. a -> ArrayType b -> ArrayType a)
-> Functor ArrayType
forall a b. a -> ArrayType b -> ArrayType a
forall a b. (a -> b) -> ArrayType a -> ArrayType b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ArrayType b -> ArrayType a
$c<$ :: forall a b. a -> ArrayType b -> ArrayType a
fmap :: (a -> b) -> ArrayType a -> ArrayType b
$cfmap :: forall a b. (a -> b) -> ArrayType a -> ArrayType b
Functor, ArrayType a -> Bool
(a -> m) -> ArrayType a -> m
(a -> b -> b) -> b -> ArrayType a -> b
(forall m. Monoid m => ArrayType m -> m)
-> (forall m a. Monoid m => (a -> m) -> ArrayType a -> m)
-> (forall m a. Monoid m => (a -> m) -> ArrayType a -> m)
-> (forall a b. (a -> b -> b) -> b -> ArrayType a -> b)
-> (forall a b. (a -> b -> b) -> b -> ArrayType a -> b)
-> (forall b a. (b -> a -> b) -> b -> ArrayType a -> b)
-> (forall b a. (b -> a -> b) -> b -> ArrayType a -> b)
-> (forall a. (a -> a -> a) -> ArrayType a -> a)
-> (forall a. (a -> a -> a) -> ArrayType a -> a)
-> (forall a. ArrayType a -> [a])
-> (forall a. ArrayType a -> Bool)
-> (forall a. ArrayType a -> Int)
-> (forall a. Eq a => a -> ArrayType a -> Bool)
-> (forall a. Ord a => ArrayType a -> a)
-> (forall a. Ord a => ArrayType a -> a)
-> (forall a. Num a => ArrayType a -> a)
-> (forall a. Num a => ArrayType a -> a)
-> Foldable ArrayType
forall a. Eq a => a -> ArrayType a -> Bool
forall a. Num a => ArrayType a -> a
forall a. Ord a => ArrayType a -> a
forall m. Monoid m => ArrayType m -> m
forall a. ArrayType a -> Bool
forall a. ArrayType a -> Int
forall a. ArrayType a -> [a]
forall a. (a -> a -> a) -> ArrayType a -> a
forall m a. Monoid m => (a -> m) -> ArrayType a -> m
forall b a. (b -> a -> b) -> b -> ArrayType a -> b
forall a b. (a -> b -> b) -> b -> ArrayType a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: ArrayType a -> a
$cproduct :: forall a. Num a => ArrayType a -> a
sum :: ArrayType a -> a
$csum :: forall a. Num a => ArrayType a -> a
minimum :: ArrayType a -> a
$cminimum :: forall a. Ord a => ArrayType a -> a
maximum :: ArrayType a -> a
$cmaximum :: forall a. Ord a => ArrayType a -> a
elem :: a -> ArrayType a -> Bool
$celem :: forall a. Eq a => a -> ArrayType a -> Bool
length :: ArrayType a -> Int
$clength :: forall a. ArrayType a -> Int
null :: ArrayType a -> Bool
$cnull :: forall a. ArrayType a -> Bool
toList :: ArrayType a -> [a]
$ctoList :: forall a. ArrayType a -> [a]
foldl1 :: (a -> a -> a) -> ArrayType a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ArrayType a -> a
foldr1 :: (a -> a -> a) -> ArrayType a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ArrayType a -> a
foldl' :: (b -> a -> b) -> b -> ArrayType a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ArrayType a -> b
foldl :: (b -> a -> b) -> b -> ArrayType a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ArrayType a -> b
foldr' :: (a -> b -> b) -> b -> ArrayType a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ArrayType a -> b
foldr :: (a -> b -> b) -> b -> ArrayType a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ArrayType a -> b
foldMap' :: (a -> m) -> ArrayType a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ArrayType a -> m
foldMap :: (a -> m) -> ArrayType a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ArrayType a -> m
fold :: ArrayType m -> m
$cfold :: forall m. Monoid m => ArrayType m -> m
Foldable, Functor ArrayType
Foldable ArrayType
Functor ArrayType
-> Foldable ArrayType
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ArrayType a -> f (ArrayType b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ArrayType (f a) -> f (ArrayType a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ArrayType a -> m (ArrayType b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ArrayType (m a) -> m (ArrayType a))
-> Traversable ArrayType
(a -> f b) -> ArrayType a -> f (ArrayType b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
ArrayType (m a) -> m (ArrayType a)
forall (f :: * -> *) a.
Applicative f =>
ArrayType (f a) -> f (ArrayType a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ArrayType a -> m (ArrayType b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ArrayType a -> f (ArrayType b)
sequence :: ArrayType (m a) -> m (ArrayType a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
ArrayType (m a) -> m (ArrayType a)
mapM :: (a -> m b) -> ArrayType a -> m (ArrayType b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ArrayType a -> m (ArrayType b)
sequenceA :: ArrayType (f a) -> f (ArrayType a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ArrayType (f a) -> f (ArrayType a)
traverse :: (a -> f b) -> ArrayType a -> f (ArrayType b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ArrayType a -> f (ArrayType b)
$cp2Traversable :: Foldable ArrayType
$cp1Traversable :: Functor ArrayType
Traversable)

array_type :: CParser i m => m (ArrayType i)
array_type :: m (ArrayType i)
array_type = [m (ArrayType i)] -> m (ArrayType i)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
  [ ArrayType i
forall i. ArrayType i
VariablySized ArrayType i -> m Char -> m (ArrayType i)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'*'
  , Integer -> ArrayType i
forall i. Integer -> ArrayType i
SizedByInteger (Integer -> ArrayType i) -> m Integer -> m (ArrayType i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Integer
forall (m :: * -> *). TokenParsing m => m Integer
natural
  , i -> ArrayType i
forall i. i -> ArrayType i
SizedByIdentifier (i -> ArrayType i) -> m i -> m (ArrayType i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m i
forall i (m :: * -> *). CParser i m => m i
identifier
  , ArrayType i -> m (ArrayType i)
forall (m :: * -> *) a. Monad m => a -> m a
return ArrayType i
forall i. ArrayType i
Unsized
  ]

direct_declarator :: CParser i m => m (DirectDeclarator i)
direct_declarator :: m (DirectDeclarator i)
direct_declarator = do
  DirectDeclarator i
ddecltor <- [m (DirectDeclarator i)] -> m (DirectDeclarator i)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
    [ i -> DirectDeclarator i
forall i. i -> DirectDeclarator i
DeclaratorRoot (i -> DirectDeclarator i) -> m i -> m (DirectDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m i
forall i (m :: * -> *). CParser i m => m i
identifier
    , Declarator i -> DirectDeclarator i
forall i. Declarator i -> DirectDeclarator i
DeclaratorParens (Declarator i -> DirectDeclarator i)
-> m (Declarator i) -> m (DirectDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Declarator i) -> m (Declarator i)
forall (m :: * -> *) a. TokenParsing m => m a -> m a
parens m (Declarator i)
forall i (m :: * -> *). CParser i m => m (Declarator i)
declarator
    ]
  [ArrayOrProto i]
aops <- m (ArrayOrProto i) -> m [ArrayOrProto i]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m (ArrayOrProto i)
forall i (m :: * -> *). CParser i m => m (ArrayOrProto i)
array_or_proto
  DirectDeclarator i -> m (DirectDeclarator i)
forall (m :: * -> *) a. Monad m => a -> m a
return (DirectDeclarator i -> m (DirectDeclarator i))
-> DirectDeclarator i -> m (DirectDeclarator i)
forall a b. (a -> b) -> a -> b
$ (DirectDeclarator i -> ArrayOrProto i -> DirectDeclarator i)
-> DirectDeclarator i -> [ArrayOrProto i] -> DirectDeclarator i
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl DirectDeclarator i -> ArrayOrProto i -> DirectDeclarator i
forall i.
DirectDeclarator i -> ArrayOrProto i -> DirectDeclarator i
ArrayOrProto DirectDeclarator i
ddecltor [ArrayOrProto i]
aops

data Pointer
  = Pointer [TypeQualifier]
  deriving (Typeable, Pointer -> Pointer -> Bool
(Pointer -> Pointer -> Bool)
-> (Pointer -> Pointer -> Bool) -> Eq Pointer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pointer -> Pointer -> Bool
$c/= :: Pointer -> Pointer -> Bool
== :: Pointer -> Pointer -> Bool
$c== :: Pointer -> Pointer -> Bool
Eq, Int -> Pointer -> ShowS
[Pointer] -> ShowS
Pointer -> String
(Int -> Pointer -> ShowS)
-> (Pointer -> String) -> ([Pointer] -> ShowS) -> Show Pointer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pointer] -> ShowS
$cshowList :: [Pointer] -> ShowS
show :: Pointer -> String
$cshow :: Pointer -> String
showsPrec :: Int -> Pointer -> ShowS
$cshowsPrec :: Int -> Pointer -> ShowS
Show)

pointer :: CParser i m => m Pointer
pointer :: m Pointer
pointer = do
  m Char -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m Char -> m ()) -> m Char -> m ()
forall a b. (a -> b) -> a -> b
$ Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
'*'
  [TypeQualifier] -> Pointer
Pointer ([TypeQualifier] -> Pointer) -> m [TypeQualifier] -> m Pointer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TypeQualifier -> m [TypeQualifier]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m TypeQualifier
forall i (m :: * -> *). CParser i m => m TypeQualifier
type_qualifier

parameter_list :: CParser i m => m [ParameterDeclaration i]
parameter_list :: m [ParameterDeclaration i]
parameter_list =
  m (ParameterDeclaration i) -> m Char -> m [ParameterDeclaration i]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy m (ParameterDeclaration i)
forall i (m :: * -> *). CParser i m => m (ParameterDeclaration i)
parameter_declaration (m Char -> m [ParameterDeclaration i])
-> m Char -> m [ParameterDeclaration i]
forall a b. (a -> b) -> a -> b
$ Char -> m Char
forall (m :: * -> *). TokenParsing m => Char -> m Char
symbolic Char
','

data ParameterDeclaration i = ParameterDeclaration
  { ParameterDeclaration i -> [DeclarationSpecifier]
parameterDeclarationSpecifiers :: [DeclarationSpecifier]
  , ParameterDeclaration i -> DeclaratorOrAbstractDeclarator i
parameterDeclarationDeclarator :: DeclaratorOrAbstractDeclarator i
  } deriving (ParameterDeclaration i -> ParameterDeclaration i -> Bool
(ParameterDeclaration i -> ParameterDeclaration i -> Bool)
-> (ParameterDeclaration i -> ParameterDeclaration i -> Bool)
-> Eq (ParameterDeclaration i)
forall i.
Eq i =>
ParameterDeclaration i -> ParameterDeclaration i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParameterDeclaration i -> ParameterDeclaration i -> Bool
$c/= :: forall i.
Eq i =>
ParameterDeclaration i -> ParameterDeclaration i -> Bool
== :: ParameterDeclaration i -> ParameterDeclaration i -> Bool
$c== :: forall i.
Eq i =>
ParameterDeclaration i -> ParameterDeclaration i -> Bool
Eq, Int -> ParameterDeclaration i -> ShowS
[ParameterDeclaration i] -> ShowS
ParameterDeclaration i -> String
(Int -> ParameterDeclaration i -> ShowS)
-> (ParameterDeclaration i -> String)
-> ([ParameterDeclaration i] -> ShowS)
-> Show (ParameterDeclaration i)
forall i. Show i => Int -> ParameterDeclaration i -> ShowS
forall i. Show i => [ParameterDeclaration i] -> ShowS
forall i. Show i => ParameterDeclaration i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParameterDeclaration i] -> ShowS
$cshowList :: forall i. Show i => [ParameterDeclaration i] -> ShowS
show :: ParameterDeclaration i -> String
$cshow :: forall i. Show i => ParameterDeclaration i -> String
showsPrec :: Int -> ParameterDeclaration i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> ParameterDeclaration i -> ShowS
Show, Typeable, a -> ParameterDeclaration b -> ParameterDeclaration a
(a -> b) -> ParameterDeclaration a -> ParameterDeclaration b
(forall a b.
 (a -> b) -> ParameterDeclaration a -> ParameterDeclaration b)
-> (forall a b.
    a -> ParameterDeclaration b -> ParameterDeclaration a)
-> Functor ParameterDeclaration
forall a b. a -> ParameterDeclaration b -> ParameterDeclaration a
forall a b.
(a -> b) -> ParameterDeclaration a -> ParameterDeclaration b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ParameterDeclaration b -> ParameterDeclaration a
$c<$ :: forall a b. a -> ParameterDeclaration b -> ParameterDeclaration a
fmap :: (a -> b) -> ParameterDeclaration a -> ParameterDeclaration b
$cfmap :: forall a b.
(a -> b) -> ParameterDeclaration a -> ParameterDeclaration b
Functor, ParameterDeclaration a -> Bool
(a -> m) -> ParameterDeclaration a -> m
(a -> b -> b) -> b -> ParameterDeclaration a -> b
(forall m. Monoid m => ParameterDeclaration m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> ParameterDeclaration a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> ParameterDeclaration a -> m)
-> (forall a b. (a -> b -> b) -> b -> ParameterDeclaration a -> b)
-> (forall a b. (a -> b -> b) -> b -> ParameterDeclaration a -> b)
-> (forall b a. (b -> a -> b) -> b -> ParameterDeclaration a -> b)
-> (forall b a. (b -> a -> b) -> b -> ParameterDeclaration a -> b)
-> (forall a. (a -> a -> a) -> ParameterDeclaration a -> a)
-> (forall a. (a -> a -> a) -> ParameterDeclaration a -> a)
-> (forall a. ParameterDeclaration a -> [a])
-> (forall a. ParameterDeclaration a -> Bool)
-> (forall a. ParameterDeclaration a -> Int)
-> (forall a. Eq a => a -> ParameterDeclaration a -> Bool)
-> (forall a. Ord a => ParameterDeclaration a -> a)
-> (forall a. Ord a => ParameterDeclaration a -> a)
-> (forall a. Num a => ParameterDeclaration a -> a)
-> (forall a. Num a => ParameterDeclaration a -> a)
-> Foldable ParameterDeclaration
forall a. Eq a => a -> ParameterDeclaration a -> Bool
forall a. Num a => ParameterDeclaration a -> a
forall a. Ord a => ParameterDeclaration a -> a
forall m. Monoid m => ParameterDeclaration m -> m
forall a. ParameterDeclaration a -> Bool
forall a. ParameterDeclaration a -> Int
forall a. ParameterDeclaration a -> [a]
forall a. (a -> a -> a) -> ParameterDeclaration a -> a
forall m a. Monoid m => (a -> m) -> ParameterDeclaration a -> m
forall b a. (b -> a -> b) -> b -> ParameterDeclaration a -> b
forall a b. (a -> b -> b) -> b -> ParameterDeclaration a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: ParameterDeclaration a -> a
$cproduct :: forall a. Num a => ParameterDeclaration a -> a
sum :: ParameterDeclaration a -> a
$csum :: forall a. Num a => ParameterDeclaration a -> a
minimum :: ParameterDeclaration a -> a
$cminimum :: forall a. Ord a => ParameterDeclaration a -> a
maximum :: ParameterDeclaration a -> a
$cmaximum :: forall a. Ord a => ParameterDeclaration a -> a
elem :: a -> ParameterDeclaration a -> Bool
$celem :: forall a. Eq a => a -> ParameterDeclaration a -> Bool
length :: ParameterDeclaration a -> Int
$clength :: forall a. ParameterDeclaration a -> Int
null :: ParameterDeclaration a -> Bool
$cnull :: forall a. ParameterDeclaration a -> Bool
toList :: ParameterDeclaration a -> [a]
$ctoList :: forall a. ParameterDeclaration a -> [a]
foldl1 :: (a -> a -> a) -> ParameterDeclaration a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ParameterDeclaration a -> a
foldr1 :: (a -> a -> a) -> ParameterDeclaration a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ParameterDeclaration a -> a
foldl' :: (b -> a -> b) -> b -> ParameterDeclaration a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ParameterDeclaration a -> b
foldl :: (b -> a -> b) -> b -> ParameterDeclaration a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ParameterDeclaration a -> b
foldr' :: (a -> b -> b) -> b -> ParameterDeclaration a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ParameterDeclaration a -> b
foldr :: (a -> b -> b) -> b -> ParameterDeclaration a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ParameterDeclaration a -> b
foldMap' :: (a -> m) -> ParameterDeclaration a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ParameterDeclaration a -> m
foldMap :: (a -> m) -> ParameterDeclaration a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ParameterDeclaration a -> m
fold :: ParameterDeclaration m -> m
$cfold :: forall m. Monoid m => ParameterDeclaration m -> m
Foldable, Functor ParameterDeclaration
Foldable ParameterDeclaration
Functor ParameterDeclaration
-> Foldable ParameterDeclaration
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ParameterDeclaration (f a) -> f (ParameterDeclaration a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ParameterDeclaration (m a) -> m (ParameterDeclaration a))
-> Traversable ParameterDeclaration
(a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
ParameterDeclaration (m a) -> m (ParameterDeclaration a)
forall (f :: * -> *) a.
Applicative f =>
ParameterDeclaration (f a) -> f (ParameterDeclaration a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b)
sequence :: ParameterDeclaration (m a) -> m (ParameterDeclaration a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
ParameterDeclaration (m a) -> m (ParameterDeclaration a)
mapM :: (a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ParameterDeclaration a -> m (ParameterDeclaration b)
sequenceA :: ParameterDeclaration (f a) -> f (ParameterDeclaration a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ParameterDeclaration (f a) -> f (ParameterDeclaration a)
traverse :: (a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ParameterDeclaration a -> f (ParameterDeclaration b)
$cp2Traversable :: Foldable ParameterDeclaration
$cp1Traversable :: Functor ParameterDeclaration
Traversable)

data DeclaratorOrAbstractDeclarator i
  = IsDeclarator (Declarator i)
  | IsAbstractDeclarator (AbstractDeclarator i)
  deriving (DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
(DeclaratorOrAbstractDeclarator i
 -> DeclaratorOrAbstractDeclarator i -> Bool)
-> (DeclaratorOrAbstractDeclarator i
    -> DeclaratorOrAbstractDeclarator i -> Bool)
-> Eq (DeclaratorOrAbstractDeclarator i)
forall i.
Eq i =>
DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
$c/= :: forall i.
Eq i =>
DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
== :: DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
$c== :: forall i.
Eq i =>
DeclaratorOrAbstractDeclarator i
-> DeclaratorOrAbstractDeclarator i -> Bool
Eq, Int -> DeclaratorOrAbstractDeclarator i -> ShowS
[DeclaratorOrAbstractDeclarator i] -> ShowS
DeclaratorOrAbstractDeclarator i -> String
(Int -> DeclaratorOrAbstractDeclarator i -> ShowS)
-> (DeclaratorOrAbstractDeclarator i -> String)
-> ([DeclaratorOrAbstractDeclarator i] -> ShowS)
-> Show (DeclaratorOrAbstractDeclarator i)
forall i.
Show i =>
Int -> DeclaratorOrAbstractDeclarator i -> ShowS
forall i. Show i => [DeclaratorOrAbstractDeclarator i] -> ShowS
forall i. Show i => DeclaratorOrAbstractDeclarator i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeclaratorOrAbstractDeclarator i] -> ShowS
$cshowList :: forall i. Show i => [DeclaratorOrAbstractDeclarator i] -> ShowS
show :: DeclaratorOrAbstractDeclarator i -> String
$cshow :: forall i. Show i => DeclaratorOrAbstractDeclarator i -> String
showsPrec :: Int -> DeclaratorOrAbstractDeclarator i -> ShowS
$cshowsPrec :: forall i.
Show i =>
Int -> DeclaratorOrAbstractDeclarator i -> ShowS
Show, Typeable, a
-> DeclaratorOrAbstractDeclarator b
-> DeclaratorOrAbstractDeclarator a
(a -> b)
-> DeclaratorOrAbstractDeclarator a
-> DeclaratorOrAbstractDeclarator b
(forall a b.
 (a -> b)
 -> DeclaratorOrAbstractDeclarator a
 -> DeclaratorOrAbstractDeclarator b)
-> (forall a b.
    a
    -> DeclaratorOrAbstractDeclarator b
    -> DeclaratorOrAbstractDeclarator a)
-> Functor DeclaratorOrAbstractDeclarator
forall a b.
a
-> DeclaratorOrAbstractDeclarator b
-> DeclaratorOrAbstractDeclarator a
forall a b.
(a -> b)
-> DeclaratorOrAbstractDeclarator a
-> DeclaratorOrAbstractDeclarator b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a
-> DeclaratorOrAbstractDeclarator b
-> DeclaratorOrAbstractDeclarator a
$c<$ :: forall a b.
a
-> DeclaratorOrAbstractDeclarator b
-> DeclaratorOrAbstractDeclarator a
fmap :: (a -> b)
-> DeclaratorOrAbstractDeclarator a
-> DeclaratorOrAbstractDeclarator b
$cfmap :: forall a b.
(a -> b)
-> DeclaratorOrAbstractDeclarator a
-> DeclaratorOrAbstractDeclarator b
Functor, DeclaratorOrAbstractDeclarator a -> Bool
(a -> m) -> DeclaratorOrAbstractDeclarator a -> m
(a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
(forall m. Monoid m => DeclaratorOrAbstractDeclarator m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DeclaratorOrAbstractDeclarator a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DeclaratorOrAbstractDeclarator a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b)
-> (forall a.
    (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a)
-> (forall a.
    (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a)
-> (forall a. DeclaratorOrAbstractDeclarator a -> [a])
-> (forall a. DeclaratorOrAbstractDeclarator a -> Bool)
-> (forall a. DeclaratorOrAbstractDeclarator a -> Int)
-> (forall a.
    Eq a =>
    a -> DeclaratorOrAbstractDeclarator a -> Bool)
-> (forall a. Ord a => DeclaratorOrAbstractDeclarator a -> a)
-> (forall a. Ord a => DeclaratorOrAbstractDeclarator a -> a)
-> (forall a. Num a => DeclaratorOrAbstractDeclarator a -> a)
-> (forall a. Num a => DeclaratorOrAbstractDeclarator a -> a)
-> Foldable DeclaratorOrAbstractDeclarator
forall a. Eq a => a -> DeclaratorOrAbstractDeclarator a -> Bool
forall a. Num a => DeclaratorOrAbstractDeclarator a -> a
forall a. Ord a => DeclaratorOrAbstractDeclarator a -> a
forall m. Monoid m => DeclaratorOrAbstractDeclarator m -> m
forall a. DeclaratorOrAbstractDeclarator a -> Bool
forall a. DeclaratorOrAbstractDeclarator a -> Int
forall a. DeclaratorOrAbstractDeclarator a -> [a]
forall a. (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a
forall m a.
Monoid m =>
(a -> m) -> DeclaratorOrAbstractDeclarator a -> m
forall b a.
(b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
forall a b.
(a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: DeclaratorOrAbstractDeclarator a -> a
$cproduct :: forall a. Num a => DeclaratorOrAbstractDeclarator a -> a
sum :: DeclaratorOrAbstractDeclarator a -> a
$csum :: forall a. Num a => DeclaratorOrAbstractDeclarator a -> a
minimum :: DeclaratorOrAbstractDeclarator a -> a
$cminimum :: forall a. Ord a => DeclaratorOrAbstractDeclarator a -> a
maximum :: DeclaratorOrAbstractDeclarator a -> a
$cmaximum :: forall a. Ord a => DeclaratorOrAbstractDeclarator a -> a
elem :: a -> DeclaratorOrAbstractDeclarator a -> Bool
$celem :: forall a. Eq a => a -> DeclaratorOrAbstractDeclarator a -> Bool
length :: DeclaratorOrAbstractDeclarator a -> Int
$clength :: forall a. DeclaratorOrAbstractDeclarator a -> Int
null :: DeclaratorOrAbstractDeclarator a -> Bool
$cnull :: forall a. DeclaratorOrAbstractDeclarator a -> Bool
toList :: DeclaratorOrAbstractDeclarator a -> [a]
$ctoList :: forall a. DeclaratorOrAbstractDeclarator a -> [a]
foldl1 :: (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a
foldr1 :: (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> DeclaratorOrAbstractDeclarator a -> a
foldl' :: (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
$cfoldl' :: forall b a.
(b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
foldl :: (b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
$cfoldl :: forall b a.
(b -> a -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
foldr' :: (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
$cfoldr' :: forall a b.
(a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
foldr :: (a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
$cfoldr :: forall a b.
(a -> b -> b) -> b -> DeclaratorOrAbstractDeclarator a -> b
foldMap' :: (a -> m) -> DeclaratorOrAbstractDeclarator a -> m
$cfoldMap' :: forall m a.
Monoid m =>
(a -> m) -> DeclaratorOrAbstractDeclarator a -> m
foldMap :: (a -> m) -> DeclaratorOrAbstractDeclarator a -> m
$cfoldMap :: forall m a.
Monoid m =>
(a -> m) -> DeclaratorOrAbstractDeclarator a -> m
fold :: DeclaratorOrAbstractDeclarator m -> m
$cfold :: forall m. Monoid m => DeclaratorOrAbstractDeclarator m -> m
Foldable, Functor DeclaratorOrAbstractDeclarator
Foldable DeclaratorOrAbstractDeclarator
Functor DeclaratorOrAbstractDeclarator
-> Foldable DeclaratorOrAbstractDeclarator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> DeclaratorOrAbstractDeclarator a
    -> f (DeclaratorOrAbstractDeclarator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    DeclaratorOrAbstractDeclarator (f a)
    -> f (DeclaratorOrAbstractDeclarator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> DeclaratorOrAbstractDeclarator a
    -> m (DeclaratorOrAbstractDeclarator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    DeclaratorOrAbstractDeclarator (m a)
    -> m (DeclaratorOrAbstractDeclarator a))
-> Traversable DeclaratorOrAbstractDeclarator
(a -> f b)
-> DeclaratorOrAbstractDeclarator a
-> f (DeclaratorOrAbstractDeclarator b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
DeclaratorOrAbstractDeclarator (m a)
-> m (DeclaratorOrAbstractDeclarator a)
forall (f :: * -> *) a.
Applicative f =>
DeclaratorOrAbstractDeclarator (f a)
-> f (DeclaratorOrAbstractDeclarator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DeclaratorOrAbstractDeclarator a
-> m (DeclaratorOrAbstractDeclarator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DeclaratorOrAbstractDeclarator a
-> f (DeclaratorOrAbstractDeclarator b)
sequence :: DeclaratorOrAbstractDeclarator (m a)
-> m (DeclaratorOrAbstractDeclarator a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
DeclaratorOrAbstractDeclarator (m a)
-> m (DeclaratorOrAbstractDeclarator a)
mapM :: (a -> m b)
-> DeclaratorOrAbstractDeclarator a
-> m (DeclaratorOrAbstractDeclarator b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DeclaratorOrAbstractDeclarator a
-> m (DeclaratorOrAbstractDeclarator b)
sequenceA :: DeclaratorOrAbstractDeclarator (f a)
-> f (DeclaratorOrAbstractDeclarator a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
DeclaratorOrAbstractDeclarator (f a)
-> f (DeclaratorOrAbstractDeclarator a)
traverse :: (a -> f b)
-> DeclaratorOrAbstractDeclarator a
-> f (DeclaratorOrAbstractDeclarator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DeclaratorOrAbstractDeclarator a
-> f (DeclaratorOrAbstractDeclarator b)
$cp2Traversable :: Foldable DeclaratorOrAbstractDeclarator
$cp1Traversable :: Functor DeclaratorOrAbstractDeclarator
Traversable)

parameter_declaration :: CParser i m => m (ParameterDeclaration i)
parameter_declaration :: m (ParameterDeclaration i)
parameter_declaration =
  [DeclarationSpecifier]
-> DeclaratorOrAbstractDeclarator i -> ParameterDeclaration i
forall i.
[DeclarationSpecifier]
-> DeclaratorOrAbstractDeclarator i -> ParameterDeclaration i
ParameterDeclaration
    ([DeclarationSpecifier]
 -> DeclaratorOrAbstractDeclarator i -> ParameterDeclaration i)
-> m [DeclarationSpecifier]
-> m (DeclaratorOrAbstractDeclarator i -> ParameterDeclaration i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [DeclarationSpecifier]
forall i (m :: * -> *). CParser i m => m [DeclarationSpecifier]
declaration_specifiers
    m (DeclaratorOrAbstractDeclarator i -> ParameterDeclaration i)
-> m (DeclaratorOrAbstractDeclarator i)
-> m (ParameterDeclaration i)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (DeclaratorOrAbstractDeclarator i)
mbabstract
  where
   mbabstract :: m (DeclaratorOrAbstractDeclarator i)
mbabstract =
     Declarator i -> DeclaratorOrAbstractDeclarator i
forall i. Declarator i -> DeclaratorOrAbstractDeclarator i
IsDeclarator (Declarator i -> DeclaratorOrAbstractDeclarator i)
-> m (Declarator i) -> m (DeclaratorOrAbstractDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Declarator i) -> m (Declarator i)
forall (m :: * -> *) a. Parsing m => m a -> m a
try m (Declarator i)
forall i (m :: * -> *). CParser i m => m (Declarator i)
declarator m (DeclaratorOrAbstractDeclarator i)
-> m (DeclaratorOrAbstractDeclarator i)
-> m (DeclaratorOrAbstractDeclarator i)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     AbstractDeclarator i -> DeclaratorOrAbstractDeclarator i
forall i. AbstractDeclarator i -> DeclaratorOrAbstractDeclarator i
IsAbstractDeclarator (AbstractDeclarator i -> DeclaratorOrAbstractDeclarator i)
-> m (AbstractDeclarator i) -> m (DeclaratorOrAbstractDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (AbstractDeclarator i) -> m (AbstractDeclarator i)
forall (m :: * -> *) a. Parsing m => m a -> m a
try m (AbstractDeclarator i)
forall i (m :: * -> *). CParser i m => m (AbstractDeclarator i)
abstract_declarator m (DeclaratorOrAbstractDeclarator i)
-> m (DeclaratorOrAbstractDeclarator i)
-> m (DeclaratorOrAbstractDeclarator i)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     DeclaratorOrAbstractDeclarator i
-> m (DeclaratorOrAbstractDeclarator i)
forall (m :: * -> *) a. Monad m => a -> m a
return (AbstractDeclarator i -> DeclaratorOrAbstractDeclarator i
forall i. AbstractDeclarator i -> DeclaratorOrAbstractDeclarator i
IsAbstractDeclarator ([Pointer]
-> Maybe (DirectAbstractDeclarator i) -> AbstractDeclarator i
forall i.
[Pointer]
-> Maybe (DirectAbstractDeclarator i) -> AbstractDeclarator i
AbstractDeclarator [] Maybe (DirectAbstractDeclarator i)
forall a. Maybe a
Nothing))

data AbstractDeclarator i = AbstractDeclarator
  { AbstractDeclarator i -> [Pointer]
abstractDeclaratorPointers :: [Pointer]
  , AbstractDeclarator i -> Maybe (DirectAbstractDeclarator i)
abstractDeclaratorDirect :: Maybe (DirectAbstractDeclarator i)
  } deriving (Typeable, AbstractDeclarator i -> AbstractDeclarator i -> Bool
(AbstractDeclarator i -> AbstractDeclarator i -> Bool)
-> (AbstractDeclarator i -> AbstractDeclarator i -> Bool)
-> Eq (AbstractDeclarator i)
forall i.
Eq i =>
AbstractDeclarator i -> AbstractDeclarator i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AbstractDeclarator i -> AbstractDeclarator i -> Bool
$c/= :: forall i.
Eq i =>
AbstractDeclarator i -> AbstractDeclarator i -> Bool
== :: AbstractDeclarator i -> AbstractDeclarator i -> Bool
$c== :: forall i.
Eq i =>
AbstractDeclarator i -> AbstractDeclarator i -> Bool
Eq, Int -> AbstractDeclarator i -> ShowS
[AbstractDeclarator i] -> ShowS
AbstractDeclarator i -> String
(Int -> AbstractDeclarator i -> ShowS)
-> (AbstractDeclarator i -> String)
-> ([AbstractDeclarator i] -> ShowS)
-> Show (AbstractDeclarator i)
forall i. Show i => Int -> AbstractDeclarator i -> ShowS
forall i. Show i => [AbstractDeclarator i] -> ShowS
forall i. Show i => AbstractDeclarator i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AbstractDeclarator i] -> ShowS
$cshowList :: forall i. Show i => [AbstractDeclarator i] -> ShowS
show :: AbstractDeclarator i -> String
$cshow :: forall i. Show i => AbstractDeclarator i -> String
showsPrec :: Int -> AbstractDeclarator i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> AbstractDeclarator i -> ShowS
Show, a -> AbstractDeclarator b -> AbstractDeclarator a
(a -> b) -> AbstractDeclarator a -> AbstractDeclarator b
(forall a b.
 (a -> b) -> AbstractDeclarator a -> AbstractDeclarator b)
-> (forall a b. a -> AbstractDeclarator b -> AbstractDeclarator a)
-> Functor AbstractDeclarator
forall a b. a -> AbstractDeclarator b -> AbstractDeclarator a
forall a b.
(a -> b) -> AbstractDeclarator a -> AbstractDeclarator b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> AbstractDeclarator b -> AbstractDeclarator a
$c<$ :: forall a b. a -> AbstractDeclarator b -> AbstractDeclarator a
fmap :: (a -> b) -> AbstractDeclarator a -> AbstractDeclarator b
$cfmap :: forall a b.
(a -> b) -> AbstractDeclarator a -> AbstractDeclarator b
Functor, AbstractDeclarator a -> Bool
(a -> m) -> AbstractDeclarator a -> m
(a -> b -> b) -> b -> AbstractDeclarator a -> b
(forall m. Monoid m => AbstractDeclarator m -> m)
-> (forall m a. Monoid m => (a -> m) -> AbstractDeclarator a -> m)
-> (forall m a. Monoid m => (a -> m) -> AbstractDeclarator a -> m)
-> (forall a b. (a -> b -> b) -> b -> AbstractDeclarator a -> b)
-> (forall a b. (a -> b -> b) -> b -> AbstractDeclarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> AbstractDeclarator a -> b)
-> (forall b a. (b -> a -> b) -> b -> AbstractDeclarator a -> b)
-> (forall a. (a -> a -> a) -> AbstractDeclarator a -> a)
-> (forall a. (a -> a -> a) -> AbstractDeclarator a -> a)
-> (forall a. AbstractDeclarator a -> [a])
-> (forall a. AbstractDeclarator a -> Bool)
-> (forall a. AbstractDeclarator a -> Int)
-> (forall a. Eq a => a -> AbstractDeclarator a -> Bool)
-> (forall a. Ord a => AbstractDeclarator a -> a)
-> (forall a. Ord a => AbstractDeclarator a -> a)
-> (forall a. Num a => AbstractDeclarator a -> a)
-> (forall a. Num a => AbstractDeclarator a -> a)
-> Foldable AbstractDeclarator
forall a. Eq a => a -> AbstractDeclarator a -> Bool
forall a. Num a => AbstractDeclarator a -> a
forall a. Ord a => AbstractDeclarator a -> a
forall m. Monoid m => AbstractDeclarator m -> m
forall a. AbstractDeclarator a -> Bool
forall a. AbstractDeclarator a -> Int
forall a. AbstractDeclarator a -> [a]
forall a. (a -> a -> a) -> AbstractDeclarator a -> a
forall m a. Monoid m => (a -> m) -> AbstractDeclarator a -> m
forall b a. (b -> a -> b) -> b -> AbstractDeclarator a -> b
forall a b. (a -> b -> b) -> b -> AbstractDeclarator a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: AbstractDeclarator a -> a
$cproduct :: forall a. Num a => AbstractDeclarator a -> a
sum :: AbstractDeclarator a -> a
$csum :: forall a. Num a => AbstractDeclarator a -> a
minimum :: AbstractDeclarator a -> a
$cminimum :: forall a. Ord a => AbstractDeclarator a -> a
maximum :: AbstractDeclarator a -> a
$cmaximum :: forall a. Ord a => AbstractDeclarator a -> a
elem :: a -> AbstractDeclarator a -> Bool
$celem :: forall a. Eq a => a -> AbstractDeclarator a -> Bool
length :: AbstractDeclarator a -> Int
$clength :: forall a. AbstractDeclarator a -> Int
null :: AbstractDeclarator a -> Bool
$cnull :: forall a. AbstractDeclarator a -> Bool
toList :: AbstractDeclarator a -> [a]
$ctoList :: forall a. AbstractDeclarator a -> [a]
foldl1 :: (a -> a -> a) -> AbstractDeclarator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> AbstractDeclarator a -> a
foldr1 :: (a -> a -> a) -> AbstractDeclarator a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> AbstractDeclarator a -> a
foldl' :: (b -> a -> b) -> b -> AbstractDeclarator a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> AbstractDeclarator a -> b
foldl :: (b -> a -> b) -> b -> AbstractDeclarator a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> AbstractDeclarator a -> b
foldr' :: (a -> b -> b) -> b -> AbstractDeclarator a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> AbstractDeclarator a -> b
foldr :: (a -> b -> b) -> b -> AbstractDeclarator a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> AbstractDeclarator a -> b
foldMap' :: (a -> m) -> AbstractDeclarator a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> AbstractDeclarator a -> m
foldMap :: (a -> m) -> AbstractDeclarator a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> AbstractDeclarator a -> m
fold :: AbstractDeclarator m -> m
$cfold :: forall m. Monoid m => AbstractDeclarator m -> m
Foldable, Functor AbstractDeclarator
Foldable AbstractDeclarator
Functor AbstractDeclarator
-> Foldable AbstractDeclarator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AbstractDeclarator (f a) -> f (AbstractDeclarator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> AbstractDeclarator a -> m (AbstractDeclarator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AbstractDeclarator (m a) -> m (AbstractDeclarator a))
-> Traversable AbstractDeclarator
(a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AbstractDeclarator (m a) -> m (AbstractDeclarator a)
forall (f :: * -> *) a.
Applicative f =>
AbstractDeclarator (f a) -> f (AbstractDeclarator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AbstractDeclarator a -> m (AbstractDeclarator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b)
sequence :: AbstractDeclarator (m a) -> m (AbstractDeclarator a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
AbstractDeclarator (m a) -> m (AbstractDeclarator a)
mapM :: (a -> m b) -> AbstractDeclarator a -> m (AbstractDeclarator b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AbstractDeclarator a -> m (AbstractDeclarator b)
sequenceA :: AbstractDeclarator (f a) -> f (AbstractDeclarator a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
AbstractDeclarator (f a) -> f (AbstractDeclarator a)
traverse :: (a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AbstractDeclarator a -> f (AbstractDeclarator b)
$cp2Traversable :: Foldable AbstractDeclarator
$cp1Traversable :: Functor AbstractDeclarator
Traversable)

abstract_declarator :: CParser i m => m (AbstractDeclarator i)
abstract_declarator :: m (AbstractDeclarator i)
abstract_declarator = do
  [Pointer]
ptrs <- m Pointer -> m [Pointer]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m Pointer
forall i (m :: * -> *). CParser i m => m Pointer
pointer
  -- If there are no pointers, there must be an abstract declarator.
  let p :: m (Maybe (DirectAbstractDeclarator i))
p = if [Pointer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Pointer]
ptrs
        then DirectAbstractDeclarator i -> Maybe (DirectAbstractDeclarator i)
forall a. a -> Maybe a
Just (DirectAbstractDeclarator i -> Maybe (DirectAbstractDeclarator i))
-> m (DirectAbstractDeclarator i)
-> m (Maybe (DirectAbstractDeclarator i))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (DirectAbstractDeclarator i)
forall i (m :: * -> *).
CParser i m =>
m (DirectAbstractDeclarator i)
direct_abstract_declarator
        else (DirectAbstractDeclarator i -> Maybe (DirectAbstractDeclarator i)
forall a. a -> Maybe a
Just (DirectAbstractDeclarator i -> Maybe (DirectAbstractDeclarator i))
-> m (DirectAbstractDeclarator i)
-> m (Maybe (DirectAbstractDeclarator i))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (DirectAbstractDeclarator i) -> m (DirectAbstractDeclarator i)
forall (m :: * -> *) a. Parsing m => m a -> m a
try m (DirectAbstractDeclarator i)
forall i (m :: * -> *).
CParser i m =>
m (DirectAbstractDeclarator i)
direct_abstract_declarator) m (Maybe (DirectAbstractDeclarator i))
-> m (Maybe (DirectAbstractDeclarator i))
-> m (Maybe (DirectAbstractDeclarator i))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (DirectAbstractDeclarator i)
-> m (Maybe (DirectAbstractDeclarator i))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (DirectAbstractDeclarator i)
forall a. Maybe a
Nothing
  [Pointer]
-> Maybe (DirectAbstractDeclarator i) -> AbstractDeclarator i
forall i.
[Pointer]
-> Maybe (DirectAbstractDeclarator i) -> AbstractDeclarator i
AbstractDeclarator [Pointer]
ptrs (Maybe (DirectAbstractDeclarator i) -> AbstractDeclarator i)
-> m (Maybe (DirectAbstractDeclarator i))
-> m (AbstractDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Maybe (DirectAbstractDeclarator i))
p

data DirectAbstractDeclarator i
  = ArrayOrProtoHere (ArrayOrProto i)
  | ArrayOrProtoThere (DirectAbstractDeclarator i) (ArrayOrProto i)
  | AbstractDeclaratorParens (AbstractDeclarator i)
  deriving (Typeable, DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
(DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool)
-> (DirectAbstractDeclarator i
    -> DirectAbstractDeclarator i -> Bool)
-> Eq (DirectAbstractDeclarator i)
forall i.
Eq i =>
DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
$c/= :: forall i.
Eq i =>
DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
== :: DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
$c== :: forall i.
Eq i =>
DirectAbstractDeclarator i -> DirectAbstractDeclarator i -> Bool
Eq, Int -> DirectAbstractDeclarator i -> ShowS
[DirectAbstractDeclarator i] -> ShowS
DirectAbstractDeclarator i -> String
(Int -> DirectAbstractDeclarator i -> ShowS)
-> (DirectAbstractDeclarator i -> String)
-> ([DirectAbstractDeclarator i] -> ShowS)
-> Show (DirectAbstractDeclarator i)
forall i. Show i => Int -> DirectAbstractDeclarator i -> ShowS
forall i. Show i => [DirectAbstractDeclarator i] -> ShowS
forall i. Show i => DirectAbstractDeclarator i -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DirectAbstractDeclarator i] -> ShowS
$cshowList :: forall i. Show i => [DirectAbstractDeclarator i] -> ShowS
show :: DirectAbstractDeclarator i -> String
$cshow :: forall i. Show i => DirectAbstractDeclarator i -> String
showsPrec :: Int -> DirectAbstractDeclarator i -> ShowS
$cshowsPrec :: forall i. Show i => Int -> DirectAbstractDeclarator i -> ShowS
Show, a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a
(a -> b)
-> DirectAbstractDeclarator a -> DirectAbstractDeclarator b
(forall a b.
 (a -> b)
 -> DirectAbstractDeclarator a -> DirectAbstractDeclarator b)
-> (forall a b.
    a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a)
-> Functor DirectAbstractDeclarator
forall a b.
a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a
forall a b.
(a -> b)
-> DirectAbstractDeclarator a -> DirectAbstractDeclarator b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a
$c<$ :: forall a b.
a -> DirectAbstractDeclarator b -> DirectAbstractDeclarator a
fmap :: (a -> b)
-> DirectAbstractDeclarator a -> DirectAbstractDeclarator b
$cfmap :: forall a b.
(a -> b)
-> DirectAbstractDeclarator a -> DirectAbstractDeclarator b
Functor, DirectAbstractDeclarator a -> Bool
(a -> m) -> DirectAbstractDeclarator a -> m
(a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
(forall m. Monoid m => DirectAbstractDeclarator m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DirectAbstractDeclarator a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DirectAbstractDeclarator a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b)
-> (forall a. (a -> a -> a) -> DirectAbstractDeclarator a -> a)
-> (forall a. (a -> a -> a) -> DirectAbstractDeclarator a -> a)
-> (forall a. DirectAbstractDeclarator a -> [a])
-> (forall a. DirectAbstractDeclarator a -> Bool)
-> (forall a. DirectAbstractDeclarator a -> Int)
-> (forall a. Eq a => a -> DirectAbstractDeclarator a -> Bool)
-> (forall a. Ord a => DirectAbstractDeclarator a -> a)
-> (forall a. Ord a => DirectAbstractDeclarator a -> a)
-> (forall a. Num a => DirectAbstractDeclarator a -> a)
-> (forall a. Num a => DirectAbstractDeclarator a -> a)
-> Foldable DirectAbstractDeclarator
forall a. Eq a => a -> DirectAbstractDeclarator a -> Bool
forall a. Num a => DirectAbstractDeclarator a -> a
forall a. Ord a => DirectAbstractDeclarator a -> a
forall m. Monoid m => DirectAbstractDeclarator m -> m
forall a. DirectAbstractDeclarator a -> Bool
forall a. DirectAbstractDeclarator a -> Int
forall a. DirectAbstractDeclarator a -> [a]
forall a. (a -> a -> a) -> DirectAbstractDeclarator a -> a
forall m a. Monoid m => (a -> m) -> DirectAbstractDeclarator a -> m
forall b a. (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b
forall a b. (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: DirectAbstractDeclarator a -> a
$cproduct :: forall a. Num a => DirectAbstractDeclarator a -> a
sum :: DirectAbstractDeclarator a -> a
$csum :: forall a. Num a => DirectAbstractDeclarator a -> a
minimum :: DirectAbstractDeclarator a -> a
$cminimum :: forall a. Ord a => DirectAbstractDeclarator a -> a
maximum :: DirectAbstractDeclarator a -> a
$cmaximum :: forall a. Ord a => DirectAbstractDeclarator a -> a
elem :: a -> DirectAbstractDeclarator a -> Bool
$celem :: forall a. Eq a => a -> DirectAbstractDeclarator a -> Bool
length :: DirectAbstractDeclarator a -> Int
$clength :: forall a. DirectAbstractDeclarator a -> Int
null :: DirectAbstractDeclarator a -> Bool
$cnull :: forall a. DirectAbstractDeclarator a -> Bool
toList :: DirectAbstractDeclarator a -> [a]
$ctoList :: forall a. DirectAbstractDeclarator a -> [a]
foldl1 :: (a -> a -> a) -> DirectAbstractDeclarator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> DirectAbstractDeclarator a -> a
foldr1 :: (a -> a -> a) -> DirectAbstractDeclarator a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> DirectAbstractDeclarator a -> a
foldl' :: (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b
foldl :: (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> DirectAbstractDeclarator a -> b
foldr' :: (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
foldr :: (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> DirectAbstractDeclarator a -> b
foldMap' :: (a -> m) -> DirectAbstractDeclarator a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> DirectAbstractDeclarator a -> m
foldMap :: (a -> m) -> DirectAbstractDeclarator a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> DirectAbstractDeclarator a -> m
fold :: DirectAbstractDeclarator m -> m
$cfold :: forall m. Monoid m => DirectAbstractDeclarator m -> m
Foldable, Functor DirectAbstractDeclarator
Foldable DirectAbstractDeclarator
Functor DirectAbstractDeclarator
-> Foldable DirectAbstractDeclarator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    DirectAbstractDeclarator (f a) -> f (DirectAbstractDeclarator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> DirectAbstractDeclarator a -> m (DirectAbstractDeclarator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    DirectAbstractDeclarator (m a) -> m (DirectAbstractDeclarator a))
-> Traversable DirectAbstractDeclarator
(a -> f b)
-> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
DirectAbstractDeclarator (m a) -> m (DirectAbstractDeclarator a)
forall (f :: * -> *) a.
Applicative f =>
DirectAbstractDeclarator (f a) -> f (DirectAbstractDeclarator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DirectAbstractDeclarator a -> m (DirectAbstractDeclarator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b)
sequence :: DirectAbstractDeclarator (m a) -> m (DirectAbstractDeclarator a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
DirectAbstractDeclarator (m a) -> m (DirectAbstractDeclarator a)
mapM :: (a -> m b)
-> DirectAbstractDeclarator a -> m (DirectAbstractDeclarator b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DirectAbstractDeclarator a -> m (DirectAbstractDeclarator b)
sequenceA :: DirectAbstractDeclarator (f a) -> f (DirectAbstractDeclarator a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
DirectAbstractDeclarator (f a) -> f (DirectAbstractDeclarator a)
traverse :: (a -> f b)
-> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DirectAbstractDeclarator a -> f (DirectAbstractDeclarator b)
$cp2Traversable :: Foldable DirectAbstractDeclarator
$cp1Traversable :: Functor DirectAbstractDeclarator
Traversable)

direct_abstract_declarator :: CParser i m => m (DirectAbstractDeclarator i)
direct_abstract_declarator :: m (DirectAbstractDeclarator i)
direct_abstract_declarator = do
  DirectAbstractDeclarator i
ddecltor <- [m (DirectAbstractDeclarator i)] -> m (DirectAbstractDeclarator i)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
    [ m (DirectAbstractDeclarator i) -> m (DirectAbstractDeclarator i)
forall (m :: * -> *) a. Parsing m => m a -> m a
try (ArrayOrProto i -> DirectAbstractDeclarator i
forall i. ArrayOrProto i -> DirectAbstractDeclarator i
ArrayOrProtoHere (ArrayOrProto i -> DirectAbstractDeclarator i)
-> m (ArrayOrProto i) -> m (DirectAbstractDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (ArrayOrProto i)
forall i (m :: * -> *). CParser i m => m (ArrayOrProto i)
array_or_proto)
    , AbstractDeclarator i -> DirectAbstractDeclarator i
forall i. AbstractDeclarator i -> DirectAbstractDeclarator i
AbstractDeclaratorParens (AbstractDeclarator i -> DirectAbstractDeclarator i)
-> m (AbstractDeclarator i) -> m (DirectAbstractDeclarator i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (AbstractDeclarator i) -> m (AbstractDeclarator i)
forall (m :: * -> *) a. TokenParsing m => m a -> m a
parens m (AbstractDeclarator i)
forall i (m :: * -> *). CParser i m => m (AbstractDeclarator i)
abstract_declarator
    ] m (DirectAbstractDeclarator i)
-> String -> m (DirectAbstractDeclarator i)
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"array, prototype, or parenthesised abstract declarator"
  [ArrayOrProto i]
aops <- m (ArrayOrProto i) -> m [ArrayOrProto i]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m (ArrayOrProto i)
forall i (m :: * -> *). CParser i m => m (ArrayOrProto i)
array_or_proto
  DirectAbstractDeclarator i -> m (DirectAbstractDeclarator i)
forall (m :: * -> *) a. Monad m => a -> m a
return (DirectAbstractDeclarator i -> m (DirectAbstractDeclarator i))
-> DirectAbstractDeclarator i -> m (DirectAbstractDeclarator i)
forall a b. (a -> b) -> a -> b
$ (DirectAbstractDeclarator i
 -> ArrayOrProto i -> DirectAbstractDeclarator i)
-> DirectAbstractDeclarator i
-> [ArrayOrProto i]
-> DirectAbstractDeclarator i
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl DirectAbstractDeclarator i
-> ArrayOrProto i -> DirectAbstractDeclarator i
forall i.
DirectAbstractDeclarator i
-> ArrayOrProto i -> DirectAbstractDeclarator i
ArrayOrProtoThere DirectAbstractDeclarator i
ddecltor [ArrayOrProto i]
aops

------------------------------------------------------------------------
-- Pretty printing

instance Pretty CIdentifier where
  pretty :: CIdentifier -> Doc
pretty = String -> Doc
PP.text (String -> Doc) -> (CIdentifier -> String) -> CIdentifier -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CIdentifier -> String
unCIdentifier

instance Pretty DeclarationSpecifier where
  pretty :: DeclarationSpecifier -> Doc
pretty DeclarationSpecifier
dspec = case DeclarationSpecifier
dspec of
    StorageClassSpecifier StorageClassSpecifier
x -> StorageClassSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty StorageClassSpecifier
x
    TypeSpecifier TypeSpecifier
x -> TypeSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty TypeSpecifier
x
    TypeQualifier TypeQualifier
x -> TypeQualifier -> Doc
forall a. Pretty a => a -> Doc
pretty TypeQualifier
x
    FunctionSpecifier FunctionSpecifier
x -> FunctionSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty FunctionSpecifier
x

instance Pretty StorageClassSpecifier where
  pretty :: StorageClassSpecifier -> Doc
pretty StorageClassSpecifier
storage = case StorageClassSpecifier
storage of
    StorageClassSpecifier
TYPEDEF -> Doc
"typedef"
    StorageClassSpecifier
EXTERN -> Doc
"extern"
    StorageClassSpecifier
STATIC -> Doc
"static"
    StorageClassSpecifier
AUTO -> Doc
"auto"
    StorageClassSpecifier
REGISTER -> Doc
"register"

instance Pretty TypeSpecifier where
  pretty :: TypeSpecifier -> Doc
pretty TypeSpecifier
tySpec = case TypeSpecifier
tySpec of
   TypeSpecifier
VOID -> Doc
"void"
   TypeSpecifier
BOOL -> Doc
"bool"
   TypeSpecifier
CHAR -> Doc
"char"
   TypeSpecifier
SHORT -> Doc
"short"
   TypeSpecifier
INT -> Doc
"int"
   TypeSpecifier
LONG -> Doc
"long"
   TypeSpecifier
FLOAT -> Doc
"float"
   TypeSpecifier
DOUBLE -> Doc
"double"
   TypeSpecifier
SIGNED -> Doc
"signed"
   TypeSpecifier
UNSIGNED -> Doc
"unsigned"
   Struct CIdentifier
x -> Doc
"struct" Doc -> Doc -> Doc
<+> CIdentifier -> Doc
forall a. Pretty a => a -> Doc
pretty CIdentifier
x
   Enum CIdentifier
x -> Doc
"enum" Doc -> Doc -> Doc
<+> CIdentifier -> Doc
forall a. Pretty a => a -> Doc
pretty CIdentifier
x
   TypeName CIdentifier
x -> CIdentifier -> Doc
forall a. Pretty a => a -> Doc
pretty CIdentifier
x
   Template CIdentifier
x [TypeSpecifier]
args -> CIdentifier -> Doc
forall a. Pretty a => a -> Doc
pretty CIdentifier
x Doc -> Doc -> Doc
<+> Doc
"<" Doc -> Doc -> Doc
<+> [Doc] -> Doc
forall a. Monoid a => [a] -> a
mconcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse Doc
"," ((TypeSpecifier -> Doc) -> [TypeSpecifier] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TypeSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty [TypeSpecifier]
args))  Doc -> Doc -> Doc
<+> Doc
">"
   TemplateConst String
x -> String -> Doc
forall a. Pretty a => a -> Doc
pretty String
x
   TemplatePointer TypeSpecifier
x -> TypeSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty TypeSpecifier
x Doc -> Doc -> Doc
<+> Doc
"*"

instance Pretty TypeQualifier where
  pretty :: TypeQualifier -> Doc
pretty TypeQualifier
tyQual = case TypeQualifier
tyQual of
    TypeQualifier
CONST -> Doc
"const"
    TypeQualifier
RESTRICT -> Doc
"restrict"
    TypeQualifier
VOLATILE -> Doc
"volatile"

instance Pretty FunctionSpecifier where
  pretty :: FunctionSpecifier -> Doc
pretty FunctionSpecifier
funSpec = case FunctionSpecifier
funSpec of
    FunctionSpecifier
INLINE -> Doc
"inline"

instance Pretty i => Pretty (Declarator i) where
  pretty :: Declarator i -> Doc
pretty (Declarator [Pointer]
ptrs DirectDeclarator i
ddecltor) = case [Pointer]
ptrs of
    [] -> DirectDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectDeclarator i
ddecltor
    Pointer
_:[Pointer]
_ -> [Pointer] -> Doc
prettyPointers [Pointer]
ptrs Doc -> Doc -> Doc
<+> DirectDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectDeclarator i
ddecltor

prettyPointers :: [Pointer] -> Doc
prettyPointers :: [Pointer] -> Doc
prettyPointers [] = Doc
""
prettyPointers (Pointer
x : [Pointer]
xs) = Pointer -> Doc
forall a. Pretty a => a -> Doc
pretty Pointer
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Pointer] -> Doc
prettyPointers [Pointer]
xs

instance Pretty Pointer where
  pretty :: Pointer -> Doc
pretty (Pointer [TypeQualifier]
tyQual) = Doc
"*" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [Doc] -> Doc
hsep ((TypeQualifier -> Doc) -> [TypeQualifier] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TypeQualifier -> Doc
forall a. Pretty a => a -> Doc
pretty [TypeQualifier]
tyQual)

instance Pretty i => Pretty (DirectDeclarator i) where
  pretty :: DirectDeclarator i -> Doc
pretty DirectDeclarator i
decltor = case DirectDeclarator i
decltor of
    DeclaratorRoot i
x -> i -> Doc
forall a. Pretty a => a -> Doc
pretty i
x
    DeclaratorParens Declarator i
x -> Doc
"(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Declarator i -> Doc
forall a. Pretty a => a -> Doc
pretty Declarator i
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
")"
    ArrayOrProto DirectDeclarator i
ddecltor ArrayOrProto i
aorp -> DirectDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectDeclarator i
ddecltor Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> ArrayOrProto i -> Doc
forall a. Pretty a => a -> Doc
pretty ArrayOrProto i
aorp

instance Pretty i => Pretty (ArrayOrProto i) where
  pretty :: ArrayOrProto i -> Doc
pretty ArrayOrProto i
aorp = case ArrayOrProto i
aorp of
    Array ArrayType i
x -> Doc
"[" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> ArrayType i -> Doc
forall a. Pretty a => a -> Doc
pretty ArrayType i
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
"]"
    Proto [ParameterDeclaration i]
x -> Doc
"(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> [ParameterDeclaration i] -> Doc
forall a. Pretty a => [a] -> Doc
prettyParams [ParameterDeclaration i]
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
")"

prettyParams :: (Pretty a) => [a] -> Doc
prettyParams :: [a] -> Doc
prettyParams [a]
xs = case [a]
xs of
  [] -> Doc
""
  [a
x] -> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
x
  a
x : xs' :: [a]
xs'@(a
_:[a]
_) -> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
"," Doc -> Doc -> Doc
<+> [a] -> Doc
forall a. Pretty a => [a] -> Doc
prettyParams [a]
xs'

instance Pretty i => Pretty (ArrayType i) where
  pretty :: ArrayType i -> Doc
pretty ArrayType i
at = case ArrayType i
at of
    ArrayType i
VariablySized -> Doc
"*"
    SizedByInteger Integer
n -> Integer -> Doc
forall a. Pretty a => a -> Doc
pretty Integer
n
    SizedByIdentifier i
s -> i -> Doc
forall a. Pretty a => a -> Doc
pretty i
s
    ArrayType i
Unsized -> Doc
""

instance Pretty i => Pretty (ParameterDeclaration i) where
  pretty :: ParameterDeclaration i -> Doc
pretty (ParameterDeclaration [DeclarationSpecifier]
declSpecs DeclaratorOrAbstractDeclarator i
decltor) = case [DeclarationSpecifier]
declSpecs of
    [] -> Doc
decltorDoc
    DeclarationSpecifier
_:[DeclarationSpecifier]
_ -> [Doc] -> Doc
hsep ((DeclarationSpecifier -> Doc) -> [DeclarationSpecifier] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map DeclarationSpecifier -> Doc
forall a. Pretty a => a -> Doc
pretty [DeclarationSpecifier]
declSpecs) Doc -> Doc -> Doc
<+> Doc
decltorDoc
    where
      decltorDoc :: Doc
decltorDoc = case DeclaratorOrAbstractDeclarator i
decltor of
        IsDeclarator Declarator i
x -> Declarator i -> Doc
forall a. Pretty a => a -> Doc
pretty Declarator i
x
        IsAbstractDeclarator AbstractDeclarator i
x -> AbstractDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty AbstractDeclarator i
x

instance Pretty i => Pretty (AbstractDeclarator i) where
  pretty :: AbstractDeclarator i -> Doc
pretty (AbstractDeclarator [Pointer]
ptrs Maybe (DirectAbstractDeclarator i)
mbDecltor) = case ([Pointer]
ptrs, Maybe (DirectAbstractDeclarator i)
mbDecltor) of
    ([Pointer]
_, Maybe (DirectAbstractDeclarator i)
Nothing) -> [Pointer] -> Doc
prettyPointers [Pointer]
ptrs
    ([], Just DirectAbstractDeclarator i
x) -> DirectAbstractDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectAbstractDeclarator i
x
    (Pointer
_:[Pointer]
_, Just DirectAbstractDeclarator i
x) -> [Pointer] -> Doc
prettyPointers [Pointer]
ptrs Doc -> Doc -> Doc
<+> DirectAbstractDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectAbstractDeclarator i
x

instance Pretty i => Pretty (DirectAbstractDeclarator i) where
  pretty :: DirectAbstractDeclarator i -> Doc
pretty DirectAbstractDeclarator i
ddecltor = case DirectAbstractDeclarator i
ddecltor of
    AbstractDeclaratorParens AbstractDeclarator i
x -> Doc
"(" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> AbstractDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty AbstractDeclarator i
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
")"
    ArrayOrProtoHere ArrayOrProto i
aop -> ArrayOrProto i -> Doc
forall a. Pretty a => a -> Doc
pretty ArrayOrProto i
aop
    ArrayOrProtoThere DirectAbstractDeclarator i
ddecltor' ArrayOrProto i
aop -> DirectAbstractDeclarator i -> Doc
forall a. Pretty a => a -> Doc
pretty DirectAbstractDeclarator i
ddecltor' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> ArrayOrProto i -> Doc
forall a. Pretty a => a -> Doc
pretty ArrayOrProto i
aop

------------------------------------------------------------------------
-- Utils

many1 :: CParser i m => m a -> m [a]
many1 :: m a -> m [a]
many1 m a
p = (:) (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
p m ([a] -> [a]) -> m [a] -> m [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m a
p

------------------------------------------------------------------------
-- YACC grammar

-- $yacc
--
-- The parser above is derived from a modification of the YACC grammar
-- for C99 found at <http://www.quut.com/c/ANSI-C-grammar-y-1999.html>,
-- reproduced below.
--
-- @
-- %token IDENTIFIER TYPE_NAME INTEGER
--
-- %token TYPEDEF EXTERN STATIC AUTO REGISTER INLINE RESTRICT
-- %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
-- %token BOOL COMPLEX IMAGINARY
-- %token STRUCT UNION ENUM
--
-- %start parameter_list
-- %%
--
-- declaration_specifiers
-- 	: storage_class_specifier
-- 	| storage_class_specifier declaration_specifiers
-- 	| type_specifier
-- 	| type_specifier declaration_specifiers
-- 	| type_qualifier
-- 	| type_qualifier declaration_specifiers
-- 	| function_specifier
-- 	| function_specifier declaration_specifiers
-- 	;
--
-- storage_class_specifier
-- 	: TYPEDEF
-- 	| EXTERN
-- 	| STATIC
-- 	| AUTO
-- 	| REGISTER
-- 	;
--
-- type_specifier
-- 	: VOID
-- 	| CHAR
-- 	| SHORT
-- 	| INT
-- 	| LONG
-- 	| FLOAT
-- 	| DOUBLE
-- 	| SIGNED
-- 	| UNSIGNED
-- 	| BOOL
-- 	| COMPLEX
-- 	| IMAGINARY
--  	| STRUCT IDENTIFIER
-- 	| UNION IDENTIFIER
-- 	| ENUM IDENTIFIER
-- 	| TYPE_NAME
-- 	;
--
-- type_qualifier
-- 	: CONST
-- 	| RESTRICT
-- 	| VOLATILE
-- 	;
--
-- function_specifier
-- 	: INLINE
-- 	;
--
-- declarator
-- 	: pointer direct_declarator
-- 	| direct_declarator
-- 	;
--
-- direct_declarator
-- 	: IDENTIFIER
-- 	| '(' declarator ')'
-- 	| direct_declarator '[' type_qualifier_list ']'
-- 	| direct_declarator '[' type_qualifier_list '*' ']'
-- 	| direct_declarator '[' '*' ']'
--  	| direct_declarator '[' IDENTIFIER ']'
-- 	| direct_declarator '[' INTEGER ']'
-- 	| direct_declarator '[' ']'
-- 	| direct_declarator '(' parameter_list ')'
-- 	| direct_declarator '(' ')'
-- 	;
--
-- pointer
-- 	: '*'
-- 	| '*' type_qualifier_list
-- 	| '*' pointer
-- 	| '*' type_qualifier_list pointer
-- 	;
--
-- type_qualifier_list
-- 	: type_qualifier
-- 	| type_qualifier_list type_qualifier
-- 	;
--
-- parameter_list
-- 	: parameter_declaration
-- 	| parameter_list ',' parameter_declaration
-- 	;
--
-- parameter_declaration
-- 	: declaration_specifiers declarator
-- 	| declaration_specifiers abstract_declarator
-- 	| declaration_specifiers
-- 	;
--
-- abstract_declarator
-- 	: pointer
-- 	| direct_abstract_declarator
-- 	| pointer direct_abstract_declarator
-- 	;
--
-- direct_abstract_declarator
-- 	: '(' abstract_declarator ')'
-- 	| '[' ']'
-- 	| direct_abstract_declarator '[' ']'
-- 	| '[' '*' ']'
-- 	| direct_abstract_declarator '[' '*' ']'
-- 	| '[' IDENTIFIER ']'
-- 	| direct_abstract_declarator '[' IDENTIFIER ']'
-- 	| '[' INTEGER ']'
-- 	| direct_abstract_declarator '[' INTEGER ']'
-- 	| '(' ')'
-- 	| '(' parameter_list ')'
-- 	| direct_abstract_declarator '(' ')'
-- 	| direct_abstract_declarator '(' parameter_list ')'
-- 	;
--
-- %%
-- #include \<stdio.h\>
--
-- extern char yytext[];
-- extern int column;
--
-- void yyerror(char const *s)
-- {
-- 	fflush(stdout);
-- 	printf("\n%*s\n%*s\n", column, "^", column, s);
-- }
-- @

-- Utils
------------------------------------------------------------------------

cppIdentParser :: (Monad m, CharParsing m) => Bool -> IdentifierStyle m -> m [Char]
cppIdentParser :: Bool -> IdentifierStyle m -> m String
cppIdentParser Bool
useCpp IdentifierStyle m
s = m String
cidentParserWithNamespace
  where
    cidentParser :: m String
cidentParser = ((:) (Char -> ShowS) -> m Char -> m ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleStart IdentifierStyle m
s m ShowS -> m String -> m String
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Char -> m String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (IdentifierStyle m -> m Char
forall (m :: * -> *). IdentifierStyle m -> m Char
_styleLetter IdentifierStyle m
s) m String -> String -> m String
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s)
    cidentParserWithNamespace :: m String
cidentParserWithNamespace =
      if Bool
useCpp
      then
        m String -> m String
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> m [String] -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [m String] -> m [String]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [m String
cidentParser, (String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
string String
"::"), m String
cidentParserWithNamespace]) m String -> m String -> m String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
        m String
cidentParser
      else
        m String
cidentParser

identNoLex :: (TokenParsing m, Monad m, IsString s) => Bool -> IdentifierStyle m -> m s
identNoLex :: Bool -> IdentifierStyle m -> m s
identNoLex Bool
useCpp IdentifierStyle m
s = (String -> s) -> m String -> m s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> s
forall a. IsString a => String -> a
fromString (m String -> m s) -> m String -> m s
forall a b. (a -> b) -> a -> b
$ m String -> m String
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ do
  String
name <- Highlight -> m String -> m String
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
s) (Bool -> IdentifierStyle m -> m String
forall (m :: * -> *).
(Monad m, CharParsing m) =>
Bool -> IdentifierStyle m -> m String
cppIdentParser Bool
useCpp IdentifierStyle m
s)
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String -> HashSet String -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member String
name (IdentifierStyle m -> HashSet String
forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved IdentifierStyle m
s)) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> m ()
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"reserved " String -> ShowS
forall a. [a] -> [a] -> [a]
++ IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
name
  String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return String
name

ident' :: (TokenParsing m, Monad m, IsString s) => Bool -> IdentifierStyle m -> m s
ident' :: Bool -> IdentifierStyle m -> m s
ident' Bool
useCpp IdentifierStyle m
s = (String -> s) -> m String -> m s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> s
forall a. IsString a => String -> a
fromString (m String -> m s) -> m String -> m s
forall a b. (a -> b) -> a -> b
$ m String -> m String
forall (m :: * -> *) a. TokenParsing m => m a -> m a
token (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ m String -> m String
forall (m :: * -> *) a. Parsing m => m a -> m a
try (m String -> m String) -> m String -> m String
forall a b. (a -> b) -> a -> b
$ do
  String
name <- Highlight -> m String -> m String
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
highlight (IdentifierStyle m -> Highlight
forall (m :: * -> *). IdentifierStyle m -> Highlight
_styleHighlight IdentifierStyle m
s) (Bool -> IdentifierStyle m -> m String
forall (m :: * -> *).
(Monad m, CharParsing m) =>
Bool -> IdentifierStyle m -> m String
cppIdentParser Bool
useCpp IdentifierStyle m
s)
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String -> HashSet String -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HashSet.member String
name (IdentifierStyle m -> HashSet String
forall (m :: * -> *). IdentifierStyle m -> HashSet String
_styleReserved IdentifierStyle m
s)) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> m ()
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"reserved " String -> ShowS
forall a. [a] -> [a] -> [a]
++ IdentifierStyle m -> String
forall (m :: * -> *). IdentifierStyle m -> String
_styleName IdentifierStyle m
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
name
  String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return String
name