Browse Source

Some bugfixes for yield return.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
ae0d6d5295
  1. 3
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 17
      ICSharpCode.Decompiler/ILAst/YieldReturnDecompiler.cs

3
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -142,6 +142,8 @@ namespace ICSharpCode.Decompiler.Ast
public TypeDeclaration CreateType(TypeDefinition typeDef) public TypeDeclaration CreateType(TypeDefinition typeDef)
{ {
TypeDefinition oldCurrentType = context.CurrentType;
context.CurrentType = typeDef;
TypeDeclaration astType = new TypeDeclaration(); TypeDeclaration astType = new TypeDeclaration();
astType.AddAnnotation(typeDef); astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef); astType.Modifiers = ConvertModifiers(typeDef);
@ -207,6 +209,7 @@ namespace ICSharpCode.Decompiler.Ast
} }
ConvertAttributes(astType, typeDef); ConvertAttributes(astType, typeDef);
context.CurrentType = oldCurrentType;
return astType; return astType;
} }

17
ICSharpCode.Decompiler/ILAst/YieldReturnDecompiler.cs

@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.ILAst
break; break;
if (ldloc.Code != ILCode.Ldloc || ldarg.Code != ILCode.Ldarg) if (ldloc.Code != ILCode.Ldloc || ldarg.Code != ILCode.Ldarg)
return false; return false;
if (ldloc.Operand != storedField || !(storedField is FieldDefinition)) if (ldloc.Operand != var1 || !(storedField is FieldDefinition))
return false; return false;
fieldToParameterMap[(FieldDefinition)storedField] = (ParameterDefinition)ldarg.Operand; fieldToParameterMap[(FieldDefinition)storedField] = (ParameterDefinition)ldarg.Operand;
} }
@ -377,11 +377,9 @@ namespace ICSharpCode.Decompiler.ILAst
throw new YieldAnalysisFailedException(); throw new YieldAnalysisFailedException();
MethodDefinition mdef = call.Operand as MethodDefinition; MethodDefinition mdef = call.Operand as MethodDefinition;
if (mdef != null) { if (mdef == null || finallyMethodToStateInterval.ContainsKey(mdef))
if (finallyMethodToStateInterval.ContainsKey(mdef)) throw new YieldAnalysisFailedException();
throw new YieldAnalysisFailedException(); finallyMethodToStateInterval.Add(mdef, interval);
finallyMethodToStateInterval.Add(mdef, interval);
}
} }
ranges = null; ranges = null;
} }
@ -436,6 +434,13 @@ namespace ICSharpCode.Decompiler.ILAst
break; break;
case ILCode.Ret: case ILCode.Ret:
break; break;
case ILCode.Call:
// in some cases (e.g. foreach over array) the C# compiler produces a finally method outside of try-finally blocks
MethodDefinition mdef = expr.Operand as MethodDefinition;
if (mdef == null || finallyMethodToStateInterval.ContainsKey(mdef))
throw new YieldAnalysisFailedException();
finallyMethodToStateInterval.Add(mdef, nodeRange.ToInterval());
break;
default: default:
throw new YieldAnalysisFailedException(); throw new YieldAnalysisFailedException();
} }

Loading…
Cancel
Save