Jason McKesson avatar Jason McKesson committed 7c355d7

GL Load headers complete (outside of bugs).

Comments (0)

Files changed (4)

modules/StructGLLoad.lua

 
 local struct = require "Structure"
 
+--Common set of header stuff.
+local common_ext_struct =
+{ type="group",
+	{ type="enum-iter",
+		{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options)", },
+	},
+	{ type="blank", cond="enum-iter"},
+	{ type="func-iter",
+		{ type="write", name="FuncTypedef(hFile, func, typemap, spec, options)", },
+	},
+	{ type="blank", cond="func-iter"},
+	{ type="func-iter",
+		{ type="write", name="FuncDecl(hFile, func, typemap, spec, options)", },
+	},
+	{ type="blank", cond="func-iter"},
+}
+
+--Extension file.
+local ext_file_struct =
+{ type="file", style="ext_hdr", name="GetFilename(basename, spec, options)",
+	{ type="block", name="IncludeGuard",
+		{ type="blank"},
+		{ type="write", name="Typedefs(hFile, specData, spec, options)",},
+		{ type="blank"},
+		{ type="block", name="Extern(hFile, spec, options)",
+			{ type="ext-iter",
+				{ type="write", name="ExtVariable(hFile, extName, spec, options)" },
+			},
+			{ type="blank"},
+			{ type="ext-iter",
+				common_ext_struct,
+			},
+		},
+	},
+}
+
+
 local my_struct =
 {
 -- Internal header files.
 { type="func-seen",
 	--Write the type header file.
 	{ type="file", style="type_hdr", name="GetFilename(basename, spec, options)",
+		{ type="block", name="IncludeGuard(hFile, spec, options)",
+			{ type="write", name="Init(hFile, spec, options)"},
+			{ type="write", name="StdTypedefs(hFile, spec, options)"},
+			{ type="write", name="PassthruTypedefs(hFile, specData, spec, options)"},
+		},
 	},
 	
 	--Write the extension file
-	{ type="file", style="ext_hdr", name="GetFilename(basename, spec, options)",
-	},
+	ext_file_struct,
 	
 	--For each version, write files containing just the core declarations.
 	{ type="version-iter",
-		{ type="file", style="core_hdr", name="GetFilename(basename, version, spec, options)",
+		{ type="filter", name="VersionHasCore(version, specData, spec, options)",
+			{ type="file", style="core_hdr", name="GetFilename(basename, version, spec, options)",
+				{ type="block", name="IncludeGuard(hFile, version, spec, options)",
+					{ type="blank"},
+					{ type="block", name="Extern(hFile, spec, options)",
+						common_ext_struct,
+					},
+				},
+			},
 		},
 	},
 	
 	{ type="version-iter",
 		{ type="filter", name="VersionHasRemoved(version, specData, spec, options)",
 			{ type="file", style="core_hdr", name="GetFilenameRem(basename, version, spec, options)",
+				{ type="block", name="IncludeGuardRem(hFile, version, spec, options)",
+					{ type="blank"},
+					{ type="block", name="Extern(hFile, spec, options)",
+						common_ext_struct,
+					},
+				},
 			},
 		},
 	},

modules/Structure.lua

 - block: Represents a block. Must be in a file scope.
 -		name: Part of the function name to call. When starting the block, it will call "WriteBlockBegin"..name. To end it, it will call "WriteBlockEnd"..name. The default parameters are (hFile, spec, options).
 
+- group: Represents a collection of stuff. Has no particular semantics (though it can have conditionals and such.
+
 - write: Simply calls a given writing function. Must be in a file scope.
 -		name: Part of the function name to call. The complete function name is "Write"..name. The default parameters are (hFile, specData, spec, options).
 
 - first: When set, this particular action (and any of its child actions) will only be executed the first time through the most recent iteration loop. Note that this only works for the most recent iteration loop. And it only works within an interation loop, since they are the only ones who execute their children multiple times.
 
 - last: Like first, except for the last time through a block. Usually for inserting blank space.
+
+- cond: Only processes the node and its children if the condition is "true". Available conditions:
+	- ext-iter
+	- version-iter
+	- core-ext-iter
+	- core-ext-cull-iter
+	- enum-iter
+	- func-iter
+	- core-funcs: True if the spec has core functions. IE: is OpenGL.
+
+All of the iterator-based conditions will be true iff performing that iterator in this context would result in at least one match. They can only be used in the same context where the equivalent iterator could.
+
 ]]
 
 local actionTypes = {}
 end)
 
 
+-------------------------------------
+-- Group Action
+local groupAction = {}
+
+MakeActionType("group", groupAction, function(self, data)
+end)
+
+
 ------------------------------------------
 -- Write Action
 local writeAction = {}
 end)
 
 conditionals["enum-iter"] = function(context)
