Minor bug fixes to source generator body rewrite
このコミットが含まれているのは:
1 親
9a220c1ada
コミット
6548d1acb3
3ファイル変更
+38
-15
検索条件に一致するファイルはありません
@@ -47,20 +47,11 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
IMethodSymbol methodDeclarationSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration)!;
|
||||
|
||||
// Extract the source from either a block or an expression body
|
||||
var methodWithBlockBody = methodDeclaration.WithBody(
|
||||
(methodDeclaration.Body, methodDeclaration.ExpressionBody) switch
|
||||
{
|
||||
(BlockSyntax block, _) => block,
|
||||
(_, ArrowExpressionClauseSyntax arrow) => Block(ExpressionStatement(arrow.Expression)),
|
||||
_ => Block()
|
||||
});
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var processedMethod = new ShaderSourceRewriter(semanticModel)
|
||||
.Visit(methodWithBlockBody)
|
||||
.NormalizeWhitespace()
|
||||
.ToFullString();
|
||||
var processedMethod = new ShaderSourceRewriter(semanticModel).Visit(methodDeclaration)!.WithoutTrivia();
|
||||
|
||||
// Produce the final method source
|
||||
var processedMethodSource = processedMethod.NormalizeWhitespace().ToFullString();
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
@@ -69,7 +60,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
Attribute(IdentifierName("ComputeSharp.IComputeShaderSource")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(structFullName))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(methodDeclarationSymbol.Name))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(processedMethod))))))
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(processedMethodSource))))))
|
||||
.WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList()))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword))))
|
||||
.NormalizeWhitespace()
|
||||
@@ -102,6 +93,13 @@ namespace ComputeSharp.SourceGenerators
|
||||
this.semanticModel = semanticModel;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public TNode? Visit<TNode>(TNode? node)
|
||||
where TNode : SyntaxNode
|
||||
{
|
||||
return (TNode?)base.Visit(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitParameter(ParameterSyntax node)
|
||||
{
|
||||
@@ -168,6 +166,12 @@ namespace ComputeSharp.SourceGenerators
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
return ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithBlockBody();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする