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

27
ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

@ -28,33 +28,6 @@ namespace ICSharpCode.Decompiler.IL
{ {
static class ILTypeExtensions 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) public static StackType GetStackType(this MetadataType typeCode)
{ {
switch (typeCode) { switch (typeCode) {

Loading…
Cancel
Save