Browse Source

Fixed crash in AddCheckedBlocks.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
18fde488f1
  1. 11
      ICSharpCode.Decompiler/Ast/Transforms/AddCheckedBlocks.cs
  2. 4
      ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs

11
ICSharpCode.Decompiler/Ast/Transforms/AddCheckedBlocks.cs

@ -142,8 +142,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -142,8 +142,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
class InsertedBlock : InsertedNode
{
readonly Statement firstStatement;
readonly Statement lastStatement;
readonly Statement firstStatement; // inclusive
readonly Statement lastStatement; // exclusive
readonly bool isChecked;
public InsertedBlock(Statement firstStatement, Statement lastStatement, bool isChecked)
@ -156,13 +156,18 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -156,13 +156,18 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public override void Insert()
{
BlockStatement newBlock = new BlockStatement();
for (Statement stmt = firstStatement.NextStatement; stmt != lastStatement; stmt = stmt.NextStatement) {
// Move all statements except for the first
Statement next;
for (Statement stmt = firstStatement.NextStatement; stmt != lastStatement; stmt = next) {
next = stmt.NextStatement;
newBlock.Add(stmt.Detach());
}
// Replace the first statement with the new (un)checked block
if (isChecked)
firstStatement.ReplaceWith(new CheckedStatement { Body = newBlock });
else
firstStatement.ReplaceWith(new UncheckedStatement { Body = newBlock });
// now also move the first node into the new block
newBlock.Statements.InsertAfter(null, firstStatement);
}
}

4
ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs

@ -24,10 +24,6 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -24,10 +24,6 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public void Run(AstNode compilationUnit)
{
// Don't show using when decompiling a single method or nested types:
if (context.CurrentMethod != null || (context.CurrentType != null && context.CurrentType.DeclaringType != null))
return;
// First determine all the namespaces that need to be imported:
compilationUnit.AcceptVisitor(this, null);

Loading…
Cancel
Save