From 4652a5a1cdd3f58b066bdab175e4ca47d9230660 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 9 Apr 2022 17:12:14 +0200 Subject: [PATCH] Fix discovery of bytecode attributes --- .../Extensions/ISymbolExtensions.cs | 17 +++-------------- ...1ShaderGenerator.CreateLoadBytecodeMethod.cs | 4 ++-- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/Extensions/ISymbolExtensions.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/Extensions/ISymbolExtensions.cs index 9481f70e..d2d8a5ed 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/Extensions/ISymbolExtensions.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/Extensions/ISymbolExtensions.cs @@ -30,17 +30,6 @@ internal static class ISymbolExtensions .WithMemberOptions(SymbolDisplayMemberOptions.IncludeContainingType) .WithParameterOptions(SymbolDisplayParameterOptions.None); - /// - /// Checks whether or not a given type symbol has a specified full name. - /// - /// The input instance to check. - /// The full name to check. - /// Whether has a full name equals to . - public static bool HasFullyQualifiedName(this ISymbol symbol, string name) - { - return symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) == name; - } - /// /// Gets the full metadata name for a given instance. /// @@ -145,19 +134,19 @@ internal static class ISymbolExtensions } /// - /// Tries to get an attribute with the specified full name. + /// Tries to get an attribute with the specified full metadata name. /// /// The input instance to check. /// The attribute name to look for. /// The resulting attribute data, if found. /// Whether or not has an attribute with the specified name. - public static bool TryGetAttributeWithFullyQualifiedName(this ISymbol symbol, string name, out AttributeData? attributeData) + public static bool TryGetAttributeWithFullMetadataName(this ISymbol symbol, string name, out AttributeData? attributeData) { ImmutableArray attributes = symbol.GetAttributes(); foreach (AttributeData attribute in attributes) { - if (attribute.AttributeClass?.HasFullyQualifiedName(name) == true) + if (attribute.AttributeClass?.GetFullMetadataName() == name) { attributeData = attribute; diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs index a5df02f2..ff9806de 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs @@ -29,7 +29,7 @@ partial class ID2D1ShaderGenerator /// The shader profile to use to compile the shader, if present. public static D2D1ShaderProfile? GetShaderProfile(INamedTypeSymbol structDeclarationSymbol) { - if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedName("ComputeSharp.D2D1Interop.D2DEmbeddedBytecodeAttribute", out AttributeData? attributeData)) + if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1Interop.D2DEmbeddedBytecodeAttribute", out AttributeData? attributeData)) { return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } @@ -44,7 +44,7 @@ partial class ID2D1ShaderGenerator /// Whether the shader only has simple inputs. public static bool IsSimpleInputShader(INamedTypeSymbol structDeclarationSymbol) { - if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedName("ComputeSharp.D2D1Interop.D2DInputCountAttribute", out AttributeData? inputCountAttribute)) + if (!structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1Interop.D2DInputCountAttribute", out AttributeData? inputCountAttribute)) { return false; }