mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 12:15:37 +00:00
Added documentation comments to generated enums.
Improved ISpecWriter API by removing low-level implementation details. Made Constant implement IComparable so it can be sorted before being written to output.
This commit is contained in:
parent
91519cb62b
commit
55324777ca
|
@ -82,7 +82,7 @@ namespace Bind
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
|
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
WriteEnums(sw, enums);
|
WriteEnums(sw, enums, wrappers);
|
||||||
sw.Unindent();
|
sw.Unindent();
|
||||||
|
|
||||||
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
||||||
|
@ -169,7 +169,7 @@ namespace Bind
|
||||||
|
|
||||||
#region WriteDelegates
|
#region WriteDelegates
|
||||||
|
|
||||||
public void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
|
void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("Writing delegates to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.DelegatesClass));
|
Trace.WriteLine(String.Format("Writing delegates to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.DelegatesClass));
|
||||||
|
|
||||||
|
@ -405,13 +405,41 @@ namespace Bind
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region WriteConstants
|
||||||
|
|
||||||
|
void WriteConstants(BindStreamWriter sw, IEnumerable<Constant> constants)
|
||||||
|
{
|
||||||
|
// Make sure everything is sorted. This will avoid random changes between
|
||||||
|
// consecutive runs of the program.
|
||||||
|
constants = constants.OrderBy(c => c);
|
||||||
|
|
||||||
|
foreach (var c in constants)
|
||||||
|
{
|
||||||
|
if (!Settings.IsEnabled(Settings.Legacy.NoDocumentation))
|
||||||
|
{
|
||||||
|
sw.WriteLine("/// <summary>");
|
||||||
|
sw.WriteLine("/// Original was " + Settings.ConstantPrefix + c.OriginalName + " = " + c.Value);
|
||||||
|
sw.WriteLine("/// </summary>");
|
||||||
|
}
|
||||||
|
|
||||||
|
var str = String.Format("{0} = {1}((int){2}{3})", c.Name, c.Unchecked ? "unchecked" : "",
|
||||||
|
!String.IsNullOrEmpty(c.Reference) ? c.Reference + Settings.NamespaceSeparator : "", c.Value);
|
||||||
|
|
||||||
|
sw.Write(str);
|
||||||
|
if (!String.IsNullOrEmpty(str))
|
||||||
|
sw.WriteLine(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region WriteEnums
|
#region WriteEnums
|
||||||
|
|
||||||
public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
|
void WriteEnums(BindStreamWriter sw, EnumCollection enums, FunctionCollection wrappers)
|
||||||
{
|
{
|
||||||
//sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute
|
//sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute
|
||||||
sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
|
//sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
|
||||||
sw.WriteLine();
|
//sw.WriteLine();
|
||||||
|
|
||||||
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
||||||
Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass));
|
Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass));
|
||||||
|
@ -430,7 +458,31 @@ namespace Bind
|
||||||
|
|
||||||
foreach (Enum @enum in enums.Values)
|
foreach (Enum @enum in enums.Values)
|
||||||
{
|
{
|
||||||
sw.Write(@enum);
|
if (!Settings.IsEnabled(Settings.Legacy.NoDocumentation))
|
||||||
|
{
|
||||||
|
// Document which functions use this enum.
|
||||||
|
var functions =
|
||||||
|
(from wrapper in wrappers
|
||||||
|
from function in wrapper.Value
|
||||||
|
from param in function.Parameters
|
||||||
|
where param.CurrentType == @enum.Name
|
||||||
|
select Settings.GLClass + (function.Extension != "Core" ? ("." + function.Extension) : "") + "." + function.TrimmedName)
|
||||||
|
.Distinct();
|
||||||
|
|
||||||
|
sw.WriteLine("/// <summary>");
|
||||||
|
sw.WriteLine(String.Format("/// {0}", functions.Count() > 0 ?
|
||||||
|
("Used in " + String.Join(", ", functions.ToArray())) : "Not used directly."));
|
||||||
|
sw.WriteLine("/// </summary>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@enum.IsFlagCollection)
|
||||||
|
sw.WriteLine("[Flags]");
|
||||||
|
sw.WriteLine("public enum " + @enum.Name + " : " + @enum.Type);
|
||||||
|
sw.WriteLine("{");
|
||||||
|
sw.Indent();
|
||||||
|
WriteConstants(sw, @enum.ConstantCollection.Values);
|
||||||
|
sw.Unindent();
|
||||||
|
sw.WriteLine("}");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ namespace Bind
|
||||||
{
|
{
|
||||||
if (enum_override != null)
|
if (enum_override != null)
|
||||||
{
|
{
|
||||||
XPathNavigator constant_override = enum_override.SelectSingleNode(String.Format("token[@name='{0}']", c.PreviousName)) ??
|
XPathNavigator constant_override = enum_override.SelectSingleNode(String.Format("token[@name='{0}']", c.OriginalName)) ??
|
||||||
enum_override.SelectSingleNode(String.Format("token[@name={0}]", c.Name));
|
enum_override.SelectSingleNode(String.Format("token[@name={0}]", c.Name));
|
||||||
if (constant_override != null)
|
if (constant_override != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,10 @@ namespace Bind
|
||||||
interface ISpecWriter
|
interface ISpecWriter
|
||||||
{
|
{
|
||||||
void WriteBindings(IBind generator);
|
void WriteBindings(IBind generator);
|
||||||
void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates);
|
// void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates);
|
||||||
void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
|
// void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
|
||||||
void WriteEnums(BindStreamWriter sw, EnumCollection enums);
|
// void WriteEnums(BindStreamWriter sw, EnumCollection enums);
|
||||||
void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
|
// void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
|
||||||
void WriteLicense(BindStreamWriter sw);
|
// void WriteLicense(BindStreamWriter sw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Bind.Structures
|
||||||
/// can be retrieved or set. The value can be either a number, another constant
|
/// can be retrieved or set. The value can be either a number, another constant
|
||||||
/// or an alias to a constant
|
/// or an alias to a constant
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Constant
|
public class Constant : IComparable<Constant>
|
||||||
{
|
{
|
||||||
static StringBuilder translator = new StringBuilder();
|
static StringBuilder translator = new StringBuilder();
|
||||||
static readonly int MaxReferenceDepth = 8;
|
static readonly int MaxReferenceDepth = 8;
|
||||||
|
@ -25,13 +25,13 @@ namespace Bind.Structures
|
||||||
|
|
||||||
#region PreviousName
|
#region PreviousName
|
||||||
|
|
||||||
string previous_name;
|
string original_name;
|
||||||
|
|
||||||
// Gets the name prior to translation.
|
// Gets the name prior to translation.
|
||||||
public string PreviousName
|
public string OriginalName
|
||||||
{
|
{
|
||||||
get { return previous_name; }
|
get { return original_name; }
|
||||||
private set { previous_name = value; }
|
private set { original_name = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -51,7 +51,10 @@ namespace Bind.Structures
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(value))
|
if (String.IsNullOrEmpty(value))
|
||||||
throw new ArgumentNullException("value");
|
throw new ArgumentNullException("value");
|
||||||
PreviousName = _name;
|
|
||||||
|
if (OriginalName == null)
|
||||||
|
OriginalName = _name;
|
||||||
|
|
||||||
_name = value;
|
_name = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,6 +262,7 @@ namespace Bind.Structures
|
||||||
/// (eg GL_XXX_YYY = (int)0xDEADBEEF or GL_XXX_YYY = GL_ZZZ.FOOBAR).
|
/// (eg GL_XXX_YYY = (int)0xDEADBEEF or GL_XXX_YYY = GL_ZZZ.FOOBAR).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[Obsolete("This belongs to the language-specific ISpecWriter implementations.")]
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(Name))
|
if (String.IsNullOrEmpty(Name))
|
||||||
|
@ -271,5 +275,17 @@ namespace Bind.Structures
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region IComparable <Constant>Members
|
||||||
|
|
||||||
|
public int CompareTo(Constant other)
|
||||||
|
{
|
||||||
|
int ret = Value.CompareTo(other.Value);
|
||||||
|
if (ret == 0)
|
||||||
|
return Name.CompareTo(other.Name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue