/// <summary> /// Generate the C# source code for this enumerant. /// </summary> /// <param name="sw"> /// A <see cref="SourceStreamWriter"/> used for writing the source code. /// </param> internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx) { if (sw == null) { throw new ArgumentNullException("sw"); } RegistryDocumentation.GenerateDocumentation(sw, ctx, this); foreach (Enumerant aliasOf in AliasOf) { sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.Name); } foreach (IFeature feature in RequiredBy) { sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name); } foreach (Enumerant aliasOf in AliasOf) { foreach (IFeature feature in aliasOf.RequiredBy) { sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name); } } foreach (IFeature feature in RemovedBy) { sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name); } // This metadata is used for procedure logging function bool requiresLogAttribute = ParentEnumerantBlock.Type == "bitmask"; if (requiresLogAttribute == true) { if (ParentEnumerantBlock.Type == "bitmask") { sw.WriteLine("[Log(BitmaskName = \"{0}\")]", ParentEnumerantBlock.Namespace); } } if (IsDeprecated) { sw.Write("#if DEBUG && !OPENGL_NET_COMPATIBILITY_PROFILE" + Environment.NewLine); sw.WriteLine("[Obsolete(\"Deprecated/removed by {0}.\")]", SpecificationStyle.GetKhronosVersionHumanReadable(RemovedBy[0].Name)); sw.Write("#endif" + Environment.NewLine); } sw.WriteLine(Declaration); }
internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx) { if (sw == null) { throw new ArgumentNullException("sw"); } if (ctx == null) { throw new ArgumentNullException("ctx"); } bool bitmask = Enums.TrueForAll(delegate(Enumerant item) { Enumerant actualEnumerant = ctx.Registry.GetEnumerant(item.Name); return(actualEnumerant == null || actualEnumerant.ParentEnumerantBlock.Type == "bitmask"); }); // Collect group enumerants by their value Dictionary <string, List <Enumerant> > groupEnums = new Dictionary <string, List <Enumerant> >(); // ...include all enums defined in this group foreach (Enumerant item in Enums) { Enumerant itemValue = ctx.Registry.GetEnumerant(item.Name); if (itemValue != null) { if (!groupEnums.ContainsKey(itemValue.Value)) { groupEnums.Add(itemValue.Value, new List <Enumerant>()); } groupEnums[itemValue.Value].Add(itemValue); } } // Modify canonical enumeration (value/block/group) definition CommandFlagsDatabase.EnumerantItem enumerantExtension = CommandFlagsDatabase.FindEnumerant(Name); if (enumerantExtension != null) { // ...override group information if (enumerantExtension.Type != null) { switch (enumerantExtension.Type) { case "bitmask": bitmask = true; break; } } // ...include all enums to be added by additional configuration foreach (string addedEnum in enumerantExtension.AddEnumerants) { Enumerant addedEnumValue = ctx.Registry.GetEnumerant(addedEnum); if (addedEnumValue != null) { if (!groupEnums.ContainsKey(addedEnumValue.Value)) { groupEnums.Add(addedEnumValue.Value, new List <Enumerant>()); } // Note: since specification can be updated while the CommandFlags.xml is not in synch, the specification // may defined missed enumerant values. In this case do not add enumerant value if (groupEnums[addedEnumValue.Value].Contains(addedEnumValue) == false) { groupEnums[addedEnumValue.Value].Add(addedEnumValue); } } } } // Make enumerants distinct (discard duplicated enumerants, mainly from extensions _ARB, _EXT, ...) List <Enumerant> uniqueEnums = new List <Enumerant>(); foreach (KeyValuePair <string, List <Enumerant> > pair in groupEnums) { if (pair.Value.Count > 1) { Enumerant shorterNameEnum = null; foreach (Enumerant item in pair.Value) { if ((shorterNameEnum == null) || (shorterNameEnum.Name.Length > item.Name.Length)) { shorterNameEnum = item; } } uniqueEnums.Add(shorterNameEnum); } else { uniqueEnums.Add(pair.Value[0]); } } sw.WriteLine("/// <summary>"); sw.WriteLine("/// Strongly typed enumeration {0}.", Name); sw.WriteLine("/// </summary>"); if (bitmask) { sw.WriteLine("[Flags()]"); } sw.WriteLine("public enum {0}{1}", Name, bitmask ? " : uint" : String.Empty); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in uniqueEnums) { List <Enumerant> allEnums = groupEnums[enumerant.Value]; string bindingName = enumerant.EnumAlias == null ? enumerant.ImplementationName : enumerant.EnumAlias.ImplementationName; string camelCase = SpecificationStyle.GetCamelCase(bindingName); sw.WriteLine("/// <summary>"); if (allEnums.Count > 1) { StringBuilder sb = new StringBuilder(); sb.Append("Strongly typed for value "); for (int i = 0; i < allEnums.Count; i++) { sb.Append(allEnums[i].Name); if (i < allEnums.Count - 1) { sb.Append(", "); } } sb.Append("."); foreach (string docLine in RegistryDocumentation.SplitDocumentationLines(sb.ToString())) { sw.WriteLine("/// {0}", docLine); } } else { sw.WriteLine("/// Strongly typed for value {0}.", enumerant.Name); } sw.WriteLine("/// </summary>"); sw.WriteLine("{0} = Gl.{1},", camelCase, bindingName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); }
internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx) { if (sw == null) { throw new ArgumentNullException("sw"); } if (ctx == null) { throw new ArgumentNullException("ctx"); } bool bitmask = Enums.TrueForAll(delegate(Enumerant item) { Enumerant actualEnumerant = ctx.Registry.GetEnumerant(item.Name); return(actualEnumerant == null || actualEnumerant.ParentEnumerantBlock.Type == "bitmask"); }); // Collect group enumerants by their value Dictionary <string, List <Enumerant> > groupEnums = new Dictionary <string, List <Enumerant> >(); // ...include all enums defined in this group foreach (Enumerant item in Enums) { Enumerant itemValue = ctx.Registry.GetEnumerant(item.Name); if (itemValue != null) { if (!groupEnums.ContainsKey(itemValue.Value)) { groupEnums.Add(itemValue.Value, new List <Enumerant>()); } groupEnums[itemValue.Value].Add(itemValue); } } // Modify canonical enumeration (value/block/group) definition CommandFlagsDatabase.EnumerantItem enumerantExtension = CommandFlagsDatabase.FindEnumerant(Name); if (enumerantExtension != null) { // ...override group information if (enumerantExtension.Type != null) { switch (enumerantExtension.Type) { case "bitmask": bitmask = true; break; } } // ...include all enums to be added by additional configuration foreach (string addedEnum in enumerantExtension.AddEnumerants) { Enumerant addedEnumValue = ctx.Registry.GetEnumerant(addedEnum); if (addedEnumValue != null) { if (!groupEnums.ContainsKey(addedEnumValue.Value)) { groupEnums.Add(addedEnumValue.Value, new List <Enumerant>()); } // Note: since specification can be updated while the CommandFlags.xml is not in synch, the specification // may defined missed enumerant values. In this case do not add enumerant value if (groupEnums[addedEnumValue.Value].Contains(addedEnumValue) == false) { groupEnums[addedEnumValue.Value].Add(addedEnumValue); } } } } // Make enumerants distinct (discard duplicated enumerants, mainly from extensions _ARB, _EXT, ...) List <Enumerant> uniqueEnums = new List <Enumerant>(); foreach (KeyValuePair <string, List <Enumerant> > pair in groupEnums) { if (pair.Value.Count > 1) { List <Enumerant> uniqueNames = new List <Enumerant>(); foreach (Enumerant item in pair.Value) { if (item.Alias != null) { continue; } if (item.EnumAlias != null) { continue; } if (uniqueNames.FindIndex(delegate(Enumerant item1) { return(item.Name.StartsWith(item1.Name)); }) >= 0) { continue; } if (uniqueNames.FindIndex(delegate(Enumerant item1) { return(item1.Name.StartsWith(item.Name)); }) >= 0) { uniqueNames.RemoveAll(delegate(Enumerant item1) { return(item1.Name.StartsWith(item.Name)); }); } uniqueNames.Add(item); } uniqueEnums.AddRange(uniqueNames); } else { uniqueEnums.AddRange(pair.Value); } } sw.WriteLine("/// <summary>"); sw.WriteLine("/// Strongly typed enumeration {0}.", Name); sw.WriteLine("/// </summary>"); if (bitmask) { sw.WriteLine("[Flags()]"); } sw.WriteLine("public enum {0}{1}", Name, bitmask ? " : uint" : String.Empty); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in uniqueEnums) { List <Enumerant> allEnums = groupEnums[enumerant.Value]; string bindingName = enumerant.EnumAlias == null ? enumerant.ImplementationName : enumerant.EnumAlias.ImplementationName; string camelCase = SpecificationStyle.GetCamelCase(bindingName); if (enumerantExtension != null && enumerantExtension.ItemPrefix != null && camelCase.StartsWith(enumerantExtension.ItemPrefix)) { camelCase = camelCase.Substring(enumerantExtension.ItemPrefix.Length); } sw.WriteLine("/// <summary>"); if (allEnums.Count > 1) { StringBuilder sb = new StringBuilder(); sb.Append("Strongly typed for value "); for (int i = 0; i < allEnums.Count; i++) { sb.Append(allEnums[i].Name); if (i < allEnums.Count - 1) { sb.Append(", "); } } sb.Append("."); foreach (string docLine in RegistryDocumentation.SplitDocumentationLines(sb.ToString())) { sw.WriteLine("/// {0}", docLine); } } else { sw.WriteLine("/// Strongly typed for value {0}.", enumerant.Name); } sw.WriteLine("/// </summary>"); Enumerant enumvalue = ctx.Registry.GetEnumerant(ctx.Class.ToUpperInvariant() + "_" + bindingName); string classDefaultApi = ctx.Class.ToLower(); if (enumvalue != null) { // RequiredByFeature foreach (IFeature feature in enumvalue.RequiredBy) { sw.WriteLine(feature.GenerateRequiredByAttribute(null, classDefaultApi)); } // RequiredByFeature (from aliases) Note: not sure that Profile is considered here foreach (Enumerant aliasOf in enumvalue.AliasOf) { foreach (IFeature feature in aliasOf.RequiredBy) { sw.WriteLine(feature.GenerateRequiredByAttribute(null, classDefaultApi)); } } // RemovedByFeature foreach (IFeature feature in enumvalue.RemovedBy) { sw.WriteLine(feature.GenerateRemovedByAttribute(classDefaultApi)); } } sw.WriteLine("{0} = {1}.{2},", camelCase, ctx.Class, bindingName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); }
/// <summary> /// Generate the command implementation signature and the method documentation. /// </summary> /// <param name="sw"> /// The <see cref="SourceStreamWriter"/> used to write the source code. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> defining the OpenGL registry information. /// </param> /// <param name="commandParams"> /// A <see cref="T:List{CommandParameter}"/> determining the method overload. /// </param> private void GenerateImplementation_Signature(SourceStreamWriter sw, RegistryContext ctx, List <CommandParameter> commandParams, string implementationName, string returnType) { #if !DEBUG // Documentation RegistryDocumentation.GenerateDocumentation(sw, ctx, this, commandParams); #endif foreach (IFeature feature in RequiredBy) { sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name); } foreach (IFeature feature in RemovedBy) { sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name); } #region Signature sw.WriteIdentation(); // Signature sw.Write("{0} static ", CommandFlagsDatabase.GetCommandVisibility(this)); if (IsUnsafeImplementationSignature(ctx, commandParams)) { sw.Write("unsafe "); } sw.Write("{0} {1}(", returnType, implementationName); // Signature - Parameters int paramCount = commandParams.FindAll(delegate(CommandParameter item) { return(!item.IsImplicit(ctx, this)); }).Count; foreach (CommandParameter param in commandParams) { // Skip in signature implicit parameters if (param.IsImplicit(ctx, this)) { continue; } string paramAttributes = param.GetImplementationTypeAttributes(ctx, this); string paramModifier = param.GetImplementationTypeModifier(ctx, this); if (paramAttributes != null) { sw.Write("{0} ", paramAttributes); } if (paramModifier != null) { sw.Write("{0} ", paramModifier); } if ((paramCount == 1) && (param.IsManagedArray) && ((Flags & CommandFlags.VariadicParams) != 0)) { sw.Write("params "); } sw.Write("{0} {1}", param.GetImplementationType(ctx, this), param.ImplementationName); paramCount--; if (paramCount > 0) { sw.Write(", "); } } sw.Write(")"); sw.WriteLine(); #endregion }