Browse Source

Eliminate GetStackType() for cecil type references; it was incorrect for arrays of enums.

pull/728/head
Daniel Grunwald 9 years ago
parent
commit
a95cf38ab6
  1. 7
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 27
      ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

7
ICSharpCode.Decompiler/IL/ILReader.cs

@ -59,6 +59,7 @@ namespace ICSharpCode.Decompiler.IL @@ -59,6 +59,7 @@ namespace ICSharpCode.Decompiler.IL
}
Cil.MethodBody body;
StackType methodReturnStackType;
BlobReader reader;
ImmutableStack<ILVariable> currentStack;
ILVariable[] parameterVariables;
@ -80,6 +81,7 @@ namespace ICSharpCode.Decompiler.IL @@ -80,6 +81,7 @@ namespace ICSharpCode.Decompiler.IL
this.reader = body.GetILReader();
this.currentStack = ImmutableStack<ILVariable>.Empty;
this.unionFind = new UnionFind<ILVariable>();
this.methodReturnStackType = typeSystem.Resolve(body.Method.ReturnType).GetStackType();
InitParameterVariables();
this.localVariables = body.Variables.SelectArray(CreateILVariable);
if (body.InitLocals) {
@ -903,11 +905,10 @@ namespace ICSharpCode.Decompiler.IL @@ -903,11 +905,10 @@ namespace ICSharpCode.Decompiler.IL
private ILInstruction Return()
{
var stackType = body.Method.ReturnType.GetStackType();
if (stackType == StackType.Void)
if (methodReturnStackType == StackType.Void)
return new IL.Return();
else
return new IL.Return(Pop(stackType));
return new IL.Return(Pop(methodReturnStackType));
}
private ILInstruction DecodeLdstr()

27
ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

@ -28,33 +28,6 @@ namespace ICSharpCode.Decompiler.IL @@ -28,33 +28,6 @@ namespace ICSharpCode.Decompiler.IL
{
static class ILTypeExtensions
{
/*public static ImmutableArray<StackType> GetStackTypes(this TypeSignatureCollection typeSignatureCollection)
{
var result = new StackType[typeSignatureCollection.Count];
int i = 0;
foreach (var typeSig in typeSignatureCollection) {
result[i++] = GetStackType(typeSig);
}
return ImmutableArray.Create(result);
}*/
public static StackType GetStackType(this TypeReference typeRef)
{
typeRef = typeRef.SkipModifiers();
TypeDefinition typeDef = typeRef.Resolve();
if (typeDef != null && typeDef.IsEnum) {
typeRef = typeDef.GetEnumUnderlyingType();
}
return typeRef.MetadataType.GetStackType();
}
public static TypeReference SkipModifiers(this TypeReference typeRef)
{
while (typeRef.IsOptionalModifier || typeRef.IsRequiredModifier)
typeRef = ((IModifierType)typeRef).ElementType;
return typeRef;
}
public static StackType GetStackType(this MetadataType typeCode)
{
switch (typeCode) {

Loading…
Cancel
Save