Browse Source

Merge branch 'master' into bookmarks

pull/263/head
Ronny Klier 14 years ago
parent
commit
9a160befbd
  1. 8
      Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs
  2. 1
      Debugger/ILSpy.Debugger/Commands/DebuggerCommands.cs
  3. 5
      Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj
  4. 10
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  5. 2335
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  6. 61
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  7. 23
      ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs
  8. 17
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  9. 13
      ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs
  10. 4
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  11. 2
      ICSharpCode.Decompiler/ITextOutput.cs
  12. 2
      ICSharpCode.Decompiler/PlainTextOutput.cs
  13. 23
      ILSpy.BamlDecompiler/CecilTypeResolver.cs
  14. 55
      ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarMargin.cs
  15. 4
      ILSpy.SharpDevelop.LGPL/AvalonEdit/TextMarkerService.cs
  16. 21
      ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmark.cs
  17. 10
      ILSpy.SharpDevelop.LGPL/Bookmarks/CurrentLineBookmark.cs
  18. 5
      ILSpy.SharpDevelop.LGPL/DebugInformation.cs
  19. 8
      ILSpy.SharpDevelop.LGPL/ILSpy.SharpDevelop.LGPL.csproj
  20. 2
      ILSpy.SharpDevelop.LGPL/Models/ToolTipRequestEventArgs.cs
  21. 20
      ILSpy.SharpDevelop.LGPL/Services/DebuggerService.cs
  22. 0
      ILSpy.SharpDevelop.LGPL/Services/IDebugger.cs
  23. 11
      ILSpy.SharpDevelop.LGPL/Services/ParserService.cs
  24. 4
      ILSpy/AboutPage.cs
  25. 10
      ILSpy/App.xaml.cs
  26. 9
      ILSpy/TextView/AvalonEditTextOutput.cs
  27. 34
      ILSpy/TextView/DecompilerTextView.cs
  28. 5
      ILSpy/TextView/ReferenceElementGenerator.cs
  29. 8
      ILSpy/TreeNodes/EventTreeNode.cs
  30. 6
      ILSpy/TreeNodes/FieldTreeNode.cs
  31. 13
      ILSpy/TreeNodes/ILSpyTreeNode.cs
  32. 6
      ILSpy/TreeNodes/MethodTreeNode.cs
  33. 13
      ILSpy/TreeNodes/PropertyTreeNode.cs
  34. 2
      ILSpy/TreeNodes/TypeTreeNode.cs
  35. 41
      ILSpy/XmlDoc/XmlDocKeyProvider.cs
  36. 3
      ILSpy/XmlDoc/XmlDocLoader.cs
  37. 5
      SharpTreeView/SharpTreeNode.cs
  38. 4
      SharpTreeView/Themes/Generic.xaml

8
Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs

@ -36,14 +36,10 @@ namespace ICSharpCode.ILSpy.Debugger.Commands
} }
// no bookmark on the line: create a new breakpoint // no bookmark on the line: create a new breakpoint
MemberReference memberReference;
if (!DebugInformation.DecompiledMemberReferences.TryGetValue(storageEntry.Key, out memberReference)) {
continue;
}
DebuggerService.ToggleBreakpointAt( DebuggerService.ToggleBreakpointAt(
memberReference, instruction.MemberMapping.MemberReference,
line, line,
token,
instruction.ILInstructionOffset, instruction.ILInstructionOffset,
DebugInformation.Language); DebugInformation.Language);
break; break;

1
Debugger/ILSpy.Debugger/Commands/DebuggerCommands.cs

@ -307,6 +307,7 @@ namespace ICSharpCode.ILSpy.Debugger.Commands
public override void Execute(object parameter) public override void Execute(object parameter)
{ {
if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning) { if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning) {
CurrentLineBookmark.Remove();
CurrentDebugger.Continue(); CurrentDebugger.Continue();
MainWindow.Instance.SetStatus("Running...", Brushes.Black); MainWindow.Instance.SetStatus("Running...", Brushes.Black);
} }

5
Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj

@ -87,8 +87,6 @@
<Compile Include="Models\TreeModel\TreeNode.cs" /> <Compile Include="Models\TreeModel\TreeNode.cs" />
<Compile Include="Models\TreeModel\Utils.cs" /> <Compile Include="Models\TreeModel\Utils.cs" />
<Compile Include="Services\Debugger\DebuggerHelper.cs" /> <Compile Include="Services\Debugger\DebuggerHelper.cs" />
<Compile Include="Services\Debugger\DebuggerService.cs" />
<Compile Include="Services\Debugger\IDebugger.cs" />
<Compile Include="Services\Debugger\ListHelper.cs" /> <Compile Include="Services\Debugger\ListHelper.cs" />
<Compile Include="Services\Debugger\TypeResolverExtension.cs" /> <Compile Include="Services\Debugger\TypeResolverExtension.cs" />
<Compile Include="Services\Debugger\WindowsDebugger.cs" /> <Compile Include="Services\Debugger\WindowsDebugger.cs" />
@ -96,13 +94,11 @@
<Compile Include="Services\ImageService\ImageService.cs" /> <Compile Include="Services\ImageService\ImageService.cs" />
<Compile Include="Models\RunningProcess.cs" /> <Compile Include="Models\RunningProcess.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\ParserService\ParserService.cs" />
<Compile Include="ToolTips\DebuggerPopup.cs" /> <Compile Include="ToolTips\DebuggerPopup.cs" />
<Compile Include="ToolTips\DebuggerTooltipControl.xaml.cs"> <Compile Include="ToolTips\DebuggerTooltipControl.xaml.cs">
<DependentUpon>DebuggerTooltipControl.xaml</DependentUpon> <DependentUpon>DebuggerTooltipControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="ToolTips\LazyItemsControl.cs" /> <Compile Include="ToolTips\LazyItemsControl.cs" />
<Compile Include="ToolTips\Models\ToolTipRequestEventArgs.cs" />
<Compile Include="ToolTips\TextEditorListener.cs" /> <Compile Include="ToolTips\TextEditorListener.cs" />
<Compile Include="ToolTips\VirtualizingIEnumerable.cs" /> <Compile Include="ToolTips\VirtualizingIEnumerable.cs" />
<Compile Include="UI\AttachToProcessWindow.xaml.cs"> <Compile Include="UI\AttachToProcessWindow.xaml.cs">
@ -131,7 +127,6 @@
<Folder Include="Models\TreeModel" /> <Folder Include="Models\TreeModel" />
<Folder Include="Commands" /> <Folder Include="Commands" />
<Folder Include="ToolTips" /> <Folder Include="ToolTips" />
<Folder Include="ToolTips\Models" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="ToolTips\DebuggerTooltipControl.xaml" /> <Page Include="ToolTips\DebuggerTooltipControl.xaml" />

