Commits

Jason McKesson committed 774dc55

Basic structure of the GL Load style implemented.

Comments (0)

Files changed (5)

modules/StructGLLoad.lua

+
+local struct = require "Structure"
+
+local my_struct =
+{
+-- Internal header files.
+{ type="enum-seen",
+{ type="func-seen",
+	--Write the type header file.
+	{ type="file", style="type_hdr", name="GetFilename(basename, spec, options)",
+	},
+	
+	--Write the extension file
+	{ type="file", style="ext_hdr", name="GetFilename(basename, spec, options)",
+	},
+	
+	--For each version, write files containing just the core declarations.
+	{ type="version-iter",
+		{ type="file", style="core_hdr", name="GetFilename(basename, version, spec, options)",
+		},
+	},
+	
+	--For each version, write files containing core declarations that were removed.
+	{ type="version-iter",
+		{ type="filter", name="VersionHasRemoved(version, specData, spec, options)",
+			{ type="file", style="core_hdr", name="GetFilenameRem(basename, version, spec, options)",
+			},
+		},
+	},
+},
+},
+
+	--Main header files.
+	{ type="version-iter",
+		{ type="file", style="incl_hdr", name="VersionFilenameCore(basename, version, spec, options)",
+			{ type="block", name="IncludeGuardCore(hFile, version, spec, options)",
+				{ type="blank" },
+				{ type="write", name="IncludeIntType(hFile, spec, options)"},
+				{ type="write", name="IncludeIntExts(hFile, spec, options)"},
+				{ type="blank" },
+				{ type="sub-version-iter",
+					{ type="write", name="IncludeIntVersionCore(hFile, sub_version, spec, options)"},
+					{ type="blank", last=true, },
+				},
+			},
+		},
+	},
+
+	--Compatibility headers.
+	{ type="version-iter",
+		{ type="filter", name="HasCompatibility(version, specData, spec, options)",
+			{ type="file", style="incl_hdr", name="VersionFilenameComp(basename, version, spec, options)",
+				{ type="block", name="IncludeGuardComp(hFile, version, spec, options)",
+					{ type="blank" },
+					{ type="write", name="IncludeIntType(hFile, spec, options)"},
+					{ type="write", name="IncludeIntExts(hFile, spec, options)"},
+					{ type="blank" },
+					{ type="sub-version-iter",
+						{ type="write", name="IncludeIntVersionCore(hFile, sub_version, spec, options)"},
+						{ type="write", name="IncludeIntVersionComp(hFile, sub_version, specData, spec, options)"},
+						{ type="blank", last=true, },
+					},
+				},
+			},
+		},
+	},
+
+	--Header that includes everything.
+	{ type="file", style="incl_hdr", name="AllFilename(basename, spec, options)",
+		{ type="block", name="IncludeGuardAll(hFile, spec, options)",
+			{ type="blank" },
+			{ type="write", name="IncludeIntType(hFile, spec, options)"},
+			{ type="write", name="IncludeIntExts(hFile, spec, options)"},
+			{ type="blank" },
+			{ type="version-iter",
+				{ type="write", name="IncludeIntVersionCore(hFile, version, spec, options)"},
+				{ type="write", name="IncludeIntVersionComp(hFile, version, specData, spec, options)"},
+				{ type="blank", last=true, },
+			},
+		},
+	},
+
+	--Header to load things.
+	{ type="file", style="load_hdr", name="GetFilename(basename, spec, options)",
+	},
+	
+	--Source file.
+	{ type="file", style="source", name="GetFilename(basename, spec, options)",
+	},
+}
+
+
+my_struct = struct.BuildStructure(my_struct)
+
+return my_struct

modules/Structure.lua

 - file_style	Provided by file blocks. A file-specific subsection of `style`.
 - extName		Provided by extension iterators.
 - version		Provided by version iterators.
+- sub_version	Provided by sub-version iterators.
 - enum			Provided by enum iterators.
 - enumTable		Provided by enum iterators.
 - enumSeen		Provided by enum seen blocks.
 -		style: This represents a scoping for the style for all children of the file. So if your style has a "header" subtable with functions for creating header files, you set `style` to "header".
 
 - 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)
+-		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).
 
 - 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).
 
-- blank: Writes an empty line.
+- blank: Writes an empty line. Must be in a file scope.
+
+- filter: Contains a group of actions. If the named function returns false, then the children will not be processed.
+-		name: Part of the function name to call. The complete function name is "Filter"..name. The default parameters are () (ie: none).
 
 - ext-iter: Iterates over all of the extensions explicitly requested by the user. Cannot nest. Children can access the `extName` parameter, the name of the current extension.
 
