Commits

Jason McKesson committed 4af0947

Final file format. Proper Lua scripts.
One per extension/version

Comments (0)

Files changed (4)

 syntax: glob
 glLoadGen/*
+basic_dump/*
+DO NOT EDIT THE FILES PLACED HERE!
+
+This is the initial dump directly from OpenGL's .spec files. All of these are empty. This allows us to track changes to the .spec files and copy new data from here to the place where we manually edit in new enums.
+

glLoadGen/MakeDirectDump.lua

+
+local cmds =
+{
+	[[lua MakeAllExts.lua -spec=gl AllExt.txt]],
+	[[lua LoadGen.lua ../basic_dump/out -spec=gl -style=enumdb -version=4.3 -extfile=AllExt.txt -profile=compatibility]]
+}
+
+for _, cmd in ipairs(cmds) do
+	os.execute(cmd)
+end

glLoadGen/modules/StyleEnumDB.lua

 local util = require "util"
+local tab = require "TabbedFile"
 local struct = require "Structure"
 local common = require "CommonStyle"
 
 local function CollectEnumParams(func, typemap)
-	local enumParamList = {}
+	local enumParamList = nil
 
 	for i, param in ipairs(func.params) do
 		local paramType = typemap[param.type] or param.type
-		if(param.type == "GLenum") then
+		if(paramType == "GLenum") then
+			enumParamList = enumParamList or {}
 			table.insert(enumParamList, param.name)
 		end
 	end
 
 local my_style = {}
 
-local function PossiblyWriteFile(func, typemap, GetFilePath)
+function my_style.StateMakeTable()
+	return {}
+end
+
+function my_style.CollectEnumParams(func, typemap, functbl_)
 	local enumParamList = CollectEnumParams(func, typemap)
-	
-	if(#enumParamList ~= 0) then
-		local path = GetFilePath() .. "/"
-		util.EnsurePath(path)
 
-		local filename = path .. "/" .. func.name .. ".lua"
-		
-		local hFile, errorMsg = io.open(filename, "w")
+	if(enumParamList) then
+		table.insert(functbl_, {name=func.name, list=enumParamList})
+	end
+end
+
+local function WriteTableToFile(basename, filename, functbl_)
+	local hFile
+	for _, funcEntry in ipairs(functbl_) do
 		if(not hFile) then
-			print("Unable to write " .. filename)
-			return
+			local base, dir = util.ParsePath(basename)
+			util.EnsurePath(dir)
+			local pathname = dir .. filename
+			hFile = io.open(pathname, "w")
+			if(not hFile) then
+				print("Could not write to file " .. pathname)
+				return
+			end
+			
+			hFile = tab.TabbedFile(hFile, "tab")
+			hFile:write("return {\n")
 		end
 		
-		for _, paramName in ipairs(enumParamList) do
-			hFile:write(paramName, "\n")
+		hFile:fmt("['%s'] = {\n", funcEntry.name)
+		hFile:inc()
+		for _, enumParamName in ipairs(funcEntry.list) do
+			hFile:fmt("['%s'] = {},\n", enumParamName)
 		end
+		hFile:dec()
+		hFile:fmt("},\n\n")
 		
+	end
+	
+	if(hFile) then
+		hFile:write("}")
 		hFile:close()
 	end
 end
 
-function my_style.ExtensionFunc(basename, func, typemap, extName, spec, options)
-	PossiblyWriteFile(func, typemap, function()
-		local base, dir = util.ParsePath(basename)
-
-		return dir .. extName
-	end)
+function my_style.WriteExtension(basename, extName, functbl_)
+	local filename = extName .. ".lua"
+	WriteTableToFile(basename, filename, functbl_)
 end
 
-function my_style.VersionFunc(basename, func, typemap, version, spec, options)
-	PossiblyWriteFile(func, typemap, function()
-		local base, dir = util.ParsePath(basename)
-
-		return dir .. "Version_" .. version:gsub("%.", "_")
-	end)
+function my_style.WriteVersion(basename, version, functbl_)
+	local filename = "Version_" .. version:gsub("%.", "_") .. ".lua"
+	WriteTableToFile(basename, filename, functbl_)
 end
 
 local my_struct = 
 {
 { type="func-seen",
 	{ type="ext-iter",
-		{type="func-iter",
-			{ type="call", name="ExtensionFunc(basename, func, typemap, extName, spec, options)", },
+		{ type="context", key="functbl_", name="MakeTable()",
+			{ type="func-iter",
+				{ type="call", name="CollectEnumParams(func, typemap, functbl_)", },
+			},
+			
+			{ type="call", name="WriteExtension(basename, extName, functbl_)", },
 		},
 	},
 	{ type="version-iter",
-		{type="func-iter",
-			{ type="call", name="VersionFunc(basename, func, typemap, version, spec, options)", },
+		{ type="context", key="functbl_", name="MakeTable()",
+			{ type="func-iter",
+				{ type="call", name="CollectEnumParams(func, typemap, functbl_)", },
+			},
+
+			{ type="call", name="WriteVersion(basename, version, functbl_)", },
 		},
 	},
 	ending,