10
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -1,6 +1,7 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.ComponentModel.Composition;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -27,6 +28,7 @@ using StackFrame = Debugger.StackFrame;
namespace ICSharpCode.ILSpy.Debugger.Services namespace ICSharpCode.ILSpy.Debugger.Services
{ {
[Export(typeof(IDebugger))]
public class WindowsDebugger : IDebugger public class WindowsDebugger : IDebugger
{ {
enum StopAttachedProcessDialogResult { enum StopAttachedProcessDialogResult {
@ -283,7 +285,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
int key = frame.MethodInfo.MetadataToken; int key = frame.MethodInfo.MetadataToken;
// get the mapped instruction from the current line marker or the next one // get the mapped instruction from the current line marker or the next one
if (!DebugInformation.CodeMappings.ContainsKey(key)) if (DebugInformation.CodeMappings == null || !DebugInformation.CodeMappings.ContainsKey(key))
return null; return null;
return DebugInformation.CodeMappings[key].GetInstructionByTokenAndOffset(key, frame.IP, out isMatch); return DebugInformation.CodeMappings[key].GetInstructionByTokenAndOffset(key, frame.IP, out isMatch);
@ -550,7 +552,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
debugger, debugger,
bookmark.MemberReference.DeclaringType.FullName, bookmark.MemberReference.DeclaringType.FullName,
bookmark.LineNumber, bookmark.LineNumber,
bookmark.MemberReference.MetadataToken.ToInt32(), bookmark.FunctionToken,
bookmark.ILRange.From, bookmark.ILRange.From,
bookmark.IsEnabled); bookmark.IsEnabled);
@ -796,12 +798,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services
int line; int line;
MemberReference memberReference; MemberReference memberReference;
if (null != DebugInformation.CodeMappings && if (DebugInformation.CodeMappings != null &&
DebugInformation.CodeMappings.ContainsKey(token) && DebugInformation.CodeMappings.ContainsKey(token) &&
DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out memberReference, out line)) { DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out memberReference, out line)) {
DebugInformation.DebugStepInformation = null; // we do not need to step into/out DebugInformation.DebugStepInformation = null; // we do not need to step into/out
DebuggerService.RemoveCurrentLineMarker(); DebuggerService.RemoveCurrentLineMarker();
DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0, ilOffset);
} }
else { else {
StepIntoUnknownFrame(frame); StepIntoUnknownFrame(frame);

2335
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

File diff suppressed because it is too large Load Diff

61
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -43,12 +43,26 @@ namespace ICSharpCode.Decompiler.Ast
public void WriteIdentifier(string identifier) public void WriteIdentifier(string identifier)
{ {
MemberReference memberRef = GetCurrentMemberReference(); object memberRef = GetCurrentMemberReference();
if (memberRef != null) if (memberRef != null) {
output.WriteReference(identifier, memberRef); output.WriteReference(identifier, memberRef);
else return;
output.Write(identifier); }
var definition = GetCurrentLocalDefinition();
if (definition != null) {
output.WriteDefinition(identifier, definition);
return;
}
memberRef = GetCurrentLocalReference();
if (memberRef != null) {
output.WriteReference(identifier, memberRef, true);
return;
}
output.Write(identifier);
} }
MemberReference GetCurrentMemberReference() MemberReference GetCurrentMemberReference()
@ -60,6 +74,43 @@ namespace ICSharpCode.Decompiler.Ast
} }
return memberRef; return memberRef;
} }
object GetCurrentLocalReference()
{
AstNode node = nodeStack.Peek();
ILVariable variable = node.Annotation<ILVariable>();
if (variable != null) {
if (variable.OriginalParameter != null)
return variable.OriginalParameter;
//if (variable.OriginalVariable != null)
// return variable.OriginalVariable;
return variable;
}
return null;
}
object GetCurrentLocalDefinition()
{
AstNode node = nodeStack.Peek();
var parameterDef = node.Annotation<ParameterDefinition>();
if (parameterDef != null)
return parameterDef;
if (node is VariableInitializer || node is CatchClause || node is ForeachStatement) {
var variable = node.Annotation<ILVariable>();
if (variable != null) {
if (variable.OriginalParameter != null)
return variable.OriginalParameter;
//if (variable.OriginalVariable != null)
// return variable.OriginalVariable;
return variable;
} else {
}
}
return null;
}
public void WriteKeyword(string keyword) public void WriteKeyword(string keyword)
{ {

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

@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Analysis; using ICSharpCode.NRefactory.CSharp.Analysis;
@ -35,6 +36,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
{ {
public AstType Type; public AstType Type;
public string Name; public string Name;
public ILVariable ILVariable;
public AssignmentExpression ReplacedAssignment; public AssignmentExpression ReplacedAssignment;
public Statement InsertionPoint; public Statement InsertionPoint;
@ -67,9 +69,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (v.ReplacedAssignment != null) { if (v.ReplacedAssignment != null) {
// We clone the right expression so that it doesn't get removed from the old ExpressionStatement, // We clone the right expression so that it doesn't get removed from the old ExpressionStatement,
// which might be still in use by the definite assignment graph. // which might be still in use by the definite assignment graph.
VariableInitializer initializer = new VariableInitializer(v.Name, v.ReplacedAssignment.Right.Detach()).CopyAnnotationsFrom(v.ReplacedAssignment).WithAnnotation(v.ILVariable);
VariableDeclarationStatement varDecl = new VariableDeclarationStatement { VariableDeclarationStatement varDecl = new VariableDeclarationStatement {
Type = (AstType)v.Type.Clone(), Type = (AstType)v.Type.Clone(),
Variables = { new VariableInitializer(v.Name, v.ReplacedAssignment.Right.Detach()).CopyAnnotationsFrom(v.ReplacedAssignment) } Variables = { initializer }
}; };
ExpressionStatement es = v.ReplacedAssignment.Parent as ExpressionStatement; ExpressionStatement es = v.ReplacedAssignment.Parent as ExpressionStatement;
if (es != null) { if (es != null) {
@ -100,9 +103,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
daa = new DefiniteAssignmentAnalysis(block, cancellationToken); daa = new DefiniteAssignmentAnalysis(block, cancellationToken);
} }
foreach (VariableDeclarationStatement varDecl in variables) { foreach (VariableDeclarationStatement varDecl in variables) {
string variableName = varDecl.Variables.Single().Name; VariableInitializer initializer = varDecl.Variables.Single();
bool allowPassIntoLoops = varDecl.Variables.Single().Annotation<DelegateConstruction.CapturedVariableAnnotation>() == null; string variableName = initializer.Name;
DeclareVariableInBlock(daa, block, varDecl.Type, variableName, allowPassIntoLoops); ILVariable v = initializer.Annotation<ILVariable>();
bool allowPassIntoLoops = initializer.Annotation<DelegateConstruction.CapturedVariableAnnotation>() == null;
DeclareVariableInBlock(daa, block, varDecl.Type, variableName, v, allowPassIntoLoops);
} }
} }
} }
@ -111,7 +116,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
} }
} }
void DeclareVariableInBlock(DefiniteAssignmentAnalysis daa, BlockStatement block, AstType type, string variableName, bool allowPassIntoLoops) void DeclareVariableInBlock(DefiniteAssignmentAnalysis daa, BlockStatement block, AstType type, string variableName, ILVariable v, bool allowPassIntoLoops)
{ {
// declarationPoint: The point where the variable would be declared, if we decide to declare it in this block // declarationPoint: The point where the variable would be declared, if we decide to declare it in this block
Statement declarationPoint = null; Statement declarationPoint = null;
@ -139,10 +144,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
foreach (AstNode child in stmt.Children) { foreach (AstNode child in stmt.Children) {
BlockStatement subBlock = child as BlockStatement; BlockStatement subBlock = child as BlockStatement;
if (subBlock != null) { if (subBlock != null) {
DeclareVariableInBlock(daa, subBlock, type, variableName, allowPassIntoLoops); DeclareVariableInBlock(daa, subBlock, type, variableName, v, allowPassIntoLoops);
} else if (HasNestedBlocks(child)) { } else if (HasNestedBlocks(child)) {
foreach (BlockStatement nestedSubBlock in child.Children.OfType<BlockStatement>()) { foreach (BlockStatement nestedSubBlock in child.Children.OfType<BlockStatement>()) {
DeclareVariableInBlock(daa, nestedSubBlock, type, variableName, allowPassIntoLoops); DeclareVariableInBlock(daa, nestedSubBlock, type, variableName, v, allowPassIntoLoops);
} }
} }
} }
@ -151,7 +156,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
// Try converting an assignment expression into a VariableDeclarationStatement // Try converting an assignment expression into a VariableDeclarationStatement
if (!TryConvertAssignmentExpressionIntoVariableDeclaration(declarationPoint, type, variableName)) { if (!TryConvertAssignmentExpressionIntoVariableDeclaration(declarationPoint, type, variableName)) {
// Declare the variable in front of declarationPoint // Declare the variable in front of declarationPoint
variablesToDeclare.Add(new VariableToDeclare { Type = type, Name = variableName, InsertionPoint = declarationPoint }); variablesToDeclare.Add(new VariableToDeclare { Type = type, Name = variableName, ILVariable = v, InsertionPoint = declarationPoint });
} }
} }
} }
@ -172,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (ae != null && ae.Operator == AssignmentOperatorType.Assign) { if (ae != null && ae.Operator == AssignmentOperatorType.Assign) {
IdentifierExpression ident = ae.Left as IdentifierExpression; IdentifierExpression ident = ae.Left as IdentifierExpression;
if (ident != null && ident.Identifier == variableName) { if (ident != null && ident.Identifier == variableName) {
variablesToDeclare.Add(new VariableToDeclare { Type = type, Name = variableName, ReplacedAssignment = ae }); variablesToDeclare.Add(new VariableToDeclare { Type = type, Name = variableName, ILVariable = ident.Annotation<ILVariable>(), ReplacedAssignment = ae });
return true; return true;
} }
} }

