Skip to content

Commit

Permalink
Supply buildGetTHType for creation of custom types for clients and si…
Browse files Browse the repository at this point in the history
…gnals
  • Loading branch information
colonelpanic8 committed Mar 9, 2018
1 parent dc3a968 commit 6eb525a
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions lib/DBus/Generation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,35 @@ data GenerationParams = GenerationParams
, getTHType :: T.Type -> Type
}

defaultGetDictType :: Type -> Type -> Type
defaultGetDictType k v =
AppT (AppT (ConT ''Map.Map) k) (v)

defaultGetTHType :: T.Type -> Type
defaultGetTHType t =
case t of
T.TypeBoolean -> ConT ''Bool
T.TypeWord8 -> ConT ''Word8
T.TypeWord16 -> ConT ''Word16
T.TypeWord32 -> ConT ''Word32
T.TypeWord64 -> ConT ''Word64
T.TypeInt16 -> ConT ''Int16
T.TypeInt32 -> ConT ''Int32
T.TypeInt64 -> ConT ''Int64
T.TypeDouble -> ConT ''Double
T.TypeUnixFd -> ConT ''Fd
T.TypeString -> ConT ''String
T.TypeSignature -> ConT ''T.Signature
T.TypeObjectPath -> ConT ''T.ObjectPath
T.TypeVariant -> ConT ''T.Variant
T.TypeArray arrayType -> AppT ListT $ defaultGetTHType arrayType
T.TypeDictionary k v -> (AppT (AppT (ConT ''Map.Map)
(defaultGetTHType k))
(defaultGetTHType v))
T.TypeStructure ts -> foldl AppT (TupleT $ length ts) $ map defaultGetTHType ts
defaultGetTHType = buildGetTHType (AppT ListT) defaultGetDictType

buildGetTHType ::
(Type -> Type) -> (Type -> Type -> Type) -> T.Type -> Type
buildGetTHType arrayTypeBuilder dictTypeBuilder = getTHType
where getTHType t =
case t of
T.TypeBoolean -> ConT ''Bool
T.TypeWord8 -> ConT ''Word8
T.TypeWord16 -> ConT ''Word16
T.TypeWord32 -> ConT ''Word32
T.TypeWord64 -> ConT ''Word64
T.TypeInt16 -> ConT ''Int16
T.TypeInt32 -> ConT ''Int32
T.TypeInt64 -> ConT ''Int64
T.TypeDouble -> ConT ''Double
T.TypeUnixFd -> ConT ''Fd
T.TypeString -> ConT ''String
T.TypeSignature -> ConT ''T.Signature
T.TypeObjectPath -> ConT ''T.ObjectPath
T.TypeVariant -> ConT ''T.Variant
T.TypeArray arrayType -> arrayTypeBuilder $ getTHType arrayType
T.TypeDictionary k v -> dictTypeBuilder (getTHType k) (getTHType v)
T.TypeStructure ts -> foldl AppT (TupleT $ length ts) $ map defaultGetTHType ts

defaultGenerationParams :: GenerationParams
defaultGenerationParams =
Expand Down

0 comments on commit 6eb525a

Please sign in to comment.