Added diagnostics for shader properties
このコミットが含まれているのは:
1 親
e12169c11e
コミット
3147e8fade
4ファイル変更
+34
-32
検索条件に一致するファイルはありません
@@ -48,4 +48,5 @@ CMPS0040 | ComputeSharp.SourceGenerators.IComputeShaderSourceGenerator | Warning
|
||||
CMPS0041 | ComputeSharp.SourceGenerators.ShaderMethodSourceGenerator | Warning | ShaderMethodSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0042 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0043 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0044 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0044 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0045 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -617,5 +617,18 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
|
||||
isEnabledByDefault: true,
|
||||
description: "The DispatchSize type can only be used within the main body of a compute shader.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for a property declaration.
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor PropertyDeclaration = new(
|
||||
id: "CMPS0045",
|
||||
title: "Property declaration",
|
||||
messageFormat: "Property declarations cannot be used in a compute shader",
|
||||
category: typeof(IComputeShader).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "Property declarations cannot be used in a compute shader.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,9 @@ namespace ComputeSharp.SourceGenerators
|
||||
// Only process compute shader types
|
||||
if (!structDeclarationSymbol.Interfaces.Any(static interfaceSymbol => interfaceSymbol.Name == nameof(IComputeShader))) return;
|
||||
|
||||
// Properties are not supported
|
||||
DetectAndReportPropertyDeclarations(context, structDeclarationSymbol);
|
||||
|
||||
// We need to sets to track all discovered custom types and static methods
|
||||
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods = new(SymbolEqualityComparer.Default);
|
||||
@@ -405,6 +408,19 @@ namespace ComputeSharp.SourceGenerators
|
||||
.ToFullString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and reports all declared properties in a shader.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
private static void DetectAndReportPropertyDeclarations(GeneratorExecutionContext context, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType<IPropertySymbol>())
|
||||
{
|
||||
context.ReportDiagnostic(DiagnosticDescriptors.PropertyDeclaration, propertySymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする