Represents a binary operator expression.
Наследование: Jurassic.Compiler.OperatorExpression
Пример #1
0
        /// <summary>
        /// Generates CIL for a compound assignment 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>
        private void GenerateCompoundAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target)
        {
            // Evaluate the left hand side only once.
            target.GenerateReference(generator, optimizationInfo);
            target.DuplicateReference(generator, optimizationInfo); // For the GenerateSet, later on.

            // Load the value to assign.
            var compoundOperator = new BinaryExpression(GetCompoundBaseOperator(this.OperatorType), new ReferenceGetExpression(target), this.GetOperand(1));
            compoundOperator.GenerateCode(generator, optimizationInfo);

            // Store the resulting value so we can return it as the result of the expression.
            var result = generator.CreateTemporaryVariable(compoundOperator.ResultType);
            generator.Duplicate();
            generator.StoreVariable(result);

            // Store the value.
            target.GenerateSet(generator, optimizationInfo, compoundOperator.ResultType, optimizationInfo.StrictMode);

            // Restore the expression result.
            generator.LoadVariable(result);
            generator.ReleaseTemporaryVariable(result);
        }
        /// <summary>
        /// Generates CIL for a compound assignment 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>
        private void GenerateCompoundAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target)
        {
            // Load the value to assign.
            var compoundOperator = new BinaryExpression(GetCompoundBaseOperator(this.OperatorType), this.GetOperand(0), this.GetOperand(1));
            compoundOperator.GenerateCode(generator, optimizationInfo);

            // Duplicate the value so it remains on the stack afterwards.
            //if (optimizationInfo.SuppressReturnValue == false)
            generator.Duplicate();

            // Store the value.
            target.GenerateSet(generator, optimizationInfo, compoundOperator.ResultType, optimizationInfo.StrictMode);
        }