public void GenerateLogMap(RegistryContext ctx, string path) { OpenGL.KhronosLogMap logMap = new OpenGL.KhronosLogMap(); List <OpenGL.KhronosLogMap.Command> logCommands = new List <OpenGL.KhronosLogMap.Command>(); foreach (Command command in _Registry.Commands) { if (command.Parameters.Exists(GenerateLogMap_IsEnumParameter) == false) { continue; } OpenGL.KhronosLogMap.Command logCommand = new OpenGL.KhronosLogMap.Command(); List <OpenGL.KhronosLogMap.CommandParam> logCommandParams = new List <OpenGL.KhronosLogMap.CommandParam>(); foreach (CommandParameter commandParameter in command.Parameters) { OpenGL.KhronosLogMap.CommandParam logParameter = new OpenGL.KhronosLogMap.CommandParam(); logParameter.Name = commandParameter.Name; logParameter.Flags = OpenGL.KhronosLogCommandParameterFlags.None; if (GenerateLogMap_IsEnumParameter(commandParameter)) { logParameter.Flags |= OpenGL.KhronosLogCommandParameterFlags.Enum; } logCommandParams.Add(logParameter); } logCommand.Name = command.Prototype.Name; logCommand.Params = logCommandParams.ToArray(); logCommands.Add(logCommand); } logMap.Commands = logCommands.ToArray(); OpenGL.KhronosLogMap.Save(path, logMap); }
/// <summary> /// Get the API command summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <returns> /// It returns the summary relative to the command <paramref name="command"/>. /// </returns> public override string QueryCommandSummary(RegistryContext ctx, Command command) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (command == null) { throw new ArgumentNullException(nameof(command)); } string commandSummary = $"Binding for {command.Prototype.Name}."; if (_Xml != null) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); XmlNode xmlIdentifier = _Xml.SelectSingleNode("/refentry/refnamediv/refpurpose", nsmgr); if (xmlIdentifier != null) { commandSummary = GetDocumentationLine(xmlIdentifier.InnerText, _TranformCommandMan, ctx); } } return(commandSummary); }
private static void GenerateCommandsImports(RegistryContext ctx, SourceStreamWriter sw, IEnumerable <Command> commands) { // Write delegates switch (ctx.Class) { // Glx and Wgl classes exposes public unsafe native methods: let UnsafeNativeMethods be public (note: automatically // generated members have internal scope) case "Glx": case "Wgl": sw.WriteLine("public unsafe static partial class UnsafeNativeMethods"); break; default: sw.WriteLine("internal unsafe static partial class UnsafeNativeMethods"); break; } sw.WriteLine("{"); sw.Indent(); foreach (Command command in commands) { if ((command.Flags & CommandFlags.Disable) != 0) { continue; } command.GenerateImport(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); }
/// <summary> /// Generate log map information, in XML. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding the OpenGL specification information. /// </param> /// <param name="path"> /// A <see cref="String"/> that specifies the log map file path. /// </param> public void GenerateLogMap(RegistryContext ctx, string path) { KhronosLogMap logMap = new KhronosLogMap(); List <KhronosLogMap.Command> logCommands = new List <KhronosLogMap.Command>(); foreach (Command command in _Registry.Commands) { if (command.Parameters.Exists(delegate(CommandParameter item) { return(item.IsEnum); }) == false) { continue; } KhronosLogMap.Command logCommand = new KhronosLogMap.Command(); List <KhronosLogMap.CommandParam> logCommandParams = new List <KhronosLogMap.CommandParam>(); foreach (CommandParameter commandParameter in command.Parameters) { KhronosLogMap.CommandParam logParameter = new KhronosLogMap.CommandParam(); logParameter.Name = commandParameter.Name; logParameter.Flags = KhronosLogCommandParameterFlags.None; if (commandParameter.IsEnum) { logParameter.Flags |= KhronosLogCommandParameterFlags.Enum; } logCommandParams.Add(logParameter); } logCommand.Name = command.Prototype.Name; logCommand.Params = logCommandParams.ToArray(); logCommands.Add(logCommand); } logMap.Commands = logCommands.ToArray(); KhronosLogMap.Save(path, logMap); }
/// <summary> /// Get the API command parameter summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <param name="commandParameter"> /// The relative <see cref="CommandParameter"/> /// </param> /// <returns> /// It returns the summary relative to the command <paramref name="commandParameter"/>. /// </returns> public override string QueryCommandParamSummary(RegistryContext ctx, Command command, CommandParameter commandParameter) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (command == null) { throw new ArgumentNullException(nameof(command)); } if (commandParameter == null) { throw new ArgumentNullException(nameof(commandParameter)); } string paramSummary = $"A <see cref=\"T:{commandParameter.GetImplementationType(ctx, command)}\"/>."; if (_Xml != null) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); string xpath = $"/refentry/refsect1[@id='parameters']/variablelist/varlistentry[term/parameter/text() = '{commandParameter.ImplementationNameRaw}']/listitem/para"; XmlNode xmlIdentifier = _Xml.SelectSingleNode(xpath, nsmgr); if (xmlIdentifier != null) { paramSummary = GetDocumentationLine(xmlIdentifier.InnerXml, _TranformCommandMan, ctx); } } return(paramSummary); }
/// <summary> /// Get the API command "see also" references. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <returns> /// It returns a <see cref="IEnumerable{String}"/> that specifies the command "see also" references. /// </returns> public override IEnumerable <string> QueryCommandSeeAlso(RegistryContext ctx, Command command) { if (_Xml == null) { yield break; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); XmlNodeList xmlNodes = _Xml.SelectNodes("/refentry/refsect1[@id='seealso']/para/citerefentry/refentrytitle", nsmgr); if (xmlNodes == null) { yield break; } foreach (XmlNode node in xmlNodes) { string implementationName = ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText); if (implementationName != string.Empty) { yield return ($"<seealso cref=\"{ctx.Class}.{ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText).Substring(ctx.Class.Length)}\"/>"); } else { yield return($"<seealso cref=\"{ctx.Class}.{node.InnerText}\"/>"); } } }
/// <summary> /// Get the API command remarks. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <returns> /// It returns a <see cref="IEnumerable{String}"/> that specifies the command remarks paragraphs. /// </returns> public override IEnumerable <string> QueryCommandRemarks(RegistryContext ctx, Command command) { if (ctx.Class == "Glx") { yield break; // Bad semantic for GLX errors: no exception is actually thrown } if (_Xml == null) { yield break; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); nsmgr.AddNamespace("x", "http://docbook.org/ns/docbook"); XmlNodeList xmlNodes = _Xml.SelectNodes("/x:refentry/x:refsect1[@xml:id='description']/x:para", nsmgr); if (xmlNodes == null || xmlNodes.Count <= 0) { yield break; } foreach (XmlNode node in xmlNodes) { yield return(GetDocumentationLine(node.InnerXml, _TranformCommandMan, ctx)); } }
public void GenerateCommands(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } if ((filter != null) && (_Registry.Commands.FindIndex(delegate(Command item) { return(filter(item)); }) < 0)) { return; } GenerateCommands(ctx, path, (CommandSerializerDelegate) delegate(RegistryContext cctx, SourceStreamWriter sw) { foreach (Command command in _Registry.Commands) { if ((filter != null) && (filter(command) == false)) { continue; } command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); }
/// <summary> /// Application entry point. /// </summary> /// <param name="args"> /// The command line invocation arguments. /// </param> static void Main(string[] args) { RegistryContext ctx; RegistryProcessor glRegistryProcessor; RegistryDocumentation.CreateLog(); // OpenGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--gl"); }) >= 0)) { ctx = new RegistryContext("Gl", Path.Combine(BasePath, "GLSpecs/gl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } #if false // OpenGL ES if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--gles"); }) >= 0)) { ctx = new RegistryContext("Gles", Path.Combine(BasePath, "GLSpecs/gl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); } #endif // OpenGL for Windows if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--wgl"); }) >= 0)) { ctx = new RegistryContext("Wgl", Path.Combine(BasePath, "GLSpecs/wgl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } // OpenGL for Unix if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--xgl"); }) >= 0)) { ctx = new RegistryContext("Glx", Path.Combine(BasePath, "GLSpecs/glx.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } // EGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--egl"); }) >= 0)) { ctx = new RegistryContext("Egl", Path.Combine(BasePath, "GLSpecs/egl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } RegistryDocumentation.CloseLog(); }
/// <summary> /// Get the API enumeration summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="enumerant"> /// The relative <see cref="Enumerant"/>. /// </param> /// <returns> /// It returns the summary relative to <paramref name="enumerant"/>. /// </returns> public override string QueryEnumSummary(RegistryContext ctx, Enumerant enumerant) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (enumerant == null) { throw new ArgumentNullException(nameof(enumerant)); } if (_Xml != null) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); nsmgr.AddNamespace("x", "http://docbook.org/ns/docbook"); XmlNodeList enumerants = _Xml.SelectNodes("/x:refentry/x:refsect1[@xml:id='description']/x:variablelist/x:varlistentry", nsmgr); foreach (XmlNode xmlNode in enumerants) { XmlNode enumerantId = xmlNode.SelectSingleNode("x:term/x:constant", nsmgr); if (enumerantId == null || enumerantId.InnerText != enumerant.Name) { continue; } XmlNode enumerantDoc = xmlNode.SelectSingleNode("x:listitem", nsmgr); if (enumerantDoc == null) { continue; } if (!Regex.IsMatch(enumerantId.InnerText, "^(GL_|WGL_|GLX_|EGL_).*")) { continue; } XmlNodeList xmlIdentifiers = _Xml.DocumentElement.SelectNodes("/x:refentry/x:refsynopsisdiv/x:funcsynopsis/x:funcprototype/x:funcdef/x:function", nsmgr); string functionName = string.Empty; if (xmlIdentifiers.Count > 0) { Command commandRef = ctx.Registry.GetCommand(xmlIdentifiers[0].InnerXml); functionName = $"{ctx.Class}.{commandRef.GetImplementationName(ctx)}: "; } return(functionName + GetDocumentationLine(enumerantDoc.InnerXml, _TranformEnumerantMan, ctx)); } return(base.QueryEnumSummary(ctx, enumerant)); } else { return(base.QueryEnumSummary(ctx, enumerant)); } }
/// <summary> /// Application entry point. /// </summary> /// <param name="args"> /// The command line invocation arguments. /// </param> static void Main(string[] args) { RegistryContext ctx; RegistryProcessor glRegistryProcessor; RegistryDocumentation.CreateLog(); // OpenGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return (item == "--gl"); }) >= 0)) { ctx = new RegistryContext("Gl", Path.Combine(BasePath, "GLSpecs/gl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } #if false // OpenGL ES if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return (item == "--gles"); }) >= 0)) { ctx = new RegistryContext("Gles", Path.Combine(BasePath, "GLSpecs/gl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); } #endif // OpenGL for Windows if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return (item == "--wgl"); }) >= 0)) { ctx = new RegistryContext("Wgl", Path.Combine(BasePath, "GLSpecs/wgl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } // OpenGL for Unix if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return (item == "--xgl"); }) >= 0)) { ctx = new RegistryContext("Glx", Path.Combine(BasePath, "GLSpecs/glx.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } // EGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return (item == "--egl"); }) >= 0)) { ctx = new RegistryContext("Egl", Path.Combine(BasePath, "GLSpecs/egl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); } RegistryDocumentation.CloseLog(); }
/// <summary> /// Generate source code file. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding the OpenGL specification information. /// </param> /// <param name="path"> /// A <see cref="String"/> that specifies the source code file path. /// </param> /// <param name="filter"></param> public void GenerateSource(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) { throw new ArgumentNullException(nameof(path)); } Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { 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("// ReSharper disable RedundantUsingDirective"); 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("using Khronos;"); sw.WriteLine(); sw.WriteLine("// ReSharper disable CheckNamespace"); sw.WriteLine("// ReSharper disable InconsistentNaming"); sw.WriteLine("// ReSharper disable JoinDeclarationAndInitializer"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Get the API command summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <returns> /// It returns the summary relative to the command <paramref name="command"/>. /// </returns> public override string QueryCommandSummary(RegistryContext ctx, Command command) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (command == null) { throw new ArgumentNullException(nameof(command)); } return($"Binding for {command.Prototype.Name}."); }
/// <summary> /// Get the API enumeration summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="enumerant"> /// The relative <see cref="Enumerant"/>. /// </param> /// <returns> /// It returns the summary relative to <paramref name="enumerant"/>. /// </returns> public override string QueryEnumSummary(RegistryContext ctx, Enumerant enumerant) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (enumerant == null) { throw new ArgumentNullException(nameof(enumerant)); } return($"Value of {enumerant.Name} symbol{(enumerant.IsDeprecated ? " (DEPRECATED)" : string.Empty)}."); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="filter"></param> public void GenerateEnums(RegistryContext ctx, string path, EnumerantFilterDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } List <Enumerant> enumerants = _Registry.Enumerants; if ((filter != null) && (enumerants.FindIndex(delegate(Enumerant item) { return(filter(item)); }) < 0)) { return; } Console.WriteLine("Generate registry enums to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in _Registry.Enumerants) { if ((filter != null) && (filter(enumerant) == false)) { continue; } enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Generate source code file for enumerations. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding the OpenGL specification information. /// </param> /// <param name="path"> /// A <see cref="String"/> that specifies the source code file path. /// </param> public void GenerateStronglyTypedEnums(RegistryContext ctx, string path) { if (path == null) { throw new ArgumentNullException("path"); } if (_Registry.Groups.Count == 0) { return; } Console.WriteLine("Generate registry enums (strognly typed) to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("// Disable \"'token' is obsolete\" warnings"); sw.WriteLine("#pragma warning disable 618"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("using Khronos;"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); // Sort enumerations by name List <EnumerantGroup> glGroups = new List <EnumerantGroup>(_Registry.Groups); glGroups.Sort(delegate(EnumerantGroup x, EnumerantGroup y) { return(x.Name.CompareTo(y.Name)); }); foreach (EnumerantGroup enumerantGroup in glGroups) { enumerantGroup.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); } }
/// <summary> /// Get the API command parameter summary. /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <param name="commandParameter"> /// The relative <see cref="CommandParameter"/> /// </param> /// <returns> /// It returns the summary relative to the command <paramref name="commandParameter"/>. /// </returns> public override string QueryCommandParamSummary(RegistryContext ctx, Command command, CommandParameter commandParameter) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (command == null) { throw new ArgumentNullException(nameof(command)); } if (commandParameter == null) { throw new ArgumentNullException(nameof(commandParameter)); } return($"A <see cref=\"T:{commandParameter.GetImplementationType(ctx, command)}\"/>."); }
/// <summary> /// Get the API command associated "gets". /// </summary> /// <param name="ctx"> /// The <see cref="RegistryContext"/> holding information about the generated class. /// </param> /// <param name="command"> /// The relative <see cref="Command"/>. /// </param> /// <returns> /// It returns a <see cref="IEnumerable{String}"/> that specifies the command "get" paragraphs. /// </returns> public override IEnumerable <string> QueryCommandGets(RegistryContext ctx, Command command) { if (_Xml != null) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); XmlNodeList xmlNodes = _Xml.SelectNodes("/refentry/refsect1[@id='associatedgets']/para", nsmgr); if (xmlNodes == null || xmlNodes.Count <= 0) { yield break; } foreach (XmlNode node in xmlNodes) { yield return(GetDocumentationLine(node.InnerXml, _TranformCommandMan, ctx)); } } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="filter"></param> public void GenerateEnums(RegistryContext ctx, string path, EnumerantFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); List<Enumerant> enumerants = mRegistry.Enumerants; if ((filter != null) && (enumerants.FindIndex(delegate(Enumerant item) { return (filter(item)); }) < 0)) return; Console.WriteLine("Generate registry enums to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in mRegistry.Enumerants) { if ((filter != null) && (filter(enumerant) == false)) continue; enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateStronglyTypedEnums(RegistryContext ctx, string path, EnumerantGroupFilterDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } if (_Registry.Groups.Count == 0) { return; } Console.WriteLine("Generate registry enums (strognly typed) to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("// Disable \"'token' is obsolete\" warnings"); sw.WriteLine("#pragma warning disable 618"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); foreach (EnumerantGroup enumerantGroup in _Registry.Groups) { if ((filter != null) && (filter(enumerantGroup) == false)) { continue; } enumerantGroup.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); } }
private static void GenerateCommandsDelegates(RegistryContext ctx, SourceStreamWriter sw, IEnumerable <Command> commands) { sw.WriteLine("internal unsafe static partial class Delegates"); sw.WriteLine("{"); sw.Indent(); foreach (Command command in commands) { if ((command.Flags & CommandFlags.Disable) != 0) { continue; } command.GenerateDelegate(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); }
public void GenerateCommands(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { 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("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Get the path of the source file defining feature requirement. /// </summary> /// <param name="feature"> /// The <see cref="IFeature"/> that specifies the OpenGL feature. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> that actually parses the OpenGL specification. /// </param> /// <returns> /// It returns the relative path of the file defining <paramref name="feature"/> requirements. /// </returns> private static string GetFeatureFilePath(IFeature feature, RegistryContext ctx) { string path = String.Format("{0}/{1}.{2}.cs", _OutputBasePath, ctx.Class, feature.Name.Substring(ctx.Class.Length + 1)); string featureName = feature.Name.Substring(ctx.Class.Length + 1); int separatorIndex = featureName.IndexOf('_'); if (separatorIndex >= 0) { string ext = featureName.Substring(0, separatorIndex); if (ctx.ExtensionsDictionary.HasWord(ext)) { string extensionDir = Path.Combine(BasePath, String.Format("{0}/{1}", _OutputBasePath, ext)); if (!Directory.Exists(extensionDir)) { Directory.CreateDirectory(extensionDir); } path = String.Format("{3}/{2}/{0}.{1}.cs", ctx.Class, featureName, ext, _OutputBasePath); } } return(Path.Combine(BasePath, path)); }
public static string GetCamelCase(RegistryContext ctx, string token) { if (token == null) { throw new ArgumentNullException(nameof(token)); } StringBuilder sb = new StringBuilder(token.Length); string[] tokens = Regex.Split(token, "_"); string extensionName = null; int camelTokensCount = tokens.Length; if (camelTokensCount > 1 && ctx.ExtensionsDictionary.HasWord(tokens[tokens.Length - 1])) { camelTokensCount -= 1; extensionName = tokens[tokens.Length - 1]; } for (int i = 0; i < camelTokensCount; i++) { string word = tokens[i]; if (word.Length == 0) { continue; } sb.Append(Char.ToUpper(word[0]) + word.Substring(1).ToLower()); } if (extensionName != null) { sb.Append(extensionName); } return(GetLegalCsField(sb.ToString())); }
/// <summary> /// Get the path of the source file defining feature requirement. /// </summary> /// <param name="feature"> /// The <see cref="IFeature"/> that specifies the OpenGL feature. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> that actually parses the OpenGL specification. /// </param> /// <returns> /// It returns the relative path of the file defining <paramref name="feature"/> requirements. /// </returns> private static string GetFeatureFilePath(IFeature feature, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.{1}.cs", ctx.Class, feature.Name.Substring(ctx.Class.Length + 1)); string featureName = feature.Name.Substring(ctx.Class.Length + 1); int separatorIndex = featureName.IndexOf('_'); if (separatorIndex >= 0) { string ext = featureName.Substring(0, separatorIndex); if (ctx.ExtensionsDictionary.HasWord(ext)) { string extensionDir = Path.Combine(BasePath, String.Format("OpenGL.NET/{0}", ext)); if (!Directory.Exists(extensionDir)) Directory.CreateDirectory(extensionDir); path = String.Format("OpenGL.NET/{2}/{0}.{1}.cs", ctx.Class, featureName, ext); } } return (Path.Combine(BasePath, path)); }
private static void GenerateVersionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.Versions.cs", ctx.Class); Console.WriteLine("Generate version support class to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("#region Known Versions Constants"); sw.WriteLine(); foreach (Feature featureVersion in ctx.Registry.Features) { if (featureVersion.Number == null) continue; // Determine version value (support up to 3 version numbers) Match versionMatch = Regex.Match(featureVersion.Number, @"(?<Major>\d+)\.(?<Minor>\d+)(\.(?<Rev>\d+))?"); if (versionMatch.Success == false) continue; int versionMajor = Int32.Parse(versionMatch.Groups["Major"].Value); int versionMinor = Int32.Parse(versionMatch.Groups["Minor"].Value); int versionRev = versionMatch.Groups["Rev"].Success ? Int32.Parse(versionMatch.Groups["Rev"].Value) : 0; int versionValue = versionMajor * 100 + versionMinor * 10 + versionRev; // Determine version name string versionName = String.Format("Version_{0}", versionValue); if (featureVersion.IsEsVersion) versionName = String.Format("Version_{0}ES", versionValue); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Version for {0} API.", SpecificationStyle.GetKhronosVersionHumanReadable(featureVersion.Name)); sw.WriteLine("/// </summary>"); sw.WriteLine("public const int {0} = {1};", versionName, versionValue); sw.WriteLine(); } sw.WriteLine("#endregion"); sw.WriteLine(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public override string GetDocumentation(RegistryContext ctx, XslCompiledTransform transform) { Command commandRef = ctx.Registry.GetCommand(CommandRef); StringBuilder doc = new StringBuilder(); doc.AppendFormat("{0}.{1}: ", ctx.Class, commandRef.GetImplementationName(ctx)); List<string> periods = SplitDocumentationPeriods(EnumDescriptionNode.InnerXml); for (int i = 0; (i < 1) && (i < (periods.Count - 1)); i++) { string documentationLine = GetDocumentationLine(periods[i], transform, ctx); if (documentationLine.Length == 0) continue; doc.AppendFormat("{0}", GetDocumentationLine(periods[i], transform, ctx)); } return (doc.ToString()); }
private static void GenerateExtensionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("{0}/{1}.Extensions.cs", _OutputBasePath, ctx.Class); Console.WriteLine("Generate registry khronosExtensions to {0}.", path); SortedList <int, List <IFeature> > khronosExtensions = new SortedList <int, List <IFeature> >(); SortedList <int, List <IFeature> > vendorExtensions = new SortedList <int, List <IFeature> >(); foreach (IFeature feature in ctx.Registry.Extensions) { SortedList <int, List <IFeature> > extensionDict; List <IFeature> extensionFeatures; if (Extension.IsArbVendor(feature.Name)) { extensionDict = khronosExtensions; } else { extensionDict = vendorExtensions; } int index = ExtensionIndices.GetIndex(feature.Name); if (extensionDict.TryGetValue(index, out extensionFeatures) == false) { extensionFeatures = new List <IFeature>(); extensionDict.Add(index, extensionFeatures); } extensionFeatures.Add(feature); } using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Extension support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class Extensions : ExtensionsCollection"); sw.WriteLine("{"); sw.Indent(); foreach (KeyValuePair <int, List <IFeature> > pair in khronosExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) { if (feature.Api != null && feature.Api != ctx.Class.ToLower()) { sw.WriteLine("[Extension(\"{0}\", Api = \"{1}\")]", feature.Name, feature.Api); } else { sw.WriteLine("[Extension(\"{0}\")]", feature.Name); } } Extension mainExtension = (Extension)mainFeature; if (String.IsNullOrEmpty(mainExtension.Supported) == false) { sw.WriteLine("[ExtensionSupport(\"{0}\")]", mainExtension.Supported); } sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } foreach (KeyValuePair <int, List <IFeature> > pair in vendorExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) { if (feature.Api != null && feature.Api != ctx.Class.ToLower()) { sw.WriteLine("[Extension(\"{0}\", Api = \"{1}\")]", feature.Name, feature.Api); } else { sw.WriteLine("[Extension(\"{0}\")]", feature.Name); } } sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Translate the XHTML documentation using a <see cref="XslCompiledTransform"/>. /// </summary> /// <param name="documentation"> /// The XHTML documentation to be translated. /// </param> /// <param name="transform"> /// The <see cref="XslCompiledTransform"/> defining the transformation process. /// </param> /// <returns> /// It returns <paramref name="documentation"/> processed with <paramref name="transform"/>. /// </returns> private static string ProcessXmlDocumentation(string documentation, XslCompiledTransform transform, RegistryContext ctx) { string transformedXml; using (StringWriter sw = new StringWriter()) { XsltArgumentList xsltArgs = new XsltArgumentList(); xsltArgs.AddParam("class", String.Empty, ctx.Class); XmlDocument xmlDocumentation = new XmlDocument(); StringBuilder xmlBulder = new StringBuilder(); xmlBulder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); xmlBulder.Append("<documentation>"); xmlBulder.Append(documentation); xmlBulder.Append("</documentation>"); xmlDocumentation.LoadXml(xmlBulder.ToString()); transform.Transform(xmlDocumentation.DocumentElement.CreateNavigator(), xsltArgs, sw); transformedXml = sw.ToString(); // Untag elements transformedXml = transformedXml.Replace("see_cref", "see cref"); transformedXml = transformedXml.Replace("paramref_name", "paramref name"); } return (transformedXml); }
/// <summary> /// Generate a <see cref="Command"/> documentation using the OpenGL 4 manual. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> public static void GenerateDocumentation(SourceStreamWriter sw, RegistryContext ctx, Enumerant enumerant) { StringBuilder sb = new StringBuilder(); // GL4 documentation if (GenerateDocumentation_GL4(sw, ctx, enumerant)) return; // GL2 documentation if (GenerateDocumentation_GL2(sw, ctx, enumerant)) return; // GL4 documentation if (GenerateDocumentation_EGL(sw, ctx, enumerant)) return; // Fallback (generic documentation) sw.WriteLine("/// <summary>"); sw.WriteLine("/// Value of {0} symbol{1}.", enumerant.Name, enumerant.IsDeprecated ? " (DEPRECATED)" : String.Empty); sw.WriteLine("/// </summary>"); GenerateDocumentation_Remarks(sw, ctx, enumerant); }
private static void GenerateVersionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("{0}/{1}.Versions.cs", _OutputBasePath, ctx.Class); Console.WriteLine("Generate version support class to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("#region Known Versions Constants"); sw.WriteLine(); foreach (Feature featureVersion in ctx.Registry.Features) { if (featureVersion.Number == null) { continue; } // Determine version value (support up to 3 version numbers) Match versionMatch = Regex.Match(featureVersion.Number, @"(?<Major>\d+)\.(?<Minor>\d+)(\.(?<Rev>\d+))?"); if (versionMatch.Success == false) { continue; } int versionMajor = Int32.Parse(versionMatch.Groups["Major"].Value); int versionMinor = Int32.Parse(versionMatch.Groups["Minor"].Value); int versionRev = versionMatch.Groups["Rev"].Success ? Int32.Parse(versionMatch.Groups["Rev"].Value) : 0; int versionValue = versionMajor * 100 + versionMinor * 10 + versionRev; // Determine version/api name string versionName = String.Format("Version_{0}", versionValue); string api = ctx.Class; if (featureVersion.IsEsVersion) { versionName = String.Format("Version_{0}_ES", versionValue); switch (versionMajor) { case 1: api = "Gles1"; break; case 2: default: api = "Gles2"; break; } } else if (featureVersion.IsScVersion) { versionName = String.Format("Version_{0}_SC", versionValue); api = "Glsc2"; } sw.WriteLine("/// <summary>"); sw.WriteLine("/// Version for {0} API.", SpecificationStyle.GetKhronosVersionHumanReadable(featureVersion.Name)); sw.WriteLine("/// </summary>"); if (versionRev != 0) { sw.WriteLine("public static readonly KhronosVersion {0} = new KhronosVersion({1}, {2}, {3}, KhronosVersion.Api{4});", versionName, versionMajor, versionMinor, versionRev, api); } else { sw.WriteLine("public static readonly KhronosVersion {0} = new KhronosVersion({1}, {2}, KhronosVersion.Api{3});", versionName, versionMajor, versionMinor, api); } sw.WriteLine(); } sw.WriteLine("#endregion"); sw.WriteLine(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Generate a <see cref="Command"/> documentation using the OpenGL 2 manual. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> public static bool GenerateDocumentation_GL2(SourceStreamWriter sw, RegistryContext ctx, Command command, bool fail, List<CommandParameter> commandParams) { XmlDocument xml = null; XmlElement root = null; XmlNodeList xmlNodes; XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); if (sDocumentationMap2.TryGetValue(command.Prototype.Name, out xml)) root = xml.DocumentElement; if (fail && (root == null)) return (false); #region Summary string purpose = String.Format("Binding for {0}.", command.Prototype.Name); if (root != null) { XmlNode xmlIdentifier = xml.SelectSingleNode("/refentry/refnamediv/refpurpose", nsmgr); if (xmlIdentifier != null) purpose = GetDocumentationLine(xmlIdentifier.InnerText, TranformCommandMan2, ctx); } sw.WriteLine("/// <summary>"); sw.WriteLine("/// {0}", purpose); sw.WriteLine("/// </summary>"); #endregion #region Parameters foreach (CommandParameter param in commandParams) { List<string> paramDoc = new List<string>(); // Note: in the case of overloaded methods, some parameters are implicit. Skip the documentation for those parameters. if (param.IsImplicit(ctx, command)) continue; // Default paramDoc.Add(String.Format("A <see cref=\"T:{0}\"/>.", param.GetImplementationType(ctx, command))); if (root != null) { string xpath = String.Format("/refentry/refsect1[@id='parameters']/variablelist/varlistentry[term/parameter/text() = '{0}']/listitem/para", param.Name); XmlNode xmlIdentifier = root.SelectSingleNode(xpath, nsmgr); if (xmlIdentifier != null) paramDoc = GetDocumentationLines(xmlIdentifier.InnerXml, TranformCommandMan2, ctx); } sw.WriteLine("/// <param name=\"{0}\">", param.Name); foreach (string line in paramDoc) sw.WriteLine("/// {0}", line); sw.WriteLine("/// </param>"); } #endregion #region Remarks xmlNodes = root.SelectNodes("/refentry/refsect1[@id='errors']/para", nsmgr); int errorsCount = xmlNodes.Count == 0 ? 0 : xmlNodes.Count; bool requiresRemarks = ((root != null) && (DocumentationLevel == 0)) || (errorsCount > 0); if (requiresRemarks) { sw.WriteLine("/// <remarks>"); #region Description & Associated Gets if (root != null && DocumentationLevel == 0) { xmlNodes = root.SelectNodes("/refentry/refsect1[@id='description']/para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { List<string> para = GetDocumentationLines(node.InnerXml, TranformCommandMan2, ctx); foreach (string paraLine in para) sw.WriteLine("/// {0}", paraLine); } } xmlNodes = root.SelectNodes("/refentry/refsect1[@id='associatedgets']/para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { sw.WriteLine("/// <para>"); sw.WriteLine("/// The associated information is got with the following commands:"); foreach (XmlNode node in xmlNodes) { List<string> para = GetDocumentationLines(node.InnerXml, TranformCommandMan2, ctx); sw.WriteLine("/// - {0}", para[0]); if (para.Count > 1) for (int i = 1; i < para.Count; i++) sw.WriteLine("/// {0}", para[i]); } sw.WriteLine("/// </para>"); } } #endregion if (errorsCount > 0) { if ((command.Flags & CommandFlags.NoGetError) != 0) { sw.WriteLine("/// <para>The exception{0} below won't be thrown; caller must check result manually.</para>", errorsCount > 1 ? "s" : String.Empty); } else { // sw.WriteLine("<para>The exception{0} below are thrown if compiled with DEBUG symbol.</para>", errorsCount > 1 ? "s" : String.Empty); } } sw.WriteLine("/// </remarks>"); } #endregion #region Errors if (root != null) { xmlNodes = root.SelectNodes("/refentry/refsect1[@id='errors']/para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { sw.WriteLine("/// <exception cref=\"InvalidOperationException\">"); StringBuilder sb = new StringBuilder(); sb.Append(GetDocumentationLine(node.InnerXml, TranformCommandMan2, ctx)); List<string> lines = SplitDocumentationLines(sb.ToString()); foreach (string line in lines) sw.WriteLine("/// {0}", line); sw.WriteLine("/// </exception>"); } } } #endregion #region See Also if (root != null) { xmlNodes = root.SelectNodes("/refentry/refsect1[@id='seealso']/para/citerefentry/refentrytitle", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { string implementationName = ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText); if (implementationName != String.Empty) sw.WriteLine("/// <seealso cref=\"{0}.{1}\"/>", ctx.Class, ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText).Substring(ctx.Class.Length)); else sw.WriteLine("/// <seealso cref=\"{0}.{1}\"/>", ctx.Class, node.InnerText); } } } #endregion return (true); }
/// <summary> /// Generate a <see cref="Command"/> documentation, sourced from OpenGL 2 manual, OpenGL 4 manual or a generic one. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> public static void GenerateDocumentation(SourceStreamWriter sw, RegistryContext ctx, Command command, List<CommandParameter> commandParams) { StringBuilder sb = new StringBuilder(); // GL4 documentation try { if (GenerateDocumentation_GL4(sw, ctx, command, true, commandParams)) return; } catch (Exception exception) { sb.AppendFormat("Unable to generate GL4 documentation: {0}", exception.Message); } // GL2 documentation try { if (GenerateDocumentation_GL2(sw, ctx, command, true, commandParams)) return; } catch (Exception exception) { sb.AppendFormat("Unable to generate GL2 documentation: {0}", exception.Message); } // EGL documentation try { if (GenerateDocumentation_EGL(sw, ctx, command, true, commandParams)) return; } catch (Exception exception) { sb.AppendFormat("Unable to generate EGL documentation: {0}", exception.Message); } // Fallback (generic documentation) GenerateDocumentation_GL4(sw, ctx, command, false, commandParams); }
public void GenerateCommandsDelegates(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("#pragma warning disable 649, 1572, 1573"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Delegates // Write delegates sw.WriteLine("internal unsafe static partial class Delegates"); sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) continue; if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateDelegate(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateStronglyTypedEnums(RegistryContext ctx, string path, EnumerantGroupFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); if (mRegistry.Groups.Count == 0) return; Console.WriteLine("Generate registry enums (strognly typed) to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("// Disable \"'token' is obsolete\" warnings"); sw.WriteLine("#pragma warning disable 618"); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); foreach (EnumerantGroup enumerantGroup in mRegistry.Groups) { if ((filter != null) && (filter(enumerantGroup) == false)) continue; enumerantGroup.GenerateSource(sw, ctx); sw.WriteLine(); } sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommandsImports(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Imports // Write delegates switch (ctx.Class) { // Glx and Wgl classes exposes public unsafe native methods: let UnsafeNativeMethods be public (note: automatically // generated members have internal scope) case "Glx": case "Wgl": sw.WriteLine("public unsafe static partial class UnsafeNativeMethods"); break; default: sw.WriteLine("internal unsafe static partial class UnsafeNativeMethods"); break; } sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) continue; if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateImport(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Generate a <see cref="Command"/> documentation using the OpenGL 4 manual. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> public static bool GenerateDocumentation_GL4(SourceStreamWriter sw, RegistryContext ctx, Command command, bool fail, List<CommandParameter> commandParams) { XmlDocument xml = null; XmlElement root = null; XmlNodeList xmlNodes; XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); nsmgr.AddNamespace("x", "http://docbook.org/ns/docbook"); if (sDocumentationMap4.TryGetValue(command.Prototype.Name, out xml)) root = xml.DocumentElement; if (fail && (root == null)) return (false); #region Summary string purpose = String.Format("Binding for {0}.", command.Prototype.Name); if (root != null) { XmlNode xmlIdentifier = xml.SelectSingleNode("/x:refentry/x:refnamediv/x:refpurpose", nsmgr); if (xmlIdentifier != null) purpose = GetDocumentationLine(xmlIdentifier.InnerText, TranformCommandMan4, ctx); } sw.WriteLine("/// <summary>"); sw.WriteLine("/// {0}", purpose); sw.WriteLine("/// </summary>"); #endregion #region Parameters foreach (CommandParameter param in commandParams) { List<string> paramDoc = new List<string>(); // Note: in the case of overloaded methods, some parameters are implicit. Skip the documentation for those parameters. if (param.IsImplicit(ctx, command)) continue; // Default paramDoc.Add(String.Format("A <see cref=\"T:{0}\"/>.", param.GetImplementationType(ctx, command))); if (root != null) { XmlNode xmlIdentifier = null; List<string> paramAliases = new List<string>(); paramAliases.Add(param.Name.ToLowerInvariant()); if (param.Name == "x") paramAliases.Add("v0"); if (param.Name == "y") paramAliases.Add("v1"); if (param.Name == "z") paramAliases.Add("v2"); if (param.Name == "w") paramAliases.Add("v3"); foreach (string paramAlias in paramAliases) { string xpath = String.Format( "/x:refentry/x:refsect1["+ "translate(@xml:id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456790','abcdefghijklmnopqrstuvwxyz123456790')='parameters'" + "]/x:variablelist/x:varlistentry[" + "translate(x:term/x:parameter/text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456790','abcdefghijklmnopqrstuvwxyz123456790')='{0}'" + "]/x:listitem/x:para", param.Name.ToLowerInvariant() ); if ((xmlIdentifier = root.SelectSingleNode(xpath, nsmgr)) != null) break; } if (xmlIdentifier != null) paramDoc = GetDocumentationLines(xmlIdentifier.InnerXml, TranformCommandMan4, ctx); else { if (mWarningLog != null) mWarningLog.WriteLine("Missing documentation: {0}.{1}.{2}", ctx.Class, command.GetImplementationName(ctx), param.Name); Console.WriteLine("Unable to to document {0}.{1}.{2}", ctx.Class, command.GetImplementationName(ctx), param.Name); } } sw.WriteLine("/// <param name=\"{0}\">", param.Name); foreach (string line in paramDoc) sw.WriteLine("/// {0}", line); sw.WriteLine("/// </param>"); } #endregion #region Remarks xmlNodes = null; if (root != null) xmlNodes = root.SelectNodes("/x:refentry/x:refsect1[@xml:id='errors']/x:para", nsmgr); int errorsCount = (xmlNodes == null) || (xmlNodes.Count == 0) ? 0 : xmlNodes.Count; if (ctx.Class == "Glx") errorsCount = 0; // Bad semantic for GLX errors: no exception is actually thrown bool requiresRemarks = ((root != null) && (DocumentationLevel == 0)) || (errorsCount > 0); if (requiresRemarks) { sw.WriteLine("/// <remarks>"); #region Description & Associated Gets if (root != null && DocumentationLevel == 0) { xmlNodes = root.SelectNodes("/x:refentry/x:refsect1[@xml:id='description']/x:para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { List<string> para = GetDocumentationLines(node.InnerXml, TranformCommandMan4, ctx); foreach (string paraLine in para) sw.WriteLine("/// {0}", paraLine); } } xmlNodes = root.SelectNodes("/x:refentry/x:refsect1[@xml:id='associatedgets']/x:para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { sw.WriteLine("/// <para>"); sw.WriteLine("/// The associated information is got with the following commands:"); foreach (XmlNode node in xmlNodes) { List<string> para = GetDocumentationLines(node.InnerXml, TranformCommandMan4, ctx); sw.WriteLine("/// - {0}", para[0]); if (para.Count > 1) for (int i = 1; i < para.Count; i++) sw.WriteLine("/// {0}", para[i]); } sw.WriteLine("/// </para>"); } } #endregion if (errorsCount > 0) { if ((command.Flags & CommandFlags.NoGetError) != 0) { sw.WriteLine("/// <para>The exception{0} below won't be thrown; caller must check result manually.</para>", errorsCount > 1 ? "s" : String.Empty); } else { // sw.WriteLine("<para>The exception{0} below are thrown if compiled with DEBUG symbol.</para>", errorsCount > 1 ? "s" : String.Empty); } } sw.WriteLine("/// </remarks>"); } #endregion #region Errors if (root != null) { xmlNodes = root.SelectNodes("/x:refentry/x:refsect1[@xml:id='errors']/x:para", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { sw.WriteLine("/// <exception cref=\"InvalidOperationException\">"); StringBuilder sb = new StringBuilder(); sb.Append(GetDocumentationLine(node.InnerXml, TranformCommandMan4, ctx)); List<string> lines = SplitDocumentationLines(sb.ToString()); foreach (string line in lines) sw.WriteLine("/// {0}", line); sw.WriteLine("/// </exception>"); } } } #endregion #region See Also if (root != null) { xmlNodes = root.SelectNodes("/x:refentry/x:refsect1[@xml:id='seealso']/x:para/x:citerefentry/x:refentrytitle", nsmgr); if ((xmlNodes != null) && (xmlNodes.Count > 0)) { foreach (XmlNode node in xmlNodes) { string implementationName = ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText); if (implementationName != String.Empty) sw.WriteLine("/// <seealso cref=\"{0}.{1}\"/>", ctx.Class, ctx.WordsDictionary.GetOverridableName(ctx, node.InnerText).Substring(ctx.Class.Length)); else sw.WriteLine("/// <seealso cref=\"{0}.{1}\"/>", ctx.Class, node.InnerText); } } } #endregion return (true); }
/// <summary> /// Generate a <see cref="Command"/> documentation using the Khronos reference pages. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> public static void GenerateDocumentation(this ICollection <IRegistryDocumentation> docs, SourceStreamWriter sw, RegistryContext ctx, Command command, bool fail, List <CommandParameter> commandParams) { if (docs == null || docs.Count == 0) { return; } List <IRegistryDocumentation> validDocs = GetDocRegistries(docs, command); if (validDocs.Count > 0) { if (validDocs.Count > 1) { List <RegistryDocumentationHandler> handlers = new List <RegistryDocumentationHandler>(); foreach (IRegistryDocumentation docRegistry in validDocs) { List <RegistryDocumentationHandler> registryHandlers = docRegistry.GetDocumentationHandlers(command); if (registryHandlers != null) { handlers.AddRange(registryHandlers); } } RegistryDocumentation.GenerateDocumentation(sw, ctx, command, fail, commandParams, handlers); } else { validDocs[0].GenerateDocumentation(sw, ctx, command, fail, commandParams); } } else { RegistryDocumentation.GenerateDocumentation(sw, ctx, command, fail, commandParams, new List <RegistryDocumentationHandler>(new RegistryDocumentationHandler[] { new RegistryDocumentationHandler_Default() })); } }
public override string GetDocumentation(RegistryContext ctx, XslCompiledTransform transform) { Command commandRef = ctx.Registry.GetCommand(CommandRef); StringBuilder doc = new StringBuilder(); doc.AppendFormat("{0}.{1}: ", ctx.Class, commandRef.GetImplementationName(ctx)); string actualDoc = GetDocumentationLine(EnumNode.InnerXml, transform, ctx); actualDoc = SpecificationStyle.EnsureFirstLowerCase(actualDoc); doc.Append(actualDoc); return (doc.ToString()); }
/// <summary> /// Application entry point. /// </summary> /// <param name="args"> /// The command line invocation arguments. /// </param> static void Main(string[] args) { RegistryContext ctx; RegistryProcessor glRegistryProcessor; int index; DummyStream = Array.FindIndex(args, delegate(string item) { return(item == "--dummy"); }) >= 0; DocDisabled = Array.FindIndex(args, delegate(string item) { return(item == "--nodoc"); }) >= 0; #region Assembly processing if ((args.Length > 0) && ((index = Array.FindIndex(args, delegate(string item) { return(item == "--assembly"); })) >= 0)) { string assemblyPath = args[index + 1]; bool overwriteAssembly = Array.Exists(args, delegate(string item) { return(item.StartsWith("--assembly-overwrite")); }); bool profileOnlyOpts = Array.Exists(args, delegate(string item) { return(item.StartsWith("--profile-")); }); List <RegistryAssemblyConfiguration> cfgs = new List <RegistryAssemblyConfiguration>(); if (profileOnlyOpts == false) { cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.CoreProfile.xml")); cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.ES2Profile.xml")); cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.SC2Profile.xml")); } else { if (Array.Exists(args, delegate(string item) { return(item.StartsWith("--profile-core")); })) { cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.CoreProfile.xml")); } if (Array.Exists(args, delegate(string item) { return(item.StartsWith("--profile-es2")); })) { cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.ES2Profile.xml")); } if (Array.Exists(args, delegate(string item) { return(item.StartsWith("--profile-sc2")); })) { cfgs.Add(RegistryAssemblyConfiguration.Load("BindingsGen.Profiles.SC2Profile.xml")); } } foreach (RegistryAssemblyConfiguration cfg in cfgs) { try { RegistryAssembly.CleanAssembly(assemblyPath, cfg, overwriteAssembly); } catch (Exception exception) { Console.WriteLine("Unable to process assembly: {0}.", exception.Message); } } // Exclusive option return; } #endregion #region Log Maps if ((args.Length > 0) && (Array.FindIndex(args, delegate(string item) { return(item == "--only-logmaps"); }) >= 0)) { if ((args.Length == 1) || (Array.FindIndex(args, delegate(string item) { return(item == "--gl"); }) >= 0)) { Console.WriteLine("Generating GL log map..."); ctx = new RegistryContext("Gl", Path.Combine(BasePath, "GLSpecs/gl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapGl.xml")); } if ((args.Length == 1) || (Array.FindIndex(args, delegate(string item) { return(item == "--wgl"); }) >= 0)) { Console.WriteLine("Generating WGL log map..."); ctx = new RegistryContext("Wgl", Path.Combine(BasePath, "GLSpecs/wgl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapWgl.xml")); } if ((args.Length == 1) || (Array.FindIndex(args, delegate(string item) { return(item == "--glx"); }) >= 0)) { Console.WriteLine("Generating GLX log map..."); ctx = new RegistryContext("Glx", Path.Combine(BasePath, "GLSpecs/glx.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapGlx.xml")); } if ((args.Length == 1) || (Array.FindIndex(args, delegate(string item) { return(item == "--egl"); }) >= 0)) { Console.WriteLine("Generating EGL log map..."); ctx = new RegistryContext("Egl", Path.Combine(BasePath, "GLSpecs/egl.xml")); glRegistryProcessor = new RegistryProcessor(ctx.Registry); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapEgl.xml")); } // Exclusive option return; } #endregion // (Common) Documentation RegistryDocumentation <RegistryDocumentationHandler_GL4> gl4Documentation = new RegistryDocumentation <RegistryDocumentationHandler_GL4>(); gl4Documentation.Api = "GL4"; if (DocDisabled == false) { gl4Documentation.ScanDocumentation(Path.Combine(BasePath, "Refpages/OpenGL/gl4")); } RegistryDocumentation <RegistryDocumentationHandler_GL2> gl2Documentation = new RegistryDocumentation <RegistryDocumentationHandler_GL2>(); gl2Documentation.Api = "GL2.1"; if (DocDisabled == false) { gl2Documentation.ScanDocumentation(Path.Combine(BasePath, "Refpages/OpenGL/gl2.1")); } // XML-based specifications // OpenGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--gl"); }) >= 0)) { // Additional ES documentation RegistryDocumentation <RegistryDocumentationHandler_GL4> gles3Documentation = new RegistryDocumentation <RegistryDocumentationHandler_GL4>(); gles3Documentation.Api = "GLES3.2"; if (DocDisabled == false) { gles3Documentation.ScanDocumentation(Path.Combine(BasePath, "Refpages/OpenGL/es3")); } RegistryDocumentation <RegistryDocumentationHandler_GL2> gles1Documentation = new RegistryDocumentation <RegistryDocumentationHandler_GL2>(); gles1Documentation.Api = "GLES1.1"; if (DocDisabled == false) { gles1Documentation.ScanDocumentation(Path.Combine(BasePath, "Refpages/OpenGL/es1.1")); } Console.WriteLine("Loading GL specification..."); ctx = new RegistryContext("Gl", Path.Combine(BasePath, "GLSpecs/gl.xml")); ctx.RefPages.Add(gl4Documentation); ctx.RefPages.Add(gl2Documentation); ctx.RefPages.Add(gles3Documentation); ctx.RefPages.Add(gles1Documentation); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateLimitsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapGl.xml")); } // OpenGL for Windows if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--wgl"); }) >= 0)) { ctx = new RegistryContext("Wgl", Path.Combine(BasePath, "GLSpecs/wgl.xml")); ctx.RefPages.Add(gl4Documentation); ctx.RefPages.Add(gl2Documentation); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapWgl.xml")); } // OpenGL for Unix if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--glx"); }) >= 0)) { ctx = new RegistryContext("Glx", Path.Combine(BasePath, "GLSpecs/glx.xml")); ctx.RefPages.Add(gl4Documentation); ctx.RefPages.Add(gl2Documentation); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapGlx.xml")); } // EGL if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--egl"); }) >= 0)) { RegistryDocumentation <RegistryDocumentationHandler_EGL> eglDocumentation = new RegistryDocumentation <RegistryDocumentationHandler_EGL>(); eglDocumentation.Api = "EGL"; eglDocumentation.ScanDocumentation(Path.Combine(BasePath, "Refpages/EGL-Registry/sdk/docs/man")); ctx = new RegistryContext("Egl", Path.Combine(BasePath, "GLSpecs/egl.xml")); ctx.RefPages.Add(eglDocumentation); glRegistryProcessor = new RegistryProcessor(ctx.Registry); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); glRegistryProcessor.GenerateLogMap(ctx, Path.Combine(BasePath, "OpenGL.Net/KhronosLogMapEgl.xml")); } // OpenWF _OutputBasePath = "OpenWF.Net"; _Namespace = "OpenWF"; // OpenWF(C) // Note: you must setup CLI to generate this bindings if ((args.Length > 0) && (Array.FindIndex(args, delegate(string item) { return(item == "--wfc"); }) >= 0)) { Header headRegistry = new Header("Wfc"); headRegistry.AppendHeader(Path.Combine(BasePath, "GLSpecs/WF/wfc.h")); ctx = new RegistryContext("Wfc", headRegistry); glRegistryProcessor = new RegistryProcessor(ctx.Registry, "OpenWF"); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); } // OpenWF(D) if ((args.Length == 0) || (Array.FindIndex(args, delegate(string item) { return(item == "--wfd"); }) >= 0)) { Header headRegistry = new Header("Wfd"); headRegistry.AppendHeader(Path.Combine(BasePath, "GLSpecs/WF/wfd.h")); ctx = new RegistryContext("Wfd", headRegistry); glRegistryProcessor = new RegistryProcessor(ctx.Registry, "OpenWF"); GenerateCommandsAndEnums(glRegistryProcessor, ctx); GenerateExtensionsSupportClass(glRegistryProcessor, ctx); GenerateVersionsSupportClass(glRegistryProcessor, ctx); GenerateVbCommands(glRegistryProcessor, ctx); } }
public abstract string GetDocumentation(RegistryContext ctx, XslCompiledTransform transform);
public void GenerateCommands(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) throw new ArgumentNullException("path"); Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public static void GenerateDocumentation_Remarks(SourceStreamWriter sw, RegistryContext ctx, Enumerant enumerant) { return; bool requireRemarks = (enumerant.AliasOf.Count > 0); if (requireRemarks) { sw.WriteLine("/// <remarks>"); #if false if (enumerant.AliasOf.Count > 0) { sw.WriteLine("/// <para>"); sw.WriteLine("/// This enumerant is equaivalent to {0}.", SpecificationStyle.GetEnumBindingName(Alias)); sw.WriteLine("/// </para>"); } #endif sw.WriteLine("/// </remarks>"); } }
/// <summary> /// Translate the XHTML documentation into code documentation, splitting it into a sequence of lines. /// </summary> /// <param name="documentation"> /// A <see cref="String"/> taht specifies the XHTML documentation. /// </param> /// <param name="transform"> /// The <see cref="XslCompiledTransform"/> used to translate the XHTML documentation into code documentation. /// </param> /// <returns> /// It returns a <see cref="T:List{String}"/> that specifies <paramref name="documentation"/> string, after /// having processes and splitted into multiple lines. /// </returns> /// <remarks> /// The maximum line size is 120 columns. /// </remarks> private static List<string> GetDocumentationLines(string documentation, XslCompiledTransform transform, RegistryContext ctx) { documentation = ProcessXmlDocumentation(documentation, transform, ctx); documentation = TrimXmlDocumentation(documentation); //documentation = BeautifyDocumentation(documentation); return (SplitDocumentationLines(documentation)); }
private static bool GenerateDocumentation_EGL(SourceStreamWriter sw, RegistryContext ctx, Enumerant enumerant) { List<EnumerationDocumentationBase> enumDocumentations; if (sDocumentationEnumMapE.TryGetValue(enumerant.Name, out enumDocumentations) == false) return (false); bool arrangeInPara = enumDocumentations.Count > 1; sw.WriteLine("/// <summary>"); foreach (EnumerationDocumentationBase enumDocumentation in enumDocumentations) { List<string> enumerantDocLines = SplitDocumentationLines(enumDocumentation.GetDocumentation(ctx, TranformEnumerantMan4)); if (arrangeInPara) sw.WriteLine("/// <para>"); foreach (string line in enumerantDocLines) sw.WriteLine("/// {0}", line); if (arrangeInPara) sw.WriteLine("/// </para>"); } sw.WriteLine("/// </summary>"); GenerateDocumentation_Remarks(sw, ctx, enumerant); return (true); }
/// <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("OpenGL.NET/{0}.Enums.cs", ctx.Class)), null); glRegistryProcessor.GenerateCommandsImports(ctx, Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Imports.cs", ctx.Class)), null); glRegistryProcessor.GenerateCommandsDelegates(ctx, Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Delegates.cs", ctx.Class)), delegate(Command command) { return (command.Alias == 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 && !Regex.IsMatch(ctx.Class.ToLower(), 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(); } }); } #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("OpenGL.NET/{0}.Orphans.cs", 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 }
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); } } }
private static void GenerateExtensionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.Extensions.cs", ctx.Class); Console.WriteLine("Generate registry khronosExtensions to {0}.", path); SortedList<int, List<IFeature>> khronosExtensions = new SortedList<int, List<IFeature>>(); SortedList<int, List<IFeature>> vendorExtensions = new SortedList<int, List<IFeature>>(); foreach (IFeature feature in ctx.Registry.Extensions) { SortedList<int, List<IFeature>> extensionDict; List<IFeature> extensionFeatures; if (Extension.IsArbVendor(feature.Name)) extensionDict = khronosExtensions; else extensionDict = vendorExtensions; int index = ExtensionIndices.GetIndex(feature.Name); if (extensionDict.TryGetValue(index, out extensionFeatures) == false) { extensionFeatures = new List<IFeature>(); extensionDict.Add(index, extensionFeatures); } extensionFeatures.Add(feature); } using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Extension support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class Extensions : ExtensionsCollection"); sw.WriteLine("{"); sw.Indent(); foreach (KeyValuePair<int, List<IFeature>> pair in khronosExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) sw.WriteLine("[Extension(\"{0}\")]", feature.Name); Extension mainExtension = (Extension)mainFeature; if (String.IsNullOrEmpty(mainExtension.Supported) == false) sw.WriteLine("[ExtensionSupport(\"{0}\")]", mainExtension.Supported); sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } foreach (KeyValuePair<int, List<IFeature>> pair in vendorExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) sw.WriteLine("[Extension(\"{0}\")]", feature.Name); sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
private static void GenerateLimitsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("{0}/{1}.Limits.cs", _OutputBasePath, ctx.Class); List <Enumerant> limitEnums = new List <Enumerant>(); foreach (Enumerant enumerant in ctx.Registry.Enumerants) { // Skip enumeration with aliases if (enumerant.EnumAlias != null) { continue; } bool maxLimit = enumerant.Name.StartsWith("GL_MAX_"); bool minLimit = enumerant.Name.StartsWith("GL_MIN_"); if (!maxLimit && !minLimit) { continue; } if (CommandFlagsDatabase.IsExcludedLimit(enumerant.Name)) { continue; } limitEnums.Add(enumerant); } foreach (CommandFlagsDatabase.Limit limit in CommandFlagsDatabase.GetLimits()) { if (limitEnums.Exists(delegate(Enumerant item) { return(item.Name == limit.Name); })) { continue; } Enumerant addedEnum = ctx.Registry.GetEnumerant(limit.Name); Debug.Assert(addedEnum != null); if (addedEnum == null) { continue; } limitEnums.Add(addedEnum); } Console.WriteLine("Generate API limits to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Limits support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public sealed partial class Limits"); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in limitEnums) { // Filter enumerant CommandFlagsDatabase.Limit limit = CommandFlagsDatabase.GetLimit(enumerant.Name); string fieldName = SpecificationStyle.GetCamelCase(enumerant.ImplementationName); string fieldType = "int"; int fieldLength = 1; if (limit != null) { fieldType = limit.Type; fieldLength = limit.Length; } enumerant.GenerateDocumentation(sw, ctx); if (fieldLength > 1) { sw.WriteLine("[Limit({0}, ArrayLength = {1})]", enumerant.ImplementationName, fieldLength); enumerant.GenerateRequirements(sw, ctx); StringBuilder sb = new StringBuilder(); sb.AppendFormat("public {0}[] {1} = new {0}[] {{", fieldType, fieldName); for (int i = 0; i < fieldLength; i++) { switch (fieldType) { case "int": sb.Append("0"); break; case "float": sb.Append("0.0f"); break; } if (i < fieldLength - 1) { sb.Append(", "); } } sb.Append(" };"); sw.WriteLine(sb.ToString()); } else { sw.WriteLine("[Limit({0})]", enumerant.ImplementationName); enumerant.GenerateRequirements(sw, ctx); sw.WriteLine("public {0} {1};", fieldType, fieldName); } sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
/// <summary> /// Generate a <see cref="Command"/> documentation using the OpenGL 4 manual. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> public static bool GenerateDocumentation_EGL(SourceStreamWriter sw, RegistryContext ctx, Command command, bool fail, List<CommandParameter> commandParams) { XmlDocument xml = null; XmlElement root = null; XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("mml", "http://www.w3.org/2001/XMLSchema-instance"); nsmgr.AddNamespace("x", "http://docbook.org/ns/docbook"); if (sDocumentationMapE.TryGetValue(command.Prototype.Name, out xml)) root = xml.DocumentElement; if (fail && (root == null)) return (false); #region Summary string purpose = String.Format("Binding for {0}.", command.Prototype.Name); if (root != null) { XmlNode xmlIdentifier = xml.SelectSingleNode("/x:refentry/x:refnamediv/x:refpurpose", nsmgr); if (xmlIdentifier != null) purpose = GetDocumentationLine(xmlIdentifier.InnerText, TranformCommandMan4, ctx); } sw.WriteLine("/// <summary>"); sw.WriteLine("/// {0}", purpose); sw.WriteLine("/// </summary>"); #endregion #region Parameters foreach (CommandParameter param in commandParams) { List<string> paramDoc = new List<string>(); // Note: in the case of overloaded methods, some parameters are implicit. Skip the documentation for those parameters. if (param.IsImplicit(ctx, command)) continue; // Default paramDoc.Add(String.Format("A <see cref=\"T:{0}\"/>.", param.GetImplementationType(ctx, command))); if (root != null) { string xpath = String.Format("/x:refentry/x:refsect1[@xml:id='parameters']/x:variablelist/x:varlistentry[x:term/x:parameter/text() = '{0}']/x:listitem/x:para", param.ImportName); XmlNode xmlIdentifier = root.SelectSingleNode(xpath, nsmgr); if (xmlIdentifier != null) paramDoc = GetDocumentationLines(xmlIdentifier.InnerXml, TranformCommandMan4, ctx); } sw.WriteLine("/// <param name=\"{0}\">", param.Name); foreach (string line in paramDoc) sw.WriteLine("/// {0}", line); sw.WriteLine("/// </param>"); } #endregion return (true); }
/// <summary> /// Generate a <see cref="Command"/> documentation using the Khronos reference pages. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used to write the documentation of <paramref name="command"/>. /// </param> /// <param name="ctx"> /// A <see cref="RegistryContext"/> that defines the OpenGL specification. /// </param> /// <param name="command"> /// The <see cref="Command"/> to be documented. /// </param> /// <param name="fail"></param> internal static bool GenerateDocumentation(SourceStreamWriter sw, RegistryContext ctx, Command command, bool fail, List <CommandParameter> commandParams, IList <RegistryDocumentationHandler> docHandlers) { // Loads documentation information foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandler.Load(); } string defaultApi = ctx.Class.ToUpperInvariant(); #region Summary sw.WriteLine("/// <summary>"); if (docHandlers.Count > 1) { List <KeyValuePair <string, string> > docHandlersDoc = new List <KeyValuePair <string, string> >(); foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandlersDoc.Add(new KeyValuePair <string, string>(docHandler.Api ?? defaultApi, docHandler.QueryCommandSummary(ctx, command))); } if (docHandlersDoc.Count == 2 && docHandlersDoc[0].Value == docHandlersDoc[1].Value) { string api = (docHandlersDoc[0].Key) + "|" + (docHandlersDoc[1].Key); string doc = docHandlersDoc[0].Value; docHandlersDoc.Clear(); docHandlersDoc.Add(new KeyValuePair <string, string>(api, doc)); } foreach (KeyValuePair <string, string> docHandler in docHandlersDoc) { sw.WriteLine("/// <para>"); sw.WriteLine("/// {0}", SplitDocumentationLines(String.Format("[{0}] {1}", docHandler.Key, docHandler.Value))); sw.WriteLine("/// </para>"); } } else { sw.WriteLine("/// {0}", SplitDocumentationLines(String.Format("[{0}] {1}", docHandlers[0].Api ?? defaultApi, docHandlers[0].QueryCommandSummary(ctx, command)))); } sw.WriteLine("/// </summary>"); #endregion #region Parameters foreach (CommandParameter param in commandParams) { // Note: in the case of overloaded methods, some parameters are implicit. Skip the documentation for those parameters. if (param.IsImplicit(ctx, command)) { continue; } sw.WriteLine("/// <param name=\"{0}\">", param.ImplementationNameRaw); if (docHandlers.Count > 1 && false) { foreach (RegistryDocumentationHandler docHandler in docHandlers) { List <string> paramDoc = SplitDocumentationLines(docHandler.QueryCommandParamSummary(ctx, command, param)); sw.WriteLine("/// <para>"); foreach (string line in paramDoc) { sw.WriteLine("/// {0}", line); } sw.WriteLine("/// </para>"); } } else { List <string> paramDoc = SplitDocumentationLines(docHandlers[0].QueryCommandParamSummary(ctx, command, param)); foreach (string line in paramDoc) { sw.WriteLine("/// {0}", line); } } sw.WriteLine("/// </param>"); } #endregion #region Remarks IEnumerable <string> remarksDoc = docHandlers[0].QueryCommandRemarks(ctx, command); List <string> remarksLines = new List <string>(remarksDoc); if (remarksLines.Count > 0 && false) { sw.WriteLine("/// <remarks>"); foreach (string remarksLine in remarksLines) { sw.WriteLine("/// <para>"); sw.WriteLine("/// {0}", SplitDocumentationLines(remarksLine)); sw.WriteLine("/// </para>"); } sw.WriteLine("/// </remarks>"); } #endregion #region Errors IEnumerable <string> errorsDoc = docHandlers[0].QueryCommandErrors(ctx, command); List <string> errorsLines = new List <string>(errorsDoc); if (remarksLines.Count > 0) { foreach (string errorLine in errorsLines) { sw.WriteLine("/// <exception cref=\"KhronosException\">"); sw.WriteLine("/// {0}", SplitDocumentationLines(errorLine)); sw.WriteLine("/// </exception>"); } } #endregion #region See Also IEnumerable <string> seealsoDoc = docHandlers[0].QueryCommandSeeAlso(ctx, command); List <string> seealsoLines = new List <string>(seealsoDoc); if (seealsoLines.Count > 0) { foreach (string seealsoLine in seealsoLines) { sw.WriteLine("/// {0}", seealsoLine); } } #endregion // Dispose documentation information foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandler.Dispose(); } return(true); }
public void GenerateCommands(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); if ((filter != null) && (mRegistry.Commands.FindIndex(delegate(Command item) { return (filter(item)); }) < 0)) return; GenerateCommands(ctx, path, (CommandSerializerDelegate)delegate(RegistryContext cctx, SourceStreamWriter sw) { foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) continue; command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); }
internal static bool GenerateDocumentation(SourceStreamWriter sw, RegistryContext ctx, Enumerant enumerant, IList <RegistryDocumentationHandler> docHandlers) { // Loads documentation information foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandler.Load(); } string defaultApi = ctx.Class.ToUpperInvariant(); List <KeyValuePair <string, string> > docHandlersDoc = new List <KeyValuePair <string, string> >(); foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandlersDoc.Add(new KeyValuePair <string, string>(docHandler.Api ?? defaultApi, docHandler.QueryEnumSummary(ctx, enumerant))); } if (docHandlersDoc.Count == 2 && docHandlersDoc[0].Value == docHandlersDoc[1].Value) { string api = (docHandlers[0].Api ?? defaultApi) + "|" + (docHandlers[1].Api ?? defaultApi); string doc = docHandlersDoc[0].Value; docHandlersDoc.Clear(); docHandlersDoc.Add(new KeyValuePair <string, string>(api, doc)); } if (docHandlersDoc.Count == 4) { bool func1 = docHandlersDoc[0].Value == docHandlersDoc[2].Value; bool func2 = docHandlersDoc[1].Value == docHandlersDoc[3].Value; if (func1 && func2) { string api1 = (docHandlers[0].Api ?? defaultApi) + "|" + (docHandlers[2].Api ?? defaultApi); string doc1 = docHandlersDoc[0].Value; string api2 = (docHandlers[1].Api ?? defaultApi) + "|" + (docHandlers[3].Api ?? defaultApi); string doc2 = docHandlersDoc[1].Value; docHandlersDoc.Clear(); docHandlersDoc.Add(new KeyValuePair <string, string>(api1, doc1)); docHandlersDoc.Add(new KeyValuePair <string, string>(api2, doc2)); } } sw.WriteLine("/// <summary>"); if (docHandlersDoc.Count > 1) { foreach (KeyValuePair <string, string> doc in docHandlersDoc) { sw.WriteLine("/// <para>"); sw.WriteLine("/// {0}", SplitDocumentationLines(String.Format("[{0}] {1}", doc.Key, doc.Value))); sw.WriteLine("/// </para>"); } } else { sw.WriteLine("/// {0}", SplitDocumentationLines(String.Format("[{0}] {1}", docHandlersDoc[0].Key, docHandlersDoc[0].Value))); } sw.WriteLine("/// </summary>"); // Dispose documentation information foreach (RegistryDocumentationHandler docHandler in docHandlers) { docHandler.Dispose(); } return(true); }
public void GenerateCommands(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) throw new ArgumentNullException("path"); Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { 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("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }