|
From: <cod...@go...> - 2008-09-25 20:18:57
|
Author: wol...@gm...
Date: Thu Sep 25 13:18:22 2008
New Revision: 310
Added:
trunk/hoc/InterfaceGenerator2/HackEnumNames.hs
Modified:
trunk/hoc/InterfaceGenerator2/Main.hs
Log:
Add another pass on the newly-parsed syntax trees to recover
enum type names on Leopard. When an anonymous enum declaration
is immediately followed by a typedef of NSInteger or NSUInteger,
this is converted to a typedef of the enum instead.
This is to necessary to deal with changes Apple introduced to
improve 64-bit compatibility in Leopard.
Added: trunk/hoc/InterfaceGenerator2/HackEnumNames.hs
==============================================================================
--- (empty file)
+++ trunk/hoc/InterfaceGenerator2/HackEnumNames.hs Thu Sep 25 13:18:22 2008
@@ -0,0 +1,27 @@
+{-# LANGUAGE PatternGuards #-}
+module HackEnumNames where
+
+import SyntaxTree
+import Headers
+
+hackEnumNames (HeaderInfo name imports decls)
+ = HeaderInfo name imports (hackEnums1 Just id decls)
+ where
+ hackEnums1 :: (a -> Maybe Declaration) -> (Declaration -> a) ->
[a] -> [a]
+ hackEnums1 unwrap wrap (x : y : xs)
+ | Just (CTypeDecl (CTEnum name1 vals)) <- unwrap x,
+ Just (Typedef (CTSimple baseType) name2) <- unwrap y,
+ null name1 || name1 == name2 || name1 == '_' : name2,
+ baseType == "NSInteger" || baseType == "NSUInteger"
+ = wrap (Typedef (CTEnum name1 vals) name2)
+ : hackEnums1 unwrap wrap xs
+ hackEnums1 unwrap wrap (x : xs)
+ | Just (SelectorList header items) <- unwrap x
+ = wrap (SelectorList header (hackEnums1 decl LocalDecl items))
+ : hackEnums1 unwrap wrap xs
+ | otherwise
+ = x : hackEnums1 unwrap wrap xs
+ where decl (LocalDecl d) = Just d
+ decl other = Nothing
+ hackEnums1 unwrap wrap [] = []
+
Modified: trunk/hoc/InterfaceGenerator2/Main.hs
==============================================================================
--- trunk/hoc/InterfaceGenerator2/Main.hs (original)
+++ trunk/hoc/InterfaceGenerator2/Main.hs Thu Sep 25 13:18:22 2008
@@ -16,7 +16,6 @@
-- import Traversals
import Files
--- import Debug.Trace
import Progress
import qualified Data.ByteString.Char8 as BS
@@ -27,10 +26,10 @@
#ifdef BINARY_INTERFACES
import Data.Binary ( encodeFile, decode )
import BinaryInstances ()
-#endif
-
import qualified Data.ByteString.Lazy as LBS
+#endif
+import HackEnumNames
import BuildEntities
import ResolveAndZap
import DependenceGraphs
@@ -165,6 +164,8 @@
loaded <- loadHeaders parseProgress headers
+ let enumHacked = map hackEnumNames loaded
+
importedEMaps <- mapM (\(fn, progress) ->
readInterfaceFileWithProgress progress
("HOC-" ++ fn ++ "/" ++ fn ++ ".pi")
@@ -178,7 +179,7 @@
emptyEntityPile $
zip (map BS.pack requiredFrameworks) importedEMaps
- let initialEntities = monitor initialProgress $ makeEntities bs
loaded importedEntities
+ let initialEntities = monitor initialProgress $ makeEntities bs
enumHacked importedEntities
additionalEntities <-
|