-	self:Assert(context.version or context.extName, "Cannot have an enum-iter conditional outside of a version or extension iterator.")
+	assert(context.version or context.extName, "Cannot have an enum-iter conditional outside of a version or extension iterator.")
 
 	return #GetEnumList(context) > 0
 end

modules/StyleGLLoadC.lua

 	return dir .. glload.headerDirectory .. glload.GetTypeHeaderBasename(spec, options)
 end
 
+function type_hdr.WriteBlockBeginIncludeGuard(hFile, spec, options)
+	local includeGuard = glload.GetTypeHdrFileIncludeGuard(spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function type_hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetTypeHdrFileIncludeGuard(spec, options))
+end
+
+function type_hdr.WriteInit(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
+function type_hdr.WriteStdTypedefs(hFile, spec, options)
+	local defArray = common.GetStdTypedefs()
+	
+	--Use include-guards for the typedefs, since they're common among
+	--headers in this style.
+	hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("\n")
+	hFile:inc()
+	
+	for _, def in ipairs(defArray) do
+		hFile:write(def)
+	end
+	
+	hFile:dec()
+	hFile:write("\n")
+	hFile:write("#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/\n")
+	hFile:write("\n")
+end
+
+function type_hdr.WritePassthruTypedefs(hFile, specData, spec, options)
+	common.WritePassthruData(hFile, specData.funcData.passthru)
+end
+
 -----------------------------------------------------------
 -- Extension header.
 local ext_hdr = {}
 	return dir .. glload.headerDirectory .. glload.GetExtsHeaderBasename(spec, options)
 end
 
+function ext_hdr.WriteBlockBeginIncludeGuard(hFile, spec, options)
+	local includeGuard = glload.GetExtFileIncludeGuard(spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function ext_hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetExtFileIncludeGuard(spec, options))
+end
+
+function ext_hdr.WriteTypedefs(hFile, specData, spec, options)
+	common.WritePassthruData(hFile, specData.funcData.passthru)
+end
+
+function ext_hdr.WriteBlockBeginExtern(hFile, spec, options)
+	hFile:writeblock(glload.GetBeginExternBlock())
+end
+
+function ext_hdr.WriteBlockEndExtern(hFile, spec, options)
+	hFile:writeblock(glload.GetEndExternBlock())
+end
+
+function ext_hdr.WriteExtVariable(hFile, extName, spec, options)
+	hFile:fmt("extern int %s;\n",
+		glload.GetExtVariableName(extName, spec, options))
+end
+
+function ext_hdr.WriteEnumerator(hFile, enum, enumTable, spec, options)
+	hFile:fmt("#define %s %s\n",
+		glload.GetEnumeratorName(enum, spec, options),
+		common.ResolveEnumValue(enum, enumTable))
+end
+
+function ext_hdr.WriteFuncTypedef(hFile, func, typemap, spec, options)
+	hFile:fmt(glload.GetTypedefFormat(spec),
+		common.GetFuncReturnType(func, typemap),
+		glload.GetFuncTypedefName(func, spec, options),
+		common.GetFuncParamList(func, typemap))
+end
+
+function ext_hdr.WriteFuncDecl(hFile, func, typemap, spec, options)
+	hFile:fmt("extern %s %s;\n",
+		glload.GetFuncTypedefName(func, spec, options),
+		glload.GetFuncPtrName(func, spec, options))
+	hFile:fmt("#define %s %s\n",
+		spec.FuncNamePrefix() .. func.name,
+		glload.GetFuncPtrName(func, spec, options))
+end
+
 
 -----------------------------------------------------------
 -- Core header.
 	return dir .. glload.headerDirectory .. glload.GetRemHeaderBasename(version, spec, options)
 end
 
+function core_hdr.WriteBlockBeginIncludeGuard(hFile, version, spec, options)
+	local includeGuard = glload.GetCoreHdrFileIncludeGuard(version, spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function core_hdr.WriteBlockEndIncludeGuard(hFile, version, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options))
+end
+
+function core_hdr.WriteBlockBeginIncludeGuardRem(hFile, version, spec, options)
+	local includeGuard = glload.GetCoreHdrFileIncludeGuard(version, spec, options, true)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function core_hdr.WriteBlockEndIncludeGuardRem(hFile, version, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options, true))
+end
+
+function core_hdr.WriteBlockBeginExtern(hFile, spec, options)
+	hFile:writeblock(glload.GetBeginExternBlock())
+end
+
+function core_hdr.WriteBlockEndExtern(hFile, spec, options)
+	hFile:writeblock(glload.GetEndExternBlock())
+end
+
+function core_hdr.WriteEnumerator(hFile, enum, enumTable, spec, options)
+	hFile:fmt("#define %s %s\n",
+		glload.GetEnumeratorName(enum, spec, options),
+		common.ResolveEnumValue(enum, enumTable))
+end
+
+function core_hdr.WriteFuncTypedef(hFile, func, typemap, spec, options)
+	hFile:fmt(glload.GetTypedefFormat(spec),
+		common.GetFuncReturnType(func, typemap),
+		glload.GetFuncTypedefName(func, spec, options),
+		common.GetFuncParamList(func, typemap))
+end
+
+function core_hdr.WriteFuncDecl(hFile, func, typemap, spec, options)
+	hFile:fmt("extern %s %s;\n",
+		glload.GetFuncTypedefName(func, spec, options),
+		glload.GetFuncPtrName(func, spec, options))
+	hFile:fmt("#define %s %s\n",
+		spec.FuncNamePrefix() .. func.name,
+		glload.GetFuncPtrName(func, spec, options))
+end
+
 
 -----------------------------------------------------------
 -- Include header
 	return false
 end
 
