Complete prototype to also generate code

このコミットが含まれているのは:
Sergio Pedri committed 2024-10-17 21:41:03 -07:00
1 親 58ad9e8bc9
コミット 44959ce417
3ファイル変更
+125 -2

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

+27 -1
ファイルの表示
@@ -1,5 +1,6 @@
using ComputeSharp.D2D1.WinUI.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
@@ -41,6 +42,11 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
string typeNameWithNullabilityAnnotations = propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations();
bool isOldPropertyValueDirectlyReferenced = Execute.IsOldPropertyValueDirectlyReferenced(propertySymbol);
// We're using IsValueType here and not IsReferenceType to also cover unconstrained type parameter cases.
// This will cover both reference types as well T when the constraints are not struct or unmanaged.
// If this is true, it means the field storage can potentially be in a null state (even if not annotated).
bool isReferenceTypeOrUnconstraindTypeParameter = !propertySymbol.Type.IsValueType;
// Finally, get the hierarchy too
HierarchyInfo hierarchyInfo = HierarchyInfo.From(typeSymbol);
@@ -50,8 +56,28 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato
Hierarchy: hierarchyInfo,
PropertyName: propertySymbol.Name,
TypeNameWithNullabilityAnnotations: typeNameWithNullabilityAnnotations,
IsOldPropertyValueDirectlyReferenced: isOldPropertyValueDirectlyReferenced);
IsOldPropertyValueDirectlyReferenced: isOldPropertyValueDirectlyReferenced,
IsReferenceTypeOrUnconstraindTypeParameter: isReferenceTypeOrUnconstraindTypeParameter);
})
.Where(static item => item is not null)!;
// Split and group by containing type
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EquatableArray<CanvasEffectPropertyInfo> Properties)> groupedPropertyInfo =
propertyInfo
.GroupBy(keySelector: static item => item.Hierarchy, elementSelector: static item => item);
// Generate the source files, if any
context.RegisterSourceOutput(groupedPropertyInfo, static (context, item) =>
{
using IndentedTextWriter writer = new();
item.Hierarchy.WriteSyntax(
state: item.Properties,
writer: writer,
baseTypes: [],
memberCallbacks: [Execute.WritePropertyDeclarations]);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.g.cs", writer.ToString());
});
}
}