-- version-iter: Iterates over each version in the spec, where applicable. Cannot nest. Children can access the `version` parameter, the current version as a *string*.
+- version-iter: Iterates over each version in the spec, which is less than or equal to the requested version, where applicable. Cannot nest. Children can access the `version` parameter, the current version as a *string*.
+
+- sub-version-iter: Iterates over each version that is less than or equal to the current version. Cannot nest. Must be done within a context that provides the `version` parameter. Children can access the `sub_version` parameter, the current sub-version as a *string*.
 
 - core-ext-iter: Iterates over all core extensions of the current version. Cannot nest. Must be done within a context that provides the `version` parameter. Children can access the `extName` parameter, the name of the current core extension.
 
 	self:CallFunction(context.file_style, context)
 end
 
-function writeAction:PostProcess(context)
-end
-
 MakeActionType("write", writeAction, function(self, data)
 	assert(data.name, "Write actions must have a `name`")
 	self.name = "Write" .. self.name
 local blankAction = {}
 
 function blankAction:PreProcess(context)
-	self:Assert(context.hFile, "Spaces must be in files.")
+	self:Assert(context.hFile, "Blanks must be in files.")
 	context.hFile:write("\n")
 end
 
 end)
 
 
+-------------------------------------------
+-- Filter Action
+local filterAction = {}
+
+function filterAction:PreProcess(context)
+	return not self:CallFunction(context:GetStyle(), context, self.name)
+end
+
+MakeActionType("filter", filterAction, function(self, data)
+	assert(data.name, "Filter actions must have a `name`")
+	self.name = "Filter" .. self.name
+	self.params = self.params or {}
+end)
+
+
 ---------------------------------------------
 -- Extension Iterator Action
 local extIterAction = {}
 end
 
 
