private void DoWhileNode(WhileNode node)
        {
            // see if the condition is a constant
            if (m_parser.Settings.IsModificationAllowed(TreeModifications.EvaluateNumericExpressions))
            {
                var constantCondition = node.Condition as ConstantWrapper;
                if (constantCondition != null)
                {
                    // TODO: (someday) we'd RATHER eliminate the statement altogether if the condition is always false,
                    // but we'd need to make sure var'd variables and declared functions are properly handled.
                    try
                    {
                        bool isTrue = constantCondition.ToBoolean();
                        if (isTrue)
                        {
                            // the condition is always true, so we should change it to 1
                            if (m_parser.Settings.IsModificationAllowed(TreeModifications.ChangeWhileToFor))
                            {
                                // the condition is always true; we should change it to a for(;;) statement.
                                // less bytes than while(1)

                                // check to see if we want to combine a preceding var with a for-statement
                                AstNode initializer = null;
                                if (m_parser.Settings.IsModificationAllowed(TreeModifications.MoveVarIntoFor))
                                {
                                    // if the previous statement is a var, we can move it to the initializer
                                    // and save even more bytes. The parent should always be a block. If not, 
                                    // then assume there is no previous.
                                    var parentBlock = node.Parent as Block;
                                    if (parentBlock != null)
                                    {
                                        int whileIndex = parentBlock.IndexOf(node);
                                        if (whileIndex > 0)
                                        {
                                            var previousVar = parentBlock[whileIndex - 1] as Var;
                                            if (previousVar != null)
                                            {
                                                initializer = previousVar;
                                                parentBlock.RemoveAt(whileIndex - 1);
                                            }
                                        }
                                    }
                                }

                                // create the for using our body and replace ourselves with it
                                var forNode = new ForNode(node.Context, m_parser)
                                    {
                                        Initializer = initializer,
                                        Body = node.Body
                                    };
                                node.Parent.ReplaceChild(node, forNode);
                            }
                            else
                            {
                                // the condition is always true, so we can replace the condition
                                // with a 1 -- only one byte
                                node.Condition = new ConstantWrapper(1, PrimitiveType.Number, null, m_parser);
                            }
                        }
                        else if (constantCondition.IsNotOneOrPositiveZero)
                        {
                            // the condition is always false, so we can replace the condition
                            // with a zero -- only one byte
                            node.Condition = new ConstantWrapper(0, PrimitiveType.Number, null, m_parser);
                        }
                    }
                    catch (InvalidCastException)
                    {
                        // ignore any invalid cast exceptions
                    }
                }
            }
        }
 public void Visit(WhileNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
        public override void Visit(WhileNode node)
        {
            if (node != null)
            {
                // depth-first
                base.Visit(node);

                DoWhileNode(node);
            }
        }
        public void Visit(WhileNode node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;
                if (node.Condition != null)
                {
                    node.Condition.Accept(this);
                }

                if (node.Body != null)
                {
                    node.Body.Accept(this);
                }
            }
        }
 public void Visit(WhileNode node)
 {
     Debug.Fail("shouldn't get here");
 }
 public void Visit(WhileNode node)
 {
     // not applicable; terminate
 }
        public override void Visit(WhileNode node)
        {
            if (node != null)
            {
                if (m_parser.Settings.StripDebugStatements
                     && m_parser.Settings.IsModificationAllowed(TreeModifications.StripDebugStatements)
                     && node.Body != null
                     && node.Body.IsDebuggerStatement)
                {
                    node.Body = null;
                }

                // recurse
                base.Visit(node);

                // if the body is now empty, make it null
                if (node.Body != null && node.Body.Count == 0)
                {
                    node.Body = null;
                }
            }
        }