@@ -36,14 +36,14 @@ printFeature :: API -> Version -> ProfileName -> Registry -> IO ()
3636printFeature api version profile registry = do
3737 let relName = capitalize (unProfileName profile) ++
3838 show (major version) ++ show (minor version)
39- printExtension Nothing [ relName] $ fixedReplay api version profile registry
39+ printExtension Nothing relName [ ] $ fixedReplay api version profile registry
4040
4141printTokens :: API -> Registry -> IO ()
4242printTokens api registry = do
4343 let comment =
4444 [" All enumeration tokens from the" ,
4545 " <http://www.opengl.org/registry/ OpenGL registry>." ]
46- startModule Nothing [ " Tokens" ] Nothing comment $ \ moduleName h -> do
46+ startModule Nothing " Tokens" Nothing comment $ \ moduleName h -> do
4747 SI. hPutStrLn h $ " module " ++ moduleName ++ " where"
4848 SI. hPutStrLn h " "
4949 SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.Types"
@@ -67,7 +67,7 @@ signatureMap registry = fst $ M.foldl' step (M.empty, 0) (commands registry)
6767printForeign :: M. Map String String -> IO ()
6868printForeign sigMap = do
6969 let comment = [" All foreign imports." ]
70- startModule Nothing [ " Foreign" ] (Just " {-# LANGUAGE CPP #-}" ) comment $ \ moduleName h -> do
70+ startModule Nothing " Foreign" (Just " {-# LANGUAGE CPP #-}" ) comment $ \ moduleName h -> do
7171 SI. hPutStrLn h $ " module " ++ moduleName ++ " where"
7272 SI. hPutStrLn h " "
7373 SI. hPutStrLn h " import Foreign.C.Types"
@@ -81,7 +81,7 @@ printFunctions api registry sigMap = do
8181 let comment =
8282 [" All raw functions from the" ,
8383 " <http://www.opengl.org/registry/ OpenGL registry>." ]
84- startModule Nothing [ " Functions" ] Nothing comment $ \ moduleName h -> do
84+ startModule Nothing " Functions" Nothing comment $ \ moduleName h -> do
8585 SI. hPutStrLn h $ " module " ++ moduleName ++ " ("
8686 SI. hPutStrLn h . separate unCommandName . M. keys . commands $ registry
8787 SI. hPutStrLn h " ) where"
@@ -113,29 +113,30 @@ printExtensions api registry = do
113113 , api `supports` extensionSupported ext
114114 , nameAndMods@ (_,(_: _)) <- [nameAndModifications api ext] ]
115115 CM. forM_ supportedExtensions $ \ (n,mods) -> do
116- let profileAndModName =
116+ let (" GL" : vendor: extWords) = splitBy (== ' _' ) (unExtensionName n)
117+ modSuff = concat (zipWith fixExtensionWord extWords [0 .. ])
118+ profileAndModuleNameSuffix =
117119 if any isProfileDependent mods
118- then [(ProfileName p, extendExtensionName n p)
120+ then [(ProfileName p, modSuff ++ capitalize p)
119121 | p <- [" core" , " compatibility" ] ]
120- else [(ProfileName " core" , n)] -- the actual profile doesn't matter
121- CM. forM_ profileAndModName $ \ (prof, modName) -> do
122- let (" GL" : vendor: extWords) = splitBy (== ' _' ) (unExtensionName modName)
123- printExtension (Just vendor) extWords $
122+ else [(ProfileName " core" , modSuff)] -- the actual profile doesn't matter
123+ ext = L. intercalate " _" extWords
124+ comment = [" The <https://www.opengl.org/registry/specs/" ++
125+ vendor ++ " /" ++ ext ++ " .txt " ++
126+ vendor ++ " _" ++ ext ++ " > extension." ]
127+ CM. forM_ profileAndModuleNameSuffix $ \ (prof, moduleNameSuffix) ->
128+ printExtension (Just vendor) moduleNameSuffix comment $
124129 executeModifications api prof registry mods
125130
126131isProfileDependent :: Modification -> Bool
127132isProfileDependent = DM. isJust . modificationProfile
128133
129- extendExtensionName :: ExtensionName -> String -> ExtensionName
130- extendExtensionName n profile =
131- ExtensionName . (++ (" _" ++ profile)). unExtensionName $ n
132-
133- startModule :: Maybe String -> [String ] -> Maybe String -> [String ] -> (String -> SI. Handle -> IO () ) -> IO ()
134- startModule mbVendor extWords mbPragma comments action = do
134+ startModule :: Maybe String -> String -> Maybe String -> [String ] -> (String -> SI. Handle -> IO () ) -> IO ()
135+ startModule mbVendor moduleNameSuffix mbPragma comments action = do
135136 let moduleNameParts =
136137 [" Graphics" , " Rendering" , " OpenGL" , " Raw" ] ++
137138 maybe [] (\ vendor -> [fixVendor vendor]) mbVendor ++
138- [concat ( zipWith fixExtensionWord extWords [ 0 .. ]) ]
139+ [moduleNameSuffix ]
139140 path = F. joinPath moduleNameParts `F.addExtension` " hs"
140141 moduleName = L. intercalate " ." moduleNameParts
141142 D. createDirectoryIfMissing True $ F. takeDirectory path
@@ -208,10 +209,9 @@ separate :: (a -> String) -> [a] -> String
208209separate f = L. intercalate " ,\n " . map (" " ++ ) . map f
209210
210211-- Note that we handle features just like extensions.
211- printExtension :: Maybe String -> [String ] -> ([TypeName ], [Enum' ], [Command ]) -> IO ()
212- printExtension mbVendor extWords (ts, es, cs) = do
213- let comment = maybe [] (makeExtensionURL extWords) mbVendor
214- startModule mbVendor extWords Nothing comment $ \ moduleName h -> do
212+ printExtension :: Maybe String -> String -> [String ] -> ([TypeName ], [Enum' ], [Command ]) -> IO ()
213+ printExtension mbVendor moduleNameSuffix comment (ts, es, cs) =
214+ startModule mbVendor moduleNameSuffix Nothing comment $ \ moduleName h -> do
215215 SI. hPutStrLn h $ " module " ++ moduleName ++ " ("
216216 CM. unless (null ts) $ do
217217 SI. hPutStrLn h " -- * Types"
@@ -234,12 +234,6 @@ printExtension mbVendor extWords (ts, es, cs) = do
234234 CM. unless (null cs) $
235235 SI. hPutStrLn h " import Graphics.Rendering.OpenGL.Raw.Functions"
236236
237- makeExtensionURL :: [String ] -> String -> [String ]
238- makeExtensionURL extWords vendor =
239- [" The <https://www.opengl.org/registry/specs/" ++
240- vendor ++ " /" ++ L. intercalate " _" extWords ++ " .txt " ++
241- L. intercalate " _" (vendor : extWords) ++ " > extension." ]
242-
243237printModuleHeader :: SI. Handle -> Maybe String -> String -> [String ] -> IO ()
244238printModuleHeader h mbPragma moduleName comments = do
245239 maybe (return () ) (SI. hPutStrLn h) mbPragma
0 commit comments