From 93743f913dad8dd0d89416d4506808a93977f23b Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 10 Oct 2010 12:28:27 +0000 Subject: [PATCH] Add support for function deprecation. --- Source/Bind/GL2/Generator.cs | 11 +++++++++++ Source/Bind/Generator.Bind.csproj | 1 + Source/Bind/Settings.cs | 20 ++++++++++++++++++++ Source/Bind/Structures/Delegate.cs | 5 +++++ 4 files changed, 37 insertions(+) diff --git a/Source/Bind/GL2/Generator.cs b/Source/Bind/GL2/Generator.cs index 485895ee..b7981bb9 100644 --- a/Source/Bind/GL2/Generator.cs +++ b/Source/Bind/GL2/Generator.cs @@ -162,6 +162,11 @@ namespace Bind.GL2 case "category": d.Category = words[1]; break; + + case "deprecated": + d.Deprecated = true; + d.DeprecatedVersion = words[1]; + break; } } while (!specFile.EndOfStream); @@ -709,10 +714,16 @@ namespace Bind.GL2 private static void WriteMethod(BindStreamWriter sw, Function f) { + if (f.Deprecated && Settings.IsEnabled(Settings.Legacy.AddDeprecationWarnings)) + { + sw.WriteLine("[Obsolete(\"Deprecated in OpenGL {0}\")]", f.DeprecatedVersion); + } + 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 "); diff --git a/Source/Bind/Generator.Bind.csproj b/Source/Bind/Generator.Bind.csproj index d41f86a6..c81ed8f2 100644 --- a/Source/Bind/Generator.Bind.csproj +++ b/Source/Bind/Generator.Bind.csproj @@ -139,6 +139,7 @@ Properties\GlobalAssemblyInfo.cs + Code diff --git a/Source/Bind/Settings.cs b/Source/Bind/Settings.cs index 99a4e501..773728bc 100644 --- a/Source/Bind/Settings.cs +++ b/Source/Bind/Settings.cs @@ -127,6 +127,8 @@ namespace Bind NoDebugHelpers = 0x800, /// Generate both typed and untyped ("All") signatures for enum parameters. KeepUntypedEnums = 0x1000, + /// Marks deprecated functions as [Obsolete] + AddDeprecationWarnings = 0x2000, Tao = ConstIntEnums | NoAdvancedEnumProcessing | NoPublicUnsafeFunctions | @@ -142,6 +144,24 @@ namespace Bind /*GenerateAllPermutations,*/ } + // Returns true if flag is enabled. + public static bool IsEnabled(Legacy flag) + { + return (Compatibility & flag) != (Legacy)0; + } + + // Enables the specified flag. + public static void Enable(Legacy flag) + { + Compatibility |= flag; + } + + // Disables the specified flag. + public static void Disable(Legacy flag) + { + Compatibility &= ~flag; + } + /// True if multiple tokens should be dropped (e.g. FooARB, FooEXT and FooSGI). public static bool DropMultipleTokens { diff --git a/Source/Bind/Structures/Delegate.cs b/Source/Bind/Structures/Delegate.cs index bd2f9d2b..5626aa10 100644 --- a/Source/Bind/Structures/Delegate.cs +++ b/Source/Bind/Structures/Delegate.cs @@ -79,6 +79,8 @@ namespace Bind.Structures ReturnType = new Type(d.ReturnType); Version = d.Version; //this.Version = !String.IsNullOrEmpty(d.Version) ? new string(d.Version.ToCharArray()) : ""; + Deprecated = d.Deprecated; + DeprecatedVersion = d.DeprecatedVersion; } #endregion @@ -277,6 +279,9 @@ namespace Bind.Structures #endregion + public bool Deprecated { get; set; } + public string DeprecatedVersion { get; set; } + #endregion #region --- Strings ---