From: Axel S. <si...@co...> - 2009-10-30 17:02:20
|
Sun May 10 03:59:21 EDT 2009 Axe...@en... * Extend the type hierarchy generator to allow for re-exporting of modules and to emit mk... functions that contain Haskell constructor and a C destructor function. hunk ./tools/hierarchyGen/Hierarchy.chs.template 29 +-- Note: the mk... functions were originally meant to simply be an alias +-- for the constructor. However, in order to communicate the destructor +-- of an object to objectNew, the mk... functions are now a tuple containing +-- Haskell constructor and the destructor function pointer. This hack avoids +-- changing all modules that simply pass mk... to objectNew. +-- hunk ./tools/hierarchyGen/Hierarchy.chs.template 36 -@MODULE_EXPORTS@ +@MODULE_EXPORTS@@FORWARD_EXPORTS@ hunk ./tools/hierarchyGen/Hierarchy.chs.template 43 - +@DESTR_IMPORT@ +@FORWARD_IMPORTS@ hunk ./tools/hierarchyGen/TypeGen.hs 129 - + let forwardNames = map (drop 10) (filter ("--forward=" `isPrefixOf`) rem) + let destrFun = case map (drop 13) (filter ("--destructor=" `isPrefixOf`) rem) of + [] -> "objectUnref" + (destrFun:_) -> destrFun hunk ./tools/hierarchyGen/TypeGen.hs 155 - "MODULE_EXPORTS" -> generateExports parentName objs + "MODULE_EXPORTS" -> generateExports parentName forwardNames objs hunk ./tools/hierarchyGen/TypeGen.hs 157 - then ss "" + then id hunk ./tools/hierarchyGen/TypeGen.hs 159 + "FORWARD_IMPORTS"-> + foldl (.) id [ ss "import " . ss m . indent 0 | m <- forwardNames ] + "DESTR_IMPORT" -> if destrFun/="objectUnref" then id else + indent 0.ss "import System.Glib.GObject(objectUnref)" hunk ./tools/hierarchyGen/TypeGen.hs 165 - "DECLERATIONS" -> generateDeclerations prefix objs specialQueries + "DECLERATIONS" -> generateDeclerations destrFun prefix objs specialQueries hunk ./tools/hierarchyGen/TypeGen.hs 175 + \ {--forward=<fwdName>} {--destructor=<destrName>}\n\ hunk ./tools/hierarchyGen/TypeGen.hs 190 - \ parent classes eg Hierarchy (default is none)\n" + \ parent classes eg Hierarchy (default is none)\n\ + \ <fwdName> specify a number of modules that are imported\n\ + \ as well as exported from the generated module\n\ + \ <destrName> specify a non-standard C function pointer that\n\ + \ is called to destroy the objects\n" hunk ./tools/hierarchyGen/TypeGen.hs 203 -generateExports :: String -> [[String]] -> ShowS -generateExports parent objs = +generateExports :: String -> [String] -> [[String]] -> ShowS +generateExports parent forwardNames objs = hunk ./tools/hierarchyGen/TypeGen.hs 208 - drop 2. - foldl (\s1 s2 -> s1.ss ", ".s2) id + drop 1. + foldl (\s1 s2 -> s1.ss ",".indent 1.ss "module ".s2) id + (map ss forwardNames). + foldl (\s1 s2 -> s1.ss ",".s2) id hunk ./tools/hierarchyGen/TypeGen.hs 219 -generateDeclerations :: String -> [[String]] -> TypeTable -> ShowS -generateDeclerations prefix objs typeTable = +generateDeclerations :: String -> String -> [[String]] -> TypeTable -> ShowS +generateDeclerations destr prefix objs typeTable = hunk ./tools/hierarchyGen/TypeGen.hs 222 - [ makeClass prefix typeTable obj + [ makeClass destr prefix typeTable obj hunk ./tools/hierarchyGen/TypeGen.hs 268 -makeClass :: String -> TypeTable -> [String] -> ShowS -makeClass prefix table (name:[]) = id -makeClass prefix table (name:parents) = +makeClass :: String -> String -> TypeTable -> [String] -> ShowS +makeClass destr prefix table (name:[]) = id +makeClass destr prefix table (name:parents) = hunk ./tools/hierarchyGen/TypeGen.hs 289 - indent 0.ss "mk".ss name.ss " = ".ss name. + indent 0.ss "mk".ss name.ss " = (".ss name.ss ", ".ss destr.ss ")". hunk ./tools/hierarchyGen/TypeGen.hs 309 - indent 1.ss "toGObject = mkGObject . castForeignPtr . un".ss name. - indent 1.ss "unsafeCastGObject = mk".ss name.ss" . castForeignPtr . unGObject" + indent 1.ss "toGObject = GObject . castForeignPtr . un".ss name. + indent 1.ss "unsafeCastGObject = ".ss name.ss" . castForeignPtr . unGObject" |