Add initial 'CanvasEffectPropertyGenerator' type

このコミットが含まれているのは:
Sergio Pedri committed 2024-10-17 21:41:03 -07:00
1 親 e330bb5372
コミット 8185999b72
5ファイル変更
+73 -1

検索条件に一致するファイルはありません

+1
ファイルの表示
@@ -587,5 +587,6 @@ Global
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.D2D1\ComputeSharp.SwapChain.Shaders.D2D1.projitems*{f8bf7666-7ccf-4fe4-b055-2eba4bcd4564}*SharedItemsImports = 13
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{fa18ba9f-76bf-4de0-8d24-02fc7657e6cb}*SharedItemsImports = 5
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{febec83a-fe70-4d4b-9b00-76db31e75f17}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
@@ -0,0 +1,42 @@
using System.Threading;
using ComputeSharp.SourceGeneration.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace ComputeSharp.D2D1.WinUI.SourceGenerators;
/// <inheritdoc/>
partial class CanvasEffectPropertyGenerator
{
/// <summary>
/// A container for all the logic for <see cref="CanvasEffectPropertyGenerator"/>.
/// </summary>
private static partial class Execute
{
/// <summary>
/// Checks whether an input syntax node is a candidate property declaration for the generator.
/// </summary>
/// <param name="node">The input syntax node to check.</param>
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
/// <returns>Whether <paramref name="node"/> is a candidate property declaration.</returns>
public static bool IsCandidatePropertyDeclaration(SyntaxNode node, CancellationToken token)
{
// The node must be a property declaration with two accessors
if (node is not PropertyDeclarationSyntax { AccessorList.Accessors: { Count: 2 } accessors })
{
return false;
}
// The accessors must be a get and a set (with any accessibility)
if (accessors[0].Kind() is not (SyntaxKind.GetAccessorDeclaration or SyntaxKind.SetAccessorDeclaration) ||
accessors[1].Kind() is not (SyntaxKind.GetAccessorDeclaration or SyntaxKind.SetAccessorDeclaration))
{
return false;
}
// The property must be in a type with a base type (as it must derive from CanvasEffect)
return node.Parent?.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<ClassDeclarationSyntax>() == true;
}
}
}
+26
ファイルの表示
@@ -0,0 +1,26 @@
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.WinUI.SourceGenerators;
/// <summary>
/// A source generator creating implementations of effect properties.
/// </summary>
[Generator(LanguageNames.CSharp)]
public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerator
{
/// <summary>
/// The name of generator to include in the generated code.
/// </summary>
private const string GeneratorName = "ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator";
/// <inheritdoc/>
public void Initialize(IncrementalGeneratorInitializationContext context)
{
IncrementalValuesProvider<object?> propertyInfo =
context.SyntaxProvider
.ForAttributeWithMetadataName(
"ComputeSharp.D2D1.WinUI.GeneratedCanvasEffectPropertyAttribute",
Execute.IsCandidatePropertyDeclaration,
static (context, token) => (object?)null);
}
}
@@ -11,4 +11,7 @@
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>
<!-- Shared project with common helpers -->
<Import Project="..\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems" Label="Shared" />
</Project>
+1 -1
ファイルの表示
@@ -73,7 +73,7 @@
<EmbeddedResource Include="..\..\libs\arm64\dxil.dll" Link="ComputeSharp\Libraries\arm64\dxil.dll" />
</ItemGroup>
<!-- Shared project with common helpers -->
<!-- Shared projects with common helpers -->
<Import Project="..\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems" Label="Shared" />