Browse Source

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

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
2997cdbef4
  1. 10
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/DeclareVariableInSmallestScope.cs
  3. 8
      ICSharpCode.Decompiler/Ast/NRefactoryExtensions.cs
  4. 4
      ICSharpCode.Decompiler/Ast/NameVariables.cs
  5. 20
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  6. 4
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  7. 1
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs
  8. 1
      ILSpy/MainWindow.xaml
  9. 6
      ILSpy/MainWindow.xaml.cs

10
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -514,7 +514,7 @@ namespace Decompiler
return MakeRef(new Ast.IdentifierExpression(((ParameterDefinition)operand).Name).WithAnnotation(operand)); return MakeRef(new Ast.IdentifierExpression(((ParameterDefinition)operand).Name).WithAnnotation(operand));
} }
case Code.Ldc_I4: case Code.Ldc_I4:
return PrimitiveExpression((int)operand, byteCode.InferredType); return MakePrimitive((int)operand, byteCode.InferredType);
case Code.Ldc_I8: case Code.Ldc_I8:
case Code.Ldc_R4: case Code.Ldc_R4:
case Code.Ldc_R8: case Code.Ldc_R8:
@ -763,7 +763,7 @@ namespace Decompiler
if (TypeAnalysis.IsBoolean(actualType)) if (TypeAnalysis.IsBoolean(actualType))
return expr; return expr;
if (actualIsIntegerOrEnum) { if (actualIsIntegerOrEnum) {
return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, PrimitiveExpression(0, actualType)); return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, MakePrimitive(0, actualType));
} else { } else {
return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression()); return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression());
} }
@ -771,8 +771,8 @@ namespace Decompiler
if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) { if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) {
return new ConditionalExpression { return new ConditionalExpression {
Condition = expr, Condition = expr,
TrueExpression = PrimitiveExpression(1, reqType), TrueExpression = MakePrimitive(1, reqType),
FalseExpression = PrimitiveExpression(0, reqType) FalseExpression = MakePrimitive(0, reqType)
}; };
} }
if (actualIsIntegerOrEnum && requiredIsIntegerOrEnum) { if (actualIsIntegerOrEnum && requiredIsIntegerOrEnum) {
@ -782,7 +782,7 @@ namespace Decompiler
} }
} }
Expression PrimitiveExpression(long val, TypeReference type) Expression MakePrimitive(long val, TypeReference type)
{ {
if (TypeAnalysis.IsBoolean(type) && val == 0) if (TypeAnalysis.IsBoolean(type) && val == 0)
return new Ast.PrimitiveExpression(false); return new Ast.PrimitiveExpression(false);

2
ICSharpCode.Decompiler/Ast/DeclareVariableInSmallestScope.cs

@ -34,6 +34,8 @@ namespace Decompiler
Match m = assignmentPattern.Match(pos); Match m = assignmentPattern.Match(pos);
if (m != null && m.Get<IdentifierExpression>("ident").Single().Identifier == name) { if (m != null && m.Get<IdentifierExpression>("ident").Single().Identifier == name) {
result = new VariableDeclarationStatement(type, name, m.Get<Expression>("init").Single().Detach()); result = new VariableDeclarationStatement(type, name, m.Get<Expression>("init").Single().Detach());
result.Variables.Single().CopyAnnotationsFrom(((ExpressionStatement)pos).Expression);
result.CopyAnnotationsFrom(pos);
pos.ReplaceWith(result); pos.ReplaceWith(result);
} else { } else {
result = new VariableDeclarationStatement(type, name); result = new VariableDeclarationStatement(type, name);

8
ICSharpCode.Decompiler/Ast/NRefactoryExtensions.cs

@ -15,6 +15,14 @@ namespace Decompiler
return node; return node;
} }
public static T CopyAnnotationsFrom<T>(this T node, AstNode other) where T : AstNode
{
foreach (var annotation in other.Annotations<object>()) {
node.AddAnnotation(annotation);
}
return node;
}
public static T Detach<T>(this T node) where T : AstNode public static T Detach<T>(this T node) where T : AstNode
{ {
node.Remove(); node.Remove();

4
ICSharpCode.Decompiler/Ast/NameVariables.cs

@ -99,10 +99,10 @@ namespace Decompiler
case ILCode.Ldfld: case ILCode.Ldfld:
// Use the field name only if it's not a field on this (avoid confusion between local variables and fields) // Use the field name only if it's not a field on this (avoid confusion between local variables and fields)
if (!(expr.Arguments[0].Code == ILCode.Ldarg && ((ParameterDefinition)expr.Arguments[0].Operand).Index < 0)) if (!(expr.Arguments[0].Code == ILCode.Ldarg && ((ParameterDefinition)expr.Arguments[0].Operand).Index < 0))
return ((FieldReference)expr.Operand).Name; return CleanUpVariableName(((FieldReference)expr.Operand).Name);
break; break;
case ILCode.Ldsfld: case ILCode.Ldsfld:
return ((FieldReference)expr.Operand).Name; return CleanUpVariableName(((FieldReference)expr.Operand).Name);
case ILCode.Call: case ILCode.Call:
case ILCode.Callvirt: case ILCode.Callvirt:
MethodReference mr = (MethodReference)expr.Operand; MethodReference mr = (MethodReference)expr.Operand;

20
ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using Mono.Cecil; using Mono.Cecil;
using Ast = ICSharpCode.NRefactory.CSharp; using Ast = ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
@ -142,7 +143,7 @@ namespace Decompiler.Transforms
public override object VisitAssignmentExpression(AssignmentExpression assignment, object data) public override object VisitAssignmentExpression(AssignmentExpression assignment, object data)
{ {
base.VisitAssignmentExpression(assignment, data); base.VisitAssignmentExpression(assignment, data);
// First, combine "x = x op y" into "x op= y" // Combine "x = x op y" into "x op= y"
BinaryOperatorExpression binary = assignment.Right as BinaryOperatorExpression; BinaryOperatorExpression binary = assignment.Right as BinaryOperatorExpression;
if (binary != null && assignment.Operator == AssignmentOperatorType.Assign) { if (binary != null && assignment.Operator == AssignmentOperatorType.Assign) {
if (IsWithoutSideEffects(assignment.Left) && assignment.Left.Match(binary.Left) != null) { if (IsWithoutSideEffects(assignment.Left) && assignment.Left.Match(binary.Left) != null) {
@ -180,10 +181,27 @@ namespace Decompiler.Transforms
} }
if (assignment.Operator != AssignmentOperatorType.Assign) { if (assignment.Operator != AssignmentOperatorType.Assign) {
// If we found a shorter operator, get rid of the BinaryOperatorExpression: // If we found a shorter operator, get rid of the BinaryOperatorExpression:
assignment.CopyAnnotationsFrom(binary);
assignment.Right = binary.Right; assignment.Right = binary.Right;
} }
} }
} }
if (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) {
// detect increment/decrement
if (assignment.Right.Match(new PrimitiveExpression(1)) != null) {
// only if it's not a custom operator
if (assignment.Annotation<MethodReference>() == null) {
UnaryOperatorType type;
// When the parent is an expression statement, pre- or post-increment doesn't matter;
// so we can pick post-increment which is more commonly used (for (int i = 0; i < x; i++))
if (assignment.Parent is ExpressionStatement)
type = (assignment.Operator == AssignmentOperatorType.Add) ? UnaryOperatorType.PostIncrement : UnaryOperatorType.PostDecrement;
else
type = (assignment.Operator == AssignmentOperatorType.Add) ? UnaryOperatorType.Increment : UnaryOperatorType.Decrement;
assignment.ReplaceWith(new UnaryOperatorExpression(type, assignment.Left.Detach()).CopyAnnotationsFrom(assignment));
}
}
}
return null; return null;
} }

4
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -36,7 +36,7 @@ namespace Decompiler.ControlFlow
foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>().ToList()) { foreach(ILBlock block in method.GetSelfAndChildrenRecursive<ILBlock>().ToList()) {
ControlFlowGraph graph; ControlFlowGraph graph;
graph = BuildGraph(block.Body, (ILLabel)block.EntryGoto.Operand); graph = BuildGraph(block.Body, (ILLabel)block.EntryGoto.Operand);
graph.ComputeDominance(); graph.ComputeDominance(context.CancellationToken);
graph.ComputeDominanceFrontier(); graph.ComputeDominanceFrontier();
block.Body = FindLoops(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint, false); block.Body = FindLoops(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint, false);
} }
@ -49,7 +49,7 @@ namespace Decompiler.ControlFlow
// TODO: Fix // TODO: Fix
if (graph == null) if (graph == null)
continue; continue;
graph.ComputeDominance(); graph.ComputeDominance(context.CancellationToken);
graph.ComputeDominanceFrontier(); graph.ComputeDominanceFrontier();
block.Body = FindConditions(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint); block.Body = FindConditions(new HashSet<ControlFlowNode>(graph.Nodes.Skip(3)), graph.EntryPoint);
} }

