Exemplo n.º 1
0
		internal Dictionary<MethodDef, 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, FieldDef stateField)
		{
			this.mode = mode;
			this.stateField = stateField;
			if (mode == StateRangeAnalysisMode.IteratorDispose) {
				finallyMethodToStateInterval = new Dictionary<MethodDef, Interval>();
			}
			
			ranges = new DefaultDictionary<ILNode, StateRange>(n => new StateRange());
			ranges[entryPoint] = new StateRange(int.MinValue, int.MaxValue);
			evalContext = new SymbolicEvaluationContext(stateField);
		}
Exemplo n.º 2
0
        internal Dictionary <MethodDefinition, StateRange> finallyMethodToStateRange;        // 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, ILVariable cachedStateVar = null)
        {
            this.mode       = mode;
            this.stateField = stateField;
            if (mode == StateRangeAnalysisMode.IteratorDispose)
            {
                finallyMethodToStateRange = new Dictionary <MethodDefinition, StateRange>();
            }

            ranges             = new DefaultDictionary <ILNode, StateRange>(n => new StateRange());
            ranges[entryPoint] = new StateRange(int.MinValue, int.MaxValue);
            evalContext        = new SymbolicEvaluationContext(stateField);
            if (cachedStateVar != null)
            {
                evalContext.AddStateVariable(cachedStateVar);
            }
        }
        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;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <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;
 }