Browse Source

Make NumberOfCompilerGeneratedGenerics immutable and rename to NumberOfCompilerGeneratedTypeParameters

pull/1797/head
Siegfried Pammer 5 years ago
parent
commit
9e89384916
  1. 4
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  3. 9
      ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs
  4. 20
      ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs

4
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -197,7 +197,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -197,7 +197,7 @@ namespace ICSharpCode.Decompiler.CSharp
} else if (localFunction != null) {
var ide = new IdentifierExpression(localFunction.Name);
if (method.TypeArguments.Count > 0) {
int skipCount = localFunction.ReducedMethod.NumberOfCompilerGeneratedGenerics;
int skipCount = localFunction.ReducedMethod.NumberOfCompilerGeneratedTypeParameters;
ide.TypeArguments.AddRange(method.TypeArguments.Skip(skipCount).Select(expressionBuilder.ConvertType));
}
target = ide.WithoutILInstruction()
@ -1401,7 +1401,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1401,7 +1401,7 @@ namespace ICSharpCode.Decompiler.CSharp
if ((step & 2) != 0) {
int skipCount = 0;
if (localFunction != null && method.TypeArguments.Count > 0) {
skipCount = localFunction.ReducedMethod.NumberOfCompilerGeneratedGenerics;
skipCount = localFunction.ReducedMethod.NumberOfCompilerGeneratedTypeParameters;
}
ide.TypeArguments.AddRange(method.TypeArguments.Skip(skipCount).Select(expressionBuilder.ConvertType));
}

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -990,7 +990,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -990,7 +990,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (function.Method.TypeParameters.Count > 0) {
var astBuilder = exprBuilder.astBuilder;
if (astBuilder.ShowTypeParameters) {
int skipCount = function.ReducedMethod.NumberOfCompilerGeneratedGenerics;
int skipCount = function.ReducedMethod.NumberOfCompilerGeneratedTypeParameters;
stmt.TypeParameters.AddRange(function.Method.TypeParameters.Skip(skipCount).Select(t => astBuilder.ConvertTypeParameter(t)));
if (astBuilder.ShowTypeParameterConstraints) {
stmt.Constraints.AddRange(function.Method.TypeParameters.Skip(skipCount).Select(t => astBuilder.ConvertTypeParameterConstraint(t)).Where(c => c != null));

9
ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
declaringFunction.LocalFunctions.Add(localFunction);
}
if (TryValidateSkipCount(info, out int skipCount) && skipCount != localFunction.ReducedMethod.NumberOfCompilerGeneratedGenerics) {
if (TryValidateSkipCount(info, out int skipCount) && skipCount != localFunction.ReducedMethod.NumberOfCompilerGeneratedTypeParameters) {
Debug.Assert(false);
function.Warnings.Add($"Could not decode local function '{info.Method}'");
if (localFunction.DeclarationScope != function.Body && localFunction.DeclarationScope.Parent is ILFunction declaringFunction) {
@ -228,8 +228,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -228,8 +228,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var nestedContext = new ILTransformContext(context, function);
function.RunTransforms(CSharpDecompiler.GetILTransforms().TakeWhile(t => !(t is LocalFunctionDecompiler)), nestedContext);
function.DeclarationScope = null;
function.ReducedMethod = ReduceToLocalFunction(function.Method);
function.ReducedMethod.NumberOfCompilerGeneratedGenerics = skipCount;
function.ReducedMethod = ReduceToLocalFunction(function.Method, skipCount);
return function;
}
@ -324,7 +323,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -324,7 +323,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return inst;
}
LocalFunctionMethod ReduceToLocalFunction(IMethod method)
LocalFunctionMethod ReduceToLocalFunction(IMethod method, int skipCount)
{
int parametersToRemove = 0;
for (int i = method.Parameters.Count - 1; i >= 0; i--) {
@ -332,7 +331,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -332,7 +331,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
break;
parametersToRemove++;
}
return new LocalFunctionMethod(method, parametersToRemove);
return new LocalFunctionMethod(method, parametersToRemove, skipCount);
}
static void TransformToLocalFunctionReference(ILFunction function, CallInstruction useSite)

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

@ -31,20 +31,24 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -31,20 +31,24 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{
readonly IMethod baseMethod;
public LocalFunctionMethod(IMethod baseMethod, int numberOfCompilerGeneratedParameters)
public LocalFunctionMethod(IMethod baseMethod, int numberOfCompilerGeneratedParameters, int numberOfCompilerGeneratedTypeParameters)
{
if (baseMethod == null)
throw new ArgumentNullException(nameof(baseMethod));
if (baseMethod is SpecializedMethod)
throw new ArgumentException("Must not be a specialized method!", nameof(baseMethod));
this.baseMethod = baseMethod;
this.NumberOfCompilerGeneratedParameters = numberOfCompilerGeneratedParameters;
this.NumberOfCompilerGeneratedTypeParameters = numberOfCompilerGeneratedTypeParameters;
}
public bool Equals(IMember obj, TypeVisitor typeNormalization)
{
if (!(obj is LocalFunctionMethod other))
return false;
return baseMethod.Equals(other.baseMethod, typeNormalization)
&& NumberOfCompilerGeneratedParameters == other.NumberOfCompilerGeneratedParameters
&& NumberOfCompilerGeneratedGenerics == other.NumberOfCompilerGeneratedGenerics;
&& NumberOfCompilerGeneratedTypeParameters == other.NumberOfCompilerGeneratedTypeParameters;
}
public override bool Equals(object obj)
@ -53,24 +57,22 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -53,24 +57,22 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
return false;
return baseMethod.Equals(other.baseMethod)
&& NumberOfCompilerGeneratedParameters == other.NumberOfCompilerGeneratedParameters
&& NumberOfCompilerGeneratedGenerics == other.NumberOfCompilerGeneratedGenerics;
&& NumberOfCompilerGeneratedTypeParameters == other.NumberOfCompilerGeneratedTypeParameters;
}
public override int GetHashCode()
{
unchecked {
return baseMethod.GetHashCode() + NumberOfCompilerGeneratedParameters + 1;
}
return baseMethod.GetHashCode();
}
public override string ToString()
{
return string.Format("[LocalFunctionMethod: ReducedFrom={0}, NumberOfGeneratedParameters={1}, NumberOfCompilerGeneratedGenerics={2}]", ReducedFrom, NumberOfCompilerGeneratedParameters, NumberOfCompilerGeneratedGenerics);
return string.Format("[LocalFunctionMethod: ReducedFrom={0}, NumberOfGeneratedParameters={1}, NumberOfCompilerGeneratedTypeParameters={2}]", ReducedFrom, NumberOfCompilerGeneratedParameters, NumberOfCompilerGeneratedTypeParameters);
}
internal int NumberOfCompilerGeneratedParameters { get; }
internal int NumberOfCompilerGeneratedGenerics { get; set; }
internal int NumberOfCompilerGeneratedTypeParameters { get; }
internal bool IsStaticLocalFunction => NumberOfCompilerGeneratedParameters == 0 && (baseMethod.IsStatic || (baseMethod.DeclaringTypeDefinition.IsCompilerGenerated() && !baseMethod.DeclaringType.GetFields(f => !f.IsStatic).Any()));

Loading…
Cancel
Save