diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index b1d881b6a..cef6c8b52 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -96,11 +96,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return base.VisitForStatement(forStatement); } - public override AstNode VisitWhileStatement(WhileStatement whileStatement) - { - return TransformDoWhile(whileStatement) ?? base.VisitWhileStatement(whileStatement); - } - public override AstNode VisitIfElseStatement(IfElseStatement ifElseStatement) { AstNode simplifiedIfElse = SimplifyCascadingIfElseStatements(ifElseStatement); @@ -276,54 +271,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms #endregion - #region doWhile - static readonly WhileStatement doWhilePattern = new WhileStatement { - Condition = new PrimitiveExpression(true), - EmbeddedStatement = new BlockStatement { - Statements = { - new Repeat(new AnyNode("statement")), - new IfElseStatement { - Condition = new AnyNode("condition"), - TrueStatement = new BlockStatement { new BreakStatement() } - } - } - }}; - - public DoWhileStatement TransformDoWhile(WhileStatement whileLoop) - { - Match m = doWhilePattern.Match(whileLoop); - if (m.Success) { - DoWhileStatement doLoop = new DoWhileStatement(); - doLoop.Condition = new UnaryOperatorExpression(UnaryOperatorType.Not, m.Get("condition").Single().Detach()); - //doLoop.Condition.AcceptVisitor(new PushNegation(), null); - BlockStatement block = (BlockStatement)whileLoop.EmbeddedStatement; - block.Statements.Last().Remove(); // remove if statement - doLoop.EmbeddedStatement = block.Detach(); - doLoop.CopyAnnotationsFrom(whileLoop); - whileLoop.ReplaceWith(doLoop); - - // we may have to extract variable definitions out of the loop if they were used in the condition: - foreach (var varDecl in block.Statements.OfType()) { - VariableInitializer v = varDecl.Variables.Single(); - if (doLoop.Condition.DescendantsAndSelf.OfType().Any(i => i.Identifier == v.Name)) { - AssignmentExpression assign = new AssignmentExpression(new IdentifierExpression(v.Name), v.Initializer.Detach()); - // move annotations from v to assign: - assign.CopyAnnotationsFrom(v); - v.RemoveAnnotations(); - // remove varDecl with assignment; and move annotations from varDecl to the ExpressionStatement: - varDecl.ReplaceWith(new ExpressionStatement(assign).CopyAnnotationsFrom(varDecl)); - varDecl.RemoveAnnotations(); - - // insert the varDecl above the do-while loop: - doLoop.Parent.InsertChildBefore(doLoop, varDecl, BlockStatement.StatementRole); - } - } - return doLoop; - } - return null; - } - #endregion - #region Automatic Properties static readonly PropertyDeclaration automaticPropertyPattern = new PropertyDeclaration { Attributes = { new Repeat(new AnyNode()) },