2009-02-22 10:43:35 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace Bind.Structures
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
class Function : Delegate, IEquatable<Function>, IComparable<Function>
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-02-28 19:29:34 +00:00
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
Delegate wrapped_delegate;
|
|
|
|
|
|
|
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
|
|
public Function(Delegate d)
|
|
|
|
|
: base(d)
|
|
|
|
|
{
|
2009-03-21 21:44:07 +00:00
|
|
|
|
Name = d.Name;
|
|
|
|
|
Body = new FunctionBody();
|
2009-02-28 19:29:34 +00:00
|
|
|
|
WrappedDelegate = d;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-21 21:44:07 +00:00
|
|
|
|
public Function(Function f)
|
2009-10-28 23:09:25 +00:00
|
|
|
|
: this(f.WrappedDelegate)
|
2009-03-21 21:44:07 +00:00
|
|
|
|
{
|
2009-10-28 23:09:25 +00:00
|
|
|
|
Parameters = new ParameterCollection(f.Parameters);
|
|
|
|
|
ReturnType = new Type(f.ReturnType);
|
|
|
|
|
Body.AddRange(f.Body);
|
2009-03-21 21:44:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2009-03-25 17:55:37 +00:00
|
|
|
|
#region public Delegate WrappedDelegate
|
|
|
|
|
|
2009-02-28 19:29:34 +00:00
|
|
|
|
public Delegate WrappedDelegate
|
|
|
|
|
{
|
|
|
|
|
get { return wrapped_delegate; }
|
|
|
|
|
set { wrapped_delegate = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-25 17:55:37 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2009-02-28 19:29:34 +00:00
|
|
|
|
#region public void TurnVoidPointersToIntPtr()
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
public void TurnVoidPointersToIntPtr()
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
foreach (Parameter p in Parameters)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-07-15 22:33:26 +00:00
|
|
|
|
if (p.Pointer != 0 && p.CurrentType == "void")
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
p.CurrentType = "IntPtr";
|
2009-07-15 22:33:26 +00:00
|
|
|
|
p.Pointer = 0;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-28 19:29:34 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
#region public override bool Unsafe
|
|
|
|
|
|
|
|
|
|
public override bool Unsafe
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.NoPublicUnsafeFunctions) != Settings.Legacy.None)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return base.Unsafe;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public FunctionBody Body
|
|
|
|
|
|
|
|
|
|
FunctionBody _body;
|
|
|
|
|
|
|
|
|
|
public FunctionBody Body
|
|
|
|
|
{
|
|
|
|
|
get { return _body; }
|
|
|
|
|
set { _body = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public string TrimmedName
|
|
|
|
|
|
|
|
|
|
public string TrimmedName;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public override string Name
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the name of the opengl function.
|
|
|
|
|
/// If no Tao compatibility is set, set TrimmedName to Name, after removing
|
|
|
|
|
/// [u][bsifd][v].
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return base.Name; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Name = value;
|
|
|
|
|
|
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.NoTrimFunctionEnding) != Settings.Legacy.None)
|
|
|
|
|
{
|
|
|
|
|
// If we don't need compatibility with Tao,
|
|
|
|
|
// remove the Extension and the overload information from the name
|
|
|
|
|
// (Extension == "ARB", "EXT", etc, overload == [u][bsidf][v])
|
|
|
|
|
// TODO: Use some regex's here, to reduce clutter.
|
|
|
|
|
TrimmedName = value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-12-07 00:01:48 +00:00
|
|
|
|
TrimmedName = FuncProcessor.TrimName(Name, false);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public override string ToString()
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.Append(Unsafe ? "unsafe " : "");
|
|
|
|
|
sb.Append(ReturnType);
|
|
|
|
|
sb.Append(" ");
|
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.NoTrimFunctionEnding) != Settings.Legacy.None)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(Settings.FunctionPrefix);
|
|
|
|
|
}
|
|
|
|
|
sb.Append(!String.IsNullOrEmpty(TrimmedName) ? TrimmedName : Name);
|
2009-03-21 21:44:07 +00:00
|
|
|
|
|
|
|
|
|
if (Parameters.HasGenericParameters)
|
|
|
|
|
{
|
|
|
|
|
sb.Append("<");
|
|
|
|
|
foreach (Parameter p in Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (p.Generic)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(p.CurrentType);
|
|
|
|
|
sb.Append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.Remove(sb.Length - 1, 1);
|
|
|
|
|
sb.Append(">");
|
|
|
|
|
}
|
|
|
|
|
sb.AppendLine(Parameters.ToString(false));
|
|
|
|
|
if (Parameters.HasGenericParameters)
|
|
|
|
|
{
|
|
|
|
|
foreach (Parameter p in Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (p.Generic)
|
|
|
|
|
sb.AppendLine(String.Format(" where {0} : struct", p.CurrentType));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
if (Body.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(Body.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEquatable<Function> Members
|
|
|
|
|
|
|
|
|
|
public bool Equals(Function other)
|
|
|
|
|
{
|
|
|
|
|
return
|
2009-08-25 15:59:57 +00:00
|
|
|
|
!String.IsNullOrEmpty(TrimmedName) && !String.IsNullOrEmpty(other.TrimmedName) &&
|
|
|
|
|
TrimmedName == other.TrimmedName &&
|
|
|
|
|
Parameters.ToString(true) == other.Parameters.ToString(true);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2009-05-30 15:28:52 +00:00
|
|
|
|
#region IComparable<Function> Members
|
|
|
|
|
|
|
|
|
|
public int CompareTo(Function other)
|
|
|
|
|
{
|
2009-08-11 14:06:40 +00:00
|
|
|
|
int ret = Name.CompareTo(other.Name);
|
|
|
|
|
if (ret == 0)
|
2009-11-17 09:33:14 +00:00
|
|
|
|
ret = Parameters.CompareTo(other.Parameters);
|
2009-08-11 14:06:40 +00:00
|
|
|
|
if (ret == 0)
|
2009-11-17 09:33:14 +00:00
|
|
|
|
ret = ReturnType.CompareTo(other.ReturnType);
|
2009-08-11 14:06:40 +00:00
|
|
|
|
return ret;
|
2009-05-30 15:28:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region class FunctionBody : List<string>
|
|
|
|
|
|
|
|
|
|
public class FunctionBody : List<string>
|
|
|
|
|
{
|
|
|
|
|
public FunctionBody()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FunctionBody(FunctionBody fb)
|
|
|
|
|
{
|
|
|
|
|
foreach (string s in fb)
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
Add(s);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string indent = "";
|
|
|
|
|
|
|
|
|
|
public void Indent()
|
|
|
|
|
{
|
|
|
|
|
indent += " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unindent()
|
|
|
|
|
{
|
|
|
|
|
if (indent.Length >= 4)
|
|
|
|
|
indent = indent.Substring(4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new public void Add(string s)
|
|
|
|
|
{
|
|
|
|
|
base.Add(indent + s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new public void AddRange(IEnumerable<string> collection)
|
|
|
|
|
{
|
|
|
|
|
foreach (string t in collection)
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
Add(t);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
if (Count == 0)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
return String.Empty;
|
|
|
|
|
|
2009-08-25 15:59:57 +00:00
|
|
|
|
StringBuilder sb = new StringBuilder(Count);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
sb.AppendLine("{");
|
|
|
|
|
foreach (string s in this)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(" " + s);
|
|
|
|
|
}
|
|
|
|
|
sb.Append("}");
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2009-05-29 15:57:01 +00:00
|
|
|
|
#region class FunctionCollection : SortedDictionary<string, List<Function>>
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-05-29 15:57:01 +00:00
|
|
|
|
class FunctionCollection : SortedDictionary<string, List<Function>>
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
Regex unsignedFunctions = new Regex(@".+(u[dfisb]v?)", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
public void Add(Function f)
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
if (!ContainsKey(f.Extension))
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
Add(f.Extension, new List<Function>());
|
2009-02-22 10:43:35 +00:00
|
|
|
|
this[f.Extension].Add(f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this[f.Extension].Add(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddRange(IEnumerable<Function> functions)
|
|
|
|
|
{
|
|
|
|
|
foreach (Function f in functions)
|
|
|
|
|
{
|
2009-08-25 15:59:57 +00:00
|
|
|
|
Add(f);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2009-03-08 19:19:52 +00:00
|
|
|
|
/// Adds the function to the collection, if a function with the same name and parameters doesn't already exist.
|
2009-02-22 10:43:35 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="f">The Function to add.</param>
|
|
|
|
|
public void AddChecked(Function f)
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
if (ContainsKey(f.Extension))
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
int index = this[f.Extension].IndexOf(f);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
if (index == -1)
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
Add(f);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
2009-03-08 22:00:13 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
Function existing = this[f.Extension][index];
|
2009-03-08 22:00:13 +00:00
|
|
|
|
if ((existing.Parameters.HasUnsignedParameters && !unsignedFunctions.IsMatch(existing.Name) && unsignedFunctions.IsMatch(f.Name)) ||
|
|
|
|
|
(!existing.Parameters.HasUnsignedParameters && unsignedFunctions.IsMatch(existing.Name) && !unsignedFunctions.IsMatch(f.Name)))
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
this[f.Extension].RemoveAt(index);
|
|
|
|
|
this[f.Extension].Add(f);
|
2009-03-08 22:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-12-04 21:51:40 +00:00
|
|
|
|
Add(f);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|