Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Fix numerous binder errors #781

Merged
merged 10 commits into from Jul 21, 2018
  •  
  •  
  •  
33 changes: 32 additions & 1 deletion OpenTK.sln.DotSettings
Expand Up @@ -31,5 +31,36 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NONINFRINGEMENT/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ACCUM/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Apostolopoulos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ATTRIB/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ATTRIBS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Clipmap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CMYK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coord/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=COORDS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DOUBLEBUFFER/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=FRAMEBUFFER/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Framezoom/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=LUID/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MINMAX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MODELVIEW/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MULTISAMPLE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NONINFRINGEMENT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PRECLIP/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=QCOM/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Renderbuffer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=RESAMPLE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SGIS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sgix/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SRGB/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stefanos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SUBPIXEL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SUBSAMPLE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=TEXEL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Typemap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=typeparam/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unindent/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unindented/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=WRITEMASK/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

70 changes: 56 additions & 14 deletions src/Generator.Bind/BindingsWriter.cs
Expand Up @@ -95,8 +95,8 @@ private void WriteWrappers(FunctionCollection wrappers, DelegateCollection deleg
sw.WriteLineNoTabs();

sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("using System.Text;");
sw.WriteLineNoTabs();

sw.WriteLine($"namespace {Generator.Namespace}");
Expand Down Expand Up @@ -189,8 +189,8 @@ private void WriteWrappers(FunctionCollection wrappers, DelegateCollection deleg
sw.WriteLineNoTabs();

sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("using System.Text;");
sw.WriteLineNoTabs();

sw.WriteLine($"namespace {Generator.Namespace}");
Expand Down Expand Up @@ -340,7 +340,14 @@ private void WriteDocumentation(SourceWriter sw, FunctionDefinition f)
var summaryLines = docs.Summary.TrimEnd().Split('\n');
foreach (var summaryLine in summaryLines)
{
sw.WriteLine($"/// {summaryLine}");
sw.Write($"/// {summaryLine}");

if (summaryLine == summaryLines.Last() && !summaryLine.EndsWith("."))
{
sw.Write('.');
}

sw.WriteLine();
}
}
sw.WriteLine("/// </summary>");
Expand Down Expand Up @@ -412,6 +419,12 @@ private void WriteDocumentation(SourceWriter sw, FunctionDefinition f)
{
sw.WriteLine($"/// <typeparam name=\"{genericParameterName}\"></typeparam>");
}

if (!f.ReturnTypeDefinition.TypeName.Equals(typeof(void).Name, StringComparison.OrdinalIgnoreCase))
{
// TODO: Return value documentation
sw.WriteLine("/// <returns></returns>");
}
}

private void WriteConstants(SourceWriter sw, IEnumerable<ConstantDefinition> constants)
Expand Down Expand Up @@ -514,26 +527,22 @@ private void WriteEnums(EnumCollection enums, FunctionCollection wrappers)
WriteLicense(sw);
sw.WriteLineNoTabs();

sw.WriteLine("using System;");
sw.WriteLineNoTabs();
if (@enum.IsFlagCollection || @enum.IsObsolete)
{
sw.WriteLine("using System;");
sw.WriteLineNoTabs();
}

sw.WriteLine("// ReSharper disable InconsistentNaming");
sw.WriteLine("#pragma warning disable SA1139 // Use literal suffix notation instead of casting");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? I tried looking for places which break this rule but couldn't find any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mainly for the enumerations and their members - it shows up as a bunch of warnings otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's fine then - I did know what it was for, but couldn't find any examples where it would show warnings. Figured it couldn't hurt to ask

sw.WriteLineNoTabs();

sw.WriteLine($"namespace {Generator.Namespace}");
using (sw.BeginBlock())
{
// Document which functions use this enum.
var functions = enumCounts[@enum]
.Select(w =>
Generator.ClassName + (w.ExtensionName != "Core" ? "." + w.ExtensionName : string.Empty) + "." +
w.TrimmedName)
.Distinct()
.ToList();

sw.WriteLine("/// <summary>");
sw.WriteLine(
$"/// {(functions.Count >= 3 ? $"Used in {string.Join(", ", functions.Take(2).ToArray())} and {functions.Count - 2} other function{(functions.Count() - 2 > 1 ? "s" : string.Empty)}" : functions.Count() >= 1 ? $"Used in {string.Join(", ", functions.ToArray())}" : "Not used directly.")}");
sw.WriteLine($"/// {GetEnumUsageString(enumCounts, @enum)}");
sw.WriteLine("/// </summary>");

if (@enum.IsObsolete)
Expand Down Expand Up @@ -572,6 +581,39 @@ private void WriteEnums(EnumCollection enums, FunctionCollection wrappers)
}
}

