Opentk/Source/Bind/GL2/Generator.cs
2010-12-02 21:36:05 +00:00

96 lines
3 KiB
C#

#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.XPath;
using Bind.Structures;
using Delegate=Bind.Structures.Delegate;
using Enum=Bind.Structures.Enum;
using Type=Bind.Structures.Type;
namespace Bind.GL2
{
class Generator : IBind
{
#region Fields
protected static string glTypemap = "GL2/gl.tm";
protected static string csTypemap = "csharp.tm";
protected static string enumSpec = "GL2/enum.spec";
protected static string enumSpecExt = "GL2/enumext.spec";
protected static string glSpec = "GL2/gl.spec";
protected static string glSpecExt = "";
protected static string importsFile = "GLCore.cs";
protected static string delegatesFile = "GLDelegates.cs";
protected static string enumsFile = "GLEnums.cs";
protected static string wrappersFile = "GL.cs";
protected static string functionOverridesFile = "GL2/gloverrides.xml";
protected static string loadAllFuncName = "LoadAll";
protected static Regex enumToDotNet = new Regex("_[a-z|A-Z]?", RegexOptions.Compiled);
protected static readonly char[] numbers = "0123456789".ToCharArray();
//protected static readonly Dictionary<string, string> doc_replacements;
protected ISpecReader SpecReader = new XmlSpecReader(functionOverridesFile);
protected ISpecWriter SpecWriter = new CSharpSpecWriter(wrappersFile, importsFile,
enumsFile, delegatesFile);
#endregion
#region Constructors
public Generator()
{
if (Settings.Compatibility == Settings.Legacy.Tao)
{
Settings.OutputNamespace = "Tao.OpenGl";
Settings.OutputClass = "Gl";
}
else
{
// Defaults
}
}
#endregion
#region Process
public virtual void Process()
{
var overrides = new XPathDocument(Path.Combine(Settings.InputPath, functionOverridesFile));
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);
}
var enums = SpecReader.ReadEnums(new StreamReader(Path.Combine(Settings.InputPath, enumSpec)));
var delegates = SpecReader.ReadDelegates(new StreamReader(Path.Combine(Settings.InputPath, glSpec)));
enums = new EnumProcessor(overrides).Process(enums);
var wrappers = new FuncProcessor(overrides).Process(delegates, enums);
SpecWriter.WriteBindings(delegates, wrappers, enums);
}
#endregion
}
}