+-----------------------------------------------
+-- Sub-Version Iterator
+local subVersionIterAction = {}
+
+function subVersionIterAction:PreProcess(context)
+	self:Assert(context.sub_version == nil, "Cannot nest sub-version-iter actions.")
+	self:Assert(context.version, "Must put sub-version-iter inside versions.")
+	local rawVersionList = context.spec.GetVersions()
+	local versionList = {}
+	for _, version in ipairs(rawVersionList) do
+		if(tonumber(version) <= tonumber(context.version)) then
+			versionList[#versionList + 1] = version
+		end
+	end
+
+	self:IterateChildren(context, versionList, "sub_version")
+	return true --Stops regular child processing.
+end
+
+MakeActionType("sub-version-iter", subVersionIterAction, function(self, data)
+end)
+
+
 ---------------------------------------------
 -- Core Extension Iterator Action
 local coreExtIterAction = {}
 end
 
 function coreExtCullIterAction:PreProcess(context)
-	self:Assert(context.version, "Must put this in a version iterator")
-	self:Assert(context.extName == nil, "Cannot nest core-ext-iter actions.")
+	self:Assert(context.version, "Must put core-ext-cull-iters in a version")
+	self:Assert(context.extName == nil, "Cannot nest core-ext-cull-iter actions.")
 	local extList = BuildCulledExtList(context)
 	if(#extList > 0) then
 		self:IterateChildren(context, extList, "extName")
 		context._coreExts = spec.GetCoreExts()
 		context._extTbl = util.InvertTable(options.extensions)
 		
+		function context:GetStyle()
+			return context.file_style or self.style
+		end
+		
 		for _, action in ipairs(actions) do
 			action:Process(context)
 		end

modules/StyleGLLoadC.lua

+local util = require "util"
+local struct = require "StructGLLoad"
+local common = require "CommonStyle"
+local glload = require "glload_util"
+
+
+local my_style
+
+----------------------------------------------------------
+-- Type header.
+local type_hdr = {}
+
+function type_hdr.GetFilename(basename, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. glload.GetTypeHeaderBasename(spec, options)
+end
+
+-----------------------------------------------------------
+-- Extension header.
+local ext_hdr = {}
+
+function ext_hdr.GetFilename(basename, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. glload.GetExtsHeaderBasename(spec, options)
+end
+
+
+-----------------------------------------------------------
+-- Core header.
+local core_hdr = {}
+
+function core_hdr.GetFilename(basename, version, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. glload.GetCoreHeaderBasename(version, spec, options)
+end
+
+function core_hdr.GetFilenameRem(basename, version, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. glload.GetRemHeaderBasename(version, spec, options)
+end
+
+
+-----------------------------------------------------------
+-- Include header
+local incl_hdr = {}
+
+function incl_hdr.VersionFilenameCore(basename, version, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. spec.FilePrefix() .. version .. ".h"
+end
+
+function incl_hdr.VersionFilenameComp(basename, version, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. spec.FilePrefix() .. version .. "_comp.h"
+end
+
+function incl_hdr.AllFilename(basename, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. spec.FilePrefix() .. "all.h"
+end
+
+function incl_hdr.WriteBlockBeginIncludeGuardCore(hFile, version, spec, options)
+	local includeGuard = glload.GetInclFileIncludeGuard(version, spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function incl_hdr.WriteBlockEndIncludeGuardCore(hFile, version, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetInclFileIncludeGuard(version, spec, options))
+end
+
+function incl_hdr.WriteBlockBeginIncludeGuardComp(hFile, version, spec, options)
+	local includeGuard = glload.GetInclFileCompIncludeGuard(version, spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function incl_hdr.WriteBlockEndIncludeGuardComp(hFile, version, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetInclFileCompIncludeGuard(version, spec, options))
+end
+
+function incl_hdr.WriteBlockBeginIncludeGuardAll(hFile, spec, options)
+	local includeGuard = glload.GetInclFileAllIncludeGuard(spec, options)
+	hFile:fmt("#ifndef %s\n", includeGuard)
+	hFile:fmt("#define %s\n", includeGuard)
+end
+
+function incl_hdr.WriteBlockEndIncludeGuardAll(hFile, spec, options)
+	hFile:fmt("#endif //%s\n", glload.GetInclFileAllIncludeGuard(spec, options))
+end
+
+function incl_hdr.WriteIncludeIntType(hFile, spec, options)
+	hFile:fmt('#include "%s"\n', glload.GetTypeHeaderBasename(spec, options))
+end
+
+function incl_hdr.WriteIncludeIntExts(hFile, spec, options)
+	hFile:fmt('#include "%s"\n', glload.GetExtsHeaderBasename(spec, options))
+end
+
+function incl_hdr.WriteIncludeIntVersionCore(hFile, sub_version, spec, options)
+	hFile:fmt('#include "%s"\n', glload.GetCoreHeaderBasename(sub_version, spec, options))
+end
+
+function incl_hdr.WriteIncludeIntVersionComp(hFile, sub_version, specData, spec, options)
+	if(not my_style.FilterVersionHasRemoved(sub_version, specData, spec, options)) then
+		return
+	end
+	
+	hFile:fmt('#include "%s"\n', glload.GetRemHeaderBasename(sub_version, spec, options))
+end
+
+----------------------------------------------------------
+-- Type header.
+local load_hdr = {}
+
+function load_hdr.GetFilename(basename, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.headerDirectory .. spec.FilePrefix() .. "load.h"
+end
+
+
+----------------------------------------------------------
+-- Source file.
+local source = {}
+
+function source.GetFilename(basename, spec, options)
+	local basename, dir = util.ParsePath(basename)
+	return dir .. glload.sourceDirectory .. spec.FilePrefix() .. "load.c"
+end
+
+
+
+my_style =
+{
+	type_hdr = type_hdr,
+	ext_hdr = ext_hdr,
+	core_hdr = core_hdr,
+	incl_hdr = incl_hdr,
+	load_hdr = load_hdr,
+	source = source,
+}
+
+function my_style.FilterVersionHasRemoved(version, specData, spec, options)
+	for _, enum in ipairs(specData.coredefs[version].enums) do
+		if(enum.removed) then
+			return true
+		end
+	end
+	
+	for _, func in ipairs(specData.coredefs[version].funcs) do
+		if(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
+	else
+		return false
+	end
+end
+
+local function Create()
+	return common.DeepCopyTable(my_style), struct
+end
+
+return { Create = Create }

modules/Styles.lua

 {
 	pointer_c = require("StylePointerC"),
 	pointer_cpp = require("StylePointerCPP"),
+	glload_c = require("StyleGLLoadC"),
 }
 
 local default_style = "pointer_c"

modules/glload_util.lua

+
+local util = require "util"
+
+local data = {}
+
+data.internalPrefix = "_int_"
+data.headerDirectory = ""
+data.sourceDirectory = ""
+
+function data.GetTypeHeaderBasename(spec, options)
+	return data.internalPrefix .. spec.FilePrefix() .. "type.h"
+end
+
+function data.GetExtsHeaderBasename(spec, options)
+	return data.internalPrefix .. spec.FilePrefix() .. "exts.h"
+end
+
+function data.GetCoreHeaderBasename(version, spec, options)
+	return data.internalPrefix .. spec.FilePrefix() .. version .. ".h"
+end
+
+function data.GetRemHeaderBasename(version, spec, options)
+	return data.internalPrefix .. spec.FilePrefix() .. version .. "_rem.h"
+end
+
+function data.GetInclFileIncludeGuard(version, spec, options)
+	return spec.GetIncludeGuardString() .. "_GEN_" .. version:gsub("%.", "_") .. "_H"
+end
+
+function data.GetInclFileCompIncludeGuard(version, spec, options)
+	return spec.GetIncludeGuardString() .. "_GEN_" .. version:gsub("%.", "_") .. "COMP_H"
+end
+
+function data.GetInclFileAllIncludeGuard(spec, options)
+	return spec.GetIncludeGuardString() .. "_GEN_ALL_H"
+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.