Added error for declarations of invalid type

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-18 14:34:35 +01:00
1 親 922b65668c
コミット d55d5009c6
3ファイル変更
+36 -1

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

+2 -1
ファイルの表示
@@ -34,4 +34,5 @@ CMPS0026 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator,
CMPS0027 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0028 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0029 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0030 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0030 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0031 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -426,5 +426,21 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
isEnabledByDefault: true,
description: "A yield statement cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid object declaration.
/// <para>
/// Format: <c>"A variable of type {0} cannot be declared in a compute shader"</c>.
/// </para>
/// </summary>
public static DiagnosticDescriptor InvalidObjectDeclaration { get; } = new(
id: "CMPS0031",
title: "Invalid object declaration",
messageFormat: "A variable of type {0} cannot be declared in a compute shader (only unmanaged types are supported)",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Only unmanaged value type objects can be declared in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
}
+18
ファイルの表示
@@ -787,6 +787,24 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
return base.VisitUsingStatement(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
var updatedNode = (VariableDeclaratorSyntax)base.VisitVariableDeclarator(node)!;
if (node.Initializer is null &&
node.Parent is VariableDeclarationSyntax declaration &&
this.semanticModel.GetTypeInfo(declaration.Type).Type is ITypeSymbol { IsUnmanagedType: false } type)
{
this.context.ReportDiagnostic(Diagnostic.Create(
DiagnosticDescriptors.InvalidObjectDeclaration,
node.GetLocation(),
type));
}
return updatedNode;
}
/// <inheritdoc/>
public override SyntaxNode? VisitYieldStatement(YieldStatementSyntax node)
{