From ffa26fb20447fc246b877f274e42b552cc8c02b1 Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Thu, 5 Oct 2017 12:33:19 +0100 Subject: [PATCH] Add feature to Bind to generate legacy array overloads --- src/Generator.Bind/FuncProcessor.cs | 27 +++++++++++++++++++++++++++ src/Generator.Bind/Utilities.cs | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/src/Generator.Bind/FuncProcessor.cs b/src/Generator.Bind/FuncProcessor.cs index 213f8f65..7755f40e 100644 --- a/src/Generator.Bind/FuncProcessor.cs +++ b/src/Generator.Bind/FuncProcessor.cs @@ -648,6 +648,22 @@ namespace Bind { d.Parameters[i].WrapperType |= WrapperTypes.UncheckedParameter; } + + if (function_override != null) + { + XPathNavigator param_override = function_override.SelectSingleNode(String.Format( + "param[@name='{0}' or @index='{1}']", + d.Parameters[i].RawName, + i)); + if (param_override != null) + { + var legacyArrayParameter = param_override.GetAttribute("legacyArrayParameter", String.Empty); + if (!String.IsNullOrEmpty(legacyArrayParameter)) + { + d.Parameters[i].WrapperType |= WrapperTypes.LegacyArrayParameter; + } + } + } } } @@ -1097,6 +1113,17 @@ namespace Bind // Generics are handled in a second pass. if ((parameter.WrapperType & WrapperTypes.GenericParameter) == 0) { + if ((parameter.WrapperType & WrapperTypes.LegacyArrayParameter) != 0) + { + foreach (var wrapper in GetWrapper(wrappers, WrapperTypes.LegacyArrayParameter, func)) + { + wrapper.Obsolete = "Use out overload instead"; + var p = wrapper.Parameters[i]; + p.Array++; + p.Pointer--; + } + } + if ((parameter.WrapperType & WrapperTypes.ArrayParameter) != 0) { foreach (var wrapper in GetWrapper(wrappers, WrapperTypes.ArrayParameter, func)) diff --git a/src/Generator.Bind/Utilities.cs b/src/Generator.Bind/Utilities.cs index 188e2a75..2d55f4ff 100644 --- a/src/Generator.Bind/Utilities.cs +++ b/src/Generator.Bind/Utilities.cs @@ -94,6 +94,10 @@ namespace Bind /// Add an int32 overload for convenience. /// SizeParameter = 1 << 14, + /// + /// Function takes a ref but we emit a legacy array overload to maintain backwards compatability. + /// + LegacyArrayParameter = 1 << 15, } internal static class Utilities