From 8f9134eec7a6678fe68a7e57ee9fc3557704e689 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 Sep 2024 17:47:05 +0200 Subject: [PATCH] Strip explicit interface specifier from entry points --- .../SyntaxRewriters/ExecuteMethodRewriter.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs index 4fdb0251..65c4d830 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs @@ -24,6 +24,22 @@ internal abstract class ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceR return (TNode?)base.Visit(node); } + /// + public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node) + { + MethodDeclarationSyntax updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList()); + + // The entry point might be an explicit interface method implementation. In that case, + // the transpiled method will have the rewritten interface name as a prefix for the + // method name, which we don't want (it's invalid HLSL). So in that case, remove it. + if (updatedNode.ExplicitInterfaceSpecifier is not null) + { + updatedNode = updatedNode.WithExplicitInterfaceSpecifier(null); + } + + return updatedNode; + } + /// public override SyntaxNode? VisitParameterList(ParameterListSyntax node) {