Browse Source

Add IMethod.ThisIsRefReadOnly

pull/1728/head
Daniel Grunwald 6 years ago
parent
commit
ae32913aca
  1. 2
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 4
      ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs
  3. 5
      ICSharpCode.Decompiler/TypeSystem/IMethod.cs
  4. 1
      ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs
  5. 1
      ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs
  6. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs
  7. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMethod.cs
  8. 1
      ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs

2
ICSharpCode.Decompiler/IL/ILReader.cs

@ -191,7 +191,7 @@ namespace ICSharpCode.Decompiler.IL @@ -191,7 +191,7 @@ namespace ICSharpCode.Decompiler.IL
declaringType = new ParameterizedType(declaringType, declaringType.TypeParameters);
}
ILVariable ilVar = CreateILVariable(-1, declaringType, "this");
ilVar.IsRefReadOnly = declaringType.GetDefinition()?.IsReadOnly == true;
ilVar.IsRefReadOnly = method.ThisIsRefReadOnly;
parameterVariables[paramIndex++] = ilVar;
}
while (paramIndex < parameterVariables.Length) {

4
ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

@ -272,8 +272,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -272,8 +272,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var type = method.DeclaringType;
if (type.IsReferenceType == true)
return false; // reference types are never implicitly copied
if (type.GetDefinition()?.IsReadOnly == true)
return false; // readonly structs are never implicitly copied
if (method.ThisIsRefReadOnly)
return false; // no copies for calls on readonly structs
return true;
}

5
ICSharpCode.Decompiler/TypeSystem/IMethod.cs

@ -40,6 +40,11 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -40,6 +40,11 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// </summary>
bool ReturnTypeIsRefReadOnly { get; }
/// <summary>
/// Gets whether the method is readonly (C# 8): accepts the 'this' reference as ref readonly
/// </summary>
bool ThisIsRefReadOnly { get; }
/// <summary>
/// Gets the type parameters of this method; or an empty list if the method is not generic.
/// </summary>

1
ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs

@ -133,6 +133,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -133,6 +133,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IEnumerable<IAttribute> IMethod.GetReturnTypeAttributes() => EmptyList<IAttribute>.Instance;
bool IMethod.ReturnTypeIsRefReadOnly => false;
bool IMethod.ThisIsRefReadOnly => false;
public IReadOnlyList<ITypeParameter> TypeParameters { get; set; } = EmptyList<ITypeParameter>.Instance;

1
ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs

@ -117,6 +117,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -117,6 +117,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IEnumerable<IAttribute> IEntity.GetAttributes() => baseMethod.GetAttributes();
IEnumerable<IAttribute> IMethod.GetReturnTypeAttributes() => baseMethod.GetReturnTypeAttributes();
bool IMethod.ReturnTypeIsRefReadOnly => baseMethod.ReturnTypeIsRefReadOnly;
bool IMethod.ThisIsRefReadOnly => baseMethod.ThisIsRefReadOnly;
/// <summary>
/// We consider local functions as always static, because they do not have a "this parameter".
/// Even local functions in instance methods capture this.

2
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

@ -426,6 +426,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -426,6 +426,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
}
#endregion
public bool ThisIsRefReadOnly => DeclaringTypeDefinition?.IsReadOnly ?? false;
public Accessibility Accessibility => GetAccessibility(attributes);
internal static Accessibility GetAccessibility(MethodAttributes attr)

2
ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMethod.cs

@ -97,6 +97,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -97,6 +97,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public IEnumerable<IAttribute> GetReturnTypeAttributes() => methodDefinition.GetReturnTypeAttributes();
public bool ReturnTypeIsRefReadOnly => methodDefinition.ReturnTypeIsRefReadOnly;
bool IMethod.ThisIsRefReadOnly => methodDefinition.ThisIsRefReadOnly;
public IReadOnlyList<ITypeParameter> TypeParameters {
get {
return specializedTypeParameters ?? methodDefinition.TypeParameters;

1
ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs

@ -114,6 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -114,6 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
IEnumerable<IAttribute> IEntity.GetAttributes() => baseMethod.GetAttributes();
IEnumerable<IAttribute> IMethod.GetReturnTypeAttributes() => baseMethod.GetReturnTypeAttributes();
bool IMethod.ReturnTypeIsRefReadOnly => baseMethod.ReturnTypeIsRefReadOnly;
bool IMethod.ThisIsRefReadOnly => baseMethod.ThisIsRefReadOnly;
public IReadOnlyList<ITypeParameter> TypeParameters {
get { return baseMethod.TypeParameters; }

Loading…
Cancel
Save