2013-10-11 01:58:54 +02:00
|
|
|
|
#region License
|
|
|
|
|
//
|
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-11-03 01:20:17 +01:00
|
|
|
|
using System.Text;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Xml.XPath;
|
|
|
|
|
using Bind.Structures;
|
|
|
|
|
using Delegate = Bind.Structures.Delegate;
|
|
|
|
|
|
|
|
|
|
namespace Bind
|
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
using Enum = Bind.Structures.Enum;
|
|
|
|
|
using Type = Bind.Structures.Type;
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
class FuncProcessor
|
|
|
|
|
{
|
|
|
|
|
static readonly Regex Endings =
|
|
|
|
|
new Regex(@"((((d|f|fi)|(L?(u?i?64)?u?[isb]))_?(64)?v?)|v)", RegexOptions.Compiled | RegexOptions.RightToLeft);
|
|
|
|
|
static readonly Regex EndingsNotToTrim =
|
2013-11-10 10:16:47 +01:00
|
|
|
|
new Regex("(ib|[tdrey]s|[eE]n[vd]|bled|Attrib|Access|Coord|Feedbacks|Flag|Queries|Tess|Status|Pixels|Instanced|Indexed|Varyings|Boolean|IDs|Uniforms)", RegexOptions.Compiled | RegexOptions.RightToLeft);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
static readonly Regex EndingsAddV = new Regex("^0", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
string Overrides { get; set; }
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
IBind Generator { get; set; }
|
|
|
|
|
Settings Settings { get { return Generator.Settings; } }
|
|
|
|
|
|
|
|
|
|
public FuncProcessor(IBind generator, string overrides)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
if (generator == null)
|
|
|
|
|
throw new ArgumentNullException("generator");
|
2013-10-11 01:58:54 +02:00
|
|
|
|
if (overrides == null)
|
|
|
|
|
throw new ArgumentNullException("overrides");
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
Generator = generator;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
Overrides = overrides;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 19:32:52 +01:00
|
|
|
|
public FunctionCollection Process(EnumProcessor enum_processor, DelegateCollection delegates, EnumCollection enums,
|
|
|
|
|
string apiname, string apiversion)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Processing delegates.");
|
|
|
|
|
var nav = new XPathDocument(Overrides).CreateNavigator();
|
2013-11-04 19:32:52 +01:00
|
|
|
|
foreach (var version in apiversion.Split('|'))
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-05 08:55:52 +01:00
|
|
|
|
// Translate each delegate:
|
|
|
|
|
// 1st using the <replace> elements in overrides.xml
|
|
|
|
|
// 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
|
|
|
|
|
foreach (var signatures in delegates.Values)
|
2013-11-03 16:09:11 +01:00
|
|
|
|
{
|
2013-11-05 08:55:52 +01:00
|
|
|
|
foreach (var d in signatures)
|
2013-11-04 19:32:52 +01:00
|
|
|
|
{
|
|
|
|
|
TranslateExtension(d);
|
|
|
|
|
TranslateReturnType(enum_processor, nav, d, enums, apiname, version);
|
|
|
|
|
TranslateParameters(enum_processor, nav, d, enums, apiname, version);
|
|
|
|
|
TranslateAttributes(nav, d, enums, apiname, version);
|
|
|
|
|
}
|
2013-11-03 16:09:11 +01:00
|
|
|
|
}
|
2013-11-05 08:55:52 +01:00
|
|
|
|
|
|
|
|
|
// Create overloads for backwards compatibility,
|
|
|
|
|
// by resolving <overload> elements
|
|
|
|
|
var overload_list = new List<Delegate>();
|
|
|
|
|
foreach (var d in delegates.Values.Select(v => v.First()))
|
|
|
|
|
{
|
2013-11-12 23:38:09 +01:00
|
|
|
|
var overload_elements = GetFuncOverload(nav, d, apiname, apiversion);
|
|
|
|
|
foreach (XPathNavigator overload_element in overload_elements)
|
2013-11-05 08:55:52 +01:00
|
|
|
|
{
|
|
|
|
|
var overload = new Delegate(d);
|
|
|
|
|
ApplyParameterReplacement(overload, overload_element);
|
|
|
|
|
ApplyReturnTypeReplacement(overload, overload_element);
|
|
|
|
|
overload_list.Add(overload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var overload in overload_list)
|
|
|
|
|
{
|
2013-11-10 08:28:58 +01:00
|
|
|
|
delegates.Add(overload);
|
2013-11-05 08:55:52 +01:00
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 18:29:53 +01:00
|
|
|
|
Console.WriteLine("Generating convenience overloads.");
|
2013-11-10 08:28:58 +01:00
|
|
|
|
delegates.AddRange(CreateConvenienceOverloads(delegates));
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
Console.WriteLine("Generating wrappers.");
|
|
|
|
|
var wrappers = CreateWrappers(delegates, enums);
|
2013-11-03 16:09:11 +01:00
|
|
|
|
|
2013-11-10 18:29:53 +01:00
|
|
|
|
Console.WriteLine("Generating CLS compliant overloads.");
|
2013-10-11 01:58:54 +02:00
|
|
|
|
wrappers = CreateCLSCompliantWrappers(wrappers, enums);
|
2013-11-03 16:09:11 +01:00
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
Console.WriteLine("Removing non-CLS compliant duplicates.");
|
2013-11-03 16:09:11 +01:00
|
|
|
|
wrappers = MarkCLSCompliance(wrappers);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-08 16:40:43 +01:00
|
|
|
|
Console.WriteLine("Removing overloaded delegates.");
|
|
|
|
|
RemoveOverloadedDelegates(delegates, wrappers);
|
|
|
|
|
|
2013-11-03 16:09:11 +01:00
|
|
|
|
return wrappers;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:55:52 +01:00
|
|
|
|
#region Private Members
|
2013-11-01 09:24:18 +01:00
|
|
|
|
|
2013-11-08 16:40:43 +01:00
|
|
|
|
// When we have a list of overloaded delegates, make sure that
|
|
|
|
|
// all generated wrappers use the first (original) delegate, not
|
|
|
|
|
// the overloaded ones. This allows us to reduce the amount
|
|
|
|
|
// of delegates we need to generate (1 per entry point instead
|
|
|
|
|
// of 1 per overload), which improves loading times.
|
|
|
|
|
static void RemoveOverloadedDelegates(DelegateCollection delegates, FunctionCollection wrappers)
|
|
|
|
|
{
|
|
|
|
|
foreach (var w in wrappers.Values.SelectMany(w => w))
|
|
|
|
|
{
|
|
|
|
|
var d = delegates[w.Name].First();
|
|
|
|
|
w.WrappedDelegate = d;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:55:52 +01:00
|
|
|
|
static string GetPath(string apipath, string apiname, string apiversion, string function, string extension)
|
|
|
|
|
{
|
2013-11-03 01:20:17 +01:00
|
|
|
|
var path = new StringBuilder();
|
2013-11-05 08:55:52 +01:00
|
|
|
|
path.Append("/signatures/");
|
|
|
|
|
path.Append(apipath);
|
2013-11-04 19:32:52 +01:00
|
|
|
|
if (!String.IsNullOrEmpty(apiname) && !String.IsNullOrEmpty(apiversion))
|
|
|
|
|
{
|
|
|
|
|
path.Append(String.Format(
|
|
|
|
|
"[contains(concat('|', @name, '|'), '|{0}|') and " +
|
2013-11-07 16:48:11 +01:00
|
|
|
|
"(contains(concat('|', @version, '|'), '|{1}|') or not(boolean(@version)))]",
|
2013-11-04 19:32:52 +01:00
|
|
|
|
apiname,
|
|
|
|
|
apiversion));
|
|
|
|
|
}
|
|
|
|
|
else if (!String.IsNullOrEmpty(apiname))
|
2013-11-03 01:20:17 +01:00
|
|
|
|
{
|
|
|
|
|
path.Append(String.Format("[contains(concat('|', @name, '|'), '|{0}|')]", apiname));
|
|
|
|
|
}
|
2013-11-04 19:32:52 +01:00
|
|
|
|
else if (!String.IsNullOrEmpty(apiversion))
|
|
|
|
|
{
|
2013-11-07 16:48:11 +01:00
|
|
|
|
path.Append(String.Format("[contains(concat('|', @version, '|'), '|{0}|') or not(boolean(@version))]", apiversion));
|
2013-11-04 19:32:52 +01:00
|
|
|
|
}
|
2013-11-03 01:20:17 +01:00
|
|
|
|
|
2013-11-05 08:55:52 +01:00
|
|
|
|
if (function != null)
|
2013-11-03 01:20:17 +01:00
|
|
|
|
{
|
2013-11-05 08:55:52 +01:00
|
|
|
|
if (extension != null)
|
|
|
|
|
{
|
|
|
|
|
// match an override that has this specific extension
|
|
|
|
|
// *or* one that has no extension at all (equivalent
|
|
|
|
|
// to "match all possible extensions")
|
|
|
|
|
path.Append(String.Format(
|
|
|
|
|
"/function[contains(concat('|', @name, '|'), '|{0}|') and " +
|
|
|
|
|
"(contains(concat('|', @extension, '|'), '|{1}|') or not(boolean(@extension)))]",
|
|
|
|
|
function,
|
|
|
|
|
extension));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
path.Append(String.Format(
|
|
|
|
|
"/function[contains(concat('|', @name, '|'), '|{0}|')]",
|
|
|
|
|
function));
|
|
|
|
|
}
|
2013-11-03 01:20:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:55:52 +01:00
|
|
|
|
static string GetOverloadsPath(string apiname, string apiversion, string function, string extension)
|
|
|
|
|
{
|
|
|
|
|
return GetPath("overload", apiname, apiversion, function, extension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static string GetOverridesPath(string apiname, string apiversion, string function, string extension)
|
|
|
|
|
{
|
|
|
|
|
return GetPath("replace", apiname, apiversion, function, extension);
|
|
|
|
|
}
|
2013-11-03 01:20:17 +01:00
|
|
|
|
|
|
|
|
|
void TranslateType(Bind.Structures.Type type, EnumProcessor enum_processor, XPathNavigator overrides, EnumCollection enums,
|
|
|
|
|
string category, string apiname)
|
2013-11-01 09:24:18 +01:00
|
|
|
|
{
|
|
|
|
|
Bind.Structures.Enum @enum;
|
|
|
|
|
string s;
|
|
|
|
|
|
|
|
|
|
category = enum_processor.TranslateEnumName(category);
|
|
|
|
|
|
|
|
|
|
// Try to find out if it is an enum. If the type exists in the normal GLEnums list, use this.
|
|
|
|
|
// Special case for Boolean - it is an enum, but it is dumb to use that instead of the 'bool' type.
|
|
|
|
|
bool normal = enums.TryGetValue(type.CurrentType, out @enum);
|
|
|
|
|
|
|
|
|
|
// Translate enum types
|
|
|
|
|
if (normal && @enum.Name != "GLenum" && @enum.Name != "Boolean")
|
|
|
|
|
{
|
2013-11-03 16:09:11 +01:00
|
|
|
|
type.IsEnum = true;
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
|
|
|
|
|
{
|
|
|
|
|
type.QualifiedType = "int";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Some functions and enums have the same names.
|
|
|
|
|
// Make sure we reference the enums rather than the functions.
|
|
|
|
|
if (normal)
|
|
|
|
|
type.QualifiedType = type.CurrentType.Insert(0, String.Format("{0}.", Settings.EnumsOutput));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Generator.GLTypes.TryGetValue(type.CurrentType, out s))
|
|
|
|
|
{
|
|
|
|
|
// Check if the parameter is a generic GLenum. If it is, search for a better match,
|
|
|
|
|
// otherwise fallback to Settings.CompleteEnumName (named 'All' by default).
|
|
|
|
|
if (s.Contains("GLenum") /*&& !String.IsNullOrEmpty(category)*/)
|
|
|
|
|
{
|
2013-11-11 10:00:54 +01:00
|
|
|
|
type.IsEnum = true;
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
|
|
|
|
|
{
|
|
|
|
|
type.QualifiedType = "int";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Better match: enum.Name == function.Category (e.g. GL_VERSION_1_1 etc)
|
2013-11-03 16:09:11 +01:00
|
|
|
|
// Note: for backwards compatibility we use "category" only for the gl api.
|
|
|
|
|
// glcore, gles1 and gles2 use the All enum instead.
|
|
|
|
|
if (apiname == "gl" && enums.ContainsKey(category))
|
2013-11-01 09:24:18 +01:00
|
|
|
|
{
|
|
|
|
|
type.QualifiedType = String.Format("{0}{1}{2}", Settings.EnumsOutput,
|
|
|
|
|
Settings.NamespaceSeparator, enum_processor.TranslateEnumName(category));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
type.QualifiedType = String.Format("{0}{1}{2}", Settings.EnumsOutput,
|
|
|
|
|
Settings.NamespaceSeparator, Settings.CompleteEnumName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-11-11 10:00:54 +01:00
|
|
|
|
type.IsEnum = false;
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
// Todo: what is the point of this here? It is overwritten below.
|
|
|
|
|
// A few translations for consistency
|
|
|
|
|
switch (type.CurrentType.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "string":
|
|
|
|
|
type.QualifiedType = "String";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type.QualifiedType = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type.CurrentType =
|
|
|
|
|
Generator.CSTypes.ContainsKey(type.CurrentType) ?
|
|
|
|
|
Generator.CSTypes[type.CurrentType] : type.CurrentType;
|
|
|
|
|
|
|
|
|
|
// Make sure that enum parameters follow enum overrides, i.e.
|
|
|
|
|
// if enum ErrorCodes is overriden to ErrorCode, then parameters
|
|
|
|
|
// of type ErrorCodes should also be overriden to ErrorCode.
|
|
|
|
|
XPathNavigator enum_override = overrides.SelectSingleNode(
|
2013-11-03 01:20:17 +01:00
|
|
|
|
EnumProcessor.GetOverridesPath(apiname, type.CurrentType));
|
2013-11-01 09:24:18 +01:00
|
|
|
|
if (enum_override != null)
|
|
|
|
|
{
|
|
|
|
|
// For consistency - many overrides use string instead of String.
|
|
|
|
|
if (enum_override.Value == "string")
|
|
|
|
|
type.QualifiedType = "String";
|
|
|
|
|
else if (enum_override.Value == "StringBuilder")
|
|
|
|
|
type.QualifiedType = "StringBuilder";
|
|
|
|
|
else
|
|
|
|
|
type.CurrentType = enum_override.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type.CurrentType == "IntPtr" && String.IsNullOrEmpty(type.PreviousType))
|
|
|
|
|
type.Pointer = 0;
|
|
|
|
|
|
|
|
|
|
if (type.Pointer >= 3)
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Trace.WriteLine(String.Format(
|
|
|
|
|
"[Error] Type '{0}' has a high pointer level. Bindings will be incorrect.",
|
2013-11-03 12:12:39 +01:00
|
|
|
|
type));
|
2013-11-01 09:24:18 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-05 08:55:52 +01:00
|
|
|
|
|
2013-10-27 01:30:45 +02:00
|
|
|
|
void TranslateExtension(Delegate d)
|
|
|
|
|
{
|
|
|
|
|
var extension = d.Extension.ToUpper();
|
|
|
|
|
if (extension.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
extension = extension[0] + extension.Substring(1).ToLower();
|
|
|
|
|
}
|
|
|
|
|
d.Extension = extension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static string GetTrimmedExtension(string name, string extension)
|
|
|
|
|
{
|
|
|
|
|
// Extensions are always uppercase
|
|
|
|
|
int index = name.LastIndexOf(extension.ToUpper());
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
{
|
|
|
|
|
name = name.Remove(index);
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
// Trims unecessary suffices from the specified OpenGL function name.
|
2013-10-27 01:30:45 +02:00
|
|
|
|
static string GetTrimmedName(Delegate d)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-10-27 01:30:45 +02:00
|
|
|
|
string name = d.Name;
|
|
|
|
|
string extension = d.Extension;
|
|
|
|
|
string trimmed_name = GetTrimmedExtension(name, extension);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
|
|
|
|
// Note: some endings should not be trimmed, for example: 'b' from Attrib.
|
|
|
|
|
// Check the endingsNotToTrim regex for details.
|
|
|
|
|
Match m = EndingsNotToTrim.Match(trimmed_name);
|
|
|
|
|
if ((m.Index + m.Length) != trimmed_name.Length)
|
|
|
|
|
{
|
|
|
|
|
m = Endings.Match(trimmed_name);
|
|
|
|
|
|
|
|
|
|
if (m.Length > 0 && m.Index + m.Length == trimmed_name.Length)
|
|
|
|
|
{
|
|
|
|
|
// Only trim endings, not internal matches.
|
|
|
|
|
if (m.Value[m.Length - 1] == 'v' && EndingsAddV.IsMatch(name) &&
|
|
|
|
|
!name.StartsWith("Get") && !name.StartsWith("MatrixIndex"))
|
|
|
|
|
{
|
|
|
|
|
// Only trim ending 'v' when there is a number
|
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index) + "v";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!trimmed_name.EndsWith("xedv"))
|
|
|
|
|
{
|
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 10:16:47 +01:00
|
|
|
|
// If we have a convenience overload, we should turn the name from
|
|
|
|
|
// plural into singular
|
|
|
|
|
if (d.ReturnType.WrapperType == WrapperTypes.ConvenienceReturnType ||
|
2013-11-10 18:29:53 +01:00
|
|
|
|
d.ReturnType.WrapperType == WrapperTypes.ConvenienceArrayReturnType ||
|
|
|
|
|
d.Parameters.Any(p => p.WrapperType == WrapperTypes.ConvenienceArrayType))
|
2013-11-10 10:16:47 +01:00
|
|
|
|
{
|
|
|
|
|
trimmed_name = trimmed_name.Replace("Queries", "Query");
|
|
|
|
|
trimmed_name = trimmed_name.TrimEnd('s');
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
return trimmed_name;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 23:38:09 +01:00
|
|
|
|
static XPathNodeIterator GetFuncOverload(XPathNavigator nav, Delegate d, string apiname, string apiversion)
|
2013-11-05 08:55:52 +01:00
|
|
|
|
{
|
|
|
|
|
string ext = d.Extension;
|
|
|
|
|
string trimmed_name = GetTrimmedName(d);
|
|
|
|
|
string extensionless_name = GetTrimmedExtension(d.Name, ext);
|
|
|
|
|
|
2013-11-12 23:38:09 +01:00
|
|
|
|
var function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, d.Name, ext));
|
|
|
|
|
if (function_overload.Count == 0)
|
|
|
|
|
function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, extensionless_name, ext));
|
|
|
|
|
if (function_overload.Count == 0)
|
|
|
|
|
function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, trimmed_name, ext));
|
2013-11-05 08:55:52 +01:00
|
|
|
|
return function_overload;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 19:32:52 +01:00
|
|
|
|
static XPathNavigator GetFuncOverride(XPathNavigator nav, Delegate d, string apiname, string apiversion)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
string ext = d.Extension;
|
2013-10-27 02:35:53 +02:00
|
|
|
|
string trimmed_name = GetTrimmedName(d);
|
|
|
|
|
string extensionless_name = GetTrimmedExtension(d.Name, ext);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
|
|
|
|
var function_override =
|
2013-11-04 19:32:52 +01:00
|
|
|
|
nav.SelectSingleNode(GetOverridesPath(apiname, apiversion, d.Name, ext)) ??
|
|
|
|
|
nav.SelectSingleNode(GetOverridesPath(apiname, apiversion, extensionless_name, ext)) ??
|
|
|
|
|
nav.SelectSingleNode(GetOverridesPath(apiname, apiversion, trimmed_name, ext));
|
2013-10-11 01:58:54 +02:00
|
|
|
|
return function_override;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 01:30:45 +02:00
|
|
|
|
void TrimName(Function f)
|
|
|
|
|
{
|
|
|
|
|
f.TrimmedName = GetTrimmedName(f);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:55:52 +01:00
|
|
|
|
static void ApplyParameterReplacement(Delegate d, XPathNavigator function_override)
|
|
|
|
|
{
|
|
|
|
|
if (function_override != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < d.Parameters.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
XPathNavigator param_override = function_override.SelectSingleNode(String.Format("param[@name='{0}']", d.Parameters[i].RawName));
|
|
|
|
|
if (param_override != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (XPathNavigator node in param_override.SelectChildren(XPathNodeType.Element))
|
|
|
|
|
{
|
|
|
|
|
switch (node.Name)
|
|
|
|
|
{
|
|
|
|
|
case "type":
|
|
|
|
|
d.Parameters[i].CurrentType = (string)node.TypedValue;
|
|
|
|
|
break;
|
|
|
|
|
case "name":
|
|
|
|
|
d.Parameters[i].Name = (string)node.TypedValue;
|
|
|
|
|
break;
|
|
|
|
|
case "flow":
|
|
|
|
|
d.Parameters[i].Flow = Parameter.GetFlowDirection((string)node.TypedValue);
|
|
|
|
|
break;
|
|
|
|
|
case "count":
|
|
|
|
|
int count;
|
|
|
|
|
if (Int32.TryParse(node.Value, out count))
|
|
|
|
|
d.Parameters[i].ElementCount = count;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ApplyReturnTypeReplacement(Delegate d, XPathNavigator function_override)
|
|
|
|
|
{
|
|
|
|
|
if (function_override != null)
|
|
|
|
|
{
|
|
|
|
|
XPathNavigator return_override = function_override.SelectSingleNode("returns");
|
|
|
|
|
if (return_override != null)
|
|
|
|
|
{
|
|
|
|
|
d.ReturnType.CurrentType = return_override.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
// Translates the opengl return type to the equivalent C# type.
|
|
|
|
|
//
|
|
|
|
|
// First, we use the official typemap (gl.tm) to get the correct type.
|
|
|
|
|
// Then we override this, when it is:
|
|
|
|
|
// 1) A string (we have to use Marshal.PtrToStringAnsi, to avoid heap corruption)
|
|
|
|
|
// 2) An array (translates to IntPtr)
|
|
|
|
|
// 3) A generic object or void* (translates to IntPtr)
|
|
|
|
|
// 4) A GLenum (translates to int on Legacy.Tao or GL.Enums.GLenum otherwise).
|
|
|
|
|
// Return types must always be CLS-compliant, because .Net does not support overloading on return types.
|
2013-11-04 19:32:52 +01:00
|
|
|
|
void TranslateReturnType(EnumProcessor enum_processor, XPathNavigator nav, Delegate d,
|
|
|
|
|
EnumCollection enums, string apiname, string apiversion)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-04 19:32:52 +01:00
|
|
|
|
var function_override = GetFuncOverride(nav, d, apiname, apiversion);
|
2013-11-05 08:55:52 +01:00
|
|
|
|
ApplyReturnTypeReplacement(d, function_override);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-03 01:20:17 +01:00
|
|
|
|
TranslateType(d.ReturnType, enum_processor, nav, enums, d.Category, apiname);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
|
|
|
|
if (d.ReturnType.CurrentType.ToLower().Contains("void") && d.ReturnType.Pointer != 0)
|
|
|
|
|
{
|
|
|
|
|
d.ReturnType.QualifiedType = "IntPtr";
|
2013-11-01 09:24:18 +01:00
|
|
|
|
d.ReturnType.Pointer--;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
d.ReturnType.WrapperType = WrapperTypes.GenericReturnType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d.ReturnType.CurrentType.ToLower().Contains("string"))
|
|
|
|
|
{
|
|
|
|
|
d.ReturnType.QualifiedType = "IntPtr";
|
|
|
|
|
d.ReturnType.WrapperType = WrapperTypes.StringReturnType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d.ReturnType.CurrentType.ToLower() == "object")
|
|
|
|
|
{
|
|
|
|
|
d.ReturnType.QualifiedType = "IntPtr";
|
|
|
|
|
d.ReturnType.WrapperType |= WrapperTypes.GenericReturnType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d.ReturnType.CurrentType.Contains("GLenum"))
|
|
|
|
|
{
|
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None)
|
|
|
|
|
d.ReturnType.QualifiedType = String.Format("{0}{1}{2}",
|
|
|
|
|
Settings.EnumsOutput, Settings.NamespaceSeparator, Settings.CompleteEnumName);
|
|
|
|
|
else
|
|
|
|
|
d.ReturnType.QualifiedType = "int";
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
d.ReturnType.CurrentType = GetCLSCompliantType(d.ReturnType);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
Delegate GetCLSCompliantDelegate(Delegate d)
|
|
|
|
|
{
|
|
|
|
|
Delegate f = new Delegate(d);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < f.Parameters.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
f.Parameters[i].CurrentType = GetCLSCompliantType(f.Parameters[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f.ReturnType.CurrentType = GetCLSCompliantType(f.ReturnType);
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 01:20:17 +01:00
|
|
|
|
void TranslateParameters(EnumProcessor enum_processor,
|
2013-11-04 19:32:52 +01:00
|
|
|
|
XPathNavigator nav, Delegate d, EnumCollection enums,
|
|
|
|
|
string apiname, string apiversion)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-04 19:32:52 +01:00
|
|
|
|
var function_override = GetFuncOverride(nav, d, apiname, apiversion);
|
2013-11-05 08:55:52 +01:00
|
|
|
|
ApplyParameterReplacement(d, function_override);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < d.Parameters.Count; i++)
|
|
|
|
|
{
|
2013-11-03 01:20:17 +01:00
|
|
|
|
TranslateParameter(d.Parameters[i], enum_processor, nav, enums, d.Category, apiname);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
if (d.Parameters[i].CurrentType == "UInt16" && d.Name.Contains("LineStipple"))
|
|
|
|
|
d.Parameters[i].WrapperType = WrapperTypes.UncheckedParameter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
void TranslateParameter(Parameter p, EnumProcessor enum_processor,
|
2013-11-03 01:20:17 +01:00
|
|
|
|
XPathNavigator overrides, EnumCollection enums,
|
|
|
|
|
string category, string apiname)
|
2013-11-01 09:24:18 +01:00
|
|
|
|
{
|
2013-11-03 01:20:17 +01:00
|
|
|
|
TranslateType(p, enum_processor, overrides, enums, category, apiname);
|
2013-11-01 09:24:18 +01:00
|
|
|
|
|
|
|
|
|
// Find out the necessary wrapper types.
|
|
|
|
|
if (p.Pointer != 0)/* || CurrentType == "IntPtr")*/
|
|
|
|
|
{
|
|
|
|
|
if (p.CurrentType.ToLower().Contains("string") ||
|
|
|
|
|
p.CurrentType.ToLower().Contains("char") && p.Pointer > 1)
|
|
|
|
|
{
|
|
|
|
|
// string* -> [In] String[] or [Out] StringBuilder[]
|
|
|
|
|
p.QualifiedType =
|
|
|
|
|
p.Flow == FlowDirection.Out ?
|
|
|
|
|
"StringBuilder[]" :
|
|
|
|
|
"String[]";
|
|
|
|
|
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.WrapperType = WrapperTypes.None;
|
|
|
|
|
}
|
|
|
|
|
else if (p.CurrentType.ToLower().Contains("char"))
|
|
|
|
|
{
|
|
|
|
|
// char* -> [In] String or [Out] StringBuilder
|
|
|
|
|
p.QualifiedType =
|
|
|
|
|
p.Flow == FlowDirection.Out ?
|
|
|
|
|
"StringBuilder" :
|
|
|
|
|
"String";
|
|
|
|
|
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.WrapperType = WrapperTypes.None;
|
|
|
|
|
}
|
|
|
|
|
else if (p.CurrentType.ToLower().Contains("void") ||
|
|
|
|
|
(!String.IsNullOrEmpty(p.PreviousType) && p.PreviousType.ToLower().Contains("void")))
|
|
|
|
|
//|| CurrentType.Contains("IntPtr"))
|
|
|
|
|
{
|
|
|
|
|
p.CurrentType = "IntPtr";
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.WrapperType = WrapperTypes.GenericParameter;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.WrapperType = WrapperTypes.ArrayParameter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p.Reference)
|
|
|
|
|
p.WrapperType |= WrapperTypes.ReferenceParameter;
|
|
|
|
|
|
|
|
|
|
if (Utilities.Keywords(Settings.Language).Contains(p.Name))
|
|
|
|
|
p.Name = Settings.KeywordEscapeCharacter + p.Name;
|
|
|
|
|
|
|
|
|
|
// This causes problems with bool arrays
|
|
|
|
|
//if (CurrentType.ToLower().Contains("bool"))
|
|
|
|
|
// WrapperType = WrapperTypes.BoolParameter;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 19:32:52 +01:00
|
|
|
|
void TranslateAttributes(XPathNavigator nav, Delegate d, EnumCollection enums,
|
|
|
|
|
string apiname, string apiversion)
|
2013-10-22 21:09:18 +02:00
|
|
|
|
{
|
2013-11-04 19:32:52 +01:00
|
|
|
|
var function_override = GetFuncOverride(nav, d, apiname, apiversion);
|
2013-10-22 21:09:18 +02:00
|
|
|
|
|
|
|
|
|
if (function_override != null)
|
|
|
|
|
{
|
|
|
|
|
var version_override = function_override.SelectSingleNode("version");
|
|
|
|
|
if (version_override != null)
|
|
|
|
|
{
|
|
|
|
|
d.Version = version_override.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var profile_override = function_override.SelectSingleNode("profile");
|
|
|
|
|
if (profile_override != null)
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("Profile override not yet implemented");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 01:30:45 +02:00
|
|
|
|
FunctionCollection CreateWrappers(DelegateCollection delegates, EnumCollection enums)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
var wrappers = new FunctionCollection();
|
2013-11-03 16:09:11 +01:00
|
|
|
|
foreach (var d in delegates.Values.SelectMany(v => v))
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
wrappers.AddRange(CreateNormalWrappers(d, enums));
|
|
|
|
|
}
|
2013-11-11 10:00:54 +01:00
|
|
|
|
|
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.KeepUntypedEnums) != 0)
|
|
|
|
|
{
|
|
|
|
|
// Generate an "All" overload for every function that takes strongly-typed enums
|
|
|
|
|
var overloads = new List<Function>();
|
|
|
|
|
foreach (var list in wrappers.Values)
|
|
|
|
|
{
|
|
|
|
|
overloads.AddRange(list.Where(f => f.Parameters.Any(p => p.IsEnum)).Select(f =>
|
|
|
|
|
{
|
|
|
|
|
var fnew = new Function(f);
|
|
|
|
|
foreach (var p in fnew.Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (p.IsEnum)
|
|
|
|
|
{
|
|
|
|
|
p.CurrentType = Settings.CompleteEnumName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fnew;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
wrappers.AddRange(overloads);
|
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
return wrappers;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
FunctionCollection CreateCLSCompliantWrappers(FunctionCollection functions, EnumCollection enums)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
|
// to avoid redefinitions.
|
|
|
|
|
var wrappers = new FunctionCollection();
|
|
|
|
|
foreach (var list in functions.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (var f in list)
|
|
|
|
|
{
|
|
|
|
|
wrappers.AddChecked(f);
|
|
|
|
|
|
|
|
|
|
if (!f.CLSCompliant)
|
|
|
|
|
{
|
2013-11-10 15:35:47 +01:00
|
|
|
|
// The return type must always be cls-compliant,
|
|
|
|
|
// since we cannot overload on return types alone.
|
|
|
|
|
f.ReturnType.CurrentType = GetCLSCompliantType(f.ReturnType);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-10 15:35:47 +01:00
|
|
|
|
// Create a cls-compliant wrapper for the parameters
|
|
|
|
|
Function cls = new Function(f);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
bool modified = false;
|
|
|
|
|
for (int i = 0; i < f.Parameters.Count; i++)
|
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
cls.Parameters[i].CurrentType = GetCLSCompliantType(cls.Parameters[i]);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
if (cls.Parameters[i].CurrentType != f.Parameters[i].CurrentType)
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 15:35:47 +01:00
|
|
|
|
// Only add a cls-compliant overload if we have
|
|
|
|
|
// changed a parameter.
|
2013-10-11 01:58:54 +02:00
|
|
|
|
if (modified)
|
2013-11-10 15:35:47 +01:00
|
|
|
|
{
|
2013-10-11 01:58:54 +02:00
|
|
|
|
wrappers.AddChecked(cls);
|
2013-11-10 15:35:47 +01:00
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return wrappers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FunctionCollection MarkCLSCompliance(FunctionCollection collection)
|
|
|
|
|
{
|
|
|
|
|
//foreach (var w in
|
|
|
|
|
// (from list in collection
|
|
|
|
|
// from w1 in list.Value
|
|
|
|
|
// from w2 in list.Value
|
|
|
|
|
// where
|
|
|
|
|
// w1.TrimmedName == w2.TrimmedName &&
|
|
|
|
|
// w1.Parameters.Count == w2.Parameters.Count &&
|
|
|
|
|
// ParametersDifferOnlyInReference(w1.Parameters, w2.Parameters)
|
|
|
|
|
// select !w1.Parameters.HasReferenceParameters ? w1 : w2))
|
|
|
|
|
// {
|
|
|
|
|
// results.Add(w);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
foreach (List<Function> wrappers in collection.Values)
|
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
var must_remove = new List<int>();
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
for (int i = 0; i < wrappers.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = i + 1; j < wrappers.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (wrappers[i].TrimmedName == wrappers[j].TrimmedName && wrappers[i].Parameters.Count == wrappers[j].Parameters.Count)
|
|
|
|
|
{
|
|
|
|
|
bool function_i_is_problematic = false;
|
|
|
|
|
bool function_j_is_problematic = false;
|
|
|
|
|
|
|
|
|
|
int k;
|
|
|
|
|
for (k = 0; k < wrappers[i].Parameters.Count; k++)
|
|
|
|
|
{
|
|
|
|
|
if (wrappers[i].Parameters[k].CurrentType != wrappers[j].Parameters[k].CurrentType)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (wrappers[i].Parameters[k].DiffersOnlyOnReference(wrappers[j].Parameters[k]))
|
|
|
|
|
if (wrappers[i].Parameters[k].Reference)
|
|
|
|
|
function_i_is_problematic = true;
|
|
|
|
|
else
|
|
|
|
|
function_j_is_problematic = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (k == wrappers[i].Parameters.Count)
|
|
|
|
|
{
|
|
|
|
|
if (function_i_is_problematic)
|
2013-11-01 09:24:18 +01:00
|
|
|
|
must_remove.Add(i);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
if (function_j_is_problematic)
|
2013-11-01 09:24:18 +01:00
|
|
|
|
must_remove.Add(j);
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 09:24:18 +01:00
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
must_remove.Sort();
|
|
|
|
|
foreach (var i in must_remove)
|
|
|
|
|
{
|
|
|
|
|
// Careful: whenever we remove a function, the total count
|
|
|
|
|
// is reduced. We must account for that, or we will remove
|
|
|
|
|
// the wrong function!
|
|
|
|
|
wrappers.RemoveAt(i - count);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
return collection;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
string GetCLSCompliantType(Type type)
|
|
|
|
|
{
|
|
|
|
|
if (!type.CLSCompliant)
|
|
|
|
|
{
|
|
|
|
|
if (type.Pointer != 0 && Settings.Compatibility == Settings.Legacy.Tao)
|
|
|
|
|
return "IntPtr";
|
|
|
|
|
|
|
|
|
|
switch (type.CurrentType)
|
|
|
|
|
{
|
|
|
|
|
case "UInt16":
|
|
|
|
|
case "ushort":
|
|
|
|
|
return "Int16";
|
|
|
|
|
case "UInt32":
|
|
|
|
|
case "uint":
|
|
|
|
|
return "Int32";
|
|
|
|
|
case "UInt64":
|
|
|
|
|
case "ulong":
|
|
|
|
|
return "Int64";
|
|
|
|
|
case "SByte":
|
|
|
|
|
case "sbyte":
|
|
|
|
|
return "Byte";
|
|
|
|
|
case "UIntPtr":
|
|
|
|
|
return "IntPtr";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type.CurrentType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 01:30:45 +02:00
|
|
|
|
IEnumerable<Function> CreateNormalWrappers(Delegate d, EnumCollection enums)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
Function f = new Function(d);
|
2013-10-27 01:30:45 +02:00
|
|
|
|
TrimName(f);
|
|
|
|
|
|
2013-10-11 01:58:54 +02:00
|
|
|
|
WrapReturnType(f);
|
|
|
|
|
foreach (var wrapper in WrapParameters(f, enums))
|
|
|
|
|
{
|
|
|
|
|
yield return wrapper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 08:28:58 +01:00
|
|
|
|
IEnumerable<Delegate> CreateConvenienceOverloads(DelegateCollection delegates)
|
|
|
|
|
{
|
|
|
|
|
foreach (var list in delegates.Values)
|
|
|
|
|
{
|
|
|
|
|
var d = list.First();
|
2013-11-10 10:16:47 +01:00
|
|
|
|
if (d.Parameters.Count > 0 && d.Parameters.Count <= 2)
|
2013-11-10 08:28:58 +01:00
|
|
|
|
{
|
|
|
|
|
var p = d.Parameters.Last();
|
|
|
|
|
var r = d.ReturnType;
|
|
|
|
|
|
|
|
|
|
bool is_candidate = true;
|
2013-11-10 19:03:49 +01:00
|
|
|
|
is_candidate &= d.Name.StartsWith("Get") || d.Name.StartsWith("Gen") ||
|
|
|
|
|
d.Name.StartsWith("Delete") || d.Name.StartsWith("New");
|
2013-11-10 08:28:58 +01:00
|
|
|
|
is_candidate &= d.Name.EndsWith("v") || d.Name.EndsWith("s");
|
2013-11-10 18:29:53 +01:00
|
|
|
|
is_candidate &= p.Pointer > 0;
|
2013-11-10 08:28:58 +01:00
|
|
|
|
is_candidate &= r.CurrentType == "void" && r.Pointer == 0;
|
|
|
|
|
|
2013-11-10 18:29:53 +01:00
|
|
|
|
if (is_candidate && p.Flow == FlowDirection.Out)
|
2013-11-10 08:28:58 +01:00
|
|
|
|
{
|
2013-11-10 18:29:53 +01:00
|
|
|
|
var f = new Delegate(d);
|
|
|
|
|
f.ReturnType = new Type(f.Parameters.Last());
|
|
|
|
|
f.ReturnType.Pointer = 0;
|
|
|
|
|
f.Parameters.RemoveAt(f.Parameters.Count - 1);
|
|
|
|
|
f.ReturnType.WrapperType = WrapperTypes.ConvenienceReturnType;
|
2013-11-10 08:28:58 +01:00
|
|
|
|
|
2013-11-10 18:29:53 +01:00
|
|
|
|
if (f.Parameters.Count > 0)
|
2013-11-10 08:28:58 +01:00
|
|
|
|
{
|
2013-11-10 18:29:53 +01:00
|
|
|
|
var p_size = f.Parameters.Last();
|
2013-11-10 08:28:58 +01:00
|
|
|
|
if (p_size.CurrentType.ToLower().Contains("int") && p_size.Pointer == 0)
|
|
|
|
|
{
|
2013-11-10 18:29:53 +01:00
|
|
|
|
f.Parameters.RemoveAt(f.Parameters.Count - 1);
|
|
|
|
|
f.ReturnType.WrapperType = WrapperTypes.ConvenienceArrayReturnType;
|
2013-11-10 08:28:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 18:29:53 +01:00
|
|
|
|
yield return f;
|
|
|
|
|
}
|
|
|
|
|
else if (is_candidate && p.Flow != FlowDirection.Out)
|
|
|
|
|
{
|
|
|
|
|
if (d.Parameters.Count == 2)
|
|
|
|
|
{
|
|
|
|
|
var f = new Delegate(d);
|
|
|
|
|
var p_array = f.Parameters.Last();
|
|
|
|
|
var p_size = f.Parameters[f.Parameters.Count - 2];
|
|
|
|
|
f.Parameters.RemoveAt(f.Parameters.Count - 2);
|
|
|
|
|
p_array.WrapperType = WrapperTypes.ConvenienceArrayType;
|
|
|
|
|
p_array.Pointer = 0;
|
|
|
|
|
|
|
|
|
|
yield return f;
|
|
|
|
|
}
|
2013-11-10 08:28:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
public IEnumerable<Function> WrapParameters(Function func, EnumCollection enums)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
|
|
|
|
Function f;
|
|
|
|
|
|
|
|
|
|
if (func.Parameters.HasPointerParameters)
|
|
|
|
|
{
|
|
|
|
|
Function _this = new Function(func);
|
|
|
|
|
// Array overloads
|
|
|
|
|
foreach (Parameter p in _this.Parameters)
|
|
|
|
|
{
|
2013-10-22 13:41:31 +02:00
|
|
|
|
if (p.WrapperType == WrapperTypes.ArrayParameter)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-10-22 13:41:31 +02:00
|
|
|
|
if (p.ElementCount != 1)
|
|
|
|
|
{
|
|
|
|
|
// Create a proper array
|
|
|
|
|
p.Reference = false;
|
|
|
|
|
p.Array++;
|
|
|
|
|
p.Pointer--;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Create a reference
|
|
|
|
|
p.Reference = true;
|
|
|
|
|
p.Array--;
|
|
|
|
|
p.Pointer--;
|
2013-11-10 18:29:53 +01:00
|
|
|
|
p.WrapperType = WrapperTypes.ReferenceParameter;
|
2013-10-22 13:41:31 +02:00
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
f = new Function(_this);
|
|
|
|
|
yield return f;
|
2013-11-01 09:24:18 +01:00
|
|
|
|
foreach (var w in WrapVoidPointers(f, enums))
|
2013-10-11 01:58:54 +02:00
|
|
|
|
yield return w;
|
|
|
|
|
|
|
|
|
|
_this = new Function(func);
|
|
|
|
|
// Reference overloads
|
|
|
|
|
foreach (Parameter p in _this.Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (p.WrapperType == WrapperTypes.ArrayParameter)
|
|
|
|
|
{
|
|
|
|
|
p.Reference = true;
|
|
|
|
|
p.Array--;
|
|
|
|
|
p.Pointer--;
|
2013-11-10 18:29:53 +01:00
|
|
|
|
p.WrapperType = WrapperTypes.ReferenceParameter;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
f = new Function(_this);
|
|
|
|
|
yield return f;
|
2013-11-01 09:24:18 +01:00
|
|
|
|
foreach (var w in WrapVoidPointers(f, enums))
|
2013-10-11 01:58:54 +02:00
|
|
|
|
yield return w;
|
|
|
|
|
|
|
|
|
|
_this = func;
|
|
|
|
|
// Pointer overloads
|
2013-10-22 13:41:31 +02:00
|
|
|
|
// Should be last to work around an Intellisense bug, where
|
2013-10-11 01:58:54 +02:00
|
|
|
|
// array overloads are not reported if there is a pointer overload.
|
|
|
|
|
foreach (Parameter p in _this.Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (p.WrapperType == WrapperTypes.ArrayParameter)
|
|
|
|
|
{
|
|
|
|
|
p.Reference = false;
|
2013-11-10 18:29:53 +01:00
|
|
|
|
p.WrapperType = WrapperTypes.PointerParameter;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
f = new Function(_this);
|
|
|
|
|
yield return f;
|
2013-11-01 09:24:18 +01:00
|
|
|
|
foreach (var w in WrapVoidPointers(f, enums))
|
2013-10-11 01:58:54 +02:00
|
|
|
|
yield return w;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
f = new Function(func);
|
|
|
|
|
yield return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
IEnumerable<Function> WrapVoidPointers(Function f, EnumCollection enums)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
// reference wrapper (e.g. void Foo<T1,T2>(int, ref T1, ref T2))
|
|
|
|
|
var func = new Function(f);
|
|
|
|
|
int index = -1;
|
|
|
|
|
foreach (var p in func.Parameters)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
index++;
|
|
|
|
|
if (p.WrapperType == WrapperTypes.GenericParameter)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
p.Reference = true;
|
|
|
|
|
p.Array = 0;
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.Generic = true;
|
|
|
|
|
p.CurrentType = "T" + index.ToString();
|
|
|
|
|
p.Flow = FlowDirection.Undefined;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
func.Parameters.Rebuild = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 09:24:18 +01:00
|
|
|
|
yield return func;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
// 1d-array wrapper (e.g. void Foo<T1, T2>(int, T1[], T2[]))
|
|
|
|
|
func = new Function(f);
|
|
|
|
|
index = -1;
|
|
|
|
|
foreach (var p in func.Parameters)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
index++;
|
|
|
|
|
if (p.WrapperType == WrapperTypes.GenericParameter)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
p.Reference = false;
|
|
|
|
|
p.Array = 1;
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.Generic = true;
|
|
|
|
|
p.CurrentType = "T" + index.ToString();
|
|
|
|
|
p.Flow = FlowDirection.Undefined;
|
|
|
|
|
func.Parameters.Rebuild = true;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 09:24:18 +01:00
|
|
|
|
yield return func;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
// 2d-array wrapper (e.g. void Foo<T1, T2>(int, T1[,], T2[,]))
|
|
|
|
|
func = new Function(f);
|
|
|
|
|
index = -1;
|
|
|
|
|
foreach (var p in func.Parameters)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
index++;
|
|
|
|
|
if (p.WrapperType == WrapperTypes.GenericParameter)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
p.Reference = false;
|
|
|
|
|
p.Array = 2;
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.Generic = true;
|
|
|
|
|
p.CurrentType = "T" + index.ToString();
|
|
|
|
|
p.Flow = FlowDirection.Undefined;
|
|
|
|
|
func.Parameters.Rebuild = true;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 09:24:18 +01:00
|
|
|
|
yield return func;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
// 3d-array wrapper (e.g. void Foo<T1, T2>(int, T1[,,], T2[,,]))
|
|
|
|
|
func = new Function(f);
|
|
|
|
|
index = -1;
|
|
|
|
|
foreach (var p in func.Parameters)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
index++;
|
|
|
|
|
if (p.WrapperType == WrapperTypes.GenericParameter)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
p.Reference = false;
|
|
|
|
|
p.Array = 3;
|
|
|
|
|
p.Pointer = 0;
|
|
|
|
|
p.Generic = true;
|
|
|
|
|
p.CurrentType = "T" + index.ToString();
|
|
|
|
|
p.Flow = FlowDirection.Undefined;
|
|
|
|
|
func.Parameters.Rebuild = true;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 09:24:18 +01:00
|
|
|
|
yield return func;
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:24:18 +01:00
|
|
|
|
static void WrapReturnType(Function func)
|
2013-10-11 01:58:54 +02:00
|
|
|
|
{
|
2013-11-01 09:24:18 +01:00
|
|
|
|
switch (func.ReturnType.WrapperType)
|
|
|
|
|
{
|
|
|
|
|
case WrapperTypes.StringReturnType:
|
|
|
|
|
func.ReturnType.QualifiedType = "String";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
2013-11-03 01:20:17 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-10-11 01:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|