From 5b40433350839705183cc5e5856e3b04fb24cb97 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 6 Dec 2010 12:29:18 +0000 Subject: [PATCH] * XmlSpecReader.cs: * EnumProcessor.cs: * GL2/Generator.cs: * FuncProcessor.cs: Fixed handling of overrides file: we now add signatures as requested and reset the stream after we are done reading the file. --- Source/Bind/EnumProcessor.cs | 12 +++++++----- Source/Bind/FuncProcessor.cs | 9 ++++++--- Source/Bind/GL2/Generator.cs | 31 +++++++++++++++++++------------ Source/Bind/XmlSpecReader.cs | 7 ++++--- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Source/Bind/EnumProcessor.cs b/Source/Bind/EnumProcessor.cs index 14129b92..9c677fab 100644 --- a/Source/Bind/EnumProcessor.cs +++ b/Source/Bind/EnumProcessor.cs @@ -26,22 +26,23 @@ #endregion using System; -using System.Linq; using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; using System.Text; using System.Xml.XPath; using Bind.Structures; using Enum = Bind.Structures.Enum; -using System.Globalization; namespace Bind { class EnumProcessor { const string Path = "/signatures/replace/enum[@name='{0}']"; - XPathDocument Overrides { get; set; } + StreamReader Overrides { get; set; } - public EnumProcessor(XPathDocument overrides) + public EnumProcessor(StreamReader overrides) { if (overrides == null) throw new ArgumentNullException("overrides"); @@ -51,9 +52,10 @@ namespace Bind public EnumCollection Process(EnumCollection enums) { - var nav = Overrides.CreateNavigator(); + var nav = new XPathDocument(Overrides).CreateNavigator(); enums = ProcessNames(enums, nav); enums = ProcessConstants(enums, nav); + Overrides.BaseStream.Seek(0, SeekOrigin.Begin); return enums; } diff --git a/Source/Bind/FuncProcessor.cs b/Source/Bind/FuncProcessor.cs index 011810a4..6f6d9c00 100644 --- a/Source/Bind/FuncProcessor.cs +++ b/Source/Bind/FuncProcessor.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Xml.XPath; @@ -45,9 +46,9 @@ namespace Bind new Regex("(ib|[tdrey]s|[eE]n[vd]|bled|Flag|Tess|Status|Pixels|Instanced|Indexed|Varyings|Boolean|IDs)", RegexOptions.Compiled | RegexOptions.RightToLeft); static readonly Regex EndingsAddV = new Regex("^0", RegexOptions.Compiled); - XPathDocument Overrides { get; set; } + StreamReader Overrides { get; set; } - public FuncProcessor(XPathDocument overrides) + public FuncProcessor(StreamReader overrides) { if (overrides == null) throw new ArgumentNullException("overrides"); @@ -58,7 +59,7 @@ namespace Bind public FunctionCollection Process(DelegateCollection delegates, EnumCollection enums) { Console.WriteLine("Processing delegates."); - var nav = Overrides.CreateNavigator(); + var nav = new XPathDocument(Overrides).CreateNavigator(); foreach (var d in delegates.Values) { TranslateReturnType(nav, d, enums); @@ -70,6 +71,8 @@ namespace Bind Console.WriteLine("Creating CLS compliant overloads."); wrappers = CreateCLSCompliantWrappers(wrappers, enums); Console.WriteLine("Removing non-CLS compliant duplicates."); + + Overrides.BaseStream.Seek(0, SeekOrigin.Begin); return MarkCLSCompliance(wrappers); } diff --git a/Source/Bind/GL2/Generator.cs b/Source/Bind/GL2/Generator.cs index 363f3f2d..89dbbb38 100644 --- a/Source/Bind/GL2/Generator.cs +++ b/Source/Bind/GL2/Generator.cs @@ -70,19 +70,26 @@ namespace Bind.GL2 public virtual void Process() { - var overrides = new XPathDocument(Path.Combine(Settings.InputPath, Settings.OverridesFile)); + using (var overrides = new StreamReader(Path.Combine(Settings.InputPath, Settings.OverridesFile))) + { + using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, glTypemap)) + Type.GLTypes = SpecReader.ReadTypeMap(sr); + using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, csTypemap)) + Type.CSTypes = SpecReader.ReadCSTypeMap(sr); + using (var sr = new StreamReader(Path.Combine(Settings.InputPath, enumSpec))) + { + Enums = SpecReader.ReadEnums(sr); + Utilities.Merge(Enums, SpecReader.ReadEnums(overrides)); + } + using (var sr = new StreamReader(Path.Combine(Settings.InputPath, glSpec))) + { + Delegates = SpecReader.ReadDelegates(sr); + Utilities.Merge(Delegates, SpecReader.ReadDelegates(overrides)); + } - using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, glTypemap)) - Type.GLTypes = SpecReader.ReadTypeMap(sr); - using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, csTypemap)) - Type.CSTypes = SpecReader.ReadCSTypeMap(sr); - using (var sr = new StreamReader(Path.Combine(Settings.InputPath, enumSpec))) - Enums = SpecReader.ReadEnums(sr); - using (var sr = new StreamReader(Path.Combine(Settings.InputPath, glSpec))) - Delegates = SpecReader.ReadDelegates(sr); - - Enums = new EnumProcessor(overrides).Process(Enums); - Wrappers = new FuncProcessor(overrides).Process(Delegates, Enums); + Enums = new EnumProcessor(overrides).Process(Enums); + Wrappers = new FuncProcessor(overrides).Process(Delegates, Enums); + } } #endregion diff --git a/Source/Bind/XmlSpecReader.cs b/Source/Bind/XmlSpecReader.cs index 76d81189..8ca864e5 100644 --- a/Source/Bind/XmlSpecReader.cs +++ b/Source/Bind/XmlSpecReader.cs @@ -105,7 +105,9 @@ namespace Bind public DelegateCollection ReadDelegates(StreamReader specFile) { XPathDocument specs = new XPathDocument(specFile); - return ReadDelegates(specs.CreateNavigator().SelectSingleNode("/signatures/add")); + var delegates = ReadDelegates(specs.CreateNavigator().SelectSingleNode("/signatures/add")); + specFile.BaseStream.Seek(0, SeekOrigin.Begin); + return delegates; } public Dictionary ReadTypeMap(StreamReader specFile) @@ -201,8 +203,6 @@ namespace Bind EnumCollection enums = new EnumCollection(); XPathDocument specs = new XPathDocument(specFile); - XPathDocument overrides = new XPathDocument(new StreamReader( - Path.Combine(Settings.InputPath, Settings.OverridesFile))); foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/add")) { @@ -210,6 +210,7 @@ namespace Bind Utilities.Merge(enums, new_enums); } + specFile.BaseStream.Seek(0, SeekOrigin.Begin); return enums; }