From 370396ab7fd6b0c75b29faf70fd36d772a32cdea Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 5 May 2009 21:00:48 +0000 Subject: [PATCH] The generator now detects and adds the FlagsAttribute to bitwise collections. Fixes bug [#792] "Resharper - Bitwise operation on enum which is not marked by [Flags] attribute" (http://www.opentk.com/node/792). --- Source/Bind/GL2/Generator.cs | 4 ++++ Source/Bind/Structures/Constant.cs | 10 --------- Source/Bind/Structures/Enum.cs | 32 +++++++++++++++++++++++++++- Source/OpenTK/Graphics/GL/GLEnums.cs | 8 +++++++ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Source/Bind/GL2/Generator.cs b/Source/Bind/GL2/Generator.cs index 90f6db14..209f0609 100644 --- a/Source/Bind/GL2/Generator.cs +++ b/Source/Bind/GL2/Generator.cs @@ -466,6 +466,10 @@ namespace Bind.GL2 using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, enumsFile))) { WriteLicense(sw); + + sw.WriteLine("using System;"); + sw.WriteLine(); + if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None) { sw.WriteLine("namespace {0}", Settings.OutputNamespace); diff --git a/Source/Bind/Structures/Constant.cs b/Source/Bind/Structures/Constant.cs index 94a8aa9b..97c47103 100644 --- a/Source/Bind/Structures/Constant.cs +++ b/Source/Bind/Structures/Constant.cs @@ -51,16 +51,6 @@ namespace Bind.Structures { get { - //if (String.IsNullOrEmpty(Reference)) - // return _value; - //else - //{ - // Enum @ref; - // if (Enum.GLEnums.TryGetValue(Reference, out @ref) || Enum.AuxEnums.TryGetValue(Reference, out @ref)) - // if (@ref.ConstantCollection.ContainsKey(_value)) - // return (@ref.ConstantCollection[_value] as Constant).Value; - //} - return _value; } set diff --git a/Source/Bind/Structures/Enum.cs b/Source/Bind/Structures/Enum.cs index 4289a3ca..a365ba29 100644 --- a/Source/Bind/Structures/Enum.cs +++ b/Source/Bind/Structures/Enum.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Text; using System.IO; +using System.Globalization; namespace Bind.Structures { @@ -77,6 +78,20 @@ namespace Bind.Structures #endregion + #region Public Members + + // Returns true if the enum contains a collection of flags, i.e. 1, 2, 4, 8, ... + public bool IsFlagCollection + { + get + { + // It seems that all flag collections contain "Mask" in their names. + // This looks like a heuristic, but it holds 100% in practice + // (checked all enums to make sure). + return Name.Contains("Mask"); + } + } + #region public string Name public string Name @@ -87,14 +102,19 @@ namespace Bind.Structures #endregion + #region ConstantCollection + Dictionary _constant_collection = new Dictionary(); public IDictionary ConstantCollection { get { return _constant_collection; } - //set { _constant_collection = value; } } + #endregion + + #region TranslateName + public static string TranslateName(string name) { if (Utilities.Keywords.Contains(name)) @@ -137,6 +157,10 @@ namespace Bind.Structures return translator.ToString(); } + #endregion + + #region ToString + public override string ToString() { StringBuilder sb = new StringBuilder(); @@ -149,6 +173,8 @@ namespace Bind.Structures return ret; }); + if (IsFlagCollection) + sb.AppendLine("[Flags]"); sb.AppendLine("public enum " + Name); sb.AppendLine("{"); @@ -163,6 +189,10 @@ namespace Bind.Structures return sb.ToString(); } + + #endregion + + #endregion } #endregion diff --git a/Source/OpenTK/Graphics/GL/GLEnums.cs b/Source/OpenTK/Graphics/GL/GLEnums.cs index e5abd201..1099cafe 100644 --- a/Source/OpenTK/Graphics/GL/GLEnums.cs +++ b/Source/OpenTK/Graphics/GL/GLEnums.cs @@ -25,6 +25,8 @@ // #endregion +using System; + namespace OpenTK.Graphics { #pragma warning disable 1591 @@ -43,6 +45,7 @@ namespace OpenTK.Graphics UnsignedInt = ((int)0X1405), } + [Flags] public enum AttribMask { CurrentBit = ((int)0X00000001), @@ -69,6 +72,7 @@ namespace OpenTK.Graphics AllAttribBits = unchecked((int)0Xffffffff), } + [Flags] public enum ClearBufferMask { DepthBufferBit = ((int)0X00000100), @@ -77,6 +81,7 @@ namespace OpenTK.Graphics ColorBufferBit = ((int)0X00004000), } + [Flags] public enum ClientAttribMask { ClientPixelStoreBit = ((int)0X00000001), @@ -441,6 +446,7 @@ namespace OpenTK.Graphics LineResetToken = ((int)0X0707), } + [Flags] public enum FfdMaskSgix { TextureDeformationBitSgix = ((int)0X00000001), @@ -2804,6 +2810,7 @@ namespace OpenTK.Graphics Ycrcb444Sgix = ((int)0X81bc), } + [Flags] public enum SgisTextureColorMask { TextureColorWritemaskSgis = ((int)0X81ef), @@ -9867,6 +9874,7 @@ namespace OpenTK.Graphics UnsignedNormalized = ((int)0X8c17), } + [Flags] public enum BufferAccessMask { MapReadBit = ((int)0X0001),