TransformReadVariable() private method

private TransformReadVariable ( AstGenerator gen, bool tryRead ) : Expression
gen AstGenerator
tryRead bool
return System.Linq.Expressions.Expression
Esempio n. 1
0
        /// <code>
        /// End-exclusive range:
        ///   if state
        ///     state = IsFalse({end})
        ///     true
        ///   else
        ///     state = IsTrue({begin})
        ///   end
        ///
        /// End-inclusive range:
        ///   if state || IsTrue({begin})
        ///     state = IsFalse({end})
        ///     true
        ///   else
        ///     false
        ///   end
        /// </code>
        internal override MSA.Expression /*!*/ TransformRead(AstGenerator /*!*/ gen)
        {
            var begin = AstUtils.Box(_range.Begin.TransformRead(gen));
            var end   = AstUtils.Box(_range.End.TransformRead(gen));

            // state:
            // false <=> null
            // true <=> non-null
            if (_range.IsExclusive)
            {
                return(Ast.Condition(
                           Ast.ReferenceNotEqual(
                               _stateVariable.TransformReadVariable(gen, false),
                               AstUtils.Constant(null)
                               ),
                           Ast.Block(
                               _stateVariable.TransformWriteVariable(gen, Methods.NullIfTrue.OpCall(end)),
                               AstUtils.Constant(true)
                               ),
                           Ast.ReferenceNotEqual(
                               _stateVariable.TransformWriteVariable(gen, Methods.NullIfFalse.OpCall(begin)),
                               AstUtils.Constant(null)
                               )
                           ));
            }
            else
            {
                return(Ast.Condition(
                           Ast.OrElse(
                               Ast.ReferenceNotEqual(
                                   _stateVariable.TransformReadVariable(gen, false),
                                   AstUtils.Constant(null)
                                   ),
                               Methods.IsTrue.OpCall(begin)
                               ),
                           Ast.Block(
                               _stateVariable.TransformWriteVariable(gen, Methods.NullIfTrue.OpCall(end)),
                               AstUtils.Constant(true)
                               ),
                           AstUtils.Constant(false)
                           ));
            }
        }