From 08823f5d5b47cb6fcfc41578b75ee2f5537fd782 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Sun, 3 Nov 2013 20:30:43 +0100 Subject: [PATCH] Maintain api version information on converted signatures Signatures were split into 4 APIs before (gl, glcore, gles1, gles2). However, gles2 contains bindings for both version 2.0 and 3.0. The version information is now maintained, which allows us to cut down on the number of generated enumerations. --- Source/Converter/GLXmlParser.cs | 27 ++++++++++++++++++--------- Source/Converter/Main.cs | 11 +++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Source/Converter/GLXmlParser.cs b/Source/Converter/GLXmlParser.cs index 28d55e02..f40b3d8e 100644 --- a/Source/Converter/GLXmlParser.cs +++ b/Source/Converter/GLXmlParser.cs @@ -62,10 +62,12 @@ namespace CHeaderToXML foreach (var e in ParseEnums(input).Concat(ParseFunctions(input))) { var name = e.Attribute("name").Value; - if (!elements.ContainsKey(name)) - elements.Add(name, e); + var version = (e.Attribute("version") ?? new XAttribute("version", String.Empty)).Value; + var key = name + version; + if (!elements.ContainsKey(key)) + elements.Add(key, e); else - elements[name].Add(e.Elements()); + elements[key].Add(e.Elements()); } return elements.Values; @@ -196,7 +198,7 @@ namespace CHeaderToXML foreach (var api in APIs.Values) { - var apiname = api.Attribute("name").Value; + var apiname = api.Attribute("name").Value; // Mark deprecated enums foreach (var token in feature.Elements("remove").Elements("enum")) @@ -265,13 +267,20 @@ namespace CHeaderToXML foreach (var apiname in apinames) { i++; - if (!APIs.ContainsKey(apiname)) - APIs.Add(apiname, new XElement("api", new XAttribute("name", apiname))); - var api = APIs[apiname]; var cmd_category = category; var cmd_version = version.Length > i ? version[i] : version[0]; + var key = apiname + cmd_version; + if (!APIs.ContainsKey(key)) + APIs.Add( + key, + new XElement( + "api", + new XAttribute("name", apiname), + new XAttribute("version", cmd_version))); + var api = APIs[key]; + foreach (var command in feature.Elements("require").Elements("command")) { var cmd_name = TrimName(command.Attribute("name").Value); @@ -292,11 +301,11 @@ namespace CHeaderToXML } i = -1; - foreach (var apiname in apinames) + foreach (var api in APIs.Values) { i++; + var apiname = api.Attribute("name").Value; var cmd_version = version.Length > i ? version[i] : version[0]; - var api = APIs[apiname]; // Mark all deprecated functions as such foreach (var command in feature.Elements("remove").Elements("command")) diff --git a/Source/Converter/Main.cs b/Source/Converter/Main.cs index c75b8a91..dad60d94 100644 --- a/Source/Converter/Main.cs +++ b/Source/Converter/Main.cs @@ -147,6 +147,7 @@ namespace CHeaderToXML output.Add( new XElement("add", new XAttribute("name", api.Attribute("name").Value), + api.Attribute("version") != null ? new XAttribute("version", api.Attribute("version").Value) : null, api.Elements() .OrderBy(s => s.Name.LocalName) .ThenBy(s => (string)s.Attribute("value") ?? String.Empty) @@ -190,19 +191,21 @@ namespace CHeaderToXML private static Dictionary MergeDuplicates(IEnumerable> sigs) { var entries = new Dictionary(); - foreach (var e in sigs.SelectMany(s => s))//.Where(s => s.Name.LocalName == "enum")) + foreach (var e in sigs.SelectMany(s => s)) { var name = (string)e.Attribute("name") ?? ""; - if (entries.ContainsKey(name))// && e.Name.LocalName == "enum") + var version = (string)e.Attribute("version") ?? ""; + var key = name + version; + if (entries.ContainsKey(key)) { - var p = entries[name]; + var p = entries[key]; var curTokens = p.Nodes().ToList(); p.RemoveNodes(); p.Add(curTokens.Concat(e.Nodes()).Distinct(new EnumTokenComparer())); } else { - entries.Add(name, e); + entries.Add(key, e); } } return entries;