Browse Source

Add sequence point on closing brace if there's an implicit void return.

pull/1440/head
Daniel Grunwald 6 years ago
parent
commit
6a47826fe2
  1. 14
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  2. 6
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
  3. 3
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

14
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -201,4 +201,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -201,4 +201,18 @@ namespace ICSharpCode.Decompiler.CSharp
GetCurrentCall = getCurrentCall;
}
}
/// <summary>
/// Annotates the top-level block statement of a function
/// with the implicitly executed return/yield break.
/// </summary>
public class ImplicitReturnAnnotation
{
public readonly Leave Leave;
public ImplicitReturnAnnotation(Leave leave)
{
this.Leave = leave;
}
}
}

6
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -84,6 +84,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -84,6 +84,12 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var stmt in blockStatement.Statements) {
VisitAsSequencePoint(stmt);
}
var implicitReturn = blockStatement.Annotation<ImplicitReturnAnnotation>();
if (implicitReturn != null) {
StartSequencePoint(blockStatement.RBraceToken);
AddToSequencePoint(implicitReturn.Leave);
EndSequencePoint(blockStatement.RBraceToken.StartLocation, blockStatement.RBraceToken.EndLocation);
}
}
public override void VisitForStatement(ForStatement forStatement)

3
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -936,8 +936,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -936,8 +936,9 @@ namespace ICSharpCode.Decompiler.CSharp
blockStatement.Add(new LabelStatement { Label = block.Label });
}
foreach (var inst in block.Instructions) {
if (!isLoop && inst.OpCode == OpCode.Leave && IsFinalLeave((Leave)inst)) {
if (!isLoop && inst is Leave leave && IsFinalLeave(leave)) {
// skip the final 'leave' instruction and just fall out of the BlockStatement
blockStatement.AddAnnotation(new ImplicitReturnAnnotation(leave));
continue;
}
var stmt = Convert(inst);

Loading…
Cancel
Save