Skip to content

Commit

Permalink
Issue #83: Better API for libclang command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Aug 19, 2024
1 parent 6c9879b commit 3669c5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion hs-bindgen/app/HsBindgen/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module HsBindgen.Cmdline (
) where

import Data.Default
import Data.Void (Void)
import Options.Applicative

import HsBindgen.Lib
Expand Down Expand Up @@ -102,10 +103,13 @@ parseVerbosity =

parseClangArgs :: Parser ClangArgs
parseClangArgs =
many $ strOption $ mconcat [
many $ option parseClangArg $ mconcat [
long "clang-option"
, help "Pass option to libclang"
]
where
parseClangArg :: ReadM Void
parseClangArg = maybeReader (\_ -> Nothing)

parseInput :: Parser FilePath
parseInput =
Expand Down
4 changes: 2 additions & 2 deletions hs-bindgen/src/HsBindgen/C/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ parseHeaderWith ::
-> IO [a]
parseHeaderWith args fp fold = do
index <- clang_createIndex DontDisplayDiagnostics
unit <- clang_parseTranslationUnit index fp args flags
unit <- clang_parseTranslationUnit index fp (prettyClangArgs args) flags
cursor <- clang_getTranslationUnitCursor unit

clang_fold cursor fold
Expand Down Expand Up @@ -204,4 +204,4 @@ data LogMsg =

instance PrettyLogMsg LogMsg where
prettyLogMsg (Skipping cs kind) =
"Skipping over " ++ show kind ++ " at " ++ prettyCallStack cs
"Skipping over " ++ show kind ++ " at " ++ prettyCallStack cs
12 changes: 10 additions & 2 deletions hs-bindgen/src/HsBindgen/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module HsBindgen.Spec (
-- * Prepare input
, PrepareInput(..)
, ClangArgs
, prettyClangArgs
-- * Translate
, Translation(..)
, HsModuleOpts(..)
Expand All @@ -20,6 +21,7 @@ module HsBindgen.Spec (
, HsRenderOpts(..)
) where

import Data.Void (Void, absurd)
import Language.Haskell.Exts qualified as Hs
import Language.Haskell.TH (Q)
import Language.Haskell.TH qualified as TH
Expand Down Expand Up @@ -79,9 +81,15 @@ data PrepareInput inp where
-- | @libclang@ command line arguments
--
-- TODO: <https://github.com/well-typed/hs-bindgen/issues/83>
-- We should have a proper data type instead of @[String]@ for the arguments
-- We should have a proper data type instead of @[Void]@ for the arguments
-- (part of #10 and #71).
type ClangArgs = [String]
--
-- Currently there are no use for them, so [Void] ~ () works well.
type ClangArgs = [Void]

-- | Translate clang arguments to arguments passed to the library
prettyClangArgs :: ClangArgs -> [String]
prettyClangArgs = map absurd

{-------------------------------------------------------------------------------
Translation (this should be a pure function)
Expand Down

0 comments on commit 3669c5b

Please sign in to comment.