@@ -61,15 +61,21 @@ cident = lexeme $ do
6161 t <- many $ P. satisfy $ \ c -> c == ' _' || isLetter c -- or num
6262 return (h : t)
6363
64- -- we cheat a bit, we don't recognise *.
64+ -- pointers are only recognised when they are surrounded by whitespace
65+ pointer :: Parser Char
66+ pointer = lexeme (P. char ' *' )
67+
68+ pointerS :: Parser String
69+ pointerS = (: [] ) <$> pointer
70+
6571varDecl :: Parser Var
6672varDecl = do
67- x <- cident
68- y <- cident
73+ x <- cident <|> pointerS
74+ y <- cident <|> pointerS
6975 go (x : ) y
7076 where
7177 go :: ([String ] -> [String ]) -> String -> Parser Var
72- go xs y = (cident >>= \ z -> go (xs . (y : )) z) <|> return (Var (xs [] ) y)
78+ go xs y = (( cident <|> pointerS) >>= \ z -> go (xs . (y : )) z) <|> return (Var (xs [] ) y)
7379
7480funDeclP :: Parser Decl
7581funDeclP = do
@@ -106,12 +112,15 @@ ffiModule ds = unlines $
106112 header =
107113 [ " {-| this module is autogenerated with cabal run clang-bootstrap -}"
108114 , " module Clang.LowLevel.FFI (module Clang.LowLevel.FFI) where"
109- , " import Foreign.C.Types "
115+ , " "
110116 , " import Clang.Enum.Simple"
111117 , " import Clang.Internal.ByValue"
118+ , " import Clang.Internal.ConstPtr"
112119 , " import Clang.LowLevel.Core.Enums"
113120 , " import Clang.LowLevel.Core.Pointers"
114121 , " import Clang.LowLevel.Core.Structs"
122+ , " import Foreign.C.Types"
123+ , " "
115124 ]
116125
117126ffiDecl :: Decl -> [String ]
@@ -256,6 +265,7 @@ toHaskellType _ ["unsigned","long","long"] = "CULLong"
256265toHaskellType _ [" unsigned" ] = " CUInt"
257266toHaskellType _ [" int" ] = " CInt"
258267toHaskellType _ [" void" ] = " ()"
268+ toHaskellType _ [" const" , " char" , " *" ] = " ConstPtr CChar"
259269toHaskellType _ ty = error $ " Unknown type " ++ unwords ty
260270
261271cRA :: RA -> String
@@ -282,4 +292,5 @@ toCType _ ["unsigned","long","long"] = "unsigned long long"
282292toCType _ [" unsigned" ] = " unsigned"
283293toCType _ [" int" ] = " int"
284294toCType _ [" void" ] = " void"
295+ toCType _ [" const" , " char" , " *" ] = " const char *"
285296toCType _ ty = error $ " Unknown type " ++ unwords ty
0 commit comments