From 2b9a40371b639ed9c784132a8bfa1731494971e7 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 5 Aug 2019 22:02:14 +0200 Subject: [PATCH] Remove the dead LoopingTransform. Make ILInstruction.IsDirty debug-only, as it is only used for assertions now. --- .../IL/Instructions/ILInstruction.cs | 31 +++++----- .../IL/Transforms/LoopingTransform.cs | 61 ------------------- 2 files changed, 17 insertions(+), 75 deletions(-) delete mode 100644 ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index 261cf9b63..789634a57 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs @@ -125,32 +125,35 @@ namespace ICSharpCode.Decompiler.IL Debug.Assert(a == b); return a; } - + +#if DEBUG /// /// Gets whether this node (or any subnode) was modified since the last ResetDirty() call. /// /// - /// IsDirty is used by the LoopingTransform, and must not be used by individual transforms within the loop. + /// IsDirty is used by the StatementTransform, and must not be used by individual transforms within the loop. /// - public bool IsDirty { get; private set; } - - protected void MakeDirty() - { - for (ILInstruction inst = this; inst != null && !inst.IsDirty; inst = inst.parent) - inst.IsDirty = true; - } - + internal bool IsDirty { get; private set; } + /// /// Marks this node (and all subnodes) as IsDirty=false. /// - /// - /// IsDirty is used by the LoopingTransform, and must not be used by individual transforms within the loop. - /// - public void ResetDirty() + internal void ResetDirty() { foreach (ILInstruction inst in Descendants) inst.IsDirty = false; } +#endif + + [Conditional("DEBUG")] + protected private void MakeDirty() + { +#if DEBUG + for (ILInstruction inst = this; inst != null && !inst.IsDirty; inst = inst.parent) { + inst.IsDirty = true; + } +#endif + } const InstructionFlags invalidFlags = (InstructionFlags)(-1); diff --git a/ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs deleted file mode 100644 index 27f761feb..000000000 --- a/ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2016 Siegfried Pammer -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -using System; -using System.Collections.Generic; - -namespace ICSharpCode.Decompiler.IL.Transforms -{ - /// - /// Repeats the child transforms until the ILAst no longer changes (fixpoint iteration). - /// - public class LoopingBlockTransform : IBlockTransform - { - readonly IBlockTransform[] children; - bool running; - - public LoopingBlockTransform(params IBlockTransform[] children) - { - this.children = children; - } - - public void Run(Block block, BlockTransformContext context) - { - if (running) - throw new InvalidOperationException("LoopingBlockTransform already running. Transforms (and the CSharpDecompiler) are neither thread-safe nor re-entrant."); - running = true; - try { - int count = 1; - do { - block.ResetDirty(); - block.RunTransforms(children, context); - if (block.IsDirty) - context.Step($"Block is dirty; running loop iteration #{++count}.", block); - } while (block.IsDirty); - } finally { - running = false; - } - } - - public IReadOnlyCollection Transforms { - get { return children; } - } - } -} - -