internal Dictionary <MethodDefinition, Interval> finallyMethodToStateInterval; // used only for IteratorDispose /// <summary> /// Initializes the state range logic: /// Clears 'ranges' and sets 'ranges[entryPoint]' to the full range (int.MinValue to int.MaxValue) /// </summary> public StateRangeAnalysis(ILNode entryPoint, StateRangeAnalysisMode mode, FieldDefinition stateField) { this.mode = mode; this.stateField = stateField; if (mode == StateRangeAnalysisMode.IteratorDispose) { finallyMethodToStateInterval = new Dictionary <MethodDefinition, Interval>(); } ranges = new DefaultDictionary <ILNode, StateRange>(n => new StateRange()); ranges[entryPoint] = new StateRange(int.MinValue, int.MaxValue); evalContext = new SymbolicEvaluationContext(stateField); }
internal static void TranslateFieldsToLocalAccess(List <ILNode> newBody, Dictionary <FieldDefinition, ILVariable> fieldToParameterMap) { var fieldToLocalMap = new DefaultDictionary <FieldDefinition, ILVariable>(f => new ILVariable { Name = f.Name, Type = f.FieldType }); foreach (ILNode node in newBody) { foreach (ILExpression expr in node.GetSelfAndChildrenRecursive <ILExpression>()) { FieldDefinition field = GetFieldDefinition(expr.Operand as FieldReference); if (field != null) { switch (expr.Code) { case ILCode.Ldfld: if (expr.Arguments[0].MatchThis()) { expr.Code = ILCode.Ldloc; if (fieldToParameterMap.ContainsKey(field)) { expr.Operand = fieldToParameterMap[field]; } else { expr.Operand = fieldToLocalMap[field]; } expr.Arguments.Clear(); } break; case ILCode.Stfld: if (expr.Arguments[0].MatchThis()) { expr.Code = ILCode.Stloc; if (fieldToParameterMap.ContainsKey(field)) { expr.Operand = fieldToParameterMap[field]; } else { expr.Operand = fieldToLocalMap[field]; } expr.Arguments.RemoveAt(0); } break; case ILCode.Ldflda: if (expr.Arguments[0].MatchThis()) { expr.Code = ILCode.Ldloca; if (fieldToParameterMap.ContainsKey(field)) { expr.Operand = fieldToParameterMap[field]; } else { expr.Operand = fieldToLocalMap[field]; } expr.Arguments.Clear(); } break; } } } } }