Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy

pull/285/head
Eusebiu Marcu 14 years ago
parent
commit
21100731fa
  1. 42
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  2. 5
      ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs
  3. 27
      ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs
  4. 1
      ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs
  5. 8
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  6. 2
      ILSpy/TextView/DecompilerTextView.cs
  7. 13
      NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

42
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -33,6 +33,8 @@ namespace ICSharpCode.Decompiler.Ast
readonly Stack<AstNode> nodeStack = new Stack<AstNode>();
int braceLevelWithinType = -1;
bool inDocumentationComment = false;
bool firstUsingDeclaration;
bool lastUsingDeclaration;
public TextOutputFormatter(ITextOutput output)
{
@ -62,6 +64,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -62,6 +64,11 @@ namespace ICSharpCode.Decompiler.Ast
return;
}
if (firstUsingDeclaration) {
output.MarkFoldStart(defaultCollapsed: true);
firstUsingDeclaration = false;
}
output.Write(identifier);
}
@ -86,6 +93,15 @@ namespace ICSharpCode.Decompiler.Ast @@ -86,6 +93,15 @@ namespace ICSharpCode.Decompiler.Ast
// return variable.OriginalVariable;
return variable;
}
var gotoStatement = node as GotoStatement;
if (gotoStatement != null)
{
var method = nodeStack.Select(nd => nd.Annotation<MethodReference>()).FirstOrDefault(mr => mr != null);
if (method != null)
return method.ToString() + gotoStatement.Label;
}
return null;
}
@ -109,6 +125,14 @@ namespace ICSharpCode.Decompiler.Ast @@ -109,6 +125,14 @@ namespace ICSharpCode.Decompiler.Ast
}
}
var label = node as LabelStatement;
if (label != null)
{
var method = nodeStack.Select(nd => nd.Annotation<MethodReference>()).FirstOrDefault(mr => mr != null);
if (method != null)
return method.ToString() + label.Label;
}
return null;
}
@ -167,6 +191,10 @@ namespace ICSharpCode.Decompiler.Ast @@ -167,6 +191,10 @@ namespace ICSharpCode.Decompiler.Ast
public void NewLine()
{
if (lastUsingDeclaration) {
output.MarkFoldEnd();
lastUsingDeclaration = false;
}
output.WriteLine();
}
@ -205,6 +233,15 @@ namespace ICSharpCode.Decompiler.Ast @@ -205,6 +233,15 @@ namespace ICSharpCode.Decompiler.Ast
public void StartNode(AstNode node)
{
if (nodeStack.Count == 0) {
if (IsUsingDeclaration(node)) {
firstUsingDeclaration = !IsUsingDeclaration(node.PrevSibling);
lastUsingDeclaration = !IsUsingDeclaration(node.NextSibling);
} else {
firstUsingDeclaration = false;
lastUsingDeclaration = false;
}
}
nodeStack.Push(node);
startLocations.Push(output.Location);
@ -215,6 +252,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -215,6 +252,11 @@ namespace ICSharpCode.Decompiler.Ast
}
}
private bool IsUsingDeclaration(AstNode node)
{
return node is UsingDeclaration || node is UsingAliasDeclaration;
}
public void EndNode(AstNode node)
{
if (nodeStack.Pop() != node)

5
ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs

@ -59,9 +59,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -59,9 +59,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
foreach (var v in variablesToDeclare) {
if (v.ReplacedAssignment == null) {
BlockStatement block = (BlockStatement)v.InsertionPoint.Parent;
var decl = new VariableDeclarationStatement((AstType)v.Type.Clone(), v.Name);
if (v.ILVariable != null)
decl.Variables.Single().AddAnnotation(v.ILVariable);
block.Statements.InsertBefore(
v.InsertionPoint,
new VariableDeclarationStatement((AstType)v.Type.Clone(), v.Name));
decl);
}
}
// First do all the insertions, then do all the replacements. This is necessary because a replacement might remove our reference point from the AST.

27
ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.Decompiler.Ast.Transforms
{
class FlattenSwitchBlocks : IAstTransform
{
public void Run(AstNode compilationUnit)
{
foreach (var switchSection in compilationUnit.Descendants.OfType<SwitchSection>())
{
if (switchSection.Statements.Count != 1)
continue;
var blockStatement = switchSection.Statements.First() as BlockStatement;
if (blockStatement == null || blockStatement.Statements.Any(st => st is VariableDeclarationStatement))
continue;
blockStatement.Remove();
blockStatement.Statements.MoveTo(switchSection.Statements);
}
}
}
}

1
ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs

@ -45,6 +45,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -45,6 +45,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
new IntroduceExtensionMethods(context), // must run after IntroduceUsingDeclarations
new IntroduceQueryExpressions(context), // must run after IntroduceExtensionMethods
new CombineQueryExpressions(context),
new FlattenSwitchBlocks(),
};
}

8
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -64,6 +64,7 @@ @@ -64,6 +64,7 @@
<Compile Include="Ast\Transforms\DecimalConstantTransform.cs" />
<Compile Include="Ast\Transforms\DeclareVariables.cs" />
<Compile Include="Ast\Transforms\DelegateConstruction.cs" />
<Compile Include="Ast\Transforms\FlattenSwitchBlocks.cs" />
<Compile Include="Ast\Transforms\IntroduceExtensionMethods.cs" />
<Compile Include="Ast\Transforms\IntroduceQueryExpressions.cs" />
<Compile Include="Ast\Transforms\IntroduceUnsafeModifier.cs" />
@ -131,12 +132,7 @@ @@ -131,12 +132,7 @@
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Ast" />
<Folder Include="Ast\Transforms" />
<Folder Include="Disassembler" />
<Folder Include="ILAst" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<Target Name="BeforeBuild">
<MSBuild Projects="$(MSBuildProjectDirectory)\..\BuildTools\UpdateAssemblyInfo\UpdateAssemblyInfo.csproj" Targets="Build" Properties="Configuration=Debug" />

2
ILSpy/TextView/DecompilerTextView.cs

@ -602,7 +602,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -602,7 +602,7 @@ namespace ICSharpCode.ILSpy.TextView
ClearLocalReferenceMarks();
if (references != null) {
foreach (var r in references) {
if (r.Reference == reference) {
if (reference.Equals(r.Reference)) {
var mark = textMarkerService.Create(r.StartOffset, r.Length);
mark.BackgroundColor = r.IsLocalTarget ? Colors.LightSeaGreen : Colors.GreenYellow;
localReferenceMarks.Add(mark);

13
NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1734,13 +1734,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1734,13 +1734,16 @@ namespace ICSharpCode.NRefactory.CSharp
label.AcceptVisitor (this, data);
first = false;
}
if(!(switchSection.Statements.FirstOrDefault() is BlockStatement))
NewLine();
if (policy.IndentCaseBody)
formatter.Indent ();
foreach (var statement in switchSection.Statements) {
NewLine ();
statement.AcceptVisitor (this, data);
}
foreach (var statement in switchSection.Statements)
statement.AcceptVisitor(this, data);
if (switchSection.NextSibling != null)
NewLine();
if (policy.IndentCaseBody)
formatter.Unindent ();

Loading…
Cancel
Save