diff --git a/Source/Bind/EnumProcessor.cs b/Source/Bind/EnumProcessor.cs index 9c677fab..829c9e96 100644 --- a/Source/Bind/EnumProcessor.cs +++ b/Source/Bind/EnumProcessor.cs @@ -40,9 +40,9 @@ namespace Bind class EnumProcessor { const string Path = "/signatures/replace/enum[@name='{0}']"; - StreamReader Overrides { get; set; } + string Overrides { get; set; } - public EnumProcessor(StreamReader overrides) + public EnumProcessor(string overrides) { if (overrides == null) throw new ArgumentNullException("overrides"); @@ -55,7 +55,6 @@ namespace Bind 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 6f6d9c00..90ce5488 100644 --- a/Source/Bind/FuncProcessor.cs +++ b/Source/Bind/FuncProcessor.cs @@ -46,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); - StreamReader Overrides { get; set; } + string Overrides { get; set; } - public FuncProcessor(StreamReader overrides) + public FuncProcessor(string overrides) { if (overrides == null) throw new ArgumentNullException("overrides"); @@ -72,7 +72,6 @@ namespace Bind 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 89dbbb38..950baee7 100644 --- a/Source/Bind/GL2/Generator.cs +++ b/Source/Bind/GL2/Generator.cs @@ -70,26 +70,16 @@ namespace Bind.GL2 public virtual void Process() { - 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)); - } + string overrides = Path.Combine(Settings.InputPath, Settings.OverridesFile); + Type.GLTypes = SpecReader.ReadTypeMap(Path.Combine(Settings.InputPath, glTypemap)); + Type.CSTypes = SpecReader.ReadCSTypeMap(Path.Combine(Settings.InputPath, csTypemap)); + Enums = SpecReader.ReadEnums(Path.Combine(Settings.InputPath, enumSpec)); + Utilities.Merge(Enums, SpecReader.ReadEnums(overrides)); + Delegates = SpecReader.ReadDelegates(Path.Combine(Settings.InputPath, glSpec)); + Utilities.Merge(Delegates, SpecReader.ReadDelegates(overrides)); - 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/ISpecReader.cs b/Source/Bind/ISpecReader.cs index 3c9f428e..e996ef5e 100644 --- a/Source/Bind/ISpecReader.cs +++ b/Source/Bind/ISpecReader.cs @@ -12,9 +12,9 @@ namespace Bind { interface ISpecReader { - DelegateCollection ReadDelegates(StreamReader specFile); - EnumCollection ReadEnums(StreamReader specFile); - Dictionary ReadTypeMap(StreamReader specFile); - Dictionary ReadCSTypeMap(StreamReader specFile); + DelegateCollection ReadDelegates(string file); + EnumCollection ReadEnums(string file); + Dictionary ReadTypeMap(string file); + Dictionary ReadCSTypeMap(string file); } } diff --git a/Source/Bind/XmlSpecReader.cs b/Source/Bind/XmlSpecReader.cs index 8ca864e5..e9c7f741 100644 --- a/Source/Bind/XmlSpecReader.cs +++ b/Source/Bind/XmlSpecReader.cs @@ -102,115 +102,118 @@ namespace Bind #region ISpecReader Members - public DelegateCollection ReadDelegates(StreamReader specFile) + public DelegateCollection ReadDelegates(string file) { - XPathDocument specs = new XPathDocument(specFile); + var specs = new XPathDocument(file); var delegates = ReadDelegates(specs.CreateNavigator().SelectSingleNode("/signatures/add")); - specFile.BaseStream.Seek(0, SeekOrigin.Begin); return delegates; } - public Dictionary ReadTypeMap(StreamReader specFile) + public Dictionary ReadTypeMap(string file) { - Console.WriteLine("Reading opengl types."); - Dictionary GLTypes = new Dictionary(); + using (var sr = new StreamReader(file)) + { + Console.WriteLine("Reading opengl types."); + Dictionary GLTypes = new Dictionary(); + + if (sr == null) + return GLTypes; + + do + { + string line = sr.ReadLine(); + + if (String.IsNullOrEmpty(line) || line.StartsWith("#")) + continue; + + string[] words = line.Split(" ,*\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + + if (words[0].ToLower() == "void") + { + // Special case for "void" -> "". We make it "void" -> "void" + GLTypes.Add(words[0], "void"); + } + else if (words[0] == "VoidPointer" || words[0] == "ConstVoidPointer") + { + // "(Const)VoidPointer" -> "void*" + GLTypes.Add(words[0], "void*"); + } + else if (words[0] == "CharPointer" || words[0] == "charPointerARB") + { + // The typematching logic cannot handle pointers to pointers, e.g. CharPointer* -> char** -> string* -> string[]. + // Hence we give it a push. + // Note: When both CurrentType == "String" and Pointer == true, the typematching is hardcoded to use + // String[] or StringBuilder[]. + GLTypes.Add(words[0], "String"); + } + /*else if (words[0].Contains("Pointer")) + { + GLTypes.Add(words[0], words[1].Replace("Pointer", "*")); + }*/ + else if (words[1].Contains("GLvoid")) + { + GLTypes.Add(words[0], "void"); + } + else if (words[1] == "const" && words[2] == "GLubyte") + { + GLTypes.Add(words[0], "String"); + } + else if (words[1] == "struct") + { + GLTypes.Add(words[0], words[2]); + } + else + { + GLTypes.Add(words[0], words[1]); + } + } + while (!sr.EndOfStream); - if (specFile == null) return GLTypes; - - do - { - string line = specFile.ReadLine(); - - if (String.IsNullOrEmpty(line) || line.StartsWith("#")) - continue; - - string[] words = line.Split(" ,*\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - - if (words[0].ToLower() == "void") - { - // Special case for "void" -> "". We make it "void" -> "void" - GLTypes.Add(words[0], "void"); - } - else if (words[0] == "VoidPointer" || words[0] == "ConstVoidPointer") - { - // "(Const)VoidPointer" -> "void*" - GLTypes.Add(words[0], "void*"); - } - else if (words[0] == "CharPointer" || words[0] == "charPointerARB") - { - // The typematching logic cannot handle pointers to pointers, e.g. CharPointer* -> char** -> string* -> string[]. - // Hence we give it a push. - // Note: When both CurrentType == "String" and Pointer == true, the typematching is hardcoded to use - // String[] or StringBuilder[]. - GLTypes.Add(words[0], "String"); - } - /*else if (words[0].Contains("Pointer")) - { - GLTypes.Add(words[0], words[1].Replace("Pointer", "*")); - }*/ - else if (words[1].Contains("GLvoid")) - { - GLTypes.Add(words[0], "void"); - } - else if (words[1] == "const" && words[2] == "GLubyte") - { - GLTypes.Add(words[0], "String"); - } - else if (words[1] == "struct") - { - GLTypes.Add(words[0], words[2]); - } - else - { - GLTypes.Add(words[0], words[1]); - } } - while (!specFile.EndOfStream); - - return GLTypes; } - public Dictionary ReadCSTypeMap(StreamReader specFile) + public Dictionary ReadCSTypeMap(string file) { - Dictionary CSTypes = new Dictionary(); - Console.WriteLine("Reading C# types."); - - while (!specFile.EndOfStream) + using (var sr = new StreamReader(file)) { - string line = specFile.ReadLine(); - if (String.IsNullOrEmpty(line) || line.StartsWith("#")) - continue; + Dictionary CSTypes = new Dictionary(); + Console.WriteLine("Reading C# types."); - string[] words = line.Split(" ,\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - if (words.Length < 2) - continue; + while (!sr.EndOfStream) + { + string line = sr.ReadLine(); + if (String.IsNullOrEmpty(line) || line.StartsWith("#")) + continue; - if (((Settings.Compatibility & Settings.Legacy.NoBoolParameters) != Settings.Legacy.None) && words[1] == "bool") - words[1] = "Int32"; + string[] words = line.Split(" ,\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (words.Length < 2) + continue; - CSTypes.Add(words[0], words[1]); + if (((Settings.Compatibility & Settings.Legacy.NoBoolParameters) != Settings.Legacy.None) && words[1] == "bool") + words[1] = "Int32"; + + CSTypes.Add(words[0], words[1]); + } + + return CSTypes; } - - return CSTypes; } - public EnumCollection ReadEnums(StreamReader specFile) + public EnumCollection ReadEnums(string file) { // First, read all enum definitions from spec and override file. // Afterwards, read all token/enum overrides from overrides file. // Every single enum is merged into EnumCollection enums = new EnumCollection(); - XPathDocument specs = new XPathDocument(specFile); - + var specs = new XPathDocument(file); foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/add")) { var new_enums = ReadEnums(nav); Utilities.Merge(enums, new_enums); } - specFile.BaseStream.Seek(0, SeekOrigin.Begin); return enums; }