17
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -386,7 +386,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
} }
// Now create variables for all fields of the display class (except for those that we already handled as parameters) // Now create variables for all fields of the display class (except for those that we already handled as parameters)
List<Tuple<AstType, string>> variablesToDeclare = new List<Tuple<AstType, string>>(); List<Tuple<AstType, ILVariable>> variablesToDeclare = new List<Tuple<AstType, ILVariable>>();
foreach (FieldDefinition field in type.Fields) { foreach (FieldDefinition field in type.Fields) {
if (field.IsStatic) if (field.IsStatic)
continue; // skip static fields continue; // skip static fields
@ -397,8 +397,14 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
capturedVariableName = capturedVariableName.Substring(10); capturedVariableName = capturedVariableName.Substring(10);
EnsureVariableNameIsAvailable(blockStatement, capturedVariableName); EnsureVariableNameIsAvailable(blockStatement, capturedVariableName);
currentlyUsedVariableNames.Add(capturedVariableName); currentlyUsedVariableNames.Add(capturedVariableName);
variablesToDeclare.Add(Tuple.Create(AstBuilder.ConvertType(field.FieldType, field), capturedVariableName)); ILVariable ilVar = new ILVariable
dict[field] = new IdentifierExpression(capturedVariableName); {
IsGenerated = true,
Name = capturedVariableName,
Type = field.FieldType,
};
variablesToDeclare.Add(Tuple.Create(AstBuilder.ConvertType(field.FieldType, field), ilVar));
dict[field] = new IdentifierExpression(capturedVariableName).WithAnnotation(ilVar);
} }
// Now figure out where the closure was accessed and use the simpler replacement expression there: // Now figure out where the closure was accessed and use the simpler replacement expression there:
@ -414,15 +420,16 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
// Now insert the variable declarations (we can do this after the replacements only so that the scope detection works): // Now insert the variable declarations (we can do this after the replacements only so that the scope detection works):
Statement insertionPoint = blockStatement.Statements.FirstOrDefault(); Statement insertionPoint = blockStatement.Statements.FirstOrDefault();
foreach (var tuple in variablesToDeclare) { foreach (var tuple in variablesToDeclare) {
var newVarDecl = new VariableDeclarationStatement(tuple.Item1, tuple.Item2); var newVarDecl = new VariableDeclarationStatement(tuple.Item1, tuple.Item2.Name);
newVarDecl.Variables.Single().AddAnnotation(new CapturedVariableAnnotation()); newVarDecl.Variables.Single().AddAnnotation(new CapturedVariableAnnotation());
newVarDecl.Variables.Single().AddAnnotation(tuple.Item2);
blockStatement.Statements.InsertBefore(insertionPoint, newVarDecl); blockStatement.Statements.InsertBefore(insertionPoint, newVarDecl);
} }
} }
currentlyUsedVariableNames.RemoveRange(numberOfVariablesOutsideBlock, currentlyUsedVariableNames.Count - numberOfVariablesOutsideBlock); currentlyUsedVariableNames.RemoveRange(numberOfVariablesOutsideBlock, currentlyUsedVariableNames.Count - numberOfVariablesOutsideBlock);
return null; return null;
} }
void EnsureVariableNameIsAvailable(AstNode currentNode, string name) void EnsureVariableNameIsAvailable(AstNode currentNode, string name)
{ {
int pos = currentlyUsedVariableNames.IndexOf(name); int pos = currentlyUsedVariableNames.IndexOf(name);

13
ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs

@ -227,6 +227,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
Name = variableName, Name = variableName,
Initializer = m1.Get<Expression>("initializer").Single().Detach() Initializer = m1.Get<Expression>("initializer").Single().Detach()
}.CopyAnnotationsFrom(node.Expression) }.CopyAnnotationsFrom(node.Expression)
.WithAnnotation(m1.Get<AstNode>("variable").Single().Annotation<ILVariable>())
} }
}.CopyAnnotationsFrom(node); }.CopyAnnotationsFrom(node);
} else { } else {
@ -382,7 +383,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
VariableName = itemVar.Identifier, VariableName = itemVar.Identifier,
InExpression = m.Get<Expression>("collection").Single().Detach(), InExpression = m.Get<Expression>("collection").Single().Detach(),
EmbeddedStatement = newBody EmbeddedStatement = newBody
}; }.WithAnnotation(itemVarDecl.Variables.Single().Annotation<ILVariable>());
if (foreachStatement.InExpression is BaseReferenceExpression) { if (foreachStatement.InExpression is BaseReferenceExpression) {
foreachStatement.InExpression = new ThisReferenceExpression().CopyAnnotationsFrom(foreachStatement.InExpression); foreachStatement.InExpression = new ThisReferenceExpression().CopyAnnotationsFrom(foreachStatement.InExpression);
} }
@ -471,10 +472,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
// We just care that we can move it in front of the loop: // We just care that we can move it in front of the loop:
if (declarationPoint != loop) if (declarationPoint != loop)
return null; return null;
ForeachStatement foreachStatement = new ForeachStatement(); ForeachStatement foreachStatement = new ForeachStatement
foreachStatement.VariableType = itemVarDecl.Type.Clone(); {
foreachStatement.VariableName = itemVar.Identifier; VariableType = itemVarDecl.Type.Clone(),
VariableName = itemVar.Identifier,
}.WithAnnotation(itemVarDecl.Variables.Single().Annotation<ILVariable>());
BlockStatement body = new BlockStatement(); BlockStatement body = new BlockStatement();
foreachStatement.EmbeddedStatement = body; foreachStatement.EmbeddedStatement = body;
((BlockStatement)node.Parent).Statements.InsertBefore(node, foreachStatement); ((BlockStatement)node.Parent).Statements.InsertBefore(node, foreachStatement);

