Browse Source

Fix #2177: PDB Generation is confused by enhanced using statements

pull/2157/head
Siegfried Pammer 6 years ago
parent
commit
65a5af2c99
  1. 22
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

22
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -112,21 +112,28 @@ namespace ICSharpCode.Decompiler.CSharp
public override void VisitBlockStatement(BlockStatement blockStatement) public override void VisitBlockStatement(BlockStatement blockStatement)
{ {
ILInstruction blockContainer = blockStatement.Annotations.OfType<ILInstruction>().FirstOrDefault(); // enhanced using variables need special-casing here, because we omit the block syntax from the
// text output, so we cannot use positions of opening/closing braces here.
bool isEnhancedUsing = blockStatement.Parent is UsingStatement us && us.IsEnhanced;
if (!isEnhancedUsing)
{
var blockContainer = blockStatement.Annotation<BlockContainer>();
if (blockContainer != null) if (blockContainer != null)
{ {
StartSequencePoint(blockStatement.LBraceToken); StartSequencePoint(blockStatement.LBraceToken);
int intervalStart; int intervalStart;
if (blockContainer.Parent is TryCatchHandler handler && !handler.ExceptionSpecifierILRange.IsEmpty) if (blockContainer.Parent is TryCatchHandler handler && !handler.ExceptionSpecifierILRange.IsEmpty)
{ {
// if this block container is part of a TryCatchHandler, do not steal the exception-specifier IL range // if this block container is part of a TryCatchHandler, do not steal the
// exception-specifier IL range
intervalStart = handler.ExceptionSpecifierILRange.End; intervalStart = handler.ExceptionSpecifierILRange.End;
} }
else else
{ {
intervalStart = blockContainer.StartILOffset; intervalStart = blockContainer.StartILOffset;
} }
// The end will be set to the first sequence point candidate location before the first statement of the function when the seqeunce point is adjusted // The end will be set to the first sequence point candidate location before the first
// statement of the function when the seqeunce point is adjusted
int intervalEnd = intervalStart + 1; int intervalEnd = intervalStart + 1;
Interval interval = new Interval(intervalStart, intervalEnd); Interval interval = new Interval(intervalStart, intervalEnd);
@ -138,16 +145,18 @@ namespace ICSharpCode.Decompiler.CSharp
} }
else else
{ {
// Ideally, we'd be able to address this case. Blocks that are not the top-level function block have no ILInstruction annotations. It isn't clear to me how to determine the il range. // Ideally, we'd be able to address this case. Blocks that are not the top-level function
// block have no ILInstruction annotations. It isn't clear to me how to determine the il range.
// For now, do not add the opening brace sequence in this case. // For now, do not add the opening brace sequence in this case.
} }
}
foreach (var stmt in blockStatement.Statements) foreach (var stmt in blockStatement.Statements)
{ {
VisitAsSequencePoint(stmt); VisitAsSequencePoint(stmt);
} }
var implicitReturn = blockStatement.Annotation<ImplicitReturnAnnotation>(); var implicitReturn = blockStatement.Annotation<ImplicitReturnAnnotation>();
if (implicitReturn != null) if (implicitReturn != null && !isEnhancedUsing)
{ {
StartSequencePoint(blockStatement.RBraceToken); StartSequencePoint(blockStatement.RBraceToken);
AddToSequencePoint(implicitReturn.Leave); AddToSequencePoint(implicitReturn.Leave);
@ -263,6 +272,9 @@ namespace ICSharpCode.Decompiler.CSharp
usingStatement.ResourceAcquisition.AcceptVisitor(this); usingStatement.ResourceAcquisition.AcceptVisitor(this);
VisitAsSequencePoint(usingStatement.EmbeddedStatement); VisitAsSequencePoint(usingStatement.EmbeddedStatement);
AddToSequencePoint(usingStatement); AddToSequencePoint(usingStatement);
if (usingStatement.IsEnhanced)
EndSequencePoint(usingStatement.StartLocation, usingStatement.ResourceAcquisition.EndLocation);
else
EndSequencePoint(usingStatement.StartLocation, usingStatement.RParToken.EndLocation); EndSequencePoint(usingStatement.StartLocation, usingStatement.RParToken.EndLocation);
} }

Loading…
Cancel
Save