private static void GenerateVbCommands(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { Dictionary <string, bool> serializedCommands = new Dictionary <string, bool>(); Dictionary <string, bool> serializedEnums = new Dictionary <string, bool>(); List <Command> featureVbCommands = new List <Command>(); List <Enumerant> featureVbEnums = new List <Enumerant>(); Console.WriteLine("Testing for VB.Net incompatibilities."); #region Select VB incompatible commands foreach (IFeature feature in ctx.Registry.AllFeatures(ctx)) { foreach (FeatureCommand featureCommand in feature.Requirements) { if (featureCommand.Api != null && !ctx.IsSupportedApi(featureCommand.Api)) { Console.WriteLine("Skip command: API {1} not supported", featureCommand.Api); continue; } foreach (FeatureCommand.Item featureCommandItem in featureCommand.Commands) { Command command = ctx.Registry.GetCommand(featureCommandItem.Name); Debug.Assert(command != null); if (serializedCommands.ContainsKey(command.Prototype.Name)) { continue; } serializedCommands.Add(command.Prototype.Name, true); // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) { continue; } // Do not generate command with aliases if (command.Alias != null) { continue; } // Do not generate methods not conflicting with enumerations having the same name with different case Enumerant enumInConflict = ctx.Registry.GetEnumerantNoCase(command.GetImplementationName(ctx)); if (enumInConflict == null) { continue; } // VB.Net command featureVbCommands.Add(command); if (serializedEnums.ContainsKey(enumInConflict.Name)) { continue; } serializedEnums.Add(enumInConflict.Name, true); // VB.Net enum featureVbEnums.Add(enumInConflict); } } } #endregion string path = Path.Combine(BasePath, String.Format("{0}/{1}.Vb.cs", _OutputBasePath, ctx.Class)); if (featureVbCommands.Count > 0) { Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { RegistryProcessor.GenerateLicensePreamble(sw); // Warning CS1734 XML comment on 'method' has a paramref tag for 'param', but there is no parameter by that name // sw.WriteLine("#pragma warning disable 1734"); // sw.WriteLine(); sw.WriteLine("#pragma warning disable 649, 1572, 1573"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Class for scoping those methods conflicting with other fields/enums."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // VB Commands class sw.WriteLine("public static class VB"); sw.WriteLine("{"); sw.Indent(); // VB Function implementations foreach (Command command in featureVbCommands) { command.GenerateImplementations(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); // VB Commands class sw.WriteLine(); sw.WriteLine("public static class VBEnum"); sw.WriteLine("{"); sw.Indent(); // VB Function implementations foreach (Enumerant enumerant in featureVbEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } } else { if (File.Exists(path)) { File.Delete(path); } } }
/// <summary> /// Generate all required files for OpenGL C# bindings. /// </summary> /// <param name="glRegistryProcessor"> /// The <see cref="RegistryProcessor"/> that actually process the OpenGL specification. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> that actually parses the OpenGL specification. /// </param> private static void GenerateCommandsAndEnums(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { Dictionary <string, bool> serializedCommands = new Dictionary <string, bool>(); Dictionary <string, bool> serializedEnums = new Dictionary <string, bool>(); glRegistryProcessor.GenerateStronglyTypedEnums(ctx, Path.Combine(BasePath, String.Format("{0}/{1}.Enums.cs", _OutputBasePath, ctx.Class)), null); #region By features and extensions foreach (IFeature feature in ctx.Registry.AllFeatures(ctx)) { List <Command> featureCommands = new List <Command>(); List <Enumerant> featureEnums = new List <Enumerant>(); #region Select enumerants and commands foreach (FeatureCommand featureCommand in feature.Requirements) { if (featureCommand.Api != null && !ctx.IsSupportedApi(featureCommand.Api)) { Console.WriteLine("Skip command: API {1} not supported", featureCommand.Api); continue; } foreach (FeatureCommand.Item featureCommandItem in featureCommand.Commands) { Command command = ctx.Registry.GetCommand(featureCommandItem.Name); Debug.Assert(command != null); if (serializedCommands.ContainsKey(command.Prototype.Name)) { continue; } serializedCommands.Add(command.Prototype.Name, true); // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) { continue; } // Do not generate command with aliases if (command.Alias != null) { continue; } featureCommands.Add(command); } foreach (FeatureCommand.Item featureEnumItem in featureCommand.Enums) { Enumerant enumerant = ctx.Registry.GetEnumerant(featureEnumItem.Name); if (enumerant == null) { continue; } if (serializedEnums.ContainsKey(enumerant.Name)) { continue; } serializedEnums.Add(enumerant.Name, true); // Do not generate enumerant if it has an alias if (enumerant.EnumAlias != null) { continue; } featureEnums.Add(enumerant); } } #endregion if ((featureCommands.Count == 0) && (featureEnums.Count == 0)) { // No commands and no enumerations: remove file if existing string sourceFilePath = GetFeatureFilePath(feature, ctx); if (File.Exists(sourceFilePath)) { File.Delete(sourceFilePath); } // Next... continue; } glRegistryProcessor.GenerateCommands(ctx, GetFeatureFilePath(feature, ctx), delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", featureEnums.Count); foreach (Enumerant enumerant in featureEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", featureCommands.Count); foreach (Command command in featureCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } if (featureCommands.Count > 0) { GenerateCommandsImports(cctx, sw, featureCommands); sw.WriteLine(); } if (featureCommands.Count > 0) { GenerateCommandsDelegates(cctx, sw, featureCommands); } }); } #endregion #region Orphans List <Command> orphanCommands = new List <Command>(); List <Enumerant> orphanEnums = new List <Enumerant>(); foreach (Command command in ctx.Registry.Commands) { if (serializedCommands.ContainsKey(command.Prototype.Name)) { continue; } // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) { continue; } // Do not generate command with aliases if (command.Alias != null) { continue; } orphanCommands.Add(command); } foreach (Enumerant enumerant in ctx.Registry.Enumerants) { if (serializedEnums.ContainsKey(enumerant.Name)) { continue; } orphanEnums.Add(enumerant); } string orphanFile = Path.Combine(BasePath, String.Format("{0}/{1}.Orphans.cs", _OutputBasePath, ctx.Class)); if ((orphanCommands.Count != 0) || (orphanEnums.Count != 0)) { glRegistryProcessor.GenerateCommands(ctx, orphanFile, delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", orphanEnums.Count); foreach (Enumerant enumerant in orphanEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", orphanCommands.Count); foreach (Command command in orphanCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); } else { if (File.Exists(orphanFile)) { File.Delete(orphanFile); } } #endregion }