4
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -632,6 +632,10 @@ namespace ICSharpCode.Decompiler.ILAst
foreach (ParameterDefinition p in methodDef.Parameters) { foreach (ParameterDefinition p in methodDef.Parameters) {
this.Parameters.Add(new ILVariable { Type = p.ParameterType, Name = p.Name, OriginalParameter = p }); this.Parameters.Add(new ILVariable { Type = p.ParameterType, Name = p.Name, OriginalParameter = p });
} }
if (this.Parameters.Count > 0 && (methodDef.IsSetter || methodDef.IsAddOn || methodDef.IsRemoveOn)) {
// last parameter must be 'value', so rename it
this.Parameters.Last().Name = "value";
}
foreach (ByteCode byteCode in body) { foreach (ByteCode byteCode in body) {
ParameterDefinition p; ParameterDefinition p;
switch (byteCode.Code) { switch (byteCode.Code) {

2
ICSharpCode.Decompiler/ITextOutput.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler
void Write(string text); void Write(string text);
void WriteLine(); void WriteLine();
void WriteDefinition(string text, object definition); void WriteDefinition(string text, object definition);
void WriteReference(string text, object reference); void WriteReference(string text, object reference, bool isLocal = false);
void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false); void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false);
void MarkFoldEnd(); void MarkFoldEnd();

2
ICSharpCode.Decompiler/PlainTextOutput.cs

@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler
Write(text); Write(text);
} }
public void WriteReference(string text, object reference) public void WriteReference(string text, object reference, bool isLocal)
{ {
Write(text); Write(text);
} }

23
ILSpy.BamlDecompiler/CecilTypeResolver.cs

@ -48,15 +48,38 @@ namespace ILSpy.BamlDecompiler
string assemblyName = name.Substring(comma + 1).Trim(); string assemblyName = name.Substring(comma + 1).Trim();
var type = thisAssembly.MainModule.GetType(fullName); var type = thisAssembly.MainModule.GetType(fullName);
if (type == null) {
type = TryFindInExportedTypes(fullName, thisAssembly);
}
if (type == null) { if (type == null) {
var otherAssembly = resolver.Resolve(assemblyName); var otherAssembly = resolver.Resolve(assemblyName);
if (otherAssembly == null) if (otherAssembly == null)
throw new Exception("could not resolve '" + assemblyName + "'!"); throw new Exception("could not resolve '" + assemblyName + "'!");
type = otherAssembly.MainModule.GetType(fullName.Replace('+', '/')); type = otherAssembly.MainModule.GetType(fullName.Replace('+', '/'));
if (type == null) {
type = TryFindInExportedTypes(fullName, otherAssembly);
}
} }
if (type == null)
throw new Exception("could not resolve '" + name + "'!");
return new CecilType(type); return new CecilType(type);
} }
TypeDefinition TryFindInExportedTypes(string fullName, AssemblyDefinition asm)
{
foreach (var exportedType in asm.MainModule.ExportedTypes) {
if (exportedType.IsForwarder && exportedType.FullName == fullName) {
return exportedType.Resolve();
}
}
return null;
}
public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType) public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType)
{ {

55
ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarMargin.cs

@ -15,6 +15,7 @@ using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Bookmarks; using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.Debugger; using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Bookmarks; using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil; using Mono.Cecil;
@ -70,10 +71,15 @@ namespace ICSharpCode.ILSpy.AvalonEdit
// create a dictionary line number => first bookmark // create a dictionary line number => first bookmark
Dictionary<int, IBookmark> bookmarkDict = new Dictionary<int, IBookmark>(); Dictionary<int, IBookmark> bookmarkDict = new Dictionary<int, IBookmark>();
foreach (var bm in BookmarkManager.Bookmarks) { foreach (var bm in BookmarkManager.Bookmarks) {
if (DebugInformation.DecompiledMemberReferences == null || DebugInformation.DecompiledMemberReferences.Count == 0 || if (bm is BreakpointBookmark) {
!DebugInformation.DecompiledMemberReferences.ContainsKey(bm.MemberReference.MetadataToken.ToInt32())) if (DebugInformation.CodeMappings == null || DebugInformation.CodeMappings.Count == 0 ||
continue; !DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)bm).FunctionToken))
continue;
} else {
if (DebugInformation.DecompiledMemberReferences == null || DebugInformation.DecompiledMemberReferences.Count == 0 ||
!DebugInformation.DecompiledMemberReferences.ContainsKey(((MarkerBookmark)bm).MemberReference.MetadataToken.ToInt32()))
continue;
}
int line = bm.LineNumber; int line = bm.LineNumber;
IBookmark existingBookmark; IBookmark existingBookmark;
if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder)
@ -281,7 +287,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit
if (storage == null || storage.Count == 0) if (storage == null || storage.Count == 0)
return; return;
//remove existing bookmarks and create new ones // TODO: handle other types of bookmarks
// remove existing bookmarks and create new ones
// update of existing bookmarks for new position does not update TextMarker // update of existing bookmarks for new position does not update TextMarker
// this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed // this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed
List<BreakpointBookmark> newBookmarks = new List<BreakpointBookmark>(); List<BreakpointBookmark> newBookmarks = new List<BreakpointBookmark>();
@ -290,26 +297,24 @@ namespace ICSharpCode.ILSpy.AvalonEdit
if (breakpoint == null) if (breakpoint == null)
continue; continue;
var key = breakpoint.MemberReference.MetadataToken.ToInt32(); var key = breakpoint.FunctionToken;
if (!storage.ContainsKey(key)) if (!storage.ContainsKey(key))
{ {
continue; continue;
} }
var member = DebugInformation.DecompiledMemberReferences[key];
bool isMatch; bool isMatch;
SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset( SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(key, breakpoint.ILRange.From, out isMatch);
member.MetadataToken.ToInt32(), breakpoint.ILRange.From, out isMatch);
if (map != null) { if (map != null) {
BreakpointBookmark newBookmark = new BreakpointBookmark( BreakpointBookmark newBookmark = new BreakpointBookmark(
member, new AstLocation(map.SourceCodeLine, 0), breakpoint.MemberReference, new AstLocation(map.SourceCodeLine, 0), breakpoint.FunctionToken,
map.ILInstructionOffset, BreakpointAction.Break, DebugInformation.Language); map.ILInstructionOffset, BreakpointAction.Break, DebugInformation.Language);
newBookmark.IsEnabled = breakpoint.IsEnabled; newBookmark.IsEnabled = breakpoint.IsEnabled;
newBookmarks.Add(newBookmark); newBookmarks.Add(newBookmark);
BookmarkManager.RemoveMark(breakpoint);
BookmarkManager.RemoveMark(breakpoint);
} }
} }
newBookmarks.ForEach(m => BookmarkManager.AddMark(m)); newBookmarks.ForEach(m => BookmarkManager.AddMark(m));
@ -322,33 +327,25 @@ namespace ICSharpCode.ILSpy.AvalonEdit
if (CurrentLineBookmark.Instance == null) if (CurrentLineBookmark.Instance == null)
return; return;
var oldMappings = DebugInformation.OldCodeMappings; var codeMappings = DebugInformation.CodeMappings;
var newMappings = DebugInformation.CodeMappings; if (codeMappings == null)
if (oldMappings == null || newMappings == null)
return; return;
// 1. Save it's data // 1. Save it's data
int line = CurrentLineBookmark.Instance.LineNumber; int line = CurrentLineBookmark.Instance.LineNumber;
var markerType = CurrentLineBookmark.Instance.MemberReference; var markerType = CurrentLineBookmark.Instance.MemberReference;
int token = markerType.MetadataToken.ToInt32();
int offset = CurrentLineBookmark.Instance.ILOffset;
if (!oldMappings.ContainsKey(markerType.MetadataToken.ToInt32()) || !newMappings.ContainsKey(markerType.MetadataToken.ToInt32())) if (!codeMappings.ContainsKey(token))
return; return;
// 2. Remove it // 2. map the marker line
CurrentLineBookmark.Remove();
// 3. map the marker line
int token;
var instruction = oldMappings[markerType.MetadataToken.ToInt32()].GetInstructionByLineNumber(line, out token);
if (instruction == null)
return;
MemberReference memberReference; MemberReference memberReference;
int newline; int newline;
if (newMappings[markerType.MetadataToken.ToInt32()].GetInstructionByTokenAndOffset(token, instruction.ILInstructionOffset.From, out memberReference, out newline)) { if (codeMappings[token].GetInstructionByTokenAndOffset(token, offset, out memberReference, out newline)) {
// 4. create breakpoint for new languages // 3. create breakpoint for new languages
CurrentLineBookmark.SetPosition(memberReference, newline, 0, newline, 0); DebuggerService.JumpToCurrentLine(memberReference, newline, 0, newline, 0, offset);
} }
} }
} }

