/// <summary> /// Initializes the state range logic: /// Clears 'ranges' and sets 'ranges[entryPoint]' to the full range (int.MinValue to int.MaxValue) /// </summary> void InitStateRanges(ILNode entryPoint) { ranges = new DefaultDictionary <ILNode, StateRange>(n => new StateRange()); ranges[entryPoint] = new StateRange(int.MinValue, int.MaxValue); rangeAnalysisStateVariable = null; }
void TranslateFieldsToLocalAccess() { 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.EnumerateSelfAndChildrenRecursive().OfType <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; } } } } }