* 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.
This commit is contained in:
the_fiddler 2010-12-06 12:29:18 +00:00
parent 029957c03a
commit 5b40433350
4 changed files with 36 additions and 23 deletions

View file

@ -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;
}

View file

@ -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);
}

View file

@ -70,20 +70,27 @@ 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));
}
Enums = new EnumProcessor(overrides).Process(Enums);
Wrappers = new FuncProcessor(overrides).Process(Delegates, Enums);
}
}
#endregion
}

View file

@ -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<string, string> 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;
}