From 7351489aeb081e3e9b9d4d5f06257a2a6b599ef9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 23 Aug 2019 19:14:40 +0200 Subject: [PATCH] Minor tweaks to the source code unwrapping --- .../Translation/MethodDecompiler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs index cd2e083f..3046b64f 100644 --- a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs @@ -189,6 +189,11 @@ namespace ComputeSharp.Shaders.Translation /// private static readonly Regex NestedClosureFieldRegex = new Regex(@"(?<=public )((?:\w+\.)+<>[\w_]+) (CS\$<>[\w_]+)(?=;)", RegexOptions.Compiled); + /// + /// A used to identify compiler generated fields + /// + private static readonly Regex CompilerGeneratedFieldRegex = new Regex(@"CS\$<>[\w_]+\.", RegexOptions.Compiled); + /// /// Unwraps all the nested captured fields in the given source code, moving them to the top level /// @@ -239,9 +244,13 @@ namespace ComputeSharp.Shaders.Translation builder.AppendLine(field.ToFullString()); string fields = builder.ToString().TrimEnd(' ', '\r', '\n'); + // Replace the field declarations Match match = NestedClosureFieldRegex.Match(source); - source = source.Remove(match.Index - 11, match.Length + 12); + source = source.Remove(match.Index - 11, match.Length + 12); // leading " public " and trailing ";" source = source.Insert(match.Index - 11, fields); + + // Adjust the method body to remove references to compiler generated fields + source = CompilerGeneratedFieldRegex.Replace(source, string.Empty); } return source;