Skip to content

Commit 926fa1e

Browse files
authored
Merge pull request #14 from well-typed/edsko/delete-userprovided
Give up on trying to detect all anon declarations
2 parents 6c0867c + 75a4f54 commit 926fa1e

7 files changed

Lines changed: 17 additions & 119 deletions

File tree

libclang-bindings.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,11 @@ library
9393
Clang.HighLevel.Fold
9494
Clang.HighLevel.SourceLoc
9595
Clang.HighLevel.Tokens
96-
Clang.HighLevel.UserProvided
9796
Clang.HighLevel.Wrappers
9897
build-depends:
9998
-- External dependencies
10099
, data-default >= 0.7 && < 0.9
101100
, exceptions >= 0.10 && < 0.11
102-
, mtl >= 2.2 && < 2.4
103101
, text >= 1.2 && < 2.2
104102
, unliftio-core >= 0.2.1 && < 0.3
105103

src/Clang/HighLevel.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ module Clang.HighLevel (
4141
, clang_getDiagnostics
4242
-- * Folds
4343
, clang_visitChildren
44-
-- * User-provided names
45-
, clang_getCursorSpelling
4644
-- * Declaration classification
4745
, classifyDeclaration
4846
, classifyTentativeDefinition
@@ -58,5 +56,4 @@ import Clang.HighLevel.Diagnostics
5856
import Clang.HighLevel.Fold
5957
import Clang.HighLevel.SourceLoc
6058
import Clang.HighLevel.Tokens
61-
import Clang.HighLevel.UserProvided
6259
import Clang.HighLevel.Wrappers

src/Clang/HighLevel/Types.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ module Clang.HighLevel.Types (
4040
, foldRecurseOpt
4141
, foldRecursePure
4242
, foldRecursePureOpt
43-
-- * User-provided names
44-
, CursorSpelling(..)
4543
-- * Declaration classification
4644
, DeclarationClassification(..)
4745
) where
@@ -51,4 +49,3 @@ import Clang.HighLevel.Diagnostics
5149
import Clang.HighLevel.Fold
5250
import Clang.HighLevel.SourceLoc
5351
import Clang.HighLevel.Tokens
54-
import Clang.HighLevel.UserProvided

src/Clang/HighLevel/UserProvided.hs

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/Clang/Internal/Results.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Clang.Internal.Results (
1414
, checkNotNull
1515
, ensureNotInRange
1616
-- * Auxiliary
17-
, isNullPtr
17+
, IsNullPtr(..)
1818
) where
1919

2020
import Control.Exception
@@ -76,12 +76,12 @@ ensureOn f p call = do
7676

7777
-- | Ensure that a function did not return 'nullPtr' (indicating error)
7878
ensureNotNull ::
79-
(HasCallStack, Coercible a (Ptr x), Show a)
79+
(HasCallStack, IsNullPtr a, Show a)
8080
=> IO a -> IO a
8181
ensureNotNull = ensure (not . isNullPtr)
8282

8383
-- | If the result is 'nullPtr', return 'Nothing'
84-
checkNotNull :: Coercible a (Ptr x) => IO a -> IO (Maybe a)
84+
checkNotNull :: IsNullPtr a => IO a -> IO (Maybe a)
8585
checkNotNull call = do
8686
ptr <- call
8787
return $ if isNullPtr ptr
@@ -110,8 +110,11 @@ ensureNotInRange = ensureOn conv (not . simpleEnumInRange)
110110
Auxiliary
111111
-------------------------------------------------------------------------------}
112112

113-
isNullPtr :: Coercible a (Ptr x) => a -> Bool
114-
isNullPtr ptr = ptr' == nullPtr
115-
where
116-
ptr' :: Ptr x
117-
ptr' = coerce ptr
113+
class IsNullPtr a where
114+
isNullPtr :: a -> Bool
115+
116+
instance IsNullPtr (Ptr a) where
117+
isNullPtr ptr = ptr' == nullPtr
118+
where
119+
ptr' :: Ptr x
120+
ptr' = coerce ptr

src/Clang/LowLevel/Core.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ module Clang.LowLevel.Core (
208208
, clang_CXRewriter_writeMainFileToStdOut
209209
, clang_CXRewriter_dispose
210210
-- * Auxiliary
211+
, IsNullPtr(..)
211212
, nullCursor
212213
) where
213214

@@ -604,7 +605,7 @@ clang_getDiagnosticFixIt diagnostic fixit = liftIO $
604605
-- <https://clang.llvm.org/doxygen/group__CINDEX.html#gacdb7815736ca709ce9a5e1ec2b7e16ac>
605606
newtype CXTranslationUnit = CXTranslationUnit (Ptr ())
606607
deriving stock (Show)
607-
deriving newtype (Storable)
608+
deriving newtype (Storable, IsNullPtr)
608609

609610
-- | An opaque type representing target information for a given translation
610611
-- unit.
@@ -1729,6 +1730,7 @@ clang_getCursorExtent cursor = liftIO $
17291730

17301731
newtype CXToken = CXToken (Ptr ())
17311732
deriving stock (Show)
1733+
deriving newtype (IsNullPtr)
17321734

17331735
foreign import capi unsafe "clang_wrappers.h wrap_getToken"
17341736
wrap_getToken :: CXTranslationUnit -> R CXSourceLocation_ -> IO CXToken

src/Clang/LowLevel/Core/Pointers.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Clang.LowLevel.Core.Pointers (
55

66
import Foreign
77

8+
import Clang.Internal.Results
9+
810
{-------------------------------------------------------------------------------
911
CXFile
1012
-------------------------------------------------------------------------------}
@@ -16,7 +18,7 @@ import Foreign
1618
-- <https://clang.llvm.org/doxygen/group__CINDEX__FILES.html#gacfcea9c1239c916597e2e5b3e109215a>
1719
newtype CXFile = CXFile (Ptr ())
1820
deriving stock (Show, Eq)
19-
deriving newtype (Storable)
21+
deriving newtype (Storable, IsNullPtr)
2022

2123
{-------------------------------------------------------------------------------
2224
CXPrintingPolicy

0 commit comments

Comments
 (0)