1
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -646,6 +646,7 @@ namespace Decompiler
case MetadataType.IntPtr: case MetadataType.IntPtr:
return true; return true;
case MetadataType.Byte: case MetadataType.Byte:
case MetadataType.Char:
case MetadataType.UInt16: case MetadataType.UInt16:
case MetadataType.UInt32: case MetadataType.UInt32:
case MetadataType.UInt64: case MetadataType.UInt64:

1
ILSpy/MainWindow.xaml

@ -11,7 +11,6 @@
MinHeight="200" MinHeight="200"
UseLayoutRounding="True" UseLayoutRounding="True"
TextOptions.TextFormattingMode="Display" TextOptions.TextFormattingMode="Display"
Icon="pack://application:,,,/ILSpy;component/images/ILSpy.ico"
FocusManager.FocusedElement="{Binding ElementName=treeView}" FocusManager.FocusedElement="{Binding ElementName=treeView}"
> >
<Window.Resources> <Window.Resources>

6
ILSpy/MainWindow.xaml.cs

@ -26,6 +26,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;
@ -55,6 +56,11 @@ namespace ICSharpCode.ILSpy
this.sessionSettings = new SessionSettings(spySettings); this.sessionSettings = new SessionSettings(spySettings);
this.assemblyListManager = new AssemblyListManager(spySettings); this.assemblyListManager = new AssemblyListManager(spySettings);
if (Environment.OSVersion.Version.Major >= 6)
this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
else
this.Icon = Images.AssemblyLoading;
this.DataContext = sessionSettings; this.DataContext = sessionSettings;
this.Left = sessionSettings.WindowBounds.Left; this.Left = sessionSettings.WindowBounds.Left;
this.Top = sessionSettings.WindowBounds.Top; this.Top = sessionSettings.WindowBounds.Top;

Loading…
Cancel
Save