Handle and emit diagnostic for initializer expressions

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-29 00:19:05 +01:00
1 親 45455abda9
コミット 1826122849
6ファイル変更
+42 -5

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

+1
ファイルの表示
@@ -77,3 +77,4 @@ CMPSD2D0067 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0068 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0069 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0070 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0071 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+13
ファイルの表示
@@ -1054,4 +1054,17 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "Shader types should be readonly (shaders cannot mutate their instance state while running, so shader types not being readonly makes them error prone).",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an initializer expression.
/// </summary>
public static readonly DiagnosticDescriptor InitializerExpression = new(
id: "CMPSD2D0071",
title: "Initializer expression",
messageFormat: "An initializer expression cannot be used in a pixel shader",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "An initializer expression cannot be used in a pixel shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
@@ -11,11 +11,17 @@ partial class HlslSourceRewriter
/// <inheritdoc/>
public override SyntaxNode? VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
{
AnonymousObjectCreationExpressionSyntax updatedNode = (AnonymousObjectCreationExpressionSyntax)base.VisitAnonymousObjectCreationExpression(node)!;
Diagnostics.Add(AnonymousObjectCreationExpression, node);
return updatedNode;
return base.VisitAnonymousObjectCreationExpression(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitInitializerExpression(InitializerExpressionSyntax node)
{
Diagnostics.Add(InitializerExpression, node);
return base.VisitInitializerExpression(node);
}
/// <inheritdoc/>
+5 -2
ファイルの表示
@@ -124,8 +124,11 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
Diagnostics.Add(InvalidObjectCreationExpression, node, type);
}
// Mutate the syntax like with explicit object creation expressions
if (updatedNode.ArgumentList!.Arguments.Count == 0)
// Mutate the syntax like with explicit object creation expressions. This also handles object
// initializer expressions. If those are used, the HLSL will just contain a default expression.
// There is a diagnostic being emitted to inform the users if that path is hit. If users want
// to create an object and immediately set some values, they should use a factory method.
if (updatedNode is not { ArgumentList.Arguments.Count: > 0, Initializer: null })
{
return CastExpression(targetType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
}
+1
ファイルの表示
@@ -64,3 +64,4 @@ CMPS0055 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Ser
CMPS0056 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0057 | ComputeSharp.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0058 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0059 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+13
ファイルの表示
@@ -830,4 +830,17 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "The [GloballyCoherent] attribute is only valid on ReadWriteBuffer<T> instance fields in compute shader types.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an initializer expression.
/// </summary>
public static readonly DiagnosticDescriptor InitializerExpression = new(
id: "CMPS0059",
title: "Initializer expression",
messageFormat: "An initializer expression cannot be used in a compute shader",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "An initializer expression cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}