コード例 #1
0
        private Statement ProcessForStatement(ForNode node)
        {
            ForStatement statement = new ForStatement();

            _symbolTable.PushScope();

            if (node.Initializer != null) {
                if (node.Initializer is VariableDeclarationNode) {
                    VariableDeclarationStatement initializer = (VariableDeclarationStatement)BuildStatement((StatementNode)node.Initializer);
                    statement.AddInitializer(initializer);
                }
                else {
                    Debug.Assert(node.Initializer is ExpressionListNode);

                    ICollection<Expression> initializers = _expressionBuilder.BuildExpressionList((ExpressionListNode)node.Initializer);
                    foreach (Expression initializer in initializers) {
                        statement.AddInitializer(initializer);
                    }
                }
            }

            if (node.Condition != null) {
                Expression condition = _expressionBuilder.BuildExpression(node.Condition);
                if (condition is MemberExpression) {
                    condition = _expressionBuilder.TransformMemberExpression((MemberExpression)condition);
                }
                statement.AddCondition(condition);
            }

            if (node.Increment != null) {
                Debug.Assert(node.Increment is ExpressionListNode);

                ICollection<Expression> increments = _expressionBuilder.BuildExpressionList((ExpressionListNode)node.Increment);
                foreach (Expression increment in increments) {
                    statement.AddIncrement(increment);
                }
            }

            Statement body = BuildStatement((StatementNode)node.Body);
            statement.AddBody(body);

            _symbolTable.PopScope();

            return statement;
        }