Browse Source

Fix bugs when decompiling release builds of yield-return enumerators.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
b2b93aff71
  1. 18
      ICSharpCode.Decompiler/ILAst/YieldReturnDecompiler.cs

18
ICSharpCode.Decompiler/ILAst/YieldReturnDecompiler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.ILAst
MethodDefinition disposeMethod;
FieldDefinition stateField;
FieldDefinition currentField;
Dictionary<FieldDefinition, ParameterDefinition> fieldToParameterMap;
Dictionary<FieldDefinition, ParameterDefinition> fieldToParameterMap = new Dictionary<FieldDefinition, ParameterDefinition>();
List<ILNode> newBody;
#region Run() method
@ -84,7 +84,6 @@ namespace ICSharpCode.Decompiler.ILAst @@ -84,7 +84,6 @@ namespace ICSharpCode.Decompiler.ILAst
if (!MatchEnumeratorCreationNewObj(stloc.Arguments[0], out enumeratorCtor))
return false;
fieldToParameterMap = new Dictionary<FieldDefinition, ParameterDefinition>();
int i = 1;
ILExpression stfld;
while (i < method.Body.Count && method.Body[i].Match(ILCode.Stfld, out stfld)) {
@ -697,6 +696,21 @@ namespace ICSharpCode.Decompiler.ILAst @@ -697,6 +696,21 @@ namespace ICSharpCode.Decompiler.ILAst
} else {
throw new YieldAnalysisFailedException();
}
} else if (expr != null && expr.Code == ILCode.Ret) {
if (expr.Arguments.Count != 1 || expr.Arguments[0].Code != ILCode.Ldc_I4)
throw new YieldAnalysisFailedException();
// handle direct return (e.g. in release builds)
int val = (int)expr.Arguments[0].Operand;
if (val == 0) {
newBody.Add(MakeGoTo(returnFalseLabel));
} else if (val == 1) {
if (currentState >= 0 && currentState < switchLabels.Length)
newBody.Add(MakeGoTo(switchLabels[currentState]));
else
newBody.Add(MakeGoTo(returnFalseLabel));
} else {
throw new YieldAnalysisFailedException();
}
} else if (expr != null && expr.Code == ILCode.Call && expr.Arguments.Count == 1 && LoadFromThis.Instance.Match(expr.Arguments[0])) {
MethodDefinition method = expr.Operand as MethodDefinition;
if (method == null)

Loading…
Cancel
Save