
7 changed files with 109 additions and 57 deletions
-
27ICSharpCode.Decompiler/Ast/AstBuilder.cs
-
2ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs
-
55ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
-
2ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
-
28ICSharpCode.Decompiler/Ast/Transforms/SimplifyTypeReferences.cs
-
50ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs
-
2ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
@ -1,28 +0,0 @@ |
|||
using System; |
|||
|
|||
using ICSharpCode.NRefactory.CSharp; |
|||
|
|||
namespace Decompiler.Transforms.Ast |
|||
{ |
|||
public class SimplifyTypeReferences: DepthFirstAstVisitor<object, object> |
|||
{ |
|||
string currentNamepace = string.Empty; |
|||
string currentClass = null; |
|||
|
|||
public override object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) |
|||
{ |
|||
currentNamepace = namespaceDeclaration.Name; |
|||
base.VisitNamespaceDeclaration(namespaceDeclaration, data); |
|||
currentNamepace = string.Empty; |
|||
return null; |
|||
} |
|||
|
|||
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) |
|||
{ |
|||
currentClass = currentNamepace + "." + typeDeclaration.Name; |
|||
base.VisitTypeDeclaration(typeDeclaration, data); |
|||
currentClass = null; |
|||
return null; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,50 @@ |
|||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
|||
|
|||
using System; |
|||
using ICSharpCode.NRefactory.CSharp; |
|||
|
|||
namespace Decompiler.Transforms |
|||
{ |
|||
public static class TransformationPipeline |
|||
{ |
|||
static IAstVisitor<object, object>[] CreatePipeline() |
|||
{ |
|||
return new IAstVisitor<object, object>[] { |
|||
new DelegateConstruction(), |
|||
new ConvertConstructorCallIntoInitializer(), |
|||
new ReplaceMethodCallsWithOperators() |
|||
}; |
|||
} |
|||
|
|||
public static void RunTransformations(AstNode node) |
|||
{ |
|||
RunTransformationsUntil(node, v => false); |
|||
} |
|||
|
|||
public static void RunTransformationsUntil(AstNode node, Predicate<IAstVisitor<object, object>> abortCondition) |
|||
{ |
|||
if (node == null) |
|||
return; |
|||
for (int i = 0; i < 4; i++) { |
|||
if (Options.ReduceAstJumps) { |
|||
node.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null); |
|||
node.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null); |
|||
} |
|||
if (Options.ReduceAstLoops) { |
|||
node.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null); |
|||
} |
|||
if (Options.ReduceAstOther) { |
|||
node.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null); |
|||
node.AcceptVisitor(new Transforms.Ast.PushNegation(), null); |
|||
} |
|||
} |
|||
|
|||
foreach (var visitor in CreatePipeline()) { |
|||
if (abortCondition(visitor)) |
|||
return; |
|||
node.AcceptVisitor(visitor, null); |
|||
} |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue