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).
This commit is contained in:
parent
9f6e2bf323
commit
370396ab7f
4 changed files with 43 additions and 11 deletions
|
@ -466,6 +466,10 @@ namespace Bind.GL2
|
||||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, enumsFile)))
|
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, enumsFile)))
|
||||||
{
|
{
|
||||||
WriteLicense(sw);
|
WriteLicense(sw);
|
||||||
|
|
||||||
|
sw.WriteLine("using System;");
|
||||||
|
sw.WriteLine();
|
||||||
|
|
||||||
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
||||||
{
|
{
|
||||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||||
|
|
|
@ -51,16 +51,6 @@ namespace Bind.Structures
|
||||||
{
|
{
|
||||||
get
|
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;
|
return _value;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
|
@ -8,6 +8,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Bind.Structures
|
namespace Bind.Structures
|
||||||
{
|
{
|
||||||
|
@ -77,6 +78,20 @@ namespace Bind.Structures
|
||||||
|
|
||||||
#endregion
|
#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
|
#region public string Name
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
|
@ -87,14 +102,19 @@ namespace Bind.Structures
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region ConstantCollection
|
||||||
|
|
||||||
Dictionary<string, Constant> _constant_collection = new Dictionary<string, Constant>();
|
Dictionary<string, Constant> _constant_collection = new Dictionary<string, Constant>();
|
||||||
|
|
||||||
public IDictionary<string, Constant> ConstantCollection
|
public IDictionary<string, Constant> ConstantCollection
|
||||||
{
|
{
|
||||||
get { return _constant_collection; }
|
get { return _constant_collection; }
|
||||||
//set { _constant_collection = value; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region TranslateName
|
||||||
|
|
||||||
public static string TranslateName(string name)
|
public static string TranslateName(string name)
|
||||||
{
|
{
|
||||||
if (Utilities.Keywords.Contains(name))
|
if (Utilities.Keywords.Contains(name))
|
||||||
|
@ -137,6 +157,10 @@ namespace Bind.Structures
|
||||||
return translator.ToString();
|
return translator.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ToString
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -149,6 +173,8 @@ namespace Bind.Structures
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (IsFlagCollection)
|
||||||
|
sb.AppendLine("[Flags]");
|
||||||
sb.AppendLine("public enum " + Name);
|
sb.AppendLine("public enum " + Name);
|
||||||
sb.AppendLine("{");
|
sb.AppendLine("{");
|
||||||
|
|
||||||
|
@ -163,6 +189,10 @@ namespace Bind.Structures
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
//
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
namespace OpenTK.Graphics
|
||||||
{
|
{
|
||||||
#pragma warning disable 1591
|
#pragma warning disable 1591
|
||||||
|
@ -43,6 +45,7 @@ namespace OpenTK.Graphics
|
||||||
UnsignedInt = ((int)0X1405),
|
UnsignedInt = ((int)0X1405),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum AttribMask
|
public enum AttribMask
|
||||||
{
|
{
|
||||||
CurrentBit = ((int)0X00000001),
|
CurrentBit = ((int)0X00000001),
|
||||||
|
@ -69,6 +72,7 @@ namespace OpenTK.Graphics
|
||||||
AllAttribBits = unchecked((int)0Xffffffff),
|
AllAttribBits = unchecked((int)0Xffffffff),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum ClearBufferMask
|
public enum ClearBufferMask
|
||||||
{
|
{
|
||||||
DepthBufferBit = ((int)0X00000100),
|
DepthBufferBit = ((int)0X00000100),
|
||||||
|
@ -77,6 +81,7 @@ namespace OpenTK.Graphics
|
||||||
ColorBufferBit = ((int)0X00004000),
|
ColorBufferBit = ((int)0X00004000),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum ClientAttribMask
|
public enum ClientAttribMask
|
||||||
{
|
{
|
||||||
ClientPixelStoreBit = ((int)0X00000001),
|
ClientPixelStoreBit = ((int)0X00000001),
|
||||||
|
@ -441,6 +446,7 @@ namespace OpenTK.Graphics
|
||||||
LineResetToken = ((int)0X0707),
|
LineResetToken = ((int)0X0707),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum FfdMaskSgix
|
public enum FfdMaskSgix
|
||||||
{
|
{
|
||||||
TextureDeformationBitSgix = ((int)0X00000001),
|
TextureDeformationBitSgix = ((int)0X00000001),
|
||||||
|
@ -2804,6 +2810,7 @@ namespace OpenTK.Graphics
|
||||||
Ycrcb444Sgix = ((int)0X81bc),
|
Ycrcb444Sgix = ((int)0X81bc),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum SgisTextureColorMask
|
public enum SgisTextureColorMask
|
||||||
{
|
{
|
||||||
TextureColorWritemaskSgis = ((int)0X81ef),
|
TextureColorWritemaskSgis = ((int)0X81ef),
|
||||||
|
@ -9867,6 +9874,7 @@ namespace OpenTK.Graphics
|
||||||
UnsignedNormalized = ((int)0X8c17),
|
UnsignedNormalized = ((int)0X8c17),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum BufferAccessMask
|
public enum BufferAccessMask
|
||||||
{
|
{
|
||||||
MapReadBit = ((int)0X0001),
|
MapReadBit = ((int)0X0001),
|
||||||
|
|
Loading…
Reference in a new issue