/// <summary>
/// Gets a usage string for enumeration documentation that lists a sampling of the functions that the enum is
/// used in.
/// </summary>
/// <param name="enumCounts">A dictionary of the functions in which the enum is used.</param>
/// <param name="enum">The enum definition.</param>
/// <returns>The usage string.</returns>
private string GetEnumUsageString(IReadOnlyDictionary<EnumDefinition, List<FunctionDefinition>> enumCounts, EnumDefinition @enum)
{
var functions = enumCounts[@enum]
.Select(w =>
Generator.ClassName + (w.ExtensionName != "Core" ? "." + w.ExtensionName : string.Empty) + "." +
w.TrimmedName)
.Distinct()
.ToList();

if (functions.Count >= 3)
{
var additionalReference = functions.Count - 2 > 1
? "functions"
: "function";

return $"Used in {functions.Take(2).Humanize()}, as well as {functions.Count - 2} other {additionalReference}.";
}

if (functions.Count >= 1)
{
return $"Used in {functions.Humanize()}.";
}

return "Not used directly.";
}

private void WriteLicense(SourceWriter sw)
{
var licenseFilePath = Path.Combine(Program.Arguments.LicenseFile);
Expand Down
4 changes: 2 additions & 2 deletions src/Generator.Bind/FuncProcessor.cs
Expand Up @@ -831,8 +831,8 @@ private static FunctionDefinition CreateReturnTypeConvenienceWrapper(FunctionDef
return f;
}

var pSize = f.Parameters.Last().ParameterType;
if (!pSize.TypeName.ToLower().StartsWith("int") || pSize.IsPointer)
var sizeParameterType = f.Parameters.Last().ParameterType;
if (!sizeParameterType.TypeName.ToLower().StartsWith("int") || sizeParameterType.IsPointer)
{
return f;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Generator.Bind/Generators/GeneratorBase.cs
Expand Up @@ -112,14 +112,14 @@ public GeneratorBase()
/// <inheritdoc />
public virtual void LoadData()
{
var glTypemapPath = Path.Combine(Program.Arguments.InputPath, APITypemap);
var csTypemapPath = Path.Combine(Program.Arguments.InputPath, LanguageTypemap);
var apiTypemapPath = Path.Combine(Program.Arguments.InputPath, APITypemap);
var languageTypemapPath = Path.Combine(Program.Arguments.InputPath, LanguageTypemap);

var specificationFilePath = Path.Combine(Program.Arguments.InputPath, SpecificationFile);
var enumSpecificationPath = Path.Combine(Program.Arguments.InputPath, EnumSpecificationFile);

APITypes = SpecificationReader.ReadAPITypeMap(glTypemapPath);
LanguageTypes = SpecificationReader.ReadLanguageTypeMap(csTypemapPath);
APITypes = SpecificationReader.ReadAPITypeMap(apiTypemapPath);
LanguageTypes = SpecificationReader.ReadLanguageTypeMap(languageTypemapPath);

// Read enum signatures
Enums = SpecificationReader.ReadEnums(enumSpecificationPath, OverrideFiles, ProfileName, Version);
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.Bind/Generators/IGenerator.cs
Expand Up @@ -13,7 +13,7 @@ namespace Bind.Generators
internal interface IGenerator
{
/// <summary>
/// Gets a short-name identifier for the API (such as GL, GL4, ES10, etc)
/// Gets a short-name identifier for the API (such as GL, GL4, ES10, etc).
/// </summary>
string APIIdentifier { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/Generator.Bind/Structures/ConstantDefinition.cs
Expand Up @@ -12,7 +12,7 @@ namespace Bind.Structures
/// <summary>
/// Represents an opengl constant in C# format. Both the constant name and value
/// 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>
internal class ConstantDefinition : IComparable<ConstantDefinition>
{
Expand Down Expand Up @@ -95,7 +95,7 @@ public bool Unchecked
/// <summary>
/// Replces the Value of the given constant with the value referenced by the [c.Reference, c.Value] pair.
/// </summary>
/// <param name="c">The Constant to translate</param>
/// <param name="c">The Constant to translate.</param>
/// <param name="enums">The list of enums to check.</param>
/// <returns>True if the reference was found; false otherwise.</returns>
public static bool TranslateConstantWithReference(ConstantDefinition c, EnumCollection enums)
Expand Down
1 change: 0 additions & 1 deletion src/Generator.Bind/Structures/DocumentationDefinition.cs
Expand Up @@ -45,4 +45,3 @@ internal class DocumentationDefinition
public List<DocumentationParameterDefinition> Parameters { get; set; }
}
}

4 changes: 3 additions & 1 deletion src/Generator.Bind/Structures/EnumDefinition.cs
Expand Up @@ -12,7 +12,9 @@ namespace Bind.Structures
/// </summary>
internal class EnumDefinition
{
private string _name, _type;
private string _name;

private string _type;

/// <summary>
/// Gets or sets a value indicating whether the enum contains a collection of flags, i.e. 1, 2, 4, 8, ...
Expand Down
4 changes: 2 additions & 2 deletions src/Generator.Bind/Structures/FlowDirection.cs
Expand Up @@ -26,8 +26,8 @@
namespace Bind.Structures
{
/// <summary>
/// Enumarates the possible flows of a parameter (ie. is this parameter
/// used as input or as output?)
/// Enumerates the possible flows of a parameter (ie. is this parameter
/// used as input or as output?).
/// </summary>
public enum FlowDirection
{
Expand Down
6 changes: 3 additions & 3 deletions src/Generator.Bind/Structures/FunctionCollection.cs
Expand Up @@ -58,9 +58,9 @@ private void AddChecked(FunctionDefinition f)
replace |= !existing.Parameters.Any(p => p.ParameterType.IsUnsigned) &&
_unsignedFunctions.IsMatch(existing.Name) && !_unsignedFunctions.IsMatch(f.Name);
replace |=
(from pOld in existing.Parameters
join pNew in f.Parameters on pOld.Name equals pNew.Name
where pNew.ParameterType.ElementCount == 0 && pOld.ParameterType.ElementCount != 0
(from oldParameter in existing.Parameters
join newParameter in f.Parameters on oldParameter.Name equals newParameter.Name
where newParameter.ParameterType.ElementCount == 0 && oldParameter.ParameterType.ElementCount != 0
select true)
.Count() != 0;
if (replace)
Expand Down
5 changes: 4 additions & 1 deletion src/Generator.Bind/Structures/ParameterDefinition.cs
Expand Up @@ -132,7 +132,10 @@ public static FlowDirection GetFlowDirection(string direction)
return direction == "out" ? FlowDirection.Out : direction == "in" ? FlowDirection.In : FlowDirection.Undefined;
}

/// <inheritdoc/>
/// <summary>
/// Gets a string that would declare this object in C# source code.
/// </summary>
/// <returns>The declaration string.</returns>
public string GetDeclarationString()
{
var sb = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.Bind/Structures/TypeDefinition.cs
Expand Up @@ -140,7 +140,7 @@ public string TypeName
/// <summary>
/// Gets a value indicating whether the type is an unsigned type.
/// </summary>
public bool IsUnsigned => (TypeName.Contains("UInt") || TypeName.Contains("Byte"));
public bool IsUnsigned => TypeName.Contains("UInt") || TypeName.Contains("Byte");

/// <summary>
/// Gets or sets the wrapper type hinting information for this definition.
Expand Down
4 changes: 2 additions & 2 deletions src/Generator.Bind/Utilities.cs
Expand Up @@ -196,7 +196,7 @@ internal static void Merge(EnumCollection currentEnums, EnumDefinition newEnum)
/// <summary>
/// Places a new constant in the specified enum, if it doesn't already exist.
/// The existing constant is replaced if the new has a numeric value and the old
/// has a reference value (eg 0x5 is preferred over AttribMask.Foo)
/// has a reference value (eg 0x5 is preferred over AttribMask.Foo).
/// </summary>
/// <param name="enumDefinition">The enumeration definiton.</param>
/// <param name="constantDefinition">The constant definition.</param>
Expand Down Expand Up @@ -226,7 +226,7 @@ internal static void Merge(EnumDefinition enumDefinition, ConstantDefinition con
/// Whether or not to return the extension name unmodified. If false, the extension name will be turned to title
/// case.
/// </param>
/// <returns>The extension name,</returns>
/// <returns>The extension name.</returns>
internal static string GetExtension(string name, bool returnUnmodified)
{
var match = Extensions.Match(name);
Expand Down