Now prints the OpenTK license and adds the [AutoGenerated] attribute to the generated bindings.

This commit is contained in:
the_fiddler 2009-02-28 19:29:34 +00:00
parent 08bf5e52ad
commit 3656003844
7 changed files with 310 additions and 56 deletions

View file

@ -11,6 +11,7 @@ using System.IO;
using Bind.Structures;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Bind.Properties;
namespace Bind.GL2
{
@ -24,11 +25,11 @@ namespace Bind.GL2
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 delegatesFile = "GLDelegates.cs";
protected static string enumsFile = "GLEnums.cs";
protected static string wrappersFile = "GL.cs";
protected static string loadAllFuncName = "LoadAll";
@ -72,11 +73,11 @@ namespace Bind.GL2
// Process enums and delegates - create wrappers.
Trace.WriteLine("Processing specs, please wait...");
//this.Translate();
this.WriteBindings(
Bind.Structures.Delegate.Delegates,
Bind.Structures.Function.Wrappers,
Bind.Structures.Enum.GLEnums);
Bind.Structures.Delegate.Delegates,
Bind.Structures.Function.Wrappers,
Bind.Structures.Enum.GLEnums);
}
#endregion
@ -146,14 +147,14 @@ namespace Bind.GL2
p.CurrentType = words[2];
p.Pointer = words[4].Contains("array") ? true : words[4].Contains("reference") ? true : false;
p.Flow = words[3] == "in" ? Parameter.FlowDirection.In : Parameter.FlowDirection.Out;
d.Parameters.Add(p);
break;
// Version directive is not used. GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
//case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
// d.UserData.Add("version", words[1]);
// break;
// GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
d.Version = words[1];
break;
case "category":
d.Category = words[1];
@ -453,7 +454,7 @@ namespace Bind.GL2
#region ISpecWriter Members
#region void WriteBindings
public void WriteBindings(DelegateCollection delegates, FunctionCollection functions, EnumCollection enums)
{
if (!Directory.Exists(Settings.OutputPath))
@ -461,6 +462,7 @@ namespace Bind.GL2
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, enumsFile)))
{
WriteLicense(sw, Resources.License);
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
{
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
@ -472,7 +474,7 @@ namespace Bind.GL2
sw.WriteLine("namespace {0}", Settings.EnumsOutput);
sw.WriteLine("{");
sw.Indent();
WriteEnums(sw, Bind.Structures.Enum.GLEnums);
sw.Unindent();
@ -487,6 +489,7 @@ namespace Bind.GL2
}
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, delegatesFile)))
{
WriteLicense(sw, Resources.License);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
@ -502,13 +505,14 @@ namespace Bind.GL2
}
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, importsFile)))
{
WriteLicense(sw, Resources.License);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
//specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;");
WriteImports(sw, Bind.Structures.Delegate.Delegates);
sw.Unindent();
@ -516,6 +520,7 @@ namespace Bind.GL2
}
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, wrappersFile)))
{
WriteLicense(sw, Resources.License);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
@ -529,11 +534,11 @@ namespace Bind.GL2
sw.WriteLine("}");
}
}
#endregion
#region void WriteDelegates
public virtual void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
{
Trace.WriteLine(String.Format("Writing delegates to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.DelegatesClass));
@ -549,7 +554,7 @@ namespace Bind.GL2
sw.WriteLine("internal static partial class {0}", Settings.DelegatesClass);
sw.WriteLine("{");
sw.Indent();
foreach (Bind.Structures.Delegate d in delegates.Values)
{
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
@ -559,7 +564,7 @@ namespace Bind.GL2
d.Name,
Settings.FunctionPrefix);
}
sw.Unindent();
sw.WriteLine("}");
@ -590,25 +595,25 @@ namespace Bind.GL2
sw.WriteLine();
foreach (Bind.Structures.Delegate d in delegates.Values)
{
if (String.IsNullOrEmpty(d.Extension) || d.Extension == "Core")
{
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
sw.WriteLine(
"[System.Runtime.InteropServices.DllImport({0}.Library, EntryPoint = \"{1}{2}\"{3})]",
if (String.IsNullOrEmpty(d.Extension) || d.Extension == "Core")
{
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
sw.WriteLine(
"[System.Runtime.InteropServices.DllImport({0}.Library, EntryPoint = \"{1}{2}\"{3})]",
Settings.OutputClass,
Settings.FunctionPrefix,
d.Name,
d.Name,
d.Name.EndsWith("W") || d.Name.EndsWith("A") ? ", CharSet = CharSet.Auto" : ", ExactSpelling = true"
);
sw.WriteLine("internal extern static {0};", d.DeclarationString());
}
);
sw.WriteLine("internal extern static {0};", d.DeclarationString());
}
}
sw.Unindent();
sw.WriteLine("}");
sw.Unindent();
sw.WriteLine("}");
}
#endregion
#region void WriteWrappers
@ -631,13 +636,13 @@ namespace Bind.GL2
{
if (((Settings.Compatibility & Settings.Legacy.NoSeparateFunctionNamespaces) == Settings.Legacy.None) && key != "Core")
{
if (!Char.IsDigit(key[0]))
{
sw.WriteLine("public static partial class {0}", key);
}
if (!Char.IsDigit(key[0]))
{
sw.WriteLine("public static partial class {0}", key);
}
else
{
// Identifiers cannot start with a number:
// Identifiers cannot start with a number:
sw.WriteLine("public static partial class {0}{1}", Settings.ConstantPrefix, key);
}
sw.WriteLine("{");
@ -650,6 +655,8 @@ namespace Bind.GL2
{
sw.WriteLine("[System.CLSCompliant(false)]");
}
sw.WriteLine("[AutoGenerated(Category = \"{0}\", Version = \"{1}\", EntryPoint = \"{2}\")]",
f.Category, f.Version, "gl" + f.WrappedDelegate.Name);
sw.WriteLine("public static ");
sw.Write(f);
sw.WriteLine();
@ -682,7 +689,7 @@ namespace Bind.GL2
#endregion
#region void WriteEnums
#region void WriteEnums
public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
{
@ -741,6 +748,16 @@ namespace Bind.GL2
#endregion
#region void WriteLicense
public void WriteLicense(BindStreamWriter sw, string license)
{
sw.WriteLine(Resources.License);
sw.WriteLine();
}
#endregion
#endregion
}
}

View file

@ -20,5 +20,6 @@ namespace Bind
void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
void WriteEnums(BindStreamWriter sw, EnumCollection enums);
void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
void WriteLicense(BindStreamWriter sw, string license);
}
}

