Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3031: emit sequence points for expression-bodied properties and indexers #3032

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
</ItemGroup>

<ItemGroup>
<Content Include="TestCases\PdbGen\Members.xml" />
<Content Include="TestCases\PdbGen\ProgressReporting.xml" />
<Content Include="TestCases\PdbGen\ForLoopTests.xml" />
<Content Include="TestCases\PdbGen\CustomPdbId.xml" />
Expand Down
9 changes: 8 additions & 1 deletion ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public void LambdaCapturing()
TestGeneratePdb();
}

[Test]
[Ignore("Duplicate sequence points for local function")]
public void Members()
{
TestGeneratePdb();
}

[Test]
public void CustomPdbId()
{
Expand Down Expand Up @@ -155,7 +162,7 @@ private void TestGeneratePdb([CallerMemberName] string testName = null)
ProcessXmlFile(expectedFileName);
string generatedFileName = Path.ChangeExtension(xmlFile, ".generated.xml");
ProcessXmlFile(generatedFileName);
Assert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName));
CodeAssert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName));
}

private (string peFileName, string pdbFileName) CompileTestCase(string testName)
Expand Down
95 changes: 95 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/PdbGen/Members.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<symbols>
<files>
<file id="1" name="-\C.cs" language="C#" checksumAlgorithm="SHA256">
<![CDATA[using System;

internal class C : IDisposable
{
private int ExpressionProperty => 42;

private int Property
{
get
{
return 0;
}
set
{
}
}

private C this[int index] => null;

private C this[string s]
{
get
{
return null;
}
set
{
}
}

public event Action Event
{
add
{
}
remove
{
}
}

public static implicit operator C(int i)
{
return null;
}

static C()
{
}

public C()
{
Console.WriteLine();
}

~C()
{
}

void IDisposable.Dispose()
{
}

private static void Main()
{
C c = new C();

c.Event += delegate
{
};
_ = c.Property;
_ = c.ExpressionProperty;
_ = c[0];
_ = c[""];

_ = (C)1;

Local();

static void Local()
{
Console.WriteLine();
}
}
}
]]></file>
</files>
<methods>
</methods>
<method-spans>
</method-spans>
</symbols>
6 changes: 1 addition & 5 deletions ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,10 +1698,7 @@ void DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun de
var function = ilReader.ReadIL((MethodDefinitionHandle)method.MetadataToken, methodBody, cancellationToken: CancellationToken);
function.CheckInvariant(ILPhase.Normal);

if (entityDecl != null)
{
AddAnnotationsToDeclaration(method, entityDecl, function);
}
AddAnnotationsToDeclaration(method, entityDecl, function);

var localSettings = settings.Clone();
if (IsWindowsFormsInitializeComponentMethod(method))
Expand Down Expand Up @@ -1751,7 +1748,6 @@ void DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun de

entityDecl.AddChild(body, Roles.Body);
}
entityDecl.AddAnnotation(function);

CleanUpMethodDeclaration(entityDecl, body, function, localSettings.DecompileMemberBodies);
}
Expand Down
24 changes: 24 additions & 0 deletions ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@ public override void VisitBlockStatement(BlockStatement blockStatement)
}
}

public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
if (!propertyDeclaration.ExpressionBody.IsNull)
{
VisitAsSequencePoint(propertyDeclaration.ExpressionBody);
}
else
{
base.VisitPropertyDeclaration(propertyDeclaration);
}
}

public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
{
if (!indexerDeclaration.ExpressionBody.IsNull)
{
VisitAsSequencePoint(indexerDeclaration.ExpressionBody);
}
else
{
base.VisitIndexerDeclaration(indexerDeclaration);
}
}

public override void VisitForStatement(ForStatement forStatement)
{
// Every element of a for-statement is its own sequence point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void SimplifyPropertyDeclaration(PropertyDeclaration propertyDeclaration)
return;
propertyDeclaration.Modifiers |= propertyDeclaration.Getter.Modifiers;
propertyDeclaration.ExpressionBody = m.Get<Expression>("expression").Single().Detach();
propertyDeclaration.CopyAnnotationsFrom(propertyDeclaration.Getter);
siegfriedpammer marked this conversation as resolved.
Show resolved Hide resolved
propertyDeclaration.Getter.Remove();
}

Expand All @@ -230,6 +231,7 @@ void SimplifyIndexerDeclaration(IndexerDeclaration indexerDeclaration)
return;
indexerDeclaration.Modifiers |= indexerDeclaration.Getter.Modifiers;
indexerDeclaration.ExpressionBody = m.Get<Expression>("expression").Single().Detach();
indexerDeclaration.CopyAnnotationsFrom(indexerDeclaration.Getter);
indexerDeclaration.Getter.Remove();
}
}
Expand Down
24 changes: 24 additions & 0 deletions ICSharpCode.Decompiler/DebugInfo/DebugInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ public override void VisitAnonymousMethodExpression(AnonymousMethodExpression an
HandleMethod(anonymousMethodExpression);
}

public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
if (!propertyDeclaration.ExpressionBody.IsNull)
{
HandleMethod(propertyDeclaration.ExpressionBody, propertyDeclaration.Annotation<ILFunction>());
}
else
{
base.VisitPropertyDeclaration(propertyDeclaration);
}
}

public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
{
if (!indexerDeclaration.ExpressionBody.IsNull)
{
HandleMethod(indexerDeclaration.ExpressionBody, indexerDeclaration.Annotation<ILFunction>());
}
else
{
base.VisitIndexerDeclaration(indexerDeclaration);
}
}

public override void VisitQueryFromClause(QueryFromClause queryFromClause)
{
if (queryFromClause.Parent.FirstChild != queryFromClause)
Expand Down