Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .silktouch/sdl-clangsharp.stout
Binary file not shown.
942 changes: 471 additions & 471 deletions sources/OpenAL/OpenAL/al/AL.gen.cs

Large diffs are not rendered by default.

262 changes: 131 additions & 131 deletions sources/OpenAL/OpenAL/al/IAL.gen.cs

Large diffs are not rendered by default.

7,262 changes: 3,606 additions & 3,656 deletions sources/OpenGL/OpenGL/gl/GL.gen.cs

Large diffs are not rendered by default.

1,552 changes: 770 additions & 782 deletions sources/OpenGL/OpenGL/gl/IGL.gen.cs

Large diffs are not rendered by default.

63 changes: 0 additions & 63 deletions sources/SilkTouch/SilkTouch/Mods/Common/AttributeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,69 +203,6 @@ out _
return meth;
}

/// <summary>
/// Adds a name prefix attribute to the given attribute list.
/// </summary>
/// <param name="attributeLists">The attribute lists to add the attribute to.</param>
/// <param name="category">The affix category.</param>
/// <param name="prefix">The value of the affix.</param>
/// <param name="addToInner">
/// Use true if the affix comes from the inside of the name.
/// Use false if not (outside or appended to end).
/// True means that the attribute is added to the start of the attribute list, meaning that the affix is re-appended earlier.
/// </param>
public static SyntaxList<AttributeListSyntax> AddNamePrefix(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved these to the new NameAffixer static class to keep everything related to name affixes together.

I also changed the API to use the new NameAffixType enum and changed it so that we only have the AddNameAffix method instead of AddNamePrefix/Suffix separately.

this IEnumerable<AttributeListSyntax> attributeLists,
string category,
string prefix,
bool addToInner = false
) => attributeLists.AddNamePrefixOrSuffix("Prefix", category, prefix, addToInner);

/// <summary>
/// Adds a name suffix attribute to the given attribute list.
/// </summary>
/// <param name="attributeLists">The attribute lists to add the attribute to.</param>
/// <param name="category">The affix category.</param>
/// <param name="suffix">The value of the affix.</param>
/// <param name="addToInner">
/// Use true if the affix comes from the inside of the name.
/// Use false if not (outside or appended to end).
/// True means that the attribute is added to the start of the attribute list, meaning that the affix is re-appended earlier.
/// </param>
public static SyntaxList<AttributeListSyntax> AddNameSuffix(
this IEnumerable<AttributeListSyntax> attributeLists,
string category,
string suffix,
bool addToInner = false
) => attributeLists.AddNamePrefixOrSuffix("Suffix", category, suffix, addToInner);

private static SyntaxList<AttributeListSyntax> AddNamePrefixOrSuffix(
this IEnumerable<AttributeListSyntax> attributeLists,
string type,
string category,
string affix,
bool addToInner = false
)
{
var typeArgument = AttributeArgument(
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{type}\"", type))
);
var categoryArgument = AttributeArgument(
LiteralExpression(
SyntaxKind.StringLiteralExpression,
Literal($"\"{category}\"", category)
)
);
var affixArgument = AttributeArgument(
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{affix}\"", affix))
);
var argumentList = AttributeArgumentList([typeArgument, categoryArgument, affixArgument]);

var attribute = AttributeList([Attribute(IdentifierName("NameAffix"), argumentList)]);

return addToInner ? [attribute, .. attributeLists] : [.. attributeLists, attribute];
}

/// <summary>
/// Gets the native name or returns the specified default.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion sources/SilkTouch/SilkTouch/Mods/ExtractNestedTyping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ _fallbackFromOuterFunctionPointer is not null
: default
)
.WithNativeName(currentNativeTypeName)
.AddNameSuffix("FunctionPointerDelegateType", "Delegate"),
.AddNameAffix(
NameAffixType.Suffix,
"FunctionPointerDelegateType",
"Delegate"
),
node
);
FunctionPointerTypes[currentNativeTypeName] = pfnInfo = (pfn, @delegate, [], []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.Options;
using Silk.NET.SilkTouch.Naming;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Silk.NET.SilkTouch.Mods;
Expand Down Expand Up @@ -131,7 +132,11 @@ or SyntaxKind.ProtectedKeyword
);