4
ILSpy.SharpDevelop.LGPL/AvalonEdit/TextMarkerService.cs

@ -123,7 +123,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
int lineStart = line.Offset; int lineStart = line.Offset;
int lineEnd = lineStart + line.Length; int lineEnd = lineStart + line.Length;
foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length).Reverse()) { foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length).Reverse()) {
if (!marker.IsVisible(marker.Bookmark)) if (marker.Bookmark != null && !marker.IsVisible(marker.Bookmark))
continue; continue;
Brush foregroundBrush = null; Brush foregroundBrush = null;
@ -166,7 +166,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
int viewStart = visualLines.First().FirstDocumentLine.Offset; int viewStart = visualLines.First().FirstDocumentLine.Offset;
int viewEnd = visualLines.Last().LastDocumentLine.Offset + visualLines.Last().LastDocumentLine.Length; int viewEnd = visualLines.Last().LastDocumentLine.Offset + visualLines.Last().LastDocumentLine.Length;
foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart).Reverse()) { foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart).Reverse()) {
if (!marker.IsVisible(marker.Bookmark)) if (marker.Bookmark != null && !marker.IsVisible(marker.Bookmark))
continue; continue;
if (marker.BackgroundColor != null) { if (marker.BackgroundColor != null) {

21
ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmark.cs

@ -40,7 +40,16 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
} }
} }
public ILRange ILRange { get; set; } /// <summary>
/// Gets the function/method where the breakpoint is set.
/// <remarks>
/// In case of methods, it is the same as the MemberReference metadata token.<br/>
/// In case of properties and events, it's the GetMethod/SetMethod|AddMethod/RemoveMethod token.
/// </remarks>
/// </summary>
public int FunctionToken { get; private set; }
public ILRange ILRange { get; private set; }
public virtual bool IsHealthy { public virtual bool IsHealthy {
get { get {
@ -74,12 +83,14 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
public string Tooltip { get; private set; } public string Tooltip { get; private set; }
public BreakpointBookmark(MemberReference member, AstLocation location, ILRange range, BreakpointAction action, DecompiledLanguages language) : base(member, location) public BreakpointBookmark(MemberReference member, AstLocation location, int functionToken, ILRange range, BreakpointAction action, DecompiledLanguages language)
: base(member, location)
{ {
this.action = action; this.action = action;
this.FunctionToken = functionToken;
this.ILRange = range; this.ILRange = range;
this.Tooltip = string.Format("Language:{0}, Line:{1}, IL range:{2}-{3}", language.ToString(), location.Line, range.From, range.To); this.Tooltip = string.Format("Language:{0}, Line:{1}, IL range:{2}-{3}", language.ToString(), location.Line, range.From, range.To);
this.Language = language; this.Language = language;
} }
public override ImageSource Image { public override ImageSource Image {
@ -95,8 +106,8 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
ITextMarker marker = markerService.Create(offset, length); ITextMarker marker = markerService.Create(offset, length);
marker.BackgroundColor = Color.FromRgb(180, 38, 38); marker.BackgroundColor = Color.FromRgb(180, 38, 38);
marker.ForegroundColor = Colors.White; marker.ForegroundColor = Colors.White;
marker.IsVisible = b => b is MarkerBookmark && DebugInformation.DecompiledMemberReferences != null && marker.IsVisible = b => b is BreakpointBookmark && DebugInformation.CodeMappings != null &&
DebugInformation.DecompiledMemberReferences.ContainsKey(((MarkerBookmark)b).MemberReference.MetadataToken.ToInt32()); DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)b).FunctionToken);
marker.Bookmark = this; marker.Bookmark = this;
this.Marker = marker; this.Marker = marker;

10
ILSpy.SharpDevelop.LGPL/Bookmarks/CurrentLineBookmark.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
static int endLine; static int endLine;
static int endColumn; static int endColumn;
public static void SetPosition(MemberReference memberReference, int makerStartLine, int makerStartColumn, int makerEndLine, int makerEndColumn) public static void SetPosition(MemberReference memberReference, int makerStartLine, int makerStartColumn, int makerEndLine, int makerEndColumn, int ilOffset)
{ {
Remove(); Remove();
@ -33,7 +33,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
endLine = makerEndLine; endLine = makerEndLine;
endColumn = makerEndColumn; endColumn = makerEndColumn;
instance = new CurrentLineBookmark(memberReference, new AstLocation(startLine, startColumn)); instance = new CurrentLineBookmark(memberReference, new AstLocation(startLine, startColumn), ilOffset);
BookmarkManager.AddMark(instance); BookmarkManager.AddMark(instance);
} }
@ -53,11 +53,13 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
get { return 100; } get { return 100; }
} }
private CurrentLineBookmark(MemberReference member, AstLocation location) : base(member, location) private CurrentLineBookmark(MemberReference member, AstLocation location, int ilOffset) : base(member, location)
{ {
this.ILOffset = ilOffset;
} }
public int ILOffset { get; private set; }
public override ImageSource Image { public override ImageSource Image {
get { return Images.CurrentLine; } get { return Images.CurrentLine; }
} }

5
ILSpy.SharpDevelop.LGPL/DebugInformation.cs

@ -47,11 +47,6 @@ namespace ICSharpCode.ILSpy.Debugger
/// </summary> /// </summary>
public static ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; set; } public static ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; set; }
/// <summary>
/// Gets or sets the old code mappings.
/// </summary>
public static Dictionary<int, List<MemberMapping>> OldCodeMappings { get; set; }
/// <summary> /// <summary>
/// Gets or sets the MembeReference that was decompiled (a TypeDefinition, MethodDefinition, etc) /// Gets or sets the MembeReference that was decompiled (a TypeDefinition, MethodDefinition, etc)
/// </summary> /// </summary>

8
ILSpy.SharpDevelop.LGPL/ILSpy.SharpDevelop.LGPL.csproj

