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:
the_fiddler 2011-07-20 10:10:33 +00:00
parent 91519cb62b
commit 55324777ca
4 changed files with 86 additions and 18 deletions

View file

@ -82,7 +82,7 @@ namespace Bind
sw.WriteLine("{");
sw.Indent();
WriteEnums(sw, enums);
WriteEnums(sw, enums, wrappers);
sw.Unindent();
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
@ -169,7 +169,7 @@ namespace Bind
#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));
@ -405,13 +405,41 @@ namespace Bind
#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
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 1591"); // Missing doc comments
sw.WriteLine();
//sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
//sw.WriteLine();
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass));
@ -430,7 +458,31 @@ namespace Bind
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();
}

View file

@ -183,7 +183,7 @@ namespace Bind
{
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));
if (constant_override != null)
{

View file

@ -12,10 +12,10 @@ namespace Bind
interface ISpecWriter
{
void WriteBindings(IBind generator);
void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates);
void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
void WriteEnums(BindStreamWriter sw, EnumCollection enums);
void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
void WriteLicense(BindStreamWriter sw);
// void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates);
// void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
// void WriteEnums(BindStreamWriter sw, EnumCollection enums);
// void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
// void WriteLicense(BindStreamWriter sw);
}
}

View file

@ -17,7 +17,7 @@ namespace Bind.Structures
/// can be retrieved or set. The value can be either a number, another constant
/// or an alias to a constant
/// </summary>
public class Constant
public class Constant : IComparable<Constant>
{
static StringBuilder translator = new StringBuilder();
static readonly int MaxReferenceDepth = 8;
@ -25,13 +25,13 @@ namespace Bind.Structures
#region PreviousName
string previous_name;
string original_name;
// Gets the name prior to translation.
public string PreviousName
public string OriginalName
{
get { return previous_name; }
private set { previous_name = value; }
get { return original_name; }
private set { original_name = value; }
}
#endregion
@ -51,7 +51,10 @@ namespace Bind.Structures
{
if (String.IsNullOrEmpty(value))
throw new ArgumentNullException("value");
PreviousName = _name;
if (OriginalName == null)
OriginalName = _name;
_name = value;
}
}
@ -259,6 +262,7 @@ namespace Bind.Structures
/// (eg GL_XXX_YYY = (int)0xDEADBEEF or GL_XXX_YYY = GL_ZZZ.FOOBAR).
/// </summary>
/// <returns></returns>
[Obsolete("This belongs to the language-specific ISpecWriter implementations.")]
public override string ToString()
{
if (String.IsNullOrEmpty(Name))
@ -271,5 +275,17 @@ namespace Bind.Structures
}
#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
}
}