/// <summary> /// Generates CIL for an increment or decrement expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> /// <param name="postfix"> <c>true</c> if this is the postfix version of the operator; /// <c>false</c> otherwise. </param> /// <param name="increment"> <c>true</c> if this is the increment operator; <c>false</c> if /// this is the decrement operator. </param> private void GenerateIncrementOrDecrement(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target, bool postfix, bool increment) { // Note: increment and decrement can produce a number that is out of range if the // target is of type Int32. The only time this should happen is for a loop variable // where the range has been carefully checked to make sure an out of range condition // cannot happen. // Store the value. target.GenerateSet(generator, optimizationInfo, optimizationInfo.RootExpression != this, target.GetResultType(optimizationInfo) == typeof(int) ? typeof(int) : typeof(double), delegate(bool two) { // Get the target value. target.GenerateGet(generator, optimizationInfo, true); // Convert it to a number. if (target.GetResultType(optimizationInfo) != typeof(int)) { EmitConversion.ToNumber(generator, target.GetResultType(optimizationInfo)); } // If this is PostIncrement or PostDecrement, duplicate the value so it can be produced as the return value. if (postfix && two) { generator.Duplicate(); } // Load the increment constant. if (target.GetResultType(optimizationInfo) == typeof(int)) { generator.LoadInt32(1); } else { generator.LoadDouble(1.0); } // Add or subtract the constant to the target value. if (increment == true) { generator.Add(); } else { generator.Subtract(); } // If this is PreIncrement or PreDecrement, duplicate the value so it can be produced as the return value. if (!postfix && two) { generator.Duplicate(); } }, optimizationInfo.StrictMode); }