-- GENERATED by C->Haskell Compiler, version 0.26.2 Budburst, 26 October 2015 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Clang/Internal/FFI.chs" #-}
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-unused-matches #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE CPP #-}

module Clang.Internal.FFI
( versionMajor
, versionMinor
, encodedVersion
, Index
, createIndex
, GlobalIndexOptions(..)
, threadBackgroundPriorityForAll
, cXIndex_setGlobalOptions
, cXIndex_getGlobalOptions
, TranslationUnit
, UnsavedFile
, unsavedFilename
, unsavedContents
, newUnsavedFile
, updateUnsavedContents
, AvailabilityKind(..)
, Version(..)
, ClangString
, getString
, getByteString
, unsafeGetByteString
, File(..)
, getFileName
, getFileTime
, UniqueId(..)
, getFileUniqueID
, isFileMultipleIncludeGuarded
, getFile
, SourceLocation
, getNullLocation
, equalLocations
, getLocation
, getLocationForOffset
, location_isInSystemHeader
, location_isFromMainFile
, SourceRange
, getNullRange
, getRange
, equalRanges
, range_isNull
, getExpansionLocation
, getPresumedLocation
, getSpellingLocation
, getFileLocation
, getRangeStart
, getRangeEnd
, Severity(..)
, Diagnostic
, DiagnosticSet
, getNumDiagnosticsInSet
, getDiagnosticInSet
, LoadError(..)
, loadDiagnostics
, getChildDiagnostics
, getNumDiagnostics
, getDiagnostic
, getDiagnosticSetFromTU
, DisplayOptions(..)
, formatDiagnostic
, defaultDiagnosticDisplayOptions
, getDiagnosticSeverity
, getDiagnosticLocation
, getDiagnosticSpelling
, getDiagnosticOption
, getDiagnosticCategory
, getDiagnosticCategoryText
, getDiagnosticNumRanges
, getDiagnosticRange
, getDiagnosticNumFixIts
, getDiagnosticFixIt
, getTranslationUnitSpelling
, createTranslationUnitFromSourceFile
, createTranslationUnit
, TranslationUnitFlags(..)
, defaultEditingTranslationUnitOptions
, parseTranslationUnit
, setClangResourcesPath
, SaveTranslationUnitFlags(..)
, defaultSaveOptions
, saveTranslationUnit
, ReparseFlags(..)
, defaultReparseOptions
, reparseTranslationUnit
, CursorKind(..)
, firstDeclCursor
, lastDeclCursor
, firstRefCursor
, lastRefCursor
, firstInvalidCursor
, lastInvalidCursor
, firstExprCursor
, lastExprCursor
, firstStmtCursor
, lastStmtCursor
, firstAttrCursor
, lastAttrCursor
, firstPreprocessingCursor
, lastPreprocessingCursor
, firstExtraDeclCursor
, lastExtraDeclCursor
, gccAsmStmtCursor
, macroInstantiationCursor
, Comment(..)
, Cursor
, getNullCursor
, getTranslationUnitCursor
, cursor_isNull
, hashCursor
, getCursorKind
, isDeclaration
, isReference
, isExpression
, isStatement
, isAttribute
, isInvalid
, isTranslationUnit
, isPreprocessing
, isUnexposed
, LinkageKind(..)
, getCursorLinkage
, getCursorAvailability
, PlatformAvailability(..)
, PlatformAvailabilityInfo(..)
, getCursorPlatformAvailability
, LanguageKind(..)
, getCursorLanguage
, cursor_getTranslationUnit
, CursorSet
, createCXCursorSet
, cXCursorSet_contains
, cXCursorSet_insert
, getCursorSemanticParent
, getCursorLexicalParent
, getOverriddenCursors
, getIncludedFile
, getCursor
, getCursorLocation
, getCursorSpellingLocation
, getCursorExtent
, TypeKind(..)
, type_FirstBuiltin
, type_LastBuiltin
, CallingConv(..)
, Type
, getTypeKind
, getCursorType
, getTypeSpelling
, getTypedefDeclUnderlyingType
, getEnumDeclIntegerType
, getEnumConstantDeclValue
, getEnumConstantDeclUnsignedValue
, getFieldDeclBitWidth
, cursor_getNumArguments
, cursor_getArgument
, equalTypes
, getCanonicalType
, isConstQualifiedType
, isVolatileQualifiedType
, isRestrictQualifiedType
, getPointeeType
, getTypeDeclaration
, getDeclObjCTypeEncoding
, getTypeKindSpelling
, getFunctionTypeCallingConv
, getResultType
, getNumArgTypes
, getArgType
, isFunctionTypeVariadic
, getCursorResultType
, isPODType
, getElementType
, getNumElements
, getArrayElementType
, getArraySize
, TypeLayoutError(..)
, type_getAlignOf
, type_getClassType
, type_getSizeOf
, type_getOffsetOf
, RefQualifierKind(..)
, type_getCXXRefQualifier
, isBitField
, isVirtualBase
, CXXAccessSpecifier(..)
, getCXXAccessSpecifier
, getNumOverloadedDecls
, getOverloadedDecl
, getIBOutletCollectionType
, CursorList
, getChildren
, getDescendants
, getDeclarations
, getReferences
, getDeclarationsAndReferences
, ParentedCursor(..)
, ParentedCursorList
, getParentedDescendants
, getParentedDeclarations
, getParentedReferences
, getParentedDeclarationsAndReferences
, getCursorUSR
, constructUSR_ObjCClass
, constructUSR_ObjCCategory
, constructUSR_ObjCProtocol
, constructUSR_ObjCIvar
, constructUSR_ObjCMethod
, constructUSR_ObjCProperty
, getCursorSpelling
, cursor_getSpellingNameRange
, getCursorDisplayName
, getCursorReferenced
, getCursorDefinition
, isCursorDefinition
, cursor_isDynamicCall
, getCanonicalCursor
, cursor_getObjCSelectorIndex
, cursor_getReceiverType
, ObjCPropertyAttrKind(..)
, cursor_getObjCPropertyAttributes
, ObjCDeclQualifierKind(..)
, cursor_getObjCDeclQualifiers
, cursor_isObjCOptional
, cursor_isVariadic
, cursor_getCommentRange
, cursor_getRawCommentText
, cursor_getBriefCommentText
, cursor_getParsedComment
, Module(..)
, cursor_getModule
, module_getASTFile
, module_getParent
, module_getName
, module_getFullName
, module_getNumTopLevelHeaders
, module_getTopLevelHeader
, cXXMethod_isPureVirtual
, cXXMethod_isStatic
, cXXMethod_isVirtual
, getTemplateCursorKind
, getSpecializedCursorTemplate
, getCursorReferenceNameRange
, NameRefFlags(..)
, CommentKind(..)
, InlineCommandRenderStyle(..)
, ParamPassDirectionKind(..)
, comment_getKind
, comment_getNumChildren
, comment_getChild
, comment_isWhitespace
, inlineContentComment_hasTrailingNewline
, textComment_getText
, inlineCommandComment_getCommandName
, inlineCommandComment_getRenderKind
, inlineCommandComment_getNumArgs
, inlineCommandComment_getArgText
, hTMLTagComment_getTagName
, hTMLStartTagComment_isSelfClosing
, hTMLStartTag_getNumAttrs
, hTMLStartTag_getAttrName
, hTMLStartTag_getAttrValue
, blockCommandComment_getCommandName
, blockCommandComment_getNumArgs
, blockCommandComment_getArgText
, blockCommandComment_getParagraph
, paramCommandComment_getParamName
, paramCommandComment_isParamIndexValid
, paramCommandComment_getParamIndex
, paramCommandComment_isDirectionExplicit
, paramCommandComment_getDirection
, tParamCommandComment_getParamName
, tParamCommandComment_isParamPositionValid
, tParamCommandComment_getDepth
, tParamCommandComment_getIndex
, verbatimBlockLineComment_getText
, verbatimLineComment_getText
, hTMLTagComment_getAsString
, fullComment_getAsHTML
, fullComment_getAsXML
, TokenKind(..)
, Token
, TokenList
, getTokenKind
, getTokenSpelling
, getTokenLocation
, getTokenExtent
, tokenize
, annotateTokens
, getCursorKindSpelling
, enableStackTraces
, CompletionString
, CompletionResult
, ChunkKind(..)
, getCompletionChunkKind
, getCompletionChunkText
, getCompletionChunkCompletionString
, getNumCompletionChunks
, getCompletionPriority
, getCompletionAvailability
, getCompletionNumAnnotations
, getCompletionAnnotation
, getCompletionParent
, getCompletionBriefComment
, getCursorCompletionString
, CodeCompleteFlags(..)
, defaultCodeCompleteOptions
, CodeCompleteResults
, codeCompleteAt
, codeCompleteGetNumResults
, codeCompleteGetResult
, sortCodeCompletionResults
, codeCompleteGetNumDiagnostics
, codeCompleteGetDiagnostic
, CompletionContext(..)
, codeCompleteGetContexts
, codeCompleteGetContainerKind
, codeCompleteGetContainerUSR
, codeCompleteGetObjCSelector
, getClangVersion
, toggleCrashRecovery
, Inclusion(..)
, InclusionList
, getInclusions
, Remapping
, getRemappings
, getRemappingsFromFileList
, remap_getNumFiles
, remap_getFilenames
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Array as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp



import Control.Monad (forM_)
import Control.Monad.Trans
import qualified Data.ByteString as B
import qualified Data.ByteString.Unsafe as BU
import Data.Hashable
import Data.Typeable (Typeable)
import qualified Data.Vector as DV
import qualified Data.Vector.Storable as DVS
import qualified Data.Vector.Storable.Mutable as DVSM
import Data.Word
import Foreign.C
import Foreign
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Unsafe.Coerce (unsafeCoerce)  -- With GHC 7.8 we can use the safer 'coerce'.
import System.IO.Unsafe(unsafePerformIO)

import Clang.Internal.BitFlags
import Clang.Internal.FFIConstants
import Clang.Internal.Monad










{-
LibClang uses two strategies to create safe, deterministic
bindings.

First, all types that either represent resources managed on the C side
(for example, TranslationUnit and ClangString) or contain pointers into
those resources (for example, Cursor) are tagged with an ST-like
universally quantified phantom type parameter. This prevents them from
being used outside of the scope in which they were allocated. This is
particularly important for libclang, which uses an arena allocator to
store much of its data; preventing resources from leaking outside
their proper scope is critical to making this safe.

Second, all operations that allocate a resource that later
needs to be freed are wrapped in a type-specific 'register'
function. An example is registerClangString. This function registers a
cleanup action with the underlying ClangT monad, which is essentially
just ResourceT in disguise. This not only provides safety, but it also
enforces prompt finalization of resources which can significantly
increase performance by keeping the working set of user programs down.

There are a few different patterns for the FFI code, depending on what
kind of value the libclang function we want to wrap returns.

If it returns a pure value (say an Int), then we don't need to do
anything special. The greencard-generated function will have a return
type of IO Int, and the user-facing wrapper function will use liftIO
to call it.

If it returns a value that doesn't represent a newly allocated
resource, but does need the phantom type parameter (because it
contains a pointer into some other resource, generally), then we
generally pass a Proxy value with a type parameter that we'll use to
tag the return type. This has no runtime cost. The user-facing wrapper
function still needs to call liftIO.

For values that DO represent a newly allocated resource, we need to
call the appropriate 'register' function. This function will return a
value in the ClangT monad, so user-facing wrapper functions don't need
to use liftIO or Proxy in this case. It's the convention to use '()' for the
phantom type parameter returned from the greencard-generated function,
and allow the 'register' function to coerce the value to the correct
type. This way we can distinguish values that need to be registered
from other values: if a value's phantom type parameter is '()', it
needs to be registered, and it won't typecheck as the return value of
a user-facing wrapper function.

It's important to keep in mind that it should be legal to use values
from enclosing scopes in an inner scope created by clangScope. In
practice, this means that the phantom type parameters used by each
argument to a function should be distinct, and they should all be
distinct from the phantom type parameter used in the return value.
Of course, this doesn't apply to the Proxy parameter, which must
always have the same phantom type parameter as the return value.
-}

-- Marshalling utility functions.
fromCInt :: Num b => CInt -> b
fromCInt = fromIntegral

toCInt :: Integral a => a -> CInt
toCInt = fromIntegral

-- Version information.
versionMajor :: Int
versionMajor   = 0
{-# LINE 439 "src/Clang/Internal/FFI.chs" #-}

versionMinor :: Int
versionMinor   = 20
{-# LINE 441 "src/Clang/Internal/FFI.chs" #-}

encodedVersion :: Int
encodedVersion = 0 * 10000 + 20 * 1
{-# LINE 443 "src/Clang/Internal/FFI.chs" #-}


-- typedef void *CXIndex;
newtype Index s = Index { unIndex :: Ptr () }
                  deriving (Eq, Ord, Typeable)

instance ClangValue Index

mkIndex :: Ptr () -> Index ()
mkIndex = Index

-- CXIndex clang_createIndex(int excludeDeclarationsFromPCH, int displayDiagnostics);
clang_createIndex :: (CInt) -> (CInt) -> IO ((Ptr ()))
clang_createIndex a1 a2 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  clang_createIndex'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 455 "src/Clang/Internal/FFI.chs" #-}

unsafe_createIndex :: Bool -> Bool -> IO (Index ())
unsafe_createIndex a b = clang_createIndex (fromBool a) (fromBool b) >>= return . mkIndex

createIndex :: ClangBase m => Bool -> Bool -> ClangT s m (Index s)
createIndex = (registerIndex .) . unsafe_createIndex


-- void clang_disposeIndex(CXIndex index);
clang_disposeIndex :: (Ptr ()) -> IO ()
clang_disposeIndex a1 =
  let {a1' = id a1} in 
  clang_disposeIndex'_ a1' >>
  return ()

{-# LINE 464 "src/Clang/Internal/FFI.chs" #-}

disposeIndex :: Index s -> IO ()
disposeIndex index = clang_disposeIndex (unIndex index)

registerIndex :: ClangBase m => IO (Index ()) -> ClangT s m (Index s)
registerIndex action = do
  (_, idx) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\i -> disposeIndex i)
  return idx
{-# INLINEABLE registerIndex #-}

-- typedef enum {
--   CXGlobalOpt_None = 0x0,
--   CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
--   CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
--   CXGlobalOpt_ThreadBackgroundPriorityForAll =
--       CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
--       CXGlobalOpt_ThreadBackgroundPriorityForEditing
--
-- } CXGlobalOptFlags;

-- | Options that apply globally to every translation unit within an index.
data GlobalIndexOptions = DefaultGlobalIndexOptions
                        | ThreadBackgroundPriorityForIndexing
                        | ThreadBackgroundPriorityForEditing
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum GlobalIndexOptions where
  succ DefaultGlobalIndexOptions = ThreadBackgroundPriorityForIndexing
  succ ThreadBackgroundPriorityForIndexing = ThreadBackgroundPriorityForEditing
  succ ThreadBackgroundPriorityForEditing = error "GlobalIndexOptions.succ: ThreadBackgroundPriorityForEditing has no successor"

  pred ThreadBackgroundPriorityForIndexing = DefaultGlobalIndexOptions
  pred ThreadBackgroundPriorityForEditing = ThreadBackgroundPriorityForIndexing
  pred DefaultGlobalIndexOptions = error "GlobalIndexOptions.pred: DefaultGlobalIndexOptions has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ThreadBackgroundPriorityForEditing

  fromEnum DefaultGlobalIndexOptions = 0
  fromEnum ThreadBackgroundPriorityForIndexing = 1
  fromEnum ThreadBackgroundPriorityForEditing = 2

  toEnum 0 = DefaultGlobalIndexOptions
  toEnum 1 = ThreadBackgroundPriorityForIndexing
  toEnum 2 = ThreadBackgroundPriorityForEditing
  toEnum unmatched = error ("GlobalIndexOptions.toEnum: Cannot match " ++ show unmatched)

{-# LINE 492 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags GlobalIndexOptions where
  toBit DefaultGlobalIndexOptions           = 0x0
  toBit ThreadBackgroundPriorityForIndexing = 0x1
  toBit ThreadBackgroundPriorityForEditing  = 0x2

-- | A set of global index options that requests background priority for all threads.
threadBackgroundPriorityForAll :: [GlobalIndexOptions]
threadBackgroundPriorityForAll = [ThreadBackgroundPriorityForEditing,
                                  ThreadBackgroundPriorityForIndexing]

-- void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
clang_CXIndex_setGlobalOptions :: (Ptr ()) -> (Int) -> IO ()
clang_CXIndex_setGlobalOptions a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_CXIndex_setGlobalOptions'_ a1' a2' >>
  return ()

{-# LINE 505 "src/Clang/Internal/FFI.chs" #-}

cXIndex_setGlobalOptions :: Index s -> Int -> IO ()
cXIndex_setGlobalOptions index options = clang_CXIndex_setGlobalOptions (unIndex index) options

-- unsigned clang_CXIndex_getGlobalOptions(CXIndex);
clang_CXIndex_getGlobalOptions :: (Ptr ()) -> IO ((Int))
clang_CXIndex_getGlobalOptions a1 =
  let {a1' = id a1} in 
  clang_CXIndex_getGlobalOptions'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 510 "src/Clang/Internal/FFI.chs" #-}

cXIndex_getGlobalOptions :: Index s -> IO Int
cXIndex_getGlobalOptions index = clang_CXIndex_getGlobalOptions (unIndex index)

-- typedef struct CXTranslationUnitImpl *CXTranslationUnit;
newtype TranslationUnit s = TranslationUnit { unTranslationUnit :: (Ptr ()) }
                            deriving (Eq, Ord, Typeable)

instance ClangValue TranslationUnit

mkTranslationUnit :: Ptr () -> TranslationUnit ()
mkTranslationUnit = TranslationUnit

-- void clang_disposeTranslationUnit(CXTranslationUnit);
clang_disposeTranslationUnit :: (Ptr ()) -> IO ()
clang_disposeTranslationUnit a1 =
  let {a1' = id a1} in 
  clang_disposeTranslationUnit'_ a1' >>
  return ()

{-# LINE 524 "src/Clang/Internal/FFI.chs" #-}

disposeTranslationUnit :: TranslationUnit s -> IO ()
disposeTranslationUnit t = clang_disposeTranslationUnit (unTranslationUnit t)

registerTranslationUnit :: ClangBase m => IO (TranslationUnit ())
                        -> ClangT s m (TranslationUnit s)
registerTranslationUnit action = do
  (_, tu) <- clangAllocate (action >>= return . unsafeCoerce)
                           (\t -> disposeTranslationUnit t)
  return tu
{-# INLINEABLE registerTranslationUnit #-}

-- struct CXUnsavedFile {
--   const char* Filename;
--   const char* Contents;
--   unsigned long Length;
-- };

-- | A representation of an unsaved file and its contents.
data UnsavedFile = UnsavedFile
  { _unsavedFilename :: !B.ByteString
  , _unsavedContents :: !B.ByteString
  } deriving (Eq, Show, Typeable)

-- We maintain the invariant that _unsavedFilename is always
-- null-terminated. That's why we don't directly expose the record fields.
unsavedFilename :: UnsavedFile -> B.ByteString
unsavedFilename = _unsavedFilename

unsavedContents :: UnsavedFile -> B.ByteString
unsavedContents = _unsavedContents

newUnsavedFile :: B.ByteString -> B.ByteString -> UnsavedFile
newUnsavedFile f c = UnsavedFile (nullTerminate f) c

updateUnsavedContents :: UnsavedFile -> B.ByteString -> UnsavedFile
updateUnsavedContents uf c = UnsavedFile (unsavedFilename uf) c

-- TODO: Use BU.unsafeLast when we can use newer B.ByteString.
nullTerminate :: B.ByteString -> B.ByteString
nullTerminate bs
  | B.null bs      = B.singleton 0
  | B.last bs == 0 = bs
  | otherwise      = B.snoc bs 0

-- Functions which take a Vector UnsavedFile argument are implemented
-- internally in terms of this function, which temporarily allocates a
-- Vector CUnsavedFile holding the same data. (But does not copy the
-- string data itself.)
withUnsavedFiles :: DV.Vector UnsavedFile -> (Ptr CUnsavedFile -> Int -> IO a) -> IO a
withUnsavedFiles ufs f =
  withCUnsavedFiles ufs $ \cufs ->
    DVS.unsafeWith cufs $ \ptr ->
      f ptr (DVS.length cufs)

data CUnsavedFile = CUnsavedFile
  { cUnsavedFilename    :: CString
  , cUnsavedContents    :: CString
  , cUnsavedContentsLen :: CULong
  }

instance Storable CUnsavedFile where
    sizeOf _ = sizeOfCXUnsavedFile
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXUnsavedFile
    {-# INLINE alignment #-}

    peek p = do
      filename    <- peekByteOff p offsetCXUnsavedFileFilename
      contents    <- peekByteOff p offsetCXUnsavedFileContents
      contentsLen <- peekByteOff p offsetCXUnsavedFileContentsLen
      return $! CUnsavedFile filename contents contentsLen
    {-# INLINE peek #-}

    poke p (CUnsavedFile filename contents contentsLen) = do
      pokeByteOff p offsetCXUnsavedFileFilename filename
      pokeByteOff p offsetCXUnsavedFileContents contents
      pokeByteOff p offsetCXUnsavedFileContentsLen contentsLen
    {-# INLINE poke #-}


withCUnsavedFiles :: DV.Vector UnsavedFile -> (DVS.Vector CUnsavedFile -> IO a) -> IO a
withCUnsavedFiles ufs f = do
    let len = DV.length ufs
    v <- DVSM.new len
    go v 0 len
  where
    go v i len
      | i == len  = f =<< DVS.unsafeFreeze v
      | otherwise = do let uf = DV.unsafeIndex ufs i
                           ufFilename = unsavedFilename uf
                           ufContents = unsavedContents uf
                       BU.unsafeUseAsCString ufFilename $ \cufFilename ->
                         BU.unsafeUseAsCString ufContents $ \cufContents -> do
                           let contentsLen = fromIntegral $ B.length ufContents
                               cuf = CUnsavedFile cufFilename cufContents contentsLen
                           DVSM.write v i cuf
                           go v (i + 1) len

data AvailabilityKind = Availability_Available
                      | Availability_Deprecated
                      | Availability_NotAvailable
                      | Availability_NotAccessible
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum AvailabilityKind where
  succ Availability_Available = Availability_Deprecated
  succ Availability_Deprecated = Availability_NotAvailable
  succ Availability_NotAvailable = Availability_NotAccessible
  succ Availability_NotAccessible = error "AvailabilityKind.succ: Availability_NotAccessible has no successor"

  pred Availability_Deprecated = Availability_Available
  pred Availability_NotAvailable = Availability_Deprecated
  pred Availability_NotAccessible = Availability_NotAvailable
  pred Availability_Available = error "AvailabilityKind.pred: Availability_Available has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from Availability_NotAccessible

  fromEnum Availability_Available = 0
  fromEnum Availability_Deprecated = 1
  fromEnum Availability_NotAvailable = 2
  fromEnum Availability_NotAccessible = 3

  toEnum 0 = Availability_Available
  toEnum 1 = Availability_Deprecated
  toEnum 2 = Availability_NotAvailable
  toEnum 3 = Availability_NotAccessible
  toEnum unmatched = error ("AvailabilityKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 631 "src/Clang/Internal/FFI.chs" #-}


data Version = Version
  { majorVersion    :: !Int
  , minorVersion    :: !Int
  , subminorVersion :: !Int
  } deriving (Eq, Ord, Show, Typeable)

instance Storable Version where
  sizeOf _ = sizeOfCXVersion
  {-# INLINE sizeOf #-}

  alignment _ = alignOfCXVersion
  {-# INLINE alignment #-}

  peek p = do
    major <- fromCInt <$> peekByteOff p offsetCXVersionMajor
    minor <- fromCInt <$> peekByteOff p offsetCXVersionMinor
    subminor <- fromCInt <$> peekByteOff p offsetCXVersionSubminor
    return $! Version major minor subminor
  {-# INLINE peek #-}

  poke p (Version major minor subminor) = do
    pokeByteOff p offsetCXVersionMajor major
    pokeByteOff p offsetCXVersionMinor minor
    pokeByteOff p offsetCXVersionSubminor subminor
  {-# INLINE poke #-}

-- typedef struct {
--   const void *data;
--   unsigned private_flags;
-- } CXString;
data ClangString s = ClangString !(Ptr ()) !Word32
                     deriving (Eq, Ord, Typeable)

instance ClangValue ClangString

instance Storable (ClangString s) where
  sizeOf _ = 12 -- sizeOfCXString
  {-# INLINE sizeOf #-}

  alignment _ = 8 -- alignOfCXString
  {-# INLINE alignment #-}

  peek p = do
    strData <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) p
    strFlags <- (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CUInt}) p
    return $! ClangString strData (fromIntegral strFlags)
  {-# INLINE peek #-}

  poke p (ClangString d f) = do
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr ()))}) p d
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CUInt)}) p (fromIntegral f)
  {-# INLINE poke #-}

instance Hashable (ClangString s) where
  hashWithSalt salt (ClangString p f) = (`hashWithSalt` f)
                                      . (`hashWithSalt` pInt)
                                      $ salt
    where
      pInt = (fromIntegral $ ptrToWordPtr p) :: Int

registerClangString :: ClangBase m => IO (ClangString ()) -> ClangT s m (ClangString s)
registerClangString action = do
  (_, str) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\(ClangString d f) -> freeClangString d f)
  return str
{-# INLINEABLE registerClangString #-}

freeClangString :: (Ptr ()) -> (Word32) -> IO ()
freeClangString a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  freeClangString'_ a1' a2' >>
  return ()

{-# LINE 700 "src/Clang/Internal/FFI.chs" #-}


unmarshall_clangString :: Ptr () -> Word32 -> IO (ClangString ())
unmarshall_clangString d f = return $ ClangString d f

getString :: ClangBase m => ClangString s' -> ClangT s m String
getString (ClangString d f) = liftIO $ getCStringPtr d f >>= peekCString

getByteString :: ClangBase m => ClangString s' -> ClangT s m B.ByteString
getByteString (ClangString d f) = liftIO $ getCStringPtr d f >>= B.packCString

unsafeGetByteString :: ClangBase m => ClangString s' -> ClangT s m B.ByteString
unsafeGetByteString (ClangString d f) = liftIO $ getCStringPtr d f >>= BU.unsafePackCString

-- const char *clang_getCString(ClangString string);
clang_getCString :: (ClangString a) -> IO ((CString))
clang_getCString a1 =
  withVoided a1 $ \a1' -> 
  clang_getCString'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 715 "src/Clang/Internal/FFI.chs" #-}

getCStringPtr :: Ptr () -> Word32 -> IO CString
getCStringPtr d f = clang_getCString (ClangString d f)

-- typedef void *CXFile;
newtype File s = File { unFile :: Ptr () }
                 deriving (Eq, Ord, Typeable)

instance ClangValue File

instance Hashable (File s) where
  hashWithSalt salt (File p) = let !pInt = (fromIntegral $ ptrToWordPtr p) :: Int
                               in  hashWithSalt salt pInt

maybeFile :: File s' -> Maybe (File s)
maybeFile (File p) | p == nullPtr = Nothing
maybeFile f                       = Just (unsafeCoerce f)

unMaybeFile :: Maybe (File s') -> File s
unMaybeFile (Just f) = unsafeCoerce f
unMaybeFile Nothing  = File nullPtr


-- CXString clang_getFileName(CXFile SFile);
clang_getFileName :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_getFileName a1 =
  let {a1' = id a1} in 
  clang_getFileName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 739 "src/Clang/Internal/FFI.chs" #-}

unsafe_getFileName :: File s -> IO (ClangString ())
unsafe_getFileName x = clang_getFileName (unFile x) >>= peek

getFileName :: ClangBase m => File s' -> ClangT s m (ClangString s)
getFileName = registerClangString . unsafe_getFileName

-- time_t clang_getFileTime(CXFile SFile);
foreign import ccall unsafe "clang-c/Index.h clang_getFileTime" clang_getFileTime :: Ptr () -> IO CTime

getFileTime :: File s -> IO CTime
getFileTime (File ptr) = clang_getFileTime ptr

-- | A unique identifier that can be used to distinguish 'File's.
data UniqueId = UniqueId !Word64 !Word64 !Word64
                deriving (Eq, Ord, Show, Typeable)

instance Hashable UniqueId where
    hashWithSalt salt (UniqueId a b c) = (`hashWithSalt` a)
                                       . (`hashWithSalt` b)
                                       . (`hashWithSalt` c)
                                       $ salt
    {-# INLINE hashWithSalt #-}

maybeFileUniqueID :: (Int, Word64, Word64, Word64) -> Maybe UniqueId
maybeFileUniqueID (v, d1, d2, d3) | v /= 0    = Nothing
                                  | otherwise = Just $ UniqueId d1 d2 d3

-- int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
clang_getFileUniqueID :: (Ptr ()) -> (Ptr ()) -> IO ((CInt))
clang_getFileUniqueID a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  clang_getFileUniqueID'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 768 "src/Clang/Internal/FFI.chs" #-}

getFileUniqueID :: File s -> IO (Maybe UniqueId)
getFileUniqueID f =
  allocaArray 3 (ptrToFileUniqueId f)
  where
    ptrToFileUniqueId :: File s -> Ptr Word64 -> IO (Maybe UniqueId)
    ptrToFileUniqueId f' ptr = do
       res' <- clang_getFileUniqueID (unFile f') (castPtr ptr)
       ds' <- peekArray 3 ptr
       return (maybeFileUniqueID (fromIntegral res', ds' !! 0, ds' !! 1, ds' !! 2))

-- -- unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
clang_isFileMultipleIncludeGuarded :: (Ptr ()) -> (Ptr ()) -> IO ((CInt))
clang_isFileMultipleIncludeGuarded a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  clang_isFileMultipleIncludeGuarded'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 780 "src/Clang/Internal/FFI.chs" #-}

isFileMultipleIncludeGuarded :: TranslationUnit s -> File s' -> IO Bool
isFileMultipleIncludeGuarded t f = clang_isFileMultipleIncludeGuarded (unTranslationUnit t) (unFile f) >>= return . (toBool :: Int -> Bool) . fromIntegral

-- CXFile clang_getFile(CXTranslationUnit tu, const char *file_name);
clang_getFile :: (Ptr ()) -> (CString) -> IO ((Ptr ()))
clang_getFile a1 a2 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  clang_getFile'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 785 "src/Clang/Internal/FFI.chs" #-}

getFile:: Proxy s -> TranslationUnit s' -> String -> IO (File s)
getFile _ t s = withCString s (\cs -> clang_getFile (unTranslationUnit t) cs >>= return . File)

-- typedef struct {
--   void *ptr_data[2];
--   unsigned int_data;
-- } CXSourceLocation;

data SourceLocation s = SourceLocation !(Ptr ()) !(Ptr ()) !Int
                        deriving (Ord, Typeable)

instance ClangValue SourceLocation

instance Eq (SourceLocation s) where
  a == b = unsafePerformIO $ equalLocations a b

instance Storable (SourceLocation s) where
    sizeOf _ = sizeOfCXSourceLocation
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXSourceLocation
    {-# INLINE alignment #-}

    peek p = do
      ptrArray <- (\ptr -> do {return $ ptr `C2HSImp.plusPtr` 0 :: IO (C2HSImp.Ptr (C2HSImp.Ptr ()))}) p >>= peekArray 2
      intData <- (\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CUInt}) p
      return $! SourceLocation (ptrArray !! 0) (ptrArray !! 1) (fromIntegral intData)
    {-# INLINE peek #-}

    poke p (SourceLocation p0 p1 i )= do
      ptrsArray <- mallocArray 2
      pokeArray ptrsArray [p0,p1]
      (\ptr val -> do {C2HSImp.copyArray (ptr `C2HSImp.plusPtr` 0) (val :: (C2HSImp.Ptr (C2HSImp.Ptr ()))) 2}) p (castPtr ptrsArray)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: C2HSImp.CUInt)}) p (fromIntegral i)
    {-# INLINE poke #-}

-- typedef struct {
--   void *ptr_data[2];
--   unsigned begin_int_data;
--   unsigned end_int_data;
-- } CXSourceRange;
data SourceRange s = SourceRange !(Ptr ()) !(Ptr ()) !Int !Int
                     deriving (Ord, Typeable)

instance ClangValue SourceRange

instance Eq (SourceRange s) where
  a == b = unsafePerformIO $ equalRanges a b

instance Storable (SourceRange s) where
    sizeOf _ = sizeOfCXSourceRange
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXSourceRange
    {-# INLINE alignment #-}

    peek p = do
      ptrArray <- (\ptr -> do {return $ ptr `C2HSImp.plusPtr` 0 :: IO (C2HSImp.Ptr (C2HSImp.Ptr ()))}) p >>= peekArray 2
      beginIntData <- (\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CUInt}) p
      endIntData <- (\ptr -> do {C2HSImp.peekByteOff ptr 20 :: IO C2HSImp.CUInt}) p
      return $! SourceRange (ptrArray !! 0) (ptrArray !! 1) (fromIntegral beginIntData) (fromIntegral endIntData)
    {-# INLINE peek #-}

    poke p (SourceRange p0 p1 begin end)= do
      ptrsArray <- mallocArray 2
      pokeArray ptrsArray [p0,p1]
      (\ptr val -> do {C2HSImp.copyArray (ptr `C2HSImp.plusPtr` 0) (val :: (C2HSImp.Ptr (C2HSImp.Ptr ()))) 2}) p (castPtr ptrsArray)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: C2HSImp.CUInt)}) p (fromIntegral begin)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 20 (val :: C2HSImp.CUInt)}) p (fromIntegral end)
    {-# INLINE poke #-}

-- CXSourceLocation wrapped_clang_getNullLocation();
clang_getNullLocation :: IO ((Ptr (SourceLocation s)))
clang_getNullLocation =
  clang_getNullLocation'_ >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 858 "src/Clang/Internal/FFI.chs" #-}

getNullLocation :: Proxy s -> IO (SourceLocation s)
getNullLocation _ = clang_getNullLocation >>= peek

withVoided :: Storable a => a -> (Ptr () -> IO c) -> IO c
withVoided a f= with a (\aPtr -> f (castPtr aPtr))

-- unsigned clang_equalLocations(CXSourceLocation loc1, CXSourceLocation loc2);
clang_equalLocations :: (SourceLocation a) -> (SourceLocation b) -> IO ((Bool))
clang_equalLocations a1 a2 =
  withVoided a1 $ \a1' -> 
  withVoided a2 $ \a2' -> 
  clang_equalLocations'_ a1' a2' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 866 "src/Clang/Internal/FFI.chs" #-}

equalLocations :: SourceLocation s -> SourceLocation s' -> IO Bool
equalLocations s1 s2 = clang_equalLocations s1 s2

-- CXSourceLocation clang_getLocation(CXTranslationUnit tu,
--                                                   CXFile file,
--                                                   unsigned line,
--                                                   unsigned column);
clang_getLocation :: (Ptr ()) -> (Ptr ()) -> (Int) -> (Int) -> IO ((Ptr (SourceLocation s)))
clang_getLocation a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  clang_getLocation'_ a1' a2' a3' a4' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 874 "src/Clang/Internal/FFI.chs" #-}

getLocation :: Proxy s -> TranslationUnit s' -> File s'' -> Int -> Int -> IO (SourceLocation s)
getLocation _ t f i j = clang_getLocation (unTranslationUnit t) (unFile f) i j >>= peek

-- CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
--                                                            CXFile file,
--                                                            unsigned offset);
clang_getLocationForOffset :: (Ptr ()) -> (Ptr ()) -> (Int) -> IO ((Ptr (SourceLocation s)))
clang_getLocationForOffset a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  clang_getLocationForOffset'_ a1' a2' a3' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 881 "src/Clang/Internal/FFI.chs" #-}

getLocationForOffset :: Proxy s -> TranslationUnit s' -> File s'' -> Int -> IO (SourceLocation s)
getLocationForOffset _ t f i = clang_getLocationForOffset (unTranslationUnit t) (unFile f) i >>= peek

-- int clang_Location_isInSystemHeader(CXSourceLocation location);
clang_Location_isInSystemHeader :: (SourceLocation a) -> IO ((Bool))
clang_Location_isInSystemHeader a1 =
  withVoided a1 $ \a1' -> 
  clang_Location_isInSystemHeader'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 886 "src/Clang/Internal/FFI.chs" #-}

location_isInSystemHeader :: SourceLocation s -> IO Bool
location_isInSystemHeader s = clang_Location_isInSystemHeader s

-- int clang_Location_isFromMainFile(CXSourceLocation location);
clang_Location_isFromMainFile :: (SourceLocation a) -> IO ((Bool))
clang_Location_isFromMainFile a1 =
  withVoided a1 $ \a1' -> 
  clang_Location_isFromMainFile'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 891 "src/Clang/Internal/FFI.chs" #-}

location_isFromMainFile :: SourceLocation s -> IO Bool
location_isFromMainFile s = clang_Location_isFromMainFile s

-- CXSourceRange clang_getNullRange();
clang_getNullRange :: IO ((Ptr (SourceRange s)))
clang_getNullRange =
  clang_getNullRange'_ >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 896 "src/Clang/Internal/FFI.chs" #-}

getNullRange :: Proxy s -> IO (SourceRange s)
getNullRange _ = clang_getNullRange >>= peek

-- CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end);
clang_getRange :: (SourceLocation a) -> (SourceLocation b) -> IO ((Ptr (SourceRange s)))
clang_getRange a1 a2 =
  withVoided a1 $ \a1' -> 
  withVoided a2 $ \a2' -> 
  clang_getRange'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 901 "src/Clang/Internal/FFI.chs" #-}

getRange :: Proxy s -> SourceLocation s' -> SourceLocation s'' -> IO (SourceRange s)
getRange _ sl1 sl2 = clang_getRange sl1 sl2 >>= peek

-- unsigned clang_equalRanges(CXSourceRange range1, CXSourceRange range2);
clang_equalRanges :: (SourceRange a) -> (SourceRange b) -> IO ((Bool))
clang_equalRanges a1 a2 =
  withVoided a1 $ \a1' -> 
  withVoided a2 $ \a2' -> 
  clang_equalRanges'_ a1' a2' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 906 "src/Clang/Internal/FFI.chs" #-}

equalRanges :: SourceRange s' -> SourceRange s'' -> IO Bool
equalRanges sr1 sr2 = clang_equalRanges sr1 sr2

-- int clang_Range_isNull(CXSourceRange range);
clang_Range_isNull :: (SourceRange a ) -> IO ((Bool))
clang_Range_isNull a1 =
  withVoided a1 $ \a1' -> 
  clang_Range_isNull'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 911 "src/Clang/Internal/FFI.chs" #-}

range_isNull :: SourceRange s -> IO Bool
range_isNull s = clang_Range_isNull s

-- void clang_getExpansionLocation(CXSourceLocation location,
--                                 CXFile *file,
--                                 unsigned *line,
--                                 unsigned *column,
--                                 unsigned *offset);
clang_getExpansionLocation :: (SourceLocation a) -> (Ptr (Ptr ())) -> (Ptr CUInt) -> (Ptr CUInt) -> (Ptr CUInt) -> IO ()
clang_getExpansionLocation a1 a2 a3 a4 a5 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  let {a5' = id a5} in 
  clang_getExpansionLocation'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 923 "src/Clang/Internal/FFI.chs" #-}

getExpansionLocation :: Proxy s -> SourceLocation s' -> IO (Maybe (File s), Int, Int, Int)
getExpansionLocation _ s =
  allocaBytes 8 (\ptrToFilePtr ->
  alloca (\(linePtr :: (Ptr CUInt)) ->
  alloca (\(columnPtr :: (Ptr CUInt)) ->
  alloca (\(offsetPtr :: (Ptr CUInt)) -> do
    clang_getExpansionLocation s (castPtr ptrToFilePtr) (castPtr linePtr) (castPtr columnPtr) (castPtr offsetPtr)
    filePtr <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) ptrToFilePtr
    let _maybeFile = maybeFile (File filePtr)
    line <- peek linePtr
    column <- peek columnPtr
    offset <- peek offsetPtr
    return (_maybeFile, fromIntegral line, fromIntegral column, fromIntegral offset)))))

-- void clang_getPresumedLocation(CXSourceLocation location,
--                                CXString *filename,
--                                unsigned *line,
--                                unsigned *column);

clang_getPresumedLocation :: (SourceLocation a) -> (Ptr ()) -> IO ((CUInt), (CUInt))
clang_getPresumedLocation a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  alloca $ \a4' -> 
  clang_getPresumedLocation'_ a1' a2' a3' a4' >>
  peek  a3'>>= \a3'' -> 
  peek  a4'>>= \a4'' -> 
  return (a3'', a4'')

{-# LINE 943 "src/Clang/Internal/FFI.chs" #-}

unsafe_getPresumedLocation :: SourceLocation s' -> IO (ClangString (), Int, Int)
unsafe_getPresumedLocation s =
  alloca (\(stringPtr :: (Ptr (ClangString ()))) -> do
    (line, column) <- clang_getPresumedLocation s (castPtr stringPtr)
    clangString <- peek stringPtr
    return (clangString, fromIntegral line, fromIntegral column))

getPresumedLocation :: ClangBase m => SourceLocation s' -> ClangT s m (ClangString s, Int, Int)
getPresumedLocation l = do
  (f, ln, c) <- liftIO $ unsafe_getPresumedLocation l
  (,,) <$> registerClangString (return f) <*> return ln <*> return c

-- void clang_getSpellingLocation(CXSourceLocation location,
--                                CXFile *file,
--                                unsigned *line,
--                                unsigned *column,
--                                unsigned *offset);
clang_getSpellingLocation :: (SourceLocation a) -> (Ptr (Ptr ())) -> (Ptr CUInt) -> (Ptr CUInt) -> (Ptr CUInt) -> IO ()
clang_getSpellingLocation a1 a2 a3 a4 a5 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  let {a5' = id a5} in 
  clang_getSpellingLocation'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 961 "src/Clang/Internal/FFI.chs" #-}

getSpellingLocation :: Proxy s -> SourceLocation s' -> IO (Maybe (File s), Int, Int, Int)
getSpellingLocation _ s =
  allocaBytes 8 (\ptrToFilePtr ->
  alloca (\(linePtr :: (Ptr CUInt)) ->
  alloca (\(columnPtr :: (Ptr CUInt)) ->
  alloca (\(offsetPtr :: (Ptr CUInt)) -> do
    clang_getSpellingLocation s (castPtr ptrToFilePtr) linePtr columnPtr offsetPtr
    filePtr <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) ptrToFilePtr
    let _maybeFile = maybeFile (File filePtr)
    line <- peek linePtr
    column <- peek columnPtr
    offset <- peek offsetPtr
    return (_maybeFile, fromIntegral line, fromIntegral column, fromIntegral offset)))))

-- void clang_getFileLocation(CXSourceLocation location,
--                            CXFile *file,
--                            unsigned *line,
--                            unsigned *column,
--                            unsigned *offset);
clang_getFileLocation :: (SourceLocation a) -> (Ptr (Ptr ())) -> (Ptr CUInt) -> (Ptr CUInt) -> (Ptr CUInt) -> IO ()
clang_getFileLocation a1 a2 a3 a4 a5 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  let {a5' = id a5} in 
  clang_getFileLocation'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 981 "src/Clang/Internal/FFI.chs" #-}

getFileLocation :: Proxy s -> SourceLocation s' -> IO (Maybe (File s), Int, Int, Int)
getFileLocation _ s =
  allocaBytes 8 (\ptrToFilePtr ->
  alloca (\(linePtr :: (Ptr CUInt)) ->
  alloca (\(columnPtr :: (Ptr CUInt)) ->
  alloca (\(offsetPtr :: (Ptr CUInt)) -> do
    clang_getFileLocation s ptrToFilePtr (castPtr linePtr) (castPtr columnPtr) (castPtr offsetPtr)
    filePtr <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) ptrToFilePtr
    let _maybeFile = maybeFile (File filePtr)
    line <- peek linePtr
    column <- peek columnPtr
    offset <- peek offsetPtr
    return (_maybeFile, fromIntegral line, fromIntegral column, fromIntegral offset)))))

-- CXSourceLocation clang_getRangeStart(CXSourceRange range);
clang_getRangeStart :: (SourceRange a) -> IO ((Ptr (SourceLocation s)))
clang_getRangeStart a1 =
  withVoided a1 $ \a1' -> 
  clang_getRangeStart'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 997 "src/Clang/Internal/FFI.chs" #-}

getRangeStart :: Proxy s -> SourceRange s' -> IO (SourceLocation s)
getRangeStart _ sr = clang_getRangeStart sr >>= peek

-- CXSourceLocation clang_getRangeEnd(CXSourceRange range);
clang_getRangeEnd :: (SourceRange a) -> IO ((Ptr (SourceLocation s)))
clang_getRangeEnd a1 =
  withVoided a1 $ \a1' -> 
  clang_getRangeEnd'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1002 "src/Clang/Internal/FFI.chs" #-}

getRangeEnd :: Proxy s -> SourceRange s' -> IO (SourceLocation s)
getRangeEnd _ sr = clang_getRangeEnd sr >>= peek

-- enum CXDiagnosticSeverity {
--   CXDiagnostic_Ignored = 0,
--   CXDiagnostic_Note    = 1,
--   CXDiagnostic_Warning = 2,
--   CXDiagnostic_Error   = 3,
--   CXDiagnostic_Fatal   = 4
-- };

-- | The severity of a diagnostic.
data Severity = SeverityIgnored
              | SeverityNote
              | SeverityWarning
              | SeverityError
              | SeverityFatal
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum Severity where
  succ SeverityIgnored = SeverityNote
  succ SeverityNote = SeverityWarning
  succ SeverityWarning = SeverityError
  succ SeverityError = SeverityFatal
  succ SeverityFatal = error "Severity.succ: SeverityFatal has no successor"

  pred SeverityNote = SeverityIgnored
  pred SeverityWarning = SeverityNote
  pred SeverityError = SeverityWarning
  pred SeverityFatal = SeverityError
  pred SeverityIgnored = error "Severity.pred: SeverityIgnored has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from SeverityFatal

  fromEnum SeverityIgnored = 0
  fromEnum SeverityNote = 1
  fromEnum SeverityWarning = 2
  fromEnum SeverityError = 3
  fromEnum SeverityFatal = 4

  toEnum 0 = SeverityIgnored
  toEnum 1 = SeverityNote
  toEnum 2 = SeverityWarning
  toEnum 3 = SeverityError
  toEnum 4 = SeverityFatal
  toEnum unmatched = error ("Severity.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1023 "src/Clang/Internal/FFI.chs" #-}


-- typedef void* CXDiagnostic;
newtype Diagnostic s = Diagnostic { unDiagnostic :: Ptr () }
                       deriving (Eq, Ord, Typeable)

instance ClangValue Diagnostic

mkDiagnostic :: Ptr () -> Diagnostic ()
mkDiagnostic = Diagnostic

-- void clang_disposeDiagnostic(CXDiagnostic);
clang_disposeDiagnostic :: (Ptr ()) -> IO ()
clang_disposeDiagnostic a1 =
  let {a1' = id a1} in 
  clang_disposeDiagnostic'_ a1' >>
  return ()

{-# LINE 1035 "src/Clang/Internal/FFI.chs" #-}

disposeDiagnostic:: Diagnostic s -> IO ()
disposeDiagnostic d = clang_disposeDiagnostic (unDiagnostic d)

registerDiagnostic :: ClangBase m => IO (Diagnostic ()) -> ClangT s m (Diagnostic s)
registerDiagnostic action = do
  (_, idx) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\i -> disposeDiagnostic i)
  return idx
{-# INLINEABLE registerDiagnostic #-}

-- typedef void* CXDiagnosticSet;
newtype DiagnosticSet s = DiagnosticSet { unDiagnosticSet :: Ptr () }
                          deriving (Eq, Ord, Typeable)

instance ClangValue DiagnosticSet

mkDiagnosticSet :: Ptr () -> DiagnosticSet ()
mkDiagnosticSet = DiagnosticSet

-- void clang_disposeDiagnosticSet(CXDiagnosticSet);
clang_disposeDiagnosticSet :: (Ptr ()) -> IO ()
clang_disposeDiagnosticSet a1 =
  let {a1' = id a1} in 
  clang_disposeDiagnosticSet'_ a1' >>
  return ()

{-# LINE 1056 "src/Clang/Internal/FFI.chs" #-}

disposeDiagnosticSet :: DiagnosticSet s -> IO ()
disposeDiagnosticSet s = clang_disposeDiagnosticSet (unDiagnosticSet s)

registerDiagnosticSet :: ClangBase m => IO (DiagnosticSet ()) -> ClangT s m (DiagnosticSet s)
registerDiagnosticSet action = do
  (_, idx) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\i -> disposeDiagnosticSet i)
  return idx
{-# INLINEABLE registerDiagnosticSet #-}

-- unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
clang_getNumDiagnosticsInSet :: (Ptr ()) -> IO ((Int))
clang_getNumDiagnosticsInSet a1 =
  let {a1' = id a1} in 
  clang_getNumDiagnosticsInSet'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1068 "src/Clang/Internal/FFI.chs" #-}

getNumDiagnosticsInSet :: DiagnosticSet s -> IO Int
getNumDiagnosticsInSet s = clang_getNumDiagnosticsInSet (unDiagnosticSet s)

-- CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, unsigned Index);
clang_getDiagnosticInSet :: (Ptr ()) -> (Int) -> IO ((Ptr ()))
clang_getDiagnosticInSet a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getDiagnosticInSet'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1073 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticInSet :: DiagnosticSet s -> Int -> IO (Diagnostic ())
unsafe_getDiagnosticInSet s i = clang_getDiagnosticInSet (unDiagnosticSet s) i >>= return . mkDiagnostic

getDiagnosticInSet :: ClangBase m => DiagnosticSet s' -> Int -> ClangT s m (Diagnostic s)
getDiagnosticInSet = (registerDiagnostic .) . unsafe_getDiagnosticInSet

-- enum CXLoadDiag_Error {
--   CXLoadDiag_None = 0,
--   CXLoadDiag_Unknown = 1,
--   CXLoadDiag_CannotLoad = 2,
--   CXLoadDiag_InvalidFile = 3
-- };

-- | An error encountered while loading a serialized diagnostics bitcode file.
data LoadError = LoadSuccessful
               | LoadUnknownError
               | LoadCannotOpen
               | LoadInvalidFile
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum LoadError where
  succ LoadSuccessful = LoadUnknownError
  succ LoadUnknownError = LoadCannotOpen
  succ LoadCannotOpen = LoadInvalidFile
  succ LoadInvalidFile = error "LoadError.succ: LoadInvalidFile has no successor"

  pred LoadUnknownError = LoadSuccessful
  pred LoadCannotOpen = LoadUnknownError
  pred LoadInvalidFile = LoadCannotOpen
  pred LoadSuccessful = error "LoadError.pred: LoadSuccessful has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from LoadInvalidFile

  fromEnum LoadSuccessful = 0
  fromEnum LoadUnknownError = 1
  fromEnum LoadCannotOpen = 2
  fromEnum LoadInvalidFile = 3

  toEnum 0 = LoadSuccessful
  toEnum 1 = LoadUnknownError
  toEnum 2 = LoadCannotOpen
  toEnum 3 = LoadInvalidFile
  toEnum unmatched = error ("LoadError.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1095 "src/Clang/Internal/FFI.chs" #-}


data LoadDiagsResult =
  LoadDiagsResult LoadError (ClangString ()) (DiagnosticSet ())

-- CXDiagnosticSet clang_loadDiagnostics(const char *file,
--                                       enum CXLoadDiag_Error *error,
--                                       CXString *errorString);
clang_loadDiagnostics :: (CString) -> (Ptr ()) -> IO ((Ptr ()), (CInt))
clang_loadDiagnostics a1 a3 =
  (flip ($)) a1 $ \a1' -> 
  alloca $ \a2' -> 
  let {a3' = id a3} in 
  clang_loadDiagnostics'_ a1' a2' a3' >>= \res ->
  let {res' = id res} in
  peek  a2'>>= \a2'' -> 
  return (res', a2'')

{-# LINE 1103 "src/Clang/Internal/FFI.chs" #-}

unsafe_loadDiagnostics :: FilePath -> IO LoadDiagsResult
unsafe_loadDiagnostics file = withCString file (\cString -> alloca (go cString))
  where
    go :: CString -> Ptr (ClangString ()) -> IO LoadDiagsResult
    go str ptr = do
       (diagnosticSetPtr, err) <- clang_loadDiagnostics str (castPtr ptr)
       errString <- peek (castPtr ptr)
       return (LoadDiagsResult (toEnum (fromIntegral err)) errString (DiagnosticSet diagnosticSetPtr))

loadDiagnostics :: ClangBase m => FilePath
                -> ClangT s m (Either (LoadError, ClangString s) (DiagnosticSet s))
loadDiagnostics path = do
  result <- liftIO $ unsafe_loadDiagnostics path
  case result of
    (LoadDiagsResult err errStr ds@(DiagnosticSet p))
      | p == nullPtr -> Left . (err,) <$> registerClangString (return errStr)
      | otherwise    -> Right <$> registerDiagnosticSet (return ds)

-- CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
clang_getChildDiagnostics :: (Ptr ()) -> IO ((Ptr ()))
clang_getChildDiagnostics a1 =
  let {a1' = id a1} in 
  clang_getChildDiagnostics'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1123 "src/Clang/Internal/FFI.chs" #-}

unsafe_getChildDiagnostics :: Diagnostic s' -> IO (DiagnosticSet ())
unsafe_getChildDiagnostics d = clang_getChildDiagnostics (unDiagnostic d) >>= return . mkDiagnosticSet

-- Note that as a special case, the DiagnosticSet returned by this
-- function does not need to be freed, so we intentionally don't
-- register it.
getChildDiagnostics :: ClangBase m => Diagnostic s' -> ClangT s m (DiagnosticSet s)
getChildDiagnostics = unsafeCoerce <$> unsafe_getChildDiagnostics

-- unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
clang_getNumDiagnostics :: (Ptr ()) -> IO ((CUInt))
clang_getNumDiagnostics a1 =
  let {a1' = id a1} in 
  clang_getNumDiagnostics'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1134 "src/Clang/Internal/FFI.chs" #-}

getNumDiagnostics :: TranslationUnit s -> IO Int
getNumDiagnostics t = clang_getNumDiagnostics (unTranslationUnit t) >>= return . fromIntegral

-- CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index);
clang_getDiagnostic :: (Ptr ()) -> (CUInt) -> IO ((Ptr ()))
clang_getDiagnostic a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getDiagnostic'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1139 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnostic :: TranslationUnit s -> Int -> IO (Diagnostic ())
unsafe_getDiagnostic t i = clang_getDiagnostic (unTranslationUnit t) (fromIntegral i) >>= return . mkDiagnostic

getDiagnostic :: ClangBase m => TranslationUnit s' -> Int -> ClangT s m (Diagnostic s)
getDiagnostic = (registerDiagnostic .) . unsafe_getDiagnostic

-- CXDiagnosticSet clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
clang_getDiagnosticSetFromTU :: (Ptr ()) -> IO ((Ptr ()))
clang_getDiagnosticSetFromTU a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticSetFromTU'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1147 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticSetFromTU :: TranslationUnit s -> IO (DiagnosticSet ())
unsafe_getDiagnosticSetFromTU t = do
  set <- clang_getDiagnosticSetFromTU (unTranslationUnit t)
  return (mkDiagnosticSet set)

getDiagnosticSetFromTU :: ClangBase m => TranslationUnit s' -> ClangT s m (DiagnosticSet s)
getDiagnosticSetFromTU = registerDiagnosticSet . unsafe_getDiagnosticSetFromTU

-- enum CXDiagnosticDisplayOptions {
--   CXDiagnostic_DisplaySourceLocation = 0x01,
--   CXDiagnostic_DisplayColumn = 0x02,
--   CXDiagnostic_DisplaySourceRanges = 0x04,
--   CXDiagnostic_DisplayOption = 0x08,
--   CXDiagnostic_DisplayCategoryId = 0x10,
--   CXDiagnostic_DisplayCategoryName = 0x20
-- };

-- | Options for rendering of 'Diagnostic' values.
data DisplayOptions = DisplaySourceLocation
                    | DisplayColumn
                    | DisplaySourceRanges
                    | DisplayOption
                    | DisplayCategoryId
                    | DisplayCategoryName
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum DisplayOptions where
  succ DisplaySourceLocation = DisplayColumn
  succ DisplayColumn = DisplaySourceRanges
  succ DisplaySourceRanges = DisplayOption
  succ DisplayOption = DisplayCategoryId
  succ DisplayCategoryId = DisplayCategoryName
  succ DisplayCategoryName = error "DisplayOptions.succ: DisplayCategoryName has no successor"

  pred DisplayColumn = DisplaySourceLocation
  pred DisplaySourceRanges = DisplayColumn
  pred DisplayOption = DisplaySourceRanges
  pred DisplayCategoryId = DisplayOption
  pred DisplayCategoryName = DisplayCategoryId
  pred DisplaySourceLocation = error "DisplayOptions.pred: DisplaySourceLocation has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from DisplayCategoryName

  fromEnum DisplaySourceLocation = 1
  fromEnum DisplayColumn = 2
  fromEnum DisplaySourceRanges = 4
  fromEnum DisplayOption = 8
  fromEnum DisplayCategoryId = 16
  fromEnum DisplayCategoryName = 32

  toEnum 1 = DisplaySourceLocation
  toEnum 2 = DisplayColumn
  toEnum 4 = DisplaySourceRanges
  toEnum 8 = DisplayOption
  toEnum 16 = DisplayCategoryId
  toEnum 32 = DisplayCategoryName
  toEnum unmatched = error ("DisplayOptions.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1175 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags DisplayOptions where
  toBit DisplaySourceLocation = 0x1
  toBit DisplayColumn         = 0x2
  toBit DisplaySourceRanges   = 0x4
  toBit DisplayOption         = 0x8
  toBit DisplayCategoryId     = 0x10
  toBit DisplayCategoryName   = 0x20

-- CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options);
clang_formatDiagnostic :: (Ptr ()) -> (Int) -> IO ((Ptr (ClangString ())))
clang_formatDiagnostic a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_formatDiagnostic'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1186 "src/Clang/Internal/FFI.chs" #-}

unsafe_formatDiagnostic :: Diagnostic s -> Int -> IO (ClangString ())
unsafe_formatDiagnostic d i = clang_formatDiagnostic (unDiagnostic d) (fromIntegral i) >>= peek

formatDiagnostic :: ClangBase m => Diagnostic s' -> Int -> ClangT s m (ClangString s)
formatDiagnostic = (registerClangString .) . unsafe_formatDiagnostic

-- unsigned clang_defaultDiagnosticDisplayOptions(void);
clang_defaultDiagnosticDisplayOptions :: IO ((CUInt))
clang_defaultDiagnosticDisplayOptions =
  clang_defaultDiagnosticDisplayOptions'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1194 "src/Clang/Internal/FFI.chs" #-}

defaultDiagnosticDisplayOptions :: IO Int
defaultDiagnosticDisplayOptions = clang_defaultDiagnosticDisplayOptions >>= return . fromIntegral

-- clang_getDiagnosticSeverity(CXDiagnostic);
clang_getDiagnosticSeverity :: (Ptr ()) -> IO ((CInt))
clang_getDiagnosticSeverity a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticSeverity'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1199 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticSeverity :: Diagnostic s -> IO Severity
getDiagnosticSeverity d = clang_getDiagnosticSeverity (unDiagnostic d) >>= return . toEnum . fromIntegral

-- CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
clang_getDiagnosticLocation :: (Ptr ()) -> IO ((Ptr (SourceLocation s)))
clang_getDiagnosticLocation a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticLocation'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1204 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticLocation :: Proxy s -> Diagnostic s' -> IO (SourceLocation s)
getDiagnosticLocation _ d = clang_getDiagnosticLocation (unDiagnostic d) >>= peek

-- CXString clang_getDiagnosticSpelling(CXDiagnostic);
clang_getDiagnosticSpelling :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_getDiagnosticSpelling a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1209 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticSpelling :: Diagnostic s -> IO (ClangString ())
unsafe_getDiagnosticSpelling d = clang_getDiagnosticSpelling (unDiagnostic d) >>= peek

getDiagnosticSpelling :: ClangBase m => Diagnostic s' -> ClangT s m (ClangString s)
getDiagnosticSpelling = registerClangString . unsafe_getDiagnosticSpelling

-- CXString clang_getDiagnosticOption(CXDiagnostic Diag,
--                                                   CXString *Disable);
clang_getDiagnosticOption :: (Ptr ()) -> (Ptr ()) -> IO ((Ptr ()))
clang_getDiagnosticOption a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  clang_getDiagnosticOption'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1218 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticOption :: Diagnostic s -> IO (ClangString (), ClangString ())
unsafe_getDiagnosticOption d =
  alloca (\(disableCXStringPtr :: (Ptr (ClangString ()))) -> do
    diagnosticOptionPtr <- clang_getDiagnosticOption (unDiagnostic d) (castPtr disableCXStringPtr)
    disableCXString <- peek disableCXStringPtr
    diagnosticOption <- peek (castPtr diagnosticOptionPtr)
    return (diagnosticOption, disableCXString))

getDiagnosticOption :: ClangBase m => Diagnostic s' -> ClangT s m (ClangString s, ClangString s)
getDiagnosticOption d = do
  (a, b) <- liftIO $ unsafe_getDiagnosticOption d
  (,) <$> registerClangString (return a) <*> registerClangString (return b)

-- unsigned clang_getDiagnosticCategory(CXDiagnostic);
clang_getDiagnosticCategory :: (Ptr ()) -> IO ((Int))
clang_getDiagnosticCategory a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticCategory'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1233 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticCategory :: Diagnostic s -> IO Int
getDiagnosticCategory d = clang_getDiagnosticCategory (unDiagnostic d)

-- CXString clang_getDiagnosticCategoryText(CXDiagnostic);
clang_getDiagnosticCategoryText :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_getDiagnosticCategoryText a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticCategoryText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1238 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticCategoryText :: Diagnostic s -> IO (ClangString ())
unsafe_getDiagnosticCategoryText d = clang_getDiagnosticCategoryText (unDiagnostic d) >>= peek

getDiagnosticCategoryText :: ClangBase m => Diagnostic s' -> ClangT s m (ClangString s)
getDiagnosticCategoryText = registerClangString . unsafe_getDiagnosticCategoryText

-- unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
clang_getDiagnosticNumRanges :: (Ptr ()) -> IO ((Int))
clang_getDiagnosticNumRanges a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticNumRanges'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1246 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticNumRanges :: Diagnostic s -> IO Int
getDiagnosticNumRanges d = clang_getDiagnosticNumRanges (unDiagnostic d)

-- CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
--                                                       unsigned Range);
clang_getDiagnosticRange :: (Ptr ()) -> (Int) -> IO ((Ptr (SourceRange s)))
clang_getDiagnosticRange a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getDiagnosticRange'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1252 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticRange :: Diagnostic s' -> Int -> IO (SourceRange s)
getDiagnosticRange d i = clang_getDiagnosticRange (unDiagnostic d) i >>= peek

-- unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
clang_getDiagnosticNumFixIts :: (Ptr ()) -> IO ((Int))
clang_getDiagnosticNumFixIts a1 =
  let {a1' = id a1} in 
  clang_getDiagnosticNumFixIts'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1257 "src/Clang/Internal/FFI.chs" #-}

getDiagnosticNumFixIts :: Diagnostic s -> IO Int
getDiagnosticNumFixIts d = clang_getDiagnosticNumFixIts (unDiagnostic d)

-- CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
--                                                  unsigned FixIt,
--                                                CXSourceRange *ReplacementRange);
clang_getDiagnosticFixIt :: (Ptr ()) -> (Int) -> (Ptr ()) -> IO ((Ptr (ClangString())))
clang_getDiagnosticFixIt a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  clang_getDiagnosticFixIt'_ a1' a2' a3' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1264 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDiagnosticFixIt :: Diagnostic s' -> Int -> IO (SourceRange s, ClangString ())
unsafe_getDiagnosticFixIt d i =
  alloca (\(replacementRangePtr :: (Ptr (SourceRange s))) -> do
     clangStringPtr <- clang_getDiagnosticFixIt (unDiagnostic d) i (castPtr replacementRangePtr)
     clangString <- peek clangStringPtr
     replacementRange <- peek replacementRangePtr
     return (replacementRange, clangString))

getDiagnosticFixIt :: ClangBase m => Diagnostic s' -> Int
                   -> ClangT s m (SourceRange s, ClangString s)
getDiagnosticFixIt d i = do
  (r, s) <- liftIO $ unsafe_getDiagnosticFixIt d i
  (r,) <$> registerClangString (return s)

-- CXString
-- clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
clang_getTranslationUnitSpelling :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_getTranslationUnitSpelling a1 =
  let {a1' = id a1} in 
  clang_getTranslationUnitSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 1281 "src/Clang/Internal/FFI.chs" #-}

unsafe_getTranslationUnitSpelling :: TranslationUnit s -> IO (ClangString ())
unsafe_getTranslationUnitSpelling t = clang_getTranslationUnitSpelling (unTranslationUnit t) >>= peek

getTranslationUnitSpelling :: ClangBase m => TranslationUnit s' -> ClangT s m (ClangString s)
getTranslationUnitSpelling = registerClangString . unsafe_getTranslationUnitSpelling

-- CXTranslationUnit clang_createTranslationUnitFromSourceFile(
--                                          CXIndex CIdx,
--                                          const char *source_filename,
--                                          int num_clang_command_line_args,
--                                    const char * const *clang_command_line_args,
--                                          unsigned num_unsaved_files,
--                                          struct CXUnsavedFile *unsaved_files);
clang_createTranslationUnitFromSourceFile :: (Ptr ()) -> (CString) -> (Int) -> (Ptr CString) -> (Int) -> (Ptr ()) -> IO ((Ptr ()))
clang_createTranslationUnitFromSourceFile a1 a2 a3 a4 a5 a6 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  let {a4' = id a4} in 
  let {a5' = fromIntegral a5} in 
  let {a6' = id a6} in 
  clang_createTranslationUnitFromSourceFile'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1295 "src/Clang/Internal/FFI.chs" #-}

unsafe_createTranslationUnitFromSourceFile :: Index s -> String -> Int -> Ptr CString -> Int -> Ptr CUnsavedFile -> IO (TranslationUnit ())
unsafe_createTranslationUnitFromSourceFile i s nas as nufs ufs =
  withCString s (\sPtr -> do
     rPtr <- clang_createTranslationUnitFromSourceFile (unIndex i) sPtr nas as nufs (castPtr ufs)
     return (mkTranslationUnit rPtr))

createTranslationUnitFromSourceFile :: ClangBase m => Index s' -> String -> [String]
                                    -> DV.Vector UnsavedFile -> ClangT s m (TranslationUnit s)
createTranslationUnitFromSourceFile idx sf as ufs =
  registerTranslationUnit $
    withStringList as $ \asPtr asLen ->
      withUnsavedFiles ufs $ \ufsPtr ufsLen ->
        unsafe_createTranslationUnitFromSourceFile idx sf asLen asPtr ufsLen ufsPtr

-- CXTranslationUnit clang_createTranslationUnit(CXIndex,
--                                              const char *ast_filename);
clang_createTranslationUnit :: (Ptr ()) -> (CString) -> IO ((Ptr ()))
clang_createTranslationUnit a1 a2 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  clang_createTranslationUnit'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1312 "src/Clang/Internal/FFI.chs" #-}

unsafe_createTranslationUnit :: Index s -> String -> IO (TranslationUnit ())
unsafe_createTranslationUnit i s =
  withCString s (\strPtr -> do
   trPtr <- clang_createTranslationUnit (unIndex i) strPtr
   return (mkTranslationUnit trPtr))

createTranslationUnit :: ClangBase m => Index s' -> String -> ClangT s m (TranslationUnit s)
createTranslationUnit = (registerTranslationUnit .) . unsafe_createTranslationUnit

-- enum CXTranslationUnit_Flags {
--   CXTranslationUnit_None = 0x0,
--   CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
--   CXTranslationUnit_Incomplete = 0x02,
--   CXTranslationUnit_PrecompiledPreamble = 0x04,
--   CXTranslationUnit_CacheCompletionResults = 0x08,
--   CXTranslationUnit_ForSerialization = 0x10,
--   CXTranslationUnit_CXXChainedPCH = 0x20,
--   CXTranslationUnit_SkipFunctionBodies = 0x40,
--   CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
-- };

-- | Flags that control how a translation unit is parsed.
--
-- * 'DetailedPreprocessingRecordFlag': Used to indicate that the parser should construct a
--   "detailed" preprocessing record, including all macro definitions and instantiations.
--   Constructing a detailed preprocessing record requires more memory and time to parse,
--   since the information contained in the record is usually not retained. However, it can be
--   useful for applications that require more detailed information about the behavior of the
--   preprocessor.
--
-- * 'IncompleteFlag': Used to indicate that the translation unit is incomplete.
--   When a translation unit is considered "incomplete", semantic analysis that is typically
--   performed at the end of the translation unit will be suppressed. For example, this
--   suppresses the completion of tentative declarations in C and of instantiation of
--   implicitly-instantiation function templates in C++. This option is typically used when
--   parsing a header with the intent of producing a precompiled header.
--
-- * 'PrecompiledPreambleFlag': Used to indicate that the translation unit should be built
--   with an implicit precompiled header for the preamble. An implicit precompiled header is
--   used as an optimization when a particular translation unit is likely to be reparsed many
--   times when the sources aren't changing that often. In this case, an implicit precompiled
--   header will be built containing all of the initial includes at the top of the main file
--   (what we refer to as the "preamble" of the file). In subsequent parses, if the preamble
--   or the files in it have not changed, 'Clang.TranslationUnit.reparse' will re-use the
--   implicit precompiled header to improve parsing performance.
--
-- * 'CacheCompletionResultsFlag': Used to indicate that the translation unit should cache
--   some code-completion results with each reparse of the source file.
--   Caching of code-completion results is a performance optimization that introduces some
--   overhead to reparsing but improves the performance of code-completion operations.
--
-- * 'ForSerializationFlag': Used to indicate that the translation unit will be serialized
--   'Clang.TranslationUnit.save'. This option is typically used when parsing a header with
--   the intent of producing a precompiled header.
--
-- * 'CXXChainedPCHFlag': DEPRECATED: Enabled chained precompiled preambles in C++. Note:
--   this is a *temporary* option that is available only while we are testing C++ precompiled
--   preamble support. It is deprecated.
--
-- * 'SkipFunctionBodiesFlag': Used to indicate that function/method bodies should be skipped
--   while parsing. This option can be used to search for declarations/definitions while
--   ignoring the usages.
--
-- * 'IncludeBriefCommentsInCodeCompletionFlag': Used to indicate that brief documentation
--   comments should be included into the set of code completions returned from this
--   translation unit.
data TranslationUnitFlags = DefaultTranslationUnitFlags
                          | DetailedPreprocessingRecordFlag
                          | IncompleteFlag
                          | PrecompiledPreambleFlag
                          | CacheCompletionResultsFlag
                          | ForSerializationFlag
                          | ChainedPCHFlag
                          | SkipFunctionBodiesFlag
                          | IncludeBriefCommentsInCodeCompletionFlag
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum TranslationUnitFlags where
  succ DefaultTranslationUnitFlags = DetailedPreprocessingRecordFlag
  succ DetailedPreprocessingRecordFlag = IncompleteFlag
  succ IncompleteFlag = PrecompiledPreambleFlag
  succ PrecompiledPreambleFlag = CacheCompletionResultsFlag
  succ CacheCompletionResultsFlag = ForSerializationFlag
  succ ForSerializationFlag = ChainedPCHFlag
  succ ChainedPCHFlag = SkipFunctionBodiesFlag
  succ SkipFunctionBodiesFlag = IncludeBriefCommentsInCodeCompletionFlag
  succ IncludeBriefCommentsInCodeCompletionFlag = error "TranslationUnitFlags.succ: IncludeBriefCommentsInCodeCompletionFlag has no successor"

  pred DetailedPreprocessingRecordFlag = DefaultTranslationUnitFlags
  pred IncompleteFlag = DetailedPreprocessingRecordFlag
  pred PrecompiledPreambleFlag = IncompleteFlag
  pred CacheCompletionResultsFlag = PrecompiledPreambleFlag
  pred ForSerializationFlag = CacheCompletionResultsFlag
  pred ChainedPCHFlag = ForSerializationFlag
  pred SkipFunctionBodiesFlag = ChainedPCHFlag
  pred IncludeBriefCommentsInCodeCompletionFlag = SkipFunctionBodiesFlag
  pred DefaultTranslationUnitFlags = error "TranslationUnitFlags.pred: DefaultTranslationUnitFlags has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from IncludeBriefCommentsInCodeCompletionFlag

  fromEnum DefaultTranslationUnitFlags = 0
  fromEnum DetailedPreprocessingRecordFlag = 1
  fromEnum IncompleteFlag = 2
  fromEnum PrecompiledPreambleFlag = 4
  fromEnum CacheCompletionResultsFlag = 8
  fromEnum ForSerializationFlag = 16
  fromEnum ChainedPCHFlag = 32
  fromEnum SkipFunctionBodiesFlag = 64
  fromEnum IncludeBriefCommentsInCodeCompletionFlag = 128

  toEnum 0 = DefaultTranslationUnitFlags
  toEnum 1 = DetailedPreprocessingRecordFlag
  toEnum 2 = IncompleteFlag
  toEnum 4 = PrecompiledPreambleFlag
  toEnum 8 = CacheCompletionResultsFlag
  toEnum 16 = ForSerializationFlag
  toEnum 32 = ChainedPCHFlag
  toEnum 64 = SkipFunctionBodiesFlag
  toEnum 128 = IncludeBriefCommentsInCodeCompletionFlag
  toEnum unmatched = error ("TranslationUnitFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1391 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags TranslationUnitFlags where
  toBit DefaultTranslationUnitFlags              = 0x0
  toBit DetailedPreprocessingRecordFlag          = 0x01
  toBit IncompleteFlag                           = 0x02
  toBit PrecompiledPreambleFlag                  = 0x04
  toBit CacheCompletionResultsFlag               = 0x08
  toBit ForSerializationFlag                     = 0x10
  toBit ChainedPCHFlag                           = 0x20
  toBit SkipFunctionBodiesFlag                   = 0x40
  toBit IncludeBriefCommentsInCodeCompletionFlag = 0x80

-- unsigned clang_defaultEditingTranslationUnitOptions(void);
defaultEditingTranslationUnitOptions :: IO ((Int))
defaultEditingTranslationUnitOptions =
  defaultEditingTranslationUnitOptions'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1405 "src/Clang/Internal/FFI.chs" #-}


maybeTranslationUnit :: TranslationUnit s' -> Maybe (TranslationUnit s)
maybeTranslationUnit (TranslationUnit p) | p == nullPtr = Nothing
maybeTranslationUnit f                         = Just (unsafeCoerce f)

-- CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
--                                                     const char *source_filename,
--                                          const char * const *command_line_args,
--                                                       int num_command_line_args,
--                                             struct CXUnsavedFile *unsaved_files,
--                                                      unsigned num_unsaved_files,
--                                                             unsigned options);
clang_parseTranslationUnit :: (Ptr ()) -> (CString) -> (Ptr CString) -> (Int) -> (Ptr ()) -> (Int) -> (Int) -> IO ((Ptr ()))
clang_parseTranslationUnit a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  let {a3' = id a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = id a5} in 
  let {a6' = fromIntegral a6} in 
  let {a7' = fromIntegral a7} in 
  clang_parseTranslationUnit'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 1418 "src/Clang/Internal/FFI.chs" #-}

unsafe_parseTranslationUnit :: Index s -> CString -> Ptr CString -> Int -> Ptr CUnsavedFile -> Int -> Int -> IO (Maybe (TranslationUnit ()))
unsafe_parseTranslationUnit i s as nas ufs nufs o =
  clang_parseTranslationUnit (unIndex i) s as nas (castPtr ufs) nufs o >>= return . maybeTranslationUnit . mkTranslationUnit

parseTranslationUnit :: ClangBase m => Index s' -> Maybe String -> [String]
                     -> DV.Vector UnsavedFile -> Int -> ClangT s m (Maybe (TranslationUnit s))
parseTranslationUnit idx maySF as ufs opts = do
    mayTU <- liftIO $
      withMaybeCString maySF $ \cSF ->
        withStringList as $ \asPtr asLen ->
          withUnsavedFiles ufs $ \ufsPtr ufsLen ->
            unsafe_parseTranslationUnit idx cSF asPtr asLen ufsPtr ufsLen opts
    case mayTU of
      Just tu -> Just <$> registerTranslationUnit (return tu)
      Nothing -> return Nothing

withMaybeCString :: Maybe String -> (CString -> IO a) -> IO a
withMaybeCString (Just s) f = withCString s f
withMaybeCString Nothing  f = f nullPtr

withStringList :: [String] -> (Ptr CString -> Int -> IO a) -> IO a
withStringList [] f = f nullPtr 0
withStringList strs f = do
    let len = length strs
    allocaArray len $ \arr -> go arr len arr strs
  where
    go arr len _ [] = f arr len
    go arr len ptr (s : ss) = withCString s $ \cs -> do
      poke ptr cs
      go arr len (advancePtr ptr 1) ss

-- void clang_setClangResourcesPath(CXIndex CIdx, const char* path);
clang_setClangResourcesPath :: (Ptr ()) -> (CString) -> IO ()
clang_setClangResourcesPath a1 a2 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  clang_setClangResourcesPath'_ a1' a2' >>
  return ()

{-# LINE 1451 "src/Clang/Internal/FFI.chs" #-}

setClangResourcesPath :: Index s -> String -> IO ()
setClangResourcesPath i s =
  withCString s (\stringPtr -> clang_setClangResourcesPath (unIndex i) stringPtr)


-- enum CXSaveTranslationUnit_Flags {
--   CXSaveTranslationUnit_None = 0x0
-- };

-- | Flags that control how a translation unit is saved.
data SaveTranslationUnitFlags = DefaultSaveTranslationUnitFlags
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum SaveTranslationUnitFlags where
  succ DefaultSaveTranslationUnitFlags = error "SaveTranslationUnitFlags.succ: DefaultSaveTranslationUnitFlags has no successor"

  pred DefaultSaveTranslationUnitFlags = error "SaveTranslationUnitFlags.pred: DefaultSaveTranslationUnitFlags has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from DefaultSaveTranslationUnitFlags

  fromEnum DefaultSaveTranslationUnitFlags = 0

  toEnum 0 = DefaultSaveTranslationUnitFlags
  toEnum unmatched = error ("SaveTranslationUnitFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1465 "src/Clang/Internal/FFI.chs" #-}

instance BitFlags SaveTranslationUnitFlags where
  toBit DefaultSaveTranslationUnitFlags = 0x0

-- unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
clang_defaultSaveOptions :: (Ptr ()) -> IO ((Int))
clang_defaultSaveOptions a1 =
  let {a1' = id a1} in 
  clang_defaultSaveOptions'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1470 "src/Clang/Internal/FFI.chs" #-}

defaultSaveOptions :: TranslationUnit s -> IO Int
defaultSaveOptions t = clang_defaultSaveOptions (unTranslationUnit t)


-- int clang_saveTranslationUnit(CXTranslationUnit TU,
--                                              const char *FileName,
--                                              unsigned options);
clang_saveTranslationUnit :: (Ptr ()) -> (CString) -> (Int) -> IO ((Int))
clang_saveTranslationUnit a1 a2 a3 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  clang_saveTranslationUnit'_ a1' a2' a3' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1478 "src/Clang/Internal/FFI.chs" #-}

saveTranslationUnit :: TranslationUnit s -> String -> Int -> IO Bool
saveTranslationUnit t s i =
 withCString s (\sPtr -> do
   r <- clang_saveTranslationUnit (unTranslationUnit t) sPtr i
   return (toBool ((if (r /= 0) then 0 else 1) :: Int)))

-- enum CXReparse_Flags {
--   CXReparse_None = 0x0
-- };

-- | Flags that control how a translation unit is reparsed.
data ReparseFlags = DefaultReparseFlags
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum ReparseFlags where
  succ DefaultReparseFlags = error "ReparseFlags.succ: DefaultReparseFlags has no successor"

  pred DefaultReparseFlags = error "ReparseFlags.pred: DefaultReparseFlags has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from DefaultReparseFlags

  fromEnum DefaultReparseFlags = 0

  toEnum 0 = DefaultReparseFlags
  toEnum unmatched = error ("ReparseFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 1494 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags ReparseFlags where
  toBit DefaultReparseFlags = 0x0

-- unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
clang_defaultReparseOptions :: (Ptr ()) -> IO ((CUInt))
clang_defaultReparseOptions a1 =
  let {a1' = id a1} in 
  clang_defaultReparseOptions'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 1500 "src/Clang/Internal/FFI.chs" #-}

defaultReparseOptions :: TranslationUnit s -> IO Int
defaultReparseOptions t = clang_defaultReparseOptions (unTranslationUnit t) >>= return . fromIntegral

-- int clang_reparseTranslationUnit(CXTranslationUnit TU,
--                                                 unsigned num_unsaved_files,
--                                           struct CXUnsavedFile *unsaved_files,
--                                                 unsigned options);
clang_reparseTranslationUnit :: (Ptr ()) -> (Int) -> (Ptr ()) -> (Int) -> IO ((Bool))
clang_reparseTranslationUnit a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  let {a4' = fromIntegral a4} in 
  clang_reparseTranslationUnit'_ a1' a2' a3' a4' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 1508 "src/Clang/Internal/FFI.chs" #-}

unsafe_reparseTranslationUnit :: TranslationUnit s -> Ptr CUnsavedFile -> Int -> Int -> IO Bool
unsafe_reparseTranslationUnit t ufs nufs i =
  clang_reparseTranslationUnit (unTranslationUnit t) nufs (castPtr ufs) i

reparseTranslationUnit :: ClangBase m => TranslationUnit s' -> DV.Vector UnsavedFile -> Int
                       -> ClangT s m Bool
reparseTranslationUnit tu ufs opts = liftIO $
  withUnsavedFiles ufs $ \ufsPtr ufsLen ->
    unsafe_reparseTranslationUnit tu ufsPtr ufsLen opts


-- enum CXCursorKind {
--   /* Declarations */
--   /**
--    * \brief A declaration whose specific kind is not exposed via this
--    * interface.
--    *
--    * Unexposed declarations have the same operations as any other kind
--    * of declaration; one can extract their location information,
--    * spelling, find their definitions, etc. However, the specific kind
--    * of the declaration is not reported.
--    */
--   CXCursor_UnexposedDecl                 = 1,
--   /** \brief A C or C++ struct. */
--   CXCursor_StructDecl                    = 2,
--   /** \brief A C or C++ union. */
--   CXCursor_UnionDecl                     = 3,
--   /** \brief A C++ class. */
--   CXCursor_ClassDecl                     = 4,
--   /** \brief An enumeration. */
--   CXCursor_EnumDecl                      = 5,
--   /**
--    * \brief A field (in C) or non-static data member (in C++) in a
--    * struct, union, or C++ class.
--    */
--   CXCursor_FieldDecl                     = 6,
--   /** \brief An enumerator constant. */
--   CXCursor_EnumConstantDecl              = 7,
--   /** \brief A function. */
--   CXCursor_FunctionDecl                  = 8,
--   /** \brief A variable. */
--   CXCursor_VarDecl                       = 9,
--   /** \brief A function or method parameter. */
--   CXCursor_ParmDecl                      = 10,
--   /** \brief An Objective-C @interface. */
--   CXCursor_ObjCInterfaceDecl             = 11,
--   /** \brief An Objective-C @interface for a category. */
--   CXCursor_ObjCCategoryDecl              = 12,
--   /** \brief An Objective-C @protocol declaration. */
--   CXCursor_ObjCProtocolDecl              = 13,
--   /** \brief An Objective-C @property declaration. */
--   CXCursor_ObjCPropertyDecl              = 14,
--   /** \brief An Objective-C instance variable. */
--   CXCursor_ObjCIvarDecl                  = 15,
--   /** \brief An Objective-C instance method. */
--   CXCursor_ObjCInstanceMethodDecl        = 16,
--   /** \brief An Objective-C class method. */
--   CXCursor_ObjCClassMethodDecl           = 17,
--   /** \brief An Objective-C @implementation. */
--   CXCursor_ObjCImplementationDecl        = 18,
--   /** \brief An Objective-C @implementation for a category. */
--   CXCursor_ObjCCategoryImplDecl          = 19,
--   /** \brief A typedef */
--   CXCursor_TypedefDecl                   = 20,
--   /** \brief A C++ class method. */
--   CXCursor_CXXMethod                     = 21,
--   /** \brief A C++ namespace. */
--   CXCursor_Namespace                     = 22,
--   /** \brief A linkage specification, e.g. 'extern "C"'. */
--   CXCursor_LinkageSpec                   = 23,
--   /** \brief A C++ constructor. */
--   CXCursor_Constructor                   = 24,
--   /** \brief A C++ destructor. */
--   CXCursor_Destructor                    = 25,
--   /** \brief A C++ conversion function. */
--   CXCursor_ConversionFunction            = 26,
--   /** \brief A C++ template type parameter. */
--   CXCursor_TemplateTypeParameter         = 27,
--   /** \brief A C++ non-type template parameter. */
--   CXCursor_NonTypeTemplateParameter      = 28,
--   /** \brief A C++ template template parameter. */
--   CXCursor_TemplateTemplateParameter     = 29,
--   /** \brief A C++ function template. */
--   CXCursor_FunctionTemplate              = 30,
--   /** \brief A C++ class template. */
--   CXCursor_ClassTemplate                 = 31,
--   /** \brief A C++ class template partial specialization. */
--   CXCursor_ClassTemplatePartialSpecialization = 32,
--   /** \brief A C++ namespace alias declaration. */
--   CXCursor_NamespaceAlias                = 33,
--   /** \brief A C++ using directive. */
--   CXCursor_UsingDirective                = 34,
--   /** \brief A C++ using declaration. */
--   CXCursor_UsingDeclaration              = 35,
--   /** \brief A C++ alias declaration */
--   CXCursor_TypeAliasDecl                 = 36,
--   /** \brief An Objective-C @synthesize definition. */
--   CXCursor_ObjCSynthesizeDecl            = 37,
--   /** \brief An Objective-C @dynamic definition. */
--   CXCursor_ObjCDynamicDecl               = 38,
--   /** \brief An access specifier. */
--   CXCursor_CXXAccessSpecifier            = 39,

--   CXCursor_FirstDecl                     = CXCursor_UnexposedDecl,
--   CXCursor_LastDecl                      = CXCursor_CXXAccessSpecifier,

--   /* References */
--   CXCursor_FirstRef                      = 40, /* Decl references */
--   CXCursor_ObjCSuperClassRef             = 40,
--   CXCursor_ObjCProtocolRef               = 41,
--   CXCursor_ObjCClassRef                  = 42,
--   /**
--    * \brief A reference to a type declaration.
--    *
--    * A type reference occurs anywhere where a type is named but not
--    * declared. For example, given:
--    *
--    * \code
--    * typedef unsigned size_type;
--    * size_type size;
--    * \endcode
--    *
--    * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
--    * while the type of the variable "size" is referenced. The cursor
--    * referenced by the type of size is the typedef for size_type.
--    */
--   CXCursor_TypeRef                       = 43,
--   CXCursor_CXXBaseSpecifier              = 44,
--   /**
--    * \brief A reference to a class template, function template, template
--    * template parameter, or class template partial specialization.
--    */
--   CXCursor_TemplateRef                   = 45,
--   /**
--    * \brief A reference to a namespace or namespace alias.
--    */
--   CXCursor_NamespaceRef                  = 46,
--   /**
--    * \brief A reference to a member of a struct, union, or class that occurs in
--    * some non-expression context, e.g., a designated initializer.
--    */
--   CXCursor_MemberRef                     = 47,
--   /**
--    * \brief A reference to a labeled statement.
--    *
--    * This cursor kind is used to describe the jump to "start_over" in the
--    * goto statement in the following example:
--    *
--    * \code
--    *   start_over:
--    *     ++counter;
--    *
--    *     goto start_over;
--    * \endcode
--    *
--    * A label reference cursor refers to a label statement.
--    */
--   CXCursor_LabelRef                      = 48,

--   /**
--    * \brief A reference to a set of overloaded functions or function templates
--    * that has not yet been resolved to a specific function or function template.
--    *
--    * An overloaded declaration reference cursor occurs in C++ templates where
--    * a dependent name refers to a function. For example:
--    *
--    * \code
--    * template<typename T> void swap(T&, T&);
--    *
--    * struct X { ... };
--    * void swap(X&, X&);
--    *
--    * template<typename T>
--    * void reverse(T* first, T* last) {
--    *   while (first < last - 1) {
--    *     swap(*first, *--last);
--    *     ++first;
--    *   }
--    * }
--    *
--    * struct Y { };
--    * void swap(Y&, Y&);
--    * \endcode
--    *
--    * Here, the identifier "swap" is associated with an overloaded declaration
--    * reference. In the template definition, "swap" refers to either of the two
--    * "swap" functions declared above, so both results will be available. At
--    * instantiation time, "swap" may also refer to other functions found via
--    * argument-dependent lookup (e.g., the "swap" function at the end of the
--    * example).
--    *
--    * The functions \c clang_getNumOverloadedDecls() and
--    * \c clang_getOverloadedDecl() can be used to retrieve the definitions
--    * referenced by this cursor.
--    */
--   CXCursor_OverloadedDeclRef             = 49,

--   /*
--    * \brief A reference to a variable that occurs in some non-expression
--    * context, e.g., a C++ lambda capture list.
--    */
--   CXCursor_VariableRef                   = 50,

--   CXCursor_LastRef                       = CXCursor_VariableRef,

--   /* Error conditions */
--   CXCursor_FirstInvalid                  = 70,
--   CXCursor_InvalidFile                   = 70,
--   CXCursor_NoDeclFound                   = 71,
--   CXCursor_NotImplemented                = 72,
--   CXCursor_InvalidCode                   = 73,
--   CXCursor_LastInvalid                   = CXCursor_InvalidCode,

--   /* Expressions */
--   CXCursor_FirstExpr                     = 100,

--   /**
--    * \brief An expression whose specific kind is not exposed via this
--    * interface.
--    *
--    * Unexposed expressions have the same operations as any other kind
--    * of expression; one can extract their location information,
--    * spelling, children, etc. However, the specific kind of the
--    * expression is not reported.
--    */
--   CXCursor_UnexposedExpr                 = 100,

--   /**
--    * \brief An expression that refers to some value declaration, such
--    * as a function, varible, or enumerator.
--    */
--   CXCursor_DeclRefExpr                   = 101,

--   /**
--    * \brief An expression that refers to a member of a struct, union,
--    * class, Objective-C class, etc.
--    */
--   CXCursor_MemberRefExpr                 = 102,

--   /** \brief An expression that calls a function. */
--   CXCursor_CallExpr                      = 103,

--   /** \brief An expression that sends a message to an Objective-C
--    object or class. */
--   CXCursor_ObjCMessageExpr               = 104,

--   /** \brief An expression that represents a block literal. */
--   CXCursor_BlockExpr                     = 105,

--   /** \brief An integer literal.
--    */
--   CXCursor_IntegerLiteral                = 106,

--   /** \brief A floating point number literal.
--    */
--   CXCursor_FloatingLiteral               = 107,

--   /** \brief An imaginary number literal.
--    */
--   CXCursor_ImaginaryLiteral              = 108,

--   /** \brief A string literal.
--    */
--   CXCursor_StringLiteral                 = 109,

--   /** \brief A character literal.
--    */
--   CXCursor_CharacterLiteral              = 110,

--   /** \brief A parenthesized expression, e.g. "(1)".
--    *
--    * This AST node is only formed if full location information is requested.
--    */
--   CXCursor_ParenExpr                     = 111,

--   /** \brief This represents the unary-expression's (except sizeof and
--    * alignof).
--    */
--   CXCursor_UnaryOperator                 = 112,

--   /** \brief [C99 6.5.2.1] Array Subscripting.
--    */
--   CXCursor_ArraySubscriptExpr            = 113,

--   /** \brief A builtin binary operation expression such as "x + y" or
--    * "x <= y".
--    */
--   CXCursor_BinaryOperator                = 114,

--   /** \brief Compound assignment such as "+=".
--    */
--   CXCursor_CompoundAssignOperator        = 115,

--   /** \brief The ?: ternary operator.
--    */
--   CXCursor_ConditionalOperator           = 116,

--   /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
--    * (C++ [expr.cast]), which uses the syntax (Type)expr.
--    *
--    * For example: (int)f.
--    */
--   CXCursor_CStyleCastExpr                = 117,

--   /** \brief [C99 6.5.2.5]
--    */
--   CXCursor_CompoundLiteralExpr           = 118,

--   /** \brief Describes an C or C++ initializer list.
--    */
--   CXCursor_InitListExpr                  = 119,

--   /** \brief The GNU address of label extension, representing &&label.
--    */
--   CXCursor_AddrLabelExpr                 = 120,

--   /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
--    */
--   CXCursor_StmtExpr                      = 121,

--   /** \brief Represents a C1X generic selection.
--    */
--   CXCursor_GenericSelectionExpr          = 122,

--   /** \brief Implements the GNU __null extension, which is a name for a null
--    * pointer constant that has integral type (e.g., int or long) and is the same
--    * size and alignment as a pointer.
--    *
--    * The __null extension is typically only used by system headers, which define
--    * NULL as __null in C++ rather than using 0 (which is an integer that may not
--    * match the size of a pointer).
--    */
--   CXCursor_GNUNullExpr                   = 123,

--   /** \brief C++'s static_cast<> expression.
--    */
--   CXCursor_CXXStaticCastExpr             = 124,

--   /** \brief C++'s dynamic_cast<> expression.
--    */
--   CXCursor_CXXDynamicCastExpr            = 125,

--   /** \brief C++'s reinterpret_cast<> expression.
--    */
--   CXCursor_CXXReinterpretCastExpr        = 126,

--   /** \brief C++'s const_cast<> expression.
--    */
--   CXCursor_CXXConstCastExpr              = 127,

--   /** \brief Represents an explicit C++ type conversion that uses "functional"
--    * notion (C++ [expr.type.conv]).
--    *
--    * Example:
--    * \code
--    *   x = int(0.5);
--    * \endcode
--    */
--   CXCursor_CXXFunctionalCastExpr         = 128,

--   /** \brief A C++ typeid expression (C++ [expr.typeid]).
--    */
--   CXCursor_CXXTypeidExpr                 = 129,

--   /** \brief [C++ 2.13.5] C++ Boolean Literal.
--    */
--   CXCursor_CXXBoolLiteralExpr            = 130,

--   /** \brief [C++0x 2.14.7] C++ Pointer Literal.
--    */
--   CXCursor_CXXNullPtrLiteralExpr         = 131,

--   /** \brief Represents the "this" expression in C++
--    */
--   CXCursor_CXXThisExpr                   = 132,

--   /** \brief [C++ 15] C++ Throw Expression.
--    *
--    * This handles 'throw' and 'throw' assignment-expression. When
--    * assignment-expression isn't present, Op will be null.
--    */
--   CXCursor_CXXThrowExpr                  = 133,

--   /** \brief A new expression for memory allocation and constructor calls, e.g:
--    * "new CXXNewExpr(foo)".
--    */
--   CXCursor_CXXNewExpr                    = 134,

--   /** \brief A delete expression for memory deallocation and destructor calls,
--    * e.g. "delete[] pArray".
--    */
--   CXCursor_CXXDeleteExpr                 = 135,

--   /** \brief A unary expression.
--    */
--   CXCursor_UnaryExpr                     = 136,

--   /** \brief ObjCStringLiteral, used for Objective-C string literals i.e. "foo".
--    */
--   CXCursor_ObjCStringLiteral             = 137,

--   /** \brief ObjCEncodeExpr, used for in Objective-C.
--    */
--   CXCursor_ObjCEncodeExpr                = 138,

--   /** \brief ObjCSelectorExpr used for in Objective-C.
--    */
--   CXCursor_ObjCSelectorExpr              = 139,

--   /** \brief Objective-C's protocol expression.
--    */
--   CXCursor_ObjCProtocolExpr              = 140,

--   /** \brief An Objective-C "bridged" cast expression, which casts between
--    * Objective-C pointers and C pointers, transferring ownership in the process.
--    *
--    * \code
--    *   NSString *str = (__bridge_transfer NSString *)CFCreateString();
--    * \endcode
--    */
--   CXCursor_ObjCBridgedCastExpr           = 141,

--   /** \brief Represents a C++0x pack expansion that produces a sequence of
--    * expressions.
--    *
--    * A pack expansion expression contains a pattern (which itself is an
--    * expression) followed by an ellipsis. For example:
--    *
--    * \code
--    * template<typename F, typename ...Types>
--    * void forward(F f, Types &&...args) {
--    *  f(static_cast<Types&&>(args)...);
--    * }
--    * \endcode
--    */
--   CXCursor_PackExpansionExpr             = 142,

--   /** \brief Represents an expression that computes the length of a parameter
--    * pack.
--    *
--    * \code
--    * template<typename ...Types>
--    * struct count {
--    *   static const unsigned value = sizeof...(Types);
--    * };
--    * \endcode
--    */
--   CXCursor_SizeOfPackExpr                = 143,

--   /* \brief Represents a C++ lambda expression that produces a local function
--    * object.
--    *
--    * \code
--    * void abssort(float *x, unsigned N) {
--    *   std::sort(x, x + N,
--    *             [](float a, float b) {
--    *               return std::abs(a) < std::abs(b);
--    *             });
--    * }
--    * \endcode
--    */
--   CXCursor_LambdaExpr                    = 144,

--   /** \brief Objective-c Boolean Literal.
--    */
--   CXCursor_ObjCBoolLiteralExpr           = 145,

--   /** \brief Represents the "self" expression in a ObjC method.
--    */
--   CXCursor_ObjCSelfExpr                  = 146,

--   CXCursor_LastExpr                      = CXCursor_ObjCSelfExpr,

--   /* Statements */
--   CXCursor_FirstStmt                     = 200,
--   /**
--    * \brief A statement whose specific kind is not exposed via this
--    * interface.
--    *
--    * Unexposed statements have the same operations as any other kind of
--    * statement; one can extract their location information, spelling,
--    * children, etc. However, the specific kind of the statement is not
--    * reported.
--    */
--   CXCursor_UnexposedStmt                 = 200,

--   /** \brief A labelled statement in a function.
--    *
--    * This cursor kind is used to describe the "start_over:" label statement in
--    * the following example:
--    *
--    * \code
--    *   start_over:
--    *     ++counter;
--    * \endcode
--    *
--    */
--   CXCursor_LabelStmt                     = 201,

--   /** \brief A group of statements like { stmt stmt }.
--    *
--    * This cursor kind is used to describe compound statements, e.g. function
--    * bodies.
--    */
--   CXCursor_CompoundStmt                  = 202,

--   /** \brief A case statment.
--    */
--   CXCursor_CaseStmt                      = 203,

--   /** \brief A default statement.
--    */
--   CXCursor_DefaultStmt                   = 204,

--   /** \brief An if statement
--    */
--   CXCursor_IfStmt                        = 205,

--   /** \brief A switch statement.
--    */
--   CXCursor_SwitchStmt                    = 206,

--   /** \brief A while statement.
--    */
--   CXCursor_WhileStmt                     = 207,

--   /** \brief A do statement.
--    */
--   CXCursor_DoStmt                        = 208,

--   /** \brief A for statement.
--    */
--   CXCursor_ForStmt                       = 209,

--   /** \brief A goto statement.
--    */
--   CXCursor_GotoStmt                      = 210,

--   /** \brief An indirect goto statement.
--    */
--   CXCursor_IndirectGotoStmt              = 211,

--   /** \brief A continue statement.
--    */
--   CXCursor_ContinueStmt                  = 212,

--   /** \brief A break statement.
--    */
--   CXCursor_BreakStmt                     = 213,

--   /** \brief A return statement.
--    */
--   CXCursor_ReturnStmt                    = 214,

--   /** \brief A GNU inline assembly statement extension.
--    */
--   CXCursor_GCCAsmStmt                    = 215,
--   CXCursor_AsmStmt                       = CXCursor_GCCAsmStmt,

--   /** \brief Objective-C's overall @try-@catc-@finall statement.
--    */
--   CXCursor_ObjCAtTryStmt                 = 216,

--   /** \brief Objective-C's @catch statement.
--    */
--   CXCursor_ObjCAtCatchStmt               = 217,

--   /** \brief Objective-C's @finally statement.
--    */
--   CXCursor_ObjCAtFinallyStmt             = 218,

--   /** \brief Objective-C's @throw statement.
--    */
--   CXCursor_ObjCAtThrowStmt               = 219,

--   /** \brief Objective-C's @synchronized statement.
--    */
--   CXCursor_ObjCAtSynchronizedStmt        = 220,

--   /** \brief Objective-C's autorelease pool statement.
--    */
--   CXCursor_ObjCAutoreleasePoolStmt       = 221,

--   /** \brief Objective-C's collection statement.
--    */
--   CXCursor_ObjCForCollectionStmt         = 222,

--   /** \brief C++'s catch statement.
--    */
--   CXCursor_CXXCatchStmt                  = 223,

--   /** \brief C++'s try statement.
--    */
--   CXCursor_CXXTryStmt                    = 224,

--   /** \brief C++'s for (* : *) statement.
--    */
--   CXCursor_CXXForRangeStmt               = 225,

--   /** \brief Windows Structured Exception Handling's try statement.
--    */
--   CXCursor_SEHTryStmt                    = 226,

--   /** \brief Windows Structured Exception Handling's except statement.
--    */
--   CXCursor_SEHExceptStmt                 = 227,

--   /** \brief Windows Structured Exception Handling's finally statement.
--    */
--   CXCursor_SEHFinallyStmt                = 228,

--   /** \brief A MS inline assembly statement extension.
--    */
--   CXCursor_MSAsmStmt                     = 229,

--   /** \brief The null satement ";": C99 6.8.3p3.
--    *
--    * This cursor kind is used to describe the null statement.
--    */
--   CXCursor_NullStmt                      = 230,

--   /** \brief Adaptor class for mixing declarations with statements and
--    * expressions.
--    */
--   CXCursor_DeclStmt                      = 231,

--   /** \brief OpenMP parallel directive.
--    */
--   CXCursor_OMPParallelDirective          = 232,

--   CXCursor_LastStmt                      = CXCursor_OMPParallelDirective,

--   /**
--    * \brief Cursor that represents the translation unit itself.
--    *
--    * The translation unit cursor exists primarily to act as the root
--    * cursor for traversing the contents of a translation unit.
--    */
--   CXCursor_TranslationUnit               = 300,

--   /* Attributes */
--   CXCursor_FirstAttr                     = 400,
--   /**
--    * \brief An attribute whose specific kind is not exposed via this
--    * interface.
--    */
--   CXCursor_UnexposedAttr                 = 400,

--   CXCursor_IBActionAttr                  = 401,
--   CXCursor_IBOutletAttr                  = 402,
--   CXCursor_IBOutletCollectionAttr        = 403,
--   CXCursor_CXXFinalAttr                  = 404,
--   CXCursor_CXXOverrideAttr               = 405,
--   CXCursor_AnnotateAttr                  = 406,
--   CXCursor_AsmLabelAttr                  = 407,
--   CXCursor_PackedAttr                    = 408,
--   CXCursor_LastAttr                      = CXCursor_PackedAttr,

--   /* Preprocessing */
--   CXCursor_PreprocessingDirective        = 500,
--   CXCursor_MacroDefinition               = 501,
--   CXCursor_MacroExpansion                = 502,
--   CXCursor_MacroInstantiation            = CXCursor_MacroExpansion,
--   CXCursor_InclusionDirective            = 503,
--   CXCursor_FirstPreprocessing            = CXCursor_PreprocessingDirective,
--   CXCursor_LastPreprocessing             = CXCursor_InclusionDirective

--   /* Extra Declarations */
--   /**
--    * \brief A module import declaration.
--    */
--   CXCursor_ModuleImportDecl              = 600,
--   CXCursor_FirstExtraDecl                = CXCursor_ModuleImportDecl,
--   CXCursor_LastExtraDecl                 = CXCursor_ModuleImportDecl
-- };
data CursorKind = UnexposedDeclCursor
                | StructDeclCursor
                | UnionDeclCursor
                | ClassDeclCursor
                | EnumDeclCursor
                | FieldDeclCursor
                | EnumConstantDeclCursor
                | FunctionDeclCursor
                | VarDeclCursor
                | ParmDeclCursor
                | ObjCInterfaceDeclCursor
                | ObjCCategoryDeclCursor
                | ObjCProtocolDeclCursor
                | ObjCPropertyDeclCursor
                | ObjCIvarDeclCursor
                | ObjCInstanceMethodDeclCursor
                | ObjCClassMethodDeclCursor
                | ObjCImplementationDeclCursor
                | ObjCCategoryImplDeclCursor
                | TypedefDeclCursor
                | CXXMethodCursor
                | NamespaceCursor
                | LinkageSpecCursor
                | ConstructorCursor
                | DestructorCursor
                | ConversionFunctionCursor
                | TemplateTypeParameterCursor
                | NonTypeTemplateParameterCursor
                | TemplateTemplateParameterCursor
                | FunctionTemplateCursor
                | ClassTemplateCursor
                | ClassTemplatePartialSpecializationCursor
                | NamespaceAliasCursor
                | UsingDirectiveCursor
                | UsingDeclarationCursor
                | TypeAliasDeclCursor
                | ObjCSynthesizeDeclCursor
                | ObjCDynamicDeclCursor
                | CXXAccessSpecifierCursor
                | ObjCSuperClassRefCursor
                | ObjCProtocolRefCursor
                | ObjCClassRefCursor
                | TypeRefCursor
                | CXXBaseSpecifierCursor
                | TemplateRefCursor
                | NamespaceRefCursor
                | MemberRefCursor
                | LabelRefCursor
                | OverloadedDeclRefCursor
                | VariableRefCursor
                | InvalidFileCursor
                | NoDeclFoundCursor
                | NotImplementedCursor
                | InvalidCodeCursor
                | UnexposedExprCursor
                | DeclRefExprCursor
                | MemberRefExprCursor
                | CallExprCursor
                | ObjCMessageExprCursor
                | BlockExprCursor
                | IntegerLiteralCursor
                | FloatingLiteralCursor
                | ImaginaryLiteralCursor
                | StringLiteralCursor
                | CharacterLiteralCursor
                | ParenExprCursor
                | UnaryOperatorCursor
                | ArraySubscriptExprCursor
                | BinaryOperatorCursor
                | CompoundAssignOperatorCursor
                | ConditionalOperatorCursor
                | CStyleCastExprCursor
                | CompoundLiteralExprCursor
                | InitListExprCursor
                | AddrLabelExprCursor
                | StmtExprCursor
                | GenericSelectionExprCursor
                | GNUNullExprCursor
                | CXXStaticCastExprCursor
                | CXXDynamicCastExprCursor
                | CXXReinterpretCastExprCursor
                | CXXConstCastExprCursor
                | CXXFunctionalCastExprCursor
                | CXXTypeidExprCursor
                | CXXBoolLiteralExprCursor
                | CXXNullPtrLiteralExprCursor
                | CXXThisExprCursor
                | CXXThrowExprCursor
                | CXXNewExprCursor
                | CXXDeleteExprCursor
                | UnaryExprCursor
                | ObjCStringLiteralCursor
                | ObjCEncodeExprCursor
                | ObjCSelectorExprCursor
                | ObjCProtocolExprCursor
                | ObjCBridgedCastExprCursor
                | PackExpansionExprCursor
                | SizeOfPackExprCursor
                | LambdaExprCursor
                | ObjCBoolLiteralExprCursor
                | ObjCSelfExprCursor
                | UnexposedStmtCursor
                | LabelStmtCursor
                | CompoundStmtCursor
                | CaseStmtCursor
                | DefaultStmtCursor
                | IfStmtCursor
                | SwitchStmtCursor
                | WhileStmtCursor
                | DoStmtCursor
                | ForStmtCursor
                | GotoStmtCursor
                | IndirectGotoStmtCursor
                | ContinueStmtCursor
                | BreakStmtCursor
                | ReturnStmtCursor
                | AsmStmtCursor
                | ObjCAtTryStmtCursor
                | ObjCAtCatchStmtCursor
                | ObjCAtFinallyStmtCursor
                | ObjCAtThrowStmtCursor
                | ObjCAtSynchronizedStmtCursor
                | ObjCAutoreleasePoolStmtCursor
                | ObjCForCollectionStmtCursor
                | CXXCatchStmtCursor
                | CXXTryStmtCursor
                | CXXForRangeStmtCursor
                | SEHTryStmtCursor
                | SEHExceptStmtCursor
                | SEHFinallyStmtCursor
                | MSAsmStmtCursor
                | NullStmtCursor
                | DeclStmtCursor
                | OMPParallelDirectiveCursor
                | TranslationUnitCursor
                | UnexposedAttrCursor
                | IBActionAttrCursor
                | IBOutletAttrCursor
                | IBOutletCollectionAttrCursor
                | CXXFinalAttrCursor
                | CXXOverrideAttrCursor
                | AnnotateAttrCursor
                | AsmLabelAttrCursor
                | PackedAttrCursor
                | PreprocessingDirectiveCursor
                | MacroDefinitionCursor
                | MacroExpansionCursor
                | InclusionDirectiveCursor
                | ModuleImportDeclCursor
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CursorKind where
  succ UnexposedDeclCursor = StructDeclCursor
  succ StructDeclCursor = UnionDeclCursor
  succ UnionDeclCursor = ClassDeclCursor
  succ ClassDeclCursor = EnumDeclCursor
  succ EnumDeclCursor = FieldDeclCursor
  succ FieldDeclCursor = EnumConstantDeclCursor
  succ EnumConstantDeclCursor = FunctionDeclCursor
  succ FunctionDeclCursor = VarDeclCursor
  succ VarDeclCursor = ParmDeclCursor
  succ ParmDeclCursor = ObjCInterfaceDeclCursor
  succ ObjCInterfaceDeclCursor = ObjCCategoryDeclCursor
  succ ObjCCategoryDeclCursor = ObjCProtocolDeclCursor
  succ ObjCProtocolDeclCursor = ObjCPropertyDeclCursor
  succ ObjCPropertyDeclCursor = ObjCIvarDeclCursor
  succ ObjCIvarDeclCursor = ObjCInstanceMethodDeclCursor
  succ ObjCInstanceMethodDeclCursor = ObjCClassMethodDeclCursor
  succ ObjCClassMethodDeclCursor = ObjCImplementationDeclCursor
  succ ObjCImplementationDeclCursor = ObjCCategoryImplDeclCursor
  succ ObjCCategoryImplDeclCursor = TypedefDeclCursor
  succ TypedefDeclCursor = CXXMethodCursor
  succ CXXMethodCursor = NamespaceCursor
  succ NamespaceCursor = LinkageSpecCursor
  succ LinkageSpecCursor = ConstructorCursor
  succ ConstructorCursor = DestructorCursor
  succ DestructorCursor = ConversionFunctionCursor
  succ ConversionFunctionCursor = TemplateTypeParameterCursor
  succ TemplateTypeParameterCursor = NonTypeTemplateParameterCursor
  succ NonTypeTemplateParameterCursor = TemplateTemplateParameterCursor
  succ TemplateTemplateParameterCursor = FunctionTemplateCursor
  succ FunctionTemplateCursor = ClassTemplateCursor
  succ ClassTemplateCursor = ClassTemplatePartialSpecializationCursor
  succ ClassTemplatePartialSpecializationCursor = NamespaceAliasCursor
  succ NamespaceAliasCursor = UsingDirectiveCursor
  succ UsingDirectiveCursor = UsingDeclarationCursor
  succ UsingDeclarationCursor = TypeAliasDeclCursor
  succ TypeAliasDeclCursor = ObjCSynthesizeDeclCursor
  succ ObjCSynthesizeDeclCursor = ObjCDynamicDeclCursor
  succ ObjCDynamicDeclCursor = CXXAccessSpecifierCursor
  succ CXXAccessSpecifierCursor = ObjCSuperClassRefCursor
  succ ObjCSuperClassRefCursor = ObjCProtocolRefCursor
  succ ObjCProtocolRefCursor = ObjCClassRefCursor
  succ ObjCClassRefCursor = TypeRefCursor
  succ TypeRefCursor = CXXBaseSpecifierCursor
  succ CXXBaseSpecifierCursor = TemplateRefCursor
  succ TemplateRefCursor = NamespaceRefCursor
  succ NamespaceRefCursor = MemberRefCursor
  succ MemberRefCursor = LabelRefCursor
  succ LabelRefCursor = OverloadedDeclRefCursor
  succ OverloadedDeclRefCursor = VariableRefCursor
  succ VariableRefCursor = InvalidFileCursor
  succ InvalidFileCursor = NoDeclFoundCursor
  succ NoDeclFoundCursor = NotImplementedCursor
  succ NotImplementedCursor = InvalidCodeCursor
  succ InvalidCodeCursor = UnexposedExprCursor
  succ UnexposedExprCursor = DeclRefExprCursor
  succ DeclRefExprCursor = MemberRefExprCursor
  succ MemberRefExprCursor = CallExprCursor
  succ CallExprCursor = ObjCMessageExprCursor
  succ ObjCMessageExprCursor = BlockExprCursor
  succ BlockExprCursor = IntegerLiteralCursor
  succ IntegerLiteralCursor = FloatingLiteralCursor
  succ FloatingLiteralCursor = ImaginaryLiteralCursor
  succ ImaginaryLiteralCursor = StringLiteralCursor
  succ StringLiteralCursor = CharacterLiteralCursor
  succ CharacterLiteralCursor = ParenExprCursor
  succ ParenExprCursor = UnaryOperatorCursor
  succ UnaryOperatorCursor = ArraySubscriptExprCursor
  succ ArraySubscriptExprCursor = BinaryOperatorCursor
  succ BinaryOperatorCursor = CompoundAssignOperatorCursor
  succ CompoundAssignOperatorCursor = ConditionalOperatorCursor
  succ ConditionalOperatorCursor = CStyleCastExprCursor
  succ CStyleCastExprCursor = CompoundLiteralExprCursor
  succ CompoundLiteralExprCursor = InitListExprCursor
  succ InitListExprCursor = AddrLabelExprCursor
  succ AddrLabelExprCursor = StmtExprCursor
  succ StmtExprCursor = GenericSelectionExprCursor
  succ GenericSelectionExprCursor = GNUNullExprCursor
  succ GNUNullExprCursor = CXXStaticCastExprCursor
  succ CXXStaticCastExprCursor = CXXDynamicCastExprCursor
  succ CXXDynamicCastExprCursor = CXXReinterpretCastExprCursor
  succ CXXReinterpretCastExprCursor = CXXConstCastExprCursor
  succ CXXConstCastExprCursor = CXXFunctionalCastExprCursor
  succ CXXFunctionalCastExprCursor = CXXTypeidExprCursor
  succ CXXTypeidExprCursor = CXXBoolLiteralExprCursor
  succ CXXBoolLiteralExprCursor = CXXNullPtrLiteralExprCursor
  succ CXXNullPtrLiteralExprCursor = CXXThisExprCursor
  succ CXXThisExprCursor = CXXThrowExprCursor
  succ CXXThrowExprCursor = CXXNewExprCursor
  succ CXXNewExprCursor = CXXDeleteExprCursor
  succ CXXDeleteExprCursor = UnaryExprCursor
  succ UnaryExprCursor = ObjCStringLiteralCursor
  succ ObjCStringLiteralCursor = ObjCEncodeExprCursor
  succ ObjCEncodeExprCursor = ObjCSelectorExprCursor
  succ ObjCSelectorExprCursor = ObjCProtocolExprCursor
  succ ObjCProtocolExprCursor = ObjCBridgedCastExprCursor
  succ ObjCBridgedCastExprCursor = PackExpansionExprCursor
  succ PackExpansionExprCursor = SizeOfPackExprCursor
  succ SizeOfPackExprCursor = LambdaExprCursor
  succ LambdaExprCursor = ObjCBoolLiteralExprCursor
  succ ObjCBoolLiteralExprCursor = ObjCSelfExprCursor
  succ ObjCSelfExprCursor = UnexposedStmtCursor
  succ UnexposedStmtCursor = LabelStmtCursor
  succ LabelStmtCursor = CompoundStmtCursor
  succ CompoundStmtCursor = CaseStmtCursor
  succ CaseStmtCursor = DefaultStmtCursor
  succ DefaultStmtCursor = IfStmtCursor
  succ IfStmtCursor = SwitchStmtCursor
  succ SwitchStmtCursor = WhileStmtCursor
  succ WhileStmtCursor = DoStmtCursor
  succ DoStmtCursor = ForStmtCursor
  succ ForStmtCursor = GotoStmtCursor
  succ GotoStmtCursor = IndirectGotoStmtCursor
  succ IndirectGotoStmtCursor = ContinueStmtCursor
  succ ContinueStmtCursor = BreakStmtCursor
  succ BreakStmtCursor = ReturnStmtCursor
  succ ReturnStmtCursor = AsmStmtCursor
  succ AsmStmtCursor = ObjCAtTryStmtCursor
  succ ObjCAtTryStmtCursor = ObjCAtCatchStmtCursor
  succ ObjCAtCatchStmtCursor = ObjCAtFinallyStmtCursor
  succ ObjCAtFinallyStmtCursor = ObjCAtThrowStmtCursor
  succ ObjCAtThrowStmtCursor = ObjCAtSynchronizedStmtCursor
  succ ObjCAtSynchronizedStmtCursor = ObjCAutoreleasePoolStmtCursor
  succ ObjCAutoreleasePoolStmtCursor = ObjCForCollectionStmtCursor
  succ ObjCForCollectionStmtCursor = CXXCatchStmtCursor
  succ CXXCatchStmtCursor = CXXTryStmtCursor
  succ CXXTryStmtCursor = CXXForRangeStmtCursor
  succ CXXForRangeStmtCursor = SEHTryStmtCursor
  succ SEHTryStmtCursor = SEHExceptStmtCursor
  succ SEHExceptStmtCursor = SEHFinallyStmtCursor
  succ SEHFinallyStmtCursor = MSAsmStmtCursor
  succ MSAsmStmtCursor = NullStmtCursor
  succ NullStmtCursor = DeclStmtCursor
  succ DeclStmtCursor = OMPParallelDirectiveCursor
  succ OMPParallelDirectiveCursor = TranslationUnitCursor
  succ TranslationUnitCursor = UnexposedAttrCursor
  succ UnexposedAttrCursor = IBActionAttrCursor
  succ IBActionAttrCursor = IBOutletAttrCursor
  succ IBOutletAttrCursor = IBOutletCollectionAttrCursor
  succ IBOutletCollectionAttrCursor = CXXFinalAttrCursor
  succ CXXFinalAttrCursor = CXXOverrideAttrCursor
  succ CXXOverrideAttrCursor = AnnotateAttrCursor
  succ AnnotateAttrCursor = AsmLabelAttrCursor
  succ AsmLabelAttrCursor = PackedAttrCursor
  succ PackedAttrCursor = PreprocessingDirectiveCursor
  succ PreprocessingDirectiveCursor = MacroDefinitionCursor
  succ MacroDefinitionCursor = MacroExpansionCursor
  succ MacroExpansionCursor = InclusionDirectiveCursor
  succ InclusionDirectiveCursor = ModuleImportDeclCursor
  succ ModuleImportDeclCursor = error "CursorKind.succ: ModuleImportDeclCursor has no successor"

  pred StructDeclCursor = UnexposedDeclCursor
  pred UnionDeclCursor = StructDeclCursor
  pred ClassDeclCursor = UnionDeclCursor
  pred EnumDeclCursor = ClassDeclCursor
  pred FieldDeclCursor = EnumDeclCursor
  pred EnumConstantDeclCursor = FieldDeclCursor
  pred FunctionDeclCursor = EnumConstantDeclCursor
  pred VarDeclCursor = FunctionDeclCursor
  pred ParmDeclCursor = VarDeclCursor
  pred ObjCInterfaceDeclCursor = ParmDeclCursor
  pred ObjCCategoryDeclCursor = ObjCInterfaceDeclCursor
  pred ObjCProtocolDeclCursor = ObjCCategoryDeclCursor
  pred ObjCPropertyDeclCursor = ObjCProtocolDeclCursor
  pred ObjCIvarDeclCursor = ObjCPropertyDeclCursor
  pred ObjCInstanceMethodDeclCursor = ObjCIvarDeclCursor
  pred ObjCClassMethodDeclCursor = ObjCInstanceMethodDeclCursor
  pred ObjCImplementationDeclCursor = ObjCClassMethodDeclCursor
  pred ObjCCategoryImplDeclCursor = ObjCImplementationDeclCursor
  pred TypedefDeclCursor = ObjCCategoryImplDeclCursor
  pred CXXMethodCursor = TypedefDeclCursor
  pred NamespaceCursor = CXXMethodCursor
  pred LinkageSpecCursor = NamespaceCursor
  pred ConstructorCursor = LinkageSpecCursor
  pred DestructorCursor = ConstructorCursor
  pred ConversionFunctionCursor = DestructorCursor
  pred TemplateTypeParameterCursor = ConversionFunctionCursor
  pred NonTypeTemplateParameterCursor = TemplateTypeParameterCursor
  pred TemplateTemplateParameterCursor = NonTypeTemplateParameterCursor
  pred FunctionTemplateCursor = TemplateTemplateParameterCursor
  pred ClassTemplateCursor = FunctionTemplateCursor
  pred ClassTemplatePartialSpecializationCursor = ClassTemplateCursor
  pred NamespaceAliasCursor = ClassTemplatePartialSpecializationCursor
  pred UsingDirectiveCursor = NamespaceAliasCursor
  pred UsingDeclarationCursor = UsingDirectiveCursor
  pred TypeAliasDeclCursor = UsingDeclarationCursor
  pred ObjCSynthesizeDeclCursor = TypeAliasDeclCursor
  pred ObjCDynamicDeclCursor = ObjCSynthesizeDeclCursor
  pred CXXAccessSpecifierCursor = ObjCDynamicDeclCursor
  pred ObjCSuperClassRefCursor = CXXAccessSpecifierCursor
  pred ObjCProtocolRefCursor = ObjCSuperClassRefCursor
  pred ObjCClassRefCursor = ObjCProtocolRefCursor
  pred TypeRefCursor = ObjCClassRefCursor
  pred CXXBaseSpecifierCursor = TypeRefCursor
  pred TemplateRefCursor = CXXBaseSpecifierCursor
  pred NamespaceRefCursor = TemplateRefCursor
  pred MemberRefCursor = NamespaceRefCursor
  pred LabelRefCursor = MemberRefCursor
  pred OverloadedDeclRefCursor = LabelRefCursor
  pred VariableRefCursor = OverloadedDeclRefCursor
  pred InvalidFileCursor = VariableRefCursor
  pred NoDeclFoundCursor = InvalidFileCursor
  pred NotImplementedCursor = NoDeclFoundCursor
  pred InvalidCodeCursor = NotImplementedCursor
  pred UnexposedExprCursor = InvalidCodeCursor
  pred DeclRefExprCursor = UnexposedExprCursor
  pred MemberRefExprCursor = DeclRefExprCursor
  pred CallExprCursor = MemberRefExprCursor
  pred ObjCMessageExprCursor = CallExprCursor
  pred BlockExprCursor = ObjCMessageExprCursor
  pred IntegerLiteralCursor = BlockExprCursor
  pred FloatingLiteralCursor = IntegerLiteralCursor
  pred ImaginaryLiteralCursor = FloatingLiteralCursor
  pred StringLiteralCursor = ImaginaryLiteralCursor
  pred CharacterLiteralCursor = StringLiteralCursor
  pred ParenExprCursor = CharacterLiteralCursor
  pred UnaryOperatorCursor = ParenExprCursor
  pred ArraySubscriptExprCursor = UnaryOperatorCursor
  pred BinaryOperatorCursor = ArraySubscriptExprCursor
  pred CompoundAssignOperatorCursor = BinaryOperatorCursor
  pred ConditionalOperatorCursor = CompoundAssignOperatorCursor
  pred CStyleCastExprCursor = ConditionalOperatorCursor
  pred CompoundLiteralExprCursor = CStyleCastExprCursor
  pred InitListExprCursor = CompoundLiteralExprCursor
  pred AddrLabelExprCursor = InitListExprCursor
  pred StmtExprCursor = AddrLabelExprCursor
  pred GenericSelectionExprCursor = StmtExprCursor
  pred GNUNullExprCursor = GenericSelectionExprCursor
  pred CXXStaticCastExprCursor = GNUNullExprCursor
  pred CXXDynamicCastExprCursor = CXXStaticCastExprCursor
  pred CXXReinterpretCastExprCursor = CXXDynamicCastExprCursor
  pred CXXConstCastExprCursor = CXXReinterpretCastExprCursor
  pred CXXFunctionalCastExprCursor = CXXConstCastExprCursor
  pred CXXTypeidExprCursor = CXXFunctionalCastExprCursor
  pred CXXBoolLiteralExprCursor = CXXTypeidExprCursor
  pred CXXNullPtrLiteralExprCursor = CXXBoolLiteralExprCursor
  pred CXXThisExprCursor = CXXNullPtrLiteralExprCursor
  pred CXXThrowExprCursor = CXXThisExprCursor
  pred CXXNewExprCursor = CXXThrowExprCursor
  pred CXXDeleteExprCursor = CXXNewExprCursor
  pred UnaryExprCursor = CXXDeleteExprCursor
  pred ObjCStringLiteralCursor = UnaryExprCursor
  pred ObjCEncodeExprCursor = ObjCStringLiteralCursor
  pred ObjCSelectorExprCursor = ObjCEncodeExprCursor
  pred ObjCProtocolExprCursor = ObjCSelectorExprCursor
  pred ObjCBridgedCastExprCursor = ObjCProtocolExprCursor
  pred PackExpansionExprCursor = ObjCBridgedCastExprCursor
  pred SizeOfPackExprCursor = PackExpansionExprCursor
  pred LambdaExprCursor = SizeOfPackExprCursor
  pred ObjCBoolLiteralExprCursor = LambdaExprCursor
  pred ObjCSelfExprCursor = ObjCBoolLiteralExprCursor
  pred UnexposedStmtCursor = ObjCSelfExprCursor
  pred LabelStmtCursor = UnexposedStmtCursor
  pred CompoundStmtCursor = LabelStmtCursor
  pred CaseStmtCursor = CompoundStmtCursor
  pred DefaultStmtCursor = CaseStmtCursor
  pred IfStmtCursor = DefaultStmtCursor
  pred SwitchStmtCursor = IfStmtCursor
  pred WhileStmtCursor = SwitchStmtCursor
  pred DoStmtCursor = WhileStmtCursor
  pred ForStmtCursor = DoStmtCursor
  pred GotoStmtCursor = ForStmtCursor
  pred IndirectGotoStmtCursor = GotoStmtCursor
  pred ContinueStmtCursor = IndirectGotoStmtCursor
  pred BreakStmtCursor = ContinueStmtCursor
  pred ReturnStmtCursor = BreakStmtCursor
  pred AsmStmtCursor = ReturnStmtCursor
  pred ObjCAtTryStmtCursor = AsmStmtCursor
  pred ObjCAtCatchStmtCursor = ObjCAtTryStmtCursor
  pred ObjCAtFinallyStmtCursor = ObjCAtCatchStmtCursor
  pred ObjCAtThrowStmtCursor = ObjCAtFinallyStmtCursor
  pred ObjCAtSynchronizedStmtCursor = ObjCAtThrowStmtCursor
  pred ObjCAutoreleasePoolStmtCursor = ObjCAtSynchronizedStmtCursor
  pred ObjCForCollectionStmtCursor = ObjCAutoreleasePoolStmtCursor
  pred CXXCatchStmtCursor = ObjCForCollectionStmtCursor
  pred CXXTryStmtCursor = CXXCatchStmtCursor
  pred CXXForRangeStmtCursor = CXXTryStmtCursor
  pred SEHTryStmtCursor = CXXForRangeStmtCursor
  pred SEHExceptStmtCursor = SEHTryStmtCursor
  pred SEHFinallyStmtCursor = SEHExceptStmtCursor
  pred MSAsmStmtCursor = SEHFinallyStmtCursor
  pred NullStmtCursor = MSAsmStmtCursor
  pred DeclStmtCursor = NullStmtCursor
  pred OMPParallelDirectiveCursor = DeclStmtCursor
  pred TranslationUnitCursor = OMPParallelDirectiveCursor
  pred UnexposedAttrCursor = TranslationUnitCursor
  pred IBActionAttrCursor = UnexposedAttrCursor
  pred IBOutletAttrCursor = IBActionAttrCursor
  pred IBOutletCollectionAttrCursor = IBOutletAttrCursor
  pred CXXFinalAttrCursor = IBOutletCollectionAttrCursor
  pred CXXOverrideAttrCursor = CXXFinalAttrCursor
  pred AnnotateAttrCursor = CXXOverrideAttrCursor
  pred AsmLabelAttrCursor = AnnotateAttrCursor
  pred PackedAttrCursor = AsmLabelAttrCursor
  pred PreprocessingDirectiveCursor = PackedAttrCursor
  pred MacroDefinitionCursor = PreprocessingDirectiveCursor
  pred MacroExpansionCursor = MacroDefinitionCursor
  pred InclusionDirectiveCursor = MacroExpansionCursor
  pred ModuleImportDeclCursor = InclusionDirectiveCursor
  pred UnexposedDeclCursor = error "CursorKind.pred: UnexposedDeclCursor has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ModuleImportDeclCursor

  fromEnum UnexposedDeclCursor = 1
  fromEnum StructDeclCursor = 2
  fromEnum UnionDeclCursor = 3
  fromEnum ClassDeclCursor = 4
  fromEnum EnumDeclCursor = 5
  fromEnum FieldDeclCursor = 6
  fromEnum EnumConstantDeclCursor = 7
  fromEnum FunctionDeclCursor = 8
  fromEnum VarDeclCursor = 9
  fromEnum ParmDeclCursor = 10
  fromEnum ObjCInterfaceDeclCursor = 11
  fromEnum ObjCCategoryDeclCursor = 12
  fromEnum ObjCProtocolDeclCursor = 13
  fromEnum ObjCPropertyDeclCursor = 14
  fromEnum ObjCIvarDeclCursor = 15
  fromEnum ObjCInstanceMethodDeclCursor = 16
  fromEnum ObjCClassMethodDeclCursor = 17
  fromEnum ObjCImplementationDeclCursor = 18
  fromEnum ObjCCategoryImplDeclCursor = 19
  fromEnum TypedefDeclCursor = 20
  fromEnum CXXMethodCursor = 21
  fromEnum NamespaceCursor = 22
  fromEnum LinkageSpecCursor = 23
  fromEnum ConstructorCursor = 24
  fromEnum DestructorCursor = 25
  fromEnum ConversionFunctionCursor = 26
  fromEnum TemplateTypeParameterCursor = 27
  fromEnum NonTypeTemplateParameterCursor = 28
  fromEnum TemplateTemplateParameterCursor = 29
  fromEnum FunctionTemplateCursor = 30
  fromEnum ClassTemplateCursor = 31
  fromEnum ClassTemplatePartialSpecializationCursor = 32
  fromEnum NamespaceAliasCursor = 33
  fromEnum UsingDirectiveCursor = 34
  fromEnum UsingDeclarationCursor = 35
  fromEnum TypeAliasDeclCursor = 36
  fromEnum ObjCSynthesizeDeclCursor = 37
  fromEnum ObjCDynamicDeclCursor = 38
  fromEnum CXXAccessSpecifierCursor = 39
  fromEnum ObjCSuperClassRefCursor = 40
  fromEnum ObjCProtocolRefCursor = 41
  fromEnum ObjCClassRefCursor = 42
  fromEnum TypeRefCursor = 43
  fromEnum CXXBaseSpecifierCursor = 44
  fromEnum TemplateRefCursor = 45
  fromEnum NamespaceRefCursor = 46
  fromEnum MemberRefCursor = 47
  fromEnum LabelRefCursor = 48
  fromEnum OverloadedDeclRefCursor = 49
  fromEnum VariableRefCursor = 50
  fromEnum InvalidFileCursor = 70
  fromEnum NoDeclFoundCursor = 71
  fromEnum NotImplementedCursor = 72
  fromEnum InvalidCodeCursor = 73
  fromEnum UnexposedExprCursor = 100
  fromEnum DeclRefExprCursor = 101
  fromEnum MemberRefExprCursor = 102
  fromEnum CallExprCursor = 103
  fromEnum ObjCMessageExprCursor = 104
  fromEnum BlockExprCursor = 105
  fromEnum IntegerLiteralCursor = 106
  fromEnum FloatingLiteralCursor = 107
  fromEnum ImaginaryLiteralCursor = 108
  fromEnum StringLiteralCursor = 109
  fromEnum CharacterLiteralCursor = 110
  fromEnum ParenExprCursor = 111
  fromEnum UnaryOperatorCursor = 112
  fromEnum ArraySubscriptExprCursor = 113
  fromEnum BinaryOperatorCursor = 114
  fromEnum CompoundAssignOperatorCursor = 115
  fromEnum ConditionalOperatorCursor = 116
  fromEnum CStyleCastExprCursor = 117
  fromEnum CompoundLiteralExprCursor = 118
  fromEnum InitListExprCursor = 119
  fromEnum AddrLabelExprCursor = 120
  fromEnum StmtExprCursor = 121
  fromEnum GenericSelectionExprCursor = 122
  fromEnum GNUNullExprCursor = 123
  fromEnum CXXStaticCastExprCursor = 124
  fromEnum CXXDynamicCastExprCursor = 125
  fromEnum CXXReinterpretCastExprCursor = 126
  fromEnum CXXConstCastExprCursor = 127
  fromEnum CXXFunctionalCastExprCursor = 128
  fromEnum CXXTypeidExprCursor = 129
  fromEnum CXXBoolLiteralExprCursor = 130
  fromEnum CXXNullPtrLiteralExprCursor = 131
  fromEnum CXXThisExprCursor = 132
  fromEnum CXXThrowExprCursor = 133
  fromEnum CXXNewExprCursor = 134
  fromEnum CXXDeleteExprCursor = 135
  fromEnum UnaryExprCursor = 136
  fromEnum ObjCStringLiteralCursor = 137
  fromEnum ObjCEncodeExprCursor = 138
  fromEnum ObjCSelectorExprCursor = 139
  fromEnum ObjCProtocolExprCursor = 140
  fromEnum ObjCBridgedCastExprCursor = 141
  fromEnum PackExpansionExprCursor = 142
  fromEnum SizeOfPackExprCursor = 143
  fromEnum LambdaExprCursor = 144
  fromEnum ObjCBoolLiteralExprCursor = 145
  fromEnum ObjCSelfExprCursor = 146
  fromEnum UnexposedStmtCursor = 200
  fromEnum LabelStmtCursor = 201
  fromEnum CompoundStmtCursor = 202
  fromEnum CaseStmtCursor = 203
  fromEnum DefaultStmtCursor = 204
  fromEnum IfStmtCursor = 205
  fromEnum SwitchStmtCursor = 206
  fromEnum WhileStmtCursor = 207
  fromEnum DoStmtCursor = 208
  fromEnum ForStmtCursor = 209
  fromEnum GotoStmtCursor = 210
  fromEnum IndirectGotoStmtCursor = 211
  fromEnum ContinueStmtCursor = 212
  fromEnum BreakStmtCursor = 213
  fromEnum ReturnStmtCursor = 214
  fromEnum AsmStmtCursor = 215
  fromEnum ObjCAtTryStmtCursor = 216
  fromEnum ObjCAtCatchStmtCursor = 217
  fromEnum ObjCAtFinallyStmtCursor = 218
  fromEnum ObjCAtThrowStmtCursor = 219
  fromEnum ObjCAtSynchronizedStmtCursor = 220
  fromEnum ObjCAutoreleasePoolStmtCursor = 221
  fromEnum ObjCForCollectionStmtCursor = 222
  fromEnum CXXCatchStmtCursor = 223
  fromEnum CXXTryStmtCursor = 224
  fromEnum CXXForRangeStmtCursor = 225
  fromEnum SEHTryStmtCursor = 226
  fromEnum SEHExceptStmtCursor = 227
  fromEnum SEHFinallyStmtCursor = 228
  fromEnum MSAsmStmtCursor = 229
  fromEnum NullStmtCursor = 230
  fromEnum DeclStmtCursor = 231
  fromEnum OMPParallelDirectiveCursor = 232
  fromEnum TranslationUnitCursor = 300
  fromEnum UnexposedAttrCursor = 400
  fromEnum IBActionAttrCursor = 401
  fromEnum IBOutletAttrCursor = 402
  fromEnum IBOutletCollectionAttrCursor = 403
  fromEnum CXXFinalAttrCursor = 404
  fromEnum CXXOverrideAttrCursor = 405
  fromEnum AnnotateAttrCursor = 406
  fromEnum AsmLabelAttrCursor = 407
  fromEnum PackedAttrCursor = 408
  fromEnum PreprocessingDirectiveCursor = 500
  fromEnum MacroDefinitionCursor = 501
  fromEnum MacroExpansionCursor = 502
  fromEnum InclusionDirectiveCursor = 503
  fromEnum ModuleImportDeclCursor = 600

  toEnum 1 = UnexposedDeclCursor
  toEnum 2 = StructDeclCursor
  toEnum 3 = UnionDeclCursor
  toEnum 4 = ClassDeclCursor
  toEnum 5 = EnumDeclCursor
  toEnum 6 = FieldDeclCursor
  toEnum 7 = EnumConstantDeclCursor
  toEnum 8 = FunctionDeclCursor
  toEnum 9 = VarDeclCursor
  toEnum 10 = ParmDeclCursor
  toEnum 11 = ObjCInterfaceDeclCursor
  toEnum 12 = ObjCCategoryDeclCursor
  toEnum 13 = ObjCProtocolDeclCursor
  toEnum 14 = ObjCPropertyDeclCursor
  toEnum 15 = ObjCIvarDeclCursor
  toEnum 16 = ObjCInstanceMethodDeclCursor
  toEnum 17 = ObjCClassMethodDeclCursor
  toEnum 18 = ObjCImplementationDeclCursor
  toEnum 19 = ObjCCategoryImplDeclCursor
  toEnum 20 = TypedefDeclCursor
  toEnum 21 = CXXMethodCursor
  toEnum 22 = NamespaceCursor
  toEnum 23 = LinkageSpecCursor
  toEnum 24 = ConstructorCursor
  toEnum 25 = DestructorCursor
  toEnum 26 = ConversionFunctionCursor
  toEnum 27 = TemplateTypeParameterCursor
  toEnum 28 = NonTypeTemplateParameterCursor
  toEnum 29 = TemplateTemplateParameterCursor
  toEnum 30 = FunctionTemplateCursor
  toEnum 31 = ClassTemplateCursor
  toEnum 32 = ClassTemplatePartialSpecializationCursor
  toEnum 33 = NamespaceAliasCursor
  toEnum 34 = UsingDirectiveCursor
  toEnum 35 = UsingDeclarationCursor
  toEnum 36 = TypeAliasDeclCursor
  toEnum 37 = ObjCSynthesizeDeclCursor
  toEnum 38 = ObjCDynamicDeclCursor
  toEnum 39 = CXXAccessSpecifierCursor
  toEnum 40 = ObjCSuperClassRefCursor
  toEnum 41 = ObjCProtocolRefCursor
  toEnum 42 = ObjCClassRefCursor
  toEnum 43 = TypeRefCursor
  toEnum 44 = CXXBaseSpecifierCursor
  toEnum 45 = TemplateRefCursor
  toEnum 46 = NamespaceRefCursor
  toEnum 47 = MemberRefCursor
  toEnum 48 = LabelRefCursor
  toEnum 49 = OverloadedDeclRefCursor
  toEnum 50 = VariableRefCursor
  toEnum 70 = InvalidFileCursor
  toEnum 71 = NoDeclFoundCursor
  toEnum 72 = NotImplementedCursor
  toEnum 73 = InvalidCodeCursor
  toEnum 100 = UnexposedExprCursor
  toEnum 101 = DeclRefExprCursor
  toEnum 102 = MemberRefExprCursor
  toEnum 103 = CallExprCursor
  toEnum 104 = ObjCMessageExprCursor
  toEnum 105 = BlockExprCursor
  toEnum 106 = IntegerLiteralCursor
  toEnum 107 = FloatingLiteralCursor
  toEnum 108 = ImaginaryLiteralCursor
  toEnum 109 = StringLiteralCursor
  toEnum 110 = CharacterLiteralCursor
  toEnum 111 = ParenExprCursor
  toEnum 112 = UnaryOperatorCursor
  toEnum 113 = ArraySubscriptExprCursor
  toEnum 114 = BinaryOperatorCursor
  toEnum 115 = CompoundAssignOperatorCursor
  toEnum 116 = ConditionalOperatorCursor
  toEnum 117 = CStyleCastExprCursor
  toEnum 118 = CompoundLiteralExprCursor
  toEnum 119 = InitListExprCursor
  toEnum 120 = AddrLabelExprCursor
  toEnum 121 = StmtExprCursor
  toEnum 122 = GenericSelectionExprCursor
  toEnum 123 = GNUNullExprCursor
  toEnum 124 = CXXStaticCastExprCursor
  toEnum 125 = CXXDynamicCastExprCursor
  toEnum 126 = CXXReinterpretCastExprCursor
  toEnum 127 = CXXConstCastExprCursor
  toEnum 128 = CXXFunctionalCastExprCursor
  toEnum 129 = CXXTypeidExprCursor
  toEnum 130 = CXXBoolLiteralExprCursor
  toEnum 131 = CXXNullPtrLiteralExprCursor
  toEnum 132 = CXXThisExprCursor
  toEnum 133 = CXXThrowExprCursor
  toEnum 134 = CXXNewExprCursor
  toEnum 135 = CXXDeleteExprCursor
  toEnum 136 = UnaryExprCursor
  toEnum 137 = ObjCStringLiteralCursor
  toEnum 138 = ObjCEncodeExprCursor
  toEnum 139 = ObjCSelectorExprCursor
  toEnum 140 = ObjCProtocolExprCursor
  toEnum 141 = ObjCBridgedCastExprCursor
  toEnum 142 = PackExpansionExprCursor
  toEnum 143 = SizeOfPackExprCursor
  toEnum 144 = LambdaExprCursor
  toEnum 145 = ObjCBoolLiteralExprCursor
  toEnum 146 = ObjCSelfExprCursor
  toEnum 200 = UnexposedStmtCursor
  toEnum 201 = LabelStmtCursor
  toEnum 202 = CompoundStmtCursor
  toEnum 203 = CaseStmtCursor
  toEnum 204 = DefaultStmtCursor
  toEnum 205 = IfStmtCursor
  toEnum 206 = SwitchStmtCursor
  toEnum 207 = WhileStmtCursor
  toEnum 208 = DoStmtCursor
  toEnum 209 = ForStmtCursor
  toEnum 210 = GotoStmtCursor
  toEnum 211 = IndirectGotoStmtCursor
  toEnum 212 = ContinueStmtCursor
  toEnum 213 = BreakStmtCursor
  toEnum 214 = ReturnStmtCursor
  toEnum 215 = AsmStmtCursor
  toEnum 216 = ObjCAtTryStmtCursor
  toEnum 217 = ObjCAtCatchStmtCursor
  toEnum 218 = ObjCAtFinallyStmtCursor
  toEnum 219 = ObjCAtThrowStmtCursor
  toEnum 220 = ObjCAtSynchronizedStmtCursor
  toEnum 221 = ObjCAutoreleasePoolStmtCursor
  toEnum 222 = ObjCForCollectionStmtCursor
  toEnum 223 = CXXCatchStmtCursor
  toEnum 224 = CXXTryStmtCursor
  toEnum 225 = CXXForRangeStmtCursor
  toEnum 226 = SEHTryStmtCursor
  toEnum 227 = SEHExceptStmtCursor
  toEnum 228 = SEHFinallyStmtCursor
  toEnum 229 = MSAsmStmtCursor
  toEnum 230 = NullStmtCursor
  toEnum 231 = DeclStmtCursor
  toEnum 232 = OMPParallelDirectiveCursor
  toEnum 300 = TranslationUnitCursor
  toEnum 400 = UnexposedAttrCursor
  toEnum 401 = IBActionAttrCursor
  toEnum 402 = IBOutletAttrCursor
  toEnum 403 = IBOutletCollectionAttrCursor
  toEnum 404 = CXXFinalAttrCursor
  toEnum 405 = CXXOverrideAttrCursor
  toEnum 406 = AnnotateAttrCursor
  toEnum 407 = AsmLabelAttrCursor
  toEnum 408 = PackedAttrCursor
  toEnum 500 = PreprocessingDirectiveCursor
  toEnum 501 = MacroDefinitionCursor
  toEnum 502 = MacroExpansionCursor
  toEnum 503 = InclusionDirectiveCursor
  toEnum 600 = ModuleImportDeclCursor
  toEnum unmatched = error ("CursorKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 2336 "src/Clang/Internal/FFI.chs" #-}


-- CursorKind ranges.
firstDeclCursor, lastDeclCursor, firstRefCursor, lastRefCursor         :: CursorKind
firstInvalidCursor, lastInvalidCursor, firstExprCursor, lastExprCursor :: CursorKind
firstStmtCursor, lastStmtCursor, firstAttrCursor, lastAttrCursor       :: CursorKind
firstPreprocessingCursor, lastPreprocessingCursor                      :: CursorKind
firstExtraDeclCursor, lastExtraDeclCursor                              :: CursorKind

firstDeclCursor          = UnexposedDeclCursor
lastDeclCursor           = CXXAccessSpecifierCursor
firstRefCursor           = ObjCSuperClassRefCursor
lastRefCursor            = VariableRefCursor
firstInvalidCursor       = InvalidFileCursor
lastInvalidCursor        = InvalidCodeCursor
firstExprCursor          = UnexposedExprCursor
lastExprCursor           = ObjCSelfExprCursor
firstStmtCursor          = UnexposedStmtCursor
lastStmtCursor           = OMPParallelDirectiveCursor
firstAttrCursor          = UnexposedAttrCursor
lastAttrCursor           = PackedAttrCursor
firstPreprocessingCursor = PreprocessingDirectiveCursor
lastPreprocessingCursor  = InclusionDirectiveCursor
firstExtraDeclCursor     = ModuleImportDeclCursor
lastExtraDeclCursor      = ModuleImportDeclCursor

-- CursorKind aliases.
gccAsmStmtCursor, macroInstantiationCursor :: CursorKind
gccAsmStmtCursor         = AsmStmtCursor
macroInstantiationCursor = MacroExpansionCursor

-- typedef struct {
--   const void *ASTNode;
--   CXTranslationUnit TranslationUnit;
-- } CXComment;
data Comment s = Comment !(Ptr ()) !(Ptr ())
                 deriving (Eq, Ord, Typeable)

instance ClangValue Comment

instance Storable (Comment s) where
    sizeOf _ = sizeOfCXComment
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXComment
    {-# INLINE alignment #-}

    peek p = do
      astNode <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) p
      tu <- (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr ())}) p
      return $! Comment astNode tu
    {-# INLINE peek #-}

    poke p (Comment astNode tu)= do
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr ()))}) p astNode
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.Ptr ()))}) p tu
    {-# INLINE poke #-}

-- typedef struct {
--   enum CXCursorKind kind;
--   int xdata;
--   const void* data[3];
-- } CXCursor;
data Cursor s = Cursor !CursorKind !Int !(Ptr ()) !(Ptr ()) !(Ptr ())
                deriving (Ord, Typeable)

instance ClangValue Cursor

instance Storable (Cursor s) where
    sizeOf _ = sizeOfCXCursor
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXCursor
    {-# INLINE alignment #-}

    peek p = do
      cursorKind <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p
      xdata <- (\ptr -> do {C2HSImp.peekByteOff ptr 4 :: IO C2HSImp.CInt}) p
      cursorData <- (\ptr -> do {return $ ptr `C2HSImp.plusPtr` 8 :: IO (C2HSImp.Ptr (C2HSImp.Ptr ()))}) p >>= peekArray 3
      return $! Cursor (toEnum (fromIntegral cursorKind)) (fromIntegral xdata) (cursorData !! 0) (cursorData !! 1) (cursorData !! 2)
    {-# INLINE peek #-}

    poke p (Cursor kind xdata p0 p1 p2)= do
      ptrsArray <- mallocArray 3
      pokeArray ptrsArray [p0,p1,p2]
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CInt)}) p (fromIntegral (fromEnum kind))
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 4 (val :: C2HSImp.CInt)}) p (fromIntegral xdata)
      (\ptr val -> do {C2HSImp.copyArray (ptr `C2HSImp.plusPtr` 8) (val :: (C2HSImp.Ptr (C2HSImp.Ptr ()))) 3}) p (castPtr ptrsArray)
    {-# INLINE poke #-}

instance Eq (Cursor s) where
    (Cursor aK aXdata aP1 aP2 aP3) == (Cursor bK bXdata bP1 bP2 bP3) =
        (aK == bK) &&
        (aXdata == bXdata) &&
        (aP1 == bP1) &&
        (aP2' == bP2') &&
        (aP3 == bP3)
      where
        aP2' = if isDeclaration aK then intPtrToPtr 0 else aP2
        bP2' = if isDeclaration bK then intPtrToPtr 0 else bP2
    {-# INLINE (==) #-}

instance Hashable (Cursor s) where
    hashWithSalt salt (Cursor k _ p1 p2 _) =
      let p = if isExpression k || isStatement k then p2 else p1
          kindHash = hashWithSalt salt (fromEnum k)
          pAsInt = fromIntegral (ptrToIntPtr p) :: Int
      in hashWithSalt kindHash pAsInt
    {-# INLINE hash #-}

-- CXCursor clang_getNullCursor(void);
getNullCursor :: ClangBase m => ClangT s m (Cursor s)
getNullCursor =
  return $ Cursor InvalidFileCursor 0 (intPtrToPtr 0) (intPtrToPtr 0) (intPtrToPtr 0)
{-# INLINE getNullCursor #-}

-- CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
clang_getTranslationUnitCursor :: (Ptr ()) -> IO ((Ptr (Cursor s)))
clang_getTranslationUnitCursor a1 =
  let {a1' = id a1} in 
  clang_getTranslationUnitCursor'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2453 "src/Clang/Internal/FFI.chs" #-}

getTranslationUnitCursor :: Proxy s -> TranslationUnit s' -> IO (Cursor s)
getTranslationUnitCursor _ (TranslationUnit tPtr) = clang_getTranslationUnitCursor tPtr >>= peek

-- int clang_Cursor_isNull(CXCursor);
cursor_isNull :: Cursor s -> Bool
cursor_isNull (Cursor k xdata p1 p2 p3)
  | k == InvalidFileCursor &&
    xdata == 0 &&
    p1 == intPtrToPtr 0 &&
    p2 == intPtrToPtr 0 &&
    p3 == intPtrToPtr 0
      = True
  | otherwise
      = False
{-# INLINE cursor_isNull #-}

-- unsigned clang_hashCursor(CXCursor);
clang_hashCursor :: (Cursor a) -> IO ((Word32))
clang_hashCursor a1 =
  withVoided a1 $ \a1' -> 
  clang_hashCursor'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 2471 "src/Clang/Internal/FFI.chs" #-}

hashCursor :: Cursor s -> IO Word32
hashCursor c = clang_hashCursor c
{-# INLINEABLE hashCursor #-}

getCursorKind :: Cursor s -> CursorKind
getCursorKind (Cursor k _ _ _ _) = k
{-# INLINE getCursorKind #-}

-- unsigned clang_isDeclaration(enum CursorKind);
isDeclaration :: CursorKind -> Bool
isDeclaration k =
  (k >= firstDeclCursor && k <= lastDeclCursor) ||
  (k >= firstExtraDeclCursor && k <= lastExtraDeclCursor)
{-# INLINE isDeclaration #-}

-- unsigned clang_isReference(enum CursorKind);
isReference :: CursorKind -> Bool
isReference k =
  (k >= firstRefCursor && k <= lastRefCursor)
{-# INLINE isReference #-}

-- unsigned clang_isExpression(enum CursorKind);
isExpression :: CursorKind -> Bool
isExpression k =
  (k >= firstExprCursor && k <= lastExprCursor)
{-# INLINE isExpression #-}

-- unsigned clang_isStatement(enum CursorKind);
isStatement :: CursorKind -> Bool
isStatement k =
  (k >= firstStmtCursor && k <= lastStmtCursor)
{-# INLINE isStatement #-}

isAttribute :: CursorKind -> Bool
isAttribute k =
  (k >= firstAttrCursor && k <= lastAttrCursor)
{-# INLINE isAttribute #-}

-- unsigned clang_isInvalid(enum CursorKind);
isInvalid :: CursorKind -> Bool
isInvalid k =
  (k >= firstInvalidCursor && k <= lastInvalidCursor)
{-# INLINE isInvalid #-}

-- unsigned clang_isTranslationUnit(enum CursorKind);
isTranslationUnit :: CursorKind -> Bool
isTranslationUnit TranslationUnitCursor = True
isTranslationUnit _ = False
{-# INLINE isTranslationUnit #-}

-- unsigned clang_isPreprocessing(enum CursorKind);
isPreprocessing :: CursorKind -> Bool
isPreprocessing k =
  (k >= firstPreprocessingCursor && k <= lastPreprocessingCursor)
{-# INLINE isPreprocessing #-}

-- unsigned clang_isUnexposed(enum CursorKind);
isUnexposed :: CursorKind -> Bool
isUnexposed k =
  (k >= firstPreprocessingCursor && k <= lastPreprocessingCursor)
{-# INLINE isUnexposed #-}

-- enum CXLinkageKind {
--   CXLinkage_Invalid,
--   CXLinkage_NoLinkage,
--   CXLinkage_Internal,
--   CXLinkage_UniqueExternal,
--   CXLinkage_External
-- };
data LinkageKind = Linkage_Invalid
                 | Linkage_NoLinkage
                 | Linkage_Internal
                 | Linkage_UniqueExternal
                 | Linkage_External
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum LinkageKind where
  succ Linkage_Invalid = Linkage_NoLinkage
  succ Linkage_NoLinkage = Linkage_Internal
  succ Linkage_Internal = Linkage_UniqueExternal
  succ Linkage_UniqueExternal = Linkage_External
  succ Linkage_External = error "LinkageKind.succ: Linkage_External has no successor"

  pred Linkage_NoLinkage = Linkage_Invalid
  pred Linkage_Internal = Linkage_NoLinkage
  pred Linkage_UniqueExternal = Linkage_Internal
  pred Linkage_External = Linkage_UniqueExternal
  pred Linkage_Invalid = error "LinkageKind.pred: Linkage_Invalid has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from Linkage_External

  fromEnum Linkage_Invalid = 0
  fromEnum Linkage_NoLinkage = 1
  fromEnum Linkage_Internal = 2
  fromEnum Linkage_UniqueExternal = 3
  fromEnum Linkage_External = 4

  toEnum 0 = Linkage_Invalid
  toEnum 1 = Linkage_NoLinkage
  toEnum 2 = Linkage_Internal
  toEnum 3 = Linkage_UniqueExternal
  toEnum 4 = Linkage_External
  toEnum unmatched = error ("LinkageKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 2549 "src/Clang/Internal/FFI.chs" #-}


-- enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
clang_getCursorLinkage :: (Cursor a) -> IO ((Int))
clang_getCursorLinkage a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorLinkage'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 2552 "src/Clang/Internal/FFI.chs" #-}

getCursorLinkage :: Cursor s -> IO LinkageKind
getCursorLinkage c = clang_getCursorLinkage c >>= return . toEnum

-- enum CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor);
clang_getCursorAvailability :: (Cursor a) -> IO ((Int))
clang_getCursorAvailability a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorAvailability'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 2557 "src/Clang/Internal/FFI.chs" #-}

getCursorAvailability :: Cursor s -> IO AvailabilityKind
getCursorAvailability c = clang_getCursorAvailability c >>= return . toEnum

data PlatformAvailability = PlatformAvailability
  { availabilityPlatform      :: !B.ByteString
  , availabilityIntroduced    :: !Version
  , availabilityDeprecated    :: !Version
  , availabilityObsoleted     :: !Version
  , availabilityIsUnavailable :: !Bool
  , availabilityMessage       :: !B.ByteString
  } deriving (Eq, Ord, Typeable)

instance Storable PlatformAvailability where
  sizeOf _ = sizeOfCXPlatformAvailability
  {-# INLINE sizeOf #-}

  alignment _ = alignOfCXPlatformAvailability
  {-# INLINE alignment #-}

  peek p = do
    (ClangString platD platF) <- peekByteOff p offsetCXPlatformAvailabilityPlatform
    platform <- B.packCString =<< getCStringPtr platD platF

    introduced <- peekByteOff p offsetCXPlatformAvailabilityIntroduced
    deprecated <- peekByteOff p offsetCXPlatformAvailabilityDeprecated
    obsoleted <- peekByteOff p offsetCXPlatformAvailabilityObsoleted
    intUnavailable :: Int <- fromCInt <$> peekByteOff p offsetCXPlatformAvailabilityUnavailable

    (ClangString msgD msgF) <- peekByteOff p offsetCXPlatformAvailabilityMessage
    message <- B.packCString =<< getCStringPtr msgD msgF

    return $! PlatformAvailability platform introduced deprecated obsoleted
                                   (if intUnavailable == 0 then False else True)
                                   message
  {-# INLINE peek #-}

  -- Since we can't construct ClangStrings, we can't really poke these.
  poke _ _ = undefined
  {-# INLINE poke #-}

-- void clang_disposeCXPlatformAvailability(CXPlatformAvailability);
clang_disposeCXPlatformAvailability :: (Ptr ()) -> IO ()
clang_disposeCXPlatformAvailability a1 =
  let {a1' = id a1} in 
  clang_disposeCXPlatformAvailability'_ a1' >>
  return ()

{-# LINE 2599 "src/Clang/Internal/FFI.chs" #-}

disposeCXPlatformAvailability :: Ptr PlatformAvailability -> IO ()
disposeCXPlatformAvailability p = clang_disposeCXPlatformAvailability (castPtr p)

-- int clang_getCursorPlatformAvailability(CXCursor cursor,
--                                         int *always_deprecated,
--                                         CXString *deprecated_message,
--                                         int *always_unavailable,
--                                         CXString *unavailable_message,
--                                         CXPlatformAvailability *availability,
--                                         int availability_size);
clang_getCursorPlatformAvailability :: (Cursor a) -> (Ptr ()) -> (Ptr ()) -> (Ptr ()) -> (Int) -> IO ((Int), (CInt), (CInt))
clang_getCursorPlatformAvailability a1 a3 a5 a6 a7 =
  withVoided a1 $ \a1' -> 
  alloca $ \a2' -> 
  let {a3' = id a3} in 
  alloca $ \a4' -> 
  let {a5' = id a5} in 
  let {a6' = id a6} in 
  let {a7' = fromIntegral a7} in 
  clang_getCursorPlatformAvailability'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = fromIntegral res} in
  peek  a2'>>= \a2'' -> 
  peek  a4'>>= \a4'' -> 
  return (res', a2'', a4'')

{-# LINE 2610 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorPlatformAvailability :: Cursor s' -> Ptr PlatformAvailability -> Int -> IO (Bool, ClangString (), Bool, ClangString (), Int)
unsafe_getCursorPlatformAvailability c dest destLen =
 alloca (\(dMsgPtr :: (Ptr (ClangString ()))) ->
 alloca (\(uMsgPtr :: (Ptr (ClangString ()))) -> do
   (size, ad, au) <- clang_getCursorPlatformAvailability
                       c
                       (castPtr dMsgPtr)
                       (castPtr uMsgPtr)
                       (castPtr dest)
                       destLen
   dm <- peek dMsgPtr
   um <- peek uMsgPtr
   return (toBool ad, dm, toBool au, um, size)))

data PlatformAvailabilityInfo s = PlatformAvailabilityInfo
  { availabilityAlwaysDeprecated   :: !Bool
  , availabilityDeprecatedMessage  :: !(ClangString s)
  , availabilityAlwaysUnavailable  :: !Bool
  , availabilityUnavailableMessage :: !(ClangString s)
  , availabilityInfo               :: ![PlatformAvailability]
  } deriving (Eq, Ord, Typeable)

instance ClangValue PlatformAvailabilityInfo

getCursorPlatformAvailability :: ClangBase m => Cursor s'
                              -> ClangT s m (PlatformAvailabilityInfo s)
getCursorPlatformAvailability c = do
    (ad, dMsg, au, uMsg, infos) <-
      liftIO $ allocaArray maxPlatformAvailability $ \p -> do
        (ad, dMsg, au, uMsg, outSize) <-
          unsafe_getCursorPlatformAvailability c p maxPlatformAvailability
        let count = min outSize maxPlatformAvailability
        infos <- peekArray count p
        forM_ [0..(count - 1)] $ \idx -> do
          disposeCXPlatformAvailability (advancePtr p idx)
        return (ad, dMsg, au, uMsg, infos)
    dMsg' <- registerClangString $ return dMsg
    uMsg' <- registerClangString $ return uMsg
    return $ PlatformAvailabilityInfo ad dMsg' au uMsg' infos
  where
    maxPlatformAvailability = 32

-- enum CXLanguageKind {
--   CXLanguage_Invalid = 0,
--   CXLanguage_C,
--   CXLanguage_ObjC,
--   CXLanguage_CPlusPlus
-- };
data LanguageKind = Language_Invalid
                  | Language_C
                  | Language_ObjC
                  | Language_CPlusPlus
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum LanguageKind where
  succ Language_Invalid = Language_C
  succ Language_C = Language_ObjC
  succ Language_ObjC = Language_CPlusPlus
  succ Language_CPlusPlus = error "LanguageKind.succ: Language_CPlusPlus has no successor"

  pred Language_C = Language_Invalid
  pred Language_ObjC = Language_C
  pred Language_CPlusPlus = Language_ObjC
  pred Language_Invalid = error "LanguageKind.pred: Language_Invalid has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from Language_CPlusPlus

  fromEnum Language_Invalid = 0
  fromEnum Language_C = 1
  fromEnum Language_ObjC = 2
  fromEnum Language_CPlusPlus = 3

  toEnum 0 = Language_Invalid
  toEnum 1 = Language_C
  toEnum 2 = Language_ObjC
  toEnum 3 = Language_CPlusPlus
  toEnum unmatched = error ("LanguageKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 2667 "src/Clang/Internal/FFI.chs" #-}


-- enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
clang_getCursorLanguage :: (Cursor a) -> IO ((Int))
clang_getCursorLanguage a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorLanguage'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 2670 "src/Clang/Internal/FFI.chs" #-}

getCursorLanguage :: Cursor s -> IO LanguageKind
getCursorLanguage c = clang_getCursorLanguage c >>= return . toEnum

-- CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
clang_Cursor_getTranslationUnit :: (Cursor a) -> IO ((Ptr ()))
clang_Cursor_getTranslationUnit a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getTranslationUnit'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 2675 "src/Clang/Internal/FFI.chs" #-}

unsafe_Cursor_getTranslationUnit :: Cursor s -> IO (TranslationUnit ())
unsafe_Cursor_getTranslationUnit c =
  clang_Cursor_getTranslationUnit c >>= return . mkTranslationUnit

-- Note that we do not register the translation unit! This function
-- never creates a 'new' translation unit, so we don't need to dispose
-- it. Moreover, since translation units aren't reference counted doing
-- so will lead to crashes.
cursor_getTranslationUnit :: ClangBase m => Cursor s' -> ClangT s m (TranslationUnit s)
cursor_getTranslationUnit c = liftIO $ unsafeCoerce <$> unsafe_Cursor_getTranslationUnit c

-- typedef struct CXCursorSetImpl *CXCursorSet;
newtype CursorSet s = CursorSet { unCursorSet :: Ptr () }
                      deriving (Eq, Ord, Typeable)

instance ClangValue CursorSet

-- void clang_disposeCXCursorSet(CXCursorSet cset);
clang_disposeCXCursorSet :: (Ptr ()) -> IO ()
clang_disposeCXCursorSet a1 =
  let {a1' = id a1} in 
  clang_disposeCXCursorSet'_ a1' >>
  return ()

{-# LINE 2694 "src/Clang/Internal/FFI.chs" #-}

disposeCXCursorSet :: CursorSet s -> IO ()
disposeCXCursorSet cs = clang_disposeCXCursorSet (unCursorSet cs)

registerCursorSet :: ClangBase m => IO (CursorSet ()) -> ClangT s m (CursorSet s)
registerCursorSet action = do
  (_, idx) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\i -> disposeCXCursorSet i)
  return idx
{-# INLINEABLE registerCursorSet #-}

-- CXCursorSet clang_createCXCursorSet();
clang_createCXCursorSet :: IO ((Ptr ()))
clang_createCXCursorSet =
  clang_createCXCursorSet'_ >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 2706 "src/Clang/Internal/FFI.chs" #-}

unsafe_createCXCursorSet :: IO (CursorSet ())
unsafe_createCXCursorSet = clang_createCXCursorSet >>= return . CursorSet

createCXCursorSet :: ClangBase m => ClangT s m (CursorSet s)
createCXCursorSet = registerCursorSet unsafe_createCXCursorSet

-- unsigned clang_CXCursorSet_contains(CXCursorSet cset, CXCursor cursor);
clang_CXCursorSet_contains :: (Ptr ()) -> (Cursor a) -> IO ((Bool))
clang_CXCursorSet_contains a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_CXCursorSet_contains'_ a1' a2' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 2714 "src/Clang/Internal/FFI.chs" #-}

cXCursorSet_contains :: CursorSet s -> Cursor s' -> IO Bool
cXCursorSet_contains cs c =
  clang_CXCursorSet_contains (unCursorSet cs) c

-- unsigned clang_CXCursorSet_insert(CXCursorSet cset, CXCursor cursor);
clang_CXCursorSet_insert :: (Ptr ()) -> (Cursor a) -> IO ((Bool))
clang_CXCursorSet_insert a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_CXCursorSet_insert'_ a1' a2' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 2720 "src/Clang/Internal/FFI.chs" #-}

cXCursorSet_insert :: CursorSet s -> Cursor s' -> IO Bool
cXCursorSet_insert cs c =
  clang_CXCursorSet_insert (unCursorSet cs) c

-- CXCursor clang_getCursorSemanticParent(CXCursor cursor);
clang_getCursorSemanticParent :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getCursorSemanticParent a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorSemanticParent'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2726 "src/Clang/Internal/FFI.chs" #-}

getCursorSemanticParent :: Proxy s -> Cursor s' -> IO (Cursor s)
getCursorSemanticParent _ c =
  clang_getCursorSemanticParent c >>= peek

-- CXCursor clang_getCursorLexicalParent(CXCursor cursor);
clang_getCursorLexicalParent :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getCursorLexicalParent a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorLexicalParent'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2732 "src/Clang/Internal/FFI.chs" #-}

getCursorLexicalParent :: Proxy s -> Cursor s' -> IO (Cursor s)
getCursorLexicalParent _ c =
  clang_getCursorLexicalParent c >>= peek

-- void clang_disposeOverriddenCursors(CXCursor *overridden);
clang_disposeOverriddenCursors :: (Ptr ()) -> IO ()
clang_disposeOverriddenCursors a1 =
  let {a1' = id a1} in 
  clang_disposeOverriddenCursors'_ a1' >>
  return ()

{-# LINE 2738 "src/Clang/Internal/FFI.chs" #-}

disposeOverridden :: CursorList s -> IO ()
disposeOverridden cl =
 let (csPtr, _) = fromCursorList cl in
 clang_disposeOverriddenCursors csPtr

registerOverriddenList :: ClangBase m => IO UnsafeCursorList -> ClangT s m (CursorList s)
registerOverriddenList action = do
    (_, cursorList) <- clangAllocate (action >>= cursorListToVector) disposeOverridden
    return cursorList
{-# INLINEABLE registerOverriddenList #-}

-- void clang_getOverriddenCursors(CXCursor cursor, CXCursor **overridden, unsigned *num_overridden);
clang_getOverriddenCursors :: (Cursor a) -> (Ptr (Ptr ())) -> IO ((CUInt))
clang_getOverriddenCursors a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  clang_getOverriddenCursors'_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 2751 "src/Clang/Internal/FFI.chs" #-}

unsafe_getOverriddenCursors :: Cursor s -> IO UnsafeCursorList
unsafe_getOverriddenCursors c = do
  cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr (Cursor s)))))
  n <- clang_getOverriddenCursors c (castPtr cxListPtr)
  free cxListPtr
  return (toCursorList (cxListPtr, (fromIntegral n)))

getOverriddenCursors :: ClangBase m => Cursor s' -> ClangT s m (CursorList s)
getOverriddenCursors = registerOverriddenList . unsafe_getOverriddenCursors

-- CXFile clang_getIncludedFile(CXCursor cursor);
clang_getIncludedFile :: (Cursor a) -> IO ((Ptr ()))
clang_getIncludedFile a1 =
  withVoided a1 $ \a1' -> 
  clang_getIncludedFile'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 2763 "src/Clang/Internal/FFI.chs" #-}

getIncludedFile :: Proxy s -> Cursor s' -> IO (Maybe (File s))
getIncludedFile _ c =
  clang_getIncludedFile c >>= return . maybeFile . File . castPtr

-- CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
clang_getCursor :: (Ptr ()) -> (SourceLocation a) -> IO ((Ptr (Cursor s)))
clang_getCursor a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_getCursor'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2769 "src/Clang/Internal/FFI.chs" #-}

getCursor :: Proxy s -> TranslationUnit s' -> SourceLocation s'' -> IO (Cursor s)
getCursor _ t s = clang_getCursor (unTranslationUnit t) s >>= peek

-- CXSourceLocation clang_getCursorLocation(CXCursor);
clang_getCursorLocation :: (Cursor a) -> IO ((Ptr (SourceLocation s)))
clang_getCursorLocation a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorLocation'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2774 "src/Clang/Internal/FFI.chs" #-}

getCursorLocation :: Proxy s -> Cursor s' -> IO (SourceLocation s)
getCursorLocation _ c =
  clang_getCursorLocation c>>= peek
{-# INLINEABLE getCursorLocation #-}

-- Variant of clang_getCursorLocation that fuses a call to clang_getSpellingLocation.
getCursorSpellingLocation :: Proxy s -> Cursor s' -> IO (Maybe (File s), Int, Int, Int)
getCursorSpellingLocation _ c =
  allocaBytes 8 (\ptrToFilePtr ->
  alloca (\(linePtr :: (Ptr CUInt)) ->
  alloca (\(columnPtr :: (Ptr CUInt)) ->
  alloca (\(offsetPtr :: (Ptr CUInt)) -> do
    slPtr <- clang_getCursorLocation c
    peek slPtr >>= \sl -> clang_getSpellingLocation sl ptrToFilePtr linePtr columnPtr offsetPtr
    filePtr <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) ptrToFilePtr
    let _maybeFile = maybeFile (File filePtr)
    line <- peek linePtr
    column <- peek columnPtr
    offset <- peek offsetPtr
    return (_maybeFile, fromIntegral line, fromIntegral column, fromIntegral offset)))))
{-# INLINEABLE getCursorSpellingLocation #-}

-- CXSourceRange clang_getCursorExtent(CXCursor);
clang_getCursorExtent :: (Cursor a) -> IO ((Ptr (SourceRange s)))
clang_getCursorExtent a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorExtent'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2798 "src/Clang/Internal/FFI.chs" #-}

getCursorExtent :: Proxy s -> Cursor s' -> IO (SourceRange s)
getCursorExtent _ c =
  clang_getCursorExtent c >>= peek
{-# INLINEABLE getCursorExtent #-}

-- enum CXTypeKind {
--   CXType_Invalid = 0,
--   CXType_Unexposed = 1,
--   CXType_Void = 2,
--   CXType_Bool = 3,
--   CXType_Char_U = 4,
--   CXType_UChar = 5,
--   CXType_Char16 = 6,
--   CXType_Char32 = 7,
--   CXType_UShort = 8,
--   CXType_UInt = 9,
--   CXType_ULong = 10,
--   CXType_ULongLong = 11,
--   CXType_UInt128 = 12,
--   CXType_Char_S = 13,
--   CXType_SChar = 14,
--   CXType_WChar = 15,
--   CXType_Short = 16,
--   CXType_Int = 17,
--   CXType_Long = 18,
--   CXType_LongLong = 19,
--   CXType_Int128 = 20,
--   CXType_Float = 21,
--   CXType_Double = 22,
--   CXType_LongDouble = 23,
--   CXType_NullPtr = 24,
--   CXType_Overload = 25,
--   CXType_Dependent = 26,
--   CXType_ObjCId = 27,
--   CXType_ObjCClass = 28,
--   CXType_ObjCSel = 29,
--   CXType_FirstBuiltin = CXType_Void,
--   CXType_LastBuiltin  = CXType_ObjCSel,
--   CXType_Complex = 100,
--   CXType_Pointer = 101,
--   CXType_BlockPointer = 102,
--   CXType_LValueReference = 103,
--   CXType_RValueReference = 104,
--   CXType_Record = 105,
--   CXType_Enum = 106,
--   CXType_Typedef = 107,
--   CXType_ObjCInterface = 108,
--   CXType_ObjCObjectPointer = 109,
--   CXType_FunctionNoProto = 110,
--   CXType_FunctionProto = 111
--   CXType_ConstantArray = 112
--   CXType_Vector = 113,
--   CXType_IncompleteArray = 114,
--   CXType_VariableArray = 115,
--   CXType_DependentSizedArray = 116,
--   CXType_MemberPointer = 117
-- };

data TypeKind = Type_Invalid
              | Type_Unexposed
              | Type_Void
              | Type_Bool
              | Type_Char_U
              | Type_UChar
              | Type_Char16
              | Type_Char32
              | Type_UShort
              | Type_UInt
              | Type_ULong
              | Type_ULongLong
              | Type_UInt128
              | Type_Char_S
              | Type_SChar
              | Type_WChar
              | Type_Short
              | Type_Int
              | Type_Long
              | Type_LongLong
              | Type_Int128
              | Type_Float
              | Type_Double
              | Type_LongDouble
              | Type_NullPtr
              | Type_Overload
              | Type_Dependent
              | Type_ObjCId
              | Type_ObjCClass
              | Type_ObjCSel
              | Type_Complex
              | Type_Pointer
              | Type_BlockPointer
              | Type_LValueReference
              | Type_RValueReference
              | Type_Record
              | Type_Enum
              | Type_Typedef
              | Type_ObjCInterface
              | Type_ObjCObjectPointer
              | Type_FunctionNoProto
              | Type_FunctionProto
              | Type_ConstantArray
              | Type_Vector
              | Type_IncompleteArray
              | Type_VariableArray
              | Type_DependentSizedArray
              | Type_MemberPointer
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum TypeKind where
  succ Type_Invalid = Type_Unexposed
  succ Type_Unexposed = Type_Void
  succ Type_Void = Type_Bool
  succ Type_Bool = Type_Char_U
  succ Type_Char_U = Type_UChar
  succ Type_UChar = Type_Char16
  succ Type_Char16 = Type_Char32
  succ Type_Char32 = Type_UShort
  succ Type_UShort = Type_UInt
  succ Type_UInt = Type_ULong
  succ Type_ULong = Type_ULongLong
  succ Type_ULongLong = Type_UInt128
  succ Type_UInt128 = Type_Char_S
  succ Type_Char_S = Type_SChar
  succ Type_SChar = Type_WChar
  succ Type_WChar = Type_Short
  succ Type_Short = Type_Int
  succ Type_Int = Type_Long
  succ Type_Long = Type_LongLong
  succ Type_LongLong = Type_Int128
  succ Type_Int128 = Type_Float
  succ Type_Float = Type_Double
  succ Type_Double = Type_LongDouble
  succ Type_LongDouble = Type_NullPtr
  succ Type_NullPtr = Type_Overload
  succ Type_Overload = Type_Dependent
  succ Type_Dependent = Type_ObjCId
  succ Type_ObjCId = Type_ObjCClass
  succ Type_ObjCClass = Type_ObjCSel
  succ Type_ObjCSel = Type_Complex
  succ Type_Complex = Type_Pointer
  succ Type_Pointer = Type_BlockPointer
  succ Type_BlockPointer = Type_LValueReference
  succ Type_LValueReference = Type_RValueReference
  succ Type_RValueReference = Type_Record
  succ Type_Record = Type_Enum
  succ Type_Enum = Type_Typedef
  succ Type_Typedef = Type_ObjCInterface
  succ Type_ObjCInterface = Type_ObjCObjectPointer
  succ Type_ObjCObjectPointer = Type_FunctionNoProto
  succ Type_FunctionNoProto = Type_FunctionProto
  succ Type_FunctionProto = Type_ConstantArray
  succ Type_ConstantArray = Type_Vector
  succ Type_Vector = Type_IncompleteArray
  succ Type_IncompleteArray = Type_VariableArray
  succ Type_VariableArray = Type_DependentSizedArray
  succ Type_DependentSizedArray = Type_MemberPointer
  succ Type_MemberPointer = error "TypeKind.succ: Type_MemberPointer has no successor"

  pred Type_Unexposed = Type_Invalid
  pred Type_Void = Type_Unexposed
  pred Type_Bool = Type_Void
  pred Type_Char_U = Type_Bool
  pred Type_UChar = Type_Char_U
  pred Type_Char16 = Type_UChar
  pred Type_Char32 = Type_Char16
  pred Type_UShort = Type_Char32
  pred Type_UInt = Type_UShort
  pred Type_ULong = Type_UInt
  pred Type_ULongLong = Type_ULong
  pred Type_UInt128 = Type_ULongLong
  pred Type_Char_S = Type_UInt128
  pred Type_SChar = Type_Char_S
  pred Type_WChar = Type_SChar
  pred Type_Short = Type_WChar
  pred Type_Int = Type_Short
  pred Type_Long = Type_Int
  pred Type_LongLong = Type_Long
  pred Type_Int128 = Type_LongLong
  pred Type_Float = Type_Int128
  pred Type_Double = Type_Float
  pred Type_LongDouble = Type_Double
  pred Type_NullPtr = Type_LongDouble
  pred Type_Overload = Type_NullPtr
  pred Type_Dependent = Type_Overload
  pred Type_ObjCId = Type_Dependent
  pred Type_ObjCClass = Type_ObjCId
  pred Type_ObjCSel = Type_ObjCClass
  pred Type_Complex = Type_ObjCSel
  pred Type_Pointer = Type_Complex
  pred Type_BlockPointer = Type_Pointer
  pred Type_LValueReference = Type_BlockPointer
  pred Type_RValueReference = Type_LValueReference
  pred Type_Record = Type_RValueReference
  pred Type_Enum = Type_Record
  pred Type_Typedef = Type_Enum
  pred Type_ObjCInterface = Type_Typedef
  pred Type_ObjCObjectPointer = Type_ObjCInterface
  pred Type_FunctionNoProto = Type_ObjCObjectPointer
  pred Type_FunctionProto = Type_FunctionNoProto
  pred Type_ConstantArray = Type_FunctionProto
  pred Type_Vector = Type_ConstantArray
  pred Type_IncompleteArray = Type_Vector
  pred Type_VariableArray = Type_IncompleteArray
  pred Type_DependentSizedArray = Type_VariableArray
  pred Type_MemberPointer = Type_DependentSizedArray
  pred Type_Invalid = error "TypeKind.pred: Type_Invalid has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from Type_MemberPointer

  fromEnum Type_Invalid = 0
  fromEnum Type_Unexposed = 1
  fromEnum Type_Void = 2
  fromEnum Type_Bool = 3
  fromEnum Type_Char_U = 4
  fromEnum Type_UChar = 5
  fromEnum Type_Char16 = 6
  fromEnum Type_Char32 = 7
  fromEnum Type_UShort = 8
  fromEnum Type_UInt = 9
  fromEnum Type_ULong = 10
  fromEnum Type_ULongLong = 11
  fromEnum Type_UInt128 = 12
  fromEnum Type_Char_S = 13
  fromEnum Type_SChar = 14
  fromEnum Type_WChar = 15
  fromEnum Type_Short = 16
  fromEnum Type_Int = 17
  fromEnum Type_Long = 18
  fromEnum Type_LongLong = 19
  fromEnum Type_Int128 = 20
  fromEnum Type_Float = 21
  fromEnum Type_Double = 22
  fromEnum Type_LongDouble = 23
  fromEnum Type_NullPtr = 24
  fromEnum Type_Overload = 25
  fromEnum Type_Dependent = 26
  fromEnum Type_ObjCId = 27
  fromEnum Type_ObjCClass = 28
  fromEnum Type_ObjCSel = 29
  fromEnum Type_Complex = 100
  fromEnum Type_Pointer = 101
  fromEnum Type_BlockPointer = 102
  fromEnum Type_LValueReference = 103
  fromEnum Type_RValueReference = 104
  fromEnum Type_Record = 105
  fromEnum Type_Enum = 106
  fromEnum Type_Typedef = 107
  fromEnum Type_ObjCInterface = 108
  fromEnum Type_ObjCObjectPointer = 109
  fromEnum Type_FunctionNoProto = 110
  fromEnum Type_FunctionProto = 111
  fromEnum Type_ConstantArray = 112
  fromEnum Type_Vector = 113
  fromEnum Type_IncompleteArray = 114
  fromEnum Type_VariableArray = 115
  fromEnum Type_DependentSizedArray = 116
  fromEnum Type_MemberPointer = 117

  toEnum 0 = Type_Invalid
  toEnum 1 = Type_Unexposed
  toEnum 2 = Type_Void
  toEnum 3 = Type_Bool
  toEnum 4 = Type_Char_U
  toEnum 5 = Type_UChar
  toEnum 6 = Type_Char16
  toEnum 7 = Type_Char32
  toEnum 8 = Type_UShort
  toEnum 9 = Type_UInt
  toEnum 10 = Type_ULong
  toEnum 11 = Type_ULongLong
  toEnum 12 = Type_UInt128
  toEnum 13 = Type_Char_S
  toEnum 14 = Type_SChar
  toEnum 15 = Type_WChar
  toEnum 16 = Type_Short
  toEnum 17 = Type_Int
  toEnum 18 = Type_Long
  toEnum 19 = Type_LongLong
  toEnum 20 = Type_Int128
  toEnum 21 = Type_Float
  toEnum 22 = Type_Double
  toEnum 23 = Type_LongDouble
  toEnum 24 = Type_NullPtr
  toEnum 25 = Type_Overload
  toEnum 26 = Type_Dependent
  toEnum 27 = Type_ObjCId
  toEnum 28 = Type_ObjCClass
  toEnum 29 = Type_ObjCSel
  toEnum 100 = Type_Complex
  toEnum 101 = Type_Pointer
  toEnum 102 = Type_BlockPointer
  toEnum 103 = Type_LValueReference
  toEnum 104 = Type_RValueReference
  toEnum 105 = Type_Record
  toEnum 106 = Type_Enum
  toEnum 107 = Type_Typedef
  toEnum 108 = Type_ObjCInterface
  toEnum 109 = Type_ObjCObjectPointer
  toEnum 110 = Type_FunctionNoProto
  toEnum 111 = Type_FunctionProto
  toEnum 112 = Type_ConstantArray
  toEnum 113 = Type_Vector
  toEnum 114 = Type_IncompleteArray
  toEnum 115 = Type_VariableArray
  toEnum 116 = Type_DependentSizedArray
  toEnum 117 = Type_MemberPointer
  toEnum unmatched = error ("TypeKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 2908 "src/Clang/Internal/FFI.chs" #-}


type_FirstBuiltin, type_LastBuiltin :: TypeKind
type_FirstBuiltin = Type_Void
type_LastBuiltin  = Type_ObjCSel

-- enum CXCallingConv {
--   CXCallingConv_Default = 0,
--   CXCallingConv_C = 1,
--   CXCallingConv_X86StdCall = 2,
--   CXCallingConv_X86FastCall = 3,
--   CXCallingConv_X86ThisCall = 4,
--   CXCallingConv_X86Pascal = 5,
--   CXCallingConv_AAPCS = 6,
--   CXCallingConv_AAPCS_VFP = 7,
--   CXCallingConv_PnaclCall = 8,
--   CXCallingConv_IntelOclBicc = 9,
--   CXCallingConv_X86_64Win64 = 10,
--   CXCallingConv_X86_64SysV = 11,
--   CXCallingConv_Invalid = 100,
--   CXCallingConv_Unexposed = 200
-- };
data CallingConv = CallingConv_Default
                 | CallingConv_C
                 | CallingConv_X86StdCall
                 | CallingConv_X86FastCall
                 | CallingConv_X86ThisCall
                 | CallingConv_X86Pascal
                 | CallingConv_AAPCS
                 | CallingConv_AAPCS_VFP
                 | CallingConv_PnaclCall
                 | CallingConv_IntelOclBic
                 | CallingConv_X86_64Win64
                 | CallingConv_X86_64SysV
                 | CallingConv_Invalid
                 | CallingConv_Unexposed
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CallingConv where
  succ CallingConv_Default = CallingConv_C
  succ CallingConv_C = CallingConv_X86StdCall
  succ CallingConv_X86StdCall = CallingConv_X86FastCall
  succ CallingConv_X86FastCall = CallingConv_X86ThisCall
  succ CallingConv_X86ThisCall = CallingConv_X86Pascal
  succ CallingConv_X86Pascal = CallingConv_AAPCS
  succ CallingConv_AAPCS = CallingConv_AAPCS_VFP
  succ CallingConv_AAPCS_VFP = CallingConv_PnaclCall
  succ CallingConv_PnaclCall = CallingConv_IntelOclBic
  succ CallingConv_IntelOclBic = CallingConv_X86_64Win64
  succ CallingConv_X86_64Win64 = CallingConv_X86_64SysV
  succ CallingConv_X86_64SysV = CallingConv_Invalid
  succ CallingConv_Invalid = CallingConv_Unexposed
  succ CallingConv_Unexposed = error "CallingConv.succ: CallingConv_Unexposed has no successor"

  pred CallingConv_C = CallingConv_Default
  pred CallingConv_X86StdCall = CallingConv_C
  pred CallingConv_X86FastCall = CallingConv_X86StdCall
  pred CallingConv_X86ThisCall = CallingConv_X86FastCall
  pred CallingConv_X86Pascal = CallingConv_X86ThisCall
  pred CallingConv_AAPCS = CallingConv_X86Pascal
  pred CallingConv_AAPCS_VFP = CallingConv_AAPCS
  pred CallingConv_PnaclCall = CallingConv_AAPCS_VFP
  pred CallingConv_IntelOclBic = CallingConv_PnaclCall
  pred CallingConv_X86_64Win64 = CallingConv_IntelOclBic
  pred CallingConv_X86_64SysV = CallingConv_X86_64Win64
  pred CallingConv_Invalid = CallingConv_X86_64SysV
  pred CallingConv_Unexposed = CallingConv_Invalid
  pred CallingConv_Default = error "CallingConv.pred: CallingConv_Default has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from CallingConv_Unexposed

  fromEnum CallingConv_Default = 0
  fromEnum CallingConv_C = 1
  fromEnum CallingConv_X86StdCall = 2
  fromEnum CallingConv_X86FastCall = 3
  fromEnum CallingConv_X86ThisCall = 4
  fromEnum CallingConv_X86Pascal = 5
  fromEnum CallingConv_AAPCS = 6
  fromEnum CallingConv_AAPCS_VFP = 7
  fromEnum CallingConv_PnaclCall = 8
  fromEnum CallingConv_IntelOclBic = 9
  fromEnum CallingConv_X86_64Win64 = 10
  fromEnum CallingConv_X86_64SysV = 11
  fromEnum CallingConv_Invalid = 100
  fromEnum CallingConv_Unexposed = 200

  toEnum 0 = CallingConv_Default
  toEnum 1 = CallingConv_C
  toEnum 2 = CallingConv_X86StdCall
  toEnum 3 = CallingConv_X86FastCall
  toEnum 4 = CallingConv_X86ThisCall
  toEnum 5 = CallingConv_X86Pascal
  toEnum 6 = CallingConv_AAPCS
  toEnum 7 = CallingConv_AAPCS_VFP
  toEnum 8 = CallingConv_PnaclCall
  toEnum 9 = CallingConv_IntelOclBic
  toEnum 10 = CallingConv_X86_64Win64
  toEnum 11 = CallingConv_X86_64SysV
  toEnum 100 = CallingConv_Invalid
  toEnum 200 = CallingConv_Unexposed
  toEnum unmatched = error ("CallingConv.toEnum: Cannot match " ++ show unmatched)

{-# LINE 2947 "src/Clang/Internal/FFI.chs" #-}


-- typedef struct {
--   enum CXTypeKind kind;
--   void *data[2];
-- } CXType;
data Type s = Type !TypeKind !(Ptr ()) !(Ptr ())
              deriving (Eq, Ord, Typeable)

instance ClangValue Type

instance Storable (Type s) where
    sizeOf _ = 24
{-# LINE 2959 "src/Clang/Internal/FFI.chs" #-}

    {-# INLINE sizeOf #-}

    alignment _ = 8
{-# LINE 2962 "src/Clang/Internal/FFI.chs" #-}

    {-# INLINE alignment #-}

    peek p = do
      kindCInt <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p
      ptrsArray <- (\ptr -> do {return $ ptr `C2HSImp.plusPtr` 8 :: IO (C2HSImp.Ptr (C2HSImp.Ptr ()))}) p >>= peekArray 2
      return $! Type (toEnum (fromIntegral kindCInt)) (ptrsArray !! 0) (ptrsArray !! 1)
    {-# INLINE peek #-}

    poke p (Type kind p0 p1)= do
      ptrsArray <- mallocArray 2
      pokeArray ptrsArray [p0,p1]
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CInt)}) p (fromIntegral (fromEnum kind))
      (\ptr val -> do {C2HSImp.copyArray (ptr `C2HSImp.plusPtr` 8) (val :: (C2HSImp.Ptr (C2HSImp.Ptr ()))) 2}) p (castPtr ptrsArray)
    {-# INLINE poke #-}

getTypeKind :: Type s -> TypeKind
getTypeKind (Type k _ _) = k

-- CXType clang_getCursorType(CXCursor C);
clang_getCursorType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_getCursorType a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2982 "src/Clang/Internal/FFI.chs" #-}

getCursorType :: Proxy s -> Cursor s' -> IO (Type s)
getCursorType proxy c =
  clang_getCursorType c >>= peek

-- CXString clang_getTypeSpelling(CXType CT);
clang_getTypeSpelling :: (Type a) -> IO ((Ptr (ClangString ())))
clang_getTypeSpelling a1 =
  withVoided a1 $ \a1' -> 
  clang_getTypeSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2988 "src/Clang/Internal/FFI.chs" #-}

unsafe_getTypeSpelling :: (Type s) -> IO (ClangString ())
unsafe_getTypeSpelling t = do
 cxString <- clang_getTypeSpelling t
 peek cxString

getTypeSpelling :: ClangBase m => (Type s') -> ClangT s m (ClangString s)
getTypeSpelling = registerClangString . unsafe_getTypeSpelling

-- CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
clang_getTypedefDeclUnderlyingType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_getTypedefDeclUnderlyingType a1 =
  withVoided a1 $ \a1' -> 
  clang_getTypedefDeclUnderlyingType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 2998 "src/Clang/Internal/FFI.chs" #-}

getTypedefDeclUnderlyingType :: Proxy s -> Cursor s' -> IO (Type s)
getTypedefDeclUnderlyingType proxy c =
  clang_getTypedefDeclUnderlyingType c >>= peek

-- CXType clang_getEnumDeclIntegerType(CXCursor C);
clang_getEnumDeclIntegerType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_getEnumDeclIntegerType a1 =
  withVoided a1 $ \a1' -> 
  clang_getEnumDeclIntegerType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3004 "src/Clang/Internal/FFI.chs" #-}

getEnumDeclIntegerType :: Proxy s -> Cursor s' -> IO (Type s)
getEnumDeclIntegerType proxy c =
  clang_getEnumDeclIntegerType c >>= peek

-- long long clang_getEnumConstantDeclValue(CXCursor);
clang_getEnumConstantDeclValue :: (Cursor a) -> IO ((Int64))
clang_getEnumConstantDeclValue a1 =
  withVoided a1 $ \a1' -> 
  clang_getEnumConstantDeclValue'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3010 "src/Clang/Internal/FFI.chs" #-}

getEnumConstantDeclValue :: Cursor s -> IO Int64
getEnumConstantDeclValue c = clang_getEnumConstantDeclValue c

-- unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor);
clang_getEnumConstantDeclUnsignedValue :: (Cursor a) -> IO ((Word64))
clang_getEnumConstantDeclUnsignedValue a1 =
  withVoided a1 $ \a1' -> 
  clang_getEnumConstantDeclUnsignedValue'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3015 "src/Clang/Internal/FFI.chs" #-}

getEnumConstantDeclUnsignedValue :: Cursor s -> IO Word64
getEnumConstantDeclUnsignedValue c = clang_getEnumConstantDeclUnsignedValue c

-- int clang_getFieldDeclBitWidth(CXCursor C);
-- %fun clang_getFieldDeclBitWidth :: Cursor s -> IO Int
clang_getFieldDeclBitWidth :: (Cursor a) -> IO ((Int))
clang_getFieldDeclBitWidth a1 =
  withVoided a1 $ \a1' -> 
  clang_getFieldDeclBitWidth'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3021 "src/Clang/Internal/FFI.chs" #-}

getFieldDeclBitWidth :: Cursor s -> IO Int
getFieldDeclBitWidth c = clang_getFieldDeclBitWidth c

-- int clang_Cursor_getNumArguments(CXCursor C);
clang_Cursor_getNumArguments :: (Cursor a) -> IO ((Int))
clang_Cursor_getNumArguments a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getNumArguments'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3026 "src/Clang/Internal/FFI.chs" #-}

cursor_getNumArguments :: Cursor s -> IO Int
cursor_getNumArguments c = clang_Cursor_getNumArguments c

-- CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
clang_Cursor_getArgument :: (Cursor a) -> (Int) -> IO ((Ptr (Cursor s)))
clang_Cursor_getArgument a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_Cursor_getArgument'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3031 "src/Clang/Internal/FFI.chs" #-}

cursor_getArgument :: Proxy s -> Cursor s' -> Int -> IO (Cursor s)
cursor_getArgument _ c i = clang_Cursor_getArgument c i >>= peek

-- unsigned clang_equalTypes(CXType A, CXType B);
clang_equalTypes :: (Type a) -> (Type b) -> IO ((Bool))
clang_equalTypes a1 a2 =
  withVoided a1 $ \a1' -> 
  withVoided a2 $ \a2' -> 
  clang_equalTypes'_ a1' a2' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3036 "src/Clang/Internal/FFI.chs" #-}

equalTypes :: Type s -> Type s' -> IO Bool
equalTypes t1 t2 = clang_equalTypes t1 t2

-- CXType clang_getCanonicalType(CXType T);
clang_getCanonicalType :: (Type a) -> IO ((Ptr (Type s)))
clang_getCanonicalType a1 =
  withVoided a1 $ \a1' -> 
  clang_getCanonicalType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3041 "src/Clang/Internal/FFI.chs" #-}

getCanonicalType :: Proxy s -> Type s' -> IO (Type s)
getCanonicalType proxy t = do
  cPtr <- clang_getCanonicalType t
  peek cPtr

-- unsigned clang_isConstQualifiedType(CXType T);
clang_isConstQualifiedType :: (Type a) -> IO ((Bool))
clang_isConstQualifiedType a1 =
  withVoided a1 $ \a1' -> 
  clang_isConstQualifiedType'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3048 "src/Clang/Internal/FFI.chs" #-}

isConstQualifiedType :: Type s -> IO Bool
isConstQualifiedType t = clang_isConstQualifiedType t

-- unsigned clang_isVolatileQualifiedType(CXType T);
clang_isVolatileQualifiedType :: (Type a) -> IO ((Bool))
clang_isVolatileQualifiedType a1 =
  withVoided a1 $ \a1' -> 
  clang_isVolatileQualifiedType'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3053 "src/Clang/Internal/FFI.chs" #-}

isVolatileQualifiedType :: Type s -> IO Bool
isVolatileQualifiedType t = clang_isVolatileQualifiedType t

-- unsigned clang_isRestrictQualifiedType(CXType T);
clang_isRestrictQualifiedType :: (Type a) -> IO ((Bool))
clang_isRestrictQualifiedType a1 =
  withVoided a1 $ \a1' -> 
  clang_isRestrictQualifiedType'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3058 "src/Clang/Internal/FFI.chs" #-}

isRestrictQualifiedType :: Type s -> IO Bool
isRestrictQualifiedType t = clang_isRestrictQualifiedType t

-- CXType clang_getPointeeType(CXType T);
clang_getPointeeType :: (Type a) -> IO ((Ptr (Type s)))
clang_getPointeeType a1 =
  withVoided a1 $ \a1' -> 
  clang_getPointeeType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3063 "src/Clang/Internal/FFI.chs" #-}

getPointeeType :: Proxy s -> Type s' -> IO (Type s)
getPointeeType proxy t = do
  cPtr <- clang_getPointeeType t
  peek cPtr

-- CXCursor clang_getTypeDeclaration(CXType T);
clang_getTypeDeclaration :: (Type a) -> IO ((Ptr (Cursor s)))
clang_getTypeDeclaration a1 =
  withVoided a1 $ \a1' -> 
  clang_getTypeDeclaration'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3070 "src/Clang/Internal/FFI.chs" #-}

getTypeDeclaration :: Proxy s -> Type s' -> IO (Cursor s)
getTypeDeclaration _ t = do
  cPtr <- clang_getTypeDeclaration t
  peek cPtr

-- CXString clang_getDeclObjCTypeEncoding(CXCursor C);
clang_getDeclObjCTypeEncoding :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_getDeclObjCTypeEncoding a1 =
  withVoided a1 $ \a1' -> 
  clang_getDeclObjCTypeEncoding'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3077 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDeclObjCTypeEncoding :: Cursor s -> IO (ClangString ())
unsafe_getDeclObjCTypeEncoding c = clang_getDeclObjCTypeEncoding c >>= peek

getDeclObjCTypeEncoding :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
getDeclObjCTypeEncoding = registerClangString . unsafe_getDeclObjCTypeEncoding

-- CXString clang_getTypeKindSpelling(enum CXTypeKind K);
clang_getTypeKindSpelling :: (CInt) -> IO ((Ptr (ClangString ())))
clang_getTypeKindSpelling a1 =
  let {a1' = fromIntegral a1} in 
  clang_getTypeKindSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3085 "src/Clang/Internal/FFI.chs" #-}

unsafe_getTypeKindSpelling :: TypeKind -> IO (ClangString ())
unsafe_getTypeKindSpelling tk = clang_getTypeKindSpelling (fromIntegral (fromEnum tk)) >>= peek

getTypeKindSpelling :: ClangBase m => TypeKind -> ClangT s m (ClangString s)
getTypeKindSpelling = registerClangString . unsafe_getTypeKindSpelling

-- enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
clang_getFunctionTypeCallingConv :: (Type a) -> IO ((CInt))
clang_getFunctionTypeCallingConv a1 =
  withVoided a1 $ \a1' -> 
  clang_getFunctionTypeCallingConv'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3093 "src/Clang/Internal/FFI.chs" #-}

getFunctionTypeCallingConv :: Type s' -> IO CallingConv
getFunctionTypeCallingConv t = clang_getFunctionTypeCallingConv t >>= return . toEnum . fromIntegral

-- CXType clang_getResultType(CXType T);
clang_getResultType :: (Type a) -> IO ((Ptr (Type s)))
clang_getResultType a1 =
  withVoided a1 $ \a1' -> 
  clang_getResultType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3098 "src/Clang/Internal/FFI.chs" #-}

getResultType :: Proxy s -> Type s' -> IO (Type s)
getResultType proxy t = clang_getResultType t >>= peek

-- CXType clang_getNumArgTypes(CXType T);
clang_getNumArgTypes :: (Type a) -> IO ((Int))
clang_getNumArgTypes a1 =
  withVoided a1 $ \a1' -> 
  clang_getNumArgTypes'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3103 "src/Clang/Internal/FFI.chs" #-}

getNumArgTypes :: Type s -> IO Int
getNumArgTypes t = clang_getNumArgTypes t

-- CXType clang_getArgType(CXType T, int i);
clang_getArgType :: (Type a) -> (Int) -> IO ((Ptr (Type s)))
clang_getArgType a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_getArgType'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3108 "src/Clang/Internal/FFI.chs" #-}

getArgType :: Proxy s -> Type s' -> Int -> IO (Type s)
getArgType proxy t i = clang_getArgType t i >>= peek

-- unsigned clang_isFunctionTypeVariadic(CXType T);
clang_isFunctionTypeVariadic :: (Type a) -> IO ((CUInt))
clang_isFunctionTypeVariadic a1 =
  withVoided a1 $ \a1' -> 
  clang_isFunctionTypeVariadic'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3113 "src/Clang/Internal/FFI.chs" #-}

isFunctionTypeVariadic :: Type s -> IO Bool
isFunctionTypeVariadic t = clang_isFunctionTypeVariadic t >>= return . (toBool :: Int -> Bool) . fromIntegral

-- CXType clang_getCursorResultType(CXCursor C);
clang_getCursorResultType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_getCursorResultType a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorResultType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3118 "src/Clang/Internal/FFI.chs" #-}

getCursorResultType :: Proxy s -> Cursor s' -> IO (Type s)
getCursorResultType p c = clang_getCursorResultType c >>= peek

-- unsigned clang_isPODType(CXType T);
clang_isPODType :: (Type a) -> IO ((Bool))
clang_isPODType a1 =
  withVoided a1 $ \a1' -> 
  clang_isPODType'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3123 "src/Clang/Internal/FFI.chs" #-}

isPODType :: Type s -> IO Bool
isPODType t = clang_isPODType t

-- CXType clang_getElementType(CXType T);
clang_getElementType :: (Type a) -> IO ((Ptr (Type s)))
clang_getElementType a1 =
  withVoided a1 $ \a1' -> 
  clang_getElementType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3128 "src/Clang/Internal/FFI.chs" #-}

getElementType :: Proxy s -> Type s' -> IO (Type s)
getElementType proxy t = clang_getElementType t >>= peek

-- long long clang_getNumElements(CXType T);
clang_getNumElements :: (Type a) -> IO ((Int64))
clang_getNumElements a1 =
  withVoided a1 $ \a1' -> 
  clang_getNumElements'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3133 "src/Clang/Internal/FFI.chs" #-}

getNumElements :: Type s -> IO Int64
getNumElements t = clang_getNumElements t

-- CXType clang_getArrayElementType(CXType T);
clang_getArrayElementType :: (Type a) -> IO ((Ptr (Type s)))
clang_getArrayElementType a1 =
  withVoided a1 $ \a1' -> 
  clang_getArrayElementType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3138 "src/Clang/Internal/FFI.chs" #-}

getArrayElementType :: Proxy s -> Type s' -> IO (Type s)
getArrayElementType proxy t = clang_getArrayElementType t >>= peek

-- long long clang_getArraySize(CXType T);
clang_getArraySize :: (Type a) -> IO ((Int64))
clang_getArraySize a1 =
  withVoided a1 $ \a1' -> 
  clang_getArraySize'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3143 "src/Clang/Internal/FFI.chs" #-}

getArraySize :: Type s -> IO Int64
getArraySize t = clang_getArraySize t

-- enum CXTypeLayoutError {
--   CXTypeLayoutError_Invalid = -1,
--   CXTypeLayoutError_Incomplete = -2,
--   CXTypeLayoutError_Dependent = -3,
--   CXTypeLayoutError_NotConstantSize = -4,
--   CXTypeLayoutError_InvalidFieldName = -5
-- };
data TypeLayoutError = TypeLayoutError_InvalidFieldName
                     | TypeLayoutError_NotConstantSize
                     | TypeLayoutError_Dependent
                     | TypeLayoutError_Incomplete
                     | TypeLayoutError_Invalid
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum TypeLayoutError where
  succ TypeLayoutError_InvalidFieldName = TypeLayoutError_NotConstantSize
  succ TypeLayoutError_NotConstantSize = TypeLayoutError_Dependent
  succ TypeLayoutError_Dependent = TypeLayoutError_Incomplete
  succ TypeLayoutError_Incomplete = TypeLayoutError_Invalid
  succ TypeLayoutError_Invalid = error "TypeLayoutError.succ: TypeLayoutError_Invalid has no successor"

  pred TypeLayoutError_NotConstantSize = TypeLayoutError_InvalidFieldName
  pred TypeLayoutError_Dependent = TypeLayoutError_NotConstantSize
  pred TypeLayoutError_Incomplete = TypeLayoutError_Dependent
  pred TypeLayoutError_Invalid = TypeLayoutError_Incomplete
  pred TypeLayoutError_InvalidFieldName = error "TypeLayoutError.pred: TypeLayoutError_InvalidFieldName has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from TypeLayoutError_Invalid

  fromEnum TypeLayoutError_InvalidFieldName = (-5)
  fromEnum TypeLayoutError_NotConstantSize = (-4)
  fromEnum TypeLayoutError_Dependent = (-3)
  fromEnum TypeLayoutError_Incomplete = (-2)
  fromEnum TypeLayoutError_Invalid = (-1)

  toEnum (-5) = TypeLayoutError_InvalidFieldName
  toEnum (-4) = TypeLayoutError_NotConstantSize
  toEnum (-3) = TypeLayoutError_Dependent
  toEnum (-2) = TypeLayoutError_Incomplete
  toEnum (-1) = TypeLayoutError_Invalid
  toEnum unmatched = error ("TypeLayoutError.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3162 "src/Clang/Internal/FFI.chs" #-}


int64OrLayoutError :: Int64 -> Either TypeLayoutError Int64
int64OrLayoutError v | v == -1   = Left TypeLayoutError_Invalid
                     | v == -2   = Left TypeLayoutError_Incomplete
                     | v == -3   = Left TypeLayoutError_Dependent
                     | v == -4   = Left TypeLayoutError_NotConstantSize
                     | v == -5   = Left TypeLayoutError_InvalidFieldName
                     | otherwise = Right v

-- long long clang_Type_getAlignOf(CXType T);
clang_Type_getAlignOf :: (Type a) -> IO ((Int64))
clang_Type_getAlignOf a1 =
  withVoided a1 $ \a1' -> 
  clang_Type_getAlignOf'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3173 "src/Clang/Internal/FFI.chs" #-}

type_getAlignOf :: Type s -> IO (Either TypeLayoutError Int64)
type_getAlignOf t = clang_Type_getAlignOf t >>= return . int64OrLayoutError

-- CXType clang_Type_getClassType(CXType T);
clang_Type_getClassType :: (Type a) -> IO ((Ptr (Type s)))
clang_Type_getClassType a1 =
  withVoided a1 $ \a1' -> 
  clang_Type_getClassType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3178 "src/Clang/Internal/FFI.chs" #-}

type_getClassType :: Proxy s -> Type s' -> IO (Type s)
type_getClassType proxy t = clang_getElementType t >>= peek

-- long long clang_Type_getSizeOf(CXType T);
clang_Type_getSizeOf :: (Type a) -> IO ((Int64))
clang_Type_getSizeOf a1 =
  withVoided a1 $ \a1' -> 
  clang_Type_getSizeOf'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3183 "src/Clang/Internal/FFI.chs" #-}

type_getSizeOf :: Type s -> IO (Either TypeLayoutError Int64)
type_getSizeOf t = clang_Type_getSizeOf t >>= return . int64OrLayoutError

-- long long clang_Type_getOffsetOf(CXType T, const char *S);
clang_Type_getOffsetOf :: (Type a) -> (CString) -> IO ((Int64))
clang_Type_getOffsetOf a1 a2 =
  withVoided a1 $ \a1' -> 
  (flip ($)) a2 $ \a2' -> 
  clang_Type_getOffsetOf'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3188 "src/Clang/Internal/FFI.chs" #-}

unsafe_Type_getOffsetOf :: Type s -> CString -> IO (Either TypeLayoutError Int64)
unsafe_Type_getOffsetOf t s = clang_Type_getOffsetOf t s >>= return . int64OrLayoutError

type_getOffsetOf :: ClangBase m => Type s' -> B.ByteString
                 -> ClangT s m (Either TypeLayoutError Int64)
type_getOffsetOf t field = liftIO $ B.useAsCString field $ \cField ->
  unsafe_Type_getOffsetOf t cField

-- enum CXRefQualifierKind {
--   CXRefQualifier_None = 0,
--   CXRefQualifier_LValue,
--   CXRefQualifier_RValue
-- };
data RefQualifierKind = RefQualifier_None
                      | RefQualifier_LValue
                      | RefQualifier_RValue
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum RefQualifierKind where
  succ RefQualifier_None = RefQualifier_LValue
  succ RefQualifier_LValue = RefQualifier_RValue
  succ RefQualifier_RValue = error "RefQualifierKind.succ: RefQualifier_RValue has no successor"

  pred RefQualifier_LValue = RefQualifier_None
  pred RefQualifier_RValue = RefQualifier_LValue
  pred RefQualifier_None = error "RefQualifierKind.pred: RefQualifier_None has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from RefQualifier_RValue

  fromEnum RefQualifier_None = 0
  fromEnum RefQualifier_LValue = 1
  fromEnum RefQualifier_RValue = 2

  toEnum 0 = RefQualifier_None
  toEnum 1 = RefQualifier_LValue
  toEnum 2 = RefQualifier_RValue
  toEnum unmatched = error ("RefQualifierKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3208 "src/Clang/Internal/FFI.chs" #-}


-- enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
clang_Type_getCXXRefQualifier :: (Type a) -> IO ((Int))
clang_Type_getCXXRefQualifier a1 =
  withVoided a1 $ \a1' -> 
  clang_Type_getCXXRefQualifier'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3211 "src/Clang/Internal/FFI.chs" #-}

type_getCXXRefQualifier :: Type s -> IO RefQualifierKind
type_getCXXRefQualifier t = clang_Type_getCXXRefQualifier t >>= return . toEnum


-- unsigned clang_Cursor_isBitField(CXCursor C);
clang_Cursor_isBitField :: (Cursor a) -> IO ((Bool))
clang_Cursor_isBitField a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_isBitField'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3217 "src/Clang/Internal/FFI.chs" #-}

isBitField :: Cursor s -> IO Bool
isBitField c = clang_Cursor_isBitField c

-- unsigned clang_isVirtualBase(CXCursor);
clang_isVirtualBase :: (Cursor a) -> IO ((Bool))
clang_isVirtualBase a1 =
  withVoided a1 $ \a1' -> 
  clang_isVirtualBase'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3222 "src/Clang/Internal/FFI.chs" #-}

isVirtualBase :: Cursor s -> IO Bool
isVirtualBase c = clang_Cursor_isBitField c

-- enum CX_CXXAccessSpecifier {
--   CX_CXXInvalidAccessSpecifier,
--   CX_CXXPublic,
--   CX_CXXProtected,
--   CX_CXXPrivate
-- };
data CXXAccessSpecifier = CXXInvalidAccessSpecifier
                        | CXXPublic
                        | CXXProtected
                        | CXXPrivate
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CXXAccessSpecifier where
  succ CXXInvalidAccessSpecifier = CXXPublic
  succ CXXPublic = CXXProtected
  succ CXXProtected = CXXPrivate
  succ CXXPrivate = error "CXXAccessSpecifier.succ: CXXPrivate has no successor"

  pred CXXPublic = CXXInvalidAccessSpecifier
  pred CXXProtected = CXXPublic
  pred CXXPrivate = CXXProtected
  pred CXXInvalidAccessSpecifier = error "CXXAccessSpecifier.pred: CXXInvalidAccessSpecifier has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from CXXPrivate

  fromEnum CXXInvalidAccessSpecifier = 0
  fromEnum CXXPublic = 1
  fromEnum CXXProtected = 2
  fromEnum CXXPrivate = 3

  toEnum 0 = CXXInvalidAccessSpecifier
  toEnum 1 = CXXPublic
  toEnum 2 = CXXProtected
  toEnum 3 = CXXPrivate
  toEnum unmatched = error ("CXXAccessSpecifier.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3240 "src/Clang/Internal/FFI.chs" #-}


-- enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
clang_getCXXAccessSpecifier :: (Cursor a) -> IO ((Int))
clang_getCXXAccessSpecifier a1 =
  withVoided a1 $ \a1' -> 
  clang_getCXXAccessSpecifier'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3243 "src/Clang/Internal/FFI.chs" #-}

getCXXAccessSpecifier :: Cursor s -> IO CXXAccessSpecifier
getCXXAccessSpecifier c = clang_getCXXAccessSpecifier c >>= return . toEnum

-- unsigned clang_getNumOverloadedDecls(CXCursor cursor);
clang_getNumOverloadedDecls :: (Cursor a) -> IO ((CUInt))
clang_getNumOverloadedDecls a1 =
  withVoided a1 $ \a1' -> 
  clang_getNumOverloadedDecls'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3248 "src/Clang/Internal/FFI.chs" #-}

getNumOverloadedDecls :: Cursor s -> IO Int
getNumOverloadedDecls c = clang_getNumOverloadedDecls c >>= return . fromIntegral

-- CXCursor clang_getOverloadedDecl(CXCursor cursor,
--                                                 unsigned index);
clang_getOverloadedDecl :: (Cursor a) -> (Int) -> IO ((Ptr (Cursor s)))
clang_getOverloadedDecl a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_getOverloadedDecl'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3254 "src/Clang/Internal/FFI.chs" #-}

getOverloadedDecl :: Proxy s -> Cursor s' -> Int -> IO (Cursor s)
getOverloadedDecl _ c i = clang_getOverloadedDecl c i >>= peek

-- CXType clang_getIBOutletCollectionType(CXCursor);
clang_getIBOutletCollectionType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_getIBOutletCollectionType a1 =
  withVoided a1 $ \a1' -> 
  clang_getIBOutletCollectionType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3259 "src/Clang/Internal/FFI.chs" #-}

getIBOutletCollectionType :: Proxy s -> Cursor s' -> IO (Type s)
getIBOutletCollectionType proxy c = clang_getIBOutletCollectionType c >>= peek


-- We deliberately don't export the constructor for UnsafeCursorList.
-- The only way to unwrap it is registerCursorList.
type CursorList s = DVS.Vector (Cursor s)
instance ClangValueList Cursor
data UnsafeCursorList = UnsafeCursorList !(Ptr ()) !Int

-- void freeCursorList(CXCursor* cursors);
freeCursorList' :: (Ptr ()) -> IO ()
freeCursorList' a1 =
  let {a1' = id a1} in 
  freeCursorList''_ a1' >>
  return ()

{-# LINE 3271 "src/Clang/Internal/FFI.chs" #-}

freeCursorList :: CursorList s -> IO ()
freeCursorList cl = let (ptr, _) = fromCursorList cl in freeCursorList' ptr

registerCursorList :: ClangBase m => IO UnsafeCursorList -> ClangT s m (CursorList s)
registerCursorList action = do
    (_, cursorList) <- clangAllocate (action >>= cursorListToVector) freeCursorList
    return cursorList
{-# INLINEABLE registerCursorList #-}

cursorListToVector :: Storable a => UnsafeCursorList -> IO (DVS.Vector a)
cursorListToVector (UnsafeCursorList cs n) = do
  fptr <- newForeignPtr_ (castPtr cs)
  return $ DVS.unsafeFromForeignPtr fptr 0 n
{-# INLINE cursorListToVector #-}

fromCursorList :: CursorList s -> (Ptr (), Int)
fromCursorList cs = let (p, _, _) = DVS.unsafeToForeignPtr cs in
                   (castPtr $ Foreign.ForeignPtr.Unsafe.unsafeForeignPtrToPtr p, DVS.length cs)

toCursorList :: (Ptr (), Int) -> UnsafeCursorList
toCursorList (cs, n) = UnsafeCursorList cs n

-- A more efficient alternative to clang_visitChildren.
-- void getChildren(CXCursor parent, CXCursor** childrenOut, unsigned* countOut)
getChildren' :: (Cursor a) -> (Ptr (Ptr ())) -> IO ((CUInt))
getChildren' a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getChildren''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3296 "src/Clang/Internal/FFI.chs" #-}

unsafe_getChildren :: Cursor s -> IO UnsafeCursorList
unsafe_getChildren c =
 do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   n <- getChildren' c cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toCursorList (cxList, fromIntegral n))

getChildren :: ClangBase m => Cursor s' -> ClangT s m (CursorList s)
getChildren = registerCursorList . unsafe_getChildren

-- Like getChildren, but gets all transitive descendants.
-- void getDescendants(CXCursor parent, CXCursor** childrenOut, unsigned* countOut)
getDescendants' :: (Cursor a) -> (Ptr (Ptr ())) -> IO ((CUInt))
getDescendants' a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getDescendants''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3311 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDescendants :: Cursor s -> IO UnsafeCursorList
unsafe_getDescendants c =
 do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Cursor s))))
   n <- getDescendants' c cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toCursorList (cxList, fromIntegral n))

getDescendants :: ClangBase m => Cursor s' -> ClangT s m (CursorList s)
getDescendants = registerCursorList . unsafe_getDescendants

-- void getDeclarations(CXTranslationUnit tu, CXCursor** declsOut, unsigned* declCountOut);
getDeclarations' :: (Ptr ()) -> (Ptr (Ptr ())) -> IO ((CUInt))
getDeclarations' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getDeclarations''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3325 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDeclarations :: TranslationUnit s -> IO UnsafeCursorList
unsafe_getDeclarations t = do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr (Cursor ())))))
   n <- getDeclarations' (unTranslationUnit t) cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toCursorList (cxList, fromIntegral n))

getDeclarations :: ClangBase m => TranslationUnit s' -> ClangT s m (CursorList s)
getDeclarations = registerCursorList . unsafe_getDeclarations

-- void getReferences(CXTranslationUnit tu, CXCursor** declsOut, unsigned* declCountOut);
getReferences' :: (Ptr ()) -> (Ptr (Ptr ())) -> IO ((CUInt))
getReferences' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getReferences''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3338 "src/Clang/Internal/FFI.chs" #-}

unsafe_getReferences :: TranslationUnit s -> IO UnsafeCursorList
unsafe_getReferences t = do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   n <- getReferences' (unTranslationUnit t) cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toCursorList (cxList, fromIntegral n))

getReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (CursorList s)
getReferences = registerCursorList . unsafe_getReferences

-- void getDeclarationsAndReferences(CXTranslationUnit tu,
--                                   CXCursor** declsOut, unsigned* declCountOut,
--                                   CXCursor** refsOut, unsigned* refCountOut);
getDeclarationsAndReferences' :: (Ptr ()) -> (Ptr (Ptr ())) -> (Ptr (Ptr ())) -> IO ((CUInt), (CUInt))
getDeclarationsAndReferences' a1 a2 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  let {a4' = id a4} in 
  alloca $ \a5' -> 
  getDeclarationsAndReferences''_ a1' a2' a3' a4' a5' >>
  peek  a3'>>= \a3'' -> 
  peek  a5'>>= \a5'' -> 
  return (a3'', a5'')

{-# LINE 3354 "src/Clang/Internal/FFI.chs" #-}

unsafe_getDeclarationsAndReferences :: TranslationUnit s -> IO (UnsafeCursorList, UnsafeCursorList)
unsafe_getDeclarationsAndReferences t =
  alloca (\(declsPtr :: Ptr (Ptr ())) ->
  alloca (\(refsPtr :: Ptr (Ptr ())) -> do
   (nDecls, nRefs) <- getDeclarationsAndReferences' (unTranslationUnit t) (castPtr declsPtr) (castPtr refsPtr)
   decls <- peek declsPtr
   refs <- peek refsPtr
   return ((toCursorList (decls, fromIntegral nDecls)), (toCursorList (refs, fromIntegral nRefs)))))

-- %fun unsafe_getDeclarationsAndReferences :: TranslationUnit s -> IO (UnsafeCursorList, UnsafeCursorList)
-- %call (translationUnit t)
-- %code CXCursor* decls; unsigned declCount;
-- %     CXCursor* refs; unsigned refCount;
-- %     getDeclarationsAndReferences(t, &decls, &declCount, &refs, &refCount);
-- %result (cursorList decls declCount, cursorList refs refCount)

getDeclarationsAndReferences :: ClangBase m => TranslationUnit s'
                             -> ClangT s m (CursorList s, CursorList s)
getDeclarationsAndReferences tu = do
  (ds, rs) <- liftIO $ unsafe_getDeclarationsAndReferences tu
  (,) <$> registerCursorList (return ds) <*> registerCursorList (return rs)

data ParentedCursor s = ParentedCursor
  { parentCursor :: !(Cursor s)
  , childCursor  :: !(Cursor s)
  } deriving (Eq, Ord, Typeable)

instance ClangValue ParentedCursor

instance Storable (ParentedCursor s) where
    sizeOf _ = sizeOfParentedCursor
    {-# INLINE sizeOf #-}

    alignment _ = alignOfParentedCursor
    {-# INLINE alignment #-}

    peek p = do
      parent <- peekByteOff p offsetParentedCursorParent
      child <- peekByteOff p offsetParentedCursorCursor
      return $! ParentedCursor parent child
    {-# INLINE peek #-}

    poke p (ParentedCursor parent child) = do
      pokeByteOff p offsetParentedCursorParent parent
      pokeByteOff p offsetParentedCursorCursor child
    {-# INLINE poke #-}

-- We deliberately don't export the constructor for UnsafeParentedCursorList.
-- The only way to unwrap it is registerParentedCursorList.
type ParentedCursorList s = DVS.Vector (ParentedCursor s)
instance ClangValueList ParentedCursor
data UnsafeParentedCursorList = UnsafeParentedCursorList !(Ptr ()) !Int

-- void freeParentedCursorList(struct ParentedCursor* parentedCursors);
freeParentedCursorList' :: (Ptr ()) -> IO ()
freeParentedCursorList' a1 =
  let {a1' = id a1} in 
  freeParentedCursorList''_ a1' >>
  return ()

{-# LINE 3409 "src/Clang/Internal/FFI.chs" #-}

freeParentedCursorList :: ParentedCursorList s -> IO ()
freeParentedCursorList pcl = let (pclPtr, _ ) = fromParentedCursorList pcl in freeParentedCursorList' pclPtr

registerParentedCursorList :: ClangBase m => IO UnsafeParentedCursorList
                           -> ClangT s m (ParentedCursorList s)
registerParentedCursorList action = do
    (_, pcList) <- clangAllocate (action >>= mkSafe) freeParentedCursorList
    return pcList
  where
    mkSafe (UnsafeParentedCursorList cs n) = do
      fptr <- newForeignPtr_ (castPtr cs)
      return $ DVS.unsafeFromForeignPtr fptr 0 n
{-# INLINEABLE registerParentedCursorList #-}

fromParentedCursorList :: ParentedCursorList s -> (Ptr (), Int)
fromParentedCursorList cs =
  let (p, _, _) = DVS.unsafeToForeignPtr cs in
  (castPtr $ Foreign.ForeignPtr.Unsafe.unsafeForeignPtrToPtr p, DVS.length cs)

toParentedCursorList :: (Ptr (), Int) -> UnsafeParentedCursorList
toParentedCursorList (cs, n) = UnsafeParentedCursorList cs n

-- %dis parentedCursorList cs n = <fromParentedCursorList/toParentedCursorList> (ptr cs) (int n)

-- Like getParentedDescendants, but pairs each descendant with its parent.
-- void getParentedDescendants(CXCursor parent, struct ParentedCursor** descendantsOut,
--                             unsigned* countOut)
getParentedDescendants' :: (Cursor a) -> (Ptr (Ptr ())) -> IO ((CUInt))
getParentedDescendants' a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getParentedDescendants''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3437 "src/Clang/Internal/FFI.chs" #-}

unsafe_getParentedDescendants :: Cursor s -> IO UnsafeParentedCursorList
unsafe_getParentedDescendants c =
 do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   n <- getParentedDescendants' c cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toParentedCursorList (cxList, fromIntegral n))

getParentedDescendants :: ClangBase m => Cursor s' -> ClangT s m (ParentedCursorList s)
getParentedDescendants = registerParentedCursorList . unsafe_getParentedDescendants

-- void getParentedDeclarations(CXTranslationUnit tu, CXCursor** declsOut, unsigned* declCountOut);
getParentedDeclarations' :: (Ptr ()) -> (Ptr (Ptr ())) -> IO ((CUInt))
getParentedDeclarations' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getParentedDeclarations''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3451 "src/Clang/Internal/FFI.chs" #-}

unsafe_getParentedDeclarations :: TranslationUnit s -> IO UnsafeParentedCursorList
unsafe_getParentedDeclarations t = do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr (Cursor ())))))
   n <- getParentedDeclarations' (unTranslationUnit t) (castPtr cxListPtr)
   cxList <- peek cxListPtr
   free cxListPtr
   return (toParentedCursorList (cxList, fromIntegral n))

getParentedDeclarations :: ClangBase m => TranslationUnit s' -> ClangT s m (ParentedCursorList s)
getParentedDeclarations = registerParentedCursorList . unsafe_getParentedDeclarations

-- void getParentedReferences(CXTranslationUnit tu, CXCursor** declsOut, unsigned* declCountOut);
getParentedReferences' :: (Ptr ()) -> (Ptr (Ptr ())) -> IO ((CUInt))
getParentedReferences' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getParentedReferences''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 3464 "src/Clang/Internal/FFI.chs" #-}

unsafe_getParentedReferences :: TranslationUnit s -> IO UnsafeParentedCursorList
unsafe_getParentedReferences t = do
   cxListPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   n <- getParentedReferences' (unTranslationUnit t) cxListPtr
   cxList <- peek cxListPtr
   free cxListPtr
   return (toParentedCursorList (cxList, fromIntegral n))

getParentedReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (ParentedCursorList s)
getParentedReferences = registerParentedCursorList . unsafe_getParentedReferences

-- void getParentedDeclarationsAndReferences(CXTranslationUnit tu,
--                                           ParentedCursor** declsOut,
--                                           unsigned* declCountOut,
--                                           ParentedCursor** refsOut,
--                                           unsigned* refCountOut);
getParentedDeclarationsAndReferences' :: (Ptr ()) -> (Ptr (Ptr ())) -> (Ptr (Ptr ())) -> IO ((CUInt), (CUInt))
getParentedDeclarationsAndReferences' a1 a2 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  let {a4' = id a4} in 
  alloca $ \a5' -> 
  getParentedDeclarationsAndReferences''_ a1' a2' a3' a4' a5' >>
  peek  a3'>>= \a3'' -> 
  peek  a5'>>= \a5'' -> 
  return (a3'', a5'')

{-# LINE 3482 "src/Clang/Internal/FFI.chs" #-}

unsafe_getParentedDeclarationsAndReferences :: TranslationUnit s -> IO (UnsafeParentedCursorList, UnsafeParentedCursorList)
unsafe_getParentedDeclarationsAndReferences t = do
   declsPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   refsPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
   (nDecls, nRefs) <- getParentedDeclarationsAndReferences' (unTranslationUnit t) declsPtr refsPtr
   decls <- peek declsPtr
   refs <- peek refsPtr
   free declsPtr
   free refsPtr
   return ((toParentedCursorList (decls, fromIntegral nDecls)), (toParentedCursorList (refs, fromIntegral nRefs)))

getParentedDeclarationsAndReferences :: ClangBase m => TranslationUnit s'
                                     -> ClangT s m (ParentedCursorList s, ParentedCursorList s)
getParentedDeclarationsAndReferences tu = do
  (ds, rs) <- liftIO $ unsafe_getParentedDeclarationsAndReferences tu
  (,) <$> registerParentedCursorList (return ds) <*> registerParentedCursorList (return rs)

-- CXString clang_getCursorUSR(CXCursor);
clang_getCursorUSR :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_getCursorUSR a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorUSR'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3501 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorUSR :: Cursor s -> IO (ClangString ())
unsafe_getCursorUSR c =
  clang_getCursorUSR c >>= peek

getCursorUSR :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
getCursorUSR = registerClangString . unsafe_getCursorUSR

-- CXString clang_constructUSR_ObjCClass(const char *class_name);
clang_constructUSR_ObjCClass :: (CString) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCClass a1 =
  (flip ($)) a1 $ \a1' -> 
  clang_constructUSR_ObjCClass'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3510 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCClass :: String -> IO (ClangString ())
unsafe_constructUSR_ObjCClass s = withCString s (\sPtr -> clang_constructUSR_ObjCClass sPtr >>= peek)

constructUSR_ObjCClass :: ClangBase m => String -> ClangT s m (ClangString s)
constructUSR_ObjCClass = registerClangString . unsafe_constructUSR_ObjCClass

-- CXString
--   clang_constructUSR_ObjCCategory(const char *class_name,
--                                  const char *category_name);
clang_constructUSR_ObjCCategory :: (CString) -> (CString) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCCategory a1 a2 =
  (flip ($)) a1 $ \a1' -> 
  (flip ($)) a2 $ \a2' -> 
  clang_constructUSR_ObjCCategory'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3520 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCCategory :: String -> String -> IO (ClangString ())
unsafe_constructUSR_ObjCCategory s p =
  withCString s (\sPtr ->
  withCString p (\pPtr ->
    clang_constructUSR_ObjCCategory sPtr pPtr >>= peek))

constructUSR_ObjCCategory :: ClangBase m => String -> String -> ClangT s m (ClangString s)
constructUSR_ObjCCategory = (registerClangString .) . unsafe_constructUSR_ObjCCategory

-- CXString
--   clang_constructUSR_ObjCProtocol(const char *protocol_name);
clang_constructUSR_ObjCProtocol :: (CString) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCProtocol a1 =
  (flip ($)) a1 $ \a1' -> 
  clang_constructUSR_ObjCProtocol'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3532 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCProtocol :: String -> IO (ClangString ())
unsafe_constructUSR_ObjCProtocol s = withCString s (\sPtr -> clang_constructUSR_ObjCProtocol sPtr >>= peek)

constructUSR_ObjCProtocol :: ClangBase m => String -> ClangT s m (ClangString s)
constructUSR_ObjCProtocol = registerClangString . unsafe_constructUSR_ObjCProtocol

-- CXString clang_constructUSR_ObjCIvar(const char *name,
--                                                     CXString classUSR);
clang_constructUSR_ObjCIvar :: (CString) -> (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCIvar a1 a2 =
  (flip ($)) a1 $ \a1' -> 
  let {a2' = id a2} in 
  clang_constructUSR_ObjCIvar'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3541 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCIvar :: String -> Ptr () -> Word32 -> IO (ClangString ())
unsafe_constructUSR_ObjCIvar s d f =
  let clangString = ClangString  d f in
  withCString s (\sPtr -> new clangString >>= \cs -> clang_constructUSR_ObjCIvar sPtr (castPtr cs) >>= peek)

constructUSR_ObjCIvar :: ClangBase m => String -> ClangString s' -> ClangT s m (ClangString s)
constructUSR_ObjCIvar s (ClangString d f) = registerClangString $ unsafe_constructUSR_ObjCIvar s d f

-- CXString clang_constructUSR_ObjCMethod(const char *name,
--                                                       unsigned isInstanceMethod,
--                                                       CXString classUSR);
clang_constructUSR_ObjCMethod :: (CString) -> (CUInt) -> (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCMethod a1 a2 a3 =
  (flip ($)) a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  clang_constructUSR_ObjCMethod'_ a1' a2' a3' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3553 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCMethod :: String -> Bool -> Ptr () -> Word32 -> IO (ClangString ())
unsafe_constructUSR_ObjCMethod s b d f =
  let clangString = ClangString  d f in
  withCString s (\sPtr -> (new clangString >>= \cs -> clang_constructUSR_ObjCMethod sPtr (fromIntegral ((fromBool b) :: Int)) (castPtr cs) >>= peek))

constructUSR_ObjCMethod :: ClangBase m => String -> Bool -> ClangString s' -> ClangT s m (ClangString s)
constructUSR_ObjCMethod s b (ClangString d f) =
  registerClangString $ unsafe_constructUSR_ObjCMethod s b d f

-- CXString clang_constructUSR_ObjCProperty(const char *property,
--                                                         CXString classUSR);
clang_constructUSR_ObjCProperty :: (CString) -> (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_constructUSR_ObjCProperty a1 a2 =
  (flip ($)) a1 $ \a1' -> 
  let {a2' = id a2} in 
  clang_constructUSR_ObjCProperty'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3565 "src/Clang/Internal/FFI.chs" #-}

unsafe_constructUSR_ObjCProperty :: String -> Ptr () -> Word32 -> IO (ClangString ())
unsafe_constructUSR_ObjCProperty s d f =
  let clangString = ClangString  d f in
  withCString s (\sPtr -> (new clangString >>= \cs -> clang_constructUSR_ObjCProperty sPtr (castPtr cs) >>= peek))

constructUSR_ObjCProperty :: ClangBase m => String -> ClangString s' -> ClangT s m (ClangString s)
constructUSR_ObjCProperty s (ClangString d f) =
  registerClangString $ unsafe_constructUSR_ObjCProperty s d f

-- CXString clang_getCursorSpelling(CXCursor);
clang_getCursorSpelling :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_getCursorSpelling a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3576 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorSpelling :: Cursor s -> IO (ClangString ())
unsafe_getCursorSpelling c =
  clang_getCursorSpelling c >>= peek

getCursorSpelling :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
getCursorSpelling = registerClangString . unsafe_getCursorSpelling

-- CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
--                                                 unsigned pieceIndex,
--                                                 unsigned options);
clang_Cursor_getSpellingNameRange :: (Cursor a) -> (Int) -> (Int) -> IO ((Ptr (SourceRange s)))
clang_Cursor_getSpellingNameRange a1 a2 a3 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  clang_Cursor_getSpellingNameRange'_ a1' a2' a3' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3587 "src/Clang/Internal/FFI.chs" #-}

cursor_getSpellingNameRange :: Proxy s -> Cursor s' -> Int -> IO (SourceRange s)
cursor_getSpellingNameRange _ c i = clang_Cursor_getSpellingNameRange c i 0 >>= peek

-- CXString clang_getCursorDisplayName(CXCursor);
clang_getCursorDisplayName :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_getCursorDisplayName a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorDisplayName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3592 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorDisplayName :: Cursor s -> IO (ClangString ())
unsafe_getCursorDisplayName c =
  clang_getCursorDisplayName c >>= peek

getCursorDisplayName :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
getCursorDisplayName = registerClangString . unsafe_getCursorDisplayName

-- CXCursor clang_getCursorReferenced(CXCursor);
clang_getCursorReferenced :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getCursorReferenced a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorReferenced'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3601 "src/Clang/Internal/FFI.chs" #-}

getCursorReferenced :: Proxy s -> Cursor s' -> IO (Cursor s)
getCursorReferenced _ c =
  clang_getCursorReferenced c >>= peek

-- CXCursor clang_getCursorDefinition(CXCursor);
clang_getCursorDefinition :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getCursorDefinition a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorDefinition'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3607 "src/Clang/Internal/FFI.chs" #-}

getCursorDefinition :: Proxy s -> Cursor s' -> IO (Cursor s)
getCursorDefinition _ c = clang_getCursorDefinition c >>= peek

-- unsigned clang_isCursorDefinition(CXCursor);
clang_isCursorDefinition :: (Cursor a) -> IO ((Bool))
clang_isCursorDefinition a1 =
  withVoided a1 $ \a1' -> 
  clang_isCursorDefinition'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3612 "src/Clang/Internal/FFI.chs" #-}

isCursorDefinition :: Cursor s -> IO Bool
isCursorDefinition c = clang_isCursorDefinition c

-- unsigned clang_Cursor_isDynamicCall(CXCursor);
clang_Cursor_isDynamicCall :: (Cursor a) -> IO ((Bool))
clang_Cursor_isDynamicCall a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_isDynamicCall'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3617 "src/Clang/Internal/FFI.chs" #-}

cursor_isDynamicCall :: Cursor s -> IO Bool
cursor_isDynamicCall c = clang_Cursor_isDynamicCall c

-- CXCursor clang_getCanonicalCursor(CXCursor);
clang_getCanonicalCursor :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getCanonicalCursor a1 =
  withVoided a1 $ \a1' -> 
  clang_getCanonicalCursor'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3622 "src/Clang/Internal/FFI.chs" #-}

getCanonicalCursor :: Proxy s -> Cursor s' -> IO (Cursor s)
getCanonicalCursor _ c =
  clang_getCanonicalCursor c >>= peek

-- int clang_Cursor_getObjCSelectorIndex(CXCursor);
clang_Cursor_getObjCSelectorIndex :: (Cursor a) -> IO ((Int))
clang_Cursor_getObjCSelectorIndex a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getObjCSelectorIndex'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3628 "src/Clang/Internal/FFI.chs" #-}

cursor_getObjCSelectorIndex :: Cursor s -> IO Int
cursor_getObjCSelectorIndex c = clang_Cursor_getObjCSelectorIndex c

-- CXType clang_Cursor_getReceiverType(CXCursor C);
clang_Cursor_getReceiverType :: (Cursor a) -> IO ((Ptr (Type s)))
clang_Cursor_getReceiverType a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getReceiverType'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3633 "src/Clang/Internal/FFI.chs" #-}

cursor_getReceiverType :: Proxy s -> Cursor s' -> IO (Type s)
cursor_getReceiverType proxy c =
  clang_Cursor_getReceiverType c >>= peek

-- typedef enum {
--   CXObjCPropertyAttr_noattr    = 0x00,
--   CXObjCPropertyAttr_readonly  = 0x01,
--   CXObjCPropertyAttr_getter    = 0x02,
--   CXObjCPropertyAttr_assign    = 0x04,
--   CXObjCPropertyAttr_readwrite = 0x08,
--   CXObjCPropertyAttr_retain    = 0x10,
--   CXObjCPropertyAttr_copy      = 0x20,
--   CXObjCPropertyAttr_nonatomic = 0x40,
--   CXObjCPropertyAttr_setter    = 0x80,
--   CXObjCPropertyAttr_atomic    = 0x100,
--   CXObjCPropertyAttr_weak      = 0x200,
--   CXObjCPropertyAttr_strong    = 0x400,
--   CXObjCPropertyAttr_unsafe_unretained = 0x800
-- } CXObjCPropertyAttrKind;

data ObjCPropertyAttrKind = ObjCPropertyAttr_noattr
                          | ObjCPropertyAttr_readonly
                          | ObjCPropertyAttr_getter
                          | ObjCPropertyAttr_assign
                          | ObjCPropertyAttr_readwrite
                          | ObjCPropertyAttr_retain
                          | ObjCPropertyAttr_copy
                          | ObjCPropertyAttr_nonatomic
                          | ObjCPropertyAttr_setter
                          | ObjCPropertyAttr_atomic
                          | ObjCPropertyAttr_weak
                          | ObjCPropertyAttr_strong
                          | ObjCPropertyAttr_unsafe_unretained
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum ObjCPropertyAttrKind where
  succ ObjCPropertyAttr_noattr = ObjCPropertyAttr_readonly
  succ ObjCPropertyAttr_readonly = ObjCPropertyAttr_getter
  succ ObjCPropertyAttr_getter = ObjCPropertyAttr_assign
  succ ObjCPropertyAttr_assign = ObjCPropertyAttr_readwrite
  succ ObjCPropertyAttr_readwrite = ObjCPropertyAttr_retain
  succ ObjCPropertyAttr_retain = ObjCPropertyAttr_copy
  succ ObjCPropertyAttr_copy = ObjCPropertyAttr_nonatomic
  succ ObjCPropertyAttr_nonatomic = ObjCPropertyAttr_setter
  succ ObjCPropertyAttr_setter = ObjCPropertyAttr_atomic
  succ ObjCPropertyAttr_atomic = ObjCPropertyAttr_weak
  succ ObjCPropertyAttr_weak = ObjCPropertyAttr_strong
  succ ObjCPropertyAttr_strong = ObjCPropertyAttr_unsafe_unretained
  succ ObjCPropertyAttr_unsafe_unretained = error "ObjCPropertyAttrKind.succ: ObjCPropertyAttr_unsafe_unretained has no successor"

  pred ObjCPropertyAttr_readonly = ObjCPropertyAttr_noattr
  pred ObjCPropertyAttr_getter = ObjCPropertyAttr_readonly
  pred ObjCPropertyAttr_assign = ObjCPropertyAttr_getter
  pred ObjCPropertyAttr_readwrite = ObjCPropertyAttr_assign
  pred ObjCPropertyAttr_retain = ObjCPropertyAttr_readwrite
  pred ObjCPropertyAttr_copy = ObjCPropertyAttr_retain
  pred ObjCPropertyAttr_nonatomic = ObjCPropertyAttr_copy
  pred ObjCPropertyAttr_setter = ObjCPropertyAttr_nonatomic
  pred ObjCPropertyAttr_atomic = ObjCPropertyAttr_setter
  pred ObjCPropertyAttr_weak = ObjCPropertyAttr_atomic
  pred ObjCPropertyAttr_strong = ObjCPropertyAttr_weak
  pred ObjCPropertyAttr_unsafe_unretained = ObjCPropertyAttr_strong
  pred ObjCPropertyAttr_noattr = error "ObjCPropertyAttrKind.pred: ObjCPropertyAttr_noattr has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ObjCPropertyAttr_unsafe_unretained

  fromEnum ObjCPropertyAttr_noattr = 0
  fromEnum ObjCPropertyAttr_readonly = 1
  fromEnum ObjCPropertyAttr_getter = 2
  fromEnum ObjCPropertyAttr_assign = 4
  fromEnum ObjCPropertyAttr_readwrite = 8
  fromEnum ObjCPropertyAttr_retain = 16
  fromEnum ObjCPropertyAttr_copy = 32
  fromEnum ObjCPropertyAttr_nonatomic = 64
  fromEnum ObjCPropertyAttr_setter = 128
  fromEnum ObjCPropertyAttr_atomic = 256
  fromEnum ObjCPropertyAttr_weak = 512
  fromEnum ObjCPropertyAttr_strong = 1024
  fromEnum ObjCPropertyAttr_unsafe_unretained = 2048

  toEnum 0 = ObjCPropertyAttr_noattr
  toEnum 1 = ObjCPropertyAttr_readonly
  toEnum 2 = ObjCPropertyAttr_getter
  toEnum 4 = ObjCPropertyAttr_assign
  toEnum 8 = ObjCPropertyAttr_readwrite
  toEnum 16 = ObjCPropertyAttr_retain
  toEnum 32 = ObjCPropertyAttr_copy
  toEnum 64 = ObjCPropertyAttr_nonatomic
  toEnum 128 = ObjCPropertyAttr_setter
  toEnum 256 = ObjCPropertyAttr_atomic
  toEnum 512 = ObjCPropertyAttr_weak
  toEnum 1024 = ObjCPropertyAttr_strong
  toEnum 2048 = ObjCPropertyAttr_unsafe_unretained
  toEnum unmatched = error ("ObjCPropertyAttrKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3670 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags ObjCPropertyAttrKind where
  toBit ObjCPropertyAttr_noattr            = 0x0
  toBit ObjCPropertyAttr_readonly          = 0x1
  toBit ObjCPropertyAttr_getter            = 0x2
  toBit ObjCPropertyAttr_assign            = 0x4
  toBit ObjCPropertyAttr_readwrite         = 0x8
  toBit ObjCPropertyAttr_retain            = 0x10
  toBit ObjCPropertyAttr_copy              = 0x20
  toBit ObjCPropertyAttr_nonatomic         = 0x40
  toBit ObjCPropertyAttr_setter            = 0x80
  toBit ObjCPropertyAttr_atomic            = 0x100
  toBit ObjCPropertyAttr_weak              = 0x200
  toBit ObjCPropertyAttr_strong            = 0x400
  toBit ObjCPropertyAttr_unsafe_unretained = 0x800

-- unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved);
clang_Cursor_getObjCPropertyAttributes :: (Cursor a) -> (Int) -> IO ((CUInt))
clang_Cursor_getObjCPropertyAttributes a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_Cursor_getObjCPropertyAttributes'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3688 "src/Clang/Internal/FFI.chs" #-}

cursor_getObjCPropertyAttributes :: Cursor s -> IO Int
cursor_getObjCPropertyAttributes c = clang_Cursor_getObjCPropertyAttributes c 0 >>= return . fromIntegral

-- typedef enum {
--   CXObjCDeclQualifier_None = 0x0,
--   CXObjCDeclQualifier_In = 0x1,
--   CXObjCDeclQualifier_Inout = 0x2,
--   CXObjCDeclQualifier_Out = 0x4,
--   CXObjCDeclQualifier_Bycopy = 0x8,
--   CXObjCDeclQualifier_Byref = 0x10,
--   CXObjCDeclQualifier_Oneway = 0x20
-- } CXObjCDeclQualifierKind;

data ObjCDeclQualifierKind = ObjCDeclQualifier_None
                           | ObjCDeclQualifier_In
                           | ObjCDeclQualifier_Inout
                           | ObjCDeclQualifier_Out
                           | ObjCDeclQualifier_Bycopy
                           | ObjCDeclQualifier_Byref
                           | ObjCDeclQualifier_Oneway
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum ObjCDeclQualifierKind where
  succ ObjCDeclQualifier_None = ObjCDeclQualifier_In
  succ ObjCDeclQualifier_In = ObjCDeclQualifier_Inout
  succ ObjCDeclQualifier_Inout = ObjCDeclQualifier_Out
  succ ObjCDeclQualifier_Out = ObjCDeclQualifier_Bycopy
  succ ObjCDeclQualifier_Bycopy = ObjCDeclQualifier_Byref
  succ ObjCDeclQualifier_Byref = ObjCDeclQualifier_Oneway
  succ ObjCDeclQualifier_Oneway = error "ObjCDeclQualifierKind.succ: ObjCDeclQualifier_Oneway has no successor"

  pred ObjCDeclQualifier_In = ObjCDeclQualifier_None
  pred ObjCDeclQualifier_Inout = ObjCDeclQualifier_In
  pred ObjCDeclQualifier_Out = ObjCDeclQualifier_Inout
  pred ObjCDeclQualifier_Bycopy = ObjCDeclQualifier_Out
  pred ObjCDeclQualifier_Byref = ObjCDeclQualifier_Bycopy
  pred ObjCDeclQualifier_Oneway = ObjCDeclQualifier_Byref
  pred ObjCDeclQualifier_None = error "ObjCDeclQualifierKind.pred: ObjCDeclQualifier_None has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ObjCDeclQualifier_Oneway

  fromEnum ObjCDeclQualifier_None = 0
  fromEnum ObjCDeclQualifier_In = 1
  fromEnum ObjCDeclQualifier_Inout = 2
  fromEnum ObjCDeclQualifier_Out = 4
  fromEnum ObjCDeclQualifier_Bycopy = 8
  fromEnum ObjCDeclQualifier_Byref = 16
  fromEnum ObjCDeclQualifier_Oneway = 32

  toEnum 0 = ObjCDeclQualifier_None
  toEnum 1 = ObjCDeclQualifier_In
  toEnum 2 = ObjCDeclQualifier_Inout
  toEnum 4 = ObjCDeclQualifier_Out
  toEnum 8 = ObjCDeclQualifier_Bycopy
  toEnum 16 = ObjCDeclQualifier_Byref
  toEnum 32 = ObjCDeclQualifier_Oneway
  toEnum unmatched = error ("ObjCDeclQualifierKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3712 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags ObjCDeclQualifierKind where
  toBit ObjCDeclQualifier_None   = 0x0
  toBit ObjCDeclQualifier_In     = 0x1
  toBit ObjCDeclQualifier_Inout  = 0x2
  toBit ObjCDeclQualifier_Out    = 0x4
  toBit ObjCDeclQualifier_Bycopy = 0x8
  toBit ObjCDeclQualifier_Byref  = 0x10
  toBit ObjCDeclQualifier_Oneway = 0x20

-- unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
clang_Cursor_getObjCDeclQualifiers :: (Cursor a) -> IO ((CUInt))
clang_Cursor_getObjCDeclQualifiers a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getObjCDeclQualifiers'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3724 "src/Clang/Internal/FFI.chs" #-}

cursor_getObjCDeclQualifiers :: Cursor s -> IO Int
cursor_getObjCDeclQualifiers c =
  clang_Cursor_getObjCDeclQualifiers c >>= return . fromIntegral

-- unsigned clang_Cursor_isObjCOptional(CXCursor);
clang_Cursor_isObjCOptional :: (Cursor a) -> IO ((Bool))
clang_Cursor_isObjCOptional a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_isObjCOptional'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3730 "src/Clang/Internal/FFI.chs" #-}

cursor_isObjCOptional :: Cursor s -> IO Bool
cursor_isObjCOptional c = clang_Cursor_isObjCOptional c

-- unsigned clang_Cursor_isVariadic(CXCursor);
clang_Cursor_isVariadic :: (Cursor a) -> IO ((Bool))
clang_Cursor_isVariadic a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_isVariadic'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3735 "src/Clang/Internal/FFI.chs" #-}

cursor_isVariadic :: Cursor s -> IO Bool
cursor_isVariadic c = clang_Cursor_isVariadic c

-- CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
clang_Cursor_getCommentRange :: (Cursor a) -> IO ((Ptr (SourceRange s)))
clang_Cursor_getCommentRange a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getCommentRange'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3740 "src/Clang/Internal/FFI.chs" #-}

cursor_getCommentRange :: Proxy s -> Cursor s' -> IO (SourceRange s)
cursor_getCommentRange _ c = clang_Cursor_getCommentRange c >>= peek

-- CXString clang_Cursor_getRawCommentText(CXCursor C);
clang_Cursor_getRawCommentText :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_Cursor_getRawCommentText a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getRawCommentText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3745 "src/Clang/Internal/FFI.chs" #-}

unsafe_Cursor_getRawCommentText :: Cursor s -> IO (ClangString ())
unsafe_Cursor_getRawCommentText c =
  clang_Cursor_getRawCommentText c >>= peek

cursor_getRawCommentText :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
cursor_getRawCommentText = registerClangString . unsafe_Cursor_getRawCommentText

-- CXString clang_Cursor_getBriefCommentText(CXCursor C);
clang_Cursor_getBriefCommentText :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_Cursor_getBriefCommentText a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getBriefCommentText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3754 "src/Clang/Internal/FFI.chs" #-}

unsafe_Cursor_getBriefCommentText :: Cursor s -> IO (ClangString ())
unsafe_Cursor_getBriefCommentText c =
  clang_Cursor_getBriefCommentText c >>= peek

cursor_getBriefCommentText :: ClangBase m => Cursor s' -> ClangT s m (ClangString s)
cursor_getBriefCommentText = registerClangString . unsafe_Cursor_getBriefCommentText

-- CXComment clang_Cursor_getParsedComment(CXCursor C);

clang_Cursor_getParsedComment :: (Cursor a) -> IO ((Ptr (Comment s)))
clang_Cursor_getParsedComment a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getParsedComment'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3764 "src/Clang/Internal/FFI.chs" #-}

cursor_getParsedComment :: Proxy s -> Cursor s' -> IO (Comment s)
cursor_getParsedComment _ c =
  clang_Cursor_getParsedComment c >>= peek

-- typedef void *CXModule;
newtype Module s = Module { unModule :: Ptr () }
                   deriving (Eq, Ord, Typeable)

instance ClangValue Module

-- %dis cxmodule p = <unModule/Module> (ptr p)

maybeModule :: Module s' -> Maybe (Module s)
maybeModule (Module p) | p == nullPtr = Nothing
maybeModule f                         = Just (unsafeCoerce f)

unMaybeModule :: Maybe (Module s') -> Module s
unMaybeModule (Just f) = unsafeCoerce f
unMaybeModule Nothing  = Module nullPtr

-- CXModule clang_Cursor_getModule(CXCursor C);
clang_Cursor_getModule :: (Cursor a) -> IO ((Ptr ()))
clang_Cursor_getModule a1 =
  withVoided a1 $ \a1' -> 
  clang_Cursor_getModule'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3786 "src/Clang/Internal/FFI.chs" #-}

cursor_getModule :: Proxy s -> Cursor s' -> IO (Module s)
cursor_getModule _ c =
  clang_Cursor_getModule c >>= return . Module

-- CXFile clang_Module_getASTFile(CXModule Module);
clang_Module_getASTFile :: (Ptr ()) -> IO ((Ptr ()))
clang_Module_getASTFile a1 =
  let {a1' = id a1} in 
  clang_Module_getASTFile'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3792 "src/Clang/Internal/FFI.chs" #-}

module_getASTFile :: Proxy s -> Module s' -> IO (File s)
module_getASTFile _ m = clang_Module_getASTFile (unModule m) >>= return . File

-- CXModule clang_Module_getParent(CXModule Module);
clang_Module_getParent :: (Ptr ()) -> IO ((Ptr ()))
clang_Module_getParent a1 =
  let {a1' = id a1} in 
  clang_Module_getParent'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3797 "src/Clang/Internal/FFI.chs" #-}

module_getParent :: Proxy s -> Module s' -> IO (Maybe (Module s))
module_getParent _ m = clang_Module_getParent (unModule m) >>= return . maybeModule . Module

-- CXString clang_Module_getName(CXModule Module);
clang_Module_getName :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_Module_getName a1 =
  let {a1' = id a1} in 
  clang_Module_getName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3802 "src/Clang/Internal/FFI.chs" #-}

unsafe_Module_getName :: Module s -> IO (ClangString ())
unsafe_Module_getName m = clang_Module_getName (unModule m) >>= peek

module_getName :: ClangBase m => Module s' -> ClangT s m (ClangString s)
module_getName = registerClangString . unsafe_Module_getName

-- CXString clang_Module_getFullName(CXModule Module);
clang_Module_getFullName :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_Module_getFullName a1 =
  let {a1' = id a1} in 
  clang_Module_getFullName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3810 "src/Clang/Internal/FFI.chs" #-}

unsafe_Module_getFullName :: Module s -> IO (ClangString ())
unsafe_Module_getFullName m = clang_Module_getFullName (unModule m) >>= peek

module_getFullName :: ClangBase m => Module s' -> ClangT s m (ClangString s)
module_getFullName = registerClangString . unsafe_Module_getFullName

-- unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit, CXModule Module);
clang_Module_getNumTopLevelHeaders :: (Ptr ()) -> (Ptr ()) -> IO ((Int))
clang_Module_getNumTopLevelHeaders a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  clang_Module_getNumTopLevelHeaders'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3818 "src/Clang/Internal/FFI.chs" #-}

module_getNumTopLevelHeaders :: TranslationUnit s -> Module s' -> IO Int
module_getNumTopLevelHeaders t m = clang_Module_getNumTopLevelHeaders (unTranslationUnit t) (unModule m)

-- CXFile clang_Module_getTopLevelHeader(CXTranslationUnit, CXModule Module, unsigned Index);
clang_Module_getTopLevelHeader :: (Ptr ()) -> (Ptr ()) -> (Int) -> IO ((Ptr ()))
clang_Module_getTopLevelHeader a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  clang_Module_getTopLevelHeader'_ a1' a2' a3' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 3823 "src/Clang/Internal/FFI.chs" #-}

module_getTopLevelHeader :: Proxy s -> TranslationUnit s' -> Module s'' -> Int -> IO (File s)
module_getTopLevelHeader _ t m i = clang_Module_getTopLevelHeader (unTranslationUnit t) (unModule m) i >>= return . File

-- unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
clang_CXXMethod_isPureVirtual :: (Cursor a) -> IO ((Bool))
clang_CXXMethod_isPureVirtual a1 =
  withVoided a1 $ \a1' -> 
  clang_CXXMethod_isPureVirtual'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3828 "src/Clang/Internal/FFI.chs" #-}

cXXMethod_isPureVirtual :: Cursor s -> IO Bool
cXXMethod_isPureVirtual c = clang_Cursor_isBitField c

-- unsigned clang_CXXMethod_isStatic(CXCursor C);
clang_CXXMethod_isStatic :: (Cursor a) -> IO ((Bool))
clang_CXXMethod_isStatic a1 =
  withVoided a1 $ \a1' -> 
  clang_CXXMethod_isStatic'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3833 "src/Clang/Internal/FFI.chs" #-}

cXXMethod_isStatic :: Cursor s -> IO Bool
cXXMethod_isStatic c = clang_Cursor_isBitField c

-- unsigned clang_CXXMethod_isVirtual(CXCursor C);
clang_CXXMethod_isVirtual :: (Cursor a) -> IO ((Bool))
clang_CXXMethod_isVirtual a1 =
  withVoided a1 $ \a1' -> 
  clang_CXXMethod_isVirtual'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3838 "src/Clang/Internal/FFI.chs" #-}

cXXMethod_isVirtual :: Cursor s -> IO Bool
cXXMethod_isVirtual c = clang_Cursor_isBitField c

-- enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
clang_getTemplateCursorKind :: (Cursor a) -> IO ((Int))
clang_getTemplateCursorKind a1 =
  withVoided a1 $ \a1' -> 
  clang_getTemplateCursorKind'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3843 "src/Clang/Internal/FFI.chs" #-}

getTemplateCursorKind :: Cursor s -> IO CursorKind
getTemplateCursorKind c =
  clang_getTemplateCursorKind c >>= return . toEnum

-- CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
clang_getSpecializedCursorTemplate :: (Cursor a) -> IO ((Ptr (Cursor s)))
clang_getSpecializedCursorTemplate a1 =
  withVoided a1 $ \a1' -> 
  clang_getSpecializedCursorTemplate'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3849 "src/Clang/Internal/FFI.chs" #-}

getSpecializedCursorTemplate :: Proxy s -> Cursor s' -> IO (Cursor s)
getSpecializedCursorTemplate _ c =
  clang_getSpecializedCursorTemplate c >>= peek

-- CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
--                                                 unsigned NameFlags,
--                                                 unsigned PieceIndex);
clang_getCursorReferenceNameRange :: (Cursor a) -> (Int) -> (Int) -> IO ((Ptr (SourceRange s)))
clang_getCursorReferenceNameRange a1 a2 a3 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  clang_getCursorReferenceNameRange'_ a1' a2' a3' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3857 "src/Clang/Internal/FFI.chs" #-}

getCursorReferenceNameRange :: Proxy s -> Cursor s' -> Int -> Int -> IO (SourceRange s)
getCursorReferenceNameRange _ c fs idx = clang_getCursorReferenceNameRange c fs idx >>= peek

-- enum CXNameRefFlags {
--   CXNameRange_WantQualifier = 0x1,
--   CXNameRange_WantTemplateArgs = 0x2,
--   CXNameRange_WantSinglePiece = 0x4
-- };
data NameRefFlags = NameRange_WantQualifier
                  | NameRange_WantTemplateArgs
                  | NameRange_WantSinglePiece
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum NameRefFlags where
  succ NameRange_WantQualifier = NameRange_WantTemplateArgs
  succ NameRange_WantTemplateArgs = NameRange_WantSinglePiece
  succ NameRange_WantSinglePiece = error "NameRefFlags.succ: NameRange_WantSinglePiece has no successor"

  pred NameRange_WantTemplateArgs = NameRange_WantQualifier
  pred NameRange_WantSinglePiece = NameRange_WantTemplateArgs
  pred NameRange_WantQualifier = error "NameRefFlags.pred: NameRange_WantQualifier has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from NameRange_WantSinglePiece

  fromEnum NameRange_WantQualifier = 1
  fromEnum NameRange_WantTemplateArgs = 2
  fromEnum NameRange_WantSinglePiece = 4

  toEnum 1 = NameRange_WantQualifier
  toEnum 2 = NameRange_WantTemplateArgs
  toEnum 4 = NameRange_WantSinglePiece
  toEnum unmatched = error ("NameRefFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3872 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags NameRefFlags where
  toBit NameRange_WantQualifier    = 0x01
  toBit NameRange_WantTemplateArgs = 0x02
  toBit NameRange_WantSinglePiece  = 0x04

-- enum CXCommentKind {
--   CXComment_Null = 0,
--   CXComment_Text = 1,
--   CXComment_InlineCommand = 2,
--   CXComment_HTMLStartTag = 3,
--   CXComment_HTMLEndTag = 4,
--   CXComment_Paragraph = 5,
--   CXComment_BlockCommand = 6,
--   CXComment_ParamCommand = 7,
--   CXComment_TParamCommand = 8,
--   CXComment_VerbatimBlockCommand = 9,
--   CXComment_VerbatimBlockLine = 10,
--   CXComment_VerbatimLine = 11,
--   CXComment_FullComment = 12
-- };
data CommentKind = NullComment
                 | TextComment
                 | InlineCommandComment
                 | HTMLStartTagComment
                 | HTMLEndTagComment
                 | ParagraphComment
                 | BlockCommandComment
                 | ParamCommandComment
                 | TParamCommandComment
                 | VerbatimBlockCommandComment
                 | VerbatimBlockLineComment
                 | VerbatimLineComment
                 | FullComment
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CommentKind where
  succ NullComment = TextComment
  succ TextComment = InlineCommandComment
  succ InlineCommandComment = HTMLStartTagComment
  succ HTMLStartTagComment = HTMLEndTagComment
  succ HTMLEndTagComment = ParagraphComment
  succ ParagraphComment = BlockCommandComment
  succ BlockCommandComment = ParamCommandComment
  succ ParamCommandComment = TParamCommandComment
  succ TParamCommandComment = VerbatimBlockCommandComment
  succ VerbatimBlockCommandComment = VerbatimBlockLineComment
  succ VerbatimBlockLineComment = VerbatimLineComment
  succ VerbatimLineComment = FullComment
  succ FullComment = error "CommentKind.succ: FullComment has no successor"

  pred TextComment = NullComment
  pred InlineCommandComment = TextComment
  pred HTMLStartTagComment = InlineCommandComment
  pred HTMLEndTagComment = HTMLStartTagComment
  pred ParagraphComment = HTMLEndTagComment
  pred BlockCommandComment = ParagraphComment
  pred ParamCommandComment = BlockCommandComment
  pred TParamCommandComment = ParamCommandComment
  pred VerbatimBlockCommandComment = TParamCommandComment
  pred VerbatimBlockLineComment = VerbatimBlockCommandComment
  pred VerbatimLineComment = VerbatimBlockLineComment
  pred FullComment = VerbatimLineComment
  pred NullComment = error "CommentKind.pred: NullComment has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from FullComment

  fromEnum NullComment = 0
  fromEnum TextComment = 1
  fromEnum InlineCommandComment = 2
  fromEnum HTMLStartTagComment = 3
  fromEnum HTMLEndTagComment = 4
  fromEnum ParagraphComment = 5
  fromEnum BlockCommandComment = 6
  fromEnum ParamCommandComment = 7
  fromEnum TParamCommandComment = 8
  fromEnum VerbatimBlockCommandComment = 9
  fromEnum VerbatimBlockLineComment = 10
  fromEnum VerbatimLineComment = 11
  fromEnum FullComment = 12

  toEnum 0 = NullComment
  toEnum 1 = TextComment
  toEnum 2 = InlineCommandComment
  toEnum 3 = HTMLStartTagComment
  toEnum 4 = HTMLEndTagComment
  toEnum 5 = ParagraphComment
  toEnum 6 = BlockCommandComment
  toEnum 7 = ParamCommandComment
  toEnum 8 = TParamCommandComment
  toEnum 9 = VerbatimBlockCommandComment
  toEnum 10 = VerbatimBlockLineComment
  toEnum 11 = VerbatimLineComment
  toEnum 12 = FullComment
  toEnum unmatched = error ("CommentKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3910 "src/Clang/Internal/FFI.chs" #-}


-- enum CXCommentInlineCommandRenderKind {
--   CXCommentInlineCommandRenderKind_Normal,
--   CXCommentInlineCommandRenderKind_Bold,
--   CXCommentInlineCommandRenderKind_Monospaced,
--   CXCommentInlineCommandRenderKind_Emphasized
-- };

-- | A rendering style which should be used for the associated inline command in the comment AST.
data InlineCommandRenderStyle = NormalInlineCommandRenderStyle
                              | BoldInlineCommandRenderStyle
                              | MonospacedInlineCommandRenderStyle
                              | EmphasizedInlineCommandRenderStyle
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum InlineCommandRenderStyle where
  succ NormalInlineCommandRenderStyle = BoldInlineCommandRenderStyle
  succ BoldInlineCommandRenderStyle = MonospacedInlineCommandRenderStyle
  succ MonospacedInlineCommandRenderStyle = EmphasizedInlineCommandRenderStyle
  succ EmphasizedInlineCommandRenderStyle = error "InlineCommandRenderStyle.succ: EmphasizedInlineCommandRenderStyle has no successor"

  pred BoldInlineCommandRenderStyle = NormalInlineCommandRenderStyle
  pred MonospacedInlineCommandRenderStyle = BoldInlineCommandRenderStyle
  pred EmphasizedInlineCommandRenderStyle = MonospacedInlineCommandRenderStyle
  pred NormalInlineCommandRenderStyle = error "InlineCommandRenderStyle.pred: NormalInlineCommandRenderStyle has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from EmphasizedInlineCommandRenderStyle

  fromEnum NormalInlineCommandRenderStyle = 0
  fromEnum BoldInlineCommandRenderStyle = 1
  fromEnum MonospacedInlineCommandRenderStyle = 2
  fromEnum EmphasizedInlineCommandRenderStyle = 3

  toEnum 0 = NormalInlineCommandRenderStyle
  toEnum 1 = BoldInlineCommandRenderStyle
  toEnum 2 = MonospacedInlineCommandRenderStyle
  toEnum 3 = EmphasizedInlineCommandRenderStyle
  toEnum unmatched = error ("InlineCommandRenderStyle.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3927 "src/Clang/Internal/FFI.chs" #-}

-- enum CXCommentParamPassDirection {
--   CXCommentParamPassDirection_In,
--   CXCommentParamPassDirection_Out,
--   CXCommentParamPassDirection_InOut
-- };

-- | A parameter passing direction.
data ParamPassDirectionKind = InParamPassDirection
                            | OutParamPassDirection
                            | InOutParamPassDirection
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum ParamPassDirectionKind where
  succ InParamPassDirection = OutParamPassDirection
  succ OutParamPassDirection = InOutParamPassDirection
  succ InOutParamPassDirection = error "ParamPassDirectionKind.succ: InOutParamPassDirection has no successor"

  pred OutParamPassDirection = InParamPassDirection
  pred InOutParamPassDirection = OutParamPassDirection
  pred InParamPassDirection = error "ParamPassDirectionKind.pred: InParamPassDirection has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from InOutParamPassDirection

  fromEnum InParamPassDirection = 0
  fromEnum OutParamPassDirection = 1
  fromEnum InOutParamPassDirection = 2

  toEnum 0 = InParamPassDirection
  toEnum 1 = OutParamPassDirection
  toEnum 2 = InOutParamPassDirection
  toEnum unmatched = error ("ParamPassDirectionKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 3941 "src/Clang/Internal/FFI.chs" #-}


-- enum CXCommentKind clang_Comment_getKind(CXComment Comment);
clang_Comment_getKind :: (Comment a) -> IO ((Int))
clang_Comment_getKind a1 =
  withVoided a1 $ \a1' -> 
  clang_Comment_getKind'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3944 "src/Clang/Internal/FFI.chs" #-}

comment_getKind :: Comment s -> IO CommentKind
comment_getKind c =
  clang_Comment_getKind c >>= return . toEnum

-- unsigned clang_Comment_getNumChildren(CXComment Comment);
clang_Comment_getNumChildren :: (Comment a) -> IO ((Int))
clang_Comment_getNumChildren a1 =
  withVoided a1 $ \a1' -> 
  clang_Comment_getNumChildren'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3950 "src/Clang/Internal/FFI.chs" #-}

comment_getNumChildren :: Comment s -> IO Int
comment_getNumChildren c =
  clang_Comment_getNumChildren c

-- CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
clang_Comment_getChild :: (Comment a) -> (Int) -> IO ((Ptr (Comment s)))
clang_Comment_getChild a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_Comment_getChild'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3956 "src/Clang/Internal/FFI.chs" #-}

comment_getChild :: Proxy s -> Comment s' -> Int -> IO (Comment s)
comment_getChild _ c i = clang_Comment_getChild c i >>= peek

-- unsigned clang_Comment_isWhitespace(CXComment Comment);
clang_Comment_isWhitespace :: (Comment a) -> IO ((Bool))
clang_Comment_isWhitespace a1 =
  withVoided a1 $ \a1' -> 
  clang_Comment_isWhitespace'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3961 "src/Clang/Internal/FFI.chs" #-}

comment_isWhitespace :: Comment s -> IO Bool
comment_isWhitespace c = clang_Comment_isWhitespace c

-- unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
clang_InlineContentComment_hasTrailingNewline :: (Comment a) -> IO ((Bool))
clang_InlineContentComment_hasTrailingNewline a1 =
  withVoided a1 $ \a1' -> 
  clang_InlineContentComment_hasTrailingNewline'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 3966 "src/Clang/Internal/FFI.chs" #-}

inlineContentComment_hasTrailingNewline :: Comment s -> IO Bool
inlineContentComment_hasTrailingNewline c = clang_InlineContentComment_hasTrailingNewline c

-- CXString clang_TextComment_getText(CXComment Comment);
clang_TextComment_getText :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_TextComment_getText a1 =
  withVoided a1 $ \a1' -> 
  clang_TextComment_getText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3971 "src/Clang/Internal/FFI.chs" #-}

unsafe_TextComment_getText :: Comment s -> IO (ClangString ())
unsafe_TextComment_getText c =
  clang_TextComment_getText c >>= peek

textComment_getText :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
textComment_getText = registerClangString . unsafe_TextComment_getText

-- CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
clang_InlineCommandComment_getCommandName :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_InlineCommandComment_getCommandName a1 =
  withVoided a1 $ \a1' -> 
  clang_InlineCommandComment_getCommandName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 3980 "src/Clang/Internal/FFI.chs" #-}

unsafe_InlineCommandComment_getCommandName :: Comment s -> IO (ClangString ())
unsafe_InlineCommandComment_getCommandName c =
  clang_InlineCommandComment_getCommandName c >>= peek

inlineCommandComment_getCommandName :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
inlineCommandComment_getCommandName = registerClangString . unsafe_InlineCommandComment_getCommandName

-- enum CXCommentInlineCommandRenderKind clang_InlineCommandComment_getRenderKind(CXComment Comment);
clang_InlineCommandComment_getRenderKind :: (Comment a) -> IO ((Int))
clang_InlineCommandComment_getRenderKind a1 =
  withVoided a1 $ \a1' -> 
  clang_InlineCommandComment_getRenderKind'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3989 "src/Clang/Internal/FFI.chs" #-}

inlineCommandComment_getRenderKind :: Comment s -> IO InlineCommandRenderStyle
inlineCommandComment_getRenderKind c =
  clang_InlineCommandComment_getRenderKind c >>= return . toEnum

-- unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
clang_InlineCommandComment_getNumArgs :: (Comment a) -> IO ((Int))
clang_InlineCommandComment_getNumArgs a1 =
  withVoided a1 $ \a1' -> 
  clang_InlineCommandComment_getNumArgs'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 3995 "src/Clang/Internal/FFI.chs" #-}

inlineCommandComment_getNumArgs :: Comment s -> IO Int
inlineCommandComment_getNumArgs c =
  clang_InlineCommandComment_getNumArgs c

-- CXString clang_InlineCommandComment_getArgText(CXComment Comment, unsigned ArgIdx);
clang_InlineCommandComment_getArgText :: (Comment a) -> (Int) -> IO ((Ptr (ClangString ())))
clang_InlineCommandComment_getArgText a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_InlineCommandComment_getArgText'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4001 "src/Clang/Internal/FFI.chs" #-}

unsafe_InlineCommandComment_getArgText :: Comment s -> Int -> IO (ClangString ())
unsafe_InlineCommandComment_getArgText c idx =
  clang_InlineCommandComment_getArgText c idx >>= peek

inlineCommandComment_getArgText :: ClangBase m => Comment s' -> Int -> ClangT s m (ClangString s)
inlineCommandComment_getArgText = (registerClangString .) . unsafe_InlineCommandComment_getArgText

-- CXString clang_HTMLTagComment_getTagName(CXComment Comment);
clang_HTMLTagComment_getTagName :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_HTMLTagComment_getTagName a1 =
  withVoided a1 $ \a1' -> 
  clang_HTMLTagComment_getTagName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4010 "src/Clang/Internal/FFI.chs" #-}

unsafe_HTMLTagComment_getTagName :: Comment s -> IO (ClangString ())
unsafe_HTMLTagComment_getTagName c =
  clang_HTMLTagComment_getTagName c >>= peek

hTMLTagComment_getTagName :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
hTMLTagComment_getTagName = registerClangString . unsafe_HTMLTagComment_getTagName

-- unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
clang_HTMLStartTagComment_isSelfClosing :: (Comment a) -> IO ((Bool))
clang_HTMLStartTagComment_isSelfClosing a1 =
  withVoided a1 $ \a1' -> 
  clang_HTMLStartTagComment_isSelfClosing'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 4019 "src/Clang/Internal/FFI.chs" #-}

hTMLStartTagComment_isSelfClosing :: Comment s -> IO Bool
hTMLStartTagComment_isSelfClosing c = clang_HTMLStartTagComment_isSelfClosing c

-- unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
clang_HTMLStartTag_getNumAttrs :: (Comment a) -> IO ((Int))
clang_HTMLStartTag_getNumAttrs a1 =
  withVoided a1 $ \a1' -> 
  clang_HTMLStartTag_getNumAttrs'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4024 "src/Clang/Internal/FFI.chs" #-}

hTMLStartTag_getNumAttrs :: Comment s -> IO Int
hTMLStartTag_getNumAttrs c =
  clang_HTMLStartTag_getNumAttrs c

-- CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
clang_HTMLStartTag_getAttrName :: (Comment a) -> (Int) -> IO ((Ptr (ClangString ())))
clang_HTMLStartTag_getAttrName a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_HTMLStartTag_getAttrName'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4030 "src/Clang/Internal/FFI.chs" #-}

unsafe_HTMLStartTag_getAttrName :: Comment s -> Int -> IO (ClangString ())
unsafe_HTMLStartTag_getAttrName c idx =
  clang_HTMLStartTag_getAttrName c idx >>= peek

hTMLStartTag_getAttrName :: ClangBase m => Comment s' -> Int -> ClangT s m (ClangString s)
hTMLStartTag_getAttrName = (registerClangString .) . unsafe_HTMLStartTag_getAttrName

-- CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
clang_HTMLStartTag_getAttrValue :: (Comment a) -> (Int) -> IO ((Ptr (ClangString ())))
clang_HTMLStartTag_getAttrValue a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_HTMLStartTag_getAttrValue'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4039 "src/Clang/Internal/FFI.chs" #-}

unsafe_HTMLStartTag_getAttrValue :: Comment s -> Int -> IO (ClangString ())
unsafe_HTMLStartTag_getAttrValue c idx =
  clang_HTMLStartTag_getAttrValue c idx >>= peek

hTMLStartTag_getAttrValue :: ClangBase m => Comment s' -> Int -> ClangT s m (ClangString s)
hTMLStartTag_getAttrValue = (registerClangString .) . unsafe_HTMLStartTag_getAttrValue

-- CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
clang_BlockCommandComment_getCommandName :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_BlockCommandComment_getCommandName a1 =
  withVoided a1 $ \a1' -> 
  clang_BlockCommandComment_getCommandName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4048 "src/Clang/Internal/FFI.chs" #-}

unsafe_BlockCommandComment_getCommandName :: Comment s -> IO (ClangString ())
unsafe_BlockCommandComment_getCommandName c =
  clang_BlockCommandComment_getCommandName c >>= peek

blockCommandComment_getCommandName :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
blockCommandComment_getCommandName = registerClangString . unsafe_BlockCommandComment_getCommandName

-- unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
clang_BlockCommandComment_getNumArgs :: (Comment a) -> IO ((Int))
clang_BlockCommandComment_getNumArgs a1 =
  withVoided a1 $ \a1' -> 
  clang_BlockCommandComment_getNumArgs'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4057 "src/Clang/Internal/FFI.chs" #-}

blockCommandComment_getNumArgs :: Comment s -> IO Int
blockCommandComment_getNumArgs c =
  clang_BlockCommandComment_getNumArgs c

-- CXString clang_BlockCommandComment_getArgText(CXComment Comment, unsigned ArgIdx);
clang_BlockCommandComment_getArgText :: (Comment a) -> (Int) -> IO ((Ptr (ClangString ())))
clang_BlockCommandComment_getArgText a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_BlockCommandComment_getArgText'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4063 "src/Clang/Internal/FFI.chs" #-}

unsafe_BlockCommandComment_getArgText :: Comment s -> Int -> IO (ClangString ())
unsafe_BlockCommandComment_getArgText c idx =
  clang_BlockCommandComment_getArgText c idx >>= peek

blockCommandComment_getArgText :: ClangBase m => Comment s' -> Int -> ClangT s m (ClangString s)
blockCommandComment_getArgText = (registerClangString .) . unsafe_BlockCommandComment_getArgText

-- CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
clang_BlockCommandComment_getParagraph :: (Comment a) -> IO ((Ptr (Comment s)))
clang_BlockCommandComment_getParagraph a1 =
  withVoided a1 $ \a1' -> 
  clang_BlockCommandComment_getParagraph'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4072 "src/Clang/Internal/FFI.chs" #-}

blockCommandComment_getParagraph :: Proxy s -> Comment s' -> IO (Comment s)
blockCommandComment_getParagraph _ c =
  clang_BlockCommandComment_getParagraph c >>= peek

-- CXString clang_ParamCommandComment_getParamName(CXComment Comment);
clang_ParamCommandComment_getParamName :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_ParamCommandComment_getParamName a1 =
  withVoided a1 $ \a1' -> 
  clang_ParamCommandComment_getParamName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4078 "src/Clang/Internal/FFI.chs" #-}

unsafe_ParamCommandComment_getParamName :: Comment s -> IO (ClangString ())
unsafe_ParamCommandComment_getParamName c =
  clang_ParamCommandComment_getParamName c >>= peek

paramCommandComment_getParamName :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
paramCommandComment_getParamName = registerClangString . unsafe_ParamCommandComment_getParamName

-- unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
clang_ParamCommandComment_isParamIndexValid :: (Comment a) -> IO ((Bool))
clang_ParamCommandComment_isParamIndexValid a1 =
  withVoided a1 $ \a1' -> 
  clang_ParamCommandComment_isParamIndexValid'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 4087 "src/Clang/Internal/FFI.chs" #-}

paramCommandComment_isParamIndexValid :: Comment s -> IO Bool
paramCommandComment_isParamIndexValid c =
  clang_ParamCommandComment_isParamIndexValid c

-- unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
clang_ParamCommandComment_getParamIndex :: (Comment a) -> IO ((Int))
clang_ParamCommandComment_getParamIndex a1 =
  withVoided a1 $ \a1' -> 
  clang_ParamCommandComment_getParamIndex'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4093 "src/Clang/Internal/FFI.chs" #-}

paramCommandComment_getParamIndex :: Comment s -> IO Int
paramCommandComment_getParamIndex c =
  clang_ParamCommandComment_getParamIndex c

-- unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
clang_ParamCommandComment_isDirectionExplicit :: (Comment a) -> IO ((Bool))
clang_ParamCommandComment_isDirectionExplicit a1 =
  withVoided a1 $ \a1' -> 
  clang_ParamCommandComment_isDirectionExplicit'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 4099 "src/Clang/Internal/FFI.chs" #-}

paramCommandComment_isDirectionExplicit :: Comment s -> IO Bool
paramCommandComment_isDirectionExplicit c =
  clang_ParamCommandComment_isDirectionExplicit c

-- enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(CXComment Comment);
clang_ParamCommandComment_getDirection :: (Comment a) -> IO ((Int))
clang_ParamCommandComment_getDirection a1 =
  withVoided a1 $ \a1' -> 
  clang_ParamCommandComment_getDirection'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4105 "src/Clang/Internal/FFI.chs" #-}

paramCommandComment_getDirection :: Comment s -> IO ParamPassDirectionKind
paramCommandComment_getDirection c =
  clang_ParamCommandComment_getDirection c >>= return . toEnum

-- CXString clang_TParamCommandComment_getParamName(CXComment Comment);
clang_TParamCommandComment_getParamName :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_TParamCommandComment_getParamName a1 =
  withVoided a1 $ \a1' -> 
  clang_TParamCommandComment_getParamName'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4111 "src/Clang/Internal/FFI.chs" #-}

unsafe_TParamCommandComment_getParamName :: Comment s -> IO (ClangString ())
unsafe_TParamCommandComment_getParamName c =
  clang_TParamCommandComment_getParamName c >>= peek

tParamCommandComment_getParamName :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
tParamCommandComment_getParamName = registerClangString . unsafe_TParamCommandComment_getParamName

-- unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
clang_TParamCommandComment_isParamPositionValid :: (Comment a) -> IO ((Bool))
clang_TParamCommandComment_isParamPositionValid a1 =
  withVoided a1 $ \a1' -> 
  clang_TParamCommandComment_isParamPositionValid'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 4120 "src/Clang/Internal/FFI.chs" #-}

tParamCommandComment_isParamPositionValid :: Comment s -> IO Bool
tParamCommandComment_isParamPositionValid c =
  clang_TParamCommandComment_isParamPositionValid c

-- unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
clang_TParamCommandComment_getDepth :: (Comment a) -> IO ((Int))
clang_TParamCommandComment_getDepth a1 =
  withVoided a1 $ \a1' -> 
  clang_TParamCommandComment_getDepth'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4126 "src/Clang/Internal/FFI.chs" #-}

tParamCommandComment_getDepth :: Comment s -> IO Int
tParamCommandComment_getDepth c =
  clang_TParamCommandComment_getDepth c

-- unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
clang_TParamCommandComment_getIndex :: (Comment a) -> (Int) -> IO ((Int))
clang_TParamCommandComment_getIndex a1 a2 =
  withVoided a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  clang_TParamCommandComment_getIndex'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4132 "src/Clang/Internal/FFI.chs" #-}

tParamCommandComment_getIndex :: Comment s -> Int -> IO Int
tParamCommandComment_getIndex c idx =
  clang_TParamCommandComment_getIndex c idx

-- CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
clang_VerbatimBlockLineComment_getText :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_VerbatimBlockLineComment_getText a1 =
  withVoided a1 $ \a1' -> 
  clang_VerbatimBlockLineComment_getText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4138 "src/Clang/Internal/FFI.chs" #-}

unsafe_VerbatimBlockLineComment_getText :: Comment s -> IO (ClangString ())
unsafe_VerbatimBlockLineComment_getText c =
  clang_VerbatimBlockLineComment_getText c >>= peek

verbatimBlockLineComment_getText :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
verbatimBlockLineComment_getText = registerClangString . unsafe_VerbatimBlockLineComment_getText

-- CXString clang_VerbatimLineComment_getText(CXComment Comment);
clang_VerbatimLineComment_getText :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_VerbatimLineComment_getText a1 =
  withVoided a1 $ \a1' -> 
  clang_VerbatimLineComment_getText'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4147 "src/Clang/Internal/FFI.chs" #-}

unsafe_VerbatimLineComment_getText :: Comment s -> IO (ClangString ())
unsafe_VerbatimLineComment_getText c =
  clang_VerbatimLineComment_getText c >>= peek

verbatimLineComment_getText :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
verbatimLineComment_getText = registerClangString . unsafe_VerbatimLineComment_getText

-- CXString clang_HTMLTagComment_getAsString(CXComment Comment);
clang_HTMLTagComment_getAsString :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_HTMLTagComment_getAsString a1 =
  withVoided a1 $ \a1' -> 
  clang_HTMLTagComment_getAsString'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4156 "src/Clang/Internal/FFI.chs" #-}

unsafe_HTMLTagComment_getAsString :: Comment s -> IO (ClangString ())
unsafe_HTMLTagComment_getAsString c =
  clang_HTMLTagComment_getAsString c >>= peek

hTMLTagComment_getAsString :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
hTMLTagComment_getAsString = registerClangString . unsafe_HTMLTagComment_getAsString

-- CXString clang_FullComment_getAsHTML(CXComment Comment);
clang_FullComment_getAsHTML :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_FullComment_getAsHTML a1 =
  withVoided a1 $ \a1' -> 
  clang_FullComment_getAsHTML'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4165 "src/Clang/Internal/FFI.chs" #-}

unsafe_FullComment_getAsHTML :: Comment s -> IO (ClangString ())
unsafe_FullComment_getAsHTML c =
  clang_FullComment_getAsHTML c >>= peek

fullComment_getAsHTML :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
fullComment_getAsHTML = registerClangString . unsafe_FullComment_getAsHTML

-- CXString clang_FullComment_getAsXML(CXComment Comment);
clang_FullComment_getAsXML :: (Comment a) -> IO ((Ptr (ClangString ())))
clang_FullComment_getAsXML a1 =
  withVoided a1 $ \a1' -> 
  clang_FullComment_getAsXML'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4174 "src/Clang/Internal/FFI.chs" #-}

unsafe_FullComment_getAsXML :: Comment s -> IO (ClangString ())
unsafe_FullComment_getAsXML c =
  clang_FullComment_getAsXML c >>= peek

fullComment_getAsXML :: ClangBase m => Comment s' -> ClangT s m (ClangString s)
fullComment_getAsXML = registerClangString . unsafe_FullComment_getAsXML

-- typedef enum CXTokenKind {
--   CXToken_Punctuation,
--   CXToken_Keyword,
--   CXToken_Identifier,
--   CXToken_Literal,
--   CXToken_Comment
-- } CXTokenKind;
data TokenKind = PunctuationToken
               | KeywordToken
               | IdentifierToken
               | LiteralToken
               | CommentToken
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum TokenKind where
  succ PunctuationToken = KeywordToken
  succ KeywordToken = IdentifierToken
  succ IdentifierToken = LiteralToken
  succ LiteralToken = CommentToken
  succ CommentToken = error "TokenKind.succ: CommentToken has no successor"

  pred KeywordToken = PunctuationToken
  pred IdentifierToken = KeywordToken
  pred LiteralToken = IdentifierToken
  pred CommentToken = LiteralToken
  pred PunctuationToken = error "TokenKind.pred: PunctuationToken has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from CommentToken

  fromEnum PunctuationToken = 0
  fromEnum KeywordToken = 1
  fromEnum IdentifierToken = 2
  fromEnum LiteralToken = 3
  fromEnum CommentToken = 4

  toEnum 0 = PunctuationToken
  toEnum 1 = KeywordToken
  toEnum 2 = IdentifierToken
  toEnum 3 = LiteralToken
  toEnum 4 = CommentToken
  toEnum unmatched = error ("TokenKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 4197 "src/Clang/Internal/FFI.chs" #-}


-- typedef struct {
--   unsigned int_data[4];
--   void *ptr_data;
-- } CXToken;
data Token s = Token !Int !Int !Int !Int !(Ptr ())
               deriving (Eq, Ord, Typeable)

instance ClangValue Token

instance Storable (Token s) where
    sizeOf _ = sizeOfCXToken
    {-# INLINE sizeOf #-}

    alignment _ = alignOfCXToken
    {-# INLINE alignment #-}

    peek p = do
      int_data <- (\ptr -> do {return $ ptr `C2HSImp.plusPtr` 0 :: IO (C2HSImp.Ptr C2HSImp.CUInt)}) p >>= peekArray 4
      ptr_data <- (\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO (C2HSImp.Ptr ())}) p
      return $! Token (fromIntegral (int_data !! 0)) (fromIntegral (int_data !! 1)) (fromIntegral (int_data !! 2)) (fromIntegral (int_data !! 3)) ptr_data
    {-# INLINE peek #-}

    poke p (Token i0 i1 i2 i3 ptr_data) = do
      intsArray <- mallocArray 4
      pokeArray intsArray (map fromIntegral [i0,i1,i2,i3])
      (\ptr val -> do {C2HSImp.copyArray (ptr `C2HSImp.plusPtr` 0) (val :: (C2HSImp.Ptr C2HSImp.CUInt)) 4}) p intsArray
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: (C2HSImp.Ptr ()))}) p ptr_data
    {-# INLINE poke #-}

-- CXTokenKind clang_getTokenKind(CXToken);
clang_getTokenKind :: (Token s) -> IO ((Int))
clang_getTokenKind a1 =
  withVoided a1 $ \a1' -> 
  clang_getTokenKind'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4229 "src/Clang/Internal/FFI.chs" #-}

getTokenKind :: Token s -> IO TokenKind
getTokenKind t =
  clang_getTokenKind t  >>= return . toEnum

-- CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
clang_getTokenSpelling :: (Ptr ()) -> (Token s) -> IO ((Ptr (ClangString ())))
clang_getTokenSpelling a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_getTokenSpelling'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4235 "src/Clang/Internal/FFI.chs" #-}

unsafe_getTokenSpelling :: TranslationUnit s -> Token s' -> IO (ClangString ())
unsafe_getTokenSpelling tu t =
   clang_getTokenSpelling (unTranslationUnit tu) t >>= peek

getTokenSpelling :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (ClangString s)
getTokenSpelling = (registerClangString .) . unsafe_getTokenSpelling

-- CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
--                                                        CXToken);
clang_getTokenLocation :: (Ptr ()) -> (Token a) -> IO ((Ptr (SourceLocation s)))
clang_getTokenLocation a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_getTokenLocation'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4245 "src/Clang/Internal/FFI.chs" #-}

getTokenLocation :: Proxy s -> TranslationUnit t -> Token s' -> IO (SourceLocation s)
getTokenLocation _ tu t =
  clang_getTokenLocation (unTranslationUnit tu) t >>= peek

-- CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
clang_getTokenExtent :: (Ptr ()) -> (Token a) -> IO ((Ptr (SourceRange s)))
clang_getTokenExtent a1 a2 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  clang_getTokenExtent'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4251 "src/Clang/Internal/FFI.chs" #-}

getTokenExtent :: Proxy s -> TranslationUnit t -> Token s' -> IO (SourceRange s)
getTokenExtent _ tu t =
  clang_getTokenExtent (unTranslationUnit tu) t >>= peek

-- We deliberately don't export the constructor for UnsafeTokenList.
-- The only way to unwrap it is registerTokenList.
type TokenList s = DVS.Vector (Token s)
instance ClangValueList Token
data UnsafeTokenList = UnsafeTokenList !(Ptr ()) !Int

foreign import ccall unsafe "FFI_stub_ffi.h clang_disposeTokens" clang_disposeTokens :: Ptr () -> Ptr () -> CUInt -> IO ()

disposeTokens :: TranslationUnit s -> TokenList s' -> IO ()
disposeTokens tu tl =
 let (tPtr, n) = fromTokenList tl in
 clang_disposeTokens (unTranslationUnit tu) tPtr (fromIntegral n)

registerTokenList :: ClangBase m => TranslationUnit s' -> IO UnsafeTokenList
                  -> ClangT s m (TokenList s)
registerTokenList tu action = do
    (_, tokenList) <- clangAllocate (action >>= tokenListToVector) (disposeTokens tu)
    return tokenList
{-# INLINEABLE registerTokenList #-}

tokenListToVector :: Storable a => UnsafeTokenList -> IO (DVS.Vector a)
tokenListToVector (UnsafeTokenList ts n) = do
  fptr <- newForeignPtr_ (castPtr ts)
  return $ DVS.unsafeFromForeignPtr fptr 0 n
{-# INLINE tokenListToVector #-}

fromTokenList :: TokenList s -> (Ptr (), Int)
fromTokenList ts = let (p, _, _) = DVS.unsafeToForeignPtr ts in
                   (castPtr $ Foreign.ForeignPtr.Unsafe.unsafeForeignPtrToPtr p, DVS.length ts)

toTokenList :: (Ptr (), Int) -> UnsafeTokenList
toTokenList (ts, n) = UnsafeTokenList ts n

-- void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
--                                    CXToken **Tokens, unsigned *NumTokens);
clang_tokenize :: (Ptr ()) -> (SourceRange a) -> (Ptr (Ptr ())) -> IO ((CUInt))
clang_tokenize a1 a2 a3 =
  let {a1' = id a1} in 
  withVoided a2 $ \a2' -> 
  let {a3' = id a3} in 
  alloca $ \a4' -> 
  clang_tokenize'_ a1' a2' a3' a4' >>
  peek  a4'>>= \a4'' -> 
  return (a4'')

{-# LINE 4291 "src/Clang/Internal/FFI.chs" #-}

unsafe_tokenize :: TranslationUnit s -> SourceRange s' -> IO UnsafeTokenList
unsafe_tokenize tu sr = do
  tokensPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr (Token ())))))
  numTokens <- clang_tokenize (unTranslationUnit tu) sr (castPtr tokensPtr)
  return (toTokenList (tokensPtr, fromIntegral numTokens))

tokenize :: ClangBase m => TranslationUnit s' -> SourceRange s'' -> ClangT s m (TokenList s)
tokenize tu = registerTokenList tu . unsafe_tokenize tu

-- TODO: test me
-- Note that registerCursorList can be used for the result of this
-- function because it just calls free() to dispose of the list.
--
-- void clang_annotateTokens(CXTranslationUnit TU,
--                                          CXToken *Tokens, unsigned NumTokens,
--                                          CXCursor *Cursors);
clang_annotateTokens :: (Ptr ()) -> (Ptr ()) -> (Int) -> (Ptr ()) -> IO ((()))
clang_annotateTokens a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = id a4} in 
  clang_annotateTokens'_ a1' a2' a3' a4' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 4308 "src/Clang/Internal/FFI.chs" #-}

unsafe_annotateTokens :: TranslationUnit s -> TokenList s' -> IO UnsafeCursorList
unsafe_annotateTokens tu tl =
  let (tPtr, numTokens) = fromTokenList tl in
  do
    cPtr <- mallocBytes ((sizeOf (undefined :: (Ptr (Cursor ())))) * numTokens)
    clang_annotateTokens (unTranslationUnit tu) tPtr numTokens (castPtr cPtr)
    return (toCursorList (cPtr, numTokens))

annotateTokens :: ClangBase m => TranslationUnit s' -> TokenList s'' -> ClangT s m (CursorList s)
annotateTokens = (registerCursorList .) . unsafe_annotateTokens

-- CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
clang_getCursorKindSpelling :: (CInt) -> IO ((Ptr (ClangString ())))
clang_getCursorKindSpelling a1 =
  let {a1' = fromIntegral a1} in 
  clang_getCursorKindSpelling'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4321 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorKindSpelling :: CursorKind -> IO (ClangString ())
unsafe_getCursorKindSpelling ck = clang_getCursorKindSpelling (fromIntegral (fromEnum ck)) >>= peek

getCursorKindSpelling :: ClangBase m => CursorKind -> ClangT s m (ClangString s)
getCursorKindSpelling = registerClangString . unsafe_getCursorKindSpelling

-- void clang_enableStackTraces(void);
foreign import ccall unsafe "clang-c/Index.h clang_enableStackTraces" enableStackTraces :: IO ()

-- typedef void *CXCompletionString;

-- | A semantic string that describes a code completion result.
--
-- A 'CompletionString' describes the formatting of a code completion
-- result as a single \"template\" of text that should be inserted into the
-- source buffer when a particular code completion result is selected.
-- Each semantic string is made up of some number of \"chunks\", each of which
-- contains some text along with a description of what that text means.
--
-- See 'ChunkKind' for more details about the role each kind of chunk plays.
newtype CompletionString s = CompletionString (Ptr ())
                             deriving (Eq, Ord, Typeable)

instance ClangValue CompletionString

-- typedef struct {
--   enum CXCursorKind CursorKind;
--   CXCompletionString CompletionString;
-- } CXCompletionResult;
data CompletionResult s = CompletionResult !CursorKind !(CompletionString s)
                          deriving (Eq, Ord, Typeable)

instance ClangValue CompletionResult

-- enum CXCompletionChunkKind {
--   CXCompletionChunk_Optional,
--   CXCompletionChunk_TypedText,
--   CXCompletionChunk_Text,
--   CXCompletionChunk_Placeholder,
--   CXCompletionChunk_Informative,
--   CXCompletionChunk_CurrentParameter,
--   CXCompletionChunk_LeftParen,
--   CXCompletionChunk_RightParen,
--   CXCompletionChunk_LeftBracket,
--   CXCompletionChunk_RightBracket,
--   CXCompletionChunk_LeftBrace,
--   CXCompletionChunk_RightBrace,
--   CXCompletionChunk_LeftAngle,
--   CXCompletionChunk_RightAngle,
--   CXCompletionChunk_Comma,
--   CXCompletionChunk_ResultType,
--   CXCompletionChunk_Colon,
--   CXCompletionChunk_SemiColon,
--   CXCompletionChunk_Equal,
--   CXCompletionChunk_HorizontalSpace,
--   CXCompletionChunk_VerticalSpace
-- };

-- | Describes a single piece of text within a code completion string.
--
-- * 'OptionalChunkKind': A code completion string that describes "optional" text that
--   could be a part of the template (but is not required).
--   This is the only kind of chunk that has a code completion
--   string for its representation. The code completion string describes an
--   describes an additional part of the template that is completely optional.
--   For example, optional chunks can be used to describe the placeholders for
--   arguments that match up with defaulted function parameters.
--
-- * 'TypedTextChunkKind': Text that a user would be expected to type to get this
--   code completion result.
--   There will be exactly one \"typed text\" chunk in a semantic string, which
--   will typically provide the spelling of a keyword or the name of a
--   declaration that could be used at the current code point. Clients are
--   expected to filter the code completion results based on the text in this
--   chunk.
--
-- * 'TextChunkKind': Text that should be inserted as part of a code completion result.
--   A \"text\" chunk represents text that is part of the template to be
--   inserted into user code should this particular code completion result
--   be selected.
--
-- * 'PlaceholderChunkKind': Placeholder text that should be replaced by the user.
--   A \"placeholder\" chunk marks a place where the user should insert text
--   into the code completion template. For example, placeholders might mark
--   the function parameters for a function declaration, to indicate that the
--   user should provide arguments for each of those parameters. The actual
--   text in a placeholder is a suggestion for the text to display before
--   the user replaces the placeholder with real code.
--
-- * 'InformativeChunkKind': Informative text that should be displayed but never inserted as
--   part of the template.
--   An \"informative\" chunk contains annotations that can be displayed to
--   help the user decide whether a particular code completion result is the
--   right option, but which is not part of the actual template to be inserted
--   by code completion.
--
-- * 'CurrentParameterChunkKind': Text that describes the current parameter
--   when code completion is referring to a function call, message send, or
--   template specialization.
--   A \"current parameter\" chunk occurs when code completion is providing
--   information about a parameter corresponding to the argument at the
--   code completion point. For example, given a function \"int add(int x, int y);\"
--   and the source code \"add(\", where the code completion point is after the
--   \"(\", the code completion string will contain a \"current parameter\" chunk
--   for \"int x\", indicating that the current argument will initialize that
--   parameter. After typing further, to \"add(17\", (where the code completion
--   point is after the \",\"), the code completion string will contain a
--   \"current parameter\" chunk to \"int y\".
--
-- * 'LeftParenChunkKind': A left parenthesis (\'(\'), used to initiate a function call or
--   signal the beginning of a function parameter list.
--
-- * 'RightParenChunkKind': A right parenthesis (\')\'), used to finish a function call or
--   signal the end of a function parameter list.
--
-- * 'LeftBracketChunkKind': A left bracket (\'[\').
--
-- * 'RightBracketChunkKind': A right bracket (\']\').
--
-- * 'LeftBraceChunkKind': A left brace (\'{\').
--
-- * 'RightBraceChunkKind': A right brace (\'}\').
--
-- * 'LeftAngleChunkKind': A left angle bracket (\'<\').
--
-- * 'RightAngleChunkKind': A right angle bracket (\'>\').
--
-- * 'CommaChunkKind': A comma separator (\',\').
--
-- * 'ResultTypeChunkKind': Text that specifies the result type of a given result.
--   This special kind of informative chunk is not meant to be inserted into
--   the text buffer. Rather, it is meant to illustrate the type that an
--   expression using the given completion string would have.
--
-- * 'ColonChunkKind': A colon (\':\').
--
-- * 'SemiColonChunkKind': A semicolon (\';\').
--
-- * 'EqualChunkKind': An \'=\' sign.
--
-- * 'HorizontalSpaceChunkKind': Horizontal space (\' \').
--
-- * 'VerticalSpaceChunkKind': Vertical space (\'\\n\'), after which it is generally
--   a good idea to perform indentation.
data ChunkKind = OptionalChunkKind
               | TypedTextChunkKind
               | TextChunkKind
               | PlaceholderChunkKind
               | InformativeChunkKind
               | CurrentParameterChunkKind
               | LeftParenChunkKind
               | RightParenChunkKind
               | LeftBracketChunkKind
               | RightBracketChunkKind
               | LeftBraceChunkKind
               | RightBraceChunkKind
               | LeftAngleChunkKind
               | RightAngleChunkKind
               | CommaChunkKind
               | ResultTypeChunkKind
               | ColonChunkKind
               | SemiColonChunkKind
               | EqualChunkKind
               | HorizontalSpaceChunkKind
               | VerticalSpaceChunkKind
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum ChunkKind where
  succ OptionalChunkKind = TypedTextChunkKind
  succ TypedTextChunkKind = TextChunkKind
  succ TextChunkKind = PlaceholderChunkKind
  succ PlaceholderChunkKind = InformativeChunkKind
  succ InformativeChunkKind = CurrentParameterChunkKind
  succ CurrentParameterChunkKind = LeftParenChunkKind
  succ LeftParenChunkKind = RightParenChunkKind
  succ RightParenChunkKind = LeftBracketChunkKind
  succ LeftBracketChunkKind = RightBracketChunkKind
  succ RightBracketChunkKind = LeftBraceChunkKind
  succ LeftBraceChunkKind = RightBraceChunkKind
  succ RightBraceChunkKind = LeftAngleChunkKind
  succ LeftAngleChunkKind = RightAngleChunkKind
  succ RightAngleChunkKind = CommaChunkKind
  succ CommaChunkKind = ResultTypeChunkKind
  succ ResultTypeChunkKind = ColonChunkKind
  succ ColonChunkKind = SemiColonChunkKind
  succ SemiColonChunkKind = EqualChunkKind
  succ EqualChunkKind = HorizontalSpaceChunkKind
  succ HorizontalSpaceChunkKind = VerticalSpaceChunkKind
  succ VerticalSpaceChunkKind = error "ChunkKind.succ: VerticalSpaceChunkKind has no successor"

  pred TypedTextChunkKind = OptionalChunkKind
  pred TextChunkKind = TypedTextChunkKind
  pred PlaceholderChunkKind = TextChunkKind
  pred InformativeChunkKind = PlaceholderChunkKind
  pred CurrentParameterChunkKind = InformativeChunkKind
  pred LeftParenChunkKind = CurrentParameterChunkKind
  pred RightParenChunkKind = LeftParenChunkKind
  pred LeftBracketChunkKind = RightParenChunkKind
  pred RightBracketChunkKind = LeftBracketChunkKind
  pred LeftBraceChunkKind = RightBracketChunkKind
  pred RightBraceChunkKind = LeftBraceChunkKind
  pred LeftAngleChunkKind = RightBraceChunkKind
  pred RightAngleChunkKind = LeftAngleChunkKind
  pred CommaChunkKind = RightAngleChunkKind
  pred ResultTypeChunkKind = CommaChunkKind
  pred ColonChunkKind = ResultTypeChunkKind
  pred SemiColonChunkKind = ColonChunkKind
  pred EqualChunkKind = SemiColonChunkKind
  pred HorizontalSpaceChunkKind = EqualChunkKind
  pred VerticalSpaceChunkKind = HorizontalSpaceChunkKind
  pred OptionalChunkKind = error "ChunkKind.pred: OptionalChunkKind has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from VerticalSpaceChunkKind

  fromEnum OptionalChunkKind = 0
  fromEnum TypedTextChunkKind = 1
  fromEnum TextChunkKind = 2
  fromEnum PlaceholderChunkKind = 3
  fromEnum InformativeChunkKind = 4
  fromEnum CurrentParameterChunkKind = 5
  fromEnum LeftParenChunkKind = 6
  fromEnum RightParenChunkKind = 7
  fromEnum LeftBracketChunkKind = 8
  fromEnum RightBracketChunkKind = 9
  fromEnum LeftBraceChunkKind = 10
  fromEnum RightBraceChunkKind = 11
  fromEnum LeftAngleChunkKind = 12
  fromEnum RightAngleChunkKind = 13
  fromEnum CommaChunkKind = 14
  fromEnum ResultTypeChunkKind = 15
  fromEnum ColonChunkKind = 16
  fromEnum SemiColonChunkKind = 17
  fromEnum EqualChunkKind = 18
  fromEnum HorizontalSpaceChunkKind = 19
  fromEnum VerticalSpaceChunkKind = 20

  toEnum 0 = OptionalChunkKind
  toEnum 1 = TypedTextChunkKind
  toEnum 2 = TextChunkKind
  toEnum 3 = PlaceholderChunkKind
  toEnum 4 = InformativeChunkKind
  toEnum 5 = CurrentParameterChunkKind
  toEnum 6 = LeftParenChunkKind
  toEnum 7 = RightParenChunkKind
  toEnum 8 = LeftBracketChunkKind
  toEnum 9 = RightBracketChunkKind
  toEnum 10 = LeftBraceChunkKind
  toEnum 11 = RightBraceChunkKind
  toEnum 12 = LeftAngleChunkKind
  toEnum 13 = RightAngleChunkKind
  toEnum 14 = CommaChunkKind
  toEnum 15 = ResultTypeChunkKind
  toEnum 16 = ColonChunkKind
  toEnum 17 = SemiColonChunkKind
  toEnum 18 = EqualChunkKind
  toEnum 19 = HorizontalSpaceChunkKind
  toEnum 20 = VerticalSpaceChunkKind
  toEnum unmatched = error ("ChunkKind.toEnum: Cannot match " ++ show unmatched)

{-# LINE 4490 "src/Clang/Internal/FFI.chs" #-}


-- enum CXCompletionChunkKind
-- clang_getCompletionChunkKind(CXCompletionString completion_string,
--                              unsigned chunk_number);
clang_getCompletionChunkKind :: (Ptr ()) -> (Int) -> IO ((Int))
clang_getCompletionChunkKind a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getCompletionChunkKind'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4495 "src/Clang/Internal/FFI.chs" #-}

getCompletionChunkKind :: CompletionString s -> Int -> IO ChunkKind
getCompletionChunkKind (CompletionString ptr) i = clang_getCompletionChunkKind ptr i >>= return . toEnum

-- CXString
-- clang_getCompletionChunkText(CXCompletionString completion_string,
--                              unsigned chunk_number);
clang_getCompletionChunkText :: (Ptr ()) -> (Int) -> IO ((Ptr (ClangString ())))
clang_getCompletionChunkText a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getCompletionChunkText'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4502 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCompletionChunkText :: CompletionString s -> Int -> IO (ClangString ())
unsafe_getCompletionChunkText (CompletionString ptr) i = clang_getCompletionChunkText ptr i >>= peek

getCompletionChunkText :: ClangBase m => CompletionString s' -> Int -> ClangT s m (ClangString s)
getCompletionChunkText = (registerClangString .) . unsafe_getCompletionChunkText

-- CXCompletionString
-- clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
--                                          unsigned chunk_number);
clang_getCompletionChunkCompletionString :: (Ptr ()) -> (Int) -> IO ((Ptr ()))
clang_getCompletionChunkCompletionString a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getCompletionChunkCompletionString'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 4512 "src/Clang/Internal/FFI.chs" #-}

getCompletionChunkCompletionString :: CompletionString s -> Int -> IO (CompletionString s')
getCompletionChunkCompletionString (CompletionString ptr) i =
  clang_getCompletionChunkCompletionString ptr i >>= return . CompletionString

-- unsigned
-- clang_getNumCompletionChunks(CXCompletionString completion_string);
clang_getNumCompletionChunks :: (Ptr ()) -> IO ((Int))
clang_getNumCompletionChunks a1 =
  let {a1' = id a1} in 
  clang_getNumCompletionChunks'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4519 "src/Clang/Internal/FFI.chs" #-}

getNumCompletionChunks :: CompletionString s -> IO Int
getNumCompletionChunks (CompletionString ptr) = clang_getNumCompletionChunks ptr

-- unsigned
-- clang_getCompletionPriority(CXCompletionString completion_string);
clang_getCompletionPriority :: (Ptr ()) -> IO ((Int))
clang_getCompletionPriority a1 =
  let {a1' = id a1} in 
  clang_getCompletionPriority'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4525 "src/Clang/Internal/FFI.chs" #-}

getCompletionPriority :: CompletionString s -> IO Int
getCompletionPriority (CompletionString ptr) = clang_getCompletionPriority ptr

-- enum CXAvailabilityKind
-- clang_getCompletionAvailability(CXCompletionString completion_string);
clang_getCompletionAvailability :: (Ptr ()) -> IO ((Int))
clang_getCompletionAvailability a1 =
  let {a1' = id a1} in 
  clang_getCompletionAvailability'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4531 "src/Clang/Internal/FFI.chs" #-}

getCompletionAvailability :: CompletionString s ->  IO AvailabilityKind
getCompletionAvailability (CompletionString ptr) = clang_getCompletionAvailability ptr >>= return . toEnum

-- unsigned clang_getCompletionNumAnnotations(CXCompletionString completion_string);
clang_getCompletionNumAnnotations :: (Ptr ()) -> IO ((Int))
clang_getCompletionNumAnnotations a1 =
  let {a1' = id a1} in 
  clang_getCompletionNumAnnotations'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4536 "src/Clang/Internal/FFI.chs" #-}

getCompletionNumAnnotations :: CompletionString s -> IO Int
getCompletionNumAnnotations (CompletionString ptr) = clang_getCompletionNumAnnotations ptr

-- CXString clang_getCompletionAnnotation(CXCompletionString completion_string,
--                                        unsigned annotation_number);
clang_getCompletionAnnotation :: (Ptr ()) -> (Int) -> IO ((Ptr (ClangString ())))
clang_getCompletionAnnotation a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getCompletionAnnotation'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4542 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCompletionAnnotation :: CompletionString s -> Int -> IO (ClangString ())
unsafe_getCompletionAnnotation (CompletionString ptr) i = clang_getCompletionAnnotation ptr i >>= peek

getCompletionAnnotation :: ClangBase m => CompletionString s' -> Int -> ClangT s m (ClangString s)
getCompletionAnnotation = (registerClangString .) . unsafe_getCompletionAnnotation

-- CXString clang_getCompletionParent(CXCompletionString completion_string,
--                                    enum CXCursorKind *kind);
clang_getCompletionParent :: (Ptr ()) -> (CInt) -> IO ((Ptr (ClangString ())))
clang_getCompletionParent a1 a2 =
  let {a1' = id a1} in 
  (C2HSImp.with . fromIntegral) a2 $ \a2' -> 
  clang_getCompletionParent'_ a1' a2' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4551 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCompletionParent :: CompletionString s  -> IO (ClangString ())
unsafe_getCompletionParent (CompletionString ptr) = clang_getCompletionParent ptr 0 >>= peek

getCompletionParent :: ClangBase m => CompletionString s' -> ClangT s m (ClangString s)
getCompletionParent = registerClangString . unsafe_getCompletionParent

-- CXString clang_getCompletionBriefComment(CXCompletionString completion_string);
clang_getCompletionBriefComment :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_getCompletionBriefComment a1 =
  let {a1' = id a1} in 
  clang_getCompletionBriefComment'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4559 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCompletionBriefComment :: CompletionString s  -> IO (ClangString ())
unsafe_getCompletionBriefComment (CompletionString ptr) = clang_getCompletionBriefComment ptr >>= peek

getCompletionBriefComment :: ClangBase m => CompletionString s' -> ClangT s m (ClangString s)
getCompletionBriefComment = registerClangString . unsafe_getCompletionBriefComment

-- CXCompletionString clang_getCursorCompletionString(CXCursor cursor);
clang_getCursorCompletionString :: (Cursor a) -> IO ((Ptr (ClangString ())))
clang_getCursorCompletionString a1 =
  withVoided a1 $ \a1' -> 
  clang_getCursorCompletionString'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4567 "src/Clang/Internal/FFI.chs" #-}

unsafe_getCursorCompletionString :: Cursor s'  -> IO (ClangString ())
unsafe_getCursorCompletionString c =
  clang_getCursorCompletionString c >>= peek

getCursorCompletionString :: ClangBase m => Cursor s' -> ClangT s m (CompletionString s)
getCursorCompletionString c =
  unsafeCoerce <$> (liftIO $ unsafe_getCursorCompletionString c)

-- enum CXCodeComplete_Flags {
--   CXCodeComplete_IncludeMacros = 0x01,
--   CXCodeComplete_IncludeCodePatterns = 0x02,
--   CXCodeComplete_IncludeBriefComments = 0x04
-- };

-- | Flags that can be used to modify the behavior of 'codeCompleteAt'.
--
-- * 'IncludeMacros': Whether to include macros within the set of code
--   completions returned.
--
-- * 'IncludeCodePatterns': Whether to include code patterns for language constructs
--   within the set of code completions, e.g., 'for' loops.
--
-- * 'IncludeBriefComments': Whether to include brief documentation within the set of code
--   completions returned.
data CodeCompleteFlags = IncludeMacros
                       | IncludeCodePatterns
                       | IncludeBriefComments
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CodeCompleteFlags where
  succ IncludeMacros = IncludeCodePatterns
  succ IncludeCodePatterns = IncludeBriefComments
  succ IncludeBriefComments = error "CodeCompleteFlags.succ: IncludeBriefComments has no successor"

  pred IncludeCodePatterns = IncludeMacros
  pred IncludeBriefComments = IncludeCodePatterns
  pred IncludeMacros = error "CodeCompleteFlags.pred: IncludeMacros has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from IncludeBriefComments

  fromEnum IncludeMacros = 1
  fromEnum IncludeCodePatterns = 2
  fromEnum IncludeBriefComments = 4

  toEnum 1 = IncludeMacros
  toEnum 2 = IncludeCodePatterns
  toEnum 4 = IncludeBriefComments
  toEnum unmatched = error ("CodeCompleteFlags.toEnum: Cannot match " ++ show unmatched)

{-# LINE 4598 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags CodeCompleteFlags where
  toBit IncludeMacros        = 0x01
  toBit IncludeCodePatterns  = 0x02
  toBit IncludeBriefComments = 0x04

-- unsigned clang_defaultCodeCompleteOptions(void);
defaultCodeCompleteOptions :: IO ((Int))
defaultCodeCompleteOptions =
  defaultCodeCompleteOptions'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4606 "src/Clang/Internal/FFI.chs" #-}


-- typedef struct {
--   CXCompletionResult *Results;
--   unsigned NumResults;
-- } CXCodeCompleteResults;

-- | The results of code completion.
newtype CodeCompleteResults s = CodeCompleteResults { unCodeCompleteResults :: Ptr () }
                                deriving (Eq, Ord, Typeable)

instance ClangValue CodeCompleteResults

-- void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
clang_disposeCodeCompleteResults :: (Ptr ()) -> IO ()
clang_disposeCodeCompleteResults a1 =
  let {a1' = id a1} in 
  clang_disposeCodeCompleteResults'_ a1' >>
  return ()

{-# LINE 4620 "src/Clang/Internal/FFI.chs" #-}

disposeCodeCompleteResults :: CodeCompleteResults s -> IO ()
disposeCodeCompleteResults rs = clang_disposeCodeCompleteResults (unCodeCompleteResults rs)

registerCodeCompleteResults :: ClangBase m => IO (CodeCompleteResults ())
                            -> ClangT s m (CodeCompleteResults s)
registerCodeCompleteResults action = do
  (_, ccrs) <- clangAllocate (action >>= return . unsafeCoerce)
                             disposeCodeCompleteResults
  return ccrs
{-# INLINEABLE registerCodeCompleteResults #-}

-- CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
--                                             const char *complete_filename,
--                                             unsigned complete_line,
--                                             unsigned complete_column,
--                                             struct CXUnsavedFile *unsaved_files,
--                                             unsigned num_unsaved_files,
--                                             unsigned options);
clang_codeCompleteAt :: (Ptr ()) -> (CString) -> (Int) -> (Int) -> (Ptr ()) -> (Int) -> (Int) -> IO ((Ptr ()))
clang_codeCompleteAt a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = id a1} in 
  (flip ($)) a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = id a5} in 
  let {a6' = fromIntegral a6} in 
  let {a7' = fromIntegral a7} in 
  clang_codeCompleteAt'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 4639 "src/Clang/Internal/FFI.chs" #-}

unsafe_codeCompleteAt :: TranslationUnit s -> String -> Int -> Int -> Ptr CUnsavedFile -> Int -> Int -> IO (CodeCompleteResults ())
unsafe_codeCompleteAt tu s i1 i2 ufs nufs i3 =
  withCString s (\sPtr -> clang_codeCompleteAt (unTranslationUnit tu) sPtr i1 i2 (castPtr ufs) nufs i3 >>= return . CodeCompleteResults)

codeCompleteAt :: ClangBase m => TranslationUnit s' -> String -> Int -> Int
               -> DV.Vector UnsavedFile -> Int -> ClangT s m (CodeCompleteResults s)
codeCompleteAt tu f l c ufs os =
  registerCodeCompleteResults $
    withUnsavedFiles ufs $ \ufsPtr ufsLen ->
      unsafe_codeCompleteAt tu f l c ufsPtr ufsLen os

-- This function, along with codeCompleteGetResult, exist to allow iteration over
-- the completion strings at the Haskell level. They're (obviously) not real
-- libclang functions.
codeCompleteGetNumResults' :: (Ptr ()) -> IO ((Int))
codeCompleteGetNumResults' a1 =
  let {a1' = id a1} in 
  codeCompleteGetNumResults''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4654 "src/Clang/Internal/FFI.chs" #-}

codeCompleteGetNumResults :: CodeCompleteResults s -> IO Int
codeCompleteGetNumResults rs = codeCompleteGetNumResults' (unCodeCompleteResults rs)

-- We don't need to register CompletionStrings; they're always owned by another object.
-- They still need to be scoped, though.
codeCompleteGetResult' :: (Ptr ()) -> (CInt) -> (Ptr (Ptr ())) -> IO ((CInt))
codeCompleteGetResult' a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  codeCompleteGetResult''_ a1' a2' a3' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 4660 "src/Clang/Internal/FFI.chs" #-}

unsafe_codeCompleteGetResult :: CodeCompleteResults s -> Int -> IO (CompletionString (), CursorKind)
unsafe_codeCompleteGetResult rs idx = do
 sPtr <- mallocBytes (sizeOf (undefined :: (Ptr (Ptr ()))))
 kind <- codeCompleteGetResult' (unCodeCompleteResults rs) (fromIntegral idx) (castPtr sPtr)
 return ((CompletionString sPtr), toEnum (fromIntegral kind))

codeCompleteGetResult :: ClangBase m => CodeCompleteResults s' -> Int
                      -> ClangT s m (CompletionString s, CursorKind)
codeCompleteGetResult rs n = do
  (string, kind) <- liftIO $ unsafe_codeCompleteGetResult rs n
  return (unsafeCoerce string, kind)

-- void clang_sortCodeCompletionResults(CXCompletionResult *Results,
--                                      unsigned NumResults);
clang_sortCodeCompletionResults :: (Ptr ()) -> (Int) -> IO ()
clang_sortCodeCompletionResults a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_sortCodeCompletionResults'_ a1' a2' >>
  return ()

{-# LINE 4675 "src/Clang/Internal/FFI.chs" #-}

sortCodeCompletionResults :: CodeCompleteResults s -> IO ()
sortCodeCompletionResults rs =
  let results = unCodeCompleteResults rs in
  do
    rPtr <- peek (results `plusPtr` offsetCXCodeCompleteResultsResults)
    numRs <- peek (results `plusPtr` offsetCXCodeCompleteResultsNumResults)
    clang_sortCodeCompletionResults rPtr numRs

-- unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
clang_codeCompleteGetNumDiagnostics :: (Ptr ()) -> IO ((Int))
clang_codeCompleteGetNumDiagnostics a1 =
  let {a1' = id a1} in 
  clang_codeCompleteGetNumDiagnostics'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4685 "src/Clang/Internal/FFI.chs" #-}

codeCompleteGetNumDiagnostics :: CodeCompleteResults s -> IO Int
codeCompleteGetNumDiagnostics rs = clang_codeCompleteGetNumDiagnostics (unCodeCompleteResults rs)

-- CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
--                                              unsigned Index);
clang_codeCompleteGetDiagnostic :: (Ptr ()) -> (Int) -> IO ((Ptr ()))
clang_codeCompleteGetDiagnostic a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_codeCompleteGetDiagnostic'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 4691 "src/Clang/Internal/FFI.chs" #-}

unsafe_codeCompleteGetDiagnostic :: CodeCompleteResults s -> Int -> IO (Diagnostic ())
unsafe_codeCompleteGetDiagnostic rs idx =
   clang_codeCompleteGetDiagnostic (unCodeCompleteResults rs) idx >>= return . mkDiagnostic

codeCompleteGetDiagnostic :: ClangBase m => CodeCompleteResults s' -> Int
                          -> ClangT s m (Diagnostic s)
codeCompleteGetDiagnostic = (registerDiagnostic .) . unsafe_codeCompleteGetDiagnostic

-- enum CXCompletionContext {
--   CXCompletionContext_Unexposed = 0,
--   CXCompletionContext_AnyType = 1 << 0,
--   CXCompletionContext_AnyValue = 1 << 1,
--   CXCompletionContext_ObjCObjectValue = 1 << 2,
--   CXCompletionContext_ObjCSelectorValue = 1 << 3,
--   CXCompletionContext_CXXClassTypeValue = 1 << 4,
--   CXCompletionContext_DotMemberAccess = 1 << 5,
--   CXCompletionContext_ArrowMemberAccess = 1 << 6,
--   CXCompletionContext_ObjCPropertyAccess = 1 << 7,
--   CXCompletionContext_EnumTag = 1 << 8,
--   CXCompletionContext_UnionTag = 1 << 9,
--   CXCompletionContext_StructTag = 1 << 10,
--   CXCompletionContext_ClassTag = 1 << 11,
--   CXCompletionContext_Namespace = 1 << 12,
--   CXCompletionContext_NestedNameSpecifier = 1 << 13,
--   CXCompletionContext_ObjCInterface = 1 << 14,
--   CXCompletionContext_ObjCProtocol = 1 << 15,
--   CXCompletionContext_ObjCCategory = 1 << 16,
--   CXCompletionContext_ObjCInstanceMessage = 1 << 17,
--   CXCompletionContext_ObjCClassMessage = 1 << 18,
--   CXCompletionContext_ObjCSelectorName = 1 << 19,
--   CXCompletionContext_MacroName = 1 << 20,
--   CXCompletionContext_NaturalLanguage = 1 << 21,
--   CXCompletionContext_Unknown = ((1 << 22) - 1) -- Set all
                            --   contexts... Not a real value.
-- };

-- | Contexts under which completion may occur. Multiple contexts may be
-- present at the same time.
--
-- * 'UnexposedCompletionContext': The context for completions is unexposed,
--   as only Clang results should be included.
--
-- * 'AnyTypeCompletionContext': Completions for any possible type should be
--   included in the results.
--
-- * 'AnyValueCompletionContext': Completions for any possible value (variables,
--   function calls, etc.) should be included in the results.
--
-- * 'ObjCObjectValueCompletionContext': Completions for values that resolve to
--   an Objective-C object should be included in the results.
--
-- * 'ObjCSelectorValueCompletionContext': Completions for values that resolve
--   to an Objective-C selector should be included in the results.
--
-- * 'CXXClassTypeValueCompletionContext': Completions for values that resolve
--   to a C++ class type should be included in the results.
--
-- * 'DotMemberAccessCompletionContext': Completions for fields of the member
--   being accessed using the dot operator should be included in the results.
--
-- * 'ArrowMemberAccessCompletionContext': Completions for fields of the member
--   being accessed using the arrow operator should be included in the results.
--
-- * 'ObjCPropertyAccessCompletionContext': Completions for properties of the
--   Objective-C object being accessed using the dot operator should be included in the results.
--
-- * 'EnumTagCompletionContext': Completions for enum tags should be included in the results.
--
-- * 'UnionTagCompletionContext': Completions for union tags should be included in the results.
--
-- * 'StructTagCompletionContext': Completions for struct tags should be included in the
--   results.
--
-- * 'ClassTagCompletionContext': Completions for C++ class names should be included in the
--   results.
--
-- * 'NamespaceCompletionContext': Completions for C++ namespaces and namespace aliases should
--   be included in the results.
--
-- * 'NestedNameSpecifierCompletionContext': Completions for C++ nested name specifiers should
--   be included in the results.
--
-- * 'ObjCInterfaceCompletionContext': Completions for Objective-C interfaces (classes) should
--   be included in the results.
--
-- * 'ObjCProtocolCompletionContext': Completions for Objective-C protocols should be included
--   in the results.
--
-- * 'ObjCCategoryCompletionContext': Completions for Objective-C categories should be included
--   in the results.
--
-- * 'ObjCInstanceMessageCompletionContext': Completions for Objective-C instance messages
--   should be included in the results.
--
-- * 'ObjCClassMessageCompletionContext': Completions for Objective-C class messages should be
--   included in the results.
--
-- * 'ObjCSelectorNameCompletionContext': Completions for Objective-C selector names should be
--   included in the results.
--
-- * 'MacroNameCompletionContext': Completions for preprocessor macro names should be included
--   in the results.
--
-- * 'NaturalLanguageCompletionContext': Natural language completions should be included in the
--   results.
data CompletionContext = UnexposedCompletionContext
                       | AnyTypeCompletionContext
                       | AnyValueCompletionContext
                       | ObjCObjectValueCompletionContext
                       | ObjCSelectorValueCompletionContext
                       | CXXClassTypeValueCompletionContext
                       | DotMemberAccessCompletionContext
                       | ArrowMemberAccessCompletionContext
                       | ObjCPropertyAccessCompletionContext
                       | EnumTagCompletionContext
                       | UnionTagCompletionContext
                       | StructTagCompletionContext
                       | ClassTagCompletionContext
                       | NamespaceCompletionContext
                       | NestedNameSpecifierCompletionContext
                       | ObjCInterfaceCompletionContext
                       | ObjCProtocolCompletionContext
                       | ObjCCategoryCompletionContext
                       | ObjCInstanceMessageCompletionContext
                       | ObjCClassMessageCompletionContext
                       | ObjCSelectorNameCompletionContext
                       | MacroNameCompletionContext
                       | NaturalLanguageCompletionContext
  deriving (Bounded,Eq,Ord,Read,Show,Typeable)
instance Enum CompletionContext where
  succ UnexposedCompletionContext = AnyTypeCompletionContext
  succ AnyTypeCompletionContext = AnyValueCompletionContext
  succ AnyValueCompletionContext = ObjCObjectValueCompletionContext
  succ ObjCObjectValueCompletionContext = ObjCSelectorValueCompletionContext
  succ ObjCSelectorValueCompletionContext = CXXClassTypeValueCompletionContext
  succ CXXClassTypeValueCompletionContext = DotMemberAccessCompletionContext
  succ DotMemberAccessCompletionContext = ArrowMemberAccessCompletionContext
  succ ArrowMemberAccessCompletionContext = ObjCPropertyAccessCompletionContext
  succ ObjCPropertyAccessCompletionContext = EnumTagCompletionContext
  succ EnumTagCompletionContext = UnionTagCompletionContext
  succ UnionTagCompletionContext = StructTagCompletionContext
  succ StructTagCompletionContext = ClassTagCompletionContext
  succ ClassTagCompletionContext = NamespaceCompletionContext
  succ NamespaceCompletionContext = NestedNameSpecifierCompletionContext
  succ NestedNameSpecifierCompletionContext = ObjCInterfaceCompletionContext
  succ ObjCInterfaceCompletionContext = ObjCProtocolCompletionContext
  succ ObjCProtocolCompletionContext = ObjCCategoryCompletionContext
  succ ObjCCategoryCompletionContext = ObjCInstanceMessageCompletionContext
  succ ObjCInstanceMessageCompletionContext = ObjCClassMessageCompletionContext
  succ ObjCClassMessageCompletionContext = ObjCSelectorNameCompletionContext
  succ ObjCSelectorNameCompletionContext = MacroNameCompletionContext
  succ MacroNameCompletionContext = NaturalLanguageCompletionContext
  succ NaturalLanguageCompletionContext = error "CompletionContext.succ: NaturalLanguageCompletionContext has no successor"

  pred AnyTypeCompletionContext = UnexposedCompletionContext
  pred AnyValueCompletionContext = AnyTypeCompletionContext
  pred ObjCObjectValueCompletionContext = AnyValueCompletionContext
  pred ObjCSelectorValueCompletionContext = ObjCObjectValueCompletionContext
  pred CXXClassTypeValueCompletionContext = ObjCSelectorValueCompletionContext
  pred DotMemberAccessCompletionContext = CXXClassTypeValueCompletionContext
  pred ArrowMemberAccessCompletionContext = DotMemberAccessCompletionContext
  pred ObjCPropertyAccessCompletionContext = ArrowMemberAccessCompletionContext
  pred EnumTagCompletionContext = ObjCPropertyAccessCompletionContext
  pred UnionTagCompletionContext = EnumTagCompletionContext
  pred StructTagCompletionContext = UnionTagCompletionContext
  pred ClassTagCompletionContext = StructTagCompletionContext
  pred NamespaceCompletionContext = ClassTagCompletionContext
  pred NestedNameSpecifierCompletionContext = NamespaceCompletionContext
  pred ObjCInterfaceCompletionContext = NestedNameSpecifierCompletionContext
  pred ObjCProtocolCompletionContext = ObjCInterfaceCompletionContext
  pred ObjCCategoryCompletionContext = ObjCProtocolCompletionContext
  pred ObjCInstanceMessageCompletionContext = ObjCCategoryCompletionContext
  pred ObjCClassMessageCompletionContext = ObjCInstanceMessageCompletionContext
  pred ObjCSelectorNameCompletionContext = ObjCClassMessageCompletionContext
  pred MacroNameCompletionContext = ObjCSelectorNameCompletionContext
  pred NaturalLanguageCompletionContext = MacroNameCompletionContext
  pred UnexposedCompletionContext = error "CompletionContext.pred: UnexposedCompletionContext has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from NaturalLanguageCompletionContext

  fromEnum UnexposedCompletionContext = 0
  fromEnum AnyTypeCompletionContext = 1
  fromEnum AnyValueCompletionContext = 2
  fromEnum ObjCObjectValueCompletionContext = 4
  fromEnum ObjCSelectorValueCompletionContext = 8
  fromEnum CXXClassTypeValueCompletionContext = 16
  fromEnum DotMemberAccessCompletionContext = 32
  fromEnum ArrowMemberAccessCompletionContext = 64
  fromEnum ObjCPropertyAccessCompletionContext = 128
  fromEnum EnumTagCompletionContext = 256
  fromEnum UnionTagCompletionContext = 512
  fromEnum StructTagCompletionContext = 1024
  fromEnum ClassTagCompletionContext = 2048
  fromEnum NamespaceCompletionContext = 4096
  fromEnum NestedNameSpecifierCompletionContext = 8192
  fromEnum ObjCInterfaceCompletionContext = 16384
  fromEnum ObjCProtocolCompletionContext = 32768
  fromEnum ObjCCategoryCompletionContext = 65536
  fromEnum ObjCInstanceMessageCompletionContext = 131072
  fromEnum ObjCClassMessageCompletionContext = 262144
  fromEnum ObjCSelectorNameCompletionContext = 524288
  fromEnum MacroNameCompletionContext = 1048576
  fromEnum NaturalLanguageCompletionContext = 2097152

  toEnum 0 = UnexposedCompletionContext
  toEnum 1 = AnyTypeCompletionContext
  toEnum 2 = AnyValueCompletionContext
  toEnum 4 = ObjCObjectValueCompletionContext
  toEnum 8 = ObjCSelectorValueCompletionContext
  toEnum 16 = CXXClassTypeValueCompletionContext
  toEnum 32 = DotMemberAccessCompletionContext
  toEnum 64 = ArrowMemberAccessCompletionContext
  toEnum 128 = ObjCPropertyAccessCompletionContext
  toEnum 256 = EnumTagCompletionContext
  toEnum 512 = UnionTagCompletionContext
  toEnum 1024 = StructTagCompletionContext
  toEnum 2048 = ClassTagCompletionContext
  toEnum 4096 = NamespaceCompletionContext
  toEnum 8192 = NestedNameSpecifierCompletionContext
  toEnum 16384 = ObjCInterfaceCompletionContext
  toEnum 32768 = ObjCProtocolCompletionContext
  toEnum 65536 = ObjCCategoryCompletionContext
  toEnum 131072 = ObjCInstanceMessageCompletionContext
  toEnum 262144 = ObjCClassMessageCompletionContext
  toEnum 524288 = ObjCSelectorNameCompletionContext
  toEnum 1048576 = MacroNameCompletionContext
  toEnum 2097152 = NaturalLanguageCompletionContext
  toEnum unmatched = error ("CompletionContext.toEnum: Cannot match " ++ show unmatched)

{-# LINE 4823 "src/Clang/Internal/FFI.chs" #-}


instance BitFlags CompletionContext where
  type FlagInt CompletionContext             = Int64
  toBit UnexposedCompletionContext           = 0x0
  toBit AnyTypeCompletionContext             = 0x1
  toBit AnyValueCompletionContext            = 0x2
  toBit ObjCObjectValueCompletionContext     = 0x4
  toBit ObjCSelectorValueCompletionContext   = 0x8
  toBit CXXClassTypeValueCompletionContext   = 0x10
  toBit DotMemberAccessCompletionContext     = 0x20
  toBit ArrowMemberAccessCompletionContext   = 0x40
  toBit ObjCPropertyAccessCompletionContext  = 0x80
  toBit EnumTagCompletionContext             = 0x100
  toBit UnionTagCompletionContext            = 0x200
  toBit StructTagCompletionContext           = 0x400
  toBit ClassTagCompletionContext            = 0x800
  toBit NamespaceCompletionContext           = 0x1000
  toBit NestedNameSpecifierCompletionContext = 0x2000
  toBit ObjCInterfaceCompletionContext       = 0x4000
  toBit ObjCProtocolCompletionContext        = 0x8000
  toBit ObjCCategoryCompletionContext        = 0x10000
  toBit ObjCInstanceMessageCompletionContext = 0x20000
  toBit ObjCClassMessageCompletionContext    = 0x40000
  toBit ObjCSelectorNameCompletionContext    = 0x80000
  toBit MacroNameCompletionContext           = 0x100000
  toBit NaturalLanguageCompletionContext     = 0x200000

-- unsigned long long clang_codeCompleteGetContexts(CXCodeCompleteResults *Results);
clang_codeCompleteGetContexts :: (Ptr ()) -> IO ((Int64))
clang_codeCompleteGetContexts a1 =
  let {a1' = id a1} in 
  clang_codeCompleteGetContexts'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4852 "src/Clang/Internal/FFI.chs" #-}

codeCompleteGetContexts :: CodeCompleteResults s -> IO Int64
codeCompleteGetContexts rs = clang_codeCompleteGetContexts (unCodeCompleteResults rs)

-- enum CXCursorKind clang_codeCompleteGetContainerKind(CXCodeCompleteResults *Results,
--                                                      unsigned *IsIncomplete);
clang_codeCompleteGetContainerKind :: (Ptr ()) -> (Ptr CUInt) -> IO ((Int))
clang_codeCompleteGetContainerKind a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  clang_codeCompleteGetContainerKind'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 4858 "src/Clang/Internal/FFI.chs" #-}

codeCompleteGetContainerKind :: CodeCompleteResults s -> IO (CursorKind, Bool)
codeCompleteGetContainerKind rs =
  alloca (\(iPtr :: (Ptr CUInt)) -> do
     k <- clang_codeCompleteGetContainerKind (unCodeCompleteResults rs) iPtr
     bool <- peek iPtr
     return (toEnum k, toBool ((fromIntegral bool) :: Int)))

-- CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
clang_codeCompleteGetContainerUSR :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_codeCompleteGetContainerUSR a1 =
  let {a1' = id a1} in 
  clang_codeCompleteGetContainerUSR'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4867 "src/Clang/Internal/FFI.chs" #-}

unsafe_codeCompleteGetContainerUSR :: CodeCompleteResults s -> IO (ClangString ())
unsafe_codeCompleteGetContainerUSR rs = clang_codeCompleteGetContainerUSR (unCodeCompleteResults rs) >>= peek

codeCompleteGetContainerUSR :: ClangBase m => CodeCompleteResults s' -> ClangT s m (ClangString s)
codeCompleteGetContainerUSR = registerClangString . unsafe_codeCompleteGetContainerUSR

-- CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
clang_codeCompleteGetObjCSelector :: (Ptr ()) -> IO ((Ptr (ClangString ())))
clang_codeCompleteGetObjCSelector a1 =
  let {a1' = id a1} in 
  clang_codeCompleteGetObjCSelector'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4875 "src/Clang/Internal/FFI.chs" #-}

unsafe_codeCompleteGetObjCSelector :: CodeCompleteResults s -> IO (ClangString ())
unsafe_codeCompleteGetObjCSelector rs = clang_codeCompleteGetObjCSelector (unCodeCompleteResults rs) >>= peek

codeCompleteGetObjCSelector :: ClangBase m => CodeCompleteResults s' -> ClangT s m (ClangString s)
codeCompleteGetObjCSelector = registerClangString . unsafe_codeCompleteGetObjCSelector

-- CXString clang_getClangVersion();
clang_getClangVersion :: IO ((Ptr (ClangString ())))
clang_getClangVersion =
  clang_getClangVersion'_ >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 4883 "src/Clang/Internal/FFI.chs" #-}

unsafe_getClangVersion :: IO (ClangString ())
unsafe_getClangVersion = clang_getClangVersion >>= peek

getClangVersion :: ClangBase m => ClangT s m (ClangString s)
getClangVersion = registerClangString $ unsafe_getClangVersion

-- -- void clang_toggleCrashRecovery(unsigned isEnabled);
toggleCrashRecovery' :: (Int) -> IO ()
toggleCrashRecovery' a1 =
  let {a1' = fromIntegral a1} in 
  toggleCrashRecovery''_ a1' >>
  return ()

{-# LINE 4891 "src/Clang/Internal/FFI.chs" #-}

toggleCrashRecovery :: Bool -> IO ()
toggleCrashRecovery b = toggleCrashRecovery' (fromBool b)

data Inclusion s = Inclusion !(File s) !(SourceLocation s) !Bool
                   deriving (Eq, Ord, Typeable)

instance ClangValue Inclusion

instance Storable (Inclusion s) where
    sizeOf _ = sizeOfInclusion
    {-# INLINE sizeOf #-}

    alignment _ = alignOfInclusion
    {-# INLINE alignment #-}

    peek p = do
      let fromCUChar = fromIntegral :: Num b => CUChar -> b
      file <- File <$> peekByteOff p offsetInclusionInclusion
      sl <- peekByteOff p offsetInclusionLocation
      isDirect :: Int <- fromCUChar <$> peekByteOff p offsetInclusionIsDirect
      return $! Inclusion file sl (if isDirect == 0 then False else True)
    {-# INLINE peek #-}

    poke p (Inclusion (File file) sl isDirect) = do
      let toCUChar = fromIntegral :: Integral a => a -> CUChar
      pokeByteOff p offsetInclusionInclusion file
      pokeByteOff p offsetInclusionLocation sl
      pokeByteOff p offsetInclusionIsDirect
           (toCUChar $ if isDirect then 1 :: Int else 0)
    {-# INLINE poke #-}

type InclusionList s = DVS.Vector (Inclusion s)
instance ClangValueList Inclusion
data UnsafeInclusionList = UnsafeInclusionList !(Ptr ()) !Int

-- void freeInclusions(struct Inclusion* inclusions);
freeInclusionList' :: (Ptr ()) -> IO ()
freeInclusionList' a1 =
  let {a1' = id a1} in 
  freeInclusionList''_ a1' >>
  return ()

{-# LINE 4928 "src/Clang/Internal/FFI.chs" #-}

freeInclusions :: InclusionList s -> IO ()
freeInclusions is =
  let (isPtr, n) = fromInclusionList is in
  freeInclusionList' isPtr

registerInclusionList :: ClangBase m => IO UnsafeInclusionList -> ClangT s m (InclusionList s)
registerInclusionList action = do
    (_, inclusionList) <- clangAllocate (action >>= mkSafe) freeInclusions
    return inclusionList
  where
    mkSafe (UnsafeInclusionList is n) = do
      fptr <- newForeignPtr_ (castPtr is)
      return $ DVS.unsafeFromForeignPtr fptr 0 n
{-# INLINEABLE registerInclusionList #-}

fromInclusionList :: InclusionList s -> (Ptr (), Int)
fromInclusionList is = let (p, _, _) = DVS.unsafeToForeignPtr is in
                       (castPtr $ Foreign.ForeignPtr.Unsafe.unsafeForeignPtrToPtr p, DVS.length is)

toInclusionList :: (Ptr (), Int) -> UnsafeInclusionList
toInclusionList (is, n) = UnsafeInclusionList is n

-- A more efficient alternative to clang_getInclusions.
-- void getInclusions(CXTranslationUnit tu, struct Inclusion** inclusionsOut, unsigned* countOut)
getInclusions' :: (Ptr ()) -> (Ptr (Ptr ())) -> IO ((CUInt))
getInclusions' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  alloca $ \a3' -> 
  getInclusions''_ a1' a2' a3' >>
  peek  a3'>>= \a3'' -> 
  return (a3'')

{-# LINE 4956 "src/Clang/Internal/FFI.chs" #-}

unsafe_getInclusions :: TranslationUnit s -> IO UnsafeInclusionList
unsafe_getInclusions tu = do
  iPtrPtr <- mallocBytes 8
{-# LINE 4959 "src/Clang/Internal/FFI.chs" #-}

  n <- getInclusions' (unTranslationUnit tu) (castPtr iPtrPtr)
  firstInclusion <- peek (castPtr iPtrPtr :: Ptr (Ptr ()))
  free iPtrPtr
  return (toInclusionList (firstInclusion, fromIntegral n))


getInclusions :: ClangBase m => TranslationUnit s' -> ClangT s m (InclusionList s)
getInclusions = registerInclusionList . unsafe_getInclusions

-- typedef void* CXRemapping;
newtype Remapping s = Remapping { unRemapping :: Ptr () }
                      deriving (Eq, Ord, Typeable)

instance ClangValue Remapping

mkRemapping :: Ptr () -> Remapping ()
mkRemapping = Remapping

-- void clang_remap_dispose(CXRemapping);
clang_remap_dispose :: (Ptr ()) -> IO ()
clang_remap_dispose a1 =
  let {a1' = id a1} in 
  clang_remap_dispose'_ a1' >>
  return ()

{-# LINE 4979 "src/Clang/Internal/FFI.chs" #-}

remap_dispose :: Remapping s -> IO ()
remap_dispose d = clang_remap_dispose (unRemapping d)

registerRemapping :: ClangBase m => IO (Remapping ()) -> ClangT s m (Remapping s)
registerRemapping action = do
  (_, idx) <- clangAllocate (action >>= return . unsafeCoerce)
                            (\i -> remap_dispose i)
  return idx
{-# INLINEABLE registerRemapping #-}

-- %dis remapping i = <unRemapping/mkRemapping> (ptr i)

maybeRemapping :: Remapping s' -> Maybe (Remapping s)
maybeRemapping (Remapping p) | p == nullPtr = Nothing
maybeRemapping f                            = Just (unsafeCoerce f)

unMaybeRemapping :: Maybe (Remapping s') -> Remapping s
unMaybeRemapping (Just f) = unsafeCoerce f
unMaybeRemapping Nothing  = Remapping nullPtr

-- CXRemapping clang_getRemappings(const char *path);
clang_getRemappings :: (CString) -> IO ((Ptr ()))
clang_getRemappings a1 =
  (flip ($)) a1 $ \a1' -> 
  clang_getRemappings'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 5001 "src/Clang/Internal/FFI.chs" #-}

unsafe_getRemappings :: FilePath -> IO (Maybe (Remapping ()))
unsafe_getRemappings fp =
  withCString fp (\sPtr -> clang_getRemappings sPtr >>= return . maybeRemapping . mkRemapping )

getRemappings :: ClangBase m => FilePath -> ClangT s m (Maybe (Remapping s))
getRemappings path = do
  mRemappings <- liftIO $ unsafe_getRemappings path
  case mRemappings of
    Just remappings -> Just <$> registerRemapping (return remappings)
    Nothing         -> return Nothing

-- CXRemapping clang_getRemappingsFromFileList(const char **filePaths, unsigned numFiles);
clang_getRemappingsFromFileList :: (Ptr CString) -> (Int) -> IO ((Ptr ()))
clang_getRemappingsFromFileList a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  clang_getRemappingsFromFileList'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 5014 "src/Clang/Internal/FFI.chs" #-}

unsafe_getRemappingsFromFileList :: Ptr CString -> Int -> IO (Maybe (Remapping ()))
unsafe_getRemappingsFromFileList paths numPaths =
  clang_getRemappingsFromFileList paths numPaths >>= return . maybeRemapping . mkRemapping

getRemappingsFromFileList :: ClangBase m => [FilePath] -> ClangT s m (Maybe (Remapping s))
getRemappingsFromFileList paths = do
  mRemappings <- liftIO $ withStringList paths unsafe_getRemappingsFromFileList
  case mRemappings of
    Just remappings -> Just <$> registerRemapping (return remappings)
    Nothing         -> return Nothing

-- unsigned clang_remap_getNumFiles(CXRemapping);
clang_remap_getNumFiles :: (Ptr ()) -> IO ((Int))
clang_remap_getNumFiles a1 =
  let {a1' = id a1} in 
  clang_remap_getNumFiles'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 5027 "src/Clang/Internal/FFI.chs" #-}

remap_getNumFiles :: Remapping s -> IO Int
remap_getNumFiles remaps =
  clang_remap_getNumFiles (unRemapping remaps)

-- void clang_remap_getFilenames(CXRemapping, unsigned index,
--                               CXString *original, CXString *transformed);
clang_remap_getFilenames :: (Ptr ()) -> (Int) -> (Ptr ()) -> (Ptr ()) -> IO ()
clang_remap_getFilenames a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  clang_remap_getFilenames'_ a1' a2' a3' a4' >>
  return ()

{-# LINE 5034 "src/Clang/Internal/FFI.chs" #-}

unsafe_remap_getFilenames :: Remapping s -> Int -> IO (ClangString (), ClangString ())
unsafe_remap_getFilenames remaps idx = do
    origPtr <- mallocBytes (sizeOf (undefined :: (Ptr (ClangString ()))))
    txPtr <- mallocBytes (sizeOf (undefined :: (Ptr (ClangString ()))))
    clang_remap_getFilenames (unRemapping remaps) idx origPtr txPtr
    orig <- peek (castPtr origPtr)
    tx <- peek (castPtr txPtr)
    free origPtr
    free txPtr
    return (orig, tx)

remap_getFilenames :: ClangBase m => Remapping s' -> Int -> ClangT s m (ClangString s, ClangString s)
remap_getFilenames r idx = do
  (orig, tr) <- liftIO $ unsafe_remap_getFilenames r idx
  (,) <$> registerClangString (return orig) <*> registerClangString (return tr)

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_createIndex"
  clang_createIndex'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeIndex"
  clang_disposeIndex'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_CXIndex_setGlobalOptions"
  clang_CXIndex_setGlobalOptions'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_CXIndex_getGlobalOptions"
  clang_CXIndex_getGlobalOptions'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeTranslationUnit"
  clang_disposeTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h freeClangString"
  freeClangString'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCString"
  clang_getCString'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getFileName"
  clang_getFileName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getFileUniqueID"
  clang_getFileUniqueID'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_isFileMultipleIncludeGuarded"
  clang_isFileMultipleIncludeGuarded'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getFile"
  clang_getFile'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getNullLocation"
  clang_getNullLocation'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_equalLocations"
  clang_equalLocations'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getLocation"
  clang_getLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getLocationForOffset"
  clang_getLocationForOffset'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Location_isInSystemHeader"
  clang_Location_isInSystemHeader'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Location_isFromMainFile"
  clang_Location_isFromMainFile'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getNullRange"
  clang_getNullRange'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getRange"
  clang_getRange'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_equalRanges"
  clang_equalRanges'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Range_isNull"
  clang_Range_isNull'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getExpansionLocation"
  clang_getExpansionLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getPresumedLocation"
  clang_getPresumedLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getSpellingLocation"
  clang_getSpellingLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getFileLocation"
  clang_getFileLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getRangeStart"
  clang_getRangeStart'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getRangeEnd"
  clang_getRangeEnd'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeDiagnostic"
  clang_disposeDiagnostic'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeDiagnosticSet"
  clang_disposeDiagnosticSet'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getNumDiagnosticsInSet"
  clang_getNumDiagnosticsInSet'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticInSet"
  clang_getDiagnosticInSet'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_loadDiagnostics"
  clang_loadDiagnostics'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getChildDiagnostics"
  clang_getChildDiagnostics'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getNumDiagnostics"
  clang_getNumDiagnostics'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnostic"
  clang_getDiagnostic'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticSetFromTU"
  clang_getDiagnosticSetFromTU'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_formatDiagnostic"
  clang_formatDiagnostic'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_defaultDiagnosticDisplayOptions"
  clang_defaultDiagnosticDisplayOptions'_ :: (IO C2HSImp.CUInt)

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticSeverity"
  clang_getDiagnosticSeverity'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticLocation"
  clang_getDiagnosticLocation'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticSpelling"
  clang_getDiagnosticSpelling'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticOption"
  clang_getDiagnosticOption'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticCategory"
  clang_getDiagnosticCategory'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticCategoryText"
  clang_getDiagnosticCategoryText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticNumRanges"
  clang_getDiagnosticNumRanges'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticRange"
  clang_getDiagnosticRange'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getDiagnosticNumFixIts"
  clang_getDiagnosticNumFixIts'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getDiagnosticFixIt"
  clang_getDiagnosticFixIt'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getTranslationUnitSpelling"
  clang_getTranslationUnitSpelling'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_createTranslationUnitFromSourceFile"
  clang_createTranslationUnitFromSourceFile'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_createTranslationUnit"
  clang_createTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_defaultEditingTranslationUnitOptions"
  defaultEditingTranslationUnitOptions'_ :: (IO C2HSImp.CUInt)

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_parseTranslationUnit"
  clang_parseTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_setClangResourcesPath"
  clang_setClangResourcesPath'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_defaultSaveOptions"
  clang_defaultSaveOptions'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_saveTranslationUnit"
  clang_saveTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CUInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_defaultReparseOptions"
  clang_defaultReparseOptions'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_reparseTranslationUnit"
  clang_reparseTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getTranslationUnitCursor"
  clang_getTranslationUnitCursor'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_hashCursor"
  clang_hashCursor'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCursorLinkage"
  clang_getCursorLinkage'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCursorAvailability"
  clang_getCursorAvailability'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeCXPlatformAvailability"
  clang_disposeCXPlatformAvailability'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCursorPlatformAvailability"
  clang_getCursorPlatformAvailability'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCursorLanguage"
  clang_getCursorLanguage'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getTranslationUnit"
  clang_Cursor_getTranslationUnit'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeCXCursorSet"
  clang_disposeCXCursorSet'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_createCXCursorSet"
  clang_createCXCursorSet'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_CXCursorSet_contains"
  clang_CXCursorSet_contains'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_CXCursorSet_insert"
  clang_CXCursorSet_insert'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorSemanticParent"
  clang_getCursorSemanticParent'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorLexicalParent"
  clang_getCursorLexicalParent'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeOverriddenCursors"
  clang_disposeOverriddenCursors'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getOverriddenCursors"
  clang_getOverriddenCursors'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getIncludedFile"
  clang_getIncludedFile'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCursor"
  clang_getCursor'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorLocation"
  clang_getCursorLocation'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorExtent"
  clang_getCursorExtent'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorType"
  clang_getCursorType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTypeSpelling"
  clang_getTypeSpelling'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTypedefDeclUnderlyingType"
  clang_getTypedefDeclUnderlyingType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getEnumDeclIntegerType"
  clang_getEnumDeclIntegerType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getEnumConstantDeclValue"
  clang_getEnumConstantDeclValue'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getEnumConstantDeclUnsignedValue"
  clang_getEnumConstantDeclUnsignedValue'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CULLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getFieldDeclBitWidth"
  clang_getFieldDeclBitWidth'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getNumArguments"
  clang_Cursor_getNumArguments'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getArgument"
  clang_Cursor_getArgument'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_equalTypes"
  clang_equalTypes'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCanonicalType"
  clang_getCanonicalType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isConstQualifiedType"
  clang_isConstQualifiedType'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isVolatileQualifiedType"
  clang_isVolatileQualifiedType'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isRestrictQualifiedType"
  clang_isRestrictQualifiedType'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getPointeeType"
  clang_getPointeeType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTypeDeclaration"
  clang_getTypeDeclaration'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getDeclObjCTypeEncoding"
  clang_getDeclObjCTypeEncoding'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getTypeKindSpelling"
  clang_getTypeKindSpelling'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getFunctionTypeCallingConv"
  clang_getFunctionTypeCallingConv'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getResultType"
  clang_getResultType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getNumArgTypes"
  clang_getNumArgTypes'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getArgType"
  clang_getArgType'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isFunctionTypeVariadic"
  clang_isFunctionTypeVariadic'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorResultType"
  clang_getCursorResultType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isPODType"
  clang_isPODType'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getElementType"
  clang_getElementType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getNumElements"
  clang_getNumElements'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getArrayElementType"
  clang_getArrayElementType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getArraySize"
  clang_getArraySize'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Type_getAlignOf"
  clang_Type_getAlignOf'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Type_getClassType"
  clang_Type_getClassType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Type_getSizeOf"
  clang_Type_getSizeOf'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Type_getOffsetOf"
  clang_Type_getOffsetOf'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO C2HSImp.CLLong)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Type_getCXXRefQualifier"
  clang_Type_getCXXRefQualifier'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_isBitField"
  clang_Cursor_isBitField'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isVirtualBase"
  clang_isVirtualBase'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCXXAccessSpecifier"
  clang_getCXXAccessSpecifier'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getNumOverloadedDecls"
  clang_getNumOverloadedDecls'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getOverloadedDecl"
  clang_getOverloadedDecl'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getIBOutletCollectionType"
  clang_getIBOutletCollectionType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h freeCursorList"
  freeCursorList''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__getChildren"
  getChildren''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__getDescendants"
  getDescendants''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getDeclarations"
  getDeclarations''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getReferences"
  getReferences''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getDeclarationsAndReferences"
  getDeclarationsAndReferences''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h freeParentedCursorList"
  freeParentedCursorList''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__getParentedDescendants"
  getParentedDescendants''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getParentedDeclarations"
  getParentedDeclarations''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getParentedReferences"
  getParentedReferences''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h getParentedDeclarationsAndReferences"
  getParentedDeclarationsAndReferences''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorUSR"
  clang_getCursorUSR'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCClass"
  clang_constructUSR_ObjCClass'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCCategory"
  clang_constructUSR_ObjCCategory'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCProtocol"
  clang_constructUSR_ObjCProtocol'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCIvar"
  clang_constructUSR_ObjCIvar'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCMethod"
  clang_constructUSR_ObjCMethod'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_constructUSR_ObjCProperty"
  clang_constructUSR_ObjCProperty'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorSpelling"
  clang_getCursorSpelling'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getSpellingNameRange"
  clang_Cursor_getSpellingNameRange'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorDisplayName"
  clang_getCursorDisplayName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorReferenced"
  clang_getCursorReferenced'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorDefinition"
  clang_getCursorDefinition'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_isCursorDefinition"
  clang_isCursorDefinition'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_isDynamicCall"
  clang_Cursor_isDynamicCall'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCanonicalCursor"
  clang_getCanonicalCursor'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getObjCSelectorIndex"
  clang_Cursor_getObjCSelectorIndex'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getReceiverType"
  clang_Cursor_getReceiverType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getObjCPropertyAttributes"
  clang_Cursor_getObjCPropertyAttributes'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getObjCDeclQualifiers"
  clang_Cursor_getObjCDeclQualifiers'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_isObjCOptional"
  clang_Cursor_isObjCOptional'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_isVariadic"
  clang_Cursor_isVariadic'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getCommentRange"
  clang_Cursor_getCommentRange'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getRawCommentText"
  clang_Cursor_getRawCommentText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getBriefCommentText"
  clang_Cursor_getBriefCommentText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_Cursor_getParsedComment"
  clang_Cursor_getParsedComment'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Cursor_getModule"
  clang_Cursor_getModule'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_Module_getASTFile"
  clang_Module_getASTFile'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_Module_getParent"
  clang_Module_getParent'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_Module_getName"
  clang_Module_getName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_Module_getFullName"
  clang_Module_getFullName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_Module_getNumTopLevelHeaders"
  clang_Module_getNumTopLevelHeaders'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_Module_getTopLevelHeader"
  clang_Module_getTopLevelHeader'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_CXXMethod_isPureVirtual"
  clang_CXXMethod_isPureVirtual'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_CXXMethod_isStatic"
  clang_CXXMethod_isStatic'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_CXXMethod_isVirtual"
  clang_CXXMethod_isVirtual'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getTemplateCursorKind"
  clang_getTemplateCursorKind'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getSpecializedCursorTemplate"
  clang_getSpecializedCursorTemplate'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getCursorReferenceNameRange"
  clang_getCursorReferenceNameRange'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Comment_getKind"
  clang_Comment_getKind'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Comment_getNumChildren"
  clang_Comment_getNumChildren'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Comment_getChild"
  clang_Comment_getChild'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_Comment_isWhitespace"
  clang_Comment_isWhitespace'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_InlineContentComment_hasTrailingNewline"
  clang_InlineContentComment_hasTrailingNewline'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_TextComment_getText"
  clang_TextComment_getText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_InlineCommandComment_getCommandName"
  clang_InlineCommandComment_getCommandName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_InlineCommandComment_getRenderKind"
  clang_InlineCommandComment_getRenderKind'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_InlineCommandComment_getNumArgs"
  clang_InlineCommandComment_getNumArgs'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_InlineCommandComment_getArgText"
  clang_InlineCommandComment_getArgText'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_HTMLTagComment_getTagName"
  clang_HTMLTagComment_getTagName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_HTMLStartTagComment_isSelfClosing"
  clang_HTMLStartTagComment_isSelfClosing'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_HTMLStartTag_getNumAttrs"
  clang_HTMLStartTag_getNumAttrs'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_HTMLStartTag_getAttrName"
  clang_HTMLStartTag_getAttrName'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_HTMLStartTag_getAttrValue"
  clang_HTMLStartTag_getAttrValue'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_BlockCommandComment_getCommandName"
  clang_BlockCommandComment_getCommandName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_BlockCommandComment_getNumArgs"
  clang_BlockCommandComment_getNumArgs'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_BlockCommandComment_getArgText"
  clang_BlockCommandComment_getArgText'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_BlockCommandComment_getParagraph"
  clang_BlockCommandComment_getParagraph'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_ParamCommandComment_getParamName"
  clang_ParamCommandComment_getParamName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_ParamCommandComment_isParamIndexValid"
  clang_ParamCommandComment_isParamIndexValid'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_ParamCommandComment_getParamIndex"
  clang_ParamCommandComment_getParamIndex'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_ParamCommandComment_isDirectionExplicit"
  clang_ParamCommandComment_isDirectionExplicit'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_ParamCommandComment_getDirection"
  clang_ParamCommandComment_getDirection'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_TParamCommandComment_getParamName"
  clang_TParamCommandComment_getParamName'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_TParamCommandComment_isParamPositionValid"
  clang_TParamCommandComment_isParamPositionValid'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_TParamCommandComment_getDepth"
  clang_TParamCommandComment_getDepth'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_TParamCommandComment_getIndex"
  clang_TParamCommandComment_getIndex'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO C2HSImp.CUInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_VerbatimBlockLineComment_getText"
  clang_VerbatimBlockLineComment_getText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_VerbatimLineComment_getText"
  clang_VerbatimLineComment_getText'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_HTMLTagComment_getAsString"
  clang_HTMLTagComment_getAsString'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_FullComment_getAsHTML"
  clang_FullComment_getAsHTML'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_FullComment_getAsXML"
  clang_FullComment_getAsXML'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getTokenKind"
  clang_getTokenKind'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTokenSpelling"
  clang_getTokenSpelling'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTokenLocation"
  clang_getTokenLocation'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__wrapped_clang_getTokenExtent"
  clang_getTokenExtent'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_tokenize"
  clang_tokenize'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_annotateTokens"
  clang_annotateTokens'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (IO ())))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCursorKindSpelling"
  clang_getCursorKindSpelling'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getCompletionChunkKind"
  clang_getCompletionChunkKind'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCompletionChunkText"
  clang_getCompletionChunkText'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getCompletionChunkCompletionString"
  clang_getCompletionChunkCompletionString'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getNumCompletionChunks"
  clang_getNumCompletionChunks'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getCompletionPriority"
  clang_getCompletionPriority'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getCompletionAvailability"
  clang_getCompletionAvailability'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getCompletionNumAnnotations"
  clang_getCompletionNumAnnotations'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCompletionAnnotation"
  clang_getCompletionAnnotation'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCompletionParent"
  clang_getCompletionParent'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getCompletionBriefComment"
  clang_getCompletionBriefComment'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h __c2hs_wrapped__clang_getCursorCompletionString"
  clang_getCursorCompletionString'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_defaultCodeCompleteOptions"
  defaultCodeCompleteOptions'_ :: (IO C2HSImp.CUInt)

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_disposeCodeCompleteResults"
  clang_disposeCodeCompleteResults'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteAt"
  clang_codeCompleteAt'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ())))))))))

foreign import ccall safe "Clang/Internal/FFI.chs.h codeCompleteGetNumResults"
  codeCompleteGetNumResults''_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h codeCompleteGetResult"
  codeCompleteGetResult''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_sortCodeCompletionResults"
  clang_sortCodeCompletionResults'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetNumDiagnostics"
  clang_codeCompleteGetNumDiagnostics'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetDiagnostic"
  clang_codeCompleteGetDiagnostic'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetContexts"
  clang_codeCompleteGetContexts'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CULLong))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetContainerKind"
  clang_codeCompleteGetContainerKind'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetContainerUSR"
  clang_codeCompleteGetContainerUSR'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_codeCompleteGetObjCSelector"
  clang_codeCompleteGetObjCSelector'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h wrapped_clang_getClangVersion"
  clang_getClangVersion'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_toggleCrashRecovery"
  toggleCrashRecovery''_ :: (C2HSImp.CUInt -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h freeInclusionList"
  freeInclusionList''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h getInclusions"
  getInclusions''_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (IO ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_remap_dispose"
  clang_remap_dispose'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getRemappings"
  clang_getRemappings'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_getRemappingsFromFileList"
  clang_getRemappingsFromFileList'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (C2HSImp.CUInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_remap_getNumFiles"
  clang_remap_getNumFiles'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Clang/Internal/FFI.chs.h clang_remap_getFilenames"
  clang_remap_getFilenames'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO ())))))