Browse Source

add back DeclareVariables-transform

pull/728/head
Siegfried Pammer 9 years ago
parent
commit
264fe83593
  1. 5
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  3. 22
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  4. 4
      ICSharpCode.Decompiler/CSharp/Transforms/DelegateConstruction.cs
  5. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  6. 2
      ILSpy.sln

5
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -41,6 +41,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -41,6 +41,11 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary>
public class LdTokenAnnotation {}
/// <summary>
/// Used by <see cref="Transforms.DeclareVariables"/> and <see cref="Transforms.DelegateConstruction"/>.
/// </summary>
sealed class CapturedVariableAnnotation {}
static class AnnotationExtensions
{
public static ExpressionWithILInstruction WithILInstruction(this Expression expression, ILInstruction instruction)

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.CSharp
new ReplaceMethodCallsWithOperators(),
new IntroduceUnsafeModifier(),
new AddCheckedBlocks(),
//new DeclareVariables(context), // should run after most transforms that modify statements
new DeclareVariables(), // should run after most transforms that modify statements
new ConvertConstructorCallIntoInitializer(), // must run after DeclareVariables
new DecimalConstantTransform(),
new IntroduceUsingDeclarations(),

22
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -21,7 +21,7 @@ using System.Collections.Generic; @@ -21,7 +21,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Analysis;
@ -42,17 +42,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -42,17 +42,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
public Statement InsertionPoint;
}
readonly CancellationToken cancellationToken;
CancellationToken cancellationToken;
List<VariableToDeclare> variablesToDeclare = new List<VariableToDeclare>();
public DeclareVariables(DecompilerContext context)
public void Run(AstNode rootNode, TransformContext context)
{
this.cancellationToken = context.CancellationToken;
}
public void Run(AstNode node)
{
Run(node, null);
RunInternal(rootNode, null);
// Declare all the variables at the end, after all the logic has run.
// This is done so that definite assignment analysis can work on a single representation and doesn't have to be updated
// when we change the AST.
@ -89,7 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -89,7 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
variablesToDeclare = null;
}
void Run(AstNode node, DefiniteAssignmentAnalysis daa)
void RunInternal(AstNode node, DefiniteAssignmentAnalysis daa)
{
BlockStatement block = node as BlockStatement;
if (block != null) {
@ -109,13 +105,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -109,13 +105,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
VariableInitializer initializer = varDecl.Variables.Single();
string variableName = initializer.Name;
ILVariable v = initializer.Annotation<ILVariable>();
bool allowPassIntoLoops = initializer.Annotation<DelegateConstruction.CapturedVariableAnnotation>() == null;
bool allowPassIntoLoops = initializer.Annotation<CapturedVariableAnnotation>() == null;
DeclareVariableInBlock(daa, block, varDecl.Type, variableName, v, allowPassIntoLoops);
}
}
}
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
Run(child, daa);
RunInternal(child, daa);
}
}
@ -213,7 +209,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -213,7 +209,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
public static bool FindDeclarationPoint(DefiniteAssignmentAnalysis daa, VariableDeclarationStatement varDecl, BlockStatement block, out Statement declarationPoint)
{
string variableName = varDecl.Variables.Single().Name;
bool allowPassIntoLoops = varDecl.Variables.Single().Annotation<DelegateConstruction.CapturedVariableAnnotation>() == null;
bool allowPassIntoLoops = varDecl.Variables.Single().Annotation<CapturedVariableAnnotation>() == null;
return FindDeclarationPoint(daa, variableName, allowPassIntoLoops, block, out declarationPoint);
}
@ -319,7 +315,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -319,7 +315,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
static bool HasNestedBlocks(AstNode node)
{
return node is CatchClause || node is SwitchSection;
return node is CatchClause || node is NRefactory.CSharp.SwitchSection;
}
static bool UsesVariable(AstNode node, string variableName)

4
ICSharpCode.Decompiler/CSharp/Transforms/DelegateConstruction.cs

@ -49,10 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -49,10 +49,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
}
}
internal sealed class CapturedVariableAnnotation
{
}
List<string> currentlyUsedVariableNames = new List<string>();
public DelegateConstruction(DecompilerContext context) : base(context)

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -65,6 +65,7 @@ @@ -65,6 +65,7 @@
<Compile Include="CSharp\Annotations.cs" />
<Compile Include="CSharp\DecompilerSettings.cs" />
<Compile Include="CSharp\Transforms\DecimalConstantTransform.cs" />
<Compile Include="CSharp\Transforms\DeclareVariables.cs" />
<Compile Include="CSharp\Transforms\EscapeInvalidIdentifiers.cs" />
<Compile Include="CSharp\Transforms\FixNameCollisions.cs" />
<Compile Include="CSharp\Transforms\IntroduceUsingDeclarations.cs" />

2
ILSpy.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# SharpDevelop 5.1
# SharpDevelop 5.2
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"

Loading…
Cancel
Save