void WriteEnums(BindStreamWriter sw, EnumCollection enums, FunctionCollection wrappers) { //sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute //sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments //sw.WriteLine(); if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None) { Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass)); } else { Trace.WriteLine(String.Format("Writing enums to:\t{0}", Settings.EnumsOutput)); } if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None) { if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None && !String.IsNullOrEmpty(Settings.NestedEnumsClass)) { sw.WriteLine("public class Enums"); sw.WriteLine("{"); sw.Indent(); } // Build a dictionary of which functions use which enums var enum_counts = new Dictionary <Enum, List <Function> >(); foreach (var e in enums.Values) { // Initialize the dictionary enum_counts.Add(e, new List <Function>()); } foreach (var wrapper in wrappers.Values.SelectMany(w => w)) { // Add every function to every enum parameter it references foreach (var parameter in wrapper.Parameters.Where(p => p.IsEnum)) { var e = enums[parameter.CurrentType]; var list = enum_counts[e]; list.Add(wrapper); } } foreach (Enum @enum in enums.Values) { if (!Settings.IsEnabled(Settings.Legacy.NoDocumentation)) { // Document which functions use this enum. var functions = enum_counts[@enum] .Select(w => Settings.GLClass + (w.Extension != "Core" ? ("." + w.Extension) : "") + "." + w.TrimmedName) .Distinct(); sw.WriteLine("/// <summary>"); sw.WriteLine(String.Format("/// {0}", functions.Count() >= 3 ? String.Format("Used in {0} and {1} other function{2}", String.Join(", ", functions.Take(2).ToArray()), functions.Count() - 2, functions.Count() - 2 > 1 ? "s" : "") : functions.Count() >= 1 ? String.Format("Used in {0}", String.Join(", ", functions.ToArray())) : "Not used directly.")); sw.WriteLine("/// </summary>"); } if (@enum.IsFlagCollection) { sw.WriteLine("[Flags]"); } sw.WriteLine("public enum " + @enum.Name + " : " + @enum.Type); sw.WriteLine("{"); sw.Indent(); WriteConstants(sw, @enum.ConstantCollection.Values); sw.Unindent(); sw.WriteLine("}"); sw.WriteLine(); } if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None && !String.IsNullOrEmpty(Settings.NestedEnumsClass)) { sw.Unindent(); sw.WriteLine("}"); } } else { // Tao legacy mode: dump all enums as constants in GLClass. foreach (Constant c in enums[Settings.CompleteEnumName].ConstantCollection.Values) { // Print constants avoiding circular definitions if (c.Name != c.Value) { sw.WriteLine(String.Format( "public const int {0} = {2}((int){1});", c.Name.StartsWith(Settings.ConstantPrefix) ? c.Name : Settings.ConstantPrefix + c.Name, Char.IsDigit(c.Value[0]) ? c.Value : c.Value.StartsWith(Settings.ConstantPrefix) ? c.Value : Settings.ConstantPrefix + c.Value, c.Unchecked ? "unchecked" : "")); } else { } } } }
public static bool RequiresSlot(this Delegate d, Settings settings) { double version; Double.TryParse( d.Version, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out version); return !settings.IsEnabled(Settings.Legacy.UseDllImports) || (settings.IsEnabled(Settings.Legacy.UseWindowsCompatibleGL) && version > 1.1) || d.Extension != "Core"; }
void WriteEnums(BindStreamWriter sw, EnumCollection enums, FunctionCollection wrappers) { //sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute //sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments //sw.WriteLine(); if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None) { Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass)); } else { Trace.WriteLine(String.Format("Writing enums to:\t{0}", Settings.EnumsOutput)); } if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None) { if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None && !String.IsNullOrEmpty(Settings.NestedEnumsClass)) { sw.WriteLine("public class Enums"); sw.WriteLine("{"); sw.Indent(); } foreach (Enum @enum in enums.Values) { if (!Settings.IsEnabled(Settings.Legacy.NoDocumentation)) { // Document which functions use this enum. var functions = (from wrapper in wrappers from function in wrapper.Value from param in function.Parameters where param.CurrentType == @enum.Name select Settings.GLClass + (function.Extension != "Core" ? ("." + function.Extension) : "") + "." + function.TrimmedName) .Distinct(); sw.WriteLine("/// <summary>"); sw.WriteLine(String.Format("/// {0}", functions.Count() > 0 ? ("Used in " + String.Join(", ", functions.ToArray())) : "Not used directly.")); sw.WriteLine("/// </summary>"); } if (@enum.IsFlagCollection) { sw.WriteLine("[Flags]"); } sw.WriteLine("public enum " + @enum.Name + " : " + @enum.Type); sw.WriteLine("{"); sw.Indent(); WriteConstants(sw, @enum.ConstantCollection.Values); sw.Unindent(); sw.WriteLine("}"); sw.WriteLine(); } if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None && !String.IsNullOrEmpty(Settings.NestedEnumsClass)) { sw.Unindent(); sw.WriteLine("}"); } } else { // Tao legacy mode: dump all enums as constants in GLClass. foreach (Constant c in enums[Settings.CompleteEnumName].ConstantCollection.Values) { // Print constants avoiding circular definitions if (c.Name != c.Value) { sw.WriteLine(String.Format( "public const int {0} = {2}((int){1});", c.Name.StartsWith(Settings.ConstantPrefix) ? c.Name : Settings.ConstantPrefix + c.Name, Char.IsDigit(c.Value[0]) ? c.Value : c.Value.StartsWith(Settings.ConstantPrefix) ? c.Value : Settings.ConstantPrefix + c.Value, c.Unchecked ? "unchecked" : "")); } else { } } } }