return node.WithAttributeLists(
node.AttributeLists.AddNameSuffix("InterceptedFunction", "Internal")
node.AttributeLists.AddNameAffix(
NameAffixType.Suffix,
"InterceptedFunction",
"Internal"
)
);
}
}
Expand Down
31 changes: 24 additions & 7 deletions sources/SilkTouch/SilkTouch/Mods/MixKhronosData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Silk.NET.SilkTouch.Clang;
using Silk.NET.SilkTouch.Mods.Metadata;
using Silk.NET.SilkTouch.Mods.Transformation;
using Silk.NET.SilkTouch.Naming;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Silk.NET.SilkTouch.Mods;
Expand Down Expand Up @@ -1891,7 +1892,7 @@ private SyntaxList<AttributeListSyntax> ProcessAndGetNewAttributes(
{
trimmedName = trimmedName[..^handleSuffix.Length];
attributeLists = attributeLists
.AddNameSuffix("KhronosHandleType", handleSuffix, true)
.AddNameAffix(NameAffixType.Suffix, "KhronosHandleType", handleSuffix, true)
.WithNativeName(trimmedName);
}
}
Expand All @@ -1903,7 +1904,11 @@ private SyntaxList<AttributeListSyntax> ProcessAndGetNewAttributes(
{
if (trimmedName.EndsWith(vendor))
{
attributeLists = attributeLists.AddNameSuffix("KhronosVendor", vendor);
attributeLists = attributeLists.AddNameAffix(
NameAffixType.Suffix,
"KhronosVendor",
vendor
);
trimmedName = trimmedName[..^vendor.Length];

break;
Expand All @@ -1921,7 +1926,8 @@ private SyntaxList<AttributeListSyntax> ProcessAndGetNewAttributes(
{
if (trimmedName.EndsWith(suffix))
{
attributeLists = attributeLists.AddNameSuffix(
attributeLists = attributeLists.AddNameAffix(
NameAffixType.Suffix,
"KhronosNonVendor",
suffix,
true
Expand All @@ -1943,7 +1949,8 @@ private SyntaxList<AttributeListSyntax> ProcessAndGetNewAttributes(
var dataTypeSuffix = trimmedName[match.Index..];
trimmedName = trimmedName[..match.Index];

attributeLists = attributeLists.AddNameSuffix(
attributeLists = attributeLists.AddNameAffix(
NameAffixType.Suffix,
"KhronosFunctionDataType",
dataTypeSuffix,
true
Expand Down Expand Up @@ -1998,7 +2005,11 @@ public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node)
if (groupInfo?.Namespace != null && typeName == $"{groupInfo.Namespace}Enum")
{
node = node.WithAttributeLists(
node.AttributeLists.AddNamePrefix("KhronosNamespaceEnum", groupInfo.Namespace)
node.AttributeLists.AddNameAffix(
NameAffixType.Prefix,
"KhronosNamespaceEnum",
groupInfo.Namespace
)
);
}

Expand Down Expand Up @@ -2042,7 +2053,12 @@ public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node)
{
// Mark the type vendor suffix as identified
node = node.WithAttributeLists(
node.AttributeLists.AddNameSuffix(vendorAffixType, typeVendor, true)
node.AttributeLists.AddNameAffix(
NameAffixType.Suffix,
vendorAffixType,
typeVendor,
true
)
);
}

Expand Down Expand Up @@ -2089,7 +2105,8 @@ .. node.Members.Select(member =>
{
// Identify for trimming
return member.WithAttributeLists(
member.AttributeLists.AddNameSuffix(
member.AttributeLists.AddNameAffix(
NameAffixType.Suffix,
"KhronosImpliedVendor",
typeVendor,
true
Expand Down
123 changes: 15 additions & 108 deletions sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
// The dictionary containing mappings from the original type names to the new names of the type and its members
var newNames = new Dictionary<string, RenamedType>();

var nameAffixer = new NameAffixer(visitor.AffixTypes, cfg.Affixes);
var nameAffixer = new PrettifyNamesAffixer(visitor.AffixTypes, cfg.Affixes);
var namePrettifier = new NamePrettifier(cfg.LongAcronymThreshold);

// Trim the trimmable names if the trimmer baseline is set
Expand Down Expand Up @@ -463,7 +463,7 @@ private string ApplyPrettifyOnlyPipeline(
string? container,
string name,
Dictionary<string, string> nameOverrides,
NameAffixer nameAffixer,
PrettifyNamesAffixer nameAffixer,
NamePrettifier namePrettifier
)
{
Expand Down Expand Up @@ -870,13 +870,6 @@ private record struct RenamedType(
Dictionary<string, string> Functions
);

private record struct NameAffix(
bool IsPrefix,
string Category,
string Affix,
int DeclarationOrder
Comment on lines -873 to -877
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This been moved to a separate file as a public type.

);

private record struct TypeData(List<string> NonFunctions, List<FunctionData> Functions);

private record struct FunctionData(string Name, MethodDeclarationSyntax Syntax);
Expand Down Expand Up @@ -958,52 +951,13 @@ _typeInProgress is not null
|| _enumInProgress is not null
|| node.Ancestors().OfType<BaseTypeDeclarationSyntax>().Any();

private bool TryGetAffixData(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced by NameAffixer.GetNameAffixes(), which returns an array directly instead of the TryGet pattern. The array is empty in the "false" case and does not allocate.

SyntaxList<AttributeListSyntax> attributeLists,
out NameAffix[] affixes
)
{
affixes = [];
var declarationOrder = 0;
foreach (var list in attributeLists)
{
foreach (var attribute in list.Attributes)
{
if (!attribute.IsAttribute("Silk.NET.Core.NameAffix"))
{
continue;
}

var argumentList = attribute.ArgumentList;
if (
argumentList != null
&& argumentList.Arguments[0].Expression
is LiteralExpressionSyntax { Token.Value: string type }
&& argumentList.Arguments[1].Expression
is LiteralExpressionSyntax { Token.Value: string category }
&& argumentList.Arguments[2].Expression
is LiteralExpressionSyntax { Token.Value: string affix }
)
{
affixes =
[
.. affixes,
new NameAffix(type == "Prefix", category, affix, declarationOrder),
];
declarationOrder++;
}
}
}

return affixes.Length != 0;
}

private void ReportTypeAffixData(
string typeIdentifier,
SyntaxList<AttributeListSyntax> attributeLists
)
{
if (!TryGetAffixData(attributeLists, out var affixes))
var affixes = attributeLists.GetNameAffixes();
if (affixes.Length == 0)
{
return;
}
Expand All @@ -1025,7 +979,8 @@ private void ReportMemberAffixData(
SyntaxList<AttributeListSyntax> attributeLists
)
{
if (!TryGetAffixData(attributeLists, out var affixData))
var affixes = attributeLists.GetNameAffixes();
if (affixes.Length == 0)
{
return;
}
Expand All @@ -1037,7 +992,7 @@ SyntaxList<AttributeListSyntax> attributeLists

// Note that TryAdd will lead to affixes for later members being silently dropped.
// This is to handle methods which have the same name and affixes. It is fine to drop the affixes in this case.
(typeAffixData.MemberAffixes ??= []).TryAdd(memberIdentifier, affixData);
(typeAffixData.MemberAffixes ??= []).TryAdd(memberIdentifier, affixes);
AffixTypes[typeIdentifier] = typeAffixData;
}

Expand Down Expand Up @@ -1286,7 +1241,7 @@ public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)

/// <param name="affixTypes">The affix data retrieved by the <see cref="Visitor"/>.</param>
/// <param name="config">The configuration from <see cref="Configuration.Affixes"/>.</param>
private class NameAffixer(
private class PrettifyNamesAffixer(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This class is the NameAffixer, but specialized for the needs of PrettifyNames.

Dictionary<string, TypeAffixData> affixTypes,
Dictionary<string, NameAffixConfiguration> config
)
Expand Down Expand Up @@ -1317,61 +1272,13 @@ public string RemoveAffixes(
return primary;
}

var originalPrimary = primary;

// Sort affixes so that the outer affixes are first
affixes.Sort(
static (a, b) =>
{
// Sort by descending declaration order
// Lower declaration order means the affix is closer to the inside of the name
return -a.DeclarationOrder.CompareTo(b.DeclarationOrder);
}
);

var prefixes = affixes.Where(x => x.IsPrefix).ToList();
var suffixes = affixes.Where(x => !x.IsPrefix).ToList();

RemoveSide(true, prefixes);
RemoveSide(false, suffixes);

if (originalPrimary != primary)
var stripped = NameAffixer.StripAffixes(primary, affixes);
if (stripped != primary)
{
secondary?.Add(originalPrimary);
secondary?.Add(primary);
}

return primary;

void RemoveSide(bool isPrefix, List<NameAffix> nameAffixes)
{
while (nameAffixes.Count > 0)
{
var removedAffix = false;
for (var i = 0; i < nameAffixes.Count; i++)
{
var affix = nameAffixes[i];
if (
isPrefix
? primary.StartsWith(affix.Affix)
: primary.EndsWith(affix.Affix)
)
{
primary = isPrefix
? primary[affix.Affix.Length..]
: primary[..^affix.Affix.Length];

nameAffixes.RemoveAt(i);
removedAffix = true;
break;
}
}

if (!removedAffix)
{
break;
}
}
}
return stripped;
}

/// <summary>
Expand Down Expand Up @@ -1479,7 +1386,7 @@ void CreateName(string name, Span<NameAffix> currentAffixes)
{
if (!GetConfiguration(affix).Remove)
{
if (affix.IsPrefix)
if (affix.Type == NameAffixType.Prefix)
{
name = affix.Affix + name;
}
Expand Down Expand Up @@ -1544,7 +1451,7 @@ private NameAffixConfiguration GetConfiguration(string category) =>
/// Removes identified affixes so that other trimmers can process the base name separately.
/// These affixes should be reapplied by <see cref="NameAffixerLateTrimmer"/>.
/// </summary>
private class NameAffixerEarlyTrimmer(NameAffixer affixer) : INameTrimmer
private class NameAffixerEarlyTrimmer(PrettifyNamesAffixer affixer) : INameTrimmer
{
/// <inheritdoc/>
public Version Version => new(0, 0, 0);
Expand Down Expand Up @@ -1583,7 +1490,7 @@ public void Trim(NameTrimmerContext context)
/// <summary>
/// Reapplies and transforms identified affixes based on <see cref="NameAffixConfiguration"/>.
/// </summary>
private class NameAffixerLateTrimmer(NameAffixer affixer) : INameTrimmer
private class NameAffixerLateTrimmer(PrettifyNamesAffixer affixer) : INameTrimmer
{
/// <inheritdoc/>
public Version Version => new(0, 0, 0);
Expand Down
Loading
Loading