mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-04-17 21:01:42 +00:00
[Bind] Allow multiple overrides files
Multiple overrides files allow us to split overrides by extension, simplifying maintenance.
This commit is contained in:
parent
5e8357b17e
commit
c6e8991872
|
@ -25,6 +25,8 @@ namespace Bind.ES
|
|||
Settings.DefaultDocPath = Path.Combine(
|
||||
Settings.DefaultDocPath, "ES20");
|
||||
|
||||
Settings.OverridesFiles.Add("GL2/overrides.xml");
|
||||
|
||||
Profile = "gles2";
|
||||
Version = "2.0";
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace Bind.ES
|
|||
Settings.DefaultDocPath = Path.Combine(
|
||||
Settings.DefaultDocPath, "ES30");
|
||||
|
||||
Settings.OverridesFiles.Add("GL2/overrides.xml");
|
||||
|
||||
Profile = "gles2"; // The 3.0 spec reuses the gles2 apiname
|
||||
Version = "2.0|3.0";
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace Bind.ES
|
|||
Settings.DefaultDocPath = Path.Combine(
|
||||
Settings.DefaultDocPath, "ES20"); // no ES11 docbook sources available
|
||||
|
||||
Settings.OverridesFiles.Add("GL2/overrides.xml");
|
||||
|
||||
// Khronos releases a combined 1.0+1.1 specification,
|
||||
// so we cannot distinguish between the two.
|
||||
// Todo: add support for common and light profiles.
|
||||
|
|
|
@ -39,12 +39,12 @@ namespace Bind
|
|||
{
|
||||
class EnumProcessor
|
||||
{
|
||||
string Overrides { get; set; }
|
||||
readonly IEnumerable<string> Overrides;
|
||||
|
||||
IBind Generator { get; set; }
|
||||
Settings Settings { get { return Generator.Settings; } }
|
||||
|
||||
public EnumProcessor(IBind generator, string overrides)
|
||||
public EnumProcessor(IBind generator, IEnumerable<string> overrides)
|
||||
{
|
||||
if (generator == null)
|
||||
throw new ArgumentNullException("generator");
|
||||
|
@ -57,9 +57,14 @@ namespace Bind
|
|||
|
||||
public EnumCollection Process(EnumCollection enums, string apiname)
|
||||
{
|
||||
var nav = new XPathDocument(Overrides).CreateNavigator();
|
||||
enums = ProcessNames(enums, nav, apiname);
|
||||
enums = ProcessConstants(enums, nav, apiname);
|
||||
foreach (var file in Overrides)
|
||||
{
|
||||
Console.WriteLine("Processing enums in {0}.", file);
|
||||
|
||||
var nav = new XPathDocument(file).CreateNavigator();
|
||||
enums = ProcessNames(enums, nav, apiname);
|
||||
enums = ProcessConstants(enums, nav, apiname);
|
||||
}
|
||||
return enums;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,12 @@ namespace Bind
|
|||
RegexOptions.Compiled);
|
||||
static readonly Regex EndingsAddV = new Regex("^0", RegexOptions.Compiled);
|
||||
|
||||
string Overrides { get; set; }
|
||||
readonly IEnumerable<string> Overrides;
|
||||
|
||||
IBind Generator { get; set; }
|
||||
Settings Settings { get { return Generator.Settings; } }
|
||||
|
||||
public FuncProcessor(IBind generator, string overrides)
|
||||
public FuncProcessor(IBind generator, IEnumerable<string> overrides)
|
||||
{
|
||||
if (generator == null)
|
||||
throw new ArgumentNullException("generator");
|
||||
|
@ -73,43 +73,47 @@ namespace Bind
|
|||
public FunctionCollection Process(EnumProcessor enum_processor, DocProcessor doc_processor,
|
||||
DelegateCollection delegates, EnumCollection enums, string apiname, string apiversion)
|
||||
{
|
||||
Console.WriteLine("Processing delegates.");
|
||||
var nav = new XPathDocument(Overrides).CreateNavigator();
|
||||
foreach (var version in apiversion.Split('|'))
|
||||
foreach (var file in Overrides)
|
||||
{
|
||||
// Translate each delegate:
|
||||
// 1st using the <replace> elements in overrides.xml
|
||||
// 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
|
||||
foreach (var signatures in delegates.Values)
|
||||
{
|
||||
foreach (var d in signatures)
|
||||
{
|
||||
var replace = GetFuncOverride(nav, d, apiname, apiversion);
|
||||
TranslateExtension(d);
|
||||
TranslateReturnType(d, replace, nav, enum_processor, enums, apiname, version);
|
||||
TranslateParameters(d, replace, nav, enum_processor, enums, apiname, version);
|
||||
TranslateAttributes(d, replace, nav, apiname, version);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Processing delegates in {0}.", file);
|
||||
|
||||
// Create overloads for backwards compatibility,
|
||||
// by resolving <overload> elements
|
||||
var overload_list = new List<Delegate>();
|
||||
foreach (var d in delegates.Values.Select(v => v.First()))
|
||||
var nav = new XPathDocument(file).CreateNavigator();
|
||||
foreach (var version in apiversion.Split('|'))
|
||||
{
|
||||
var overload_elements = GetFuncOverload(nav, d, apiname, apiversion);
|
||||
foreach (XPathNavigator overload_element in overload_elements)
|
||||
// Translate each delegate:
|
||||
// 1st using the <replace> elements in overrides.xml
|
||||
// 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
|
||||
foreach (var signatures in delegates.Values)
|
||||
{
|
||||
var overload = new Delegate(d);
|
||||
TranslateReturnType(overload, overload_element, nav, enum_processor, enums, apiname, version);
|
||||
TranslateParameters(overload, overload_element, nav, enum_processor, enums, apiname, version);
|
||||
TranslateAttributes(overload, overload_element, nav, apiname, version);
|
||||
overload_list.Add(overload);
|
||||
foreach (var d in signatures)
|
||||
{
|
||||
var replace = GetFuncOverride(nav, d, apiname, apiversion);
|
||||
TranslateExtension(d);
|
||||
TranslateReturnType(d, replace, nav, enum_processor, enums, apiname, version);
|
||||
TranslateParameters(d, replace, nav, enum_processor, enums, apiname, version);
|
||||
TranslateAttributes(d, replace, nav, apiname, version);
|
||||
}
|
||||
}
|
||||
|
||||
// Create overloads for backwards compatibility,
|
||||
// by resolving <overload> elements
|
||||
var overload_list = new List<Delegate>();
|
||||
foreach (var d in delegates.Values.Select(v => v.First()))
|
||||
{
|
||||
var overload_elements = GetFuncOverload(nav, d, apiname, apiversion);
|
||||
foreach (XPathNavigator overload_element in overload_elements)
|
||||
{
|
||||
var overload = new Delegate(d);
|
||||
TranslateReturnType(overload, overload_element, nav, enum_processor, enums, apiname, version);
|
||||
TranslateParameters(overload, overload_element, nav, enum_processor, enums, apiname, version);
|
||||
TranslateAttributes(overload, overload_element, nav, apiname, version);
|
||||
overload_list.Add(overload);
|
||||
}
|
||||
}
|
||||
foreach (var overload in overload_list)
|
||||
{
|
||||
delegates.Add(overload);
|
||||
}
|
||||
}
|
||||
foreach (var overload in overload_list)
|
||||
{
|
||||
delegates.Add(overload);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace Bind.GL2
|
|||
Settings.DefaultDocPath = Path.Combine(
|
||||
Settings.DefaultDocPath, "GL");
|
||||
|
||||
Settings.OverridesFiles.Add("GL2/overrides.xml");
|
||||
Settings.OverridesFiles.Add("GL2/GL/");
|
||||
|
||||
//Settings.DefaultCompatibility |=
|
||||
// Settings.Legacy.UseDllImports | Settings.Legacy.UseWindowsCompatibleGL;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ namespace Bind.GL2
|
|||
Settings.DefaultDocPath = Path.Combine(
|
||||
Settings.DefaultDocPath, "GL");
|
||||
|
||||
Settings.OverridesFiles.Add("GL2/overrides.xml");
|
||||
Settings.OverridesFiles.Add("GL2/GL/");
|
||||
|
||||
Profile = "glcore";
|
||||
|
||||
//Settings.DefaultCompatibility |=
|
||||
|
|
|
@ -76,7 +76,6 @@ namespace Bind.GL2
|
|||
enumSpecExt = String.Empty;
|
||||
glSpec = Path.Combine(dirName, "signatures.xml");
|
||||
glSpecExt = String.Empty;
|
||||
Settings.OverridesFile = Path.Combine(dirName, "overrides.xml");
|
||||
|
||||
Settings.ImportsClass = "Core";
|
||||
Settings.DelegatesClass = "Delegates";
|
||||
|
@ -91,6 +90,27 @@ namespace Bind.GL2
|
|||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
path = Path.Combine(Settings.InputPath, path);
|
||||
if ((File.GetAttributes(path) & FileAttributes.Directory) != 0)
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(
|
||||
path, "*.xml", SearchOption.AllDirectories))
|
||||
{
|
||||
yield return file;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return path;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IBind Members
|
||||
|
||||
public DelegateCollection Delegates { get; private set; }
|
||||
|
@ -101,15 +121,24 @@ namespace Bind.GL2
|
|||
|
||||
public virtual void Process()
|
||||
{
|
||||
string overrides = Path.Combine(Settings.InputPath, Settings.OverridesFile);
|
||||
|
||||
var overrides = Settings.OverridesFiles.SelectMany(GetFiles);
|
||||
|
||||
GLTypes = SpecReader.ReadTypeMap(Path.Combine(Settings.InputPath, glTypemap));
|
||||
CSTypes = SpecReader.ReadCSTypeMap(Path.Combine(Settings.InputPath, csTypemap));
|
||||
|
||||
// Read enum signatures
|
||||
SpecReader.ReadEnums(Path.Combine(Settings.InputPath, enumSpec), Enums, Profile, Version);
|
||||
SpecReader.ReadEnums(overrides, Enums, Profile, Version);
|
||||
foreach (var file in overrides)
|
||||
{
|
||||
SpecReader.ReadEnums(file, Enums, Profile, Version);
|
||||
}
|
||||
|
||||
// Read delegate signatures
|
||||
SpecReader.ReadDelegates(Path.Combine(Settings.InputPath, glSpec), Delegates, Profile, Version);
|
||||
SpecReader.ReadDelegates(overrides, Delegates, Profile, Version);
|
||||
foreach (var file in overrides)
|
||||
{
|
||||
SpecReader.ReadDelegates(file, Delegates, Profile, Version);
|
||||
}
|
||||
|
||||
var enum_processor = new EnumProcessor(this, overrides);
|
||||
var func_processor = new FuncProcessor(this, overrides);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
@ -14,9 +15,9 @@ namespace Bind
|
|||
[Serializable]
|
||||
class Settings
|
||||
{
|
||||
// Disable BeforeFieldInit.
|
||||
public Settings()
|
||||
{
|
||||
OverridesFiles = new List<string>();
|
||||
}
|
||||
|
||||
public string DefaultInputPath = "../../../Source/Bind/Specifications";
|
||||
|
@ -25,7 +26,6 @@ namespace Bind
|
|||
public string DefaultDocPath = "../../../Source/Bind/Specifications/Docs";
|
||||
public string DefaultFallbackDocPath = "../../../Source/Bind/Specifications/Docs/GL";
|
||||
public string DefaultLicenseFile = "License.txt";
|
||||
public string DefaultOverridesFile = "GL2/gloverrides.xml";
|
||||
public string DefaultLanguageTypeMapFile = "csharp.tm";
|
||||
public string DefaultKeywordEscapeCharacter = "@";
|
||||
public string DefaultImportsFile = "Core.cs";
|
||||
|
@ -34,7 +34,7 @@ namespace Bind
|
|||
public string DefaultWrappersFile = "GL.cs";
|
||||
public Legacy DefaultCompatibility = Legacy.NoDropMultipleTokens;
|
||||
|
||||
string inputPath, outputPath, outputNamespace, docPath, fallbackDocPath, licenseFile, overridesFile,
|
||||
string inputPath, outputPath, outputNamespace, docPath, fallbackDocPath, licenseFile,
|
||||
languageTypeMapFile, keywordEscapeCharacter, importsFile, delegatesFile, enumsFile,
|
||||
wrappersFile;
|
||||
Nullable<Legacy> compatibility;
|
||||
|
@ -44,7 +44,7 @@ namespace Bind
|
|||
public string DocPath { get { return docPath ?? DefaultDocPath; } set { docPath = value; } }
|
||||
public string FallbackDocPath { get { return fallbackDocPath ?? DefaultFallbackDocPath; } set { fallbackDocPath = value; } }
|
||||
public string LicenseFile { get { return licenseFile ?? DefaultLicenseFile; } set { licenseFile = value; } }
|
||||
public string OverridesFile { get { return overridesFile ?? DefaultOverridesFile; } set { overridesFile = value; } }
|
||||
public List<string> OverridesFiles { get; private set; }
|
||||
public string LanguageTypeMapFile { get { return languageTypeMapFile ?? DefaultLanguageTypeMapFile; } set { languageTypeMapFile = value; } }
|
||||
public string KeywordEscapeCharacter { get { return keywordEscapeCharacter ?? DefaultKeywordEscapeCharacter; } set { keywordEscapeCharacter = value; } }
|
||||
public string ImportsFile { get { return importsFile ?? DefaultImportsFile; } set { importsFile = value; } }
|
||||
|
|
Loading…
Reference in a new issue