* GL2/Generator.cs: Refactored WriteWrappers() into smaller methods. Added "using System.Text;" to all generated files that may contain StringBuilder parameters.

* Main.cs: Removed unused comments. Improved parameter handling. Added -o:keep_untyped_parameters option.
* Settings.cs: Added KeepUntypedEnums compatibility setting.
* Structures/Delegate.cs: Removed stale comments. Refactored CreateWrappers() method to support untyped enum overload generation and simplified method implementation. Replaced CurrentType translations with QualifiedType.
* Structures/Function.cs: Removed stale code. Fixed copy constructors to copy all necessary fields. Use QualifiedType instead of CurrentType in WrapReturnType and CreateBody methods. Made Body statement lists static to improve performance. Added hack to modify callstring casts in keep_untyped_enums wrappers. Generate call string from the Function CreateBody was called on, rather than the current Function (solves issues with invalid casts in specific cases).
* Structures/Parameter.cs: Use fully qualified type instead of current type in several caeses.
* Structures/Type.cs: Added explicit support for fully qualified types.
This commit is contained in:
the_fiddler 2009-10-27 22:37:05 +00:00
parent 584e6c48a6
commit 97e07a6e24
7 changed files with 243 additions and 106 deletions

View file

@ -8,6 +8,7 @@ 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;
@ -349,8 +350,8 @@ namespace Bind.GL2
// 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
// System.String[] or System.StringBuilder[].
GLTypes.Add(words[0], "System.String");
// String[] or StringBuilder[].
GLTypes.Add(words[0], "String");
}
/*else if (words[0].Contains("Pointer"))
{
@ -501,6 +502,7 @@ namespace Bind.GL2
sw.Indent();
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("#pragma warning disable 0649");
@ -519,6 +521,7 @@ namespace Bind.GL2
sw.Indent();
//specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
WriteImports(sw, Delegate.Delegates);
@ -536,6 +539,7 @@ namespace Bind.GL2
sw.Indent();
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
WriteWrappers(sw, Function.Wrappers, Type.CSTypes);
@ -678,38 +682,7 @@ namespace Bind.GL2
wrappers[key].Sort();
foreach (Function f in wrappers[key])
{
if ((Settings.Compatibility & Settings.Legacy.NoDocumentation) == 0)
{
Console.WriteLine("Creating docs for #{0} ({1})", current++, f.Name);
try
{
string path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix + f.WrappedDelegate.Name + ".xml");
if (!File.Exists(path))
path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix +
f.TrimmedName + ".xml");
if (!File.Exists(path))
path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml");
if (File.Exists(path))
{
DocProcessor doc_processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
sw.WriteLine(doc_processor.ProcessFile(path));
}
}
catch (FileNotFoundException)
{ }
}
if (!f.CLSCompliant)
{
sw.WriteLine("[System.CLSCompliant(false)]");
}
sw.WriteLine("[AutoGenerated(Category = \"{0}\", Version = \"{1}\", EntryPoint = \"{2}\")]",
f.Category, f.Version, Settings.FunctionPrefix + f.WrappedDelegate.Name);
sw.WriteLine("public static ");
sw.Write(f);
sw.WriteLine();
current = WriteWrapper(sw, current, f);
}
if (((Settings.Compatibility & Settings.Legacy.NoSeparateFunctionNamespaces) == Settings.Legacy.None) && key != "Core")
@ -723,13 +696,58 @@ namespace Bind.GL2
sw.WriteLine("}");
}
private static int WriteWrapper(BindStreamWriter sw, int current, Function f)
{
if ((Settings.Compatibility & Settings.Legacy.NoDocumentation) == 0)
{
Console.WriteLine("Creating docs for #{0} ({1})", current++, f.Name);
WriteDocumentation(sw, f);
}
WriteMethod(sw, f);
return current;
}
private static void WriteMethod(BindStreamWriter sw, Function f)
{
if (!f.CLSCompliant)
{
sw.WriteLine("[System.CLSCompliant(false)]");
}
sw.WriteLine("[AutoGenerated(Category = \"{0}\", Version = \"{1}\", EntryPoint = \"{2}\")]",
f.Category, f.Version, Settings.FunctionPrefix + f.WrappedDelegate.Name);
sw.WriteLine("public static ");
sw.Write(f);
sw.WriteLine();
}
private static void WriteDocumentation(BindStreamWriter sw, Function f)
{
try
{
string path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix + f.WrappedDelegate.Name + ".xml");
if (!File.Exists(path))
path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix +
f.TrimmedName + ".xml");
if (!File.Exists(path))
path = Path.Combine(Settings.DocPath, Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml");
if (File.Exists(path))
{
DocProcessor doc_processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
sw.WriteLine(doc_processor.ProcessFile(path));
}
}
catch (FileNotFoundException)
{ }
}
#endregion
#region void WriteTypes
public void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes)
{
sw.WriteLine("using System;");
sw.WriteLine();
foreach (string s in CSTypes.Keys)
{

View file

@ -48,7 +48,6 @@ namespace Bind
Console.WriteLine("OpenGL binding generator {0} for OpenTK.",
Assembly.GetExecutingAssembly().GetName().Version.ToString());
Console.WriteLine("For comments, bugs and suggestions visit http://opentk.sourceforge.net");
//Console.WriteLine(" - the OpenTK team ;-)");
Console.WriteLine();
string dirName = null;
@ -104,13 +103,14 @@ namespace Bind
case "legacy":
case "o":
case "option":
Settings.Compatibility |= b[1].ToLower().Contains("tao") ? Settings.Legacy.Tao : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("enums") ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("safe") ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "tao" ? Settings.Legacy.Tao : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "simple_enums" ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "safe" ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None;
//Settings.Compatibility |= b[1].ToLower().Contains("novoid") ? Settings.Legacy.TurnVoidPointersToIntPtr : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("permutations") ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("enums_in_class") ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("nodocs") ? Settings.Legacy.NoDocumentation : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "permutations" ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "enums_in_class" ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "nodocs" ? Settings.Legacy.NoDocumentation : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "keep_untyped_enums" ? Settings.Legacy.KeepUntypedEnums : Settings.Legacy.None;
break;
default:
throw new ArgumentException(

View file

@ -125,6 +125,8 @@ namespace Bind
NoDocumentation = 0x400,
/// <summary>Disables ErrorHelper generation.</summary>
NoDebugHelpers = 0x800,
/// <summary>Generate both typed and untyped ("All") signatures for enum parameters.</summary>
KeepUntypedEnums = 0x1000,
Tao = ConstIntEnums |
NoAdvancedEnumProcessing |
NoPublicUnsafeFunctions |

View file

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.XPath;
@ -132,15 +133,12 @@ namespace Bind.Structures
#region public bool NeedsWrapper
/// <summary>
/// Indicates whether this function needs to be wrapped with a Marshaling function.
/// Gets a value that indicates whether this function needs to be wrapped with a Marshaling function.
/// This flag is set if a function contains an Array parameter, or returns
/// an Array or string.
/// </summary>
public bool NeedsWrapper
{
//get { return _needs_wrapper; }
//set { _needs_wrapper = value; }
get
{
// TODO: Add special cases for (Get)ShaderSource.
@ -235,7 +233,7 @@ namespace Bind.Structures
public ParameterCollection Parameters
{
get { return _parameters; }
protected set { _parameters = value; }
set { _parameters = value; }
}
#endregion
@ -415,21 +413,20 @@ namespace Bind.Structures
void CreateWrappers()
{
List<Function> wrappers = new List<Function>();
if (!NeedsWrapper)
{
// No special wrapper needed - just call this delegate:
Function f = new Function(this);
f.CreateBody(false);
CreateNormalWrappers(wrappers);
wrappers.Add(f);
}
else
// Generate wrappers using the untyped enum parameters, if necessary.
if ((Settings.Compatibility & Settings.Legacy.KeepUntypedEnums) != 0)
{
Function f = new Function(this);
f.WrapReturnType();
f.WrapParameters(wrappers);
CreateUntypedEnumWrappers(wrappers);
}
// Add CLS-compliant overloads for non-CLS compliant wrappers.
CreateCLSCompliantWrappers(wrappers);
}
private static void CreateCLSCompliantWrappers(List<Function> wrappers)
{
// If the function is not CLS-compliant (e.g. it contains unsigned parameters)
// we need to create a CLS-Compliant overload. However, we should only do this
// iff the opengl function does not contain unsigned/signed overloads itself
@ -445,20 +442,47 @@ namespace Bind.Structures
cls.Body.Clear();
cls.CreateBody(true);
bool somethingChanged = false;
bool modified = false;
for (int i = 0; i < f.Parameters.Count; i++)
{
cls.Parameters[i].CurrentType = cls.Parameters[i].GetCLSCompliantType();
if (cls.Parameters[i].CurrentType != f.Parameters[i].CurrentType)
somethingChanged = true;
modified = true;
}
if (somethingChanged)
if (modified)
Function.Wrappers.AddChecked(cls);
}
}
}
private void CreateUntypedEnumWrappers(List<Function> wrappers)
{
Function f = new Function(this);
var modified = false;
f.Parameters = new ParameterCollection(f.Parameters.Select(p =>
{
if (p.IsEnum && p.CurrentType != Settings.CompleteEnumName)
{
p.CurrentType = Settings.CompleteEnumName;
modified = true;
}
return p;
}));
if (modified)
{
f.WrapReturnType();
f.WrapParameters(wrappers);
}
}
void CreateNormalWrappers(List<Function> wrappers)
{
Function f = new Function(this);
f.WrapReturnType();
f.WrapParameters(wrappers);
}
#endregion
#region TrimName
@ -529,28 +553,28 @@ namespace Bind.Structures
if (ReturnType.CurrentType.ToLower().Contains("void") && ReturnType.Pointer != 0)
{
ReturnType.CurrentType = "IntPtr";
ReturnType.QualifiedType = "System.IntPtr";
ReturnType.WrapperType = WrapperTypes.GenericReturnType;
}
if (ReturnType.CurrentType.ToLower().Contains("string"))
{
ReturnType.CurrentType = "IntPtr";
ReturnType.QualifiedType = "System.IntPtr";
ReturnType.WrapperType = WrapperTypes.StringReturnType;
}
if (ReturnType.CurrentType.ToLower().Contains("object"))
{
ReturnType.CurrentType = "IntPtr";
ReturnType.QualifiedType = "System.IntPtr";
ReturnType.WrapperType |= WrapperTypes.GenericReturnType;
}
if (ReturnType.CurrentType.Contains("GLenum"))
{
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None)
ReturnType.CurrentType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
ReturnType.QualifiedType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
else
ReturnType.CurrentType = "int";
ReturnType.QualifiedType = "int";
}
ReturnType.CurrentType = ReturnType.GetCLSCompliantType();

View file

@ -52,9 +52,11 @@ namespace Bind.Structures
}
public Function(Function f)
: this((Delegate)f)
: this(f.WrappedDelegate)
{
Body = new FunctionBody(f.Body);
Parameters = new ParameterCollection(f.Parameters);
ReturnType = new Type(f.ReturnType);
Body.AddRange(f.Body);
}
#endregion
@ -297,7 +299,6 @@ namespace Bind.Structures
}
else
{
//wrappers.Add(DefaultWrapper(new Function(this)));
f = new Function(this);
f.CreateBody(false);
wrappers.Add(f);
@ -379,7 +380,7 @@ namespace Bind.Structures
switch (ReturnType.WrapperType)
{
case WrapperTypes.StringReturnType:
ReturnType.CurrentType = "string";
ReturnType.QualifiedType = "String";
break;
}
}
@ -388,10 +389,10 @@ namespace Bind.Structures
#region public void CreateBody(bool wantCLSCompliance)
readonly List<string> handle_statements = new List<string>();
readonly List<string> handle_release_statements = new List<string>();
readonly List<string> fixed_statements = new List<string>();
readonly List<string> assign_statements = new List<string>();
readonly static List<string> handle_statements = new List<string>();
readonly static List<string> handle_release_statements = new List<string>();
readonly static List<string> fixed_statements = new List<string>();
readonly static List<string> assign_statements = new List<string>();
// For example, if parameter foo has indirection level = 1, then it
// is consumed as 'foo*' in the fixed_statements and the call string.
@ -428,7 +429,7 @@ namespace Bind.Structures
{
assign_statements.Add(String.Format(
"{0} = ({1}){0}_ptr.Target;",
p.Name, p.CurrentType));
p.Name, p.QualifiedType));
}
// Note! The following line modifies f.Parameters, *not* this.Parameters
@ -441,7 +442,7 @@ namespace Bind.Structures
// A fixed statement is issued for all non-generic pointers, arrays and references.
fixed_statements.Add(String.Format(
"fixed ({0}{3} {1} = {2})",
wantCLSCompliance && !p.CLSCompliant ? p.GetCLSCompliantType() : p.CurrentType,
wantCLSCompliance && !p.CLSCompliant ? p.GetCLSCompliantType() : p.QualifiedType,
p.Name + "_ptr",
p.Array > 0 ? p.Name : "&" + p.Name,
indirection_levels[p.IndirectionLevel]));
@ -504,16 +505,36 @@ namespace Bind.Structures
f.Body.Indent();
}
// Hack: When creating untyped enum wrappers, it is possible that the wrapper uses an "All"
// enum, while the delegate uses a specific enum (e.g. "TextureUnit"). For this reason, we need
// to modify the parameters before generating the call string.
// Note: We cannot generate a callstring using WrappedDelegate directly, as its parameters will
// typically be different than the parameters of the wrapper. We need to modify the parameters
// of the wrapper directly.
if ((Settings.Compatibility & Settings.Legacy.KeepUntypedEnums) != 0)
{
int parameter_index = -1; // Used for comparing wrapper parameters with delegate parameters
foreach (Parameter p in f.Parameters)
{
parameter_index++;
if (p.IsEnum && p.QualifiedType != f.WrappedDelegate.Parameters[parameter_index].QualifiedType)
{
p.QualifiedType = f.WrappedDelegate.Parameters[parameter_index].QualifiedType;
}
}
}
if (assign_statements.Count > 0)
{
// Call function
string method_call = f.CallString();
if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", f.CallString()));
f.Body.Add(String.Format("{0};", method_call));
else if (ReturnType.CurrentType.ToLower().Contains("string"))
f.Body.Add(String.Format("{0} {1} = Marshal.PtrToStringAnsi({2});",
ReturnType.CurrentType, "retval", CallString()));
ReturnType.QualifiedType, "retval", method_call));
else
f.Body.Add(String.Format("{0} {1} = {2};", f.ReturnType.CurrentType, "retval", f.CallString()));
f.Body.Add(String.Format("{0} {1} = {2};", f.ReturnType.QualifiedType, "retval", method_call));
// Assign out parameters
f.Body.AddRange(assign_statements);
@ -526,14 +547,12 @@ namespace Bind.Structures
}
else
{
//if (Name == "EnqueueCopyBufferToImage")
// Debugger.Break();
// Call function and return
if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", f.CallString()));
else if (ReturnType.CurrentType.ToLower().Contains("string"))
f.Body.Add(String.Format("return System.Runtime.InteropServices.Marshal.PtrToStringAnsi({0});",
CallString()));
f.CallString()));
else
f.Body.Add(String.Format("return {0};", f.CallString()));
}

View file

@ -244,7 +244,7 @@ namespace Bind.Structures
}
else
{
sb.Append(CurrentType);
sb.Append(base.ToString());
if (Array > 0)
{
sb.Append("[");
@ -256,7 +256,7 @@ namespace Bind.Structures
}
else
{
sb.Append(CurrentType);
sb.Append(base.ToString());
for (int i = 0; i < Pointer; i++)
sb.Append("*");
if (Array > 0)
@ -293,9 +293,9 @@ namespace Bind.Structures
if (CurrentType.ToLower().Contains("string"))
{
// string* -> [In] String[] or [Out] StringBuilder[]
CurrentType =
QualifiedType =
Flow == FlowDirection.Out ?
"System.Text.StringBuilder[]" :
"StringBuilder[]" :
"String[]";
Pointer = 0;
@ -304,9 +304,9 @@ namespace Bind.Structures
else if (CurrentType.ToLower().Contains("char"))
{
// char* -> [In] String or [Out] StringBuilder
CurrentType =
QualifiedType =
Flow == FlowDirection.Out ?
"System.Text.StringBuilder" :
"StringBuilder" :
"String";
Pointer = 0;
@ -385,6 +385,12 @@ namespace Bind.Structures
}
}
public ParameterCollection(IEnumerable<Parameter> parameters)
{
foreach (Parameter p in parameters)
Add(new Parameter(p));
}
#endregion
#region void BuildCache()
@ -581,24 +587,24 @@ namespace Bind.Structures
foreach (Parameter p in this)
{
if (p.Unchecked)
sb.Append("unchecked((" + p.CurrentType + ")");
sb.Append("unchecked((" + p.QualifiedType + ")");
if (!p.Generic && p.CurrentType != "object")
{
if (p.CurrentType.ToLower().Contains("string"))
{
sb.Append(String.Format("({0}{1})",
p.CurrentType, (p.Array > 0) ? "[]" : ""));
p.QualifiedType, (p.Array > 0) ? "[]" : ""));
}
else if (p.IndirectionLevel != 0)
{
if (((Settings.Compatibility & Settings.Legacy.TurnVoidPointersToIntPtr) != Settings.Legacy.None) &&
p.Pointer != 0 && p.CurrentType.Contains("void"))
sb.Append("(IntPtr)");
sb.Append("(System.IntPtr)");
else
{
sb.Append("(");
sb.Append(p.CurrentType);
sb.Append(p.QualifiedType);
for (int i = 0; i < p.IndirectionLevel; i++)
sb.Append("*");
sb.Append(")");
@ -606,7 +612,7 @@ namespace Bind.Structures
}
else
{
sb.Append(String.Format("({0})", p.CurrentType));
sb.Append(String.Format("({0})", p.QualifiedType));
}
}

View file

@ -18,6 +18,8 @@ namespace Bind.Structures
private static bool typesLoaded;
string current_qualifier = "", previous_qualifier = "";
#region internal static void Initialize(string glTypes, string csTypes)
internal static void Initialize(string glTypes, string csTypes)
@ -54,8 +56,9 @@ namespace Bind.Structures
{
if (t != null)
{
CurrentType = t.CurrentType;
QualifiedType = t.QualifiedType; // Covers current type and qualifier
PreviousType = t.PreviousType;
PreviousQualifier = t.PreviousQualifier;
WrapperType = t.WrapperType;
Array = t.Array;
Pointer = t.Pointer;
@ -66,6 +69,44 @@ namespace Bind.Structures
#endregion
public string CurrentQualifier
{
get { return current_qualifier; }
set { PreviousQualifier = CurrentQualifier; current_qualifier = value; }
}
public string PreviousQualifier
{
get { return previous_qualifier; }
private set { previous_qualifier = value; }
}
public string QualifiedType {
get
{
if (!String.IsNullOrEmpty(CurrentQualifier))
return String.Format("{0}.{1}", CurrentQualifier, CurrentType);
else
return CurrentType;
}
set
{
if (String.IsNullOrEmpty(value))
throw new ArgumentException();
int qualifier_end = value.LastIndexOf('.');
if (qualifier_end > -1)
{
CurrentQualifier = value.Substring(0, qualifier_end);
CurrentType = value.Substring(qualifier_end + 1);
}
else
{
CurrentType = value;
}
}
}
#region public string CurrentType
string type;
@ -84,6 +125,9 @@ namespace Bind.Structures
}
set
{
if (String.IsNullOrEmpty(value))
throw new ArgumentException();
if (!String.IsNullOrEmpty(type))
PreviousType = type;
if (!String.IsNullOrEmpty(value))
@ -106,10 +150,9 @@ namespace Bind.Structures
public string PreviousType
{
get { return _previous_type; }
set { _previous_type = value; }
private set { _previous_type = value; }
}
#endregion
#region public bool Reference
@ -161,6 +204,16 @@ namespace Bind.Structures
#endregion
// Returns true if parameter is an enum.
public bool IsEnum
{
get
{
return Enum.GLEnums.ContainsKey(CurrentType) ||
Enum.AuxEnums.ContainsKey(CurrentType);
}
}
#region IndirectionLevel
// Gets the the level of indirection for this type. For example,
@ -291,7 +344,7 @@ namespace Bind.Structures
public override string ToString()
{
return CurrentType;
return QualifiedType;
}
#endregion
@ -316,13 +369,14 @@ namespace Bind.Structures
if ((normal || aux) && @enum.Name != "GLenum" && @enum.Name != "Boolean")
{
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
CurrentType = "int";
QualifiedType = "int";
else
{
#warning "Unecessary code"
if (normal)
CurrentType = CurrentType.Insert(0, String.Format("{0}.", Settings.EnumsOutput));
QualifiedType = CurrentType.Insert(0, String.Format("{0}.", Settings.EnumsOutput));
else if (aux)
CurrentType = CurrentType.Insert(0, String.Format("{0}.", Settings.EnumsAuxOutput));
QualifiedType = CurrentType.Insert(0, String.Format("{0}.", Settings.EnumsAuxOutput));
}
}
else if (GLTypes.TryGetValue(CurrentType, out s))
@ -333,23 +387,30 @@ namespace Bind.Structures
{
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
{
CurrentType = "int";
QualifiedType = "int";
}
else
{
// Better match: enum.Name == function.Category (e.g. GL_VERSION_1_1 etc)
if (Enum.GLEnums.ContainsKey(category))
{
CurrentType = String.Format("{0}.{1}", Settings.EnumsOutput, Enum.TranslateName(category));
QualifiedType = String.Format("{0}.{1}", Settings.EnumsOutput, Enum.TranslateName(category));
}
else
{
CurrentType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
QualifiedType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
}
}
}
else
{
// A few translations for consistency
switch (CurrentType.ToLower())
{
case "string": QualifiedType = "String"; break;
}
#warning "Stale code"
// This is not enum, default translation:
if (CurrentType == "PIXELFORMATDESCRIPTOR" || CurrentType == "LAYERPLANEDESCRIPTOR" ||
CurrentType == "GLYPHMETRICSFLOAT")
@ -370,10 +431,9 @@ namespace Bind.Structures
{
//p.Pointer = false;
//p.Reference = true;
}
else
CurrentType = s;
QualifiedType = s;
}
}
@ -386,7 +446,15 @@ namespace Bind.Structures
// of type ErrorCodes should also be overriden to ErrorCode.
XPathNavigator enum_override = overrides.SelectSingleNode(String.Format("/overrides/replace/enum[@name='{0}']/name", CurrentType));
if (enum_override != null)
CurrentType = enum_override.Value;
{
// For consistency - many overrides use string instead of String.
if (enum_override.Value == "string")
QualifiedType = "String";
else if (enum_override.Value == "StringBuilder")
QualifiedType = "StringBuilder";
else
CurrentType = enum_override.Value;
}
if (CurrentType == "IntPtr" && String.IsNullOrEmpty(PreviousType))
Pointer = 0;