From 673522fda1800dbb4086472b8c1f858e92aaebf5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 4 Sep 2019 23:21:53 +0200 Subject: [PATCH] Fixed handling of static methods with out parameters --- .../Translation/MethodDecompiler.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs index e29793c4..a6a0b3dc 100644 --- a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs @@ -208,11 +208,16 @@ namespace ComputeSharp.Shaders.Translation { string sourceCode = DecompileMethodOrDeclaringType(methodInfo), + prototype = sourceCode.Split(Environment.NewLine)[0], commentedSourceCode = $"// {methodInfo.Name}{Environment.NewLine}{sourceCode}", inFixedSourceCode = Regex.Replace(commentedSourceCode, @"(?().First(); + + return $"// {methodInfo.Name}{Environment.NewLine}{prototype}{Environment.NewLine}{block.ToFullString()}"; } /// @@ -319,14 +324,14 @@ namespace ComputeSharp.Shaders.Translation argument.Expression.IsKind(SyntaxKind.DeclarationExpression) let match = Regex.Match(argument.Expression.ToFullString(), @"([\w.]+) ([\w_]+)") let mappedType = HlslKnownTypes.GetMappedName(match.Groups[1].Value) - let declatation = $"{mappedType} {match.Groups[2].Value} = ({mappedType})0;" - select (match.Groups[1].Value, match.Groups[2].Value, declatation)).ToArray(); + let declaration = $"{mappedType} {match.Groups[2].Value} = ({mappedType})0;" + select declaration).ToArray(); // Insert the explicit declarations at the start of the method int start = rootNode.Body.ChildNodes().First().SpanStart; - foreach (var item in outs.Reverse()) + foreach (var declaration in outs.Reverse()) { - source = source.Insert(start, $"{item.declatation}{Environment.NewLine} "); + source = source.Insert(start, $"{declaration}{Environment.NewLine} "); } // Remove the out keyword from the source