View file

@ -0,0 +1,82 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3074
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Bind.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bind.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to #region License
/////
///// The Open Toolkit Library License
/////
///// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
/////
///// Permission is hereby granted, free of charge, to any person obtaining a copy
///// of this software and associated documentation files (the &quot;Software&quot;), to deal
///// in the Software without restriction, including without limitation the rights to
///// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
///// the Software, and to permit person [rest of string was truncated]&quot;;.
/// </summary>
internal static string License {
get {
return ResourceManager.GetString("License", resourceCulture);
}
}
}
}

View file

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="License" xml:space="preserve">
<value>#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion</value>
</data>
</root>

View file

@ -104,7 +104,7 @@ namespace Bind.Structures
public string Category
{
get { return _category; }
set { _category = value; }
set { _category = Enum.TranslateName(value); }
}
#endregion
@ -345,10 +345,6 @@ namespace Bind.Structures
public void CreateWrappers()
{
if (this.Name.Contains("ReadPixels"))
{
}
List<Function> wrappers = new List<Function>();
if (!NeedsWrapper)
{
@ -509,9 +505,6 @@ namespace Bind.Structures
internal void Translate()
{
if (Name.Contains("GetError"))
{
}
TranslateReturnType();
TranslateParameters();

View file

@ -113,7 +113,7 @@ namespace Bind.Structures
foreach (char c in name)
{
char char_to_add;
if (c == '_')
if (c == '_' || c == '-')
is_after_underscore_or_number = true;
else
{

View file

@ -14,9 +14,11 @@ namespace Bind.Structures
{
public class Function : Delegate, IEquatable<Function>
{
#region Static Members
internal static FunctionCollection Wrappers;
private static bool loaded;
static bool loaded;
#region internal static void Initialize()
@ -34,6 +36,14 @@ namespace Bind.Structures
static Regex endings = new Regex(@"((([df]|u?[isb])v?)|v)", RegexOptions.Compiled | RegexOptions.RightToLeft);
static Regex endingsNotToTrim = new Regex("(ib|[tdrey]s|[eE]n[vd]|bled|Flagv|Tess|Status|Pixels)", RegexOptions.Compiled | RegexOptions.RightToLeft);
#endregion
#region Fields
Delegate wrapped_delegate;
#endregion
/// <summary>
/// Add a trailing v to functions matching this regex. Used to differntiate between overloads taking both
/// a 'type' and a 'ref type' (such overloads are not CLS Compliant).
@ -45,12 +55,6 @@ namespace Bind.Structures
#region --- Constructors ---
public Function()
: base()
{
Body = new FunctionBody();
}
public Function(Delegate d)
: base(d)
{
@ -59,10 +63,20 @@ namespace Bind.Structures
else
this.Body = new FunctionBody();
this.Name = d.Name;
WrappedDelegate = d;
}
#endregion
public Delegate WrappedDelegate
{
get { return wrapped_delegate; }
set { wrapped_delegate = value; }
}
#region public void TurnVoidPointersToIntPtr()
public void TurnVoidPointersToIntPtr()
{
foreach (Parameter p in this.Parameters)
@ -75,6 +89,8 @@ namespace Bind.Structures
}
}
#endregion
#region public override bool Unsafe
public override bool Unsafe
@ -134,9 +150,6 @@ namespace Bind.Structures
{
TrimmedName = Utilities.StripGL2Extension(value);
//if (Name.Contains("BooleanIndexed"))
{
}
Match m = endingsNotToTrim.Match(TrimmedName);
if ((m.Index + m.Length) != TrimmedName.Length)
{