Browse Source

#2685: Emit 'override' without 'newslot' as 'virtual' if there is no (known) method to override.

pull/2693/head
Siegfried Pammer 3 years ago
parent
commit
7e08c348b5
  1. 4
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs
  2. 4
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs
  3. 4
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/SequenceOfNestedIfs.cs
  4. 2
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.cs
  5. 33
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  6. 2
      ICSharpCode.Decompiler/DecompileRun.cs

4
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs

@ -92,7 +92,7 @@ public static class Program @@ -92,7 +92,7 @@ public static class Program
pc = 2;
}
public override bool get_CheckClose()
public bool get_CheckClose()
{
switch (pc)
{
@ -106,7 +106,7 @@ public static class Program @@ -106,7 +106,7 @@ public static class Program
[DebuggerNonUserCode]
[CompilerGenerated]
public override int get_LastGenerated()
public int get_LastGenerated()
{
return current;
}

4
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs

@ -93,7 +93,7 @@ public static class Program @@ -93,7 +93,7 @@ public static class Program
pc = 2;
}
public override bool get_CheckClose()
public bool get_CheckClose()
{
switch (pc)
{
@ -107,7 +107,7 @@ public static class Program @@ -107,7 +107,7 @@ public static class Program
[DebuggerNonUserCode]
[CompilerGenerated]
public override int get_LastGenerated()
public int get_LastGenerated()
{
return current;
}

4
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/SequenceOfNestedIfs.cs

@ -12,11 +12,11 @@ public class SequenceOfNestedIfs @@ -12,11 +12,11 @@ public class SequenceOfNestedIfs
{
public bool _clear;
public Material _material;
public override bool CheckShader()
public virtual bool CheckShader()
{
return false;
}
public override void CreateMaterials()
public virtual void CreateMaterials()
{
if (!_clear)
{

2
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/UnknownTypes.cs

@ -2,7 +2,7 @@ internal class UnknownTypes @@ -2,7 +2,7 @@ internal class UnknownTypes
{
private readonly IInterface memberField;
public override bool CanExecute(CallbackQuery message)
public virtual bool CanExecute(CallbackQuery message)
{
return ((IInterface<SomeClass, bool>)(object)memberField).Execute(new SomeClass {
ChatId = StaticClass.GetChatId(message),

33
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1570,14 +1570,16 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1570,14 +1570,16 @@ namespace ICSharpCode.Decompiler.CSharp
{
SetNewModifier(methodDecl);
}
//else if (!method.IsVirtual && method.IsOverride && InheritanceHelper.GetBaseMember(method) == null)
//{
// methodDecl.Modifiers &= ~Modifiers.Override;
// if (!method.DeclaringTypeDefinition.IsSealed)
// {
// methodDecl.Modifiers |= Modifiers.Virtual;
// }
//}
else if (!method.IsStatic && !method.IsExplicitInterfaceImplementation
&& !method.IsVirtual && method.IsOverride
&& InheritanceHelper.GetBaseMember(method) == null && IsTypeHierarchyKnown(method.DeclaringType))
{
methodDecl.Modifiers &= ~Modifiers.Override;
if (!method.DeclaringTypeDefinition.IsSealed)
{
methodDecl.Modifiers |= Modifiers.Virtual;
}
}
if (IsCovariantReturnOverride(method))
{
RemoveAttribute(methodDecl, KnownAttribute.PreserveBaseOverrides);
@ -1585,6 +1587,21 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1585,6 +1587,21 @@ namespace ICSharpCode.Decompiler.CSharp
methodDecl.Modifiers |= Modifiers.Override;
}
return methodDecl;
bool IsTypeHierarchyKnown(IType type)
{
var definition = type.GetDefinition();
if (definition == null)
{
return false;
}
if (decompileRun.TypeHierarchyIsKnown.TryGetValue(definition, out var value))
return value;
value = method.DeclaringType.GetNonInterfaceBaseTypes().All(t => t.Kind != TypeKind.Unknown);
decompileRun.TypeHierarchyIsKnown.Add(definition, value);
return value;
}
}
finally
{

2
ICSharpCode.Decompiler/DecompileRun.cs

@ -19,6 +19,8 @@ namespace ICSharpCode.Decompiler @@ -19,6 +19,8 @@ namespace ICSharpCode.Decompiler
public IDocumentationProvider DocumentationProvider { get; set; }
public Dictionary<ITypeDefinition, RecordDecompiler> RecordDecompilers { get; } = new Dictionary<ITypeDefinition, RecordDecompiler>();
public Dictionary<ITypeDefinition, bool> TypeHierarchyIsKnown { get; } = new();
Lazy<CSharp.TypeSystem.UsingScope> usingScope =>
new Lazy<CSharp.TypeSystem.UsingScope>(() => CreateUsingScope(Namespaces));

Loading…
Cancel
Save