Skip to content

Commit

Permalink
Use clang_getTypeSpelling for symbol name
Browse files Browse the repository at this point in the history
We will probably use something different here, but for now this makes the
parsed C code a bit more informative (and allows me to test better with
typedefs vs macros).
  • Loading branch information
edsko committed Oct 8, 2024
1 parent b57b034 commit 1f017e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions hs-bindgen/fixtures/nested_types.tree-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ WrapCHeader
StructField {
fieldName = CName "foo1",
fieldOffset = 0,
fieldType = TypElaborated},
fieldType = TypElaborated
(CName "struct foo")},
StructField {
fieldName = CName "foo2",
fieldOffset = 64,
fieldType = TypElaborated}]}])
fieldType = TypElaborated
(CName "struct foo")}]}])
7 changes: 6 additions & 1 deletion hs-bindgen/src/HsBindgen/C/AST/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ data Typ =
TypPrim PrimType
| TypStruct Struct
| TypPointer Typ
| TypElaborated -- TODO: reference into type symbol table.
| TypElaborated Symbol
-- todo | TypEnum Enum
deriving stock (Show, Eq, Generic)
deriving anyclass (PrettyVal)

-- | Reference into the type symbol table
--
-- TODO: for now this is simply the name of the C type.
type Symbol = CName

{-------------------------------------------------------------------------------
Primitives types
-------------------------------------------------------------------------------}
Expand Down
3 changes: 2 additions & 1 deletion hs-bindgen/src/HsBindgen/C/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ parseType _tracer = go
TypPointer <$> go ty'

Right CXType_Elaborated -> do
return TypElaborated
name <- CName <$> clang_getTypeSpelling ty
return $ TypElaborated name

_otherwise -> do
throwIO $ UnrecognizedType (cxtKind ty)
Expand Down

0 comments on commit 1f017e2

Please sign in to comment.