+function my_style.FilterVersionHasCore(version, specData, spec, options)
+	for _, enum in ipairs(specData.coredefs[version].enums) do
+		if(not enum.removed and not enum.extensions) then
+			return true
+		end
+	end
+	
+	for _, func in ipairs(specData.coredefs[version].funcs) do
+		if(not func.deprecated) then
+			return true
+		end
+	end
+	
+	return false
+end
+
+
 function my_style.FilterHasCompatibility(version, specData, spec, options)
 	if(tonumber(version) >= 3.1) then
 		return true

modules/glload_util.lua

 	return data.internalPrefix .. spec.FilePrefix() .. version .. "_rem.h"
 end
 
+function data.GetExtVariableName(extName, spec, options)
+	return spec.FuncNamePrefix() .. "ext_" .. extName
+end
+
+function data.GetEnumeratorName(enum, spec, options)
+	return spec.EnumNamePrefix() .. enum.name
+end
+
+function data.GetFuncTypedefName(func, spec, options)
+	local temp = "PFN" .. spec.FuncNamePrefix() .. func.name .. "PROC"
+	return temp:upper()
+end
+
+--Three parameters: the return value, the typedef name, and the params
+function data.GetTypedefFormat(spec)
+	return "typedef %s (" .. spec.GetCodegenPtrType() .. " * %s)(%s);\n"
+end
+
+function data.GetFuncPtrName(func, spec, options)
+	return "_funcptr_" .. spec.FuncNamePrefix() .. func.name
+end
+
+function data.GetTypeHdrFileIncludeGuard(spec, options)
+	return spec.GetIncludeGuardString() .. "_GEN_TYPE" .. "_H"
+end
+
+function data.GetExtFileIncludeGuard(spec, options)
+	return spec.GetIncludeGuardString() .. "_GEN_EXTENSIONS" .. "_H"
+end
+
+function data.GetCoreHdrFileIncludeGuard(version, spec, options, removed)
+	if(removed) then
+		return spec.GetIncludeGuardString() .. "_GEN_CORE_REM" .. version:gsub("%.", "_") .. "_H"
+	else
+		return spec.GetIncludeGuardString() .. "_GEN_CORE_" .. version:gsub("%.", "_") .. "_H"
+	end
+end
+
 function data.GetInclFileIncludeGuard(version, spec, options)
 	return spec.GetIncludeGuardString() .. "_GEN_" .. version:gsub("%.", "_") .. "_H"
 end
 	return spec.GetIncludeGuardString() .. "_GEN_ALL_H"
 end
 
+function data.GetBeginExternBlock()
+	return [[
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+]]
+end
+
+function data.GetEndExternBlock()
+	return [[
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+]]
+end
+
+
 return data
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.