@ -32,7 +32,7 @@
<Optimize>True</Optimize> <Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
@ -76,11 +76,17 @@
<Compile Include="Bookmarks\MarkerBookmark.cs" /> <Compile Include="Bookmarks\MarkerBookmark.cs" />
<Compile Include="DebugInformation.cs" /> <Compile Include="DebugInformation.cs" />
<Compile Include="Images.cs" /> <Compile Include="Images.cs" />
<Compile Include="Models\ToolTipRequestEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\DebuggerService.cs" />
<Compile Include="Services\IDebugger.cs" />
<Compile Include="Services\ParserService.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="AvalonEdit" /> <Folder Include="AvalonEdit" />
<Folder Include="Bookmarks" /> <Folder Include="Bookmarks" />
<Folder Include="Models" />
<Folder Include="Services" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj"> <ProjectReference Include="..\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">

2
Debugger/ILSpy.Debugger/ToolTips/Models/ToolTipRequestEventArgs.cs → ILSpy.SharpDevelop.LGPL/Models/ToolTipRequestEventArgs.cs

@ -7,7 +7,7 @@ using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.ILSpy.Debugger.Tooltips namespace ICSharpCode.ILSpy.Debugger.Tooltips
{ {
internal class ToolTipRequestEventArgs : EventArgs public class ToolTipRequestEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// Gets whether the tool tip request was handled. /// Gets whether the tool tip request was handled.

20
Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs → ILSpy.SharpDevelop.LGPL/Services/DebuggerService.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
static IDebugger GetCompatibleDebugger() static IDebugger GetCompatibleDebugger()
{ {
return currentDebugger = new WindowsDebugger(); return currentDebugger;
} }
/// <summary> /// <summary>
@ -39,6 +39,8 @@ namespace ICSharpCode.ILSpy.Debugger.Services
get { get {
if (currentDebugger == null) { if (currentDebugger == null) {
currentDebugger = GetCompatibleDebugger(); currentDebugger = GetCompatibleDebugger();
if (currentDebugger == null)
return null;
currentDebugger.DebugStarting += new EventHandler(OnDebugStarting); currentDebugger.DebugStarting += new EventHandler(OnDebugStarting);
currentDebugger.DebugStarted += new EventHandler(OnDebugStarted); currentDebugger.DebugStarted += new EventHandler(OnDebugStarted);
currentDebugger.DebugStopped += new EventHandler(OnDebugStopped); currentDebugger.DebugStopped += new EventHandler(OnDebugStopped);
@ -166,12 +168,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services
} }
} }
public static void ToggleBreakpointAt(MemberReference member, int lineNumber, ILRange range, DecompiledLanguages language) public static void ToggleBreakpointAt(MemberReference member, int lineNumber, int functionToken, ILRange range, DecompiledLanguages language)
{ {
BookmarkManager.ToggleBookmark( BookmarkManager.ToggleBookmark(
member.FullName, lineNumber, member.FullName, lineNumber,
b => b.CanToggle && b is BreakpointBookmark, b => b.CanToggle && b is BreakpointBookmark,
location => new BreakpointBookmark(member, location, range, BreakpointAction.Break, language)); location => new BreakpointBookmark(member, location, functionToken, range, BreakpointAction.Break, language));
} }
/* TODO: reimplement this stuff /* TODO: reimplement this stuff
@ -187,10 +189,9 @@ namespace ICSharpCode.ILSpy.Debugger.Services
CurrentLineBookmark.Remove(); CurrentLineBookmark.Remove();
} }
public static void JumpToCurrentLine(MemberReference memberReference, int startLine, int startColumn, int endLine, int endColumn) public static void JumpToCurrentLine(MemberReference memberReference, int startLine, int startColumn, int endLine, int endColumn, int ilOffset)
{ {
CurrentLineBookmark.SetPosition(memberReference, startLine, startColumn, endLine, endColumn); CurrentLineBookmark.SetPosition(memberReference, startLine, startColumn, endLine, endColumn, ilOffset);
MainWindow.Instance.TextView.UnfoldAndScroll(startLine);
} }
#region Tool tips #region Tool tips
@ -200,7 +201,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
/// showing its current value (when in debugging mode) can be returned /// showing its current value (when in debugging mode) can be returned
/// through the ToolTipRequestEventArgs.SetTooltip() method. /// through the ToolTipRequestEventArgs.SetTooltip() method.
/// </summary> /// </summary>
internal static void HandleToolTipRequest(ToolTipRequestEventArgs e) public static void HandleToolTipRequest(ToolTipRequestEventArgs e)
{ {
if (!e.InDocument) if (!e.InDocument)
return; return;
@ -386,5 +387,10 @@ namespace ICSharpCode.ILSpy.Debugger.Services
// return text.ToString(); // return text.ToString();
// } // }
#endregion #endregion
public static void SetDebugger(Lazy<IDebugger> debugger)
{
currentDebugger = debugger.Value;
}
} }
} }

0
Debugger/ILSpy.Debugger/Services/Debugger/IDebugger.cs → ILSpy.SharpDevelop.LGPL/Services/IDebugger.cs

11
Debugger/ILSpy.Debugger/Services/ParserService/ParserService.cs → ILSpy.SharpDevelop.LGPL/Services/ParserService.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
static ParserService() static ParserService()
{ {
mySet.AddRange((new [] { mySet.AddRange((new string [] {
".", ".",
"{", "{",
"}", "}",
@ -41,7 +41,14 @@ namespace ICSharpCode.ILSpy.Debugger.Services
@"\t", @"\t",
@"\r", @"\r",
"|" "|"
}).AsReadOnly()); }));
}
static void AddRange<T>(this ICollection<T> list, IEnumerable<T> items)
{
foreach (T item in items)
if (!list.Contains(item))
list.Add(item);
} }
/// <summary> /// <summary>

4
ILSpy/AboutPage.cs

@ -183,7 +183,9 @@ namespace ICSharpCode.ILSpy
{ {
var tcs = new TaskCompletionSource<AvailableVersionInfo>(); var tcs = new TaskCompletionSource<AvailableVersionInfo>();
WebClient wc = new WebClient(); WebClient wc = new WebClient();
wc.UseDefaultCredentials = true; IWebProxy systemWebProxy = WebRequest.GetSystemWebProxy();
systemWebProxy.Credentials = CredentialCache.DefaultCredentials;
wc.Proxy = systemWebProxy;
wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) { wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) {
if (e.Error != null) { if (e.Error != null) {
tcs.SetException(e.Error); tcs.SetException(e.Error);

10
ILSpy/App.xaml.cs

@ -17,16 +17,16 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition.Hosting;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.TextView;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
@ -73,6 +73,12 @@ namespace ICSharpCode.ILSpy
EventManager.RegisterClassHandler(typeof(Window), EventManager.RegisterClassHandler(typeof(Window),
Hyperlink.RequestNavigateEvent, Hyperlink.RequestNavigateEvent,
new RequestNavigateEventHandler(Window_RequestNavigate)); new RequestNavigateEventHandler(Window_RequestNavigate));
try {
DebuggerService.SetDebugger(compositionContainer.GetExport<IDebugger>());
} catch {
// unable to find a IDebugger
}
} }
string FullyQualifyPath(string argument) string FullyQualifyPath(string argument)

9
ILSpy/TextView/AvalonEditTextOutput.cs

@ -36,6 +36,8 @@ namespace ICSharpCode.ILSpy.TextView
sealed class ReferenceSegment : TextSegment sealed class ReferenceSegment : TextSegment
{ {
public object Reference; public object Reference;
public bool IsLocal;
public bool IsLocalTarget;
} }
/// <summary> /// <summary>
@ -204,17 +206,20 @@ namespace ICSharpCode.ILSpy.TextView
public void WriteDefinition(string text, object definition) public void WriteDefinition(string text, object definition)
{ {
WriteIndent(); WriteIndent();
int start = this.TextLength;
b.Append(text); b.Append(text);
int end = this.TextLength;
this.DefinitionLookup.AddDefinition(definition, this.TextLength); this.DefinitionLookup.AddDefinition(definition, this.TextLength);
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = definition, IsLocal = true, IsLocalTarget = true });
} }
public void WriteReference(string text, object reference) public void WriteReference(string text, object reference, bool isLocal)
{ {
WriteIndent(); WriteIndent();
int start = this.TextLength; int start = this.TextLength;
b.Append(text); b.Append(text);
int end = this.TextLength; int end = this.TextLength;
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference }); references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference, IsLocal = isLocal });
} }
public void MarkFoldStart(string collapsedText, bool defaultCollapsed) public void MarkFoldStart(string collapsedText, bool defaultCollapsed)

34
ILSpy/TextView/DecompilerTextView.cs

@ -29,6 +29,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Threading; using System.Windows.Threading;
using System.Xml; using System.Xml;
@ -45,6 +46,7 @@ using ICSharpCode.ILSpy.AvalonEdit;
using ICSharpCode.ILSpy.Bookmarks; using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.Debugger; using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Bookmarks; using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.Options; using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.XmlDoc; using ICSharpCode.ILSpy.XmlDoc;
@ -68,11 +70,13 @@ namespace ICSharpCode.ILSpy.TextView
ILSpyTreeNode[] decompiledNodes; ILSpyTreeNode[] decompiledNodes;
DefinitionLookup definitionLookup; DefinitionLookup definitionLookup;
TextSegmentCollection<ReferenceSegment> references;
CancellationTokenSource currentCancellationTokenSource; CancellationTokenSource currentCancellationTokenSource;
internal readonly IconBarManager manager; internal readonly IconBarManager manager;
readonly IconBarMargin iconMargin; readonly IconBarMargin iconMargin;
readonly TextMarkerService textMarkerService; readonly TextMarkerService textMarkerService;
readonly List<ITextMarker> localReferenceMarks = new List<ITextMarker>();
[ImportMany(typeof(ITextEditorListener))] [ImportMany(typeof(ITextEditorListener))]
IEnumerable<ITextEditorListener> textEditorListeners = null; IEnumerable<ITextEditorListener> textEditorListeners = null;
@ -315,7 +319,8 @@ namespace ICSharpCode.ILSpy.TextView
{ {
Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength); Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
Stopwatch w = Stopwatch.StartNew(); Stopwatch w = Stopwatch.StartNew();
ClearLocalReferenceMarks();
textEditor.ScrollToHome(); textEditor.ScrollToHome();
if (foldingManager != null) { if (foldingManager != null) {
FoldingManager.Uninstall(foldingManager); FoldingManager.Uninstall(foldingManager);
@ -324,6 +329,7 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.Document = null; // clear old document while we're changing the highlighting textEditor.Document = null; // clear old document while we're changing the highlighting
uiElementGenerator.UIElements = textOutput.UIElements; uiElementGenerator.UIElements = textOutput.UIElements;
referenceElementGenerator.References = textOutput.References; referenceElementGenerator.References = textOutput.References;
references = textOutput.References;
definitionLookup = textOutput.DefinitionLookup; definitionLookup = textOutput.DefinitionLookup;
textEditor.SyntaxHighlighting = highlighting; textEditor.SyntaxHighlighting = highlighting;
@ -447,7 +453,7 @@ namespace ICSharpCode.ILSpy.TextView
iconMargin.SyncBookmarks(); iconMargin.SyncBookmarks();
if (isDecompilationOk) { if (isDecompilationOk) {
if (DebugInformation.DebugStepInformation != null) { if (DebugInformation.DebugStepInformation != null && DebuggerService.CurrentDebugger != null) {
// repaint bookmarks // repaint bookmarks
iconMargin.InvalidateVisual(); iconMargin.InvalidateVisual();
@ -462,7 +468,7 @@ namespace ICSharpCode.ILSpy.TextView
DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out member, out line); DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out member, out line);
// update marker // update marker
CurrentLineBookmark.SetPosition(member, line, 0, line, 0); DebuggerService.JumpToCurrentLine(member, line, 0, line, 0, ilOffset);
var bm = CurrentLineBookmark.Instance; var bm = CurrentLineBookmark.Instance;
DocumentLine docline = textEditor.Document.GetLineByNumber(line); DocumentLine docline = textEditor.Document.GetLineByNumber(line);
@ -524,7 +530,6 @@ namespace ICSharpCode.ILSpy.TextView
void DecompileNodes(DecompilationContext context, ITextOutput textOutput) void DecompileNodes(DecompilationContext context, ITextOutput textOutput)
{ {
// reset data // reset data
DebugInformation.OldCodeMappings = DebugInformation.CodeMappings;
DebugInformation.CodeMappings = null; DebugInformation.CodeMappings = null;
DebugInformation.LocalVariables = null; DebugInformation.LocalVariables = null;
DebugInformation.DecompiledMemberReferences = null; DebugInformation.DecompiledMemberReferences = null;
@ -608,6 +613,19 @@ namespace ICSharpCode.ILSpy.TextView
internal void JumpToReference(ReferenceSegment referenceSegment) internal void JumpToReference(ReferenceSegment referenceSegment)
{ {
object reference = referenceSegment.Reference; object reference = referenceSegment.Reference;
if (referenceSegment.IsLocal) {
ClearLocalReferenceMarks();
if (references != null) {
foreach (var r in references) {
if (r.Reference == reference) {
var mark = textMarkerService.Create(r.StartOffset, r.Length);
mark.BackgroundColor = r.IsLocalTarget ? Colors.LightSeaGreen : Colors.GreenYellow;
localReferenceMarks.Add(mark);
}
}
}
return;
}
if (definitionLookup != null) { if (definitionLookup != null) {
int pos = definitionLookup.GetDefinitionPosition(reference); int pos = definitionLookup.GetDefinitionPosition(reference);
if (pos >= 0) { if (pos >= 0) {
@ -623,6 +641,14 @@ namespace ICSharpCode.ILSpy.TextView
} }
MainWindow.Instance.JumpToReference(reference); MainWindow.Instance.JumpToReference(reference);
} }
void ClearLocalReferenceMarks()
{
foreach (var mark in localReferenceMarks) {
textMarkerService.Remove(mark);
}
localReferenceMarks.Clear();
}
/// <summary> /// <summary>
/// Filters all ReferenceSegments that are no real links. /// Filters all ReferenceSegments that are no real links.

5
ILSpy/TextView/ReferenceElementGenerator.cs

@ -102,7 +102,7 @@ namespace ICSharpCode.ILSpy.TextView
protected override void OnQueryCursor(QueryCursorEventArgs e) protected override void OnQueryCursor(QueryCursorEventArgs e)
{ {
e.Handled = true; e.Handled = true;
e.Cursor = Cursors.Hand; e.Cursor = referenceSegment.IsLocal ? Cursors.Arrow : Cursors.Hand;
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -110,7 +110,8 @@ namespace ICSharpCode.ILSpy.TextView
{ {
if (e.ChangedButton == MouseButton.Left && !e.Handled) { if (e.ChangedButton == MouseButton.Left && !e.Handled) {
parent.JumpToReference(referenceSegment); parent.JumpToReference(referenceSegment);
e.Handled = true; if(!referenceSegment.IsLocal)
e.Handled = true;
} }
} }

8
ILSpy/TreeNodes/EventTreeNode.cs

@ -108,6 +108,14 @@ namespace ICSharpCode.ILSpy.TreeNodes
language.DecompileEvent(ev, output, options); language.DecompileEvent(ev, output, options);
} }
public override bool IsPublicAPI {
get {
MethodDefinition accessor = ev.AddMethod ?? ev.RemoveMethod;
return accessor != null && (accessor.IsPublic || accessor.IsFamilyOrAssembly || accessor.IsFamily);
}
}
MemberReference IMemberTreeNode.Member MemberReference IMemberTreeNode.Member
{ {
get { return ev; } get { return ev; }

6
ILSpy/TreeNodes/FieldTreeNode.cs

@ -112,6 +112,12 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
language.DecompileField(field, output, options); language.DecompileField(field, output, options);
} }
public override bool IsPublicAPI {
get {
return field.IsPublic || field.IsFamily || field.IsFamilyOrAssembly;
}
}
MemberReference IMemberTreeNode.Member MemberReference IMemberTreeNode.Member
{ {

13
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -166,5 +166,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
ApplyFilterToChild(node); ApplyFilterToChild(node);
} }
} }
public virtual bool IsPublicAPI {
get { return true; }
}
public override System.Windows.Media.Brush Foreground {
get {
if (IsPublicAPI)
return base.Foreground;
else
return System.Windows.SystemColors.GrayTextBrush;
}
}
} }
} }

6
ILSpy/TreeNodes/MethodTreeNode.cs

@ -137,6 +137,12 @@ namespace ICSharpCode.ILSpy.TreeNodes
return FilterResult.Hidden; return FilterResult.Hidden;
} }
public override bool IsPublicAPI {
get {
return method.IsPublic || method.IsFamily || method.IsFamilyOrAssembly;
}
}
MemberReference IMemberTreeNode.Member MemberReference IMemberTreeNode.Member
{ {
get { return method; } get { return method; }

13
ILSpy/TreeNodes/PropertyTreeNode.cs

@ -148,6 +148,19 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
language.DecompileProperty(property, output, options); language.DecompileProperty(property, output, options);
} }
public override bool IsPublicAPI {
get {
switch (GetAttributesOfMostAccessibleMethod(property) & MethodAttributes.MemberAccessMask) {
case MethodAttributes.Public:
case MethodAttributes.Family:
case MethodAttributes.FamORAssem:
return true;
default:
return false;
}
}
}
MemberReference IMemberTreeNode.Member MemberReference IMemberTreeNode.Member
{ {

2
ILSpy/TreeNodes/TypeTreeNode.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
get { return HighlightSearchMatch(this.Language.FormatTypeName(type)); } get { return HighlightSearchMatch(this.Language.FormatTypeName(type)); }
} }
public bool IsPublicAPI { public override bool IsPublicAPI {
get { get {
switch (type.Attributes & TypeAttributes.VisibilityMask) { switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public: case TypeAttributes.Public:

41
ILSpy/XmlDoc/XmlDocKeyProvider.cs

@ -90,20 +90,7 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
if (type is GenericInstanceType) { if (type is GenericInstanceType) {
GenericInstanceType giType = (GenericInstanceType)type; GenericInstanceType giType = (GenericInstanceType)type;
if (type.DeclaringType != null) { AppendTypeNameWithArguments(b, giType.ElementType, giType.GenericArguments);
AppendTypeName(b, type.DeclaringType);
b.Append('.');
} else if (!string.IsNullOrEmpty(type.Namespace)) {
b.Append(type.Namespace);
b.Append('.');
}
b.Append(NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name));
b.Append('{');
for (int i = 0; i < giType.GenericArguments.Count; i++) {
if (i > 0) b.Append(',');
AppendTypeName(b, giType.GenericArguments[i]);
}
b.Append('}');
} else if (type is TypeSpecification) { } else if (type is TypeSpecification) {
AppendTypeName(b, ((TypeSpecification)type).ElementType); AppendTypeName(b, ((TypeSpecification)type).ElementType);
ArrayType arrayType = type as ArrayType; ArrayType arrayType = type as ArrayType;
@ -146,6 +133,32 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
} }
} }
static int AppendTypeNameWithArguments(StringBuilder b, TypeReference type, IList<TypeReference> genericArguments)
{
int outerTypeParameterCount = 0;
if (type.DeclaringType != null) {
TypeReference declType = type.DeclaringType;
outerTypeParameterCount = AppendTypeNameWithArguments(b, declType, genericArguments);
b.Append('.');
} else if (!string.IsNullOrEmpty(type.Namespace)) {
b.Append(type.Namespace);
b.Append('.');
}
int localTypeParameterCount = 0;
b.Append(NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out localTypeParameterCount));
if (localTypeParameterCount > 0) {
int totalTypeParameterCount = outerTypeParameterCount + localTypeParameterCount;
b.Append('{');
for (int i = outerTypeParameterCount; i < totalTypeParameterCount && i < genericArguments.Count; i++) {
if (i > outerTypeParameterCount) b.Append(',');
AppendTypeName(b, genericArguments[i]);
}
b.Append('}');
}
return outerTypeParameterCount + localTypeParameterCount;
}
#endregion #endregion
#region FindMemberByKey #region FindMemberByKey

3
ILSpy/XmlDoc/XmlDocLoader.cs

@ -99,6 +99,9 @@ namespace ICSharpCode.ILSpy.XmlDoc
static string LookupLocalizedXmlDoc(string fileName) static string LookupLocalizedXmlDoc(string fileName)
{ {
if (string.IsNullOrEmpty(fileName))
return null;
string xmlFileName = Path.ChangeExtension(fileName, ".xml"); string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture); string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture);

5
SharpTreeView/SharpTreeNode.cs

@ -12,6 +12,7 @@ using System.Collections.ObjectModel;
using System.Windows.Controls; using System.Windows.Controls;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.TreeView namespace ICSharpCode.TreeView
{ {
@ -101,6 +102,10 @@ namespace ICSharpCode.TreeView
get { return null; } get { return null; }
} }
public virtual Brush Foreground {
get { return SystemColors.WindowTextBrush; }
}
public virtual object Icon public virtual object Icon
{ {
get { return null; } get { return null; }

4
SharpTreeView/Themes/Generic.xaml

@ -181,6 +181,7 @@
<Border Background="Transparent"> <Border Background="Transparent">
<Border Background="{TemplateBinding Background}"> <Border Background="{TemplateBinding Background}">
<Default:SharpTreeNodeView Name="nodeView" <Default:SharpTreeNodeView Name="nodeView"
Foreground="{Binding Foreground}"
HorizontalAlignment="Left" /> HorizontalAlignment="Left" />
</Border> </Border>
</Border> </Border>
@ -210,7 +211,8 @@
</MultiTrigger>--> </MultiTrigger>-->
<Trigger Property="IsEnabled" <Trigger Property="IsEnabled"
Value="False"> Value="False">
<Setter Property="Foreground" <Setter TargetName="nodeView"
Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>

Loading…
Cancel
Save