Added some more errorsand unit test pass

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-18 20:36:35 +01:00
1 親 5a2fcbf418
コミット 944ea0e6a0
7ファイル変更
+1219 -10

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

+5 -1
ファイルの表示
@@ -35,4 +35,8 @@ CMPS0027 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator,
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)
CMPS0031 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0031 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0032 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0033 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0034 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0035 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
+52
ファイルの表示
@@ -442,5 +442,57 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
isEnabledByDefault: true,
description: "Only unmanaged value type objects can be declared in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a pointer type.
/// </summary>
public static DiagnosticDescriptor PointerType { get; } = new(
id: "CMPS0032",
title: "Pointer type",
messageFormat: "A compute shader cannot have a pointer type declaration",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A compute shader cannot have a pointer type declaration.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a function pointer type.
/// </summary>
public static DiagnosticDescriptor FunctionPointer { get; } = new(
id: "CMPS0033",
title: "Function pointer type",
messageFormat: "A compute shader cannot have a function pointer type declaration",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A compute shader cannot have a function pointer type declaration.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an unsafe statement.
/// </summary>
public static DiagnosticDescriptor UnsafeStatement { get; } = new(
id: "CMPS0034",
title: "Unsafe statement",
messageFormat: "A compute shader cannot have an unsafe statement",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A compute shader cannot have an unsafe statement.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an unsafe modifier on a method or function.
/// </summary>
public static DiagnosticDescriptor UnsafeModifierOnMethodOrFunction { get; } = new(
id: "CMPS0035",
title: "Unsafe modifier on method or function",
messageFormat: "The unsafe modifier cannot be used in methods or functions used in a compute shader",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "The unsafe modifier cannot be used in methods or functions used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
}
+14 -1
ファイルの表示
@@ -44,7 +44,20 @@ namespace ComputeSharp.SourceGenerators.Extensions
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
where TRoot : SyntaxNode
{
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(sourceType).Type!;
// Skip immediately for function pointers
if (sourceType is FunctionPointerTypeSyntax)
{
return node.ReplaceNode(targetType, ParseTypeName("void*"));
}
// Handle the various possible type kinds
ITypeSymbol typeSymbol = sourceType switch
{
RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type).Type!,
PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType).Type!,
_ => semanticModel.GetTypeInfo(sourceType).Type!
};
string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat);
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
-2
ファイルの表示
@@ -106,8 +106,6 @@ namespace ComputeSharp.SourceGenerators
if (attribute is not null)
{
context.ReportDiagnostic(InvalidGroupSharedFieldDeclaration, fieldSymbol, structDeclarationSymbol, fieldSymbol.Name);
continue;
}
// Captured fields must be named type symbols
+41 -3
ファイルの表示
@@ -155,12 +155,16 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
var updatedNode = (MethodDeclarationSyntax?)base.Visit(node);
if (node!.Modifiers.Contains(Token(SyntaxKind.AsyncKeyword)))
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
this.context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
}
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
{
this.context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
}
if (updatedNode is not null)
{
var implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray());
@@ -252,6 +256,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
{
var updatedNode = (ImplicitObjectCreationExpressionSyntax)base.VisitImplicitObjectCreationExpression(node)!;
if (this.semanticModel.GetTypeInfo(node).Type is ITypeSymbol { IsUnmanagedType: false } type)
{
this.context.ReportDiagnostic(InvalidObjectCreationExpression, node, type);
}
TypeSyntax explicitType = IdentifierName("").ReplaceAndTrackType(node, this.semanticModel, this.discoveredTypes);
// Mutate the syntax like with explicit object creation expressions
@@ -345,11 +354,16 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
.WithAttributeLists(List<AttributeListSyntax>())
.WithIdentifier(Identifier($"__{this.currentMethod!.Identifier.Text}__{node.Identifier.Text}"));
if (node.Modifiers.Contains(Token(SyntaxKind.AsyncKeyword)))
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
this.context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
}
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
{
this.context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
}
this.localFunctionDepth--;
// HLSL doesn't support local functions, so we first process them as usual and then remove
@@ -762,6 +776,30 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
return base.VisitYieldStatement(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitFunctionPointerType(FunctionPointerTypeSyntax node)
{
this.context.ReportDiagnostic(DiagnosticDescriptors.FunctionPointer, node);
return base.VisitFunctionPointerType(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitPointerType(PointerTypeSyntax node)
{
this.context.ReportDiagnostic(DiagnosticDescriptors.PointerType, node);
return base.VisitPointerType(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitUnsafeStatement(UnsafeStatementSyntax node)
{
this.context.ReportDiagnostic(DiagnosticDescriptors.UnsafeStatement, node);
return base.VisitUnsafeStatement(node);
}
/// <inheritdoc/>
public override SyntaxToken VisitToken(SyntaxToken token)
{
@@ -10,11 +10,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests.Internals
{
[TestClass]
[TestCategory("SourceGenerator")]
public class SourceGeneratorTests
[TestCategory("AutoConstructorGenerator")]
public class AutoConstructorGeneratorTests
{
[TestMethod]
public void SequentialEnum()
public void GenerateConstructor()
{
string source = @"
using System.Numerics;
ファイル差分が大きすぎるため表示されません。 差分を読み込み