Skip to content

Commit

Permalink
handle missing case of CPTEnum. (#228)
Browse files Browse the repository at this point in the history
Now int to enum type is explicitly casted.
so on Haskell side, enum argument is still CInt, but on C++ side, it's explicitly casted by cast operator: (enum_type)
  • Loading branch information
wavewave committed Aug 26, 2023
1 parent 7c06b4b commit 8019866
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fficxx/src/FFICXX/Generate/Code/Primitive.hs
Expand Up @@ -20,6 +20,7 @@ import FFICXX.Generate.Type.Class
CPPTypes (..),
CTypes (..),
Class (..),
EnumType (enum_name),
Form (..),
Function (..),
IsConst (Const, NoConst),
Expand Down Expand Up @@ -293,6 +294,8 @@ argToCTypVar (Arg (CT ctyp isconst) varname) =
(ctypToCType ctyp isconst, R.sname varname)
argToCTypVar (Arg SelfType varname) =
(R.CTSimple (R.CName [R.NamePart "Type", R.NamePart "_p"]), R.sname varname)
argToCTypVar (Arg (CPT (CPTEnum _e) _isconst) varname) =
(ctypToCType CTInt NoConst, R.sname varname)
argToCTypVar (Arg (CPT (CPTClass c) isconst) varname) =
case isconst of
Const -> (R.CTSimple (R.sname ("const_" <> cname <> "_p")), R.sname varname)
Expand Down Expand Up @@ -356,6 +359,8 @@ c2Cxx :: Types -> R.CExp Identity -> R.CExp Identity
c2Cxx t e =
case t of
CT (CRef _) _ -> R.CStar e
CPT (CPTEnum en) _ ->
R.CCast (R.CTVerbatim (enum_name en)) e
CPT (CPTClass c) _ ->
R.CTApp
(R.sname "from_nonconst_to_nonconst")
Expand Down Expand Up @@ -840,7 +845,8 @@ extractArgRetTypes mc isvirtual (CFunSig args ret) =
case typ of
SelfType -> return (Ex.mkTVar "a")
CT CTString Const -> addstring
CT _ _ -> return $ cxx2HsType Nothing typ
CT _ _ -> pure $ cxx2HsType Nothing typ
CPT (CPTEnum _e) _ -> pure $ cxx2HsType Nothing (CT CTInt NoConst)
CPT (CPTClass c') _ -> addclass c'
CPT (CPTClassRef c') _ -> addclass c'
CPT (CPTClassCopy c') _ -> addclass c'
Expand Down Expand Up @@ -978,6 +984,7 @@ hsFFIFunType msc (CFunSig args ret) =
--
hsargtype :: Types -> HsType GhcPs
hsargtype (CT ctype _) = c2HsType ctype
hsargtype (CPT (CPTEnum _) _) = c2HsType CTInt
hsargtype (CPT (CPTClass d) _) = Ex.tyapp Ex.tyPtr (Ex.tycon rawname)
where
rawname = snd (hsClassName d)
Expand Down

0 comments on commit 8